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