1/* $NetBSD: ftpcmd.y,v 1.84 2006/02/01 14:20:12 christos Exp $ */ |
2 3/*- |
4 * Copyright (c) 1997-2005 The NetBSD Foundation, Inc. |
5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Luke Mewburn. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: --- 61 unchanged lines hidden (view full) --- 74 75%{ 76#include <sys/cdefs.h> 77 78#ifndef lint 79#if 0 80static char sccsid[] = "@(#)ftpcmd.y 8.3 (Berkeley) 4/6/94"; 81#else |
82__RCSID("$NetBSD: ftpcmd.y,v 1.84 2006/02/01 14:20:12 christos Exp $"); |
83#endif 84#endif /* not lint */ 85 86#include <sys/param.h> 87#include <sys/socket.h> 88#include <sys/stat.h> 89 90#include <netinet/in.h> --- 22 unchanged lines hidden (view full) --- 113static int cmd_type; 114static int cmd_form; 115static int cmd_bytesz; 116 117char cbuf[FTP_BUFLEN]; 118char *cmdp; 119char *fromname; 120 |
121extern int epsvall; 122struct tab sitetab[]; 123 124static int check_write(const char *, int); 125static void help(struct tab *, const char *); 126static void port_check(const char *, int); 127 int yylex(void); 128 |
129%} 130 131%union { 132 struct { 133 LLT ll; 134 int i; 135 } u; 136 char *s; --- 369 unchanged lines hidden (view full) --- 506 if ($2) 507 pwd(); 508 } 509 510 | LIST check_login CRLF 511 { 512 char *argv[] = { INTERNAL_LS, "-lgA", NULL }; 513 |
514 if (CURCLASS_FLAGS_ISSET(hidesymlinks)) 515 argv[1] = "-LlgA"; |
516 if ($2) 517 retrieve(argv, ""); 518 } 519 520 | LIST check_login SP pathname CRLF 521 { 522 char *argv[] = { INTERNAL_LS, "-lgA", NULL, NULL }; 523 |
524 if (CURCLASS_FLAGS_ISSET(hidesymlinks)) 525 argv[1] = "-LlgA"; |
526 if ($2 && $4 != NULL) { 527 argv[2] = $4; 528 retrieve(argv, $4); 529 } 530 if ($4 != NULL) 531 free($4); 532 } 533 --- 766 unchanged lines hidden (view full) --- 1300 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" }, 1301 { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" }, 1302 { "RATEGET", RATEGET,OSTR, 1, "[ <sp> get-throttle-rate ]" }, 1303 { "RATEPUT", RATEPUT,OSTR, 1, "[ <sp> put-throttle-rate ]" }, 1304 { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" }, 1305 { NULL, 0, 0, 0, NULL } 1306}; 1307 |
1308/* 1309 * Check if a filename is allowed to be modified (isupload == 0) or 1310 * uploaded (isupload == 1), and if necessary, check the filename is `sane'. 1311 * If the filename is NULL, fail. 1312 * If the filename is "", don't do the sane name check. 1313 */ 1314static int 1315check_write(const char *file, int isupload) --- 17 unchanged lines hidden (view full) --- 1333 1334 /* checking sanenames */ 1335 if (file[0] != '\0' && CURCLASS_FLAGS_ISSET(sanenames)) { 1336 const char *p; 1337 1338 if (file[0] == '.') 1339 goto insane_name; 1340 for (p = file; *p; p++) { |
1341 if (isalnum((unsigned char)*p) || *p == '-' || *p == '+' || |
1342 *p == ',' || *p == '.' || *p == '_') 1343 continue; 1344 insane_name: 1345 reply(553, "File name `%s' not allowed.", file); 1346 return (0); 1347 } 1348 } 1349 return (1); --- 21 unchanged lines hidden (view full) --- 1371 char *cs; 1372 1373 cs = s; 1374/* tmpline may contain saved command from urgent mode interruption */ 1375 for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) { 1376 *cs++ = tmpline[c]; 1377 if (tmpline[c] == '\n') { 1378 *cs++ = '\0'; |
1379 if (ftpd_debug) |
1380 syslog(LOG_DEBUG, "command: %s", s); 1381 tmpline[0] = '\0'; 1382 return(s); 1383 } 1384 if (c == 0) 1385 tmpline[0] = '\0'; 1386 } 1387 while ((c = getc(iop)) != EOF) { --- 31 unchanged lines hidden (view full) --- 1419 } 1420 *cs++ = c; 1421 if (--n <= 0 || c == '\n') 1422 break; 1423 } 1424 if (c == EOF && cs == s) 1425 return (NULL); 1426 *cs++ = '\0'; |
1427 if (ftpd_debug) { |
1428 if ((curclass.type != CLASS_GUEST && 1429 strncasecmp(s, "PASS ", 5) == 0) || 1430 strncasecmp(s, "ACCT ", 5) == 0) { 1431 /* Don't syslog passwords */ 1432 syslog(LOG_DEBUG, "command: %.4s ???", s); 1433 } else { 1434 char *cp; 1435 int len; --- 135 unchanged lines hidden (view full) --- 1571 cp = &cmdp[cpos]; 1572 n = strlen(cp); 1573 cpos += n - 1; 1574 /* 1575 * Make sure the string is nonempty and \n terminated. 1576 */ 1577 if (n > 1 && cmdp[cpos] == '\n') { 1578 cmdp[cpos] = '\0'; |
1579 yylval.s = ftpd_strdup(cp); |
1580 cmdp[cpos] = '\n'; 1581 state = ARGS; 1582 return (STRING); 1583 } 1584 break; 1585 1586 case NSTR: 1587 if (cmdp[cpos] == ' ') { 1588 cpos++; 1589 return (SP); 1590 } |
1591 if (isdigit((unsigned char)cmdp[cpos])) { |
1592 cp = &cmdp[cpos]; |
1593 while (isdigit((unsigned char)cmdp[++cpos])) |
1594 ; 1595 c = cmdp[cpos]; 1596 cmdp[cpos] = '\0'; 1597 yylval.u.i = atoi(cp); 1598 cmdp[cpos] = c; 1599 state = STR1; 1600 return (NUMBER); 1601 } 1602 state = STR1; 1603 goto dostr1; 1604 1605 case ARGS: |
1606 if (isdigit((unsigned char)cmdp[cpos])) { |
1607 cp = &cmdp[cpos]; |
1608 while (isdigit((unsigned char)cmdp[++cpos])) |
1609 ; 1610 c = cmdp[cpos]; 1611 cmdp[cpos] = '\0'; 1612 yylval.u.i = atoi(cp); 1613 yylval.u.ll = STRTOLL(cp, (char **)NULL, 10); 1614 cmdp[cpos] = c; 1615 return (NUMBER); 1616 } 1617 if (strncasecmp(&cmdp[cpos], "ALL", 3) == 0 |
1618 && !isalnum((unsigned char)cmdp[cpos + 3])) { |
1619 cpos += 3; 1620 return (ALL); 1621 } 1622 switch (cmdp[cpos++]) { 1623 1624 case '\n': 1625 state = EOLN; 1626 return (CRLF); --- 226 unchanged lines hidden --- |