OpenVAS Scanner 23.40.3
ftp_funcs.h File Reference

Header file for module ftp_funcs. More...

#include <arpa/inet.h>
#include <sys/param.h>
#include <sys/socket.h>
Include dependency graph for ftp_funcs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int ftp_log_in (int, char *, char *)
int ftp_get_pasv_address (int, struct sockaddr_in *)

Detailed Description

Header file for module ftp_funcs.

Definition in file ftp_funcs.h.

Function Documentation

◆ ftp_get_pasv_address()

int ftp_get_pasv_address ( int soc,
struct sockaddr_in * addr )

Definition at line 101 of file ftp_funcs.c.

102{
103 char buf[512];
104 char *t, *s;
105 unsigned char l[6];
106 uint32_t *a;
107 unsigned short *p;
108
109 snprintf (buf, 7, "PASV\r\n");
110 write_stream_connection (soc, buf, strlen (buf));
111 bzero (buf, sizeof (buf));
112 bzero (addr, sizeof (struct sockaddr_in));
113 if (recv_line (soc, buf, sizeof (buf) - 1) < 0)
114 return 1;
115
116 if (strncmp (buf, "227", 3) != 0)
117 return 1;
118
119 t = strchr (buf, '(');
120 if (t == NULL)
121 return 1;
122 t++;
123 s = strchr (t, ',');
124 if (s == NULL)
125 return 1;
126
127 s[0] = '\0';
128
129 l[0] = (unsigned char) atoi (t);
130 s++;
131 t = strchr (s, ',');
132 if (t == NULL)
133 return 1;
134 t[0] = 0;
135 l[1] = (unsigned char) atoi (s);
136 t++;
137 s = strchr (t, ',');
138 if (s == NULL)
139 return 1;
140 s[0] = 0;
141 l[2] = (unsigned char) atoi (t);
142 s++;
143 t = strchr (s, ',');
144 if (t == NULL)
145 return 1;
146 t[0] = 0;
147 l[3] = (unsigned char) atoi (s);
148 t++;
149 s = strchr (t, ',');
150 if (s == NULL)
151 return 1;
152 s[0] = 0;
153 l[4] = (unsigned char) atoi (t);
154 s++;
155 t = strchr (s, ')');
156 if (t == NULL)
157 return 1;
158 t[0] = 0;
159 l[5] = (unsigned char) atoi (s);
160 a = (uint32_t *) l;
161 p = (unsigned short *) (l + 4);
162
163 addr->sin_addr.s_addr = *a;
164 addr->sin_port = *p;
165 addr->sin_family = AF_INET;
166 return 0;
167}
int write_stream_connection(int fd, void *buf0, int n)
Definition network.c:1583
int recv_line(int soc, char *buf, size_t bufsiz)
Reads a text from the socket stream into the argument buffer, always.
Definition network.c:2040

References recv_line(), and write_stream_connection().

Referenced by nasl_ftp_get_pasv_address().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ftp_log_in()

int ftp_log_in ( int soc,
char * username,
char * passwd )

Definition at line 17 of file ftp_funcs.c.

18{
19 char buf[1024];
20 int n;
21 int counter;
22
23 buf[sizeof (buf) - 1] = '\0';
24 n = recv_line (soc, buf, sizeof (buf) - 1);
25 if (n <= 0)
26 return (1);
27
28 if (strncmp (buf, "220", 3) != 0)
29 {
30 return 1;
31 }
32
33 counter = 0;
34 while (buf[3] == '-' && n > 0 && counter < 1024)
35 {
36 n = recv_line (soc, buf, sizeof (buf) - 1);
37 counter++;
38 }
39
40 if (counter >= 1024)
41 return 1; /* Rogue FTP server */
42
43 if (n <= 0)
44 return 1;
45
46 snprintf (buf, sizeof (buf), "USER %s\r\n", username);
47 write_stream_connection (soc, buf, strlen (buf));
48 n = recv_line (soc, buf, sizeof (buf) - 1);
49 if (n <= 0)
50 return 1;
51 if (strncmp (buf, "230", 3) == 0)
52 {
53 counter = 0;
54 while (buf[3] == '-' && n > 0 && counter < 1024)
55 {
56 n = recv_line (soc, buf, sizeof (buf) - 1);
57 counter++;
58 }
59 return 0;
60 }
61
62 if (strncmp (buf, "331", 3) != 0)
63 {
64 return 1;
65 }
66
67 counter = 0;
68 n = 1;
69 while (buf[3] == '-' && n > 0 && counter < 1024)
70 {
71 n = recv_line (soc, buf, sizeof (buf) - 1);
72 counter++;
73 }
74
75 if (counter >= 1024)
76 return 1;
77
78 snprintf (buf, sizeof (buf), "PASS %s\r\n", passwd);
79 write_stream_connection (soc, buf, strlen (buf));
80 n = recv_line (soc, buf, sizeof (buf) - 1);
81 if (n <= 0)
82 return 1;
83
84 if (strncmp (buf, "230", 3) != 0)
85 {
86 return 1;
87 }
88
89 counter = 0;
90 n = 1;
91 while (buf[3] == '-' && n > 0 && counter < 1024)
92 {
93 n = recv_line (soc, buf, sizeof (buf) - 1);
94 counter++;
95 }
96
97 return 0;
98}
static uint32 counter
Definition genrand.c:48

References counter, recv_line(), and write_stream_connection().

Referenced by nasl_ftp_log_in().

Here is the call graph for this function:
Here is the caller graph for this function: