Parse quoting properly in name space files. [rsc] --rw-rw-r-- M 923680 glenda sys 7226 Oct 5 15:28 sys/src/libauth/newns.c /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:14,24 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:14,26 static int setenv(char*, char*); static char *expandarg(char*, char*); static int splitargs(char*, char*[], char*, int); - static int nsfile(Biobuf *, AuthRpc *); - static int nsop(int, char*[], AuthRpc*); + static int nsfile(char*, Biobuf *, AuthRpc *); + static int nsop(char*, int, char*[], AuthRpc*); static int callexport(char*, char*); static int catch(void*, char*); + int newnsdebug; + static int buildns(int newns, char *user, char *file) { /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:32,37 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:34,41 rpc = nil; /* try for factotum now because later is impossible */ afd = open("/mnt/factotum/rpc", ORDWR); + if (afd < 0 && newnsdebug) + fprint(2, "open /mnt/factotum/rpc: %r\n"); if(afd >= 0){ rpc = auth_allocrpc(afd); if(rpc == nil){ /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:59,65 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:63,69 snprint(home, 2*ANAMELEN, "/usr/%s", user); setenv("home", home); } - cdroot = nsfile(b, rpc); + cdroot = nsfile(newns ? "newns" : "addns", b, rpc); Bterm(b); if(rpc){ close(rpc->afd); /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:79,90 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:83,95 } static int - nsfile(Biobuf *b, AuthRpc *rpc) + nsfile(char *fn, Biobuf *b, AuthRpc *rpc) { int argc; char *cmd, *argv[NARG+1], argbuf[MAXARG*NARG]; - int cdroot = 0; + int cdroot; + cdroot = 0; atnotify(catch, 1); while(cmd = Brdline(b, '\n')){ cmd[Blinelen(b)-1] = '\0'; /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:94,100 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:99,105 continue; argc = splitargs(cmd, argv, argbuf, NARG); if(argc) - cdroot |= nsop(argc, argv, rpc); + cdroot |= nsop(fn, argc, argv, rpc); } atnotify(catch, 0); return cdroot; /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:128,143 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:133,154 } static int - nsop(int argc, char *argv[], AuthRpc *rpc) + nsop(char *fn, int argc, char *argv[], AuthRpc *rpc) { char *argv0; ulong flags; - int fd; + int fd, i; Biobuf *b; - int cdroot = 0; + int cdroot; + cdroot = 0; flags = 0; argv0 = 0; + if (newnsdebug){ + for (i = 0; i < argc; i++) + fprint(2, "%s ", argv[i]); + fprint(2, "\n"); + } ARGBEGIN{ case 'a': flags |= MAFTER; /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:160,184 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:171,199 b = Bopen(argv[0], OREAD); if(b == nil) return 0; - cdroot |= nsfile(b, rpc); + cdroot |= nsfile(fn, b, rpc); Bterm(b); - } else if(strcmp(argv0, "clear") == 0 && argc == 0) + }else if(strcmp(argv0, "clear") == 0 && argc == 0) rfork(RFCNAMEG); - else if(strcmp(argv0, "bind") == 0 && argc == 2) - bind(argv[0], argv[1], flags); - else if(strcmp(argv0, "unmount") == 0){ + else if(strcmp(argv0, "bind") == 0 && argc == 2){ + if(bind(argv[0], argv[1], flags) < 0 && newnsdebug) + fprint(2, "%s: bind: %s %s: %r\n", fn, argv[0], argv[1]); + }else if(strcmp(argv0, "unmount") == 0){ if(argc == 1) unmount(nil, argv[0]); else if(argc == 2) unmount(argv[0], argv[1]); - } else if(strcmp(argv0, "mount") == 0){ + }else if(strcmp(argv0, "mount") == 0){ fd = open(argv[0], ORDWR); - if(argc == 2) - famount(fd, rpc, argv[1], flags, ""); - else if(argc == 3) - famount(fd, rpc, argv[1], flags, argv[2]); + if(argc == 2){ + if(famount(fd, rpc, argv[1], flags, "") < 0 && newnsdebug) + fprint(2, "%s: mount: %s %s: %r\n", fn, argv[0], argv[1]); + }else if(argc == 3){ + if(famount(fd, rpc, argv[1], flags, argv[2]) < 0 && newnsdebug) + fprint(2, "%s: mount: %s %s %s: %r\n", fn, argv[0], argv[1], argv[2]); + } close(fd); - } else if(strcmp(argv0, "import") == 0){ + }else if(strcmp(argv0, "import") == 0){ fd = callexport(argv[0], argv[1]); if(argc == 2) famount(fd, rpc, argv[1], flags, ""); /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:185,193 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:200,209 else if(argc == 3) famount(fd, rpc, argv[2], flags, ""); close(fd); - } else if(strcmp(argv0, "cd") == 0 && argc == 1) + }else if(strcmp(argv0, "cd") == 0 && argc == 1){ if(chdir(argv[0]) == 0 && *argv[0] == '/') cdroot = 1; + } return cdroot; } /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:221,226 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:237,267 return fd; } + static char* + unquote(char *s) + { + char *r, *w; + int inquote; + + inquote = 0; + for(r=w=s; *r; r++){ + if(*r != '\''){ + *w++ = *r; + continue; + } + if(inquote){ + if(*(r+1) == '\''){ + *w++ = '\''; + r++; + }else + inquote = 0; + }else + inquote = 1; + } + *w = 0; + return s; + } + static int splitargs(char *p, char *argv[], char *argbuf, int nargv) { /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:227,233 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:268,274 char *q; int i, n; - n = gettokens(p, argv, nargv, " \t'\r"); + n = gettokens(p, argv, nargv, " \t\r"); if(n == nargv) return 0; for(i = 0; i < n; i++){ /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:234,245 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:275,303 q = argv[i]; argv[i] = argbuf; argbuf = expandarg(q, argbuf); - if(!argbuf) + if(argbuf == nil) return 0; + unquote(argv[i]); } return n; } + static char* + nextdollar(char *arg) + { + char *p; + int inquote; + + inquote = 0; + for(p=arg; *p; p++){ + if(*p == '\'') + inquote = !inquote; + if(*p == '$' && !inquote) + return p; + } + return nil; + } + /* * copy the arg into the buffer, * expanding any environment variables. /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:253,263 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:311,321 static char * expandarg(char *arg, char *buf) { - char env[3+ANAMELEN], *p, *q, *x; + char env[3+ANAMELEN], *p, *x; int fd, n, len; n = 0; - while(p = utfrune(arg, L'$')){ + while(p = nextdollar(arg)){ len = p - arg; if(n + len + ANAMELEN >= MAXARG-1) return 0; /n/sourcesdump/2005/1005/plan9/sys/src/libauth/newns.c:264,281 - /n/sourcesdump/2005/1006/plan9/sys/src/libauth/newns.c:322,332 memmove(&buf[n], arg, len); n += len; p++; - arg = utfrune(p, L'\0'); - q = utfrune(p, L'/'); - if(q && q < arg) - arg = q; - q = utfrune(p, L'.'); - if(q && q < arg) - arg = q; - q = utfrune(p, L'$'); - if(q && q < arg) - arg = q; + arg = strpbrk(p, "/.!'$"); + if(arg == nil) + arg = p+strlen(p); len = arg - p; - if(len >= ANAMELEN) + if(len == 0 || len >= ANAMELEN) continue; strcpy(env, "#e/"); strncpy(env+3, p, len); [sys] --rwxrwxr-x M 923680 glenda sys 162241 Oct 5 23:09 386/bin/exportfs /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 101371 Oct 5 23:09 386/bin/import /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/fmt/fmt.c:_fmtinstall /sys/src/libc/port/rune.c:chartorune /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 143960 Oct 5 23:09 386/bin/auth/cron /sys/src/cmd/auth/cron.c:main /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/9sys/ctime.c:gmtime /sys/src/libc/fmt/fmt.c:_fmtinstall /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 104451 Oct 5 23:09 386/bin/auth/login /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/port/rune.c:chartorune /sys/src/libc/port/strpbrk.c:strpbrk /sys/src/libsec/port/des.c:block_cipher /sys/src/libsec/port/des.c:des_key_setup /sys/src/libsec/port/des.c:keycompperm /sys/src/libsec/port/des.c:triple_block_cipher [sys] --rwxrwxr-x M 923680 rsc sys 89687 Oct 5 23:09 386/bin/auth/newns /sys/src/cmd/auth/newns.c:main /sys/src/cmd/auth/newns.c:rooted /sys/src/cmd/auth/newns.c:usage /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/fmt/fmt.c:_fmtinstall /sys/src/libc/fmt/smprint.c:smprint /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 rsc sys 89021 Oct 5 23:09 386/bin/auth/none /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 100637 Oct 5 23:09 386/bin/auth/warning /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/9sys/dirread.c:dirread /sys/src/libc/9sys/dirread.c:dirreadall /sys/src/libc/port/rune.c:chartorune /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 107968 Oct 5 23:09 386/bin/aux/listen /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/9sys/dirread.c:dirread /sys/src/libc/9sys/dirread.c:dirreadall /sys/src/libc/fmt/fmt.c:_fmtinstall /sys/src/libc/fmt/sprint.c:sprint /sys/src/libc/port/pool.c:blocksetdsize /sys/src/libc/port/pool.c:trim /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 rsc sys 94491 Oct 5 23:09 386/bin/aux/listen1 [sys] --rwxrwxr-x M 923680 glenda sys 252710 Oct 5 23:09 386/bin/aux/sshserve [sys] --rwxrwxr-x M 923680 glenda sys 170299 Oct 5 23:09 386/bin/ip/ftpd /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 292364 Oct 5 23:09 386/bin/ip/httpd/httpd /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote [sys] --rwxrwxr-x M 923680 glenda sys 237569 Oct 5 23:09 386/bin/ip/imap4d [sys] --rwxrwxr-x M 923680 glenda sys 219956 Oct 5 23:09 386/bin/ip/ppp [sys] --rwxrwxr-x M 923680 glenda sys 89977 Oct 5 23:09 386/bin/ip/rexexec /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 123067 Oct 5 23:09 386/bin/ip/telnetd /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/9sys/ctime.c:gmtime /sys/src/libc/fmt/fmt.c:_fmtinstall /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 130567 Oct 5 23:09 386/bin/ip/tftpd /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/9sys/ctime.c:gmtime /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 262187 Oct 5 23:09 386/bin/upas/pop3 /sys/src/cmd/upas/pop3/pop3.c:setuser /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 192895 Oct 5 23:09 386/bin/upas/send /sys/src/cmd/upas/smtp/rfc822.y:yylex1 /sys/src/cmd/upas/smtp/rfc822.y:yytokname /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 331205 Oct 5 23:09 386/bin/upas/smtpd /sys/src/cmd/upas/smtp/rfc822.y:yylex1 /sys/src/cmd/upas/smtp/smtpd.y:zzlex1 /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/fmt/fmt.c:_fmtinstall /sys/src/libc/port/strpbrk.c:strpbrk [sys] --rwxrwxr-x M 923680 glenda sys 101180 Oct 5 23:09 386/init /sys/src/libauth/newns.c:buildns /sys/src/libauth/newns.c:callexport /sys/src/libauth/newns.c:expandarg /sys/src/libauth/newns.c:famount /sys/src/libauth/newns.c:nextdollar /sys/src/libauth/newns.c:nsfile /sys/src/libauth/newns.c:nsop /sys/src/libauth/newns.c:setenv /sys/src/libauth/newns.c:splitargs /sys/src/libauth/newns.c:unquote /sys/src/libc/port/rune.c:chartorune /sys/src/libc/port/strpbrk.c:strpbrk /sys/src/libsec/port/des.c:block_cipher /sys/src/libsec/port/des.c:des_key_setup /sys/src/libsec/port/des.c:keycompperm /sys/src/libsec/port/des.c:triple_block_cipher [sys] --rw-rw-r-- M 923680 glenda sys 58648 Oct 5 23:09 386/lib/libauth.a