]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/ip/ftpd.c
ftpd: handle "allo" command by treating it as a no-op
[plan9front.git] / sys / src / cmd / ip / ftpd.c
old mode 100755 (executable)
new mode 100644 (file)
index 18c3264..6661189
@@ -33,7 +33,6 @@ enum
        /* maximum ms we'll wait for a command */
        Maxwait=        1000*60*30,             /* inactive for 30 minutes, we hang up */
 
-       Maxerr=         128,
        Maxpath=        512,
 };
 
@@ -49,6 +48,7 @@ int   mkdircmd(char*);
 int    modecmd(char*);
 int    namelistcmd(char*);
 int    nopcmd(char*);
+int    optscmd(char*);
 int    passcmd(char*);
 int    pasvcmd(char*);
 int    portcmd(char*);
@@ -85,6 +85,7 @@ struct Cmd
 Cmd cmdtab[] =
 {
        { "abor",       abortcmd,       0, },
+       { "allo",       nopcmd,         1, },
        { "appe",       appendcmd,      1, },
        { "cdup",       cdupcmd,        1, },
        { "cwd",        cwdcmd,         1, },
@@ -96,6 +97,7 @@ Cmd cmdtab[] =
        { "mode",       modecmd,        0, },
        { "nlst",       namelistcmd,    1, },
        { "noop",       nopcmd,         0, },
+       { "opts",       optscmd,        0, },
        { "pass",       passcmd,        0, },
        { "pasv",       pasvcmd,        1, },
        { "pwd",        pwdcmd,         0, },
@@ -159,14 +161,11 @@ logit(char *fmt, ...)
 {
        char buf[8192];
        va_list arg;
-       char errstr[128];
 
-       rerrstr(errstr, sizeof errstr);
        va_start(arg, fmt);
        vseprint(buf, buf+sizeof(buf), fmt, arg);
        va_end(arg);
        syslog(0, FTPLOG, "%s.%s %s", nci->rsys, nci->rserv, buf);
-       werrstr(errstr, sizeof errstr);
 }
 
 static void
@@ -414,10 +413,10 @@ transfer(char *cmd, char *a1, char *a2, char *a3, int image)
                if(isnone){
                        fd = open("#s/boot", ORDWR);
                        if(fd < 0
-                       || bind("#/", "/", MAFTER) < 0
-                       || amount(fd, "/bin", MREPL, "") < 0
-                       || bind("#c", "/dev", MAFTER) < 0
-                       || bind(bindir, "/bin", MREPL) < 0)
+                       || bind("#/", "/", MAFTER) == -1
+                       || amount(fd, "/bin", MREPL, "") == -1
+                       || bind("#c", "/dev", MAFTER) == -1
+                       || bind(bindir, "/bin", MREPL) == -1)
                                exits("building name space");
                        close(fd);
                }
@@ -478,6 +477,24 @@ transfer(char *cmd, char *a1, char *a2, char *a3, int image)
        return bytes;
 }
 
+int
+optscmd(char *arg)
+{
+       char *p;
+
+       if(arg == 0 || *arg == 0){
+               reply("501 Syntax error in parameters or arguments");
+               return 0;
+       }
+       if(p = strchr(arg, ' '))
+               *p = 0;
+       if(cistrcmp(arg, "UTF-8") == 0 || cistrcmp(arg, "UTF8") == 0){
+               reply("200 Command okay");
+               return 0;
+       }
+       reply("502 %s option not implemented", arg);
+       return 0;
+}
 
 /*
  *  just reply OK
@@ -590,6 +607,7 @@ passcmd(char *response)
 {
        char namefile[128];
        AuthInfo *ai;
+       Dir nd;
 
        if(response == nil)
                response = "";
@@ -616,9 +634,17 @@ passcmd(char *response)
                ch->nresp = strlen(response);
                ai = auth_response(ch);
                if(ai == nil || auth_chuid(ai, nil) < 0) {
+                       auth_freeAI(ai);
                        slowdown();
                        return reply("530 Not logged in: %r");
                }
+               /* chown network connection */
+               nulldir(&nd);
+               nd.mode = 0660;
+               nd.uid = ai->cuid;
+               dirfwstat(0, &nd);
+
+               auth_freeAI(ai);
                auth_freechal(ch);
                ch = nil;
 
@@ -785,12 +811,12 @@ mountnet(void)
 
        rv = 0;
 
-       if(bind("#/", "/", MAFTER) < 0){
+       if(bind("#/", "/", MAFTER) == -1){
                logit("can't bind #/ to /: %r");
                return reply("500 can't bind #/ to /: %r");
        }
 
-       if(bind(nci->spec, "/net", MBEFORE) < 0){
+       if(bind(nci->spec, "/net", MBEFORE) == -1){
                logit("can't bind %s to /net: %r", nci->spec);
                rv = reply("500 can't bind %s to /net: %r", nci->spec);
                unmount("#/", "/");
@@ -1058,7 +1084,7 @@ list(char *arg, int lflag)
 
        dfd = dialdata();
        if(dfd < 0){
-               reply("425 Error opening data connection:%r");
+               reply("425 Error opening data connection: %r");
                return;
        }
        reply("150 Opened data connection (%s)", data);
@@ -1152,6 +1178,8 @@ sitecmd(char *arg)
        int nf, r;
        Dir *d;
 
+       if(arg == 0)
+               return reply("501 bad site command");
        nf = tokenize(arg, f, nelem(f));
        if(nf != 3 || cistrcmp(f[0], "chmod") != 0)
                return reply("501 bad site command");
@@ -1351,7 +1379,7 @@ retrieve(char *arg, int arg2)
        reply("150 Opening data connection for %s (%s)", arg, data);
        dfd = dialdata();
        if(dfd < 0){
-               reply("425 Error opening data connection:%r");
+               reply("425 Error opening data connection: %r");
                close(fd);
                return;
        }
@@ -1423,7 +1451,7 @@ store(char *arg, int fd)
        reply("150 Opening data connection for %s (%s)", arg, data);
        dfd = dialdata();
        if(dfd < 0){
-               reply("425 Error opening data connection:%r");
+               reply("425 Error opening data connection: %r");
                close(fd);
                return;
        }
@@ -1591,6 +1619,7 @@ helpcmd(char *arg)
 
        USED(arg);
        reply("214- the following commands are implemented:");
+       buf[0] = 0;
        p = buf;
        e = buf+sizeof buf;
        for(i = 0; cmdtab[i].name; i++){
@@ -1674,30 +1703,29 @@ dialdata(void)
 {
        int fd, cfd;
        char ldir[40];
-       char err[Maxerr];
+       char err[ERRMAX];
 
        if(mountnet() < 0)
                return -1;
 
-       if(!passive.inuse){
+       if(!passive.inuse)
                fd = dial(data, "20", 0, 0);
-               errstr(err, sizeof err);
-       } else {
+       else {
+               fd = -1;
                alarm(5*60*1000);
                cfd = listen(passive.adir, ldir);
                alarm(0);
-               errstr(err, sizeof err);
-               if(cfd < 0)
-                       return -1;
-               fd = accept(cfd, ldir);
-               errstr(err, sizeof err);
-               close(cfd);
+               if(cfd >= 0){
+                       fd = accept(cfd, ldir);
+                       close(cfd);
+               }
        }
+       err[0] = 0;
+       errstr(err, sizeof err);
        if(fd < 0)
                logit("can't dial %s: %s", data, err);
-
        unmountnet();
-       werrstr(err, sizeof err);
+       errstr(err, sizeof err);
        return fd;
 }