📄 ftpcmd.c
字号:
#line 366 "ftpcmd.y"{ char *cp = yyvsp[-1].s; if (strncasecmp(cp, "SITE", 4) == 0) { cp = yyvsp[-1].s + 4; if (*cp == ' ') cp++; if (*cp) help(sitetab, cp); else help(sitetab, (char *) 0); } else help(cmdtab, yyvsp[-1].s); if (yyvsp[-1].s != NULL) free (yyvsp[-1].s); ; break;}case 29:#line 383 "ftpcmd.y"{ reply(200, "NOOP command successful."); ; break;}case 30:#line 387 "ftpcmd.y"{ if (yyvsp[-3].i && yyvsp[-1].s != NULL) makedir(yyvsp[-1].s); if (yyvsp[-1].s != NULL) free(yyvsp[-1].s); ; break;}case 31:#line 394 "ftpcmd.y"{ if (yyvsp[-3].i && yyvsp[-1].s != NULL) removedir(yyvsp[-1].s); if (yyvsp[-1].s != NULL) free(yyvsp[-1].s); ; break;}case 32:#line 401 "ftpcmd.y"{ if (yyvsp[-1].i) pwd(); ; break;}case 33:#line 406 "ftpcmd.y"{ if (yyvsp[-1].i) cwd(".."); ; break;}case 34:#line 411 "ftpcmd.y"{ help(sitetab, (char *) 0); ; break;}case 35:#line 415 "ftpcmd.y"{ help(sitetab, yyvsp[-1].s); if (yyvsp[-1].s != NULL) free (yyvsp[-1].s); ; break;}case 36:#line 421 "ftpcmd.y"{ int oldmask; if (yyvsp[-1].i) { oldmask = umask(0); umask(oldmask); reply(200, "Current UMASK is %03o", oldmask); } ; break;}case 37:#line 431 "ftpcmd.y"{ int oldmask; if (yyvsp[-3].i) { if ((yyvsp[-1].i == -1) || (yyvsp[-1].i > 0777)) { reply(501, "Bad UMASK value"); } else { oldmask = umask(yyvsp[-1].i); reply(200, "UMASK set to %03o (was %03o)", yyvsp[-1].i, oldmask); } } ; break;}case 38:#line 446 "ftpcmd.y"{ if (yyvsp[-5].i && (yyvsp[-1].s != NULL)) { if (yyvsp[-3].i > 0777) reply(501, "CHMOD: Mode value must be between 0 and 0777"); else if (chmod(yyvsp[-1].s, yyvsp[-3].i) < 0) perror_reply(550, yyvsp[-1].s); else reply(200, "CHMOD command successful."); } if (yyvsp[-1].s != NULL) free(yyvsp[-1].s); ; break;}case 39:#line 460 "ftpcmd.y"{ reply(200, "Current IDLE time limit is %d seconds; max %d", timeout, maxtimeout); ; break;}case 40:#line 466 "ftpcmd.y"{ if (yyvsp[-4].i) { if (yyvsp[-1].i < 30 || yyvsp[-1].i > maxtimeout) { reply (501, "Maximum IDLE time must be between 30 and %d seconds", maxtimeout); } else { timeout = yyvsp[-1].i; alarm((unsigned) timeout); reply(200, "Maximum IDLE time set to %d seconds", timeout); } } ; break;}case 41:#line 482 "ftpcmd.y"{ if (yyvsp[-3].i && yyvsp[-1].s != NULL) store(yyvsp[-1].s, "w", 1); if (yyvsp[-1].s != NULL) free(yyvsp[-1].s); ; break;}case 42:#line 489 "ftpcmd.y"{ const char *sys_type; /* Official rfc-defined os type. */ char *version = 0; /* A more specific type. */#ifdef HAVE_UNAME struct utsname u; if (uname (&u) == 0) { version = malloc (strlen (u.sysname) + 1 + strlen (u.release) + 1); if (version) sprintf (version, "%s %s", u.sysname, u.release); }#else#ifdef BSD version = "BSD";#endif#endif#ifdef unix sys_type = "UNIX";#else sys_type = "UNKNOWN";#endif if (version) reply(215, "%s Type: L%d Version: %s", sys_type, NBBY, version); else reply(215, "%s Type: L%d", sys_type, NBBY);#ifdef HAVE_UNAME if (version) free (version);#endif ; break;}case 43:#line 535 "ftpcmd.y"{ if (yyvsp[-3].i && yyvsp[-1].s != NULL) sizecmd(yyvsp[-1].s); if (yyvsp[-1].s != NULL) free(yyvsp[-1].s); ; break;}case 44:#line 552 "ftpcmd.y"{ if (yyvsp[-3].i && yyvsp[-1].s != NULL) { struct stat stbuf; if (stat(yyvsp[-1].s, &stbuf) < 0) reply(550, "%s: %s", yyvsp[-1].s, strerror(errno)); else if (!S_ISREG(stbuf.st_mode)) { reply(550, "%s: not a plain file.", yyvsp[-1].s); } else { struct tm *t; t = gmtime(&stbuf.st_mtime); reply(213, "%04d%02d%02d%02d%02d%02d", 1900 + t->tm_year, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); } } if (yyvsp[-1].s != NULL) free(yyvsp[-1].s); ; break;}case 45:#line 574 "ftpcmd.y"{ reply(221, "Goodbye."); dologout(0); ; break;}case 46:#line 579 "ftpcmd.y"{ yyerrok; ; break;}case 47:#line 585 "ftpcmd.y"{ restart_point = (off_t) 0; if (yyvsp[-3].i && yyvsp[-1].s) { if (fromname != NULL) free (fromname); fromname = renamefrom(yyvsp[-1].s); } if (fromname == (char *) 0 && yyvsp[-1].s) free(yyvsp[-1].s); ; break;}case 48:#line 596 "ftpcmd.y"{ if (fromname != NULL) free (fromname); fromname = (char *) 0; restart_point = yyvsp[-1].i; /* XXX $3 is only "int" */ reply(350, (sizeof(restart_point) > sizeof(long) ? "Restarting at %qd. %s" : "Restarting at %ld. %s"), restart_point, "Send STORE or RETRIEVE to initiate transfer."); ; break;}case 50:#line 615 "ftpcmd.y"{ yyval.s = (char *)calloc(1, sizeof(char)); ; break;}case 53:#line 628 "ftpcmd.y"{ char *a, *p; a = (char *)&data_dest.sin_addr; a[0] = yyvsp[-10].i; a[1] = yyvsp[-8].i; a[2] = yyvsp[-6].i; a[3] = yyvsp[-4].i; p = (char *)&data_dest.sin_port; p[0] = yyvsp[-2].i; p[1] = yyvsp[0].i; data_dest.sin_family = AF_INET; ; break;}case 54:#line 641 "ftpcmd.y"{ yyval.i = FORM_N; ; break;}case 55:#line 645 "ftpcmd.y"{ yyval.i = FORM_T; ; break;}case 56:#line 649 "ftpcmd.y"{ yyval.i = FORM_C; ; break;}case 57:#line 656 "ftpcmd.y"{ cmd_type = TYPE_A; cmd_form = FORM_N; ; break;}case 58:#line 661 "ftpcmd.y"{ cmd_type = TYPE_A; cmd_form = yyvsp[0].i; ; break;}case 59:#line 666 "ftpcmd.y"{ cmd_type = TYPE_E; cmd_form = FORM_N; ; break;}case 60:#line 671 "ftpcmd.y"{ cmd_type = TYPE_E; cmd_form = yyvsp[0].i; ; break;}case 61:#line 676 "ftpcmd.y"{ cmd_type = TYPE_I; ; break;}case 62:#line 680 "ftpcmd.y"{ cmd_type = TYPE_L; cmd_bytesz = NBBY; ; break;}case 63:#line 685 "ftpcmd.y"{ cmd_type = TYPE_L; cmd_bytesz = yyvsp[0].i; ; break;}case 64:#line 691 "ftpcmd.y"{ cmd_type = TYPE_L; cmd_bytesz = yyvsp[0].i; ; break;}case 65:#line 699 "ftpcmd.y"{ yyval.i = STRU_F; ; break;}case 66:#line 703 "ftpcmd.y"{ yyval.i = STRU_R; ; break;}case 67:#line 707 "ftpcmd.y"{ yyval.i = STRU_P; ; break;}case 68:#line 714 "ftpcmd.y"{ yyval.i = MODE_S; ; break;}case 69:#line 718 "ftpcmd.y"{ yyval.i = MODE_B; ; break;}case 70:#line 722 "ftpcmd.y"{ yyval.i = MODE_C; ; break;}case 71:#line 729 "ftpcmd.y"{ /* * Problem: this production is used for all pathname * processing, but only gives a 550 error reply. * This is a valid reply in some cases but not in others. */ if (cred.logged_in && yyvsp[0].s && *yyvsp[0].s == '~') { glob_t gl; int flags = GLOB_NOCHECK;#ifdef GLOB_BRACE flags |= GLOB_BRACE;#endif#ifdef GLOB_QUOTE flags |= GLOB_QUOTE;#endif#ifdef GLOB_TILDE flags |= GLOB_TILDE;#endif memset(&gl, 0, sizeof(gl)); if (glob(yyvsp[0].s, flags, NULL, &gl) || gl.gl_pathc == 0) { reply(550, "not found"); yyval.s = NULL; } else { yyval.s = strdup(gl.gl_pathv[0]); } globfree(&gl); free(yyvsp[0].s); } else yyval.s = yyvsp[0].s; ; break;}case 73:#line 770 "ftpcmd.y"{ int ret, dec, multby, digit; /* * Convert a number that was read as decimal number * to what it would be if it had been read as octal. */ dec = yyvsp[0].i; multby = 1; ret = 0; while (dec) { digit = dec%10; if (digit > 7) { ret = -1; break; } ret += digit * multby; multby *= 8; dec /= 10; } yyval.i = ret; ; break;}case 74:#line 797 "ftpcmd.y"{ if (cred.logged_in) yyval.i = 1; else { reply(530, "Please login with USER and PASS."); yyval.i = 0; } ; break;}} /* the action file gets copied in in place of this dollarsign */#line 543 "/usr/share/bison.simple" yyvsp -= yylen; yyssp -= yylen;#ifdef YYLSP_NEEDED yylsp -= yylen;#endif#if YYDEBUG != 0 if (yydebug) { short *ssp1 = yyss - 1; fprintf (stderr, "state stack now"); while (ssp1 != yyssp) fprintf (stderr, " %d", *++ssp1); fprintf (stderr, "\n"); }#endif *++yyvsp = yyval;#ifdef YYLSP_NEEDED yylsp++; if (yylen == 0) { yylsp->first_line = yylloc.first_line; yylsp->first_column = yylloc.first_column; yylsp->last_line = (yylsp-1)->last_line; yylsp->last_column = (yylsp-1)->last_column; yylsp->text = 0; } else { yylsp->last_line = (yylsp+yylen-1)->last_line; yylsp->last_column = (yylsp+yylen-1)->last_column; }#endif /* Now "shift" the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTBASE] + *yyssp; if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTBASE]; goto yynewstate;yyerrlab: /* here on detecting error */ if (! yyerrstatus) /* If not already recovering from an error, report this error. */ { ++yynerrs;#ifdef YYERROR_VERBOSE yyn = yypact[yystate]; if (yyn > YYFLAG && yyn < YYLAST) { int size = 0; char *msg; int x, count; count = 0; /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ for (x = (yyn < 0 ? -yyn : 0); x < (sizeof(yytname) / sizeof(char *)); x++) if (yycheck[x + yyn] == x) size += strlen(yytname[x]) + 15, count++; msg = (char *) malloc(size + 15); if (msg != 0) { strcpy(msg, "parse error"); if (count < 5) { count = 0; for (x = (yyn < 0 ? -yyn : 0); x < (sizeof(yytname) / sizeof(char *)); x++) if (yycheck[x + yyn] == x) { strcat(msg, count == 0 ? ", expecting `" : " or `"); strcat(msg, yytname[x]); strcat(msg, "'"); count++; } } yyerror(msg); free(msg); } else yyerror ("parse error; also virtual memory exceeded"); } else#endif /* YYERROR_VERBOSE */ yyerror("parse error"); } goto yyerrlab1;yyerrlab1: /* here on error raised explicitly by an action */ if (yyerrstatus == 3) { /* if just tried and failed to reuse lookahead token after an error, discard it. */ /* return failure if at end of input */ if (yychar == YYEOF) YYABORT;#if YYDEBUG != 0 if (yydebug) fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);#endif yychar = YYEMPTY; } /* Else will try to reuse lookahead token after shifting the error token. */ yyerrstatus = 3; /* Each real token shifted decrements this */ goto yyerrhandle;yyerrdefault: /* current state does not do anything special for the error token. */#if 0 /* This is wrong; only states that explicitly want error tokens should shift them. */ yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ if (yyn) goto yydefault;#endifyyerrpop: /* pop the current state because it cannot handle the error token */ if (yyssp == yyss) YYABORT; yyvsp--; yystate = *--yyssp;#ifdef YYLSP_NEEDED yylsp--;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -