]>
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$ | |
f17535a4 | 9 | * Revision 1.9 1987-08-04 02:41:22 wesommer |
10 | * Clean up messages. | |
a3cf6921 | 11 | * |
f17535a4 | 12 | * Revision 1.8 87/07/16 15:43:19 wesommer |
13 | * Fixed bug where the argv was not copied to private storage | |
14 | * (it got changed out from under us before it got sent..). | |
15 | * | |
28222705 | 16 | * Revision 1.7 87/07/14 00:39:01 wesommer |
17 | * Rearranged loggin. | |
18 | * | |
630e8323 | 19 | * Revision 1.6 87/06/30 20:04:43 wesommer |
20 | * Free returned tuples when possible. | |
21 | * | |
ed31e0d1 | 22 | * Revision 1.5 87/06/26 10:55:53 wesommer |
23 | * Added sms_access, now paiys attention to return code from | |
24 | * sms_process_query, sms_check_access. | |
25 | * | |
3630192b | 26 | * Revision 1.4 87/06/21 16:42:00 wesommer |
27 | * Performance work, rearrangement of include files. | |
28 | * | |
c27b3454 | 29 | * Revision 1.3 87/06/04 01:35:01 wesommer |
30 | * Added a working query request handler. | |
31 | * | |
78849033 | 32 | * Revision 1.2 87/06/03 16:07:50 wesommer |
33 | * Fixes for lint. | |
34 | * | |
5dbd09a0 | 35 | * Revision 1.1 87/06/02 20:07:10 wesommer |
36 | * Initial revision | |
37 | * | |
a3cf6921 | 38 | */ |
39 | ||
40 | #ifndef lint | |
41 | static char *rcsid_sms_scall_c = "$Header$"; | |
42 | #endif lint | |
43 | ||
44 | #include <krb.h> | |
78849033 | 45 | #include <errno.h> |
a3cf6921 | 46 | #include "sms_server.h" |
47 | extern char buf1[]; | |
48 | extern int nclients; | |
49 | extern char *whoami; | |
28222705 | 50 | extern char *malloc(); |
a3cf6921 | 51 | |
52 | extern void clist_delete(), do_auth(), do_shutdown(); | |
53 | void do_call(); | |
54 | ||
55 | /* | |
56 | * Welcome to the (finite state) machine (highest level). | |
57 | */ | |
58 | void | |
59 | do_client(cp) | |
60 | client *cp; | |
61 | { | |
ed31e0d1 | 62 | free_rtn_tuples(cp); |
a3cf6921 | 63 | if (OP_STATUS(cp->pending_op) == OP_CANCELLED) { |
f17535a4 | 64 | com_err(whoami, 0, "Closed connection (now %d client%s)", |
65 | nclients-1, | |
66 | nclients!=2?"s":""); | |
a3cf6921 | 67 | clist_delete(cp); |
68 | return; | |
69 | } | |
70 | switch (cp->action) { | |
71 | case CL_ACCEPT: | |
72 | case CL_SEND: | |
73 | /* Start recieving next request */ | |
74 | initialize_operation(cp->pending_op, sms_start_recv, | |
5dbd09a0 | 75 | (char *)&cp->args, (int (*)())NULL); |
a3cf6921 | 76 | queue_operation(cp->con, CON_INPUT, cp->pending_op); |
77 | cp->action = CL_RECEIVE; | |
78 | break; | |
79 | case CL_RECEIVE: | |
80 | /* Data is here. Process it & start it heading back */ | |
81 | do_call(cp); /* This may block for a while. */ | |
82 | initialize_operation(cp->pending_op, sms_start_send, | |
5dbd09a0 | 83 | (char *)&cp->reply, (int (*)())NULL); |
a3cf6921 | 84 | queue_operation(cp->con, CON_OUTPUT, cp->pending_op); |
85 | cp->action = CL_SEND; | |
86 | break; | |
87 | } | |
88 | } | |
89 | ||
a3cf6921 | 90 | char *procnames[] = { |
91 | "noop", | |
92 | "auth", | |
93 | "shutdown", | |
78849033 | 94 | "query", |
630e8323 | 95 | "access", |
96 | }; | |
97 | ||
a3cf6921 | 98 | |
99 | void | |
100 | do_call(cl) | |
101 | client *cl; | |
102 | { | |
103 | int pn; | |
104 | cl->reply.sms_argc = 0; | |
105 | cl->reply.sms_status = 0; | |
106 | if (((pn = cl->args->sms_procno) < 0) || | |
107 | (pn > SMS_MAX_PROC)) { | |
108 | com_err(whoami, 0, "procno out of range"); | |
109 | cl->reply.sms_status = SMS_UNKNOWN_PROC; | |
110 | return; | |
111 | } | |
630e8323 | 112 | if (log_flags & LOG_ARGS) |
113 | log_args(procnames[pn], cl->args->sms_argc, | |
114 | cl->args->sms_argv); | |
115 | else if (log_flags & LOG_REQUESTS) | |
f17535a4 | 116 | com_err(whoami, 0, "%s", procnames[pn]); |
a3cf6921 | 117 | |
118 | switch(pn) { | |
119 | case SMS_NOOP: | |
120 | cl->reply.sms_status = 0; | |
a3cf6921 | 121 | return; |
3630192b | 122 | |
a3cf6921 | 123 | case SMS_AUTH: |
124 | do_auth(cl); | |
125 | return; | |
78849033 | 126 | |
127 | case SMS_QUERY: | |
a3cf6921 | 128 | do_retr(cl); |
129 | return; | |
a3cf6921 | 130 | |
3630192b | 131 | case SMS_ACCESS: |
132 | do_access(cl); | |
133 | return; | |
134 | ||
a3cf6921 | 135 | case SMS_SHUTDOWN: |
136 | do_shutdown(cl); | |
137 | return; | |
138 | } | |
139 | } | |
140 | ||
ed31e0d1 | 141 | free_rtn_tuples(cp) |
142 | client *cp; | |
143 | { | |
144 | register returned_tuples *temp; | |
145 | for (temp=cp->first; temp && OP_DONE(temp->op); ) { | |
146 | register returned_tuples *t1=temp; | |
147 | temp = t1->next; | |
148 | if (t1 == cp->last) cp->last = NULL; | |
28222705 | 149 | |
ed31e0d1 | 150 | sms_destroy_reply(t1->retval); |
28222705 | 151 | #ifdef notdef |
ed31e0d1 | 152 | if (t1->retval) { |
153 | register sms_params *p = t1->retval; | |
154 | if (p->sms_flattened) | |
155 | free(p->sms_flattened); | |
156 | if (p->sms_argl) | |
157 | free(p->sms_argl); | |
158 | free(p); | |
159 | } | |
28222705 | 160 | #endif notdef |
ed31e0d1 | 161 | delete_operation(t1->op); |
162 | free(t1); | |
163 | } | |
164 | cp->first = temp; | |
165 | } | |
166 | ||
78849033 | 167 | retr_callback(argc, argv, p_cp) |
28222705 | 168 | register int argc; |
169 | register char **argv; | |
78849033 | 170 | char *p_cp; |
171 | { | |
172 | register client *cp = (client *)p_cp; | |
78849033 | 173 | /* |
174 | * This takes too much advantage of the fact that | |
175 | * serialization of the data happens during the queue operation. | |
176 | */ | |
177 | sms_params *arg_tmp = (sms_params *)db_alloc(sizeof(sms_params)); | |
ed31e0d1 | 178 | returned_tuples *tp = (returned_tuples *) |
179 | db_alloc(sizeof(returned_tuples)); | |
28222705 | 180 | register char **nargv = (char **)malloc(argc * sizeof(char *)); |
181 | register int i; | |
ed31e0d1 | 182 | |
78849033 | 183 | OPERATION op_tmp = create_operation(); |
78849033 | 184 | |
630e8323 | 185 | if (log_flags & LOG_RESP) |
186 | log_args("return: ", argc, argv); | |
187 | ||
ed31e0d1 | 188 | tp->op = op_tmp; |
189 | tp->retval = arg_tmp; | |
190 | tp->next = NULL; | |
78849033 | 191 | |
192 | arg_tmp->sms_status = SMS_MORE_DATA; | |
193 | arg_tmp->sms_argc = argc; | |
28222705 | 194 | arg_tmp->sms_argv = nargv; |
195 | for (i = 0; i < argc; i++) { | |
196 | register int len = strlen(argv[i]) + 1; | |
197 | nargv[i] = malloc(len); | |
198 | bcopy(argv[i], nargv[i], len); | |
199 | } | |
78849033 | 200 | arg_tmp->sms_flattened = (char *)NULL; |
201 | arg_tmp->sms_argl = (int *)NULL; | |
ed31e0d1 | 202 | |
203 | if (cp->last) { | |
204 | cp->last->next = tp; | |
205 | cp->last = tp; | |
206 | } else { | |
207 | cp->last = cp->first = tp; | |
208 | } | |
209 | ||
78849033 | 210 | reset_operation(op_tmp); |
211 | initialize_operation(op_tmp, sms_start_send, (char *)arg_tmp, | |
212 | (int (*)())NULL); | |
213 | queue_operation(cp->con, CON_OUTPUT, op_tmp); | |
214 | } | |
215 | ||
216 | ||
a3cf6921 | 217 | do_retr(cl) |
218 | client *cl; | |
219 | { | |
78849033 | 220 | cl->reply.sms_argc = 0; |
221 | cl->reply.sms_status = 0; | |
630e8323 | 222 | |
3630192b | 223 | cl->reply.sms_status = |
224 | sms_process_query(cl, | |
225 | cl->args->sms_argv[0], | |
226 | cl->args->sms_argc-1, | |
227 | cl->args->sms_argv+1, | |
228 | retr_callback, | |
229 | (char *)cl); | |
630e8323 | 230 | if (log_flags & LOG_RES) |
231 | com_err(whoami, 0, "Query complete."); | |
a3cf6921 | 232 | } |
78849033 | 233 | |
3630192b | 234 | do_access(cl) |
235 | client *cl; | |
236 | { | |
237 | cl->reply.sms_argc = 0; | |
630e8323 | 238 | |
3630192b | 239 | cl->reply.sms_status = |
240 | sms_check_access(cl, | |
241 | cl->args->sms_argv[0], | |
242 | cl->args->sms_argc-1, | |
243 | cl->args->sms_argv+1); | |
244 | ||
245 | com_err(whoami, 0, "Access check complete."); | |
246 | } |