]> andersk Git - moira.git/blame - server/qrtn.qc
make sure we sum up duplicate quotas correctly
[moira.git] / server / qrtn.qc
CommitLineData
d26cae4e 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
83526631 6 * Copyright (C) 1987, 1988 by the Massachusetts Institute of Technology
7ee33a8d 7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
faad6f39 9 *
d26cae4e 10 */
11
12#ifndef lint
13static char *rcsid_qrtn_qc = "$Header$";
14#endif lint
15
7ee33a8d 16#include <mit-copyright.h>
97479f6f 17#include "query.h"
97479f6f 18#include "sms_server.h"
19
20char *Argv[16];
21
ca7c2f3d 22int ingres_errno = 0;
23int sms_errcode = 0;
24## int query_timeout = 30;
7536027d 25extern char *whoami;
83526631 26extern FILE *journal;
97479f6f 27
8fcb440e 28#define INGRES_BAD_INT 4111
29#define INGRES_BAD_DATE 4302
4a7b7001 30#define INGRES_DEADLOCK 4700
ca7c2f3d 31#define INGRES_TIMEOUT 4702
8fcb440e 32
d26cae4e 33/*
34 * ingerr: (supposedly) called when Ingres indicates an error.
35 * I have not yet been able to get this to work to intercept a
36 * database open error.
37 */
38
39static int ingerr(num)
40 int *num;
97479f6f 41{
ca7c2f3d 42 ingres_errno = *num;
8fcb440e 43
44 switch (*num) {
45 case INGRES_BAD_INT:
ca7c2f3d 46 sms_errcode = SMS_INTEGER;
8fcb440e 47 break;
48 case INGRES_BAD_DATE:
ca7c2f3d 49 sms_errcode = SMS_DATE;
8fcb440e 50 break;
4a7b7001 51 case INGRES_DEADLOCK:
ca7c2f3d 52 sms_errcode = SMS_DEADLOCK;
7ee33a8d 53 com_err(whoami, 0, "INGRES deadlock detected");
ca7c2f3d 54 break;
55 case INGRES_TIMEOUT:
56 sms_errcode = SMS_BUSY;
57 com_err(whoami, 0, "timed out getting lock");
4a7b7001 58 break;
8fcb440e 59 default:
ca7c2f3d 60 sms_errcode = SMS_INGRES_ERR;
8fcb440e 61 com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
0a7ae10e 62 critical_alert("SMS", "SMS server encountered INGRES ERROR %d", *num);
8fcb440e 63 return (*num);
64 }
65 return (0);
97479f6f 66}
67
d26cae4e 68int sms_open_database()
97479f6f 69{
d26cae4e 70 register int i;
83526631 71 char *malloc();
73c902bf 72 static first_open = 1;
97479f6f 73
73c902bf 74 if (first_open) {
75 first_open = 0;
97479f6f 76
73c902bf 77 /* initialize local argv */
78 for (i = 0; i < 16; i++)
79 Argv[i] = malloc(ARGLEN);
80
81 IIseterr(ingerr);
82 incremental_init();
83 flush_cache();
84 }
97479f6f 85
d26cae4e 86 ingres_errno = 0;
73c902bf 87
d26cae4e 88 /* open the database */
89## ingres sms
ca7c2f3d 90## set lockmode session where level = table, timeout = query_timeout
45266a6f 91## set lockmode on capacls where readlock = shared
92## set lockmode on alias where readlock = shared
d26cae4e 93 return ingres_errno;
97479f6f 94}
95
d26cae4e 96int sms_close_database()
97479f6f 97{
73c902bf 98 flush_cache();
d26cae4e 99## exit
97479f6f 100}
101
7536027d 102sms_check_access(cl, name, argc, argv_ro)
103 client *cl;
104 char *name;
105 int argc;
106 char *argv_ro[];
107{
9969e1bc 108 struct query *q;
7536027d 109 struct query *get_query_by_name();
7536027d 110
ca7c2f3d 111 ingres_errno = 0;
112
83526631 113 q = get_query_by_name(name, cl->args->sms_version_no);
9969e1bc 114 if (q == (struct query *)0)
115 return(SMS_NO_HANDLE);
7536027d 116
9969e1bc 117 return(sms_verify_query(cl, q, argc, argv_ro));
7536027d 118}
119
120sms_process_query(cl, name, argc, argv_ro, action, actarg)
121 client *cl;
d26cae4e 122 char *name;
123 int argc;
124 char *argv_ro[];
125 int (*action)();
126 char *actarg;
97479f6f 127{
d26cae4e 128 register struct query *q;
7536027d 129 register int status;
7536027d 130 register struct validate *v;
7536027d 131 char qual[256];
cc1231a1 132 char sort[32];
7536027d 133 char *pqual;
cc1231a1 134 char *psort;
6a84801f 135## char *table, *rvar;
7536027d 136 struct save_queue *sq;
d26cae4e 137 struct query *get_query_by_name();
7536027d 138 int sq_save_args();
139 struct save_queue *sq_create();
cc1231a1 140 char *build_sort();
d26cae4e 141
ca7c2f3d 142 ingres_errno = 0;
143
7536027d 144 /* list queries command */
145 if (!strcmp(name, "_list_queries")) {
83526631 146 list_queries(cl->args->sms_version_no, action, actarg);
7536027d 147 return(SMS_SUCCESS);
148 }
149
150 /* help query command */
151 if (!strcmp(name, "_help")) {
83526631 152 if (argc < 1)
153 return(SMS_ARGS);
154 q = get_query_by_name(argv_ro[0], cl->args->sms_version_no);
7536027d 155 if (q == (struct query *)0) return(SMS_NO_HANDLE);
156 help_query(q, action, actarg);
157 return(SMS_SUCCESS);
158 }
159
160 /* get query structure, return error if named query does not exist */
83526631 161 q = get_query_by_name(name, cl->args->sms_version_no);
7536027d 162 if (q == (struct query *)0) return(SMS_NO_HANDLE);
163 v = q->validate;
164
7ee33a8d 165 if (q->type != RETRIEVE) {
d353058b 166## begin transaction
7ee33a8d 167 }
d353058b 168
9969e1bc 169 /* setup argument vector, verify access and arguments */
170 if ((status = sms_verify_query(cl, q, argc, argv_ro)) != SMS_SUCCESS)
d353058b 171 goto out;
7536027d 172
173 /* perform any special query pre-processing */
174 if (v && v->pre_rtn) {
175 status = (*v->pre_rtn)(q, Argv, cl, 0);
9969e1bc 176 if (status != SMS_SUCCESS)
d353058b 177 goto out;
7536027d 178 }
179
d26cae4e 180 switch (q->type) {
faad6f39 181 case RETRIEVE:
7536027d 182 /* for queries that do not permit wildcarding, check if row
183 uniquely exists */
184 if (v && v->field) {
185 status = validate_row(q, Argv, v);
186 if (status != SMS_EXISTS) break;
187 }
188
189 /* build "where" clause if needed */
d26cae4e 190 if (q->qual) {
191 build_qual(q->qual, q->argc, Argv, qual);
7536027d 192 pqual = qual;
193 } else {
194 pqual = 0;
195 }
196
cc1231a1 197 /* build "sort" clause if needed */
198 if (v && v->valobj) {
199 psort = build_sort(v, sort);
200 } else {
201 psort = 0;
202 }
203
7536027d 204 /* if there is a followup routine, then we must save the results */
205 /* of the first query for use by the followup routine */
cc1231a1 206 /* if q->rvar = NULL, perform post_rtn only */
207 if (q->rvar) {
7536027d 208 if (v && v->post_rtn) {
209 sq = sq_create();
cc1231a1 210 status = do_retrieve(q, pqual, psort, sq_save_args, sq);
7536027d 211 if (status != SMS_SUCCESS) {
212 sq_destroy(sq);
213 break;
214 }
83526631 215 status = (*v->post_rtn)(q, sq, v, action, actarg, cl);
7536027d 216 } else {
217 /* normal retrieve */
cc1231a1 218 status = do_retrieve(q, pqual, psort, action, actarg);
7536027d 219 }
220 if (status != SMS_SUCCESS) break;
7536027d 221 } else {
83526631 222 status = (*v->post_rtn)(q, Argv, cl, action, actarg);
7536027d 223 }
224
d26cae4e 225 break;
226
faad6f39 227 case UPDATE:
7536027d 228 /* see if row already exists */
229 if (v->field) {
230 status = validate_row(q, Argv, v);
231 if (status != SMS_EXISTS) break;
232 }
233
234 /* build "where" clause and perform update */
cc1231a1 235 /* if q->rvar = NULL, perform post_rtn only */
236 if (q->rvar) {
7536027d 237 build_qual(q->qual, q->argc, Argv, qual);
2755928d 238 incremental_before(q->rtable, qual, argv_ro);
7536027d 239 status = do_update(q, &Argv[q->argc], qual, action, actarg);
2755928d 240 incremental_after(q->rtable, qual, argv_ro);
7536027d 241 if (status != SMS_SUCCESS) break;
73c902bf 242 flush_name(argv_ro[0], q->rtable);
cc1231a1 243 table = q->rtable;
37e49d47 244 if (strcmp(q->shortname, "sshi") && strcmp(q->shortname, "ssif")) {
245## repeat replace tblstats (updates = tblstats.updates + 1,
246## modtime = "now")
247## where tblstats.#table = @table
248 }
d26cae4e 249 }
7536027d 250
251 /* execute followup routine (if any) */
83526631 252 if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl);
7536027d 253
d26cae4e 254 break;
97479f6f 255
faad6f39 256 case APPEND:
7536027d 257 /* see if row already exists */
258 if (v->field) {
259 status = validate_row(q, Argv, v);
260 if (status != SMS_NO_MATCH) break;
d26cae4e 261 }
7536027d 262
263 /* increment id number if necessary */
d353058b 264 if (v->object_id) {
83526631 265 status = set_next_object_id(v->object_id, q->rtable);
d353058b 266 if (status != SMS_SUCCESS) break;
267 }
7536027d 268
cc1231a1 269 /* build "where" clause if needed */
270 if (q->qual) {
271 build_qual(q->qual, q->argc, Argv, qual);
272 pqual = qual;
273 } else {
274 pqual = 0;
275 }
276
7536027d 277 /* perform the append */
cc1231a1 278 /* if q->rvar = NULL, perform post_rtn only */
279 if (q->rvar) {
2755928d 280 incremental_clear_before();
cc1231a1 281 status = do_append(q, &Argv[q->argc], pqual, action, actarg);
7536027d 282 if (status != SMS_SUCCESS) break;
2755928d 283 if (v && v->object_id) {
284 sprintf(qual, "%s.%s = values.value and values.name = \"%s\"",
285 q->rvar, v->object_id, v->object_id);
286 incremental_after(q->rtable, qual, argv_ro);
287 } else
288 incremental_after(q->rtable, pqual, argv_ro);
289
cc1231a1 290 table = q->rtable;
7536027d 291## repeat replace tblstats (appends = tblstats.appends + 1,
292## modtime = "now")
293## where tblstats.#table = @table
294 }
295
296 /* execute followup routine */
83526631 297 if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl);
d26cae4e 298 break;
97479f6f 299
faad6f39 300 case DELETE:
7536027d 301 /* see if row already exists */
302 if (v->field) {
303 status = validate_row(q, Argv, v);
304 if (status != SMS_EXISTS) break;
305 }
306
307 /* build "where" clause and perform delete */
cc1231a1 308 /* if q->rvar = NULL, perform post_rtn only */
309 if (q->rvar) {
7536027d 310 build_qual(q->qual, q->argc, Argv, qual);
6a84801f 311 table = q->rtable;
312 rvar = q->rvar;
313## range of rvar is table
2755928d 314 incremental_before(q->rtable, qual, argv_ro);
7536027d 315 status = do_delete(q, qual, action, actarg);
2755928d 316 incremental_clear_after();
7536027d 317 if (status != SMS_SUCCESS) break;
73c902bf 318 flush_name(argv_ro[0], q->rtable);
7536027d 319## repeat replace tblstats (deletes = tblstats.deletes + 1,
320## modtime = "now")
321## where tblstats.#table = @table
97479f6f 322 }
7536027d 323
324 /* execute followup routine */
83526631 325 if (v->post_rtn) status = (*v->post_rtn)(q, Argv, cl);
d26cae4e 326 break;
7536027d 327
d26cae4e 328 }
7536027d 329
d353058b 330out:
e83ef509 331 if (status == SMS_SUCCESS && ingres_errno != 0) {
332 com_err(whoami, SMS_INTERNAL, "Server didn't notice INGRES ERROR %d",
333 ingres_errno);
334 status = sms_errcode;
335 }
336
3df9e21e 337 if (q->type != RETRIEVE) {
338 if (status == SMS_SUCCESS) {
d353058b 339## end transaction /* commit to this */
83526631 340 if (journal) {
341 char buf[1024], *bp;
342 int i;
343 extern time_t now;
344
345 fprintf(journal, "%% %s %s %s",
346 cl->clname, cl->entity, ctime(&now));
347 fprintf(journal, "%s[%d] ", q->name, cl->args->sms_version_no);
348 for (i = 0; i < argc; i++) {
349 if (i != 0) {
350 putc(' ', journal);
351 }
352 requote(buf, argv_ro[i], sizeof(buf));
353 fputs(buf, journal);
354 }
355 putc('\n', journal);
356 fflush(journal);
357 }
2755928d 358 incremental_update();
3df9e21e 359 } else {
ca7c2f3d 360 if (ingres_errno != INGRES_DEADLOCK) {
7ee33a8d 361## abort /* it never happened */
362 }
2755928d 363 incremental_flush();
3df9e21e 364 }
ca7c2f3d 365## set lockmode session where readlock = system
366 }
367
1bf7f927 368 if (status != SMS_SUCCESS && log_flags & LOG_RES)
369 com_err(whoami, status, " (Query failed)");
7536027d 370 return(status);
97479f6f 371}
372
373build_qual(fmt, argc, argv, qual)
374 char *fmt;
375 int argc;
376 char *argv[];
377 char *qual;
378{
7536027d 379 register char *c;
380 register int i;
381 char *args[4];
83526631 382 char *index();
7536027d 383
384 c = fmt;
385 for (i = 0; i < argc; i++) {
83526631 386 c = index(c, '%');
7536027d 387 if (c++ == (char *)0) return(SMS_ARGS);
388 if (*c == 's')
389 args[i] = argv[i];
390 else if (*c == 'd')
391 *(int *)&args[i] = *(int *)argv[i]; /* sigh */
392 else
393 return(SMS_INGRES_ERR);
394 }
395
d26cae4e 396 switch (argc) {
397 case 0:
398 strcpy(qual, fmt);
399 break;
400
401 case 1:
7536027d 402 sprintf(qual, fmt, args[0]);
d26cae4e 403 break;
404
405 case 2:
7536027d 406 sprintf(qual, fmt, args[0], args[1]);
d26cae4e 407 break;
408
409 case 3:
7536027d 410 sprintf(qual, fmt, args[0], args[1], args[2]);
d26cae4e 411 break;
412
413 case 4:
7536027d 414 sprintf(qual, fmt, args[0], args[1], args[2], args[3]);
d26cae4e 415 break;
416 }
83526631 417 return(SMS_SUCCESS);
97479f6f 418}
419
cc1231a1 420char *
421build_sort(v, sort)
422 register struct validate *v;
423 char *sort;
424{
425 register struct valobj *vo;
426 register int n;
427 char elem[16];
428
429 n = v->objcnt;
430 vo = v->valobj;
431 *sort = 0;
432
433 while (--n >= 0) {
434 if (vo->type == V_SORT) {
435 sprintf(elem, "RET_VAR%d", vo->index + 1);
436 if (*sort) strcat(sort, ", ");
437 strcat(sort, elem);
438 }
439 vo++;
440 }
441
442 return ((*sort) ? sort : 0);
443}
444
9969e1bc 445
446/* Build arguement vector, verify query and arguments */
447
448sms_verify_query(cl, q, argc, argv_ro)
449 client *cl;
450 struct query *q;
451 int argc;
452 char *argv_ro[];
453{
454 register int argreq;
455 register int status;
456 register struct validate *v = q->validate;
457 register int i;
458 register int privileged = 0;
02d466cf 459 int len;
9969e1bc 460
461 /* copy the arguments into a local argv that we can modify */
7ee33a8d 462 if (argc >= QMAXARGS)
463 return(SMS_ARGS);
9969e1bc 464 for (i = 0; i < argc; i++) {
02d466cf 465 if ((len = strlen(argv_ro[i])) < ARGLEN)
9969e1bc 466 strcpy(Argv[i], argv_ro[i]);
467 else
468 return(SMS_ARG_TOO_LONG);
02d466cf 469 if (Argv[i][len-1] == '\\')
470 return(SMS_BAD_CHAR);
9969e1bc 471 }
472
473 /* check initial query access */
474 status = check_query_access(q, Argv, cl);
475 if (status != SMS_SUCCESS && status != SMS_PERM)
476 return(status);
477 if (status == SMS_SUCCESS)
478 privileged++;
479
480 /* check argument count */
481 argreq = q->argc;
482 if (q->type == UPDATE || q->type == APPEND) argreq += q->vcnt;
483 if (argc != argreq) return(SMS_ARGS);
484
485 /* validate arguments */
486 if (v && v->valobj) {
487 status = validate_fields(q, Argv, v->valobj, v->objcnt);
488 if (status != SMS_SUCCESS) return(status);
489 }
490
491 /* perform special query access check */
492 if (!privileged && v && v->acs_rtn) {
493 status = (*v->acs_rtn)(q, Argv, cl);
494 if (status != SMS_SUCCESS && status != SMS_PERM)
495 return(status);
496 if (status == SMS_SUCCESS)
497 privileged++;
498 }
499
500 return(privileged ? SMS_SUCCESS : SMS_PERM);
501}
502
2755928d 503
504/* This routine caches info from the database. Each query acl is stored
505 * in the query structure, and whether that acl contains everybody.
506 */
507
7536027d 508check_query_access(q, argv, cl)
509 struct query *q;
510 char *argv[];
511 client *cl;
d26cae4e 512##{
7536027d 513## char *name;
514## int acl_id;
515## int exists;
d26cae4e 516## int rowcount;
cc1231a1 517## int errorno;
7536027d 518## static int def_uid;
519 int status;
520 int client_id;
521 char *client_type;
522
7536027d 523 /* initialize default uid */
524 if (def_uid == 0) {
525## retrieve (def_uid = users.users_id) where users.login = "default"
d26cae4e 526 }
97479f6f 527
2755928d 528 /* get query access control list */
529 if (q->acl != 0)
530 acl_id = q->acl;
531 else {
532 name = q->shortname;
73c902bf 533## retrieve (acl_id = capacls.list_id) where capacls.tag = name
2755928d 534## inquire_equel (rowcount = "rowcount", errorno = "errorno")
535 if (errorno != 0) return(SMS_INGRES_ERR);
536 if (rowcount == 0) return(SMS_PERM);
537 q->acl = acl_id;
538
539 /* check for default access */
73c902bf 540## retrieve (exists = any(imembers.#member_id where
541## imembers.list_id = acl_id and
542## imembers.member_type = "USER" and
543## imembers.#member_id = def_uid))
2755928d 544 q->everybody = exists;
545 }
546
547 if (q->everybody)
548 return(SMS_SUCCESS);
549
db8a5dda 550 if (get_client(cl, &client_type, &client_id) != SMS_SUCCESS)
551 return(SMS_PERM);
552 if (find_member("LIST", acl_id, client_type, client_id, 0))
2755928d 553 return(SMS_SUCCESS);
554 else
555 return(SMS_PERM);
556##}
557
558
7536027d 559get_client(cl, client_type, client_id)
560 client *cl;
561 char **client_type;
562 int *client_id;
2755928d 563{
564 if (cl->users_id > 0) {
83526631 565 *client_id = cl->users_id;
7536027d 566 *client_type = "USER";
83526631 567 return(SMS_SUCCESS);
7536027d 568 }
83526631 569
2755928d 570 if (cl->client_id < 0) {
571 *client_id = -cl->users_id;
572 *client_type = "KERBEROS";
573 return(SMS_SUCCESS);
574 }
7536027d 575
2755928d 576 return(SMS_PERM);
577}
97479f6f 578
dff355ae 579##find_member(list_type, list_id, member_type, member_id)
83526631 580 char *list_type;
7536027d 581## int list_id;
582## char *member_type;
583## int member_id;
7536027d 584##{
dff355ae 585## int exists, errorno;
7536027d 586
e45a151a 587 if (!strcmp(strtrim(list_type), strtrim(member_type)) &&
588 list_id == member_id)
589 return(1);
590
7536027d 591 /* see if client is a direct member of list */
2755928d 592## repeat retrieve (exists = any(imembers.#member_id where
593## imembers.#list_id = @list_id and
594## imembers.#member_type = @member_type and
595## imembers.#member_id = @member_id))
dff355ae 596## inquire_equel(errorno = "errorno")
597 if (errorno == 0)
598 return(exists);
599 else
600 return(0);
d26cae4e 601##}
97479f6f 602
83526631 603
cc1231a1 604do_retrieve(q, pqual, psort, action, actarg)
d26cae4e 605 register struct query *q;
cc1231a1 606 char *pqual;
607 char *psort;
d26cae4e 608 int (*action)();
609 char *actarg;
610##{
611## char *rvar;
612## char *rtable;
613## char *cqual;
cc1231a1 614## char *csort;
d26cae4e 615## int rowcount;
cc1231a1 616## int errorno;
83526631 617 static char **vaddrs = (char **)NULL;
618
619 if (!vaddrs) {
620 register int i;
621
622 if ((vaddrs = (char **)malloc(sizeof(char *) * QMAXARGS)) == NULL) {
623 com_err(whoami, SMS_NO_MEM, "setting up static argv");
624 exit(1);
625 }
626 for (i = 0; i < QMAXARGS; i++) {
627 if ((vaddrs[i] = malloc(QMAXARGSIZE)) == NULL) {
628 com_err(whoami, SMS_NO_MEM, "setting up static argv");
629 exit(1);
630 }
631 }
632 }
7536027d 633
d26cae4e 634 if (q->rvar) {
635 rvar = q->rvar;
636 rtable = q->rtable;
637## range of rvar is rtable
638 }
97479f6f 639
cc1231a1 640 if (psort) {
641 csort = psort;
642 if (pqual) {
643 cqual = pqual;
83526631 644## retrieve unique (param (q->tlist, vaddrs)) where cqual
cc1231a1 645## sort by csort
646## {
83526631 647 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 648## }
649 } else {
83526631 650## retrieve unique (param (q->tlist, vaddrs))
cc1231a1 651## sort by csort
652## {
83526631 653 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 654## }
655 }
656
7536027d 657 } else {
cc1231a1 658 if (pqual) {
659 cqual = pqual;
83526631 660## retrieve unique (param (q->tlist, vaddrs)) where cqual
cc1231a1 661## {
83526631 662 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 663## }
664 } else {
83526631 665## retrieve unique (param (q->tlist, vaddrs))
cc1231a1 666## {
83526631 667 (*action)(q->vcnt, vaddrs, actarg);
cc1231a1 668## }
669 }
7536027d 670 }
97479f6f 671
cc1231a1 672## inquire_equel (rowcount = "rowcount", errorno = "errorno")
673 if (errorno != 0) return(SMS_INGRES_ERR);
7536027d 674 return ((rowcount == 0) ? SMS_NO_MATCH : SMS_SUCCESS);
d26cae4e 675##}
97479f6f 676
e38c941b 677do_update(q, argv, qual, action, actarg)
d26cae4e 678 register struct query *q;
679 char *argv[];
680 char *qual;
681 int (*action)();
682 char *actarg;
683##{
684## char *rvar;
685## char *rtable;
686## char *cqual;
cc1231a1 687## int errorno;
97479f6f 688
d26cae4e 689 rvar = q->rvar;
690 rtable = q->rtable;
691## range of rvar is rtable
97479f6f 692
d26cae4e 693 cqual = qual;
694## replace rvar (param (q->tlist, argv))
695## where cqual
97479f6f 696
cc1231a1 697## inquire_equel (errorno = "errorno")
4a7b7001 698 if (errorno == INGRES_BAD_INT)
8fcb440e 699 return(SMS_INTEGER);
700 else if (errorno != 0)
701 return(SMS_INGRES_ERR);
7536027d 702 return(SMS_SUCCESS);
d26cae4e 703##}
97479f6f 704
cc1231a1 705do_append(q, argv, pqual, action, actarg)
d26cae4e 706 register struct query *q;
707 char *argv[];
cc1231a1 708 char *pqual;
d26cae4e 709 int (*action)();
710 char *actarg;
711##{
712## char *rvar;
713## char *rtable;
7536027d 714## char *cqual;
cc1231a1 715## int errorno;
97479f6f 716
d26cae4e 717 rvar = q->rvar;
718 rtable = q->rtable;
719## range of rvar is rtable
97479f6f 720
cc1231a1 721 if (pqual) {
722 cqual = pqual;
7536027d 723## append to rtable (param (q->tlist, argv)) where cqual
724 } else {
725## append to rtable (param (q->tlist, argv))
726 }
97479f6f 727
cc1231a1 728## inquire_equel (errorno = "errorno")
8fcb440e 729 if (errorno == INGRES_BAD_INT)
730 return(SMS_INTEGER);
731 else if (errorno != 0)
732 return(SMS_INGRES_ERR);
7536027d 733 return(SMS_SUCCESS);
d26cae4e 734##}
97479f6f 735
e38c941b 736do_delete(q, qual, action, actarg)
d26cae4e 737 register struct query *q;
738 char *qual;
739 int (*action)();
740 char *actarg;
741##{
742## char *rvar;
743## char *rtable;
744## char *cqual;
cc1231a1 745## int errorno;
97479f6f 746
d26cae4e 747 rvar = q->rvar;
748 rtable = q->rtable;
749## range of rvar is rtable
97479f6f 750
d26cae4e 751 cqual = qual;
752## delete rvar where cqual
97479f6f 753
cc1231a1 754## inquire_equel (errorno = "errorno")
755 if (errorno != 0) return(SMS_INGRES_ERR);
7536027d 756 return(SMS_SUCCESS);
d26cae4e 757##}
97479f6f 758
d26cae4e 759
83526631 760/**
761 ** set_next_object_id - set next object id in values table
762 **
763 ** Inputs: object - object name in values table and in objects
764 ** table - name of table objects are found in
765 **
766 ** - called before an APPEND operation to set the next object id to
767 ** be used for the new record to the next free value
768 **
769 **/
770
771set_next_object_id(object, table)
772 char *object;
773 char *table;
774##{
775## char *name, *tbl;
776## int rowcount, exists, value;
777
778 name = object;
779 tbl = table;
73c902bf 780## repeat retrieve (value = values.#value) where values.#name = @name
83526631 781## inquire_equel(rowcount = "rowcount")
782 if (rowcount != 1)
8fcb440e 783 return(SMS_NO_ID);
83526631 784
785## retrieve (exists = any(tbl.name where tbl.name = value))
786## inquire_equel(rowcount = "rowcount")
787 if (rowcount != 1)
8fcb440e 788 return(SMS_NO_ID);
83526631 789 while (exists) {
790 value++;
8fcb440e 791 if (value > MAX_ID_VALUE)
792 value = MIN_ID_VALUE;
83526631 793## retrieve (exists = any(tbl.name where tbl.name = value))
794 }
795
796 if (LOG_RES)
797 com_err(whoami, 0, "setting ID %s to %d", name, value);
73c902bf 798## repeat replace values (#value = @value) where values.#name = @name
83526631 799 return(SMS_SUCCESS);
800##}
801
802
2755928d 803/* Turn a kerberos name into the user's ID of the account that principal
804 * owns. Sets the kerberos ID and user ID.
805 */
806
807set_krb_mapping(name, login, ok, kid, uid)
808char *name;
809char *login;
810int ok;
811int *kid;
812int *uid;
813##{
814## int u_id, k_id, rowcount;
815## char *krbname;
816
817 krbname = name;
818 *kid = 0;
819 *uid = 0;
820
73c902bf 821## repeat retrieve (u_id = krbmap.#users_id, k_id = krbmap.#string_id)
822## where krbmap.string_id = strings.string_id and strings.string = @krbname
2755928d 823## inquire_equel (rowcount = "rowcount")
824
825 if (rowcount == 1) {
826 *kid = -k_id;
827 *uid = u_id;
828 return;
829 }
830
73c902bf 831 if (name_to_id(name, "STRING", &k_id) == SMS_SUCCESS)
832 *kid = -k_id;
2755928d 833
834 if (!ok) {
835 *uid = *kid;
836 return;
837 }
838
73c902bf 839 if (name_to_id(login, "USER", uid) != SMS_SUCCESS)
840 *uid = 0;
841
2755928d 842 if (*kid == 0)
843 *kid = *uid;
844##}
845
846
83526631 847/* For now this just checks the argc's. It should also see that there
848 * are no duplicate names.
849 */
850
851sanity_check_queries()
852{
853 register int i;
854 int maxv = 0, maxa = 0;
c5a0c32c 855#ifdef MULTIPROTOCOLS
83526631 856 extern int QueryCount1, QueryCount2;
857 extern struct query Queries1[], Queries2[];
c5a0c32c 858#else
859 extern int QueryCount2;
860 extern struct query Queries2[];
861#endif MULTIPROTOCOLS
862
83526631 863#define MAX(x,y) ((x) > (y) ? (x) : (y))
864
c5a0c32c 865#ifdef MULTIPROTOCOLS
83526631 866 for (i = 0; i < QueryCount1; i++) {
867 maxv = MAX(maxv, Queries1[i].vcnt);
868 maxa = MAX(maxa, Queries1[i].argc);
869 }
c5a0c32c 870#endif MULTIPROTOCOLS
83526631 871 for (i = 0; i < QueryCount2; i++) {
872 maxv = MAX(maxv, Queries2[i].vcnt);
873 maxa = MAX(maxa, Queries2[i].argc);
874 }
875 if (MAX(maxv, maxa) > QMAXARGS) {
876 com_err(whoami, 0, "A query has more args than QMAXARGS");
877 exit(1);
878 }
879}
This page took 0.210977 seconds and 5 git commands to generate.