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