|
|
1.1 root 1: #include "mgr.h"
2: #include <ctype.h>
3:
4: /*
5: * routines used by actions
6: */
7: int doconn(), doexec(), docmd(), dologin();
8: int auth(), v9auth(), inauth();
9: int mesgld(), ttyld();
10: int s5parms(), parms(), asuser(), term();
11: int gateout(), gateway(), pex(), tcphup();
12: int readfiles();
13:
14: /*
15: * table of actions
16: * one per possible action
17: */
18:
19: typedef struct {
20: char *name; /* as used in the services file */
21: int (*func)(); /* function for this action */
22: int flag;
23: } ProtoAction;
24:
25: #define TAKEARG 1
26: #define NEEDARG 2
27: #define IPCACCEPT 4
28:
29: ProtoAction actions[] = {
30: { "readfiles", 0, 0 },
31: { "login", doconn, 0 },
32: { "password", dologin, 0 },
33: { "exec", doexec, 0 },
34: { "cmd", docmd, TAKEARG }, /* arg=command to exec */
35: { "auth", auth, IPCACCEPT },
36: { "v9auth", v9auth, TAKEARG|IPCACCEPT },
37: { "inauth", inauth, TAKEARG|IPCACCEPT },
38: { "mesgld", mesgld, 0 },
39: #ifdef PEX
40: { "pex", pex, 0 },
41: #endif PEX
42: { "ttyld", ttyld, 0 },
43: { "tcphup", tcphup, 0 },
44: { "s5args", s5parms, 0 },
45: { "args", parms, 0 },
46: { "term", term, TAKEARG },
47: { "user", asuser, NEEDARG|IPCACCEPT }, /* arg=user id */
48: { "gateout", gateout, NEEDARG|IPCACCEPT }, /* arg=addr prefix */
49: { "gateway", gateway, NEEDARG|IPCACCEPT }, /* arg=addr prefix */
50: { NULL }
51: };
52:
53: /*
54: * Parse a string for an action. Actions are of the form `xxx(yyy)'.
55: * `xxx' selects the action and `yyy' is the argument to the action.
56: */
57: Action *
58: newaction(cp)
59: char *cp;
60: {
61: ProtoAction *pap;
62: Action *ap = (Action *)malloc(sizeof(Action));
63: char *arg;
64: char *rp;
65:
66: if(ap==NULL) {
67: logevent("out of memory parsing action\n");
68: return NULL;
69: }
70: ap->arg = NULL;
71:
72: /* find the xxx */
73: for(; isspace(*cp); cp++)
74: ;
75: for(arg=cp; *arg && !isspace(*arg) && *arg!='('; arg++)
76: ;
77:
78: /* find the yyy */
79: if(*arg=='(') {
80: rp = strrchr(arg, ')');
81: if (rp == NULL) {
82: logevent("missing `)' in action `%s'\n", cp);
83: freeaction(ap);
84: return NULL;
85: }
86: *arg++ = '\0';
87: for(; isspace(*arg); arg++)
88: ;
89: *rp = '\0';
90: } else
91: arg = NULL;
92:
93: /* look for the action */
94: for(pap=actions; pap->name!=NULL; pap++) {
95: if(strcmp(pap->name, cp)==0) {
96: if(pap->flag&NEEDARG && arg==NULL) {
97: logevent("missing arg in action `%s'\n", cp);
98: freeaction(ap);
99: return NULL;
100: }
101: if(arg!=NULL && !pap->flag&TAKEARG) {
102: logevent("expected no arg in action `%s'\n", cp);
103: freeaction(ap);
104: return NULL;
105: }
106: ap->func = pap->func;
107: ap->arg = strdup(arg);
108: ap->accept = pap->flag&IPCACCEPT;
109: return ap;
110: }
111: }
112: logevent("unknown action `%s'\n", cp);
113: return NULL;
114: }
115:
116: freeaction(ap)
117: Action *ap;
118: {
119: if (ap==(Action *)NULL)
120: return;
121: if (ap->arg!=NULL)
122: free(ap->arg);
123: free((char *)ap);
124: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.