OpenVAS Libraries  9.0.3
ftp_funcs.h File Reference
#include <sys/socket.h>
#include <arpa/inet.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 *)
 

Function Documentation

◆ ftp_get_pasv_address()

int ftp_get_pasv_address ( int  ,
struct sockaddr_in *   
)

Definition at line 124 of file ftp_funcs.c.

References recv_line(), and write_stream_connection().

Referenced by nasl_ftp_get_pasv_address().

125 {
126  char buf[512];
127  char *t, *s;
128  unsigned char l[6];
129  unsigned long *a;
130  unsigned short *p;
131 
132  snprintf (buf, 7, "PASV\r\n");
133  write_stream_connection (soc, buf, strlen (buf));
134  bzero (buf, sizeof (buf));
135  bzero (addr, sizeof (struct sockaddr_in));
136  recv_line (soc, buf, sizeof (buf) - 1);
137 
138  if (strncmp (buf, "227", 3) != 0)
139  return 1;
140 
141  t = strchr (buf, '(');
142  if (t == NULL)
143  return 1;
144  t++;
145  s = strchr (t, ',');
146  if (s == NULL)
147  return 1;
148 
149  s[0] = '\0';
150 
151  l[0] = (unsigned char) atoi (t);
152  s++;
153  t = strchr (s, ',');
154  if (t == NULL)
155  return 1;
156  t[0] = 0;
157  l[1] = (unsigned char) atoi (s);
158  t++;
159  s = strchr (t, ',');
160  if (s == NULL)
161  return 1;
162  s[0] = 0;
163  l[2] = (unsigned char) atoi (t);
164  s++;
165  t = strchr (s, ',');
166  if (t == NULL)
167  return 1;
168  t[0] = 0;
169  l[3] = (unsigned char) atoi (s);
170  t++;
171  s = strchr (t, ',');
172  if (s == NULL)
173  return 1;
174  s[0] = 0;
175  l[4] = (unsigned char) atoi (t);
176  s++;
177  t = strchr (s, ')');
178  if (t == NULL)
179  return 1;
180  t[0] = 0;
181  l[5] = (unsigned char) atoi (s);
182  a = (unsigned long *) l;
183  p = (unsigned short *) (l + 4);
184 
185  addr->sin_addr.s_addr = *a;
186  addr->sin_port = *p;
187  addr->sin_family = AF_INET;
188  return 0;
189 }
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:2017
int write_stream_connection(int fd, void *buf0, int n)
Definition: network.c:1571
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ftp_log_in()

int ftp_log_in ( int  ,
char *  ,
char *   
)

Definition at line 37 of file ftp_funcs.c.

Referenced by nasl_ftp_log_in().

38 {
39  char buf[1024];
40  int n;
41  int counter;
42 
43  buf[sizeof (buf) - 1] = '\0';
44  n = recv_line (soc, buf, sizeof (buf) - 1);
45  if (n <= 0)
46  return (1);
47 
48  if (strncmp (buf, "220", 3) != 0)
49  {
50  return 1;
51  }
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 
60  if (counter >= 1024)
61  return 1; /* Rogue FTP server */
62 
63  if (n <= 0)
64  return 1;
65 
66 
67  snprintf (buf, sizeof (buf), "USER %s\r\n", username);
68  write_stream_connection (soc, buf, strlen (buf));
69  n = recv_line (soc, buf, sizeof (buf) - 1);
70  if (n <= 0)
71  return 1;
72  if (strncmp (buf, "230", 3) == 0)
73  {
74  counter = 0;
75  while (buf[3] == '-' && n > 0 && counter < 1024)
76  {
77  n = recv_line (soc, buf, sizeof (buf) - 1);
78  counter++;
79  }
80  return 0;
81  }
82 
83  if (strncmp (buf, "331", 3) != 0)
84  {
85  return 1;
86  }
87 
88  counter = 0;
89  n = 1;
90  while (buf[3] == '-' && n > 0 && counter < 1024)
91  {
92  n = recv_line (soc, buf, sizeof (buf) - 1);
93  counter++;
94  }
95 
96  if (counter >= 1024)
97  return 1;
98 
99 
100  snprintf (buf, sizeof (buf), "PASS %s\r\n", passwd);
101  write_stream_connection (soc, buf, strlen (buf));
102  n = recv_line (soc, buf, sizeof (buf) - 1);
103  if (n <= 0)
104  return 1;
105 
106  if (strncmp (buf, "230", 3) != 0)
107  {
108  return 1;
109  }
110 
111  counter = 0;
112  n = 1;
113  while (buf[3] == '-' && n > 0 && counter < 1024)
114  {
115  n = recv_line (soc, buf, sizeof (buf) - 1);
116  counter++;
117  }
118 
119  return 0;
120 }
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:2017
int write_stream_connection(int fd, void *buf0, int n)
Definition: network.c:1571
Here is the caller graph for this function: