|
|
1.1 ! root 1: # include "defs.h" ! 2: /* ! 3: nsh -c "comand to be executed" ! 4: ! 5: This pseudo-shell is executed over the network ! 6: as the login shell of an acount "network", no passwd. ! 7: It will only execute certain allowed commands. ! 8: ! 9: has these exit codes: ! 10: EX_USAGE = wrong # arguments to nsh ! 11: 9 = command you execute may not take arguments ! 12: 10= the execl failed ! 13: EX_UNAVAILABLE= could not find full path name for the command ! 14: ! 15: count is the # of arguments (= argc) allowed. ! 16: a count of 0 turns off the command ! 17: */ ! 18: ! 19: struct { ! 20: char *app; ! 21: char count; ! 22: char *full; ! 23: char *full1; ! 24: } st[] = { ! 25: /* I assume these are the same for RAND */ ! 26: "mmail", 20, "/usr/net/bin/mmail", "/usr/net/bin/mmail", ! 27: "mwrite", 20, "/usr/net/bin/mwrite", "/usr/net/bin/mwrite", ! 28: "prmail", 20, "/usr/net/bin/prmail", "/usr/net/bin/prmail", ! 29: # ifndef NFREECMD ! 30: "bpq", 20, "/usr/bin/bpq", "/bin/bpq", ! 31: "epq", 20, "/usr/bin/epq", "/bin/epq", ! 32: "finger", 20, "/usr/ucb/finger", "/usr/bin/finger", ! 33: "help", 20, "/bin/help", "/usr/bin/help", ! 34: "lpq", 20, "/usr/bin/lpq", "/bin/lpq", ! 35: # ifdef FREELPR ! 36: "lpr", 20, "/usr/bin/lpr", "/bin/lpr", ! 37: # endif ! 38: "netlog", 20, "/usr/bin/netlog", "/usr/ucb/netlog", ! 39: "netq", 20, "/usr/bin/netq", "/usr/ucb/netq", ! 40: "news", 20, "/usr/bin/news", "/usr/ucb/news", ! 41: "ps", 20, "/bin/ps", "/usr/bin/ps", ! 42: "pstat", 20, "/usr/bin/pstat", "/bin/pstat", ! 43: "rcs", 20, "/usr/bin/rcs", "/bin/rcs", ! 44: "rcslog", 1, "/usr/bin/rcslog", "/bin/rcslog", ! 45: "rcsq", 20, "/usr/bin/rcsq", "/bin/rcsq", ! 46: "trq", 20, "/usr/bin/trq", "/bin/trq", ! 47: "vpq", 20, "/usr/ucb/vpq", "/usr/bin/vpq", ! 48: "w", 20, "/usr/ucb/w", "/usr/bin/w", ! 49: "wc", 20, "/usr/bin/wc", "/bin/wc", ! 50: "where", 20, "/usr/bin/where", "/bin/where", ! 51: "who", 20, "/bin/who", "/usr/bin/who", ! 52: "whom", 20, "/usr/ucb/whom", "/usr/bin/whom", ! 53: "write", 20, "/usr/bin/write", "/bin/write", ! 54: "yank", 20, "/usr/ucb/yank", "/usr/bin/yank", ! 55: # endif ! 56: 0, 0, 0, 0 ! 57: }; ! 58: /* nsh -c cmd */ ! 59: main(argc,argv) ! 60: char **argv; { ! 61: char *s, buf[500]; ! 62: int i, flg = 0; ! 63: if(argc != 3){ ! 64: fprintf(stderr,"Wrong number of arguments to nsh.\n"); ! 65: exit(EX_USAGE); ! 66: } ! 67: s = argv[2]; ! 68: while(*s && *s != ' ')s++; ! 69: if(*s == ' ')flg++; ! 70: *s = 0; ! 71: if((i = mlookup(argv[2])) < 0){ ! 72: fprintf(stderr, ! 73: "Command '%s' is not allowed if logged in as 'network'.\n", ! 74: argv[2]); ! 75: exit(11); ! 76: } ! 77: if(st[i].count == 0){ ! 78: fprintf(stderr, ! 79: "The command '%s' is not allowed to have arguments.\n",argv[2]); ! 80: exit(9); ! 81: } ! 82: if(stat(st[i].full,buf) >= 0) ! 83: strcpy(buf,st[i].full); ! 84: else strcpy(buf,st[i].full1); ! 85: if(flg && st[i].count > 1){ /* some cmds don't allow parms */ ! 86: *s = ' '; ! 87: strcat(buf,s); ! 88: } ! 89: /* ! 90: fprintf(stderr,"%s\n",buf); ! 91: */ ! 92: execl(Bsh,"sh","-c",buf,0); ! 93: fprintf(stderr,"Execute of shell failed.\n"); ! 94: exit(EX_UNAVAILABLE); ! 95: } ! 96: mlookup(s) ! 97: char *s; { ! 98: int i; ! 99: for(i = 0; st[i].app; i++) ! 100: if(strcmp(st[i].app,s) == 0 || strcmp(st[i].full,s) == 0 ! 101: || strcmp(st[i].full1,s) == 0)return(i); ! 102: return(-1); ! 103: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.