|
|
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: 8 = wrong # arguments to nsh
11: 9 = command you execute may not take arguments
12: 10= the execl failed
13: 11= 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: "bpq", 20, "/usr/bin/bpq", "/bin/bpq",
26: "epq", 20, "/usr/bin/epq", "/bin/epq",
27: "finger", 20, "/usr/ucb/finger", "/usr/bin/finger",
28: "lpq", 20, "/usr/bin/lpq", "/bin/lpq",
29: # ifdef FREELPR
30: "lpr", 20, "/usr/bin/lpr", "/bin/lpr",
31: # endif
32: "mmail", 20, "/usr/net/bin/mmail", "/usr/net/bin/mmail",
33: "mwrite", 20, "/usr/net/bin/mwrite", "/usr/net/bin/mwrite",
34: "netlog", 20, "/usr/bin/netlog", "/usr/ucb/netlog",
35: "netq", 20, "/usr/bin/netq", "/usr/ucb/netq",
36: "prmail", 20, "/usr/net/bin/prmail", "/usr/net/bin/prmail",
37: "ps", 20, "/bin/ps", "/usr/bin/ps",
38: "pstat", 20, "/usr/bin/pstat", "/bin/pstat",
39: "rcs", 20, "/usr/bin/rcs", "/bin/rcs",
40: "rcslog", 1, "/usr/bin/rcslog", "/bin/rcslog",
41: "rcsq", 20, "/usr/bin/rcsq", "/bin/rcsq",
42: "trq", 20, "/usr/bin/trq", "/bin/trq",
43: "w", 20, "/usr/bin/w", "/usr/ucb/w",
44: "where", 20, "/usr/bin/where", "/bin/where",
45: "who", 20, "/bin/who", "/usr/bin/who",
46: "whom", 20, "/usr/ucb/whom", "/usr/bin/whom",
47: "write", 20, "/usr/bin/write", "/bin/write",
48: "yank", 20, "/usr/ucb/yank", "/usr/bin/yank",
49: 0, 0, 0, 0
50: };
51: /* nsh -c cmd */
52: main(argc,argv)
53: char **argv; {
54: char *s, buf[500];
55: int i, flg = 0;
56: if(argc != 3){
57: fprintf(stderr,"Wrong number of arguments to nsh.\n");
58: exit(8);
59: }
60: s = argv[2];
61: while(*s && *s != ' ')s++;
62: if(*s == ' ')flg++;
63: *s = 0;
64: if((i = mlookup(argv[2])) < 0){
65: fprintf(stderr,
66: "Command '%s' is not allowed if logged in as 'network'.\n",
67: argv[2]);
68: exit(11);
69: }
70: if(st[i].count == 0){
71: fprintf(stderr,
72: "The command '%s' is not allowed to have arguments.\n",argv[2]);
73: exit(9);
74: }
75: if(stat(st[i].full,buf) >= 0)
76: strcpy(buf,st[i].full);
77: else strcpy(buf,st[i].full1);
78: if(flg && st[i].count > 1){ /* some cmds don't allow parms */
79: *s = ' ';
80: strcat(buf,s);
81: }
82: /*
83: fprintf(stderr,"%s\n",buf);
84: */
85: execl(Bsh,"sh","-c",buf,0);
86: fprintf(stderr,"Execute of shell failed.\n");
87: exit(10);
88: }
89: mlookup(s)
90: char *s; {
91: int i;
92: for(i = 0; st[i].app; i++)
93: if(strcmp(st[i].app,s) == 0 || strcmp(st[i].full,s) == 0
94: || strcmp(st[i].full1,s) == 0)return(i);
95: return(-1);
96: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.