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