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