Develop and Download Open Source Software

Browse Subversion Repository

Diff of /tags/REL-1.1/ftp_str.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by hirohitohigashi, Wed Feb 18 08:06:53 2009 UTC revision 7 by hirohitohigashi, Fri Feb 20 12:10:40 2009 UTC
# Line 36  char path[1050]={'\0'}; Line 36  char path[1050]={'\0'};
36    
37  int strfnbytes(char *big_str, char *needle, int bytes) {  int strfnbytes(char *big_str, char *needle, int bytes) {
38    
39          int i=0;      int i=0;
40          int same=0;      int same=0;
41    
42                  if (strlen(big_str)-1 < bytes) {      if (strlen(big_str)-1 < bytes) {
43                          printf("[-] Big String MUST BE major than %d\n", bytes);          printf("[-] Big String MUST BE major than %d\n", bytes);
44                          printf("Aborting...\n");          printf("Aborting...\n");
45                          return (-1);          return (-1);
46                  }      }
47    
48    
49                  if (strlen(needle)-1 >= bytes) {      if (strlen(needle)-1 >= bytes) {
50                          printf("[-] needle MUST BE the same as n bytes\n");          printf("[-] needle MUST BE the same as n bytes\n");
51                          printf("Aborting...\n");          printf("Aborting...\n");
52                          return (-1);          return (-1);
53                  }      }
54    
55                    
56          while (big_str[i] != '\0') {      while (big_str[i] != '\0') {
57    
58                          if (i >= bytes)          if (i >= bytes)
59                                  break;              break;
60                                    
61                  if (needle[i] == big_str[i]) {          if (needle[i] == big_str[i]) {
62                                                    
63                          same++;              same++;
64                  } else {          } else {
65                                                    
66                          same=0;              same=0;
67                          break;              break;
68                  }          }
69    
70                  i++;          i++;
71                                    
72          }      }
73    
74          if (same != 0)      if (same != 0)
75                  return 0;          return 0;
76          else      else
77                  return -1;          return -1;
78    
79  }  }
80    
81  /*  /*
82  *   *
83  * find_pasv: find the ports in the PASV message reply   * find_pasv: find the ports in the PASV message reply
84  * char *StrPasv: the reply string to working on it   * char *StrPasv: the reply string to working on it
85  * int verbose: verbose mode   * int verbose: verbose mode
86  *       - 1 Yes   *      - 1 Yes
87  *       - 0 No   *      - 0 No
88  *   *
89  */   */
90    
91  int find_pasv (char *StrPasv, int verbose) {  int find_pasv (char *StrPasv, int verbose)
92    {
93  char p1[100];      char p1[100];
94  char p2[100];      char p2[100];
95    
96  int port1 = 0;      int port1 = 0;
97  int port2 = 0;      int port2 = 0;
98        int count = 0;
99  int len = strlen(StrPasv);      int i = 0;
100        int temp = 0;
101  len = len-2;      int tmp = 0;
102  StrPasv[len] = '\0';      int sum = 0;
103    
104  int count = 0;      extern int data_port1;
105  int i = 0;      extern int data_port2;
106    
107            
108          if (strstr(StrPasv, ")") == NULL) { //mmh an error occur..      int len = strlen(StrPasv);
109                  return 1;  
110        len = len-2;
111        StrPasv[len] = '\0';
112    
113            
114        if (strstr(StrPasv, ")") == NULL) { //mmh an error occur..
115            return 1;
116        }
117    
118        while (StrPasv[i] != '\0') {
119            if (StrPasv[i] == ')') {
120                break;
121          }          }
122    
123          while (StrPasv[i] != '\0') {          i++;
124                  if (StrPasv[i] == ')') {      }
                         break;  
                 }  
   
                 i++;  
         }  
125    
 int temp = 0;  
126    
127  temp = i;      temp = i;
128  i = 0;      i = 0;
129    
 int tmp = 0;  
 int sum = 0;  
130    
131    
 extern int data_port1;  
 extern int data_port2;  
132    
133  data_port1 = 0;      data_port1 = 0;
134  data_port2 = 0;      data_port2 = 0;
135    
136  count = temp;      count = temp;
137    
138  count = count - 1;      count = count - 1;
139    
140  memset(p1, 0x0, 100);      memset(p1, 0x0, 100);
141  memset(p2, 0x0, 100);      memset(p2, 0x0, 100);
142    
143          if (verbose == 1) {      if (verbose == 1) {
144          printf("--[ Server: %s\n", StrPasv);          printf("--[ Server: %s\n", StrPasv);
145          }      }
146    
147          while (StrPasv[count] != ',') {      while (StrPasv[count] != ',') {
148    
149          if (i >= 100)          if (i >= 100)
150                  return -1;              return -1;
151    
152          p1[i] = StrPasv[count];          p1[i] = StrPasv[count];
153                    
154          count--;          count--;
155          i++;          i++;
156    
157          }      }
158    
159          p1[i] = '\0';      p1[i] = '\0';
160    
161                    
162          count--;      count--;
163          i = 0;      i = 0;
164    
165          while (StrPasv[count] != ',') {      while (StrPasv[count] != ',') {
166    
167          p2[i] = StrPasv[count];          p2[i] = StrPasv[count];
168                    
# Line 169  memset(p2, 0x0, 100); Line 170  memset(p2, 0x0, 100);
170          count--;          count--;
171          i++;          i++;
172    
173          }      }
174    
175          p2[i] = '\0';      p2[i] = '\0';
176    
177          i = 0;      i = 0;
178          count = 0;      count = 0;
179          tmp = 0;      tmp = 0;
180          sum = 0;      sum = 0;
181    
182          while (p1[i] != '\0') {      while (p1[i] != '\0') {
183    
184          tmp = 0;          tmp = 0;
185          sum = 0;          sum = 0;
186    
187          if (i == 1) {          if (i == 1) {
188                                    
189          tmp = (int)p1[i] - 48;              tmp = (int)p1[i] - 48;
190          sum = 10*tmp;              sum = 10*tmp;
191    
192          port1 = port1 + sum;              port1 = port1 + sum;
193    
194          } else if (i == 2) {          } else if (i == 2) {
195    
196          tmp = (int)p1[i] - 48;              tmp = (int)p1[i] - 48;
197                    
198          sum = 100*tmp;              sum = 100*tmp;
199                    
200          port1 = port1 + sum;              port1 = port1 + sum;
201    
202          } else if (i == 0) {          } else if (i == 0) {
203                                    
204          tmp = (int)p1[i] - 48;              tmp = (int)p1[i] - 48;
205                                    
206          port1 = port1 + tmp;              port1 = port1 + tmp;
207                    
208          } else if ( i > 2) {          } else if ( i > 2) {
209    
210          return -1;              return -1;
211    
212          }          }
213    
214          i++;          i++;
215                    
216          }      }
217    
218          i = 0;      i = 0;
219          count = 0;      count = 0;
220          tmp = 0;      tmp = 0;
221          sum = 0;      sum = 0;
222    
223          while (p2[i] != '\0') {      while (p2[i] != '\0') {
224    
225          tmp = 0;          tmp = 0;
226          sum = 0;          sum = 0;
227    
228          if (i == 1) {          if (i == 1) {
229                                    
230          tmp = (int)p2[i] - 48;              tmp = (int)p2[i] - 48;
231          sum = 10*tmp;              sum = 10*tmp;
232    
233          port2 = port2 + sum;              port2 = port2 + sum;
234    
235          } else if (i == 2) {          } else if (i == 2) {
236    
237          tmp = (int)p2[i] - 48;              tmp = (int)p2[i] - 48;
238                    
239          sum = 100*tmp;              sum = 100*tmp;
240                    
241          port2 = port2 + sum;              port2 = port2 + sum;
242    
243          } else if (i == 0) {          } else if (i == 0) {
244                                    
245          tmp = (int)p2[i] - 48;              tmp = (int)p2[i] - 48;
246                                    
247          port2 = port2 + tmp;              port2 = port2 + tmp;
248    
249          } else if ( i > 2) {          } else if ( i > 2) {
250    
251          return -1;              return -1;
252    
253          }          }
254    
255          i++;          i++;
256                    
257          }      }
258    
259  data_port2 = port1;      data_port2 = port1;
260  data_port1 = port2;      data_port1 = port2;
261    
262    
263  return 0;      return 0;
264    
265    
266  }  }
267    
268  /*  /*
269  *   *
270  * ftp_DataPort: Make the right Data Port for transfer connections   * ftp_DataPort: Make the right Data Port for transfer connections
271  * int PortOne: First port in the PASV reply   * int PortOne: First port in the PASV reply
272  * int PortTwo: Second port in the PASV reply   * int PortTwo: Second port in the PASV reply
273  *   *
274  */   */
275    
276  int ftp_DataPort (int PortOne, int PortTwo) {  int ftp_DataPort (int PortOne, int PortTwo) {
277    
278  /*** HOWTO Data Transfer Connection:  /*** HOWTO Data Transfer Connection:
279  ((port1 * 256) + port2)       ((port1 * 256) + port2)
280  ***/  ***/
281    
282  extern int data_port;      extern int data_port;
283    
284  data_port = 0;      data_port = 0;
285    
286  data_port = PortOne * 256;      data_port = PortOne * 256;
287  data_port = data_port + PortTwo;      data_port = data_port + PortTwo;
288    
289  return data_port;      return data_port;
290    
291  }  }
292    
293  /*  /*
294  *   *
295  * ftp_path: Reply with the Current Directory   * ftp_path: Reply with the Current Directory
296  * char *PathCurDir: Reply of the FTPD from the PWD command   * char *PathCurDir: Reply of the FTPD from the PWD command
297  *   *
298  */   */
299    
300  int ftp_path (char *PathCurDir) {  int ftp_path (char *PathCurDir) {
301    
302  int i = 0;      int i = 0;
303  int count = 0;      int count = 0;
304    
305  if (strlen(PathCurDir) > 1024)      if (strlen(PathCurDir) > 1024)
306          return -1;          return -1;
307    
308  while (PathCurDir[i] != '"') {      while (PathCurDir[i] != '"') {
309    
310          if (i >= 1024)          if (i >= 1024)
311          return -1;              return -1;
312  i++;          i++;
313    
314  }      }
315    
316  i++;      i++;
317    
318  while (PathCurDir[i] != '"') {      while (PathCurDir[i] != '"') {
319    
320          if (i >= 1024) {          if (i >= 1024) {
321          path[i] = '\0';              path[i] = '\0';
322          break;              break;
323          }          }
324    
325  path[count] = PathCurDir[i];          path[count] = PathCurDir[i];
326  i++;          i++;
327  count++;          count++;
328  }      }
329    
330          if (i >= 1024) {      if (i >= 1024) {
331          path[i] = '\0';          path[i] = '\0';
332          return 0;          return 0;
333          }      }
334    
335  path[count] = '\0';      path[count] = '\0';
336    
337  return 0;      return 0;
338    
339  }  }

Legend:
Removed from v.1  
changed lines
  Added in v.7

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26