]>
Commit | Line | Data |
---|---|---|
a3cf6921 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * | |
8 | * $Log$ | |
3630192b | 9 | * Revision 1.5 1987-06-26 10:55:53 wesommer |
10 | * Added sms_access, now paiys attention to return code from | |
11 | * sms_process_query, sms_check_access. | |
a3cf6921 | 12 | * |
3630192b | 13 | * Revision 1.4 87/06/21 16:42:00 wesommer |
14 | * Performance work, rearrangement of include files. | |
15 | * | |
c27b3454 | 16 | * Revision 1.3 87/06/04 01:35:01 wesommer |
17 | * Added a working query request handler. | |
18 | * | |
78849033 | 19 | * Revision 1.2 87/06/03 16:07:50 wesommer |
20 | * Fixes for lint. | |
21 | * | |
5dbd09a0 | 22 | * Revision 1.1 87/06/02 20:07:10 wesommer |
23 | * Initial revision | |
24 | * | |
a3cf6921 | 25 | */ |
26 | ||
27 | #ifndef lint | |
28 | static char *rcsid_sms_scall_c = "$Header$"; | |
29 | #endif lint | |
30 | ||
31 | #include <krb.h> | |
78849033 | 32 | #include <errno.h> |
a3cf6921 | 33 | #include "sms_server.h" |
34 | extern char buf1[]; | |
35 | extern int nclients; | |
36 | extern char *whoami; | |
37 | ||
38 | extern void clist_delete(), do_auth(), do_shutdown(); | |
39 | void do_call(); | |
40 | ||
41 | /* | |
42 | * Welcome to the (finite state) machine (highest level). | |
43 | */ | |
44 | void | |
45 | do_client(cp) | |
46 | client *cp; | |
47 | { | |
48 | if (OP_STATUS(cp->pending_op) == OP_CANCELLED) { | |
49 | (void) sprintf(buf1, "Closed connection (now %d client%s)", | |
50 | nclients-1, | |
51 | nclients!=2?"s":""); | |
52 | com_err(whoami, 0, buf1); | |
53 | clist_delete(cp); | |
54 | return; | |
55 | } | |
56 | switch (cp->action) { | |
57 | case CL_ACCEPT: | |
58 | case CL_SEND: | |
59 | /* Start recieving next request */ | |
60 | initialize_operation(cp->pending_op, sms_start_recv, | |
5dbd09a0 | 61 | (char *)&cp->args, (int (*)())NULL); |
a3cf6921 | 62 | queue_operation(cp->con, CON_INPUT, cp->pending_op); |
63 | cp->action = CL_RECEIVE; | |
64 | break; | |
65 | case CL_RECEIVE: | |
66 | /* Data is here. Process it & start it heading back */ | |
67 | do_call(cp); /* This may block for a while. */ | |
68 | initialize_operation(cp->pending_op, sms_start_send, | |
5dbd09a0 | 69 | (char *)&cp->reply, (int (*)())NULL); |
a3cf6921 | 70 | queue_operation(cp->con, CON_OUTPUT, cp->pending_op); |
71 | cp->action = CL_SEND; | |
72 | break; | |
73 | } | |
74 | } | |
75 | ||
76 | #ifdef notdef | |
77 | char *procnames[] = { | |
78 | "noop", | |
79 | "auth", | |
80 | "shutdown", | |
78849033 | 81 | "query", |
a3cf6921 | 82 | }; |
83 | #endif notdef | |
84 | ||
85 | void | |
86 | do_call(cl) | |
87 | client *cl; | |
88 | { | |
89 | int pn; | |
90 | cl->reply.sms_argc = 0; | |
91 | cl->reply.sms_status = 0; | |
92 | if (((pn = cl->args->sms_procno) < 0) || | |
93 | (pn > SMS_MAX_PROC)) { | |
94 | com_err(whoami, 0, "procno out of range"); | |
95 | cl->reply.sms_status = SMS_UNKNOWN_PROC; | |
96 | return; | |
97 | } | |
98 | #ifdef SMS_DBG | |
99 | fprintf(stderr, "[#%d] %s(", cl->id, procnames[pn]); | |
100 | for (i=0; i < cl->args->sms_argc; i++) { | |
101 | if (i) fputc(',', stderr); | |
102 | frequote(stderr,cl->args->sms_argv[i]); | |
103 | } | |
104 | fprintf(stderr, ")\n"); | |
105 | #endif SMS_DBG | |
106 | ||
107 | switch(pn) { | |
108 | case SMS_NOOP: | |
109 | cl->reply.sms_status = 0; | |
110 | com_err(whoami, 0, "noop"); | |
111 | return; | |
3630192b | 112 | |
a3cf6921 | 113 | case SMS_AUTH: |
114 | do_auth(cl); | |
115 | return; | |
78849033 | 116 | |
117 | case SMS_QUERY: | |
a3cf6921 | 118 | do_retr(cl); |
119 | return; | |
a3cf6921 | 120 | |
3630192b | 121 | case SMS_ACCESS: |
122 | do_access(cl); | |
123 | return; | |
124 | ||
a3cf6921 | 125 | case SMS_SHUTDOWN: |
126 | do_shutdown(cl); | |
127 | return; | |
128 | } | |
129 | } | |
130 | ||
78849033 | 131 | retr_callback(argc, argv, p_cp) |
132 | int argc; | |
133 | char **argv; | |
134 | char *p_cp; | |
135 | { | |
136 | register client *cp = (client *)p_cp; | |
137 | /* XXX MEM when are these freed?? */ | |
138 | /* | |
139 | * This takes too much advantage of the fact that | |
140 | * serialization of the data happens during the queue operation. | |
141 | */ | |
142 | sms_params *arg_tmp = (sms_params *)db_alloc(sizeof(sms_params)); | |
143 | OPERATION op_tmp = create_operation(); | |
78849033 | 144 | |
145 | #ifdef notdef /* We really don't want this logged */ | |
146 | com_err(whoami, 0, "Returning next data:"); | |
147 | log_args(argc, argv); | |
148 | #endif notdef | |
149 | ||
150 | arg_tmp->sms_status = SMS_MORE_DATA; | |
151 | arg_tmp->sms_argc = argc; | |
152 | arg_tmp->sms_argv = argv; | |
153 | arg_tmp->sms_flattened = (char *)NULL; | |
154 | arg_tmp->sms_argl = (int *)NULL; | |
155 | reset_operation(op_tmp); | |
156 | initialize_operation(op_tmp, sms_start_send, (char *)arg_tmp, | |
157 | (int (*)())NULL); | |
158 | queue_operation(cp->con, CON_OUTPUT, op_tmp); | |
159 | } | |
160 | ||
161 | ||
a3cf6921 | 162 | do_retr(cl) |
163 | client *cl; | |
164 | { | |
78849033 | 165 | cl->reply.sms_argc = 0; |
166 | cl->reply.sms_status = 0; | |
c27b3454 | 167 | #ifdef notdef |
78849033 | 168 | if (!cl->clname) { |
169 | com_err(whoami, 0, "Unauthenticated query rejected"); | |
170 | cl->reply.sms_status = EACCES; | |
171 | return; | |
172 | } | |
c27b3454 | 173 | #endif notdef |
78849033 | 174 | com_err(whoami, 0, "Processing query: "); |
175 | log_args(cl->args->sms_argc, cl->args->sms_argv); | |
a3cf6921 | 176 | |
3630192b | 177 | cl->reply.sms_status = |
178 | sms_process_query(cl, | |
179 | cl->args->sms_argv[0], | |
180 | cl->args->sms_argc-1, | |
181 | cl->args->sms_argv+1, | |
182 | retr_callback, | |
183 | (char *)cl); | |
78849033 | 184 | |
185 | com_err(whoami, 0, "Query complete."); | |
a3cf6921 | 186 | } |
78849033 | 187 | |
3630192b | 188 | do_access(cl) |
189 | client *cl; | |
190 | { | |
191 | cl->reply.sms_argc = 0; | |
192 | cl->reply.sms_status = 0; | |
193 | #ifdef notdef | |
194 | if (!cl->clname) { | |
195 | com_err(whoami, 0, "Unauthenticated query rejected"); | |
196 | cl->reply.sms_status = EACCES; | |
197 | return; | |
198 | } | |
199 | #endif notdef | |
200 | com_err(whoami, 0, "Checking access: "); | |
201 | log_args(cl->args->sms_argc, cl->args->sms_argv); | |
202 | ||
203 | cl->reply.sms_status = | |
204 | sms_check_access(cl, | |
205 | cl->args->sms_argv[0], | |
206 | cl->args->sms_argc-1, | |
207 | cl->args->sms_argv+1); | |
208 | ||
209 | com_err(whoami, 0, "Access check complete."); | |
210 | } |