]>
Commit | Line | Data |
---|---|---|
7ac48069 | 1 | /* $Id$ |
73cf66ba | 2 | * |
7ac48069 | 3 | * Query followup routines |
4 | * | |
5 | * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology | |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
73cf66ba | 8 | * |
9 | */ | |
10 | ||
73cf66ba | 11 | #include <mit-copyright.h> |
73cf66ba | 12 | #include "mr_server.h" |
03c05291 | 13 | #include "query.h" |
7ac48069 | 14 | #include "qrtn.h" |
15 | ||
85330553 | 16 | #include <errno.h> |
73cf66ba | 17 | #include <ctype.h> |
7ac48069 | 18 | #include <stdlib.h> |
03c05291 | 19 | #include <string.h> |
7ac48069 | 20 | |
73cf66ba | 21 | EXEC SQL INCLUDE sqlca; |
7ac48069 | 22 | |
23 | RCSID("$Header$"); | |
73cf66ba | 24 | |
03c05291 | 25 | extern char *whoami, *table_name[]; |
26 | extern int dbms_errno, mr_errcode; | |
73cf66ba | 27 | |
28 | EXEC SQL BEGIN DECLARE SECTION; | |
29 | extern char stmt_buf[]; | |
30 | EXEC SQL END DECLARE SECTION; | |
31 | ||
03c05291 | 32 | EXEC SQL WHENEVER SQLERROR DO dbmserr(); |
73cf66ba | 33 | |
34 | ||
35 | /* FOLLOWUP ROUTINES */ | |
36 | ||
03c05291 | 37 | /* generic set_modtime routine. This takes the table id from the query, |
73cf66ba | 38 | * and will update the modtime, modby, and modwho fields in the entry in |
39 | * the table whose name field matches argv[0]. | |
40 | */ | |
41 | ||
5eaef520 | 42 | int set_modtime(struct query *q, char *argv[], client *cl) |
73cf66ba | 43 | { |
5eaef520 | 44 | char *name, *entity, *table; |
45 | int who; | |
73cf66ba | 46 | |
5eaef520 | 47 | entity = cl->entity; |
48 | who = cl->client_id; | |
49 | table = table_name[q->rtable]; | |
50 | name = argv[0]; | |
73cf66ba | 51 | |
5eaef520 | 52 | sprintf(stmt_buf, "UPDATE %s SET modtime = SYSDATE, modby = %d, " |
53 | "modwith = '%s' WHERE name = '%s'", table, who, entity, name); | |
54 | EXEC SQL EXECUTE IMMEDIATE :stmt_buf; | |
73cf66ba | 55 | |
5eaef520 | 56 | return MR_SUCCESS; |
73cf66ba | 57 | } |
58 | ||
03c05291 | 59 | /* generic set_modtime_by_id routine. This takes the table id from |
73cf66ba | 60 | * the query, and the id name from the validate record, |
61 | * and will update the modtime, modby, and modwho fields in the entry in | |
62 | * the table whose id matches argv[0]. | |
63 | */ | |
64 | ||
5eaef520 | 65 | int set_modtime_by_id(struct query *q, char *argv[], client *cl) |
73cf66ba | 66 | { |
5eaef520 | 67 | char *entity, *table, *id_name; |
68 | int who, id; | |
69 | ||
70 | entity = cl->entity; | |
71 | who = cl->client_id; | |
72 | table = table_name[q->rtable]; | |
73 | id_name = q->validate->object_id; | |
74 | ||
75 | id = *(int *)argv[0]; | |
76 | sprintf(stmt_buf, "UPDATE %s SET modtime = SYSDATE, modby = %d, " | |
77 | "modwith = '%s' WHERE %s = %d", table, who, entity, id_name, id); | |
78 | EXEC SQL EXECUTE IMMEDIATE :stmt_buf; | |
79 | return MR_SUCCESS; | |
73cf66ba | 80 | } |
81 | ||
82 | ||
83 | /* Sets the finger modtime on a user record. The users_id will be in argv[0]. | |
84 | */ | |
85 | ||
5eaef520 | 86 | int set_finger_modtime(struct query *q, char *argv[], client *cl) |
73cf66ba | 87 | { |
5eaef520 | 88 | EXEC SQL BEGIN DECLARE SECTION; |
89 | int users_id, who; | |
90 | char *entity; | |
91 | EXEC SQL END DECLARE SECTION; | |
73cf66ba | 92 | |
5eaef520 | 93 | entity = cl->entity; |
94 | who = cl->client_id; | |
95 | users_id = *(int *)argv[0]; | |
73cf66ba | 96 | |
5eaef520 | 97 | EXEC SQL UPDATE users SET fmodtime = SYSDATE, fmodby = :who, |
98 | fmodwith = :entity WHERE users_id = :users_id; | |
73cf66ba | 99 | |
5eaef520 | 100 | return MR_SUCCESS; |
73cf66ba | 101 | } |
102 | ||
103 | ||
104 | /* Sets the pobox modtime on a user record. The users_id will be in argv[0]. | |
105 | */ | |
106 | ||
5eaef520 | 107 | int set_pobox_modtime(struct query *q, char *argv[], client *cl) |
73cf66ba | 108 | { |
5eaef520 | 109 | EXEC SQL BEGIN DECLARE SECTION; |
110 | int users_id, who; | |
111 | char *entity; | |
112 | EXEC SQL END DECLARE SECTION; | |
73cf66ba | 113 | |
5eaef520 | 114 | entity = cl->entity; |
115 | who = cl->client_id; | |
116 | users_id = *(int *)argv[0]; | |
73cf66ba | 117 | |
5eaef520 | 118 | EXEC SQL UPDATE users SET pmodtime = SYSDATE, pmodby = :who, |
119 | pmodwith = :entity WHERE users_id = :users_id; | |
73cf66ba | 120 | |
5eaef520 | 121 | return MR_SUCCESS; |
73cf66ba | 122 | } |
123 | ||
124 | ||
125 | /* Like set_modtime, but uppercases the name first. | |
126 | */ | |
127 | ||
5eaef520 | 128 | int set_uppercase_modtime(struct query *q, char *argv[], client *cl) |
73cf66ba | 129 | { |
5eaef520 | 130 | char *name, *entity, *table; |
131 | int who; | |
73cf66ba | 132 | |
5eaef520 | 133 | entity = cl->entity; |
134 | who = cl->client_id; | |
135 | table = table_name[q->rtable]; | |
136 | name = argv[0]; | |
73cf66ba | 137 | |
5eaef520 | 138 | sprintf(stmt_buf, "UPDATE %s SET modtime = SYSDATE, modby = %d, " |
139 | "modwith = '%s' WHERE name = UPPER('%s')", table, who, entity, name); | |
140 | EXEC SQL EXECUTE IMMEDIATE :stmt_buf; | |
73cf66ba | 141 | |
5eaef520 | 142 | return MR_SUCCESS; |
73cf66ba | 143 | } |
144 | ||
145 | ||
146 | /* Sets the modtime on the machine whose mach_id is in argv[0]. This routine | |
147 | * is necessary for add_machine_to_cluster becuase the table that query | |
148 | * operates on is "mcm", not "machine". | |
149 | */ | |
150 | ||
5eaef520 | 151 | int set_mach_modtime_by_id(struct query *q, char *argv[], client *cl) |
73cf66ba | 152 | { |
5eaef520 | 153 | EXEC SQL BEGIN DECLARE SECTION; |
154 | char *entity; | |
155 | int who, id; | |
156 | EXEC SQL END DECLARE SECTION; | |
157 | ||
158 | entity = cl->entity; | |
159 | who = cl->client_id; | |
160 | id = *(int *)argv[0]; | |
161 | EXEC SQL UPDATE machine SET modtime = SYSDATE, modby = :who, | |
162 | modwith = :entity WHERE mach_id = :id; | |
163 | ||
164 | return MR_SUCCESS; | |
73cf66ba | 165 | } |
166 | ||
167 | ||
168 | /* Sets the modtime on the cluster whose mach_id is in argv[0]. This routine | |
169 | * is necessary for add_cluster_data and delete_cluster_data becuase the | |
170 | * table that query operates on is "svc", not "cluster". | |
171 | */ | |
172 | ||
5eaef520 | 173 | int set_cluster_modtime_by_id(struct query *q, char *argv[], client *cl) |
73cf66ba | 174 | { |
5eaef520 | 175 | EXEC SQL BEGIN DECLARE SECTION; |
176 | char *entity; | |
177 | int who, id; | |
178 | EXEC SQL END DECLARE SECTION; | |
179 | ||
180 | entity = cl->entity; | |
181 | who = cl->client_id; | |
182 | ||
183 | id = *(int *)argv[0]; | |
184 | EXEC SQL UPDATE clusters SET modtime = SYSDATE, modby = :who, | |
185 | modwith = :entity WHERE clu_id = :id; | |
186 | return MR_SUCCESS; | |
73cf66ba | 187 | } |
188 | ||
189 | ||
190 | /* sets the modtime on the serverhost where the service name is in argv[0] | |
191 | * and the mach_id is in argv[1]. | |
192 | */ | |
193 | ||
5eaef520 | 194 | int set_serverhost_modtime(struct query *q, char *argv[], client *cl) |
73cf66ba | 195 | { |
5eaef520 | 196 | EXEC SQL BEGIN DECLARE SECTION; |
197 | char *entity, *serv; | |
198 | int who, id; | |
199 | EXEC SQL END DECLARE SECTION; | |
200 | ||
201 | entity = cl->entity; | |
202 | who = cl->client_id; | |
203 | ||
204 | serv = argv[0]; | |
205 | id = *(int *)argv[1]; | |
206 | EXEC SQL UPDATE serverhosts | |
207 | SET modtime = SYSDATE, modby = :who, modwith = :entity | |
208 | WHERE service = :serv AND mach_id = :id; | |
209 | return MR_SUCCESS; | |
73cf66ba | 210 | } |
211 | ||
212 | ||
213 | /* sets the modtime on the nfsphys where the mach_id is in argv[0] and the | |
214 | * directory name is in argv[1]. | |
215 | */ | |
216 | ||
5eaef520 | 217 | int set_nfsphys_modtime(struct query *q, char *argv[], client *cl) |
73cf66ba | 218 | { |
5eaef520 | 219 | EXEC SQL BEGIN DECLARE SECTION; |
220 | char *entity, *dir; | |
221 | int who, id; | |
222 | EXEC SQL END DECLARE SECTION; | |
223 | ||
224 | entity = cl->entity; | |
225 | who = cl->client_id; | |
226 | ||
227 | id = *(int *)argv[0]; | |
228 | dir = argv[1]; | |
229 | EXEC SQL UPDATE nfsphys SET modtime = SYSDATE, modby = :who, | |
230 | modwith = :entity WHERE dir = :dir AND mach_id = :id; | |
231 | return MR_SUCCESS; | |
73cf66ba | 232 | } |
233 | ||
234 | ||
235 | /* sets the modtime on a filesystem, where argv[0] contains the filesys | |
236 | * label. | |
237 | */ | |
238 | ||
5eaef520 | 239 | int set_filesys_modtime(struct query *q, char *argv[], client *cl) |
73cf66ba | 240 | { |
5eaef520 | 241 | EXEC SQL BEGIN DECLARE SECTION; |
242 | char *label, *entity; | |
243 | int who; | |
244 | extern int _var_phys_id; | |
245 | EXEC SQL END DECLARE SECTION; | |
246 | ||
247 | entity = cl->entity; | |
248 | who = cl->client_id; | |
249 | ||
250 | label = argv[0]; | |
251 | if (!strcmp(q->shortname, "ufil")) | |
252 | label = argv[1]; | |
253 | ||
254 | EXEC SQL UPDATE filesys SET modtime = SYSDATE, modby = :who, | |
255 | modwith = :entity, phys_id = :_var_phys_id | |
256 | WHERE label = :label; | |
257 | return MR_SUCCESS; | |
73cf66ba | 258 | } |
259 | ||
260 | ||
261 | /* sets the modtime on a zephyr class, where argv[0] contains the class | |
262 | * name. | |
263 | */ | |
264 | ||
5eaef520 | 265 | int set_zephyr_modtime(struct query *q, char *argv[], client *cl) |
73cf66ba | 266 | { |
5eaef520 | 267 | EXEC SQL BEGIN DECLARE SECTION; |
268 | char *class, *entity; | |
269 | int who; | |
270 | EXEC SQL END DECLARE SECTION; | |
73cf66ba | 271 | |
5eaef520 | 272 | entity = cl->entity; |
273 | who = cl->client_id; | |
73cf66ba | 274 | |
5eaef520 | 275 | class = argv[0]; |
73cf66ba | 276 | |
5eaef520 | 277 | EXEC SQL UPDATE zephyr SET modtime = SYSDATE, modby = :who, |
278 | modwith = :entity WHERE class = :class; | |
73cf66ba | 279 | |
5eaef520 | 280 | return MR_SUCCESS; |
73cf66ba | 281 | } |
282 | ||
283 | ||
284 | /* fixes the modby field. This will be the second to last thing in the | |
285 | * argv, the argv length is determined from the query structure. It is | |
286 | * passed as a pointer to an integer. This will either turn it into a | |
287 | * username, or # + the users_id. | |
288 | */ | |
5eaef520 | 289 | int followup_fix_modby(struct query *q, struct save_queue *sq, |
7ac48069 | 290 | struct validate *v, int (*action)(int, char *[], void *), |
291 | void *actarg, client *cl) | |
73cf66ba | 292 | { |
44d12d58 | 293 | int i, j; |
5eaef520 | 294 | char **argv; |
295 | int id, status; | |
296 | ||
297 | i = q->vcnt - 2; | |
298 | while (sq_get_data(sq, &argv)) | |
299 | { | |
300 | id = atoi(argv[i]); | |
301 | if (id > 0) | |
302 | status = id_to_name(id, USERS_TABLE, &argv[i]); | |
303 | else | |
304 | status = id_to_name(-id, STRINGS_TABLE, &argv[i]); | |
305 | if (status && status != MR_NO_MATCH) | |
306 | return status; | |
307 | (*action)(q->vcnt, argv, actarg); | |
308 | for (j = 0; j < q->vcnt; j++) | |
309 | free(argv[j]); | |
310 | free(argv); | |
73cf66ba | 311 | } |
5eaef520 | 312 | sq_destroy(sq); |
313 | return MR_SUCCESS; | |
73cf66ba | 314 | } |
315 | ||
73cf66ba | 316 | /** |
317 | ** followup_ausr - add finger and pobox entries, set_user_modtime | |
318 | ** | |
319 | ** Inputs: | |
320 | ** argv[0] - login (add_user) | |
186dd63b | 321 | ** argv[U_LAST] - last name |
322 | ** argv[U_FIRST] - first name | |
323 | ** argv[U_MIDDLE] - middle name | |
73cf66ba | 324 | ** |
325 | **/ | |
326 | ||
5eaef520 | 327 | int followup_ausr(struct query *q, char *argv[], client *cl) |
73cf66ba | 328 | { |
5eaef520 | 329 | EXEC SQL BEGIN DECLARE SECTION; |
330 | int who, status; | |
331 | char *login, *entity, *name; | |
e688520a | 332 | char fullname[USERS_FIRST_SIZE + USERS_MIDDLE_SIZE + USERS_LAST_SIZE]; |
5eaef520 | 333 | EXEC SQL END DECLARE SECTION; |
73cf66ba | 334 | |
5eaef520 | 335 | /* build fullname */ |
186dd63b | 336 | if (strlen(argv[U_FIRST]) && strlen(argv[U_MIDDLE])) |
337 | sprintf(fullname, "%s %s %s", argv[U_FIRST], argv[U_MIDDLE], | |
338 | argv[U_LAST]); | |
339 | else if (strlen(argv[U_FIRST])) | |
340 | sprintf(fullname, "%s %s", argv[U_FIRST], argv[U_LAST]); | |
5eaef520 | 341 | else |
186dd63b | 342 | sprintf(fullname, "%s", argv[U_LAST]); |
73cf66ba | 343 | |
5eaef520 | 344 | login = argv[0]; |
345 | who = cl->client_id; | |
346 | entity = cl->entity; | |
73cf66ba | 347 | |
5eaef520 | 348 | /* create finger entry, pobox & set modtime on user */ |
5eaef520 | 349 | EXEC SQL UPDATE users |
350 | SET modtime = SYSDATE, modby = :who, modwith = :entity, | |
351 | fullname = NVL(:fullname, CHR(0)), affiliation = type, | |
352 | fmodtime = SYSDATE, fmodby = :who, fmodwith = :entity, | |
353 | potype = 'NONE', pmodtime = SYSDATE, pmodby = :who, pmodwith = :entity | |
354 | WHERE login = :login; | |
5eaef520 | 355 | |
5eaef520 | 356 | return MR_SUCCESS; |
73cf66ba | 357 | } |
5eaef520 | 358 | |
d6d830a1 | 359 | /* followup_gpob: fixes argv[2] and argv[3] based on the pobox type. |
360 | * Then completes the upcall to the user. | |
73cf66ba | 361 | * |
d6d830a1 | 362 | * argv[2] is the users_id on input and should be converted to the |
363 | * pobox name on output. argv[3] is empty on input and should be | |
364 | * converted to an email address on output. | |
73cf66ba | 365 | */ |
366 | ||
5eaef520 | 367 | int followup_gpob(struct query *q, struct save_queue *sq, struct validate *v, |
7ac48069 | 368 | int (*action)(int, char *[], void *), void *actarg, |
369 | client *cl) | |
73cf66ba | 370 | { |
5eaef520 | 371 | char **argv; |
372 | char *ptype, *p; | |
373 | int mid, sid, status, i; | |
d6d830a1 | 374 | EXEC SQL BEGIN DECLARE SECTION; |
450849e9 | 375 | int users_id, pid, iid, bid; |
d6d830a1 | 376 | char mach[MACHINE_NAME_SIZE], fs[FILESYS_LABEL_SIZE]; |
377 | char str[STRINGS_STRING_SIZE]; | |
378 | EXEC SQL END DECLARE SECTION; | |
5eaef520 | 379 | |
380 | /* for each row */ | |
381 | while (sq_get_data(sq, &argv)) | |
382 | { | |
d6d830a1 | 383 | mr_trim_args(4, argv); |
5eaef520 | 384 | ptype = argv[1]; |
d6d830a1 | 385 | users_id = atoi(argv[2]); |
5eaef520 | 386 | |
450849e9 | 387 | EXEC SQL SELECT pop_id, imap_id, box_id INTO :pid, :iid, :bid |
388 | FROM users WHERE users_id = :users_id; | |
389 | if (sqlca.sqlcode) | |
390 | return MR_USER; | |
391 | ||
392 | if (ptype[0] == 'S') | |
393 | { | |
394 | /* SMTP or SPLIT */ | |
395 | EXEC SQL SELECT string INTO :str FROM strings | |
396 | WHERE string_id = :bid; | |
397 | if (sqlca.sqlcode) | |
398 | return MR_STRING; | |
399 | ||
400 | /* If SMTP, don't bother fetching IMAP and POP boxes. */ | |
401 | if (ptype[1] == 'M') | |
402 | pid = iid = 0; | |
403 | } | |
404 | if (iid) | |
5eaef520 | 405 | { |
450849e9 | 406 | /* IMAP, or SPLIT with IMAP */ |
407 | EXEC SQL SELECT f.label, m.name INTO :fs, :mach | |
408 | FROM filesys f, machine m | |
409 | WHERE f.filsys_id = :iid AND f.mach_id = m.mach_id; | |
410 | if (sqlca.sqlcode) | |
411 | return MR_FILESYS; | |
412 | } | |
413 | if (pid) | |
414 | { | |
415 | /* POP, or SPLIT with POP */ | |
d6d830a1 | 416 | EXEC SQL SELECT m.name INTO :mach FROM machine m, users u |
417 | WHERE u.users_id = :users_id AND u.pop_id = m.mach_id; | |
418 | if (sqlca.sqlcode) | |
5eaef520 | 419 | return MR_MACHINE; |
450849e9 | 420 | } |
421 | ||
422 | free(argv[2]); | |
423 | free(argv[3]); | |
424 | ||
425 | /* Now assemble the right answer. */ | |
426 | if (!strcmp(ptype, "POP")) | |
427 | { | |
d6d830a1 | 428 | argv[2] = xstrdup(strtrim(mach)); |
d6d830a1 | 429 | argv[3] = xmalloc(strlen(argv[0]) + strlen(argv[2]) + 2); |
430 | sprintf(argv[3], "%s@%s", argv[0], argv[2]); | |
5eaef520 | 431 | } |
432 | else if (!strcmp(ptype, "SMTP")) | |
433 | { | |
d6d830a1 | 434 | argv[2] = xstrdup(strtrim(str)); |
435 | argv[3] = xstrdup(str); | |
73cf66ba | 436 | } |
f76b37f2 | 437 | else if (!strcmp(ptype, "IMAP")) |
438 | { | |
d6d830a1 | 439 | argv[2] = xstrdup(strtrim(fs)); |
d6d830a1 | 440 | argv[3] = xmalloc(strlen(argv[0]) + strlen(strtrim(mach)) + 2); |
441 | sprintf(argv[3], "%s@%s", argv[0], mach); | |
f76b37f2 | 442 | } |
450849e9 | 443 | else if (!strcmp(ptype, "SPLIT")) |
444 | { | |
445 | argv[2] = xstrdup(strtrim(str)); | |
446 | argv[3] = xmalloc(strlen(argv[0]) + strlen(strtrim(mach)) + | |
447 | strlen(str) + 4); | |
448 | sprintf(argv[3], "%s@%s, %s", argv[0], mach, str); | |
449 | } | |
5eaef520 | 450 | else /* ptype == "NONE" */ |
451 | goto skip; | |
5eaef520 | 452 | |
453 | if (!strcmp(q->shortname, "gpob")) | |
454 | { | |
d6d830a1 | 455 | sid = atoi(argv[5]); |
5eaef520 | 456 | if (sid > 0) |
d6d830a1 | 457 | status = id_to_name(sid, USERS_TABLE, &argv[5]); |
5eaef520 | 458 | else |
d6d830a1 | 459 | status = id_to_name(-sid, STRINGS_TABLE, &argv[5]); |
460 | if (status && status != MR_NO_MATCH) | |
461 | return status; | |
73cf66ba | 462 | } |
73cf66ba | 463 | |
5eaef520 | 464 | (*action)(q->vcnt, argv, actarg); |
73cf66ba | 465 | skip: |
5eaef520 | 466 | /* free saved data */ |
467 | for (i = 0; i < q->vcnt; i++) | |
468 | free(argv[i]); | |
469 | free(argv); | |
73cf66ba | 470 | } |
471 | ||
5eaef520 | 472 | sq_destroy(sq); |
473 | return MR_SUCCESS; | |
73cf66ba | 474 | } |
475 | ||
b121cf1b | 476 | /* Fix an ace_name, based on its type. */ |
477 | ||
478 | static int fix_ace(char *type, char **name) | |
479 | { | |
480 | int id = atoi(*name); | |
481 | ||
482 | if (!strcmp(type, "LIST")) | |
483 | return id_to_name(id, LIST_TABLE, name); | |
484 | else if (!strcmp(type, "USER")) | |
485 | return id_to_name(id, USERS_TABLE, name); | |
486 | else if (!strcmp(type, "KERBEROS")) | |
487 | return id_to_name(id, STRINGS_TABLE, name); | |
488 | else | |
489 | { | |
490 | free(*name); | |
491 | if (!strcmp(type, "NONE")) | |
492 | *name = xstrdup("NONE"); | |
493 | else | |
494 | *name = xstrdup("???"); | |
495 | return MR_SUCCESS; | |
496 | } | |
497 | } | |
73cf66ba | 498 | |
b121cf1b | 499 | |
500 | /* followup_gsnt: fix the ace_name and modby */ | |
73cf66ba | 501 | |
5eaef520 | 502 | int followup_gsnt(struct query *q, struct save_queue *sq, struct validate *v, |
7ac48069 | 503 | int (*action)(int, char *[], void *), void *actarg, |
504 | client *cl) | |
73cf66ba | 505 | { |
b121cf1b | 506 | char **argv; |
507 | int status; | |
5eaef520 | 508 | |
509 | while (sq_get_data(sq, &argv)) | |
510 | { | |
511 | mr_trim_args(q->vcnt, argv); | |
512 | ||
b121cf1b | 513 | status = fix_ace(argv[7], &argv[8]); |
5eaef520 | 514 | if (status && status != MR_NO_MATCH) |
515 | return status; | |
fde7313c | 516 | } |
517 | ||
b121cf1b | 518 | return followup_fix_modby(q, sq, v, action, actarg, cl); |
fde7313c | 519 | } |
520 | ||
521 | ||
b121cf1b | 522 | /* followup_ghst: fix the ace_name, strings and modby */ |
fde7313c | 523 | |
5eaef520 | 524 | int followup_ghst(struct query *q, struct save_queue *sq, struct validate *v, |
7ac48069 | 525 | int (*action)(int, char *[], void *), void *actarg, |
526 | client *cl) | |
fde7313c | 527 | { |
b121cf1b | 528 | char **argv; |
529 | int id, status; | |
5eaef520 | 530 | |
531 | while (sq_get_data(sq, &argv)) | |
532 | { | |
533 | mr_trim_args(q->vcnt, argv); | |
534 | ||
5eaef520 | 535 | id = atoi(argv[13]); |
536 | status = id_to_name(id, STRINGS_TABLE, &argv[13]); | |
537 | if (status) | |
538 | return status; | |
539 | id = atoi(argv[14]); | |
540 | status = id_to_name(id, STRINGS_TABLE, &argv[14]); | |
541 | if (status) | |
542 | return status; | |
543 | id = atoi(argv[16]); | |
544 | if (id < 0) | |
545 | status = id_to_name(-id, STRINGS_TABLE, &argv[16]); | |
546 | else | |
547 | status = id_to_name(id, USERS_TABLE, &argv[16]); | |
548 | if (status && status != MR_NO_MATCH) | |
549 | return status; | |
550 | ||
b121cf1b | 551 | status = fix_ace(argv[11], &argv[12]); |
5eaef520 | 552 | if (status && status != MR_NO_MATCH) |
553 | return status; | |
73cf66ba | 554 | } |
555 | ||
b121cf1b | 556 | return followup_fix_modby(q, sq, v, action, actarg, cl); |
73cf66ba | 557 | } |
558 | ||
559 | ||
b121cf1b | 560 | /* followup_glin: fix the ace_name, modace_name, expiration, and modby */ |
73cf66ba | 561 | |
5eaef520 | 562 | int followup_glin(struct query *q, struct save_queue *sq, struct validate *v, |
7ac48069 | 563 | int (*action)(int, char *[], void *), void *actarg, |
564 | client *cl) | |
73cf66ba | 565 | { |
b121cf1b | 566 | char **argv; |
5eaef520 | 567 | int id, i, idx, status; |
568 | ||
b121cf1b | 569 | idx = 7; |
44da57b2 | 570 | if (!strcmp(q->shortname, "glin") && q->version > 2) |
571 | idx = 8; | |
5eaef520 | 572 | if (!strcmp(q->shortname, "gsin")) |
b121cf1b | 573 | idx = 11; |
5eaef520 | 574 | |
575 | while (sq_get_data(sq, &argv)) | |
576 | { | |
577 | mr_trim_args(q->vcnt, argv); | |
578 | ||
b121cf1b | 579 | status = fix_ace(argv[idx], &argv[idx + 1]); |
5eaef520 | 580 | if (status && status != MR_NO_MATCH) |
581 | return status; | |
73cf66ba | 582 | |
5eaef520 | 583 | if (!strcmp(q->shortname, "glin") && atoi(argv[6]) == -1) |
584 | { | |
e688520a | 585 | argv[6] = xrealloc(argv[6], strlen(UNIQUE_GID) + 1); |
5eaef520 | 586 | strcpy(argv[6], UNIQUE_GID); |
73cf66ba | 587 | } |
73cf66ba | 588 | } |
589 | ||
b121cf1b | 590 | return followup_fix_modby(q, sq, v, action, actarg, cl); |
73cf66ba | 591 | } |
592 | ||
1a9a0a59 | 593 | int followup_gpsv(struct query *q, struct save_queue *sq, struct validate *v, |
594 | int (*action)(int, char *[], void *), void *actarg, | |
595 | client *cl) | |
596 | { | |
b121cf1b | 597 | char **argv; |
598 | int status; | |
1a9a0a59 | 599 | |
600 | while (sq_get_data(sq, &argv)) | |
601 | { | |
602 | mr_trim_args(q->vcnt, argv); | |
603 | ||
b121cf1b | 604 | status = fix_ace(argv[PRINTSERVER_OWNER_TYPE], |
605 | &argv[PRINTSERVER_OWNER_NAME]); | |
1a9a0a59 | 606 | if (status && status != MR_NO_MATCH) |
607 | return status; | |
608 | } | |
609 | ||
610 | return followup_fix_modby(q, sq, v, action, actarg, cl); | |
611 | } | |
612 | ||
73cf66ba | 613 | |
614 | /* followup_gqot: Fix the entity name, directory name & modby fields | |
615 | * argv[0] = filsys_id | |
616 | * argv[1] = type | |
617 | * argv[2] = entity_id | |
618 | * argv[3] = ascii(quota) | |
619 | */ | |
620 | ||
5eaef520 | 621 | int followup_gqot(struct query *q, struct save_queue *sq, struct validate *v, |
7ac48069 | 622 | int (*action)(int, char *[], void *), void *actarg, |
623 | client *cl) | |
73cf66ba | 624 | { |
44d12d58 | 625 | int j; |
5eaef520 | 626 | char **argv; |
627 | EXEC SQL BEGIN DECLARE SECTION; | |
628 | int id; | |
629 | char *name, *label; | |
630 | EXEC SQL END DECLARE SECTION; | |
631 | int status, idx; | |
632 | ||
633 | if (!strcmp(q->name, "get_quota") || | |
634 | !strcmp(q->name, "get_quota_by_filesys")) | |
635 | idx = 4; | |
636 | else | |
637 | idx = 3; | |
b121cf1b | 638 | |
5eaef520 | 639 | while (sq_get_data(sq, &argv)) |
640 | { | |
641 | if (idx == 4) | |
642 | { | |
643 | switch (argv[1][0]) | |
644 | { | |
73cf66ba | 645 | case 'U': |
5eaef520 | 646 | status = id_to_name(atoi(argv[2]), USERS_TABLE, &argv[2]); |
647 | break; | |
73cf66ba | 648 | case 'G': |
649 | case 'L': | |
5eaef520 | 650 | status = id_to_name(atoi(argv[2]), LIST_TABLE, &argv[2]); |
651 | break; | |
73cf66ba | 652 | case 'A': |
5eaef520 | 653 | free(argv[2]); |
e688520a | 654 | argv[2] = xstrdup("system:anyuser"); |
5eaef520 | 655 | break; |
73cf66ba | 656 | default: |
5eaef520 | 657 | id = atoi(argv[2]); |
e688520a | 658 | argv[2] = xmalloc(8); |
5eaef520 | 659 | sprintf(argv[2], "%d", id); |
73cf66ba | 660 | } |
661 | } | |
5eaef520 | 662 | id = atoi(argv[idx]); |
663 | free(argv[idx]); | |
e688520a | 664 | argv[idx] = xmalloc(id ? NFSPHYS_DIR_SIZE : FILESYS_NAME_SIZE); |
5eaef520 | 665 | name = argv[idx]; |
e688520a | 666 | name[0] = '\0'; |
5eaef520 | 667 | if (id == 0) |
668 | { | |
669 | label = argv[0]; | |
670 | EXEC SQL SELECT name INTO :name FROM filesys | |
671 | WHERE label = :label; | |
73cf66ba | 672 | } |
5eaef520 | 673 | else |
674 | { | |
675 | EXEC SQL SELECT dir INTO :name FROM nfsphys | |
676 | WHERE nfsphys_id = :id; | |
73cf66ba | 677 | } |
5eaef520 | 678 | if (sqlca.sqlerrd[2] != 1) |
679 | sprintf(argv[idx], "#%d", id); | |
680 | ||
681 | id = atoi(argv[idx + 3]); | |
682 | if (id > 0) | |
683 | status = id_to_name(id, USERS_TABLE, &argv[idx + 3]); | |
684 | else | |
685 | status = id_to_name(-id, STRINGS_TABLE, &argv[idx + 3]); | |
686 | if (status && status != MR_NO_MATCH) | |
687 | return status; | |
688 | (*action)(q->vcnt, argv, actarg); | |
689 | for (j = 0; j < q->vcnt; j++) | |
690 | free(argv[j]); | |
691 | free(argv); | |
73cf66ba | 692 | } |
5eaef520 | 693 | sq_destroy(sq); |
694 | return MR_SUCCESS; | |
73cf66ba | 695 | } |
696 | ||
697 | ||
698 | /* followup_aqot: Add allocation to nfsphys after creating quota. | |
699 | * argv[0] = filsys_id | |
700 | * argv[1] = type if "add_quota" or "update_quota" | |
701 | * argv[2 or 1] = id | |
702 | * argv[3 or 2] = ascii(quota) | |
703 | */ | |
704 | ||
5eaef520 | 705 | int followup_aqot(struct query *q, char *argv[], client *cl) |
73cf66ba | 706 | { |
5eaef520 | 707 | EXEC SQL BEGIN DECLARE SECTION; |
708 | int quota, id, fs, who, physid, table; | |
709 | char *entity, *qtype, *tname; | |
710 | EXEC SQL END DECLARE SECTION; | |
711 | char incr_qual[60]; | |
712 | char *incr_argv[2]; | |
713 | int status; | |
714 | ||
715 | table = q->rtable; | |
716 | tname = table_name[table]; | |
717 | fs = *(int *)argv[0]; | |
718 | EXEC SQL SELECT phys_id INTO :physid FROM filesys | |
719 | WHERE filsys_id = :fs; | |
720 | if (dbms_errno) | |
721 | return mr_errcode; | |
722 | ||
723 | if (!strcmp(q->shortname, "aqot") || !strcmp(q->shortname, "uqot")) | |
724 | { | |
725 | qtype = argv[1]; | |
726 | id = *(int *)argv[2]; | |
727 | quota = atoi(argv[3]); | |
728 | sprintf(incr_qual, "q.filsys_id = %d", fs); | |
729 | } | |
730 | else | |
731 | { | |
732 | qtype = "USER"; | |
733 | id = *(int *)argv[1]; | |
734 | quota = atoi(argv[2]); | |
735 | sprintf(incr_qual, "q.filsys_id = %d AND q.type = '%s' AND " | |
736 | "q.entity_id = %d", fs, qtype, id); | |
73cf66ba | 737 | } |
738 | ||
5eaef520 | 739 | /* quota case of incremental_{before|after} only looks at slot 1 */ |
740 | incr_argv[1] = qtype; | |
741 | ||
742 | /* Follows one of many possible gross hacks to fix these particular | |
743 | * conflicts between what is possible in the query table and what | |
744 | * is possible in SQL. | |
745 | */ | |
746 | if (q->type == APPEND) | |
747 | { | |
748 | incremental_clear_before(); | |
749 | EXEC SQL INSERT INTO quota | |
750 | (filsys_id, type, entity_id, quota, phys_id) | |
751 | VALUES (:fs, NVL(:qtype, CHR(0)), :id, :quota, :physid); | |
752 | incremental_after(table, incr_qual, incr_argv); | |
753 | } | |
754 | else | |
755 | { | |
756 | incremental_before(table, incr_qual, incr_argv); | |
757 | EXEC SQL UPDATE quota SET quota = :quota | |
758 | WHERE filsys_id = :fs AND type = :qtype AND entity_id = :id; | |
759 | status = mr_errcode; | |
760 | incremental_after(table, incr_qual, incr_argv); | |
73cf66ba | 761 | } |
762 | ||
5eaef520 | 763 | if (dbms_errno) |
764 | return mr_errcode; | |
765 | flush_name(argv[0], table); | |
766 | if (q->type == APPEND) | |
767 | { | |
768 | EXEC SQL UPDATE tblstats SET appends = appends + 1, modtime = SYSDATE | |
769 | WHERE table_name = :tname; | |
770 | } | |
771 | else | |
772 | { | |
773 | EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE | |
774 | WHERE table_name = :tname; | |
73cf66ba | 775 | } |
5eaef520 | 776 | |
777 | /* Proceed with original followup */ | |
778 | who = cl->client_id; | |
779 | entity = cl->entity; | |
780 | ||
781 | EXEC SQL UPDATE quota | |
782 | SET modtime = SYSDATE, modby = :who, modwith = :entity | |
783 | WHERE filsys_id = :fs and type = :qtype and entity_id = :id; | |
784 | EXEC SQL UPDATE nfsphys SET allocated = allocated + :quota | |
785 | WHERE nfsphys_id = :physid; | |
786 | if (dbms_errno) | |
787 | return mr_errcode; | |
788 | return MR_SUCCESS; | |
73cf66ba | 789 | } |
790 | ||
791 | ||
792 | /* Necessitated by the requirement of a correlation name by the incremental | |
5eaef520 | 793 | * routines, since query table deletes don't provide one. |
73cf66ba | 794 | */ |
5eaef520 | 795 | int followup_dqot(struct query *q, char **argv, client *cl) |
73cf66ba | 796 | { |
5eaef520 | 797 | char *qtype; |
798 | int id, fs, table; | |
799 | char *incr_argv[2]; | |
800 | EXEC SQL BEGIN DECLARE SECTION; | |
801 | char incr_qual[80], *tname; | |
802 | EXEC SQL END DECLARE SECTION; | |
803 | ||
804 | table = q->rtable; | |
805 | tname = table_name[table]; | |
806 | fs = *(int *)argv[0]; | |
807 | if (!strcmp(q->shortname, "dqot")) | |
808 | { | |
809 | qtype = argv[1]; | |
810 | id = *(int *)argv[2]; | |
811 | } | |
812 | else | |
813 | { | |
814 | qtype = "USER"; | |
815 | id = *(int *)argv[1]; | |
73cf66ba | 816 | } |
5eaef520 | 817 | sprintf(incr_qual, "q.filsys_id = %d AND q.type = '%s' AND q.entity_id = %d", |
818 | fs, qtype, id); | |
73cf66ba | 819 | |
5eaef520 | 820 | /* quota case of incremental_{before|after} only looks at slot 1 */ |
821 | incr_argv[1] = qtype; | |
73cf66ba | 822 | |
5eaef520 | 823 | incremental_before(table, incr_qual, incr_argv); |
824 | EXEC SQL DELETE FROM quota q WHERE q.filsys_id = :fs AND q.type = :qtype | |
825 | AND q.entity_id = :id; | |
826 | incremental_clear_after(); | |
73cf66ba | 827 | |
5eaef520 | 828 | if (dbms_errno) |
829 | return mr_errcode; | |
830 | flush_name(argv[0], table); | |
73cf66ba | 831 | |
5eaef520 | 832 | EXEC SQL UPDATE tblstats SET deletes = deletes + 1, modtime = SYSDATE |
833 | WHERE table_name = :tname; | |
834 | return MR_SUCCESS; | |
73cf66ba | 835 | } |
836 | ||
73cf66ba | 837 | /* followup_gzcl: |
838 | */ | |
839 | ||
5eaef520 | 840 | int followup_gzcl(struct query *q, struct save_queue *sq, struct validate *v, |
7ac48069 | 841 | int (*action)(int, char *[], void *), void *actarg, |
842 | client *cl) | |
73cf66ba | 843 | { |
b121cf1b | 844 | int i, status; |
5eaef520 | 845 | char **argv; |
846 | ||
847 | while (sq_get_data(sq, &argv)) | |
848 | { | |
849 | mr_trim_args(q->vcnt, argv); | |
850 | ||
5eaef520 | 851 | for (i = 1; i < 8; i += 2) |
852 | { | |
b121cf1b | 853 | status = fix_ace(argv[i], &argv[i + 1]); |
5eaef520 | 854 | if (status && status != MR_NO_MATCH) |
855 | return status; | |
73cf66ba | 856 | } |
73cf66ba | 857 | } |
b121cf1b | 858 | |
859 | return followup_fix_modby(q, sq, v, action, actarg, cl); | |
73cf66ba | 860 | } |
861 | ||
862 | ||
863 | /* followup_gsha: | |
864 | */ | |
865 | ||
5eaef520 | 866 | int followup_gsha(struct query *q, struct save_queue *sq, struct validate *v, |
7ac48069 | 867 | int (*action)(int, char *[], void *), void *actarg, |
868 | client *cl) | |
73cf66ba | 869 | { |
5eaef520 | 870 | char **argv; |
b121cf1b | 871 | int status; |
5eaef520 | 872 | |
873 | while (sq_get_data(sq, &argv)) | |
874 | { | |
875 | mr_trim_args(q->vcnt, argv); | |
876 | ||
b121cf1b | 877 | status = fix_ace(argv[1], &argv[2]); |
5eaef520 | 878 | if (status && status != MR_NO_MATCH) |
879 | return status; | |
73cf66ba | 880 | } |
b121cf1b | 881 | |
882 | return followup_fix_modby(q, sq, v, action, actarg, cl); | |
73cf66ba | 883 | } |
884 | ||
885 | ||
5eaef520 | 886 | int _sdl_followup(struct query *q, char *argv[], client *cl) |
73cf66ba | 887 | { |
85330553 | 888 | if (atoi(argv[0])) |
5eaef520 | 889 | EXEC SQL ALTER SESSION SET SQL_TRACE TRUE; |
890 | else | |
891 | EXEC SQL ALTER SESSION SET SQL_TRACE FALSE; | |
892 | ||
893 | return MR_SUCCESS; | |
73cf66ba | 894 | } |
895 | ||
896 | ||
85330553 | 897 | int trigger_dcm(struct query *q, char *argv[], client *cl) |
73cf66ba | 898 | { |
85330553 | 899 | pid_t pid; |
e688520a | 900 | char prog[MAXPATHLEN]; |
85330553 | 901 | |
902 | sprintf(prog, "%s/startdcm", BIN_DIR); | |
903 | pid = vfork(); | |
904 | switch (pid) | |
5eaef520 | 905 | { |
85330553 | 906 | case 0: |
907 | execl(prog, "startdcm", 0); | |
908 | exit(1); | |
909 | ||
910 | case -1: | |
911 | return errno; | |
912 | ||
73cf66ba | 913 | default: |
85330553 | 914 | return MR_SUCCESS; |
73cf66ba | 915 | } |
916 | } |