Status field is now Comment field
[unix-history] / usr / src / libexec / ftpd / ftpcmd.y
index 0b88f55..9267ae9 100644 (file)
@@ -12,7 +12,7 @@
 %{
 
 #ifndef lint
 %{
 
 #ifndef lint
-static char sccsid[] = "@(#)ftpcmd.y   5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)ftpcmd.y   5.8 (Berkeley) %G%";
 #endif
 
 #include <sys/types.h>
 #endif
 
 #include <sys/types.h>
@@ -51,6 +51,7 @@ static        int cmd_type;
 static int cmd_form;
 static int cmd_bytesz;
 char cbuf[512];
 static int cmd_form;
 static int cmd_bytesz;
 char cbuf[512];
+char *fromname;
 
 char   *index();
 %}
 
 char   *index();
 %}
@@ -77,6 +78,10 @@ char *index();
 
 cmd_list:      /* empty */
        |       cmd_list cmd
 
 cmd_list:      /* empty */
        |       cmd_list cmd
+               = {
+                       fromname = (char *) 0;
+               }
+       |       cmd_list rcmd
        ;
 
 cmd:           USER SP username CRLF
        ;
 
 cmd:           USER SP username CRLF
@@ -103,6 +108,8 @@ cmd:                USER SP username CRLF
                                else {
                                    reply(331, "Password required for %s.", $3);
                                }
                                else {
                                    reply(331, "Password required for %s.", $3);
                                }
+                       } else {
+                               reply(530, "User %s access denied.", $3);
                        }
                        free((char *) $3);
                }
                        }
                        free((char *) $3);
                }
@@ -235,6 +242,17 @@ cmd:               USER SP username CRLF
                        if ($4 != NULL)
                                free((char *) $4);
                }
                        if ($4 != NULL)
                                free((char *) $4);
                }
+       |       RNTO SP pathname CRLF
+               = {
+                       if (fromname) {
+                               renamecmd(fromname, (char *) $3);
+                               free(fromname);
+                               fromname = (char *) 0;
+                       } else {
+                               reply(503, "Bad sequence of commands.");
+                       }
+                       free((char *) $3);
+               }
        |       ABOR CRLF
                = {
                        reply(225, "ABOR command successful.");
        |       ABOR CRLF
                = {
                        reply(225, "ABOR command successful.");
@@ -251,7 +269,6 @@ cmd:                USER SP username CRLF
                        if ($4 != NULL)
                                free((char *) $4);
                }
                        if ($4 != NULL)
                                free((char *) $4);
                }
-       |       rename_cmd
        |       HELP CRLF
                = {
                        help((char *) 0);
        |       HELP CRLF
                = {
                        help((char *) 0);
@@ -309,6 +326,19 @@ cmd:               USER SP username CRLF
                }
        ;
 
                }
        ;
 
+rcmd:          RNFR check_login SP pathname CRLF
+               = {
+                       char *renamefrom();
+
+                       if ($2 && $4) {
+                               fromname = renamefrom((char *) $4);
+                               if (fromname == (char *) 0 && $4) {
+                                       free((char *) $4);
+                               }
+                       }
+               }
+       ;
+               
 username:      STRING
        ;
 
 username:      STRING
        ;
 
@@ -437,37 +467,6 @@ pathname:  pathstring
 pathstring:    STRING
        ;
 
 pathstring:    STRING
        ;
 
-rename_cmd:    rename_from rename_to
-       = {
-               if ($1 && $2)
-                       renamecmd((char *) $1, (char *) $2);
-               else
-                       reply(503, "Bad sequence of commands.");
-               if ($1)
-                       free((char *) $1);
-               if ($2)
-                       free((char *) $2);
-       }
-       ;
-
-rename_from:   RNFR check_login SP pathname CRLF
-       = {
-               char *from = 0, *renamefrom();
-
-               if ($2 && $4)
-                       from = renamefrom((char *) $4);
-               if (from == 0 && $4)
-                       free((char *) $4);
-               $$ = (int)from;
-       }
-       ;
-
-rename_to:     RNTO SP pathname CRLF
-       = {
-               $$ = $3;
-       }
-       ;
-
 check_login:   /* empty */
        = {
                if (logged_in)
 check_login:   /* empty */
        = {
                if (logged_in)
@@ -568,9 +567,9 @@ getline(s, n, iop)
 {
        register c;
        register char *cs;
 {
        register c;
        register char *cs;
-       char ch;
 
        cs = s;
 
        cs = s;
+/* tmpline may contain saved command from urgent mode interruption */
        for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
                *cs++ = tmpline[c];
                if (tmpline[c] == '\n') {
        for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
                *cs++ = tmpline[c];
                if (tmpline[c] == '\n') {
@@ -585,18 +584,32 @@ getline(s, n, iop)
                        tmpline[0] = '\0';
                }
        }
                        tmpline[0] = '\0';
                }
        }
-       while (--n > 0 && read(fileno(iop),&ch,1) >= 0) {
-               c = 0377 & ch;
+       while (--n > 0 && (c = getc(iop)) != EOF) {
+               c = 0377 & c;
                while (c == IAC) {
                while (c == IAC) {
-                       (void) read(fileno(iop),&ch,1); /* skip command */
-                       (void) read(fileno(iop),&ch,1); /* try next char */
-                       c = 0377 & ch;
+                       switch (c = 0377 & getc(iop)) {
+                       case WILL:
+                       case WONT:
+                               c = 0377 & getc(iop);
+                               printf("%c%c%c", IAC, WONT, c);
+                               (void) fflush(stdout);
+                               break;
+                       case DO:
+                       case DONT:
+                               c = 0377 & getc(iop);
+                               printf("%c%c%c", IAC, DONT, c);
+                               (void) fflush(stdout);
+                               break;
+                       default:
+                               break;
+                       }
+                       c = 0377 & getc(iop); /* try next character */
                }
                *cs++ = c;
                if (c=='\n')
                        break;
        }
                }
                *cs++ = c;
                if (c=='\n')
                        break;
        }
-       if (c < 0 && cs == s)
+       if (c == EOF && cs == s)
                return (NULL);
        *cs++ = '\0';
        if (debug) {
                return (NULL);
        *cs++ = '\0';
        if (debug) {