]> andersk Git - moira.git/blame - server/qfollow.pc
bump version number of alis, ulis, and glin, adding support for the
[moira.git] / server / qfollow.pc
CommitLineData
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 21EXEC SQL INCLUDE sqlca;
7ac48069 22
23RCSID("$Header$");
73cf66ba 24
03c05291 25extern char *whoami, *table_name[];
26extern int dbms_errno, mr_errcode;
73cf66ba 27
28EXEC SQL BEGIN DECLARE SECTION;
29extern char stmt_buf[];
30EXEC SQL END DECLARE SECTION;
31
03c05291 32EXEC 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 42int 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 65int 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 86int 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 107int 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 128int 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 151int 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 173int 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 194int 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 217int 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 239int 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 265int 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 289int 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)
321 ** argv[3] - last name
322 ** argv[4] - first name
323 ** argv[5] - middle name
324 **
325 **/
326
5eaef520 327int 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 */
336 if (strlen(argv[4]) && strlen(argv[5]))
337 sprintf(fullname, "%s %s %s", argv[4], argv[5], argv[3]);
338 else if (strlen(argv[4]))
339 sprintf(fullname, "%s %s", argv[4], argv[3]);
340 else
341 sprintf(fullname, "%s", argv[3]);
73cf66ba 342
5eaef520 343 login = argv[0];
344 who = cl->client_id;
345 entity = cl->entity;
73cf66ba 346
5eaef520 347 /* create finger entry, pobox & set modtime on user */
5eaef520 348 EXEC SQL UPDATE users
349 SET modtime = SYSDATE, modby = :who, modwith = :entity,
350 fullname = NVL(:fullname, CHR(0)), affiliation = type,
351 fmodtime = SYSDATE, fmodby = :who, fmodwith = :entity,
352 potype = 'NONE', pmodtime = SYSDATE, pmodby = :who, pmodwith = :entity
353 WHERE login = :login;
5eaef520 354
5eaef520 355 return MR_SUCCESS;
73cf66ba 356}
5eaef520 357
d6d830a1 358/* followup_gpob: fixes argv[2] and argv[3] based on the pobox type.
359 * Then completes the upcall to the user.
73cf66ba 360 *
d6d830a1 361 * argv[2] is the users_id on input and should be converted to the
362 * pobox name on output. argv[3] is empty on input and should be
363 * converted to an email address on output.
73cf66ba 364 */
365
5eaef520 366int followup_gpob(struct query *q, struct save_queue *sq, struct validate *v,
7ac48069 367 int (*action)(int, char *[], void *), void *actarg,
368 client *cl)
73cf66ba 369{
5eaef520 370 char **argv;
371 char *ptype, *p;
372 int mid, sid, status, i;
d6d830a1 373 EXEC SQL BEGIN DECLARE SECTION;
450849e9 374 int users_id, pid, iid, bid;
d6d830a1 375 char mach[MACHINE_NAME_SIZE], fs[FILESYS_LABEL_SIZE];
376 char str[STRINGS_STRING_SIZE];
377 EXEC SQL END DECLARE SECTION;
5eaef520 378
379 /* for each row */
380 while (sq_get_data(sq, &argv))
381 {
d6d830a1 382 mr_trim_args(4, argv);
5eaef520 383 ptype = argv[1];
d6d830a1 384 users_id = atoi(argv[2]);
5eaef520 385
450849e9 386 EXEC SQL SELECT pop_id, imap_id, box_id INTO :pid, :iid, :bid
387 FROM users WHERE users_id = :users_id;
388 if (sqlca.sqlcode)
389 return MR_USER;
390
391 if (ptype[0] == 'S')
392 {
393 /* SMTP or SPLIT */
394 EXEC SQL SELECT string INTO :str FROM strings
395 WHERE string_id = :bid;
396 if (sqlca.sqlcode)
397 return MR_STRING;
398
399 /* If SMTP, don't bother fetching IMAP and POP boxes. */
400 if (ptype[1] == 'M')
401 pid = iid = 0;
402 }
403 if (iid)
5eaef520 404 {
450849e9 405 /* IMAP, or SPLIT with IMAP */
406 EXEC SQL SELECT f.label, m.name INTO :fs, :mach
407 FROM filesys f, machine m
408 WHERE f.filsys_id = :iid AND f.mach_id = m.mach_id;
409 if (sqlca.sqlcode)
410 return MR_FILESYS;
411 }
412 if (pid)
413 {
414 /* POP, or SPLIT with POP */
d6d830a1 415 EXEC SQL SELECT m.name INTO :mach FROM machine m, users u
416 WHERE u.users_id = :users_id AND u.pop_id = m.mach_id;
417 if (sqlca.sqlcode)
5eaef520 418 return MR_MACHINE;
450849e9 419 }
420
421 free(argv[2]);
422 free(argv[3]);
423
424 /* Now assemble the right answer. */
425 if (!strcmp(ptype, "POP"))
426 {
d6d830a1 427 argv[2] = xstrdup(strtrim(mach));
d6d830a1 428 argv[3] = xmalloc(strlen(argv[0]) + strlen(argv[2]) + 2);
429 sprintf(argv[3], "%s@%s", argv[0], argv[2]);
5eaef520 430 }
431 else if (!strcmp(ptype, "SMTP"))
432 {
d6d830a1 433 argv[2] = xstrdup(strtrim(str));
434 argv[3] = xstrdup(str);
73cf66ba 435 }
f76b37f2 436 else if (!strcmp(ptype, "IMAP"))
437 {
d6d830a1 438 argv[2] = xstrdup(strtrim(fs));
d6d830a1 439 argv[3] = xmalloc(strlen(argv[0]) + strlen(strtrim(mach)) + 2);
440 sprintf(argv[3], "%s@%s", argv[0], mach);
f76b37f2 441 }
450849e9 442 else if (!strcmp(ptype, "SPLIT"))
443 {
444 argv[2] = xstrdup(strtrim(str));
445 argv[3] = xmalloc(strlen(argv[0]) + strlen(strtrim(mach)) +
446 strlen(str) + 4);
447 sprintf(argv[3], "%s@%s, %s", argv[0], mach, str);
448 }
5eaef520 449 else /* ptype == "NONE" */
450 goto skip;
5eaef520 451
452 if (!strcmp(q->shortname, "gpob"))
453 {
d6d830a1 454 sid = atoi(argv[5]);
5eaef520 455 if (sid > 0)
d6d830a1 456 status = id_to_name(sid, USERS_TABLE, &argv[5]);
5eaef520 457 else
d6d830a1 458 status = id_to_name(-sid, STRINGS_TABLE, &argv[5]);
459 if (status && status != MR_NO_MATCH)
460 return status;
73cf66ba 461 }
73cf66ba 462
5eaef520 463 (*action)(q->vcnt, argv, actarg);
73cf66ba 464 skip:
5eaef520 465 /* free saved data */
466 for (i = 0; i < q->vcnt; i++)
467 free(argv[i]);
468 free(argv);
73cf66ba 469 }
470
5eaef520 471 sq_destroy(sq);
472 return MR_SUCCESS;
73cf66ba 473}
474
b121cf1b 475/* Fix an ace_name, based on its type. */
476
477static int fix_ace(char *type, char **name)
478{
479 int id = atoi(*name);
480
481 if (!strcmp(type, "LIST"))
482 return id_to_name(id, LIST_TABLE, name);
483 else if (!strcmp(type, "USER"))
484 return id_to_name(id, USERS_TABLE, name);
485 else if (!strcmp(type, "KERBEROS"))
486 return id_to_name(id, STRINGS_TABLE, name);
487 else
488 {
489 free(*name);
490 if (!strcmp(type, "NONE"))
491 *name = xstrdup("NONE");
492 else
493 *name = xstrdup("???");
494 return MR_SUCCESS;
495 }
496}
73cf66ba 497
b121cf1b 498
499/* followup_gsnt: fix the ace_name and modby */
73cf66ba 500
5eaef520 501int followup_gsnt(struct query *q, struct save_queue *sq, struct validate *v,
7ac48069 502 int (*action)(int, char *[], void *), void *actarg,
503 client *cl)
73cf66ba 504{
b121cf1b 505 char **argv;
506 int status;
5eaef520 507
508 while (sq_get_data(sq, &argv))
509 {
510 mr_trim_args(q->vcnt, argv);
511
b121cf1b 512 status = fix_ace(argv[7], &argv[8]);
5eaef520 513 if (status && status != MR_NO_MATCH)
514 return status;
fde7313c 515 }
516
b121cf1b 517 return followup_fix_modby(q, sq, v, action, actarg, cl);
fde7313c 518}
519
520
b121cf1b 521/* followup_ghst: fix the ace_name, strings and modby */
fde7313c 522
5eaef520 523int followup_ghst(struct query *q, struct save_queue *sq, struct validate *v,
7ac48069 524 int (*action)(int, char *[], void *), void *actarg,
525 client *cl)
fde7313c 526{
b121cf1b 527 char **argv;
528 int id, status;
5eaef520 529
530 while (sq_get_data(sq, &argv))
531 {
532 mr_trim_args(q->vcnt, argv);
533
5eaef520 534 id = atoi(argv[13]);
535 status = id_to_name(id, STRINGS_TABLE, &argv[13]);
536 if (status)
537 return status;
538 id = atoi(argv[14]);
539 status = id_to_name(id, STRINGS_TABLE, &argv[14]);
540 if (status)
541 return status;
542 id = atoi(argv[16]);
543 if (id < 0)
544 status = id_to_name(-id, STRINGS_TABLE, &argv[16]);
545 else
546 status = id_to_name(id, USERS_TABLE, &argv[16]);
547 if (status && status != MR_NO_MATCH)
548 return status;
549
b121cf1b 550 status = fix_ace(argv[11], &argv[12]);
5eaef520 551 if (status && status != MR_NO_MATCH)
552 return status;
73cf66ba 553 }
554
b121cf1b 555 return followup_fix_modby(q, sq, v, action, actarg, cl);
73cf66ba 556}
557
558
b121cf1b 559/* followup_glin: fix the ace_name, modace_name, expiration, and modby */
73cf66ba 560
5eaef520 561int followup_glin(struct query *q, struct save_queue *sq, struct validate *v,
7ac48069 562 int (*action)(int, char *[], void *), void *actarg,
563 client *cl)
73cf66ba 564{
b121cf1b 565 char **argv;
5eaef520 566 int id, i, idx, status;
567
b121cf1b 568 idx = 7;
44da57b2 569 if (!strcmp(q->shortname, "glin") && q->version > 2)
570 idx = 8;
5eaef520 571 if (!strcmp(q->shortname, "gsin"))
b121cf1b 572 idx = 11;
5eaef520 573
574 while (sq_get_data(sq, &argv))
575 {
576 mr_trim_args(q->vcnt, argv);
577
b121cf1b 578 status = fix_ace(argv[idx], &argv[idx + 1]);
5eaef520 579 if (status && status != MR_NO_MATCH)
580 return status;
73cf66ba 581
5eaef520 582 if (!strcmp(q->shortname, "glin") && atoi(argv[6]) == -1)
583 {
e688520a 584 argv[6] = xrealloc(argv[6], strlen(UNIQUE_GID) + 1);
5eaef520 585 strcpy(argv[6], UNIQUE_GID);
73cf66ba 586 }
73cf66ba 587 }
588
b121cf1b 589 return followup_fix_modby(q, sq, v, action, actarg, cl);
73cf66ba 590}
591
1a9a0a59 592int followup_gpsv(struct query *q, struct save_queue *sq, struct validate *v,
593 int (*action)(int, char *[], void *), void *actarg,
594 client *cl)
595{
b121cf1b 596 char **argv;
597 int status;
1a9a0a59 598
599 while (sq_get_data(sq, &argv))
600 {
601 mr_trim_args(q->vcnt, argv);
602
b121cf1b 603 status = fix_ace(argv[PRINTSERVER_OWNER_TYPE],
604 &argv[PRINTSERVER_OWNER_NAME]);
1a9a0a59 605 if (status && status != MR_NO_MATCH)
606 return status;
607 }
608
609 return followup_fix_modby(q, sq, v, action, actarg, cl);
610}
611
73cf66ba 612
613/* followup_gqot: Fix the entity name, directory name & modby fields
614 * argv[0] = filsys_id
615 * argv[1] = type
616 * argv[2] = entity_id
617 * argv[3] = ascii(quota)
618 */
619
5eaef520 620int followup_gqot(struct query *q, struct save_queue *sq, struct validate *v,
7ac48069 621 int (*action)(int, char *[], void *), void *actarg,
622 client *cl)
73cf66ba 623{
44d12d58 624 int j;
5eaef520 625 char **argv;
626 EXEC SQL BEGIN DECLARE SECTION;
627 int id;
628 char *name, *label;
629 EXEC SQL END DECLARE SECTION;
630 int status, idx;
631
632 if (!strcmp(q->name, "get_quota") ||
633 !strcmp(q->name, "get_quota_by_filesys"))
634 idx = 4;
635 else
636 idx = 3;
b121cf1b 637
5eaef520 638 while (sq_get_data(sq, &argv))
639 {
640 if (idx == 4)
641 {
642 switch (argv[1][0])
643 {
73cf66ba 644 case 'U':
5eaef520 645 status = id_to_name(atoi(argv[2]), USERS_TABLE, &argv[2]);
646 break;
73cf66ba 647 case 'G':
648 case 'L':
5eaef520 649 status = id_to_name(atoi(argv[2]), LIST_TABLE, &argv[2]);
650 break;
73cf66ba 651 case 'A':
5eaef520 652 free(argv[2]);
e688520a 653 argv[2] = xstrdup("system:anyuser");
5eaef520 654 break;
73cf66ba 655 default:
5eaef520 656 id = atoi(argv[2]);
e688520a 657 argv[2] = xmalloc(8);
5eaef520 658 sprintf(argv[2], "%d", id);
73cf66ba 659 }
660 }
5eaef520 661 id = atoi(argv[idx]);
662 free(argv[idx]);
e688520a 663 argv[idx] = xmalloc(id ? NFSPHYS_DIR_SIZE : FILESYS_NAME_SIZE);
5eaef520 664 name = argv[idx];
e688520a 665 name[0] = '\0';
5eaef520 666 if (id == 0)
667 {
668 label = argv[0];
669 EXEC SQL SELECT name INTO :name FROM filesys
670 WHERE label = :label;
73cf66ba 671 }
5eaef520 672 else
673 {
674 EXEC SQL SELECT dir INTO :name FROM nfsphys
675 WHERE nfsphys_id = :id;
73cf66ba 676 }
5eaef520 677 if (sqlca.sqlerrd[2] != 1)
678 sprintf(argv[idx], "#%d", id);
679
680 id = atoi(argv[idx + 3]);
681 if (id > 0)
682 status = id_to_name(id, USERS_TABLE, &argv[idx + 3]);
683 else
684 status = id_to_name(-id, STRINGS_TABLE, &argv[idx + 3]);
685 if (status && status != MR_NO_MATCH)
686 return status;
687 (*action)(q->vcnt, argv, actarg);
688 for (j = 0; j < q->vcnt; j++)
689 free(argv[j]);
690 free(argv);
73cf66ba 691 }
5eaef520 692 sq_destroy(sq);
693 return MR_SUCCESS;
73cf66ba 694}
695
696
697/* followup_aqot: Add allocation to nfsphys after creating quota.
698 * argv[0] = filsys_id
699 * argv[1] = type if "add_quota" or "update_quota"
700 * argv[2 or 1] = id
701 * argv[3 or 2] = ascii(quota)
702 */
703
5eaef520 704int followup_aqot(struct query *q, char *argv[], client *cl)
73cf66ba 705{
5eaef520 706 EXEC SQL BEGIN DECLARE SECTION;
707 int quota, id, fs, who, physid, table;
708 char *entity, *qtype, *tname;
709 EXEC SQL END DECLARE SECTION;
710 char incr_qual[60];
711 char *incr_argv[2];
712 int status;
713
714 table = q->rtable;
715 tname = table_name[table];
716 fs = *(int *)argv[0];
717 EXEC SQL SELECT phys_id INTO :physid FROM filesys
718 WHERE filsys_id = :fs;
719 if (dbms_errno)
720 return mr_errcode;
721
722 if (!strcmp(q->shortname, "aqot") || !strcmp(q->shortname, "uqot"))
723 {
724 qtype = argv[1];
725 id = *(int *)argv[2];
726 quota = atoi(argv[3]);
727 sprintf(incr_qual, "q.filsys_id = %d", fs);
728 }
729 else
730 {
731 qtype = "USER";
732 id = *(int *)argv[1];
733 quota = atoi(argv[2]);
734 sprintf(incr_qual, "q.filsys_id = %d AND q.type = '%s' AND "
735 "q.entity_id = %d", fs, qtype, id);
73cf66ba 736 }
737
5eaef520 738 /* quota case of incremental_{before|after} only looks at slot 1 */
739 incr_argv[1] = qtype;
740
741 /* Follows one of many possible gross hacks to fix these particular
742 * conflicts between what is possible in the query table and what
743 * is possible in SQL.
744 */
745 if (q->type == APPEND)
746 {
747 incremental_clear_before();
748 EXEC SQL INSERT INTO quota
749 (filsys_id, type, entity_id, quota, phys_id)
750 VALUES (:fs, NVL(:qtype, CHR(0)), :id, :quota, :physid);
751 incremental_after(table, incr_qual, incr_argv);
752 }
753 else
754 {
755 incremental_before(table, incr_qual, incr_argv);
756 EXEC SQL UPDATE quota SET quota = :quota
757 WHERE filsys_id = :fs AND type = :qtype AND entity_id = :id;
758 status = mr_errcode;
759 incremental_after(table, incr_qual, incr_argv);
73cf66ba 760 }
761
5eaef520 762 if (dbms_errno)
763 return mr_errcode;
764 flush_name(argv[0], table);
765 if (q->type == APPEND)
766 {
767 EXEC SQL UPDATE tblstats SET appends = appends + 1, modtime = SYSDATE
768 WHERE table_name = :tname;
769 }
770 else
771 {
772 EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE
773 WHERE table_name = :tname;
73cf66ba 774 }
5eaef520 775
776 /* Proceed with original followup */
777 who = cl->client_id;
778 entity = cl->entity;
779
780 EXEC SQL UPDATE quota
781 SET modtime = SYSDATE, modby = :who, modwith = :entity
782 WHERE filsys_id = :fs and type = :qtype and entity_id = :id;
783 EXEC SQL UPDATE nfsphys SET allocated = allocated + :quota
784 WHERE nfsphys_id = :physid;
785 if (dbms_errno)
786 return mr_errcode;
787 return MR_SUCCESS;
73cf66ba 788}
789
790
791/* Necessitated by the requirement of a correlation name by the incremental
5eaef520 792 * routines, since query table deletes don't provide one.
73cf66ba 793 */
5eaef520 794int followup_dqot(struct query *q, char **argv, client *cl)
73cf66ba 795{
5eaef520 796 char *qtype;
797 int id, fs, table;
798 char *incr_argv[2];
799 EXEC SQL BEGIN DECLARE SECTION;
800 char incr_qual[80], *tname;
801 EXEC SQL END DECLARE SECTION;
802
803 table = q->rtable;
804 tname = table_name[table];
805 fs = *(int *)argv[0];
806 if (!strcmp(q->shortname, "dqot"))
807 {
808 qtype = argv[1];
809 id = *(int *)argv[2];
810 }
811 else
812 {
813 qtype = "USER";
814 id = *(int *)argv[1];
73cf66ba 815 }
5eaef520 816 sprintf(incr_qual, "q.filsys_id = %d AND q.type = '%s' AND q.entity_id = %d",
817 fs, qtype, id);
73cf66ba 818
5eaef520 819 /* quota case of incremental_{before|after} only looks at slot 1 */
820 incr_argv[1] = qtype;
73cf66ba 821
5eaef520 822 incremental_before(table, incr_qual, incr_argv);
823 EXEC SQL DELETE FROM quota q WHERE q.filsys_id = :fs AND q.type = :qtype
824 AND q.entity_id = :id;
825 incremental_clear_after();
73cf66ba 826
5eaef520 827 if (dbms_errno)
828 return mr_errcode;
829 flush_name(argv[0], table);
73cf66ba 830
5eaef520 831 EXEC SQL UPDATE tblstats SET deletes = deletes + 1, modtime = SYSDATE
832 WHERE table_name = :tname;
833 return MR_SUCCESS;
73cf66ba 834}
835
73cf66ba 836/* followup_gzcl:
837 */
838
5eaef520 839int followup_gzcl(struct query *q, struct save_queue *sq, struct validate *v,
7ac48069 840 int (*action)(int, char *[], void *), void *actarg,
841 client *cl)
73cf66ba 842{
b121cf1b 843 int i, status;
5eaef520 844 char **argv;
845
846 while (sq_get_data(sq, &argv))
847 {
848 mr_trim_args(q->vcnt, argv);
849
5eaef520 850 for (i = 1; i < 8; i += 2)
851 {
b121cf1b 852 status = fix_ace(argv[i], &argv[i + 1]);
5eaef520 853 if (status && status != MR_NO_MATCH)
854 return status;
73cf66ba 855 }
73cf66ba 856 }
b121cf1b 857
858 return followup_fix_modby(q, sq, v, action, actarg, cl);
73cf66ba 859}
860
861
862/* followup_gsha:
863 */
864
5eaef520 865int followup_gsha(struct query *q, struct save_queue *sq, struct validate *v,
7ac48069 866 int (*action)(int, char *[], void *), void *actarg,
867 client *cl)
73cf66ba 868{
5eaef520 869 char **argv;
b121cf1b 870 int status;
5eaef520 871
872 while (sq_get_data(sq, &argv))
873 {
874 mr_trim_args(q->vcnt, argv);
875
b121cf1b 876 status = fix_ace(argv[1], &argv[2]);
5eaef520 877 if (status && status != MR_NO_MATCH)
878 return status;
73cf66ba 879 }
b121cf1b 880
881 return followup_fix_modby(q, sq, v, action, actarg, cl);
73cf66ba 882}
883
884
5eaef520 885int _sdl_followup(struct query *q, char *argv[], client *cl)
73cf66ba 886{
85330553 887 if (atoi(argv[0]))
5eaef520 888 EXEC SQL ALTER SESSION SET SQL_TRACE TRUE;
889 else
890 EXEC SQL ALTER SESSION SET SQL_TRACE FALSE;
891
892 return MR_SUCCESS;
73cf66ba 893}
894
895
85330553 896int trigger_dcm(struct query *q, char *argv[], client *cl)
73cf66ba 897{
85330553 898 pid_t pid;
e688520a 899 char prog[MAXPATHLEN];
85330553 900
901 sprintf(prog, "%s/startdcm", BIN_DIR);
902 pid = vfork();
903 switch (pid)
5eaef520 904 {
85330553 905 case 0:
906 execl(prog, "startdcm", 0);
907 exit(1);
908
909 case -1:
910 return errno;
911
73cf66ba 912 default:
85330553 913 return MR_SUCCESS;
73cf66ba 914 }
915}
This page took 0.214442 seconds and 5 git commands to generate.