OpenVAS Scanner  7.0.1~git
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  ,
struct sockaddr_in *   
)

Definition at line 113 of file ftp_funcs.c.

114 {
115  char buf[512];
116  char *t, *s;
117  unsigned char l[6];
118  unsigned long *a;
119  unsigned short *p;
120 
121  snprintf (buf, 7, "PASV\r\n");
122  write_stream_connection (soc, buf, strlen (buf));
123  bzero (buf, sizeof (buf));
124  bzero (addr, sizeof (struct sockaddr_in));
125  if (recv_line (soc, buf, sizeof (buf) - 1) < 0)
126  return 1;
127 
128  if (strncmp (buf, "227", 3) != 0)
129  return 1;
130 
131  t = strchr (buf, '(');
132  if (t == NULL)
133  return 1;
134  t++;
135  s = strchr (t, ',');
136  if (s == NULL)
137  return 1;
138 
139  s[0] = '\0';
140 
141  l[0] = (unsigned char) atoi (t);
142  s++;
143  t = strchr (s, ',');
144  if (t == NULL)
145  return 1;
146  t[0] = 0;
147  l[1] = (unsigned char) atoi (s);
148  t++;
149  s = strchr (t, ',');
150  if (s == NULL)
151  return 1;
152  s[0] = 0;
153  l[2] = (unsigned char) atoi (t);
154  s++;
155  t = strchr (s, ',');
156  if (t == NULL)
157  return 1;
158  t[0] = 0;
159  l[3] = (unsigned char) atoi (s);
160  t++;
161  s = strchr (t, ',');
162  if (s == NULL)
163  return 1;
164  s[0] = 0;
165  l[4] = (unsigned char) atoi (t);
166  s++;
167  t = strchr (s, ')');
168  if (t == NULL)
169  return 1;
170  t[0] = 0;
171  l[5] = (unsigned char) atoi (s);
172  a = (unsigned long *) l;
173  p = (unsigned short *) (l + 4);
174 
175  addr->sin_addr.s_addr = *a;
176  addr->sin_port = *p;
177  addr->sin_family = AF_INET;
178  return 0;
179 }

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  ,
char *  ,
char *   
)

Definition at line 29 of file ftp_funcs.c.

30 {
31  char buf[1024];
32  int n;
33  int counter;
34 
35  buf[sizeof (buf) - 1] = '\0';
36  n = recv_line (soc, buf, sizeof (buf) - 1);
37  if (n <= 0)
38  return 1;
39 
40  if (strncmp (buf, "220", 3) != 0)
41  {
42  return 1;
43  }
44 
45  counter = 0;
46  while (buf[3] == '-' && n > 0 && counter < 1024)
47  {
48  n = recv_line (soc, buf, sizeof (buf) - 1);
49  counter++;
50  }
51 
52  if (counter >= 1024)
53  return 1; /* Rogue FTP server */
54 
55  if (n <= 0)
56  return 1;
57 
58  snprintf (buf, sizeof (buf), "USER %s\r\n", username);
59  write_stream_connection (soc, buf, strlen (buf));
60  n = recv_line (soc, buf, sizeof (buf) - 1);
61  if (n <= 0)
62  return 1;
63  if (strncmp (buf, "230", 3) == 0)
64  {
65  counter = 0;
66  while (buf[3] == '-' && n > 0 && counter < 1024)
67  {
68  n = recv_line (soc, buf, sizeof (buf) - 1);
69  counter++;
70  }
71  return 0;
72  }
73 
74  if (strncmp (buf, "331", 3) != 0)
75  {
76  return 1;
77  }
78 
79  counter = 0;
80  n = 1;
81  while (buf[3] == '-' && n > 0 && counter < 1024)
82  {
83  n = recv_line (soc, buf, sizeof (buf) - 1);
84  counter++;
85  }
86 
87  if (counter >= 1024)
88  return 1;
89 
90  snprintf (buf, sizeof (buf), "PASS %s\r\n", passwd);
91  write_stream_connection (soc, buf, strlen (buf));
92  n = recv_line (soc, buf, sizeof (buf) - 1);
93  if (n <= 0)
94  return 1;
95 
96  if (strncmp (buf, "230", 3) != 0)
97  {
98  return 1;
99  }
100 
101  counter = 0;
102  n = 1;
103  while (buf[3] == '-' && n > 0 && counter < 1024)
104  {
105  n = recv_line (soc, buf, sizeof (buf) - 1);
106  counter++;
107  }
108 
109  return 0;
110 }

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:
recv_line
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:1846
counter
static uint32 counter
Definition: genrand.c:62
write_stream_connection
int write_stream_connection(int fd, void *buf0, int n)
Definition: network.c:1396