]>
Commit | Line | Data |
---|---|---|
05cdd922 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * | |
8 | * $Log$ | |
9fbd2090 | 9 | * Revision 1.11 1987-08-28 14:55:45 mike |
10 | * Modified delete_locker to require only one argument, the login name. | |
11 | * Modified get_groups_of_all_users and get_all_poboxes to disable INGRES | |
12 | * table locking. | |
05cdd922 | 13 | * |
9fbd2090 | 14 | Revision 1.10 87/08/25 15:56:54 mike |
15 | - Fixed bugs in get_groups_of_all_users | |
16 | - Added tblstats updates to add_user_group | |
17 | - Added routines: add_hostaccess (ashi), delete_hostaccess (dshi), | |
18 | followup_ushp, and followup_usha | |
19 | ||
4b890cc4 | 20 | Revision 1.9 87/08/22 17:41:34 wesommer |
21 | More of Mike's changes. | |
22 | ||
a6cb4d4c | 23 | Revision 1.8 87/08/18 15:05:20 wesommer |
24 | Fixed definition of add_locker. | |
25 | ||
92a943d6 | 26 | Revision 1.7 87/08/04 01:49:41 wesommer |
27 | Rearranged messages. | |
28 | ||
b4182127 | 29 | Revision 1.6 87/08/04 01:10:02 wesommer |
30 | Changes by mike; checked in prior to my hacking. | |
31 | ||
c2408bd5 | 32 | Revision 1.5 87/07/30 14:54:13 wesommer |
33 | Added debugging code in an attempt to catch a flakey problem. | |
34 | ||
247969d5 | 35 | Revision 1.4 87/07/30 00:30:21 wesommer |
36 | replaced appends = appends+1 with appends = tbs.appends+1 | |
37 | ||
3b2ceb9a | 38 | Revision 1.3 87/07/30 00:26:11 wesommer |
39 | Changes by mike prior to "appends" fix. | |
40 | ||
30967516 | 41 | Revision 1.2 87/07/29 16:00:39 wesommer |
42 | Fixed add_locker. | |
43 | ||
7195989f | 44 | Revision 1.1 87/07/29 15:13:57 wesommer |
45 | Initial revision | |
46 | ||
05cdd922 | 47 | */ |
48 | ||
49 | #ifndef lint | |
50 | static char *rcsid_qsupport_qc = "$Header$"; | |
51 | #endif lint | |
52 | ||
53 | #include "query.h" | |
54 | #include "sms_server.h" | |
55 | #include <ctype.h> | |
56 | ||
57 | #define SMS_SUCCESS 0 | |
58 | ||
59 | extern char *whoami; | |
60 | ||
61 | /* Specialized Access Routines */ | |
62 | ||
63 | /** | |
64 | ** access_user - verify that client name equals specified login name | |
65 | ** | |
66 | ** Used by: update_user_shell | |
67 | ** update_finger_by_login | |
68 | ** | |
69 | ** - since field validation routines are called first, a users_id is | |
70 | ** now in argv[0] instead of the login name. Therefore, we must | |
71 | ** convert the client name to a users_id. | |
72 | **/ | |
73 | ||
74 | access_user(q, argv, cl) | |
75 | struct query *q; | |
76 | char *argv[]; | |
77 | client *cl; | |
78 | ##{ | |
79 | register struct krbname *krb; | |
80 | ## int client_id; | |
81 | ## char *client_name; | |
82 | ## int rowcount; | |
83 | ||
84 | client_name = cl->kname.name; | |
85 | ## repeat retrieve (client_id = users.users_id) | |
86 | ## where users.login = @client_name | |
87 | ## inquire_equel (rowcount = "rowcount") | |
88 | if (rowcount != 1) return(SMS_PERM); | |
89 | if (client_id != *(int *)argv[0]) return(SMS_PERM); | |
90 | ||
91 | return(SMS_SUCCESS); | |
92 | ##} | |
93 | ||
30967516 | 94 | /** |
95 | ** access_pop - same as access_user plus verifies that a user has only one | |
96 | ** mailbox of type "POP" | |
97 | ** | |
98 | ** Inputs: | |
99 | ** argv[0] - users_id | |
100 | ** argv[1] - type | |
101 | ** argv[2] - mach_id | |
102 | ** argv[3] - box | |
103 | ** | |
104 | ** Description: | |
105 | ** - if q->name = "add_pobox" and type = "POP", | |
106 | ** verify that no POP box already exists for user | |
107 | ** - call access_user | |
108 | ** | |
109 | **/ | |
110 | ||
111 | access_pop(q, argv, cl) | |
112 | struct query *q; | |
113 | char *argv[]; | |
114 | client *cl; | |
115 | ##{ | |
116 | ## int users_id; | |
117 | ## int mach_id; | |
118 | ## char *box; | |
119 | ## int exists; | |
120 | ||
121 | if (!bcmp(q->name, "add_pobox", 10) && !bcmp(argv[1], "POP", 4)) { | |
122 | users_id = *(int *)argv[0]; | |
123 | mach_id = *(int *)argv[2]; | |
124 | box = argv[3]; | |
125 | ## range of p is pobox | |
126 | ## repeat retrieve (exists = any(p.#box where p.#users_id = @users_id | |
127 | ## and p.type = "POP" | |
128 | ## and p.#mach_id = @mach_id | |
129 | ## and p.#box = @box)) | |
130 | if (exists) return(SMS_EXISTS); | |
131 | } | |
132 | ||
133 | return(access_user(q, argv, cl)); | |
134 | ##} | |
135 | ||
05cdd922 | 136 | /** |
137 | ** access_list - check access for adding or deleting list members | |
138 | ** | |
139 | ** Inputs: argv[0] - list_id | |
140 | ** cl->krb.name - client name | |
141 | ** | |
142 | ** - check that client is a member of the access control list | |
143 | ** - OR, if q->shortname == {amtl | dfml} and | |
144 | ** if list.flags & LF_PUBLIC, allow access if client = member | |
145 | ** | |
146 | **/ | |
147 | ||
148 | access_list(q, argv, cl) | |
149 | struct query *q; | |
150 | char *argv[]; | |
151 | client *cl; | |
152 | ##{ | |
153 | ## int list_id; | |
154 | ## int acl_id; | |
155 | ## int flags; | |
156 | int member_id; | |
157 | char *client_type; | |
158 | int client_id; | |
159 | int status; | |
160 | int exists; | |
161 | ||
162 | list_id = *(int *)argv[0]; | |
163 | ## repeat retrieve (acl_id = list.#acl_id, flags = list.#flags) | |
164 | ## where list.#list_id = @list_id | |
165 | ||
166 | /* parse client structure */ | |
167 | status = get_client(cl, &client_type, &client_id); | |
168 | if (status != SMS_SUCCESS) return(status); | |
169 | ||
170 | /* if amtl or dmfl and list is public allow client to add or delete self */ | |
171 | if (!bcmp("amtl", q->shortname, 4) || !bcmp("dmfl", q->shortname, 4)) { | |
172 | if ((flags & LF_PUBLIC) && !bcmp("USER", argv[1], 4)) { | |
173 | member_id = *(int *)argv[2]; | |
174 | if (member_id == client_id) return(SMS_SUCCESS); | |
175 | } | |
176 | } | |
177 | ||
178 | /* check for client in access control list */ | |
179 | exists = find_member(acl_id, client_type, client_id, 0); | |
180 | if (!exists) return(SMS_PERM); | |
181 | ||
182 | return(SMS_SUCCESS); | |
183 | ##} | |
92a943d6 | 184 | |
a6cb4d4c | 185 | /** |
186 | ** access_maillist - access_list + disallow adding user-group to maillists | |
187 | ** | |
188 | ** Inputs: | |
189 | ** argv[0] - list_id | |
190 | ** | |
191 | **/ | |
192 | ||
193 | access_maillist(q, argv, cl) | |
194 | struct query *q; | |
195 | char *argv[]; | |
196 | client *cl; | |
197 | ##{ | |
198 | ## int list_id; | |
199 | ## int exists; | |
200 | ## char list_name[32]; | |
201 | int status; | |
202 | ||
203 | status = access_list(q, argv, cl); | |
204 | if (status != SMS_SUCCESS) return(status); | |
205 | if (bcmp(q->name, "add_maillist", 12)) return(status); | |
206 | ||
207 | list_id = *(int *)argv[0]; | |
208 | ## range of g is groups | |
209 | ## repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id)) | |
210 | if (!exists) return(SMS_SUCCESS); | |
211 | ## repeat retrieve (list_name = list.name) where list.#list_id = @list_id | |
212 | ## repeat retrieve (exists = any(users.login where users.login = @list_name)) | |
213 | return ((exists) ? SMS_USER_GROUP : SMS_SUCCESS); | |
214 | ##} | |
215 | ||
92a943d6 | 216 | /** |
217 | ** Setup routine for add_group | |
218 | ** | |
219 | ** Inputs: none | |
220 | ** | |
221 | ** Description: allocate next gid and store in values table | |
222 | ** | |
223 | **/ | |
224 | ||
225 | setup_add_group(q, argv, cl, access_check) | |
226 | struct query *q; | |
227 | char *argv[]; | |
228 | client *cl; | |
229 | int access_check; | |
230 | ##{ | |
231 | ## int ngid; | |
232 | ## int exists; | |
233 | int status; | |
234 | ||
235 | status = access_list(q, argv, cl); | |
236 | ||
237 | if (status != SMS_SUCCESS || access_check) return(status); | |
238 | ||
239 | ## range of g is groups | |
240 | ## range of v is values | |
241 | ## repeat retrieve (ngid = v.value) where v.name = "gid" | |
242 | exists = 1; | |
243 | while (exists) { | |
244 | ngid++; | |
245 | ## repeat retrieve (exists = any(g.#gid where g.#gid = @ngid)) | |
246 | } | |
247 | ||
248 | ## repeat replace v (value = @ngid) where v.name = "gid" | |
249 | return(SMS_SUCCESS); | |
250 | ##} | |
05cdd922 | 251 | \f |
252 | /** | |
253 | ** Setup routine for add_user | |
254 | ** | |
255 | ** Inputs: argv[0] - login | |
256 | ** argv[1] - uid | |
257 | ** | |
258 | ** Description: | |
259 | ** | |
260 | ** - if argv[1] == "#" then set argv[1] = next(uid) | |
261 | ** - if argv[0] == "#" then set argv[0] = "#<uid>" | |
262 | ** | |
263 | **/ | |
264 | ||
265 | setup_add_user(q, argv, cl, access_check) | |
266 | struct query *q; | |
267 | register char *argv[]; | |
268 | client *cl; | |
269 | int access_check; | |
270 | ##{ | |
271 | ## int nuid; | |
272 | ## int exists; | |
273 | ||
274 | if (access_check) return(SMS_SUCCESS); | |
275 | ||
276 | if (!bcmp(argv[1], "#", 2)) { | |
277 | ## range of u is users | |
278 | ## range of v is values | |
279 | ## repeat retrieve (nuid = v.value) where v.name = "uid" | |
280 | exists = 1; | |
281 | while (exists) { | |
282 | nuid++; | |
283 | ## repeat retrieve (exists = any(u.#uid where u.#uid = @nuid)) | |
284 | } | |
285 | ## repeat replace v (value = @nuid) where v.name = "uid" | |
286 | sprintf(argv[1], "%d", nuid); | |
287 | } | |
288 | ||
289 | if (!bcmp(argv[0], "#", 2)) { | |
290 | sprintf(argv[0], "#%s", argv[1]); | |
291 | } | |
292 | ||
293 | return(SMS_SUCCESS); | |
294 | ##} | |
295 | ||
296 | /** | |
92a943d6 | 297 | ** followup_add_user - add finger entry, set_user_modtime |
298 | ** followup_delete_user - delete finger entry | |
05cdd922 | 299 | ** |
92a943d6 | 300 | ** Inputs: |
301 | ** argv[0] - login (add_user) | |
302 | ** argv[0] - users_id (delete_user) | |
05cdd922 | 303 | ** |
304 | **/ | |
305 | ||
92a943d6 | 306 | followup_add_user(q, argv) |
05cdd922 | 307 | struct query *q; |
308 | char *argv[]; | |
05cdd922 | 309 | ##{ |
92a943d6 | 310 | ## char *login; |
311 | ## int users_id; | |
312 | ## char first[33]; | |
313 | ## char middle[33]; | |
314 | ## char last[33]; | |
315 | ## char fullname[128]; | |
316 | register char *cp1; | |
317 | register char *cp2; | |
05cdd922 | 318 | |
92a943d6 | 319 | login = argv[0]; |
05cdd922 | 320 | |
92a943d6 | 321 | /* get user information */ |
322 | ## range of u is users | |
323 | ## repeat retrieve (users_id = u.#users_id, last = u.#last, | |
324 | ## first = u.#first, middle = u.#middle) | |
325 | ## where u.#login = @login | |
326 | ||
327 | /* build fullname */ | |
328 | cp2 = fullname; | |
329 | cp1 = first; | |
330 | while (*cp1) *cp2++ = *cp1++; | |
331 | *cp2++ = ' '; | |
332 | cp1 = middle; | |
333 | if (*cp1 == 0) cp2--; | |
334 | while (*cp1) *cp2++ = *cp1++; | |
335 | *cp2++ = ' '; | |
336 | cp1 = last; | |
337 | while (*cp2++ = *cp1++) ; | |
338 | ||
339 | /* create a finger entry */ | |
340 | ## repeat append finger (#users_id = @users_id, #fullname = @fullname) | |
341 | ||
342 | /* set modtime (creation time) on user */ | |
343 | ## repeat replace u (modtime = "now") where u.#users_id = @users_id | |
05cdd922 | 344 | |
92a943d6 | 345 | return(SMS_SUCCESS); |
346 | ##} | |
347 | ||
348 | followup_delete_user(q, argv) | |
349 | struct query *q; | |
350 | char *argv[]; | |
351 | ##{ | |
352 | ## int users_id; | |
353 | ||
354 | users_id = *(int *)argv[0]; | |
355 | ## repeat delete finger where finger.#users_id = @users_id | |
05cdd922 | 356 | return(SMS_SUCCESS); |
357 | ##} | |
358 | \f | |
c2408bd5 | 359 | /** |
360 | ** setup_add_filesys - verify existance of referenced file systems | |
361 | ** setup_update_filesys - same, except argv[1..5] --> argv[2..6] | |
362 | ** | |
363 | ** Inputs: Add Update | |
364 | ** argv[0] - label label | |
365 | ** argv[1] - type new label | |
366 | ** argv[2] - mach_id type | |
367 | ** argv[3] - name mach_id | |
368 | ** argv[4] - mount name | |
369 | ** argv[5] - access mount | |
370 | ** argv[6] - access | |
371 | ** | |
372 | ** Description: | |
373 | ** - for type = RVD: | |
374 | ** * verify mach_id/name in rvdvirt | |
375 | ** * verify access in {r, x, R, X} | |
376 | ** - for type = NFS: | |
377 | ** * extract directory prefix from name | |
378 | ** * verify mach_id/dir in nfsphys | |
379 | ** * verify access in {r, w, R, W} | |
380 | ** | |
381 | ** Errors: | |
382 | ** SMS_RVD - no such rvd | |
383 | ** SMS_NFS - specified directory not exported | |
384 | ** SMS_FILESYS_ACCESS - invalid filesys access | |
385 | ** | |
386 | **/ | |
387 | ||
388 | setup_add_filesys(q, argv) | |
389 | struct query *q; | |
390 | char *argv[]; | |
391 | { | |
392 | char *type; | |
393 | int mach_id; | |
394 | char *name; | |
395 | char *access; | |
396 | ||
397 | type = argv[1]; | |
398 | mach_id = *(int *)argv[2]; | |
399 | name = argv[3]; | |
400 | access = argv[5]; | |
401 | ||
402 | if (!bcmp(type, "RVD", 3)) | |
403 | return (check_rvd(mach_id, name, access)); | |
404 | else if (!bcmp(type, "NFS", 3)) | |
405 | return (check_nfs(mach_id, name, access)); | |
406 | else | |
407 | return(SMS_SUCCESS); | |
408 | } | |
409 | ||
410 | setup_update_filesys(q, argv) | |
411 | struct query *q; | |
412 | char *argv[]; | |
413 | { | |
414 | char *type; | |
415 | int mach_id; | |
416 | char *name; | |
417 | char *access; | |
418 | ||
419 | type = argv[2]; | |
420 | mach_id = *(int *)argv[3]; | |
421 | name = argv[4]; | |
422 | access = argv[6]; | |
423 | ||
424 | if (!bcmp(type, "RVD", 3)) | |
425 | return (check_rvd(mach_id, name, access)); | |
426 | else if (!bcmp(type, "NFS", 3)) | |
427 | return (check_nfs(mach_id, name, access)); | |
428 | else | |
429 | return(SMS_SUCCESS); | |
430 | } | |
431 | ||
432 | ##check_rvd(mach_id, name, access) | |
433 | ## int mach_id; | |
434 | ## char *name; | |
435 | char *access; | |
436 | ##{ | |
437 | ## int rowcount; | |
438 | char caccess; | |
439 | ||
440 | ## range of rv is rvdvirt | |
441 | ## retrieve (rowcount = any(rv.#name where rv.#mach_id = mach_id and | |
442 | ## rv.#name = name)) | |
443 | if (rowcount == 0) return(SMS_RVD); | |
444 | ||
445 | caccess = (isupper(*access)) ? tolower(*access) : *access; | |
446 | if (caccess != 'r' && caccess != 'x') return(SMS_FILESYS_ACCESS); | |
447 | ||
448 | return(SMS_SUCCESS); | |
449 | ##} | |
450 | ||
451 | ##check_nfs(mach_id, name, access) | |
452 | ## int mach_id; | |
453 | char *name; | |
454 | char *access; | |
455 | ##{ | |
456 | ## int rowcount; | |
457 | ## char dir[32]; | |
458 | char caccess; | |
459 | register char *cp1; | |
460 | register char *cp2; | |
461 | ||
462 | caccess = (isupper(*access)) ? tolower(*access) : *access; | |
463 | if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS); | |
464 | ||
465 | ## range of np is nfsphys | |
466 | ## retrieve (dir = np.#dir) where np.#mach_id = mach_id | |
467 | ## { | |
468 | cp1 = name; | |
469 | cp2 = dir; | |
470 | while (*cp2) { | |
471 | if (*cp1++ != *cp2) break; | |
472 | cp2++; | |
473 | } | |
474 | if (*cp2 == 0) return(SMS_SUCCESS); | |
475 | ## } | |
476 | ||
477 | return(SMS_NFS); | |
478 | ##} | |
479 | \f | |
05cdd922 | 480 | /* Followup Routines */ |
481 | ||
482 | set_user_modtime(q, argv) | |
483 | struct query *q; | |
484 | char *argv[]; | |
485 | ##{ | |
486 | ## char *login; | |
487 | ||
488 | login = argv[0]; | |
489 | ## repeat replace u (modtime = "now") where u.#login = @login | |
490 | return(SMS_SUCCESS); | |
491 | ##} | |
492 | ||
493 | set_user_modtime_by_id(q, argv) | |
494 | struct query *q; | |
495 | char *argv[]; | |
496 | ##{ | |
497 | ## int users_id; | |
498 | ||
499 | users_id = *(int *)argv[0]; | |
500 | ## repeat replace users (modtime = "now") where users.#users_id = @users_id | |
501 | return(SMS_SUCCESS); | |
502 | ##} | |
503 | ||
504 | set_list_modtime(q, argv) | |
505 | struct query *q; | |
506 | char *argv[]; | |
507 | ##{ | |
508 | ## char *list_name; | |
509 | ||
510 | list_name = argv[0]; | |
511 | ## repeat replace list (modtime = "now") where list.name = @list_name | |
512 | return(SMS_SUCCESS); | |
513 | ##} | |
514 | ||
515 | set_list_modtime_by_id(q, argv) | |
516 | struct query *q; | |
517 | char *argv[]; | |
518 | ##{ | |
519 | ## int list_id; | |
520 | ||
521 | list_id = *(int *)argv[0]; | |
522 | ## repeat replace list (modtime = "now") where list.#list_id = @list_id | |
523 | return(SMS_SUCCESS); | |
524 | ##} | |
525 | ||
526 | set_finger_modtime(q, argv) | |
527 | struct query *q; | |
528 | char *argv[]; | |
529 | ##{ | |
530 | ## int users_id; | |
531 | ||
532 | users_id = *(int *)argv[0]; | |
533 | ## repeat replace f (modtime = "now") where f.#users_id = @users_id | |
534 | return(SMS_SUCCESS); | |
535 | ##} | |
a6cb4d4c | 536 | \f |
537 | /** | |
538 | ** followup_amtl - followup for amtl and dmfl; when adding a list | |
539 | ** member to a maillist, add list to maillist table, | |
540 | ** unless list is a user-group. | |
541 | ** Then set_list_modtime_by_id. | |
542 | ** | |
543 | ** Inputs: | |
544 | ** argv[0] - list_id | |
545 | ** argv[1] - member_type | |
546 | ** argv[2] - member_id | |
547 | ** | |
548 | **/ | |
549 | ||
550 | followup_amtl(q, argv) | |
551 | struct query *q; | |
552 | char *argv[]; | |
553 | ##{ | |
554 | ## int list_id; | |
555 | ## int member_id; | |
556 | ## int exists; | |
557 | ## char list_name[33]; | |
558 | ||
559 | list_id = *(int *)argv[0]; | |
560 | ||
561 | ## repeat replace list (modtime = "now") where list.#list_id = @list_id | |
562 | ||
563 | /* if query is not amtl or if member_type is not LIST then return */ | |
564 | if (bcmp(q->shortname, "amtl", 4) || bcmp(argv[1], "LIST", 4)) | |
565 | return(SMS_SUCCESS); | |
566 | ||
567 | member_id = *(int *)argv[2]; | |
568 | ## range of l is list | |
569 | ## range of ml is maillists | |
570 | ## range of g is groups | |
571 | ||
572 | /* is parent list a mailing list? */ | |
573 | ## repeat retrieve (exists = any(ml.#list_id where ml.#list_id=@list_id)) | |
574 | ||
575 | /* if not then return */ | |
576 | if (!exists) return(SMS_SUCCESS); | |
577 | ||
578 | /* is member_list a user-group? */ | |
579 | /* is it a group? */ | |
580 | ## repeat retrieve (exists = any(g.#list_id where g.#list_id = @member_id)) | |
581 | if (exists) { | |
582 | /* get list_name */ | |
583 | ## repeat retrieve (list_name = l.#name) where l.#list_id = @member_id | |
584 | /* is list_name a username? */ | |
585 | ## repeat retrieve (exists = any(users.login | |
586 | ## where users.login = @list_name)) | |
587 | /* yes, return error */ | |
588 | if (exists) return(SMS_USER_GROUP); | |
589 | } | |
590 | ||
591 | /* list is not a user-group; add list to maillist table */ | |
592 | ## repeat append maillists (#list_id = @member_id, ltid = l.tid) | |
593 | ## where l.#list_id = @member_id | |
594 | ||
595 | return(SMS_SUCCESS); | |
596 | ##} | |
597 | \f | |
598 | /** | |
599 | ** followup_add_pobox | |
600 | ** followup_delete_pobox - followup routines for pobox queries | |
601 | ** | |
602 | ** Description: | |
603 | ** add_pobox: set pobox creation time | |
604 | ** increment pop usage in serverhosts | |
605 | ** | |
606 | ** delete_pobox: decrement pop usage in serverhosts | |
607 | ** | |
608 | **/ | |
609 | ||
610 | followup_add_pobox(q, argv) | |
611 | struct query *q; | |
612 | char *argv[]; | |
613 | { | |
614 | set_pobox_creation(q, argv); | |
615 | set_pop_usage(q, argv, 1); | |
616 | return(SMS_SUCCESS); | |
617 | } | |
618 | ||
619 | followup_delete_pobox(q, argv) | |
620 | struct query *q; | |
621 | char *argv[]; | |
622 | { | |
623 | set_pop_usage(q, argv, -1); | |
624 | return(SMS_SUCCESS); | |
625 | } | |
626 | ||
627 | set_pobox_creation(q, argv) | |
628 | struct query *q; | |
629 | char *argv[]; | |
630 | ##{ | |
631 | ## int users_id; | |
632 | ## int mach_id; | |
633 | ## char *type; | |
634 | ## char *box; | |
635 | ||
636 | users_id = *(int *)argv[0]; | |
637 | type = argv[1]; | |
638 | mach_id = *(int *)argv[2]; | |
639 | box = argv[3]; | |
640 | ||
641 | ## range of p is pobox | |
642 | ## repeat replace p (created = "now") | |
643 | ## where p.#users_id = @users_id and p.#type = @type and | |
644 | ## p.#mach_id = @mach_id and p.#box = @box | |
645 | ||
646 | return (SMS_SUCCESS); | |
647 | ##} | |
05cdd922 | 648 | |
30967516 | 649 | /** |
650 | ** set_pop_usage - incr/decr usage count for pop server in serverhosts talbe | |
651 | ** | |
652 | ** Inputs: | |
653 | ** q->name - "add_pobox" or "delete_pobox" | |
a6cb4d4c | 654 | ** argv[1] - type |
30967516 | 655 | ** argv[2] - mach_id |
656 | ** | |
657 | ** Description: | |
658 | ** - incr/decr value field in serverhosts table for pop/mach_id | |
659 | ** | |
660 | **/ | |
661 | ||
a6cb4d4c | 662 | set_pop_usage(q, argv, count) |
30967516 | 663 | struct query *q; |
664 | char *argv[]; | |
665 | ##{ | |
666 | ## int mach_id; | |
a6cb4d4c | 667 | ## int n; |
668 | ||
669 | if (bcmp(argv[1], "POP", 3)) return(SMS_SUCCESS); | |
30967516 | 670 | |
671 | mach_id = *(int *)argv[2]; | |
a6cb4d4c | 672 | n = count; |
673 | ||
30967516 | 674 | ## range of sh is serverhosts |
a6cb4d4c | 675 | ## repeat replace sh (value1 = sh.value1 + @n) |
676 | ## where sh.service = "pop" and sh.#mach_id = @mach_id | |
30967516 | 677 | |
a6cb4d4c | 678 | return(SMS_SUCCESS); |
679 | ##} | |
680 | ||
681 | /** | |
682 | ** delete_user_poboxes - delete all poboxes for a user | |
683 | ** | |
684 | ** Inputs: | |
685 | ** argv[0] - users_id | |
686 | ** | |
687 | **/ | |
688 | ||
689 | delete_user_poboxes(q, argv) | |
690 | struct query *q; | |
691 | char *argv[]; | |
692 | ##{ | |
693 | ## int users_id; | |
694 | ## int n; | |
695 | ## int mach_id; | |
696 | register int i; | |
697 | int mach_ids[10]; | |
698 | ||
699 | users_id = *(int *)argv[0]; | |
700 | ||
701 | /* get machine ids for pop server(s) on which the user currently exists */ | |
702 | ## range of p is pobox | |
703 | i = 0; | |
704 | ## repeat retrieve (mach_id = p.#mach_id) | |
705 | ## where p.#users_id = @users_id and p.type = "POP" | |
706 | ## { | |
707 | mach_ids[i++] = mach_id; | |
708 | if (i == 10) { | |
709 | ## endretrieve | |
710 | } | |
711 | ## } | |
712 | ||
713 | /* decrement counts on serverhost entries */ | |
714 | ## range of sh is serverhosts | |
715 | while (--i >= 0) { | |
716 | mach_id = mach_ids[i]; | |
30967516 | 717 | ## repeat replace sh (value1 = sh.value1 - 1) |
718 | ## where sh.service = "pop" and sh.#mach_id = @mach_id | |
719 | } | |
720 | ||
a6cb4d4c | 721 | /* delete user's poboxes */ |
722 | ## repeat delete p where p.#users_id = @users_id | |
723 | ||
30967516 | 724 | return(SMS_SUCCESS); |
725 | ##} | |
a6cb4d4c | 726 | |
92a943d6 | 727 | \f |
728 | /** | |
729 | ** add_new_quota | |
730 | ** delete_current_quota - adjust nfsphys values on xxx_quota queries. | |
731 | ** | |
732 | ** Inputs: | |
733 | ** argv[0] - mach_id | |
734 | ** argv[1] - device | |
735 | ** argv[2] - users_id | |
736 | ** argv[3] - quota (add_new_quota only) | |
737 | ** | |
738 | ** Description: | |
739 | ** delete_current_quota: | |
740 | ** - find nfsquota entry | |
741 | ** - decrement nfsphys.allocated by nfsquota.quota | |
742 | ** add_new_quota | |
743 | ** - increment nfsphys.allocated by quota | |
744 | ** | |
745 | **/ | |
746 | ||
747 | add_new_quota(q, argv) | |
748 | struct query *q; | |
749 | register char *argv[]; | |
750 | ##{ | |
751 | ## int mach_id; | |
752 | ## char *device; | |
753 | ## int quota; | |
754 | ||
755 | mach_id = *(int*)argv[0]; | |
756 | device = argv[1]; | |
757 | quota = *(int *)argv[3]; | |
758 | ||
759 | ## range of np is nfsphys | |
760 | ## repeat replace np (allocated = np.allocated + @quota) | |
761 | ## where np.#mach_id = @mach_id and np.#device = @device | |
762 | ||
763 | return(SMS_SUCCESS); | |
764 | ##} | |
30967516 | 765 | |
92a943d6 | 766 | delete_current_quota(q, argv, cl, access_check) |
767 | struct query *q; | |
768 | register char *argv[]; | |
769 | client *cl; | |
770 | int access_check; | |
771 | ##{ | |
772 | ## int mach_id; | |
773 | ## int users_id; | |
774 | ## char *device; | |
775 | ## int quota; | |
776 | ||
777 | if (access_check) return(SMS_SUCCESS); | |
778 | ||
779 | mach_id = *(int *)argv[0]; | |
780 | device = argv[1]; | |
781 | users_id = *(int *)argv[2]; | |
782 | ||
783 | ## range of np is nfsphys | |
784 | ## range of nq is nfsquota | |
785 | ## repeat retrieve (quota = nq.#quota) | |
786 | ## where nq.#mach_id = @mach_id and nq.#device = @device and | |
787 | ## nq.#users_id = @users_id | |
788 | ## repeat replace np (allocated = np.allocated - @quota) | |
789 | ## where np.#mach_id = @mach_id and np.#device = @device | |
790 | ||
791 | return(SMS_SUCCESS); | |
792 | ##} | |
793 | \f | |
4b890cc4 | 794 | /** |
795 | ** add_hostaccess - create entry in hostaccess table upon adding a new | |
796 | ** machine to the serverhosts table where service = | |
797 | ** "hostaccess". | |
798 | ** | |
799 | ** Inputs: | |
800 | ** argv[0] - service | |
801 | ** argv[1] - mach_id | |
802 | ** | |
803 | **/ | |
804 | ||
805 | add_hostaccess(q, argv) | |
806 | struct query *q; | |
807 | char *argv[]; | |
808 | ##{ | |
809 | ## int mach_id; | |
810 | ||
811 | /* only work with service = "hostaccess" */ | |
812 | if (bcmp(argv[0], "hostaccess", 10)) return(SMS_SUCCESS); | |
813 | ||
814 | mach_id = *(int *)argv[1]; | |
815 | ## repeat append hostaccess (#mach_id = @mach_id, status = 0) | |
816 | ## repeat replace tblstats (modtime = "now", appends = tblstats.appends + 1) | |
817 | ## where tblstats.table = "hostaccess" | |
818 | return(SMS_SUCCESS); | |
819 | ##} | |
820 | ||
821 | /* followup to delete_server_host_info */ | |
822 | ||
823 | delete_hostaccess(q, argv) | |
824 | struct query *q; | |
825 | char *argv[]; | |
826 | ##{ | |
827 | ## int mach_id; | |
828 | ||
829 | /* only work with service = "hostaccess" */ | |
830 | if (bcmp(argv[0], "hostaccess", 10)) return(SMS_SUCCESS); | |
831 | ||
832 | mach_id = *(int *)argv[1]; | |
833 | ## repeat delete hostaccess where hostaccess.#mach_id = @mach_id | |
834 | ## repeat replace tblstats (modtime = "now", deletes = tblstats.deletes + 1) | |
835 | ## where tblstats.table = "hostaccess" | |
836 | return(SMS_SUCCESS); | |
837 | ##} | |
838 | ||
839 | followup_ushp(q, argv) | |
840 | struct query *q; | |
841 | char *argv[]; | |
842 | ##{ | |
843 | ## int mach_id; | |
844 | ## int status; | |
845 | ||
846 | mach_id = *(int *)argv[0]; | |
847 | ## range of ha is hostaccess | |
848 | ## repeat retrieve (status = ha.#status) where ha.#mach_id = @mach_id | |
849 | status |= 1; | |
850 | ## repeat replace ha (#status = @status) where ha.#mach_id = @mach_id | |
851 | return(SMS_SUCCESS); | |
852 | ##} | |
853 | ||
854 | followup_usha(q, argv) | |
855 | struct query *q; | |
856 | char *argv[]; | |
857 | ##{ | |
858 | ## int mach_id; | |
859 | ## int status; | |
860 | ||
861 | mach_id = *(int *)argv[0]; | |
862 | ## range of ha is hostaccess | |
863 | ## repeat retrieve (status = ha.#status) where ha.#mach_id = @mach_id | |
864 | status |= 2; | |
865 | ## repeat replace ha (#status = @status) where ha.#mach_id = @mach_id | |
866 | return(SMS_SUCCESS); | |
867 | ##} | |
868 | \f | |
05cdd922 | 869 | /** |
870 | ** delete_list_members - called after the delete_list query to clean up | |
871 | ** members table. | |
872 | ** | |
873 | ** Inputs: argv[0] - list_id | |
874 | ** | |
875 | ** Description: | |
876 | ** - foreach string member: decr string refc; ifzero, delete string | |
877 | ** - delete all members entries for this list_id | |
878 | ** | |
879 | **/ | |
880 | ||
881 | delete_list_members(q, argv) | |
882 | struct query *q; | |
883 | register char *argv[]; | |
884 | ##{ | |
885 | ## int list_id; | |
886 | ## int string_id; | |
887 | ## int refc; | |
888 | ## int rowcount; | |
889 | struct save_queue *sq; | |
890 | struct save_queue *sq_create(); | |
891 | ||
892 | list_id = *(int *)argv[0]; | |
893 | sq = sq_create(); | |
894 | ||
895 | ## range of m is members | |
896 | ## repeat retrieve (string_id = m.member_id) | |
897 | ## where m.#list_id = @list_id and m.member_type = "STRING" | |
898 | ## { | |
899 | sq_save_data(sq, string_id); | |
900 | ## } | |
901 | ||
902 | while (sq_get_data(sq, &string_id)) { | |
903 | ## range of s is strings | |
904 | ## repeat retrieve (refc = s.#refc) where s.#string_id = @string_id | |
905 | ## inquire_equel (rowcount = "rowcount") | |
906 | if (rowcount == 0) continue; | |
907 | if (--refc == 0) { | |
908 | ## repeat delete s where s.#string_id = @string_id | |
909 | } else { | |
910 | ## repeat replace s (#refc = @refc) where s.#string_id = @string_id | |
911 | } | |
912 | } | |
913 | sq_destroy(sq); | |
914 | ||
915 | ## repeat delete m where m.#list_id = @list_id | |
916 | ||
917 | return(SMS_SUCCESS); | |
918 | ##} | |
92a943d6 | 919 | \f |
05cdd922 | 920 | /** |
4b890cc4 | 921 | ** followup_grvd - Support routine for get_rvd_servers query |
05cdd922 | 922 | ** |
923 | ** Inputs: | |
924 | ** q - grvd query structure | |
925 | ** sq - save_queue struture: contains list of {machine, oper_acl_id, | |
926 | ** admin_acl_id, shutdown_acl_id} records. | |
927 | ** v - validate structure (not used) | |
928 | ** action - action routine | |
929 | ** actarg - action routine argument | |
930 | ** | |
931 | ** Description: | |
932 | ** - translate acl_ids to list names | |
933 | ** | |
934 | **/ | |
935 | ||
4b890cc4 | 936 | followup_grvd(q, sq, v, action, actarg) |
05cdd922 | 937 | struct query *q; |
938 | struct save_queue *sq; | |
939 | struct validate *v; | |
940 | int (*action)(); | |
941 | int actarg; | |
942 | ##{ | |
943 | char **argv; | |
944 | char *targv[4]; | |
945 | ## char oper[33]; | |
946 | ## char admin[33]; | |
947 | ## char shutdown[33]; | |
948 | ## int list_id; | |
949 | ||
30967516 | 950 | targv[0] = oper; |
951 | targv[1] = admin; | |
952 | targv[2] = shutdown; | |
05cdd922 | 953 | |
954 | ## range of l is list | |
955 | ||
956 | while (sq_get_data(sq, &argv)) { | |
30967516 | 957 | sscanf(argv[0], "%d", &list_id); |
05cdd922 | 958 | ## repeat retrieve (oper = l.name) where l.#list_id = @list_id |
30967516 | 959 | sscanf(argv[1], "%d", &list_id); |
05cdd922 | 960 | ## repeat retrieve (admin = l.name) where l.#list_id = @list_id |
30967516 | 961 | sscanf(argv[2], "%d", &list_id); |
05cdd922 | 962 | ## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id |
963 | ||
30967516 | 964 | (*action)(3, targv, actarg); |
05cdd922 | 965 | free(argv[0]); |
966 | free(argv[1]); | |
967 | free(argv[2]); | |
05cdd922 | 968 | } |
969 | ||
970 | sq_destroy(sq); | |
971 | return(SMS_SUCCESS); | |
972 | ##} | |
973 | ||
4b890cc4 | 974 | followup_gars(q, sq, v, action, actarg) |
92a943d6 | 975 | struct query *q; |
976 | struct save_queue *sq; | |
977 | struct validate *v; | |
978 | int (*action)(); | |
979 | int actarg; | |
980 | ##{ | |
981 | char **argv; | |
982 | char *targv[4]; | |
983 | ## char oper[33]; | |
984 | ## char admin[33]; | |
985 | ## char shutdown[33]; | |
986 | ## int list_id; | |
987 | ||
988 | targv[1] = oper; | |
989 | targv[2] = admin; | |
990 | targv[3] = shutdown; | |
991 | ||
992 | ## range of l is list | |
993 | ||
994 | while (sq_get_data(sq, &argv)) { | |
995 | sscanf(argv[1], "%d", &list_id); | |
996 | ## repeat retrieve (oper = l.name) where l.#list_id = @list_id | |
997 | sscanf(argv[2], "%d", &list_id); | |
998 | ## repeat retrieve (admin = l.name) where l.#list_id = @list_id | |
999 | sscanf(argv[3], "%d", &list_id); | |
1000 | ## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id | |
1001 | ||
1002 | targv[0] = argv[0]; | |
1003 | (*action)(4, targv, actarg); | |
1004 | free(argv[0]); | |
1005 | free(argv[1]); | |
1006 | free(argv[2]); | |
1007 | free(argv[3]); | |
1008 | } | |
1009 | ||
1010 | sq_destroy(sq); | |
1011 | return(SMS_SUCCESS); | |
1012 | ##} | |
1013 | \f | |
05cdd922 | 1014 | /** |
1015 | ** set_next_object_id - set next object id in values table | |
1016 | ** | |
1017 | ** Inputs: object - object name in values table | |
1018 | ** | |
1019 | ** - called before an APPEND operation to set the next object id to | |
1020 | ** be used for the new record | |
1021 | ** | |
1022 | **/ | |
1023 | ||
1024 | set_next_object_id(object) | |
1025 | char *object; | |
1026 | ##{ | |
1027 | ## char *name; | |
05cdd922 | 1028 | |
1029 | name = object; | |
1030 | ## range of v is values | |
30967516 | 1031 | ## repeat replace v (value = v.value + 1) where v.#name = @name |
1032 | return(SMS_SUCCESS); | |
1033 | ##} | |
1034 | ||
1035 | /** | |
1036 | ** get_query_need - check modtime of query's associated table against given | |
1037 | ** time and return true if greater (false if not) | |
1038 | ** | |
1039 | ** Inputs: | |
1040 | ** argv[0] - query name | |
1041 | ** argv[1] - time to compare against | |
1042 | ** | |
1043 | **/ | |
1044 | ||
1045 | get_query_need(q, argv, action, actarg) | |
1046 | struct query *q; | |
1047 | register char *argv[]; | |
1048 | int (*action)(); | |
1049 | ##{ | |
1050 | struct query *q1; | |
1051 | ## char *last_get_time; | |
1052 | ## char *table; | |
1053 | ## int need; | |
1054 | char *result; | |
1055 | struct query *get_query_by_name(); | |
1056 | ||
1057 | q1 = get_query_by_name(argv[0]); | |
1058 | ||
1059 | last_get_time = argv[1]; | |
1060 | table = q1->rtable; | |
1061 | ||
92a943d6 | 1062 | if (q1->type != RETRIEVE) return(SMS_NO_MATCH); |
30967516 | 1063 | |
1064 | ## range of tbs is tblstats | |
1065 | ## repeat retrieve (need = any(tbs.modtime where tbs.#table = @table and | |
1066 | ## tbs.modtime > @last_get_time)) | |
1067 | ||
1068 | result = (need) ? "true" : "false"; | |
1069 | (*action)(1, &result, actarg); | |
05cdd922 | 1070 | return(SMS_SUCCESS); |
1071 | ##} | |
1072 | ||
92a943d6 | 1073 | /** |
1074 | ** get_list_is_group | |
1075 | ** get_list_is_maillist | |
1076 | ** | |
1077 | ** Inputs: | |
1078 | ** argv[0] - list_id | |
1079 | ** | |
1080 | ** Returns: | |
1081 | ** {true | false} | |
1082 | ** | |
1083 | **/ | |
1084 | ||
1085 | get_list_is_group(q, argv, action, actarg) | |
1086 | struct query *q; | |
1087 | char *argv[]; | |
1088 | int (*action)(); | |
1089 | int actarg; | |
1090 | ##{ | |
1091 | ## int exists; | |
1092 | ## int list_id; | |
1093 | char *result; | |
1094 | ||
1095 | list_id = *(int *)argv[0]; | |
1096 | ||
1097 | ## range of g is groups | |
1098 | ## repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id)) | |
1099 | ||
1100 | result = (exists) ? "true" : "false"; | |
1101 | (*action)(1, &result, actarg); | |
1102 | return(SMS_SUCCESS); | |
1103 | ##} | |
1104 | ||
1105 | get_list_is_maillist(q, argv, action, actarg) | |
1106 | struct query *q; | |
1107 | char *argv[]; | |
1108 | int (*action)(); | |
1109 | int actarg; | |
1110 | ##{ | |
1111 | ## int exists; | |
1112 | ## int list_id; | |
1113 | char *result; | |
1114 | ||
1115 | list_id = *(int *)argv[0]; | |
1116 | ||
1117 | ## range of ml is maillists | |
1118 | ## repeat retrieve (exists = any(ml.#list_id where ml.#list_id = @list_id)) | |
1119 | ||
1120 | result = (exists) ? "true" : "false"; | |
1121 | (*action)(1, &result, actarg); | |
1122 | return(SMS_SUCCESS); | |
1123 | ##} | |
1124 | ||
05cdd922 | 1125 | \f |
1126 | /** | |
1127 | ** add_locker - special query routine for creating a user locker | |
1128 | ** | |
1129 | ** Inputs: | |
1130 | ** argv[0] - users_id | |
1131 | ** argv[1] - machine_id | |
1132 | ** argv[2] - device | |
1133 | ** argv[3] - initial quota | |
1134 | ** | |
1135 | ** Description: | |
1136 | ** - get prefix directory (dir) for mount point on specified machine/device | |
1137 | ** - create filesys entry (label=<login>, type=NFS, machine=<machine>, | |
1138 | ** mount=<dir>/<login>, access=w, acl=dbadmin) | |
1139 | ** - increment allocated in nfsphys by quota | |
1140 | ** - create nfsquota entry | |
1141 | ** | |
1142 | ** Errors: | |
1143 | ** - SMS_NFSPHYS - machine/device does not exist in nfsphys | |
1144 | ** - SMS_FILESYS_EXISTS - file system already exists | |
1145 | ** | |
1146 | **/ | |
1147 | ||
1148 | add_locker(q, argv) | |
1149 | register struct query *q; | |
1150 | char *argv[]; | |
1151 | ##{ | |
1152 | ## int users_id; | |
1153 | ## int mach_id; | |
1154 | ## char *device; | |
1155 | ## int quota; | |
1156 | ## int rowcount; | |
30967516 | 1157 | ## char login[9]; |
05cdd922 | 1158 | ## char dir[32]; |
1159 | ## int allocated; | |
1160 | ## char locker[64]; | |
1161 | ## char mount[64]; | |
1162 | ## int user_acl; | |
1163 | ||
1164 | /* copy arguments */ | |
1165 | users_id = *(int *)argv[0]; | |
1166 | mach_id = *(int *)argv[1]; | |
1167 | device = argv[2]; | |
1168 | sscanf(argv[3], "%d", "a); | |
1169 | ||
1170 | ## range of u is users | |
1171 | ## range of f is filesys | |
1172 | ## range of np is nfsphys | |
30967516 | 1173 | ## range of tbs is tblstats |
05cdd922 | 1174 | |
1175 | /* get login name */ | |
1176 | ## repeat retrieve (login = u.#login) where u.#users_id = @users_id | |
1177 | ||
1178 | /* get user's acl id */ | |
1179 | ## repeat retrieve (user_acl = list.list_id) where list.name = @login | |
1180 | ||
1181 | /* get filesystem directory prefix; give error if machine/device | |
1182 | pair not in nfsphys table */ | |
247969d5 | 1183 | printf("np.mach_id = %d and np.device = %s\n", mach_id, device); |
1184 | ||
05cdd922 | 1185 | ## repeat retrieve (dir = np.#dir, allocated = np.#allocated) |
92a943d6 | 1186 | ## where np.#mach_id = @mach_id and np.#device = @device |
05cdd922 | 1187 | ## inquire_equel (rowcount = "rowcount") |
1188 | if (rowcount == 0) return(SMS_NFSPHYS); | |
1189 | ||
1190 | /* make sure a filesys with user's name does not already exist */ | |
1191 | ## repeat retrieve (rowcount = any(f.label where f.label = @login)) | |
1192 | if (rowcount != 0) return(SMS_FILESYS_EXISTS); | |
1193 | ||
1194 | /* create a new filesys */ | |
1195 | sprintf(locker, "%s/%s", dir, login); | |
1196 | sprintf(mount, "/mit/%s", login); | |
1197 | ## repeat append filesys | |
7195989f | 1198 | ## (#label = @login, type = "NFS", #mach_id = @mach_id, |
05cdd922 | 1199 | ## name = @locker, access = "w", order = 1, #mount = @mount, |
1200 | ## acl_id = @user_acl) | |
30967516 | 1201 | ## repeat replace tbs (appends = tbs.appends + 1, modtime = "now") |
1202 | ## where tbs.table = "filesys" | |
05cdd922 | 1203 | |
1204 | /* increment usage count in nfsphys table */ | |
1205 | allocated += quota; | |
1206 | ## replace np (#allocated = allocated) | |
1207 | ## where np.#mach_id = mach_id and np.#device = device | |
30967516 | 1208 | ## repeat replace tbs (updates = tbs.updates + 1, modtime = "now") |
1209 | ## where tbs.table = "nfsphys" | |
05cdd922 | 1210 | |
1211 | /* create nfsquota entry */ | |
1212 | ## append nfsquota (#users_id = users_id, #mach_id = mach_id, | |
7195989f | 1213 | ## #device = device, #quota = quota) |
3b2ceb9a | 1214 | ## repeat replace tbs (appends = tbs.appends + 1, modtime = "now") |
30967516 | 1215 | ## where tbs.table = "nfsquota" |
1216 | ||
1217 | return(SMS_SUCCESS); | |
1218 | ##} | |
1219 | ||
1220 | /** | |
1221 | ** delete_locker - special query routine for deleting a user locker | |
1222 | ** | |
1223 | ** Inputs: | |
1224 | ** argv[0] - users_id | |
30967516 | 1225 | ** |
1226 | ** Description: | |
9fbd2090 | 1227 | ** - get login name from users_id |
1228 | ** - get filesys entry from login | |
1229 | ** - use filesys.mach_id and filesys.name to determine machine/device | |
1230 | ** pair for nfsphys and nfsquota | |
30967516 | 1231 | ** - delete filesys entry (label=<login>) |
1232 | ** - decrement allocated in nfsphys by quota | |
1233 | ** - delete nfsquota entry | |
1234 | ** | |
1235 | ** Errors: | |
1236 | ** - SMS_FILESYS - no filesys exists for user | |
1237 | ** | |
1238 | **/ | |
1239 | ||
1240 | delete_locker(q, argv) | |
1241 | register struct query *q; | |
1242 | register char *argv[]; | |
1243 | ##{ | |
1244 | ## int users_id; | |
1245 | ## int mach_id; | |
30967516 | 1246 | ## int quota; |
1247 | ## int rowcount; | |
1248 | ## char login[9]; | |
9fbd2090 | 1249 | ## char lname[64]; |
1250 | ## char ndev[32]; | |
1251 | register char *c; | |
30967516 | 1252 | |
1253 | /* copy arguments */ | |
1254 | users_id = *(int *)argv[0]; | |
30967516 | 1255 | |
1256 | ## range of u is users | |
1257 | ## range of f is filesys | |
1258 | ## range of np is nfsphys | |
1259 | ## range of nq is nfsquota | |
1260 | ## range of tbs is tblstats | |
1261 | ||
1262 | /* get login name */ | |
1263 | ## repeat retrieve (login = u.#login) where u.#users_id = @users_id | |
1264 | ||
9fbd2090 | 1265 | /* get mach_id and locker name from filesys entry; then delete it */ |
1266 | ## repeat retrieve (mach_id = f.#mach_id, lname = f.#name) | |
1267 | ## where f.#label = @login | |
30967516 | 1268 | ## inquire_equel (rowcount = "rowcount") |
1269 | if (rowcount == 0) return(SMS_FILESYS); | |
9fbd2090 | 1270 | ## repeat delete f where f.#label = @login |
1271 | ||
1272 | /* get prefix directory */ | |
1273 | c = (char *)rindex(lname, '/'); | |
1274 | *c = 0; | |
1275 | ||
1276 | /* get nfs device */ | |
1277 | ## repeat retrieve (ndev = np.device) | |
1278 | ## where np.#mach_id = @mach_id and np.dir = @lname | |
1279 | ||
1280 | /* get quota from nfsquota entry; then delete entry */ | |
1281 | ## repeat retrieve (quota = nq.#quota) | |
1282 | ## where nq.#mach_id = @mach_id and nq.#device = @ndev and | |
1283 | ## nq.#users_id = @users_id | |
1284 | ## repeat delete nq where nq.#mach_id = @mach_id and nq.#device = @ndev and | |
1285 | ## nq.#users_id = @users_id | |
1286 | ||
1287 | /* decrement nfsphys.allocated */ | |
1288 | ## repeat replace np (allocated = np.allocated - @quota) | |
1289 | ## where np.#mach_id = @mach_id and np.#device = @ndev | |
1290 | ||
1291 | /* adjust table statistics */ | |
30967516 | 1292 | ## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now") |
1293 | ## where tbs.table = "filesys" | |
30967516 | 1294 | ## repeat replace tbs (updates = tbs.updates + 1, modtime = "now") |
1295 | ## where tbs.table = "nfsphys" | |
30967516 | 1296 | ## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now") |
1297 | ## where tbs.table = "nfsquota" | |
05cdd922 | 1298 | |
1299 | return(SMS_SUCCESS); | |
1300 | ##} | |
92a943d6 | 1301 | \f |
1302 | /** | |
1303 | ** add_user_group - create a group for a user and add user to group | |
1304 | ** | |
1305 | ** Inputs: | |
1306 | ** argv[0] - login | |
1307 | ** | |
1308 | ** Description: | |
1309 | ** - verify specified user exists | |
1310 | ** - create a list of same name as user | |
1311 | ** - add user as a member of the list | |
1312 | ** | |
1313 | **/ | |
1314 | ||
1315 | add_user_group(q, argv) | |
1316 | struct query *q; | |
1317 | char *argv[]; | |
1318 | ##{ | |
1319 | ## char *login; | |
1320 | ## int exists; | |
1321 | ## int users_id; | |
1322 | ## int list_id; | |
1323 | ## int gid; | |
1324 | ||
1325 | login = argv[0]; | |
1326 | ||
1327 | /* verify user exists */ | |
1328 | ## repeat retrieve (users_id = users.#users_id) where users.#login = @login | |
1329 | ## inquire_equel (exists = "rowcount") | |
1330 | if (exists != 1) return(SMS_USER); | |
1331 | ||
1332 | /* verify list does not exist */ | |
1333 | ## repeat retrieve (exists = any(list.name where list.name = @login)) | |
1334 | if (exists) return(SMS_LIST); | |
1335 | ||
1336 | /* get new list_id */ | |
1337 | ## repeat retrieve (list_id = values.value) where values.name = "list_id" | |
1338 | list_id++; | |
1339 | ## repeat replace values (value = @list_id) where values.name = "list_id" | |
1340 | ||
1341 | /* create the list */ | |
4b890cc4 | 1342 | ## range of tbs is tblstats |
92a943d6 | 1343 | ## repeat append list (name = @login, #list_id = @list_id, flags = 1, |
1344 | ## desc = "User Group", acl_id = @list_id, | |
1345 | ## expdate = "today" + "5 years", modtime = "now") | |
4b890cc4 | 1346 | ## repeat replace tbs (modtime = "now", appends = tbs.appends + 1) |
1347 | ## where tbs.table = "list" | |
92a943d6 | 1348 | |
1349 | /* add user to list */ | |
1350 | ## repeat append members (#list_id = @list_id, member_type = "USER", | |
1351 | ## member_id = @users_id) | |
4b890cc4 | 1352 | ## repeat replace tbs (modtime = "now", appends = tbs.appends + 1) |
1353 | ## where tbs.table = "members" | |
92a943d6 | 1354 | |
1355 | /* get new gid */ | |
1356 | ## range of g is groups | |
1357 | ## range of v is values | |
1358 | ## repeat retrieve (gid = v.value) where v.name = "gid" | |
1359 | exists = 1; | |
1360 | while (exists) { | |
1361 | gid++; | |
1362 | ## repeat retrieve (exists = any(g.#gid where g.#gid = @gid)) | |
1363 | } | |
1364 | ## repeat replace v (value = @gid) where v.name = "gid" | |
1365 | ||
1366 | /* add list to group table */ | |
1367 | ## repeat append groups (#list_id = @list_id, ltid = list.tid, #gid = @gid) | |
1368 | ## where list.#list_id = @list_id | |
4b890cc4 | 1369 | ## repeat replace tbs (modtime = "now", appends = tbs.appends + 1) |
1370 | ## where tbs.table = "members" | |
92a943d6 | 1371 | |
1372 | /* and we're done */ | |
1373 | return(SMS_SUCCESS); | |
1374 | ##} | |
1375 | ||
05cdd922 | 1376 | \f |
c2408bd5 | 1377 | /** |
1378 | ** get_members_of_list - optimized query for retrieval of list members | |
1379 | ** | |
1380 | ** Inputs: | |
1381 | ** argv[0] - list_id | |
1382 | ** | |
1383 | ** Description: | |
1384 | ** - retrieve USER members, then LIST members, then STRING members | |
1385 | ** | |
1386 | **/ | |
1387 | ||
1388 | get_members_of_list(q, argv, action, actarg) | |
1389 | struct query *q; | |
1390 | char *argv[]; | |
1391 | int (*action)(); | |
1392 | int actarg; | |
1393 | ##{ | |
1394 | ## int list_id; | |
1395 | ## char member_name[129]; | |
1396 | char *targv[2]; | |
1397 | ||
1398 | list_id = *(int *)argv[0]; | |
1399 | targv[0] = "USER"; | |
1400 | targv[1] = member_name; | |
1401 | ||
1402 | ## range of m is members | |
1403 | ## repeat retrieve (member_name = users.login) | |
1404 | ## where m.#list_id = @list_id and m.member_type = "USER" | |
1405 | ## and m.member_id = users.users_id | |
92a943d6 | 1406 | ## sort by #member_name |
c2408bd5 | 1407 | ## { |
1408 | (*action)(2, targv, actarg); | |
1409 | ## } | |
1410 | ||
1411 | targv[0] = "LIST"; | |
1412 | ## repeat retrieve (member_name = list.name) | |
1413 | ## where m.#list_id = @list_id and m.member_type = "LIST" | |
1414 | ## and m.member_id = list.#list_id | |
92a943d6 | 1415 | ## sort by #member_name |
c2408bd5 | 1416 | ## { |
1417 | (*action)(2, targv, actarg); | |
1418 | ## } | |
1419 | ||
1420 | targv[0] = "STRING"; | |
1421 | ## repeat retrieve (member_name = strings.string) | |
1422 | ## where m.#list_id = @list_id and m.member_type = "STRING" | |
1423 | ## and m.member_id = strings.string_id | |
92a943d6 | 1424 | ## sort by #member_name |
c2408bd5 | 1425 | ## { |
1426 | (*action)(2, targv, actarg); | |
1427 | ## } | |
1428 | ||
1429 | return(SMS_SUCCESS); | |
1430 | ##} | |
1431 | ||
1432 | /** | |
92a943d6 | 1433 | ** get_groups_of_user - optimized query for retrieval of all groups to |
1434 | ** which a user belongs | |
1435 | ** | |
1436 | **/ | |
1437 | ||
1438 | get_groups_of_user(q, argv, action, actarg) | |
1439 | struct query *q; | |
1440 | char *argv[]; | |
1441 | int (*action)(); | |
1442 | int actarg; | |
1443 | ##{ | |
1444 | ## int users_id; | |
1445 | ## char list_name[33]; | |
1446 | ## char gid[11]; | |
1447 | ## int rowcount; | |
1448 | char *targv[2]; | |
1449 | ||
1450 | users_id = *(int *)argv[0]; | |
1451 | targv[0] = list_name; | |
1452 | targv[1] = gid; | |
1453 | ||
1454 | ## range of m is members | |
1455 | ||
1456 | ## repeat retrieve (list_name = list.name, gid = text(groups.#gid)) | |
1457 | ## where m.member_id = @users_id and m.member_type = "USER" and | |
1458 | ## m.list_id = groups.list_id and groups.ltid = list.tid | |
1459 | ## sort by #list_name | |
1460 | ## { | |
1461 | (*action)(2, targv, actarg); | |
1462 | ## } | |
1463 | ## inquire_equel (rowcount = "rowcount") | |
1464 | ||
1465 | return ((rowcount = 0) ? SMS_NO_MATCH : SMS_SUCCESS); | |
1466 | ##} | |
a6cb4d4c | 1467 | |
1468 | get_groups_of_all_users(q, argv, action, actarg) | |
1469 | struct query *q; | |
1470 | char *argv[]; | |
1471 | int (*action)(); | |
1472 | int actarg; | |
1473 | ##{ | |
1474 | ## char login[9]; | |
1475 | ## char group[33]; | |
1476 | ## char gid[11]; | |
4b890cc4 | 1477 | char *targv[3]; |
a6cb4d4c | 1478 | ## int errorno; |
1479 | ||
4b890cc4 | 1480 | targv[0] = login; |
1481 | targv[1] = group; | |
1482 | targv[2] = gid; | |
1483 | ||
a6cb4d4c | 1484 | ## range of u is users |
1485 | ## range of l is list | |
1486 | ## range of m is members | |
1487 | ## range of g is groups | |
1488 | ||
9fbd2090 | 1489 | ## set lockmode session where readlock = nolock |
1490 | ||
4b890cc4 | 1491 | ## repeat retrieve (login = u.#login, group = l.name, gid = text(g.#gid)) |
a6cb4d4c | 1492 | ## where m.member_type = "USER" and m.member_id = u.users_id and |
1493 | ## u.status != 0 and m.list_id = g.list_id and | |
1494 | ## g.ltid = l.tid | |
1495 | ## sort by #login, #group | |
4b890cc4 | 1496 | ## { |
1497 | (*action)(3, targv, actarg); | |
1498 | ## } | |
a6cb4d4c | 1499 | |
1500 | ## inquire_equel (errorno = "errorno") | |
9fbd2090 | 1501 | ## set lockmode session where readlock = system |
a6cb4d4c | 1502 | |
1503 | return((errorno) ? SMS_INGRES_ERR : SMS_SUCCESS); | |
1504 | ##} | |
92a943d6 | 1505 | \f |
1506 | /** | |
1507 | ** get_all_poboxes - optimized query for retrieval of all poboxes | |
c2408bd5 | 1508 | ** |
1509 | ** Description: | |
1510 | ** - retrieve LOCAL boxes, then POP boxes, then FOREIGN boxes | |
1511 | ** | |
1512 | **/ | |
1513 | ||
1514 | get_all_poboxes(q, argv, action, actarg) | |
1515 | struct query *q; | |
1516 | char *argv[]; | |
1517 | int (*action)(); | |
1518 | int actarg; | |
1519 | ##{ | |
1520 | ## char login[9]; | |
1521 | ## char machine[129]; | |
1522 | ## char box[129]; | |
1523 | char *targv[4]; | |
1524 | ||
1525 | targv[0] = login; | |
1526 | targv[2] = machine; | |
1527 | targv[3] = box; | |
1528 | ||
1529 | targv[1] = "LOCAL"; | |
9fbd2090 | 1530 | |
1531 | ## set lockmode session where readlock = nolock | |
c2408bd5 | 1532 | ## range of p is pobox |
1533 | ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box) | |
1534 | ## where p.type = "LOCAL" and p.users_id = users.users_id | |
1535 | ## and p.mach_id = #machine.mach_id | |
1536 | ## { | |
1537 | (*action)(4, targv, actarg); | |
1538 | ## } | |
1539 | ||
1540 | targv[1] = "POP"; | |
1541 | ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box) | |
1542 | ## where p.type = "POP" and p.users_id = users.users_id | |
1543 | ## and p.mach_id = #machine.mach_id | |
1544 | ## { | |
1545 | (*action)(4, targv, actarg); | |
1546 | ## } | |
1547 | ||
1548 | targv[1] = "FOREIGN"; | |
1549 | ## repeat retrieve (login=users.#login, machine=strings.string, box=p.#box) | |
1550 | ## where p.type = "FOREIGN" and p.users_id = users.users_id | |
1551 | ## and p.mach_id = strings.string_id | |
1552 | ## { | |
1553 | (*action)(4, targv, actarg); | |
1554 | ## } | |
9fbd2090 | 1555 | ## set lockmode session where readlock = system |
c2408bd5 | 1556 | |
1557 | return(SMS_SUCCESS); | |
1558 | ##} | |
a6cb4d4c | 1559 | |
1560 | get_new_poboxes(q, argv, action, actarg) | |
1561 | struct query *q; | |
1562 | char *argv[]; | |
1563 | int (*action)(); | |
1564 | int actarg; | |
1565 | ##{ | |
1566 | ## char *created; | |
1567 | ## char login[9]; | |
1568 | ## char machine[129]; | |
1569 | ## char box[129]; | |
1570 | char *targv[4]; | |
1571 | ||
1572 | created = argv[0]; | |
1573 | ||
1574 | targv[0] = login; | |
1575 | targv[2] = machine; | |
1576 | targv[3] = box; | |
1577 | ||
1578 | targv[1] = "LOCAL"; | |
1579 | ## range of p is pobox | |
1580 | ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box) | |
1581 | ## where p.type = "LOCAL" and p.users_id = users.users_id | |
1582 | ## and p.mach_id = #machine.mach_id and | |
1583 | ## p.#created > @created | |
1584 | ## { | |
1585 | (*action)(4, targv, actarg); | |
1586 | ## } | |
1587 | ||
1588 | targv[1] = "POP"; | |
1589 | ## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box) | |
1590 | ## where p.type = "POP" and p.users_id = users.users_id | |
1591 | ## and p.mach_id = #machine.mach_id and | |
1592 | ## p.#created > @created | |
1593 | ## { | |
1594 | (*action)(4, targv, actarg); | |
1595 | ## } | |
1596 | ||
1597 | targv[1] = "FOREIGN"; | |
1598 | ## repeat retrieve (login=users.#login, machine=strings.string, box=p.#box) | |
1599 | ## where p.type = "FOREIGN" and p.users_id = users.users_id | |
1600 | ## and p.mach_id = strings.string_id and | |
1601 | ## p.#created > @created | |
1602 | ## { | |
1603 | (*action)(4, targv, actarg); | |
1604 | ## } | |
1605 | ||
1606 | return(SMS_SUCCESS); | |
1607 | ##} | |
c2408bd5 | 1608 | \f |
05cdd922 | 1609 | /* Validation Routines */ |
1610 | ||
1611 | validate_row(q, argv, v) | |
1612 | register struct query *q; | |
1613 | char *argv[]; | |
1614 | register struct validate *v; | |
1615 | ##{ | |
1616 | ## char *rvar; | |
1617 | ## char *table; | |
1618 | ## char *name; | |
1619 | ## char qual[128]; | |
1620 | ## int rowcount; | |
1621 | ||
1622 | /* build where clause */ | |
1623 | build_qual(v->qual, v->argc, argv, qual); | |
1624 | ||
1625 | /* setup ingres variables */ | |
1626 | rvar = q->rvar; | |
1627 | table = q->rtable; | |
1628 | name = v->field; | |
1629 | ||
b4182127 | 1630 | if (log_flags & LOG_RES) |
1631 | /* tell the logfile what we're doing */ | |
1632 | com_err(whoami, 0, "validating row: %s", qual); | |
1633 | ||
05cdd922 | 1634 | /* look for the record */ |
1635 | ## range of rvar is table | |
1636 | ## retrieve (rowcount = count(rvar.name where qual)) | |
05cdd922 | 1637 | if (rowcount == 0) return(SMS_NO_MATCH); |
1638 | if (rowcount > 1) return(SMS_NOT_UNIQUE); | |
1639 | return(SMS_EXISTS); | |
1640 | ##} | |
1641 | ||
1642 | validate_fields(q, argv, vo, n) | |
1643 | struct query *q; | |
1644 | register char *argv[]; | |
1645 | register struct valobj *vo; | |
1646 | register int n; | |
1647 | { | |
1648 | register int status; | |
05cdd922 | 1649 | |
1650 | while (--n >= 0) { | |
1651 | switch (vo->type) { | |
1652 | case V_NAME: | |
92a943d6 | 1653 | if (log_flags & LOG_RES) |
b4182127 | 1654 | com_err(whoami, 0, "validating %s in %s: %s", |
05cdd922 | 1655 | vo->namefield, vo->table, argv[vo->index]); |
05cdd922 | 1656 | status = validate_name(argv, vo); |
1657 | break; | |
1658 | ||
1659 | case V_ID: | |
92a943d6 | 1660 | if (log_flags & LOG_RES) |
b4182127 | 1661 | com_err(whoami, 0, "validating %s in %s: %s", |
05cdd922 | 1662 | vo->idfield, vo->table, argv[vo->index]); |
05cdd922 | 1663 | status = validate_id(argv, vo); |
1664 | break; | |
1665 | ||
92a943d6 | 1666 | case V_DATE: |
1667 | if (log_flags & LOG_RES) | |
1668 | com_err(whoami, 0, "validating date: %s", argv[vo->index]); | |
1669 | status = validate_date(argv, vo); | |
1670 | break; | |
1671 | ||
05cdd922 | 1672 | case V_TYPE: |
92a943d6 | 1673 | if (log_flags & LOG_RES) |
b4182127 | 1674 | com_err(whoami, 0, "validating %s type: %s", |
05cdd922 | 1675 | vo->table, argv[vo->index]); |
05cdd922 | 1676 | status = validate_type(argv, vo); |
1677 | break; | |
1678 | ||
1679 | case V_TYPEDATA: | |
92a943d6 | 1680 | if (log_flags & LOG_RES) |
1681 | com_err(whoami, 0, "validating typed data (%s): %s", | |
1682 | argv[vo->index - 1], argv[vo->index]); | |
05cdd922 | 1683 | status = validate_typedata(q, argv, vo); |
1684 | break; | |
1685 | ||
1686 | case V_FOLLOWUP: | |
1687 | status = SMS_EXISTS; | |
1688 | break; | |
1689 | ||
92a943d6 | 1690 | case V_SORT: |
1691 | status = SMS_EXISTS; | |
1692 | break; | |
1693 | ||
05cdd922 | 1694 | } |
1695 | ||
1696 | if (status != SMS_EXISTS) return(status); | |
1697 | vo++; | |
1698 | } | |
1699 | ||
1700 | return(SMS_SUCCESS); | |
1701 | } | |
1702 | ||
1703 | validate_id(argv, vo) | |
1704 | char *argv[]; | |
1705 | register struct valobj *vo; | |
1706 | ##{ | |
1707 | ## char *name; | |
1708 | ## char *table; | |
1709 | ## char *namefield; | |
1710 | ## char *idfield; | |
1711 | ## int id; | |
1712 | ## int rowcount; | |
1713 | ||
1714 | name = argv[vo->index]; | |
1715 | table = vo->table; | |
1716 | namefield = vo->namefield; | |
1717 | idfield = vo->idfield; | |
1718 | ## retrieve (id = table.idfield) where table.namefield = name | |
1719 | ## inquire_equel (rowcount = "rowcount") | |
1720 | if (rowcount != 1) return(vo->error); | |
1721 | *(int *)argv[vo->index] = id; | |
1722 | return(SMS_EXISTS); | |
1723 | ##} | |
1724 | ||
1725 | validate_name(argv, vo) | |
1726 | char *argv[]; | |
1727 | register struct valobj *vo; | |
1728 | ##{ | |
1729 | ## char *name; | |
1730 | ## char *table; | |
1731 | ## char *namefield; | |
1732 | ## int rowcount; | |
1733 | ||
1734 | name = argv[vo->index]; | |
1735 | table = vo->table; | |
1736 | namefield = vo->namefield; | |
1737 | ## retrieve (rowcount = countu(table.namefield | |
1738 | ## where table.namefield = name)) | |
1739 | return ((rowcount == 1) ? SMS_EXISTS : vo->error); | |
1740 | ##} | |
1741 | ||
92a943d6 | 1742 | validate_date(argv, vo) |
1743 | char *argv[]; | |
1744 | struct valobj *vo; | |
1745 | ##{ | |
1746 | ## char *idate; | |
1747 | ## double dd; | |
1748 | ## int errorno; | |
1749 | ||
1750 | idate = argv[vo->index]; | |
1751 | ||
1752 | ## retrieve (dd = interval("years", date(idate) - date("today"))) | |
1753 | ## inquire_equel (errorno = "errorno") | |
1754 | if (errorno != 0 || dd > 5.0) return(SMS_DATE); | |
1755 | return(SMS_SUCCESS); | |
1756 | ##} | |
1757 | ||
05cdd922 | 1758 | validate_type(argv, vo) |
1759 | char *argv[]; | |
1760 | register struct valobj *vo; | |
1761 | ##{ | |
1762 | ## char *typename; | |
1763 | ## char *value; | |
1764 | ## int rowcount; | |
1765 | register char *c; | |
1766 | ||
1767 | typename = vo->table; | |
1768 | value = argv[vo->index]; | |
1769 | ||
1770 | /* uppercase type fields */ | |
1771 | for (c = value; *c; c++) if (islower(*c)) *c = toupper(*c); | |
1772 | ||
1773 | ## range of a is alias | |
1774 | ## repeat retrieve (rowcount = count(a.trans where a.name = @typename and | |
1775 | ## a.type = "TYPE" and | |
1776 | ## a.trans = @value)) | |
1777 | return ((rowcount == 1) ? SMS_EXISTS : vo->error); | |
1778 | ##} | |
1779 | ||
1780 | /* validate member or type-specific data field */ | |
1781 | ||
1782 | validate_typedata(q, argv, vo) | |
1783 | register struct query *q; | |
1784 | register char *argv[]; | |
1785 | register struct valobj *vo; | |
1786 | ##{ | |
1787 | ## char *name; | |
1788 | ## char *field_type; | |
1789 | ## char data_type[17]; | |
1790 | ## int id; | |
1791 | ## int refc; | |
1792 | ## int rowcount; | |
a6cb4d4c | 1793 | register char *c; |
05cdd922 | 1794 | |
1795 | /* get named object */ | |
1796 | name = argv[vo->index]; | |
1797 | ||
1798 | /* get field type string (known to be at index-1) */ | |
1799 | field_type = argv[vo->index-1]; | |
1800 | ||
1801 | /* get corresponding data type associated with field type name */ | |
1802 | ## repeat retrieve (data_type = alias.trans) | |
1803 | ## where alias.#name = @field_type and alias.type = "TYPEDATA" | |
1804 | ## inquire_equel (rowcount = "rowcount") | |
1805 | if (rowcount != 1) return(SMS_TYPE); | |
1806 | ||
1807 | /* now retrieve the record id corresponding to the named object */ | |
1808 | ||
1809 | if (!strcmp(data_type, "user")) { | |
1810 | /* USER */ | |
1811 | ## repeat retrieve (id = users.users_id) where users.login = @name | |
1812 | ## inquire_equel (rowcount = "rowcount") | |
1813 | if (rowcount != 1) return(SMS_USER); | |
1814 | ||
1815 | } else if (!strcmp(data_type, "list")) { | |
1816 | /* LIST */ | |
1817 | ## repeat retrieve (id = list.list_id) where list.#name = @name | |
1818 | ## inquire_equel (rowcount = "rowcount") | |
1819 | if (rowcount != 1) return(SMS_LIST); | |
1820 | ||
1821 | } else if (!strcmp(data_type, "machine")) { | |
1822 | /* MACHINE */ | |
a6cb4d4c | 1823 | for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c); |
05cdd922 | 1824 | ## repeat retrieve (id = machine.mach_id) where machine.#name = @name |
1825 | ## inquire_equel (rowcount = "rowcount") | |
1826 | if (rowcount != 1) return(SMS_MACHINE); | |
1827 | ||
1828 | } else if (!strcmp(data_type, "string")) { | |
1829 | /* STRING */ | |
1830 | ## range of s is strings | |
1831 | ## repeat retrieve (id = s.string_id, refc = s.#refc) | |
1832 | ## where s.string = @name | |
1833 | ## inquire_equel (rowcount = "rowcount") | |
1834 | if (rowcount == 0) { | |
1835 | if (q->type != APPEND) return(SMS_STRING); | |
1836 | ## range of v is values | |
1837 | ## retrieve (id = v.value) where v.#name = "strings_id" | |
1838 | id++; | |
1839 | ## replace v (value = id) where v.#name = "strings_id" | |
1840 | ## append to strings (string_id = id, string = name, #refc = 1) | |
1841 | } else if (rowcount == 1) { | |
1842 | if (q->type == APPEND || q->type == DELETE) { | |
1843 | refc += (q->type == APPEND) ? 1 : -1; | |
1844 | if (refc > 0) { | |
1845 | ## replace s (#refc = refc) where s.string_id = id | |
1846 | } else { | |
1847 | ## delete s where s.string_id = id | |
1848 | } | |
1849 | } | |
1850 | } | |
1851 | } else { | |
1852 | return(SMS_TYPE); | |
1853 | } | |
1854 | ||
1855 | /* now set value in argv */ | |
1856 | *(int *)argv[vo->index] = id; | |
1857 | ||
1858 | return (SMS_EXISTS); | |
1859 | ##} | |
1860 | ||
1861 | \f | |
1862 | translate_ids(q, sq, v, action, actarg) | |
1863 | register struct query *q; | |
1864 | register struct save_queue *sq; | |
1865 | register struct validate *v; | |
1866 | register int (*action)(); | |
1867 | int actarg; | |
1868 | ##{ | |
1869 | ## char *name; | |
1870 | ## char *field_type; | |
1871 | ## char data_type[17]; | |
1872 | ## int id; | |
1873 | ## int rowcount; | |
1874 | register int i; | |
1875 | struct valobj *vo; | |
1876 | char **argv; | |
1877 | ||
1878 | for (i = 0; i < v->objcnt; i++) { | |
1879 | vo = &v->valobj[i]; | |
1880 | if (vo->type == V_FOLLOWUP) break; | |
1881 | } | |
1882 | ||
1883 | /* for each row */ | |
1884 | while (sq_get_data(sq, &argv)) { | |
1885 | ||
1886 | /* get object id */ | |
1887 | i = vo->index; | |
1888 | sscanf(argv[i], "%d", &id); | |
1889 | free(argv[i]); | |
1890 | name = (char *)malloc(129); | |
1891 | argv[i] = name; | |
1892 | ||
1893 | /* get field type string (known to be at index-1) */ | |
1894 | field_type = argv[vo->index-1]; | |
1895 | ||
1896 | /* get corresponding data type associated with field type name */ | |
1897 | ## repeat retrieve (data_type = alias.trans) | |
1898 | ## where alias.#name = @field_type and alias.type = "TYPEDATA" | |
1899 | ## inquire_equel (rowcount = "rowcount") | |
1900 | if (rowcount != 1) { | |
1901 | sprintf(name, "%d", id); | |
1902 | (*action)(q->vcnt, argv, actarg); | |
1903 | continue; | |
1904 | } | |
1905 | ||
1906 | /* retrieve object name */ | |
1907 | ||
1908 | if (!strcmp(data_type, "user")) { | |
1909 | /* USER */ | |
1910 | ## repeat retrieve (name = users.login) where users.users_id = @id | |
1911 | ## inquire_equel (rowcount = "rowcount") | |
1912 | ||
1913 | } else if (!strcmp(data_type, "list")) { | |
1914 | /* LIST */ | |
1915 | ## repeat retrieve (name = list.#name) where list.list_id = @id | |
1916 | ## inquire_equel (rowcount = "rowcount") | |
1917 | ||
1918 | } else if (!strcmp(data_type, "machine")) { | |
1919 | /* MACHINE */ | |
1920 | ## repeat retrieve (name = machine.#name) where machine.mach_id = @id | |
1921 | ## inquire_equel (rowcount = "rowcount") | |
1922 | ||
1923 | } else if (!strcmp(data_type, "string")) { | |
1924 | /* STRING */ | |
1925 | ## repeat retrieve (name = strings.string) | |
1926 | ## where strings.string_id = @id | |
1927 | ## inquire_equel (rowcount = "rowcount") | |
1928 | ||
1929 | } else { | |
1930 | rowcount = 0; | |
1931 | } | |
1932 | ||
1933 | /* if there wasn't a corresponding object name, then use the id */ | |
1934 | if (rowcount != 1) sprintf(name, "%d", id); | |
1935 | ||
1936 | /* send the data */ | |
1937 | (*action)(q->vcnt, argv, actarg); | |
1938 | ||
1939 | /* free saved data */ | |
1940 | for (i = 0; i < q->vcnt; i++) | |
1941 | free(argv[i]); | |
1942 | free(argv); | |
1943 | } | |
1944 | ||
1945 | sq_destroy(sq); | |
1946 | return (SMS_SUCCESS); | |
1947 | ##} | |
1948 | \f | |
1949 | /* | |
1950 | * Local Variables: | |
1951 | * mode: c | |
1952 | * c-indent-level: 4 | |
1953 | * c-continued-statement-offset: 4 | |
1954 | * c-brace-offset: -4 | |
1955 | * c-argdecl-indent: 4 | |
1956 | * c-label-offset: -4 | |
1957 | * End: | |
1958 | */ |