From 99e09b48bde566e0226862a4f904a00347ec9eee Mon Sep 17 00:00:00 2001 From: genoa Date: Tue, 4 Aug 1992 12:02:02 +0000 Subject: [PATCH] Version prior to beginning synchronization with opssrc version. --- server/cache.dc | 2 +- server/increment.dc | 83 +---------- server/qrtn.dc | 87 ++++++----- server/qsupport.dc | 287 ++++++++++++++++++++++-------------- server/queries2.c | 350 +++++++++++++++++++++++++++++++------------- 5 files changed, 478 insertions(+), 331 deletions(-) diff --git a/server/cache.dc b/server/cache.dc index 346245da..e1b66a2c 100644 --- a/server/cache.dc +++ b/server/cache.dc @@ -146,7 +146,7 @@ int *id; break; case 'M': case 'm': - EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=uppercase(:iname); + EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=UPPERCASE(:iname); break; case 'C': case 'c': diff --git a/server/increment.dc b/server/increment.dc index 8d9d5c51..a44ea882 100644 --- a/server/increment.dc +++ b/server/increment.dc @@ -125,13 +125,6 @@ char **argv; beforetable = table; if (!strcmp(table, "users")) { -/* - * retrieve (barg0 = u.login, barg1 = text(u.uid), - * barg2 = u.shell, barg3 = u.last, barg4 = u.first, - * barg5 = u.middle, barg6 = text(u.status), - * barg7 = u.mit_id, barg8 = u.mit_year) - * where qual - */ EXEC SQL SELECT login, CHAR(uid), shell, last, first, middle, CHAR(status), clearid, type INTO :barg0, :barg1, :barg2, :barg3, :barg4, :barg5, :barg6, @@ -139,17 +132,10 @@ char **argv; FROM users WHERE :qual; beforec = 9; } else if (!strcmp(table, "machine")) { -/* - * retrieve (barg0 = m.name, barg1 = m.type) where qual - */ EXEC SQL SELECT name, type INTO :barg0, :barg1 FROM machine WHERE :qual; beforec = 2; } else if (!strcmp(table, "cluster")) { -/* - * retrieve (barg0 = c.name, barg1 = c.desc, barg2 = c.location) - * where qual - */ EXEC SQL SELECT name, description, location INTO :barg0, :barg1, :barg2 FROM cluster WHERE :qual; @@ -164,17 +150,8 @@ char **argv; strcpy(barg2, argv[2]); beforec = 3; } else if (!strcmp(table, "filesys")) { -/* - * range of fs is filesys - * retrieve (barg0 = fs.label, barg1 = fs.type, barg2 = text(fs.mach_id), - * barg3 = fs.name, barg4 = fs.mount, barg5 = fs.access, - * barg6 = fs.comments, barg7 = text(fs.owner), - * barg8 = text(fs.owners), barg9 = text(fs.createflg), - * barg10 = fs.lockertype) - * where qual - */ EXEC SQL SELECT label, type, CHAR(mach_id), name, mount, access, - comments, CHAR(owner), CHAR(owners), CHAR(createflag), lockertype + comments, CHAR(owner), CHAR(owners), CHAR(createflg), lockertype INTO :barg0, :barg1, :barg2, :barg3, :barg4, :barg5, :barg6, :barg7, :barg8, :barg9, :barg10 FROM filesys WHERE :qual; @@ -185,22 +162,10 @@ char **argv; strcpy(barg2, "?"); sprintf(buffer, "%s and fs.filsys_id = q.filsys_id", qual); qual = buffer; -/* - * range of q is quota - * retrieve (barg3 = text(q.quota), barg4 = filesys.name) where qual - */ EXEC SQL SELECT q.quota, fs.name INTO :barg3, :barg4 FROM quota q, filesys fs WHERE :qual; beforec = 5; } else if (!strcmp(table, "list")) { -/* - * retrieve (barg0 = l.name, barg1 = text(l.active), - * barg2 = text(l.public), barg3 = text(l.hidden), - * barg4 = text(l.maillist), barg5 = text(l.group), - * barg6 = text(l.gid), barg7 = l.acl_type, - * barg8 = text(l.acl_id), barg9 = l.desc) - * where qual - */ EXEC SQL SELECT name, CHAR(active), CHAR(publicflg), CHAR(hidden), CHAR(maillist), CHAR(grouplist), CHAR(gid), acl_type, CHAR(acl_id), description @@ -210,9 +175,6 @@ char **argv; beforec = 10; } else if (!strcmp(table, "members")) { id = (int) argv[0]; -/* - * retrieve (barg3 = text(list.group)) where list.list_id = id - */ EXEC SQL SELECT CHAR(grouplist) INTO :barg3 FROM list WHERE list_id = :id; name = malloc(0); @@ -264,13 +226,6 @@ EXEC SQL END DECLARE SECTION; char **copy_argv(); if (!strcmp(table, "users")) { -/* - * retrieve (aarg0 = u.login, aarg1 = text(u.uid), - * aarg2 = u.shell, aarg3 = u.last, aarg4 = u.first, - * aarg5 = u.middle, aarg6 = text(u.status), - * aarg7 = u.mit_id, aarg8 = u.mit_year) - * where qual - */ EXEC SQL SELECT login, CHAR(uid), shell, last, first, middle, CHAR(status), clearid, type INTO :aarg0, :aarg1, :aarg2, :aarg3, :aarg4, :aarg5, @@ -278,17 +233,10 @@ EXEC SQL END DECLARE SECTION; FROM users WHERE :qual; afterc = 9; } else if (!strcmp(table, "machine")) { -/* - * retrieve (aarg0 = m.name, aarg1 = m.type) where qual - */ EXEC SQL SELECT name, type INTO :aarg0, :aarg1 FROM machine WHERE :qual; afterc = 2; } else if (!strcmp(table, "cluster")) { -/* - * retrieve (aarg0 = c.name, aarg1 = c.desc, aarg2 = c.location) - * where qual - */ EXEC SQL SELECT name, description, location INTO :aarg0, :aarg1, :aarg2 FROM cluster WHERE :qual; @@ -303,18 +251,8 @@ EXEC SQL END DECLARE SECTION; strcpy(aarg2, argv[2]); afterc = 3; } else if (!strcmp(table, "filesys")) { -/* - * range of fs is filesys - * retrieve (aarg0 = fs.label, aarg1 = fs.type, - * aarg2 = text(fs.mach_id), - * aarg3 = fs.name, aarg4 = fs.mount, aarg5 = fs.access, - * aarg6 = fs.comments, aarg7 = text(fs.owner), - * aarg8 = text(fs.owners), aarg9 = text(fs.createflg), - * aarg10 = fs.lockertype) - * where qual - */ - EXEC SQL SELECT label, type, CHAR(mach_id), name, mount, access, - comments, CHAR(owner), CHAR(owners), CHAR(createflag), lockertype + EXEC SQL SELECT CHAR(label), type, CHAR(mach_id), name, mount, access, + comments, CHAR(owner), CHAR(owners), CHAR(createflg), lockertype INTO :aarg0, :aarg1, :aarg2, :aarg3, :aarg4, :aarg5, :aarg6, :aarg7, :aarg8, :aarg9, :aarg10 FROM filesys fs WHERE :qual; @@ -325,22 +263,10 @@ EXEC SQL END DECLARE SECTION; strcpy(aarg2, "?"); sprintf(buffer, "%s and fs.filsys_id = q.filsys_id", qual); qual = buffer; -/* - * range of q is quota - * retrieve (aarg3 = text(q.quota), aarg4 = filesys.name) where qual - */ EXEC SQL SELECT CHAR(q.quota), fs.name INTO :aarg3, :aarg4 FROM quota q, filesys fs WHERE :qual; afterc = 5; } else if (!strcmp(table, "list")) { -/* - * retrieve (aarg0 = l.name, aarg1 = text(l.active), - * aarg2 = text(l.public), aarg3 = text(l.hidden), - * aarg4 = text(l.maillist), aarg5 = text(l.group), - * aarg6 = text(l.gid), aarg7 = l.acl_type, - * aarg8 = text(l.acl_id), aarg9 = l.desc) - * where qual - */ EXEC SQL SELECT name, CHAR(active), CHAR(publicflg), CHAR(hidden), CHAR(maillist), CHAR(grouplist), CHAR(gid), acl_type, CHAR(acl_id), description @@ -350,9 +276,6 @@ EXEC SQL END DECLARE SECTION; afterc = 10; } else if (!strcmp(table, "members")) { id = (int) argv[0]; -/* - * retrieve (aarg3 = text(list.group)) where list.list_id = id - */ EXEC SQL SELECT CHAR(grouplist) INTO :aarg3 FROM list WHERE list_id = :id; name = malloc(0); diff --git a/server/qrtn.dc b/server/qrtn.dc index 97e8e1b6..7a13219f 100644 --- a/server/qrtn.dc +++ b/server/qrtn.dc @@ -540,17 +540,23 @@ mr_verify_query(cl, q, argc, argv_ro) register struct validate *v = q->validate; register int i; register int privileged = 0; - int len; + register char *to,*fr,*stop; /* copy the arguments into a local argv that we can modify */ if (argc >= QMAXARGS) return(MR_ARGS); for (i = 0; i < argc; i++) { - if ((len = strlen(argv_ro[i])) < ARGLEN) - strcpy(Argv[i], argv_ro[i]); - else - return(MR_ARG_TOO_LONG); - if (Argv[i][len-1] == '\\') + /* Single quotes must be doubled for SQL */ + for (to=Argv[i], fr=argv_ro[i], stop=to+ARGLEN; (*fr) && (totlist,vaddrs,pqual); if(psort) { strcat(stmt_buf," ORDER BY "); strcat(stmt_buf,psort); } EXEC SQL PREPARE stmt INTO :SQLDA USING NAMES FROM :stmt_buf; - if(ingres_errno) - return(mr_errcode); - if((mr_errcode=mr_check_SQLDA(SQLDA)) != MR_SUCCESS) - return(mr_errcode); + if(sqlca.sqlcode) + return(MR_INTERNAL); EXEC SQL DECLARE csr001 CURSOR FOR stmt; EXEC SQL OPEN csr001; rowcount = 0; @@ -744,36 +748,37 @@ build_sql_stmt(result_buf,cmd,targetlist,argv,qual) char *qual; { char fmt_buf[MR_STMTBUF_LEN]; - char tmp_buf[16]; - register char *res=result_buf, *tmp=tmp_buf, *fmt=fmt_buf; - register int state; - - sprintf(fmt_buf,"%s %s",cmd,targetlist); - if(qual) { strcat(fmt_buf," WHERE "); strcat(fmt_buf,qual); } - - for(state=0;*fmt != '\0';fmt++) { - switch(state) { - case 0: - if(*fmt=='%') { /* formatting -> tmp */ - *tmp++ = *fmt; - state=1; - } else *res++ = *fmt; /* text -> res */ - break; - case 1: - if((*fmt=='%') && (tmp==tmp_buf+1)) { /* %% -> % */ - *res++ = *fmt; - tmp=tmp_buf; - state=0; - } else if(isalpha(*fmt) && (*fmt!='h') && (*fmt!='l')) { /* end of formatting */ - *tmp++ = *fmt; - *tmp='\0'; - tmp=tmp_buf; - sprintf(res,tmp_buf,*argv++); /* print to result buffer */ - while(*++res) ; - state=0; - } else *tmp++ = *fmt; /* keep copying the formatting to tmp */ - break; - } + register char *res, *fmt; + + if(qual) + sprintf(fmt_buf,"%s %s WHERE %s",cmd,targetlist,qual); + else + sprintf(fmt_buf,"%s %s",cmd,targetlist); + + for(res=result_buf, fmt=fmt_buf; *fmt; fmt++) { + if(*fmt=='%') { + if(*++fmt) { + switch(*fmt) { + case '%': /* %% -> % */ + *res++ = *fmt; + break; + case 's': + if(*argv[0]) { + *res='\0'; + strcat(res,*argv); + while(*++res) ; + } + argv++; + break; + case 'd': + sprintf(res,"%d",*(int *)*argv++); /* print to result buffer */ + while(*++res) ; + break; + default: /* Swallow other %? pairs */ + break; + } + } else break; + } else *res++ = *fmt; /* text -> result buffer */ } *res='\0'; } @@ -852,6 +857,8 @@ set_next_object_id(object, table_name, limit) sprintf(stmt_buf,"SELECT %s FROM %s WHERE %s=%d",object,table_name,object,value); EXEC SQL PREPARE stmt INTO :SQLDA USING NAMES FROM :stmt_buf; + if(sqlca.sqlcode) + return(MR_INTERNAL); EXEC SQL DECLARE csr002 CURSOR FOR stmt; EXEC SQL OPEN csr002; EXEC SQL FETCH csr002 USING DESCRIPTOR :SQLDA; diff --git a/server/qsupport.dc b/server/qsupport.dc index 6fca31de..92b7d76f 100644 --- a/server/qsupport.dc +++ b/server/qsupport.dc @@ -641,10 +641,10 @@ int setup_dlis(q, argv) if (sqlca.sqlerrd[2] > 0) return(MR_IN_USE); EXEC SQL REPEATED SELECT class INTO :cdummy FROM zephyr z - WHERE zephyr.xmt_type = 'LIST' AND z.xmt_id = :id - OR z.sub_type = 'LIST' AND z.sub_id = :id - OR z.iws_type = 'LIST' AND z.iws_id = :id - OR z.iui_type = 'LIST' AND z.iui_id = :id; + WHERE z.xmt_type = 'LIST' AND z.xmt_id = :id + OR z.sub_type = 'LIST' AND z.sub_id = :id + OR z.iws_type = 'LIST' AND z.iws_id = :id + OR z.iui_type = 'LIST' AND z.iui_id = :id; if (sqlca.sqlerrd[2] > 0) return(MR_IN_USE); if (ingres_errno) @@ -914,6 +914,26 @@ setup_dfil(q, argv, cl) } +/* setup_aftg: needed only because using the query table would + * create an invalid SQL statement. *sigh* Basically just validates + * that the first argument has type 'FSGROUP' in table 'filesys'. + */ + +setup_aftg(q, argv, cl) + struct query *q; + char **argv; + client *cl; +{ + EXEC SQL SELECT filsys_id INTO :idummy FROM filesys + WHERE type='FSGROUP'; + + if (sqlca.sqlcode != 0) + return(MR_NO_MATCH); /* Is there a better error code to return? */ + + return(MR_SUCCESS); +} + + /* setup_dnfp: check to see that the nfs physical partition does not have * any filesystems assigned to it before allowing it to be deleted. */ @@ -1044,8 +1064,7 @@ set_modtime(q, argv, cl) table = q->rtable; name = argv[0]; - sprintf(stmt_buf,"UPDATE %s SET modtime = 'now', modby = %d, \ -modwith = '%s' WHERE %s.name = '%s'",table,who,entity,table,name); + sprintf(stmt_buf,"UPDATE %s SET modtime = 'now', modby = %d, modwith = '%s' WHERE %s.name = LEFT('%s',SIZE(%s.name))",table,who,entity,table,name,table); EXEC SQL EXECUTE IMMEDIATE :stmt_buf; return(MR_SUCCESS); @@ -1119,8 +1138,8 @@ set_pobox_modtime(q, argv, cl) who = cl->client_id; users_id = *(int *)argv[0]; - EXEC SQL UPDATE users SET pmodtime='now', pmodby = :who, pmodwith = entity - WHERE users.users_id = users_id; + EXEC SQL UPDATE users SET pmodtime='now', pmodby = :who, pmodwith = :entity + WHERE users.users_id = :users_id; return(MR_SUCCESS); } @@ -1134,17 +1153,15 @@ set_uppercase_modtime(q, argv, cl) char **argv; client *cl; { - char *name, *entity, *table, *c; + char *name, *entity, *table; int who; entity = cl->entity; who = cl->client_id; table = q->rtable; name = argv[0]; - for(c=name;*c;c++) if(islower(*c)) *c = toupper(*c); /** INGRES has an uppercase() functiuons, but it's not portable. */ - sprintf(stmt_buf,"UPDATE %s SET modtime = 'now', modby = %d, \ -modwith = '%s' WHERE %s.name = '%s'",table,who,entity,table,name); + sprintf(stmt_buf,"UPDATE %s SET modtime = 'now', modby = %d, modwith = '%s' WHERE %s.name = UPPERCASE(LEFT('%s',SIZE(%s.name)))",table,who,entity,table,name,table); EXEC SQL EXECUTE IMMEDIATE :stmt_buf; return(MR_SUCCESS); @@ -1275,7 +1292,7 @@ set_filesys_modtime(q, argv, cl) EXEC SQL UPDATE filesys SET modtime = 'now', modby = :who, modwith = :entity, phys_id = :var_phys_id - WHERE label = :label; + WHERE label = LEFT(:label,SIZE(label)); return(MR_SUCCESS); } @@ -1300,7 +1317,7 @@ set_zephyr_modtime(q, argv, cl) class = argv[0]; EXEC SQL UPDATE zephyr SET modtime = 'now', modby = :who, modwith = :entity - WHERE class = :class; + WHERE class = LEFT(:class,SIZE(class)); return(MR_SUCCESS); } @@ -1509,7 +1526,7 @@ followup_gpob(q, sq, v, action, actarg, cl) { char **argv, *index(); char *ptype, *p; - int mid, sid, status; + int mid, sid, status, i; /* for each row */ while (sq_get_data(sq, &argv)) { @@ -1545,9 +1562,8 @@ followup_gpob(q, sq, v, action, actarg, cl) (*action)(q->vcnt, argv, actarg); skip: /* free saved data */ - free(argv[0]); - free(argv[1]); - free(argv[4]); + for (i = 0; i < q->vcnt; i++) + free(argv[i]); free(argv); } @@ -1992,10 +2008,11 @@ get_list_info(q, aargv, cl, action, actarg) returned = rowcount = 0; name = aargv[0]; + convert_wildcards(name); sq = sq_create(); EXEC SQL DECLARE csr102 CURSOR FOR SELECT list_id FROM list - WHERE name = :name; + WHERE name LIKE :name ESCAPE '*'; EXEC SQL OPEN csr102; while(1) { @@ -2018,17 +2035,6 @@ get_list_info(q, aargv, cl, action, actarg) if (id == 0) continue; argv[6] = gid_str; -/* - * repeat retrieve (listname = l.#name, active = text(l.#active), - * public = text(l.#public), hidden = text(l.#hidden), - * hid = l.#hidden, maillist = text(l.#maillist), - * group = text(l.#group), gid = text(l.#gid), - * acl_type = trim(l.#acl_type), acl_id = l.#acl_id, - * desc = l.#desc, modtime = l.#modtime, modby_id = l.#modby, - * modwith =l.#modwith) - * where l.list_id = :id - */ - /** Won't the TRIM() die a horrible INGRES death? **/ EXEC SQL REPEATED SELECT name, CHAR(active), CHAR(publicflg), CHAR(hidden), hidden, CHAR(maillist), CHAR(grouplist), CHAR(gid), TRIM(acl_type), acl_id, description, CHAR(modtime), modby, modwith @@ -2105,11 +2111,6 @@ int add_member_to_list(q, argv, cl) mtype = argv[1]; mid = *(int *)argv[2]; /* if the member is already a direct member of the list, punt */ -/* - * repeat retrieve (exists = any(m.list_id where m.list_id=@lid and - * m.member_id = :mid and m.member_type = :mtype - * and m.direct = 1)) - */ EXEC SQL REPEATED SELECT list_id INTO :idummy FROM imembers WHERE list_id = :lid AND member_id = :mid AND member_type = :mtype AND direct = 1; @@ -2196,14 +2197,9 @@ int add_member_to_list(q, argv, cl) if (mid == lid && !strcmp(mtype, "LIST")) { return(MR_LISTLOOP); } -/* - * repeat retrieve (exists = any(m.ref_count where m.list_id = :lid - * and m.member_id = :mid - * and m.member_type = :mtype)) - */ EXEC SQL REPEATED SELECT ref_count INTO :idummy FROM imembers WHERE list_id = :lid AND member_id = :mid - AND m.member_type = :mtype; + AND member_type = :mtype; ref = aref[a] * dref[d]; if (sqlca.sqlerrd[2] > 0) { if (a == 0 && d == 0) { @@ -2267,11 +2263,6 @@ int delete_member_from_list(q, argv, cl) mtype = argv[1]; mid = *(int *)argv[2]; /* if the member is not a direct member of the list, punt */ -/* - * repeat retrieve (exists = any(m.list_id where m.list_id=@lid and - * m.member_id = :mid and m.member_type = :mtype - * and m.direct = 1)) - */ EXEC SQL REPEATED SELECT list_id INTO :idummy FROM imembers WHERE list_id = :lid AND member_id = :mid AND member_type = :mtype AND direct = 1; @@ -2648,13 +2639,6 @@ int get_lists_of_member(q, argv, cl, action, actarg) rargv[4] = maillist; rargv[5] = grouplist; if (direct) { -/* - * repeat retrieve (name = list.#name, active = text(list.#active), - * public = text(list.#public), hidden = text(list.#hidden), - * maillist = text(list.#maillist), group = text(list.#group)) - * where list.list_id = m.list_id and m.direct = 1 and - * m.member_type = :atype and m.member_id = :aid - */ EXEC SQL DECLARE csr117a CURSOR FOR SELECT name, CHAR(active), CHAR(publicflg), CHAR(hidden), CHAR(maillist), CHAR(grouplist) @@ -2939,8 +2923,8 @@ int qualified_get(q, argv, action, actarg, start, range, field, flags) rargv[0] = SQLDA->sqlvar[0].sqldata; sprintf(stmt_buf,"SELECT %s.%s FROM %s %s WHERE %s",q->rtable,field,q->rtable,q->rvar,qual); EXEC SQL PREPARE stmt INTO :SQLDA USING NAMES FROM :stmt_buf; - if((mr_errcode=mr_check_SQLDA(SQLDA)) != MR_SUCCESS) - return(mr_errcode); + if(sqlca.sqlcode) + return(MR_INTERNAL); EXEC SQL DECLARE csr123 CURSOR FOR stmt; EXEC SQL OPEN csr123; while(1) { @@ -3029,7 +3013,7 @@ register_user(q, argv, cl) EXEC SQL BEGIN DECLARE SECTION; char *login, dir[65], *entity, *directory, machname[33]; int who, rowcount, mid, uid, users_id, flag, utype, nid, list_id, quota; - int size, alloc, pid, m_id, ostatus, nstatus, gidval, fsidval; + int size, alloc, pid, m_id, ostatus, nstatus, gidval, fsidval, npidval; EXEC SQL END DECLARE SECTION; char buffer[256], *aargv[3]; int maxsize; @@ -3053,28 +3037,36 @@ register_user(q, argv, cl) /* check new login name */ EXEC SQL REPEATED SELECT login INTO :cdummy FROM users - WHERE login = :login AND users_id != :users_id; + WHERE login = LEFT(:login,SIZE(login)) AND users_id != :users_id; if (ingres_errno) return(mr_errcode); if (sqlca.sqlerrd[2] > 0) return(MR_IN_USE); EXEC SQL REPEATED SELECT name INTO :cdummy FROM list - WHERE name = :login; + WHERE name = LEFT(:login,SIZE(name)); if (ingres_errno) return(mr_errcode); if (sqlca.sqlerrd[2] > 0) return(MR_IN_USE); EXEC SQL REPEATED SELECT label INTO :cdummy FROM filesys - WHERE label = :login; + WHERE label = LEFT(:login,SIZE(label)); if (ingres_errno) return(mr_errcode); if (sqlca.sqlerrd[2] > 0) return(MR_IN_USE); com_err(whoami, 0, "login name OK"); /* choose place for pobox, put in mid */ - EXEC SQL REPEATED SELECT sh.mach_id, m.name - INTO :mid, :machname FROM serverhosts sh, machine m - WHERE sh.service='POP' AND sh.value2 - sh.value1 = - (SELECT MAX(value2 - value1) FROM serverhosts - WHERE service = 'POP'); - if (ingres_errno) return(mr_errcode); - if (sqlca.sqlerrd[2] == 0) - return(MR_NO_POBOX); + EXEC SQL DECLARE csr130 CURSOR FOR + SELECT sh.mach_id, m.name FROM serverhosts sh, machine m + WHERE sh.service='POP' AND sh.mach_id=m.mach_id + AND sh.value2 - sh.value1 = + (SELECT MAX(value2 - value1) FROM serverhosts + WHERE service = 'POP'); + EXEC SQL OPEN csr130; + EXEC SQL FETCH csr130 INTO :mid, :machname; + if (sqlca.sqlerrd[2] == 0) { + EXEC SQL CLOSE csr130; + if (ingres_errno) return(mr_errcode); + return(MR_NO_POBOX); + } else { + EXEC SQL CLOSE csr130; + if (ingres_errno) return(mr_errcode); + } /* change login name, set pobox */ sprintf(buffer, "users.users_id = %d", users_id); @@ -3117,7 +3109,7 @@ register_user(q, argv, cl) if (ingres_errno) return(mr_errcode); if (sqlca.sqlerrd[2] != 1) return(MR_INTERNAL); - sprintf(buffer, "l.list_id = %d", list_id); + sprintf(buffer, "list_id = %d", list_id); incremental_after("list", buffer, 0); aargv[0] = (char *) list_id; aargv[1] = "USER"; @@ -3135,12 +3127,13 @@ register_user(q, argv, cl) maxsize = 0; directory = NULL; EXEC SQL DECLARE csr125 CURSOR FOR - SELECT mach_id, trim(nfsphys.dir), nfsphys_id, status, size, allocated + SELECT mach_id, trim(dir), nfsphys_id, status, partsize, allocated FROM nfsphys; EXEC SQL OPEN csr125; while(1) { EXEC SQL FETCH csr125 INTO :mid, :dir, :nid, :flag, :size, :alloc; - if(sqlca.sqlcode != 0) break; + if(sqlca.sqlcode) + break; if ((flag & utype) && (size != 0) && (size - alloc > maxsize)) { maxsize = size - alloc; if (directory) @@ -3172,9 +3165,8 @@ register_user(q, argv, cl) if (ingres_errno) return(mr_errcode); if (sqlca.sqlerrd[2] != 1) return(MR_INTERNAL); - incremental_after("filesys", - "fs.filsys_id = numvalues.value and numvalues.name = 'filsys_id'", - 0); + sprintf(buffer,"fs.filsys_id = %d",fsidval); + incremental_after("filesys", buffer, 0); com_err(whoami, 0, "filesys on mach %d in %s/%s", m_id, directory, login); @@ -3185,8 +3177,6 @@ register_user(q, argv, cl) if (sqlca.sqlerrd[2] != 1) return(MR_NO_QUOTA); incremental_clear_before(); - EXEC SQL SELECT value INTO :fsidval FROM numvalues - WHERE numvalues.name = 'filsys_id'; EXEC SQL REPEATED INSERT INTO quota (entity_id, filsys_id, type, quota, phys_id, modtime, modby, modwith) VALUES @@ -3194,17 +3184,17 @@ register_user(q, argv, cl) if (ingres_errno) return(mr_errcode); if (sqlca.sqlerrd[2] != 1) return(MR_INTERNAL); + EXEC SQL SELECT phys_id INTO :npidval FROM filesys + WHERE filsys_id=:fsidval; EXEC SQL REPEATED UPDATE nfsphys SET allocated=allocated + :quota - WHERE nfsphys_id = filesys.phys_id - AND filesys.filsys_id = numvalues.value - AND numvalues.name = 'filsys_id'; + WHERE nfsphys.nfsphys_id = :npidval; if (ingres_errno) return(mr_errcode); if (sqlca.sqlerrd[2] != 1) return(MR_INTERNAL); aargv[0] = login; aargv[1] = "USER"; aargv[2] = login; - sprintf(buffer, "q.entity_id = %d and q.filsys_id = numvalues.value and q.type = 'USER' and numvalues.name = 'filsys_id'", users_id); + sprintf(buffer, "q.entity_id = %d and q.filsys_id = %d and q.type = 'USER'", users_id, fsidval); incremental_after("quota", buffer, aargv); com_err(whoami, 0, "quota of %d assigned", quota); if (ingres_errno) return(mr_errcode); @@ -3263,12 +3253,6 @@ validate_row(q, argv, v) /* build where clause */ build_qual(v->qual, v->argc, argv, qual); -#ifdef NEVER - /** I'm pretty sure we don't need this now */ - /* setup ingres variables */ - name = v->field; -#endif - if (log_flags & LOG_VALID) /* tell the logfile what we're doing */ com_err(whoami, 0, "validating row: %s", qual); @@ -3276,6 +3260,8 @@ validate_row(q, argv, v) /* look for the record */ sprintf(stmt_buf,"SELECT COUNT (*) FROM %s WHERE %s",q->rtable,qual); EXEC SQL PREPARE stmt INTO :SQLDA USING NAMES FROM :stmt_buf; + if(sqlca.sqlcode) + return(MR_INTERNAL); EXEC SQL DECLARE csr126 CURSOR FOR stmt; EXEC SQL OPEN csr126; EXEC SQL FETCH csr126 USING DESCRIPTOR :SQLDA; @@ -3352,6 +3338,15 @@ validate_fields(q, argv, vo, n) case V_LOCK: status = lock_table(vo); break; + + case V_WILD: + status = convert_wildcards(argv[vo->index]); + break; + + case V_UPWILD: + status = convert_wildcards_uppercase(argv[vo->index]); + break; + } if (status != MR_EXISTS) return(status); @@ -3447,6 +3442,8 @@ validate_id(q, argv, vo) sprintf(stmt_buf,"SELECT %s FROM %s WHERE %s = '%s'",idfield,tbl,namefield,name); } EXEC SQL PREPARE stmt INTO :SQLDA USING NAMES FROM :stmt_buf; + if(sqlca.sqlcode) + return(MR_INTERNAL); EXEC SQL DECLARE csr127 CURSOR FOR stmt; EXEC SQL OPEN csr127; rowcount=0; @@ -3460,8 +3457,8 @@ validate_id(q, argv, vo) if (ingres_errno) return(mr_errcode); - if (rowcount != 1) return(vo->error); - *argv[vo->index] = *SQLDA->sqlvar[0].sqldata; + if (rowcount != 1) return(vo->error); + bcopy(SQLDA->sqlvar[0].sqldata,argv[vo->index],sizeof(int)); return(MR_EXISTS); } @@ -3486,6 +3483,8 @@ validate_name(argv, vo) sprintf(stmt_buf,"SELECT DISTINCT COUNT(*) FROM %s WHERE %s.%s = '%s'", tbl,tbl,namefield,name); EXEC SQL PREPARE stmt INTO :SQLDA USING NAMES FROM :stmt_buf; + if(sqlca.sqlcode) + return(MR_INTERNAL); EXEC SQL DECLARE csr128 CURSOR FOR stmt; EXEC SQL OPEN csr128; EXEC SQL FETCH csr128 USING DESCRIPTOR :SQLDA; @@ -3507,9 +3506,6 @@ validate_date(argv, vo) EXEC SQL END DECLARE SECTION; idate = argv[vo->index]; -/* - * retrieve (dd = interval("years", date(idate) - date("today"))) - */ EXEC SQL SELECT interval('years',date(:idate)-date('today')) INTO :dd; if (sqlca.sqlcode != 0 || dd > 5.0) return(MR_DATE); @@ -3542,12 +3538,11 @@ struct valobj *vo; if (idfield == 0) { if (!strcmp(argv[vo->index], argv[vo->index - 1])) return(MR_EXISTS); -/* - * retrieve (id = any(table.namefield where table.namefield = name)) - */ - sprintf(stmt_buf,"SELECT %s FROM %s WHERE %s.%s = '%s'", - namefield,tbl,tbl,namefield,name); + sprintf(stmt_buf,"SELECT %s FROM %s WHERE %s = LEFT('%s',SIZE(%s))", + namefield,tbl,namefield,name,namefield); EXEC SQL PREPARE stmt INTO :SQLDA USING NAMES FROM :stmt_buf; + if(sqlca.sqlcode) + return(MR_INTERNAL); EXEC SQL DECLARE csr129 CURSOR FOR stmt; EXEC SQL OPEN csr129; EXEC SQL FETCH csr129 USING DESCRIPTOR :SQLDA; @@ -3740,23 +3735,13 @@ MR_SQLDA_T *mr_alloc_SQLDA() } -/* Use mr_check_SQLDA before OPEN CURSOR or EXECUTE */ -mr_check_SQLDA(da) - MR_SQLDA_T *da; -{ - if(da->sqld > da->sqln) { - com_err(whoami, MR_INTERNAL, - "Internal arg count error preparing for dynamic query"); - return(MR_INTERNAL); - } - - return(MR_SUCCESS); -} - /* Use this after FETCH USING DESCRIPTOR one or more * result columns may contain NULLs. This routine is * not currently needed, since db/schema creates all * columns with a NOT NULL WITH DEFAULT clause. + * + * This is currently dead flesh, since no Moira columns + * allow null values; all use default values. */ mr_fix_nulls_in_SQLDA(da) MR_SQLDA_T *da; @@ -3823,4 +3808,90 @@ prefetch_value(q,argv,cl) return(MR_SUCCESS); } +/* prefetch_filesys(): + * Fetches the phys_id from filesys based on the filsys_id in argv[0]. + * Appends the filsys_id and the phys_id to the argv so they can be + * referenced in an INSERT into a table other than filesys. Also + * see comments at prefetch_value(). + * + * Assumes the existence of a row where filsys_id = argv[0], since a + * filesys label has already been resolved to a filsys_id. + */ +prefetch_filesys(q,argv,cl) + struct query *q; + char **argv; + client *cl; +{ + EXEC SQL BEGIN DECLARE SECTION; + int fid,phid; + EXEC SQL END DECLARE SECTION; + int argc; + + fid = *(int *)argv[0]; + EXEC SQL SELECT phys_id INTO :phid FROM filesys WHERE filsys_id = :fid; + if(ingres_errno) return(mr_errcode); + + argc=q->argc+q->vcnt; + sprintf(argv[argc++],"%d",fid); + sprintf(argv[argc],"%d",phid); + + return(MR_SUCCESS); +} + +/* Convert normal Unix-style wildcards to SQL voodoo */ +convert_wildcards(arg) + char *arg; +{ + static char buffer[QMAXARGSIZE]; + register char *s, *d; + + for(d=buffer,s=arg;*s;s++) { + switch(*s) { + case '*': *d++='%'; *d++='%'; break; + case '?': *d++='_'; break; + case '_': + case '[': + case ']': *d++='*'; *d++ = *s; break; + case '%': *d++='*'; *d++='%'; *d++='%'; break; + default: *d++ = *s; break; + } + } + *d='\0'; + + /* Copy back into argv */ + strcpy(arg,buffer); + + return(MR_EXISTS); +} + +/* This version includes uppercase conversion, for things like gmac. + * This is necessary because "LIKE" doesn't work with "uppercase()". + * Including it in a wildcard routine saves making two passes over + * the argument string. + */ +convert_wildcards_uppercase(arg) + char *arg; +{ + static char buffer[QMAXARGSIZE]; + register char *s, *d; + + for(d=buffer,s=arg;*s;s++) { + switch(*s) { + case '*': *d++='%'; *d++='%'; break; + case '?': *d++='_'; break; + case '_': + case '[': + case ']': *d++='*'; *d++ = *s; break; + case '%': *d++='*'; *d++='%'; *d++='%'; break; + default: *d++=toupper(*s); break; /* This is the only diff. */ + } + } + *d='\0'; + + /* Copy back into argv */ + strcpy(arg,buffer); + + return(MR_EXISTS); +} + /* eof:qsupport.dc */ diff --git a/server/queries2.c b/server/queries2.c index e966e935..2f79f144 100644 --- a/server/queries2.c +++ b/server/queries2.c @@ -26,6 +26,7 @@ int access_filesys(); /* Query Setup Routines */ int prefetch_value(); +int prefetch_filesys(); int setup_ausr(); int setup_dusr(); int setup_spop(); @@ -39,6 +40,7 @@ int setup_dshi(); int setup_afil(); int setup_ufil(); int setup_dfil(); +int setup_aftg(); int setup_dnfp(); int setup_dqot(); int setup_sshi(); @@ -132,12 +134,45 @@ static char UID[] = "uid"; */ static struct valobj VOsort0[] = { - {V_SORT, 0, 0, 0, 0, 0}, + {V_SORT, 0}, +}; + +static struct valobj VOwild0[] = { + {V_WILD, 0}, +}; + +static struct valobj VOupwild0[] = { + {V_UPWILD, 0}, }; static struct valobj VOwild0sort[] = { {V_WILD, 0}, - {V_SORT, 0, 0, 0, 0, 0}, + {V_SORT, 0}, +}; + +static struct valobj VOupwild0sort[] = { + {V_UPWILD, 0}, + {V_SORT, 0}, +}; + +static struct valobj VOwild01sort0[] = { + {V_WILD, 0}, + {V_WILD, 1}, + {V_SORT, 0}, +}; + +static struct valobj VOwild01sort01[] = { + {V_WILD, 0}, + {V_WILD, 1}, + {V_SORT, 0}, + {V_SORT, 1}, +}; + +static struct valobj VOwild012sort0[] = { /* get_alias */ + {V_WILD, 0}, + {V_WILD, 1}, + {V_WILD, 2}, + {V_SORT, 0}, }; static struct valobj VOdate1[] = { @@ -197,7 +232,11 @@ static struct valobj VOfilsys0user1[] = { static struct validate VDmach = { VOmach0, 1 }; static struct validate VDsort0= { VOsort0, 1 }; +static struct validate VDwild0= { VOwild0, 1 }; +static struct validate VDupwild0= { VOupwild0, 1 }; static struct validate VDsort2= { VOsort01,2 }; +static struct validate VDwild2sort2 = { VOwild01sort01,4 }; +static struct validate VDwild3sort1 = { VOwild012sort0,4 }; static struct validate VDsortf = { VOsort0, 1, @@ -210,6 +249,30 @@ static struct validate VDsortf = { followup_fix_modby, }; +static struct validate VDwildsortf = { + VOwild0sort, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + followup_fix_modby, +}; + +static struct validate VDupwildsortf = { + VOupwild0sort, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + followup_fix_modby, +}; + /* Query data */ @@ -262,6 +325,19 @@ static char *gubn_fields[] = { MIT_ID, CLASS, MOD1, MOD2, MOD3, }; +static struct validate gubn_validate = +{ + VOwild01sort0, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + followup_fix_modby, +}; + static char *gubc_fields[] = { CLASS, LOGIN, UID, SHELL, LAST, FIRST, MIDDLE, STATUS, @@ -293,7 +369,7 @@ static struct validate ausr_validate = { ausr_valobj, 7, LOGIN, - "users.login = '%s'", + "users.login = LEFT('%s',SIZE(users.login))", 1, USERS_ID, 0, @@ -600,7 +676,7 @@ static struct validate amac_validate = { amac_valobj, 3, NAME, - "machine.name = uppercase('%s')", + "machine.name = UPPERCASE(LEFT('%s',SIZE(machine.name)))", 1, MACH_ID, 0, @@ -667,12 +743,12 @@ static struct valobj aclu_valobj[] = { {V_CHAR, 0} }; -static struct validate aclu_validate = /* for aclu */ +static struct validate aclu_validate = { aclu_valobj, 2, NAME, - "cluster.name = '%s'", + "cluster.name = LEFT('%s',SIZE(cluster.name))", 1, CLU_ID, 0, @@ -724,6 +800,16 @@ static char *gmcm_fields[] = { MACHINE, CLUSTER, }; +static struct valobj gmcm_valobj[] = +{ + {V_UPWILD, 0}, + {V_WILD, 1}, + {V_SORT, 0}, + {V_SORT, 1}, +}; + +static struct validate gmcm_validate = { gmcm_valobj, 4 }; + static struct valobj amtc_valobj[] = /* ADD_MACHINE_TO_CLUSTER */ { /* DELETE_MACHINE_FROM_CLUSTER */ {V_ID, 0, MACHINE, NAME, MACH_ID, MR_MACHINE}, @@ -755,15 +841,35 @@ static char *acld_fields[] = { static struct valobj acld_valobj[] = { {V_ID, 0, CLUSTER, NAME, CLU_ID, MR_CLUSTER}, + {V_CHAR, 1}, {V_CHAR, 2}, }; -static struct validate acld_validate = /* ADD_CLUSTER_DATA */ -{ /* DELETE_CLUSTER_DATA */ +static struct validate acld_validate = +{ acld_valobj, + 3, + CLU_ID, + "svc.clu_id = %d AND svc.serv_label = '%s' AND svc.serv_cluster = LEFT('%s',SIZE(svc.serv_cluster))", + 3, + 0, + 0, + 0, + set_cluster_modtime_by_id, +}; + +static struct valobj dcld_valobj[] = +{ + {V_ID, 0, CLUSTER, NAME, CLU_ID, MR_CLUSTER}, + {V_CHAR, 2}, +}; + +static struct validate dcld_validate = +{ + dcld_valobj, 2, CLU_ID, - "svc.clu_id = %d and svc.serv_label = '%s' and svc.serv_cluster = '%s'", + "svc.clu_id = %d AND svc.serv_label = '%s' AND svc.serv_cluster = '%s'", 3, 0, 0, @@ -778,10 +884,15 @@ static char *gsin_fields[] = { ACE_TYPE, ACE_NAME, MOD1, MOD2, MOD3, }; +static struct valobj gsin_valobj[] = +{ + { V_UPWILD, 0 }, +}; + static struct validate gsin_validate = { - 0, - 0, + gsin_valobj, + 1, 0, 0, 0, @@ -832,7 +943,7 @@ static struct validate asin_validate = /* for asin, usin */ asin_valobj, 5, NAME, - "services.name = uppercase('%s')", + "servers.name = UPPERCASE(LEFT('%s',SIZE(servers.name)))", 1, 0, 0, @@ -891,9 +1002,14 @@ static char *gshi_fields[] = { "value3", MOD1, MOD2, MOD3, }; +static struct valobj gshi_valobj[] = { + { V_UPWILD, 0 }, + { V_UPWILD, 1 }, +}; + static struct validate gshi_validate = { - 0, - 0, + gshi_valobj, + 2, 0, 0, 0, @@ -943,7 +1059,7 @@ static struct validate ashi_validate = /* ashi & ushi */ ashi_valobj, 3, SERVICE, - "serverhosts.service = uppercase('%s') and serverhosts.mach_id = %d", + "serverhosts.service = UPPERCASE(LEFT('%s',SIZE(serverhosts.service))) and serverhosts.mach_id = %d", 2, 0, access_service, @@ -984,12 +1100,13 @@ static char *sshi_fields[] = { static struct valobj sshi_valobj[] = { {V_NAME, 0, "servers", NAME, 0, MR_SERVICE}, + {V_ID, 1, MACHINE, NAME, MACH_ID, MR_MACHINE}, /* Was this ok to add? */ }; static struct validate sshi_validate = { sshi_valobj, - 1, + 2, 0, 0, 0, @@ -1023,8 +1140,8 @@ static char *gsha_fields[] = { static struct validate gsha_validate = { - 0, - 0, + VOupwild0, + 1, 0, 0, 0, @@ -1092,6 +1209,24 @@ static char *gfsn_fields[] = { "create", "lockertype", MOD1, MOD2, MOD3, }; +static struct valobj gfsn_valobj[] = +{ + {V_ID, 0, MACHINE, NAME, MACH_ID, MR_MACHINE}, + {V_WILD, 1}, +}; + +static struct validate gfsn_validate = { + gfsn_valobj, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + followup_fix_modby, +}; + static char *gfsg_fields[] = { LIST, LABEL, TYPE, MACHINE, NAME, "mount", "access", "comments", "owner", "owners", @@ -1130,7 +1265,7 @@ static struct validate afil_validate = { afil_valobj, 8, LABEL, - "filesys.label = '%s'", + "filesys.label = LEFT('%s',SIZE(filesys.label))", 1, FILSYS_ID, 0, @@ -1224,7 +1359,7 @@ static struct validate aftg_validate = { 2, 0, 0, - 0, + setup_aftg, 0, }; @@ -1237,9 +1372,14 @@ static char *gnfp_fields[] = { MACHINE, DIR, DEVICE, STATUS, "allocated", "size", MOD1, MOD2, MOD3, }; +static struct valobj gnfp_valobj[] = { + {V_ID, 0, MACHINE, NAME, MACH_ID, MR_MACHINE}, + {V_WILD, 1}, +}; + static struct validate gnfp_validate = { - VOmach0, - 1, + gnfp_valobj, + 2, 0, 0, 0, @@ -1258,7 +1398,7 @@ static struct validate anfp_validate = { anfp_valobj, 2, DIR, - "nfsphys.mach_id = %d and nfsphys.dir = '%s'", + "nfsphys.mach_id = %d and nfsphys.dir = LEFT('%s',SIZE(nfsphys.dir))", 2, "nfsphys_id", 0, @@ -1278,6 +1418,10 @@ static struct validate unfp_validate = { set_nfsphys_modtime, }; +static char *ajnf_fields[] = { + MACHINE, DIR, "adjustment", +}; + static char *dnfp_fields[] = { MACHINE, DIR, }; @@ -1353,7 +1497,7 @@ static struct validate aqot_validate = { 3, 0, 0, - 0, + prefetch_filesys, followup_aqot, }; @@ -1387,8 +1531,8 @@ static char *gnfq_fields[] = { }; static struct validate gnfq_validate = { - VOsort0, - 1, + VOwild0sort, + 2, 0, 0, 0, @@ -1403,6 +1547,13 @@ static char *gnqp_fields[] = { FILESYS, LOGIN, QUOTA, DIR, MACHINE, MOD1, MOD2, MOD3, }; +static struct valobj gnqp_valobj[] = { + {V_ID, 0, MACHINE, NAME, MACH_ID, MR_MACHINE}, + {V_WILD, 1}, +}; + +static struct validate gnqp_validate = { gnqp_valobj, 2, }; + static char *anfq_fields[] = { FILESYS, LOGIN, QUOTA, }; @@ -1415,7 +1566,7 @@ static struct validate anfq_validate = { 2, 0, 0, - 0, + prefetch_filesys, followup_aqot, }; @@ -1477,7 +1628,7 @@ static struct validate alis_validate = { alis_valobj, 4, NAME, - "list.name = '%s'", + "list.name = LEFT('%s',SIZE(list.name))", 1, LIST_ID, 0, @@ -1675,8 +1826,8 @@ static char *gzcl_fields[] = { }; static struct validate gzcl_validate = { - VOsort0, - 1, + VOwild0sort, + 2, 0, 0, 0, @@ -1707,7 +1858,7 @@ static struct validate azcl_validate = { azcl_valobj, 9, CLASS, - "zephyr.class = '%s'", + "zephyr.class = LEFT('%s',SIZE(zephyr.class))", 1, 0, 0, @@ -1769,7 +1920,7 @@ static struct validate asvc_validate = { VOchar0, 1, NAME, - "services.name = '%s'", + "services.name = LEFT('%s',SIZE(services.name))", 1, 0, 0, @@ -1785,8 +1936,8 @@ static char *gpce_fields[] = { }; static struct validate gpce_validate = { - VOsort0, - 1, + VOwild0sort, + 2, 0, 0, 0, @@ -1812,7 +1963,7 @@ static struct validate apce_validate = { apce_valobj, 3, NAME, - "printcap.name = '%s'", + "printcap.name = LEFT('%s',SIZE(printcap.name))", 1, 0, 0, @@ -1856,7 +2007,7 @@ static struct validate apdm_validate = { apdm_valobj, 2, NAME, - "palladium.name = '%s'", + "palladium.name = LEFT('%s',SIZE(palladium.name))", 1, 0, 0, @@ -1895,7 +2046,7 @@ static struct validate aali_validate = { aali_valobj, 3, "trans", - "alias.name = '%s' and alias.type = '%s' and alias.trans = '%s'", + "alias.name = LEFT('%s',SIZE(alias.name)) and alias.type = '%s' and alias.trans = LEFT('%s',SIZE(alias.trans))", 3, 0, 0, @@ -1945,7 +2096,7 @@ static struct validate aval_validate = /* for aval, uval, and dval */ VOchar0, 1, NAME, - "numvalues.name = '%s'", + "numvalues.name = LEFT('%s',SIZE(numvalues.name))", /* LEFT() only needed for aval */ 1, 0, 0, @@ -2042,7 +2193,7 @@ struct query Queries2[] = { 12, "first LIKE '%s' ESCAPE '*' AND last LIKE '%s' ESCAPE '*' AND users_id != 0", 2, - &VDsortf, + &gubn_validate, }, { @@ -2072,7 +2223,7 @@ struct query Queries2[] = { 12, "clearid LIKE '%s' ESCAPE '*' AND users_id != 0", 1, - &VDsortf, + &VDwildsortf, }, @@ -2193,7 +2344,7 @@ struct query Queries2[] = { 2, "u.login LIKE '%s' ESCAPE '*' AND s.string LIKE '%s' ESCAPE '*' AND k.users_id = u.users_id AND k.string_id = s.string_id", 2, - &VDsort2, + &VDwild2sort2, }, { @@ -2203,7 +2354,7 @@ struct query Queries2[] = { APPEND, "k", "krbmap", - "INTO krbmap (users_id, string_id) VALUES (%s, %s)", + "INTO krbmap (users_id, string_id) VALUES (%d, %d)", akum_fields, 2, 0, @@ -2221,7 +2372,7 @@ struct query Queries2[] = { 0, akum_fields, 0, - "k.users_id = %d AND k.string_id = %d", + "users_id = %d AND string_id = %d", 2, &dkum_validate, }, @@ -2371,10 +2522,9 @@ struct query Queries2[] = { "CHAR(name), type, CHAR(modtime), CHAR(modby), modwith FROM machine", gmac_fields, 5, - "name = uppercase('%s') AND mach_id != 0", -/* "name LIKE '%s' ESCAPE '*' AND mach_id != 0", */ /* Pattern matching */ + "name LIKE '%s' ESCAPE '*' AND mach_id != 0", 1, - &VDsortf, + &VDupwildsortf, }, { @@ -2434,7 +2584,7 @@ struct query Queries2[] = { 6, "name LIKE '%s' ESCAPE '*' AND clu_id != 0", 1, - &VDsortf, + &VDwildsortf, }, { @@ -2492,9 +2642,9 @@ struct query Queries2[] = { "CHAR(m.name), CHAR(c.name) FROM machine m, cluster c, mcmap map", gmcm_fields, 2, - "m.name = uppercase('%s') AND c.name LIKE '%s' ESCAPE '*' AND map.clu_id = c.clu_id AND map.mach_id = m.mach_id", + "m.name LIKE '%s' ESCAPE '*' AND c.name LIKE '%s' ESCAPE '*' AND map.clu_id = c.clu_id AND map.mach_id = m.mach_id", 2, - &VDsort2, + &gmcm_validate, }, { @@ -2539,7 +2689,7 @@ struct query Queries2[] = { 3, "c.clu_id = s.clu_id AND c.name LIKE '%s' ESCAPE '*' AND s.serv_label LIKE '%s' ESCAPE '*'", 2, - &VDsort2, + &VDwild2sort2, }, { @@ -2567,9 +2717,9 @@ struct query Queries2[] = { (char *)0, acld_fields, 0, - "clu_id = %d AND serv_label LIKE '%s' ESCAPE '*' AND serv_cluster = '%s'", /** wildcard completion for serv_cluster ??? **/ + "clu_id = %d AND serv_label = '%s' AND serv_cluster = '%s'", 3, - &acld_validate, + &dcld_validate, }, { @@ -2582,7 +2732,7 @@ struct query Queries2[] = { "CHAR(name), CHAR(update_int), target_file, script, CHAR(dfgen), CHAR(dfcheck), type, CHAR(enable), CHAR(inprogress), CHAR(harderror), errmsg, acl_type, CHAR(acl_id), CHAR(modtime), CHAR(modby), modwith FROM servers", gsin_fields, 16, - "name = uppercase('%s')", + "name LIKE '%s' ESCAPE '*'", 1, &gsin_validate, }, @@ -2684,10 +2834,10 @@ struct query Queries2[] = { RETRIEVE, "sh", "serverhosts", - "CHAR(sh.service), CHAR(m.name), CHAR(sh.enable), CHAR(sh.override), CHAR(sh.success), CHAR(sh.inprogress), CHAR(sh.hosterror), sh.hosterrmsg, CHAR(sh.ltt), CHAR(sh.lts), CHAR(sh.value1), CHAR(sh.value2), sh.value, CHAR(sh.modtime), CHAR(sh.modby), sh.modwith FROM serverhosts sh, machine m", + "CHAR(sh.service), CHAR(m.name), CHAR(sh.enable), CHAR(sh.override), CHAR(sh.success), CHAR(sh.inprogress), CHAR(sh.hosterror), sh.hosterrmsg, CHAR(sh.ltt), CHAR(sh.lts), CHAR(sh.value1), CHAR(sh.value2), sh.value3, CHAR(sh.modtime), CHAR(sh.modby), sh.modwith FROM serverhosts sh, machine m", gshi_fields, 16, - "sh.service = uppercase('%s') AND m.name = uppercase('%s') AND m.mach_id = sh.mach_id", + "sh.service LIKE '%s' ESCAPE '*' AND m.name LIKE '%s' ESCAPE '*' AND m.mach_id = sh.mach_id", 2, &gshi_validate, }, @@ -2777,11 +2927,7 @@ struct query Queries2[] = { "serverhosts SET override = %s, success = %s, inprogress = %s, hosterror = %s, hosterrmsg = '%s', ltt = %s, lts = %s", sshi_fields, 7, -#ifdef NEVER - "s.service = uppercase('%s') AND s.mach_id = machine.mach_id AND machine.name = '%s'", /** Turn the machine name into a mach_id in the setup routine **/ -#else "service = uppercase('%s') AND mach_id = %d", -#endif 2, &sshi_validate, }, @@ -2811,7 +2957,7 @@ struct query Queries2[] = { "CHAR(m.name), ha.acl_type, CHAR(ha.acl_id), CHAR(ha.modtime), CHAR(ha.modby), ha.modwith FROM hostaccess ha, machine m", gsha_fields, 6, - "m.name = uppercase('%s') AND ha.mach_id = m.mach_id", + "m.name LIKE '%s' ESCAPE '*' AND ha.mach_id = m.mach_id", 1, &gsha_validate, }, @@ -2871,9 +3017,9 @@ struct query Queries2[] = { "CHAR(sh.service), CHAR(m.name) FROM serverhosts sh, machine m", gslo_fields, 2, - "sh.service = uppercase('%s') AND sh.mach_id = m.mach_id", + "sh.service LIKE '%s' ESCAPE '*' AND sh.mach_id = m.mach_id", 1, - 0, + &VDupwild0, }, { @@ -2888,7 +3034,7 @@ struct query Queries2[] = { 14, "fs.label LIKE '%s' ESCAPE '*' AND fs.mach_id = m.mach_id AND fs.owner = u.users_id AND fs.owners = l.list_id", 1, - &VDsortf, + &VDwildsortf, }, { @@ -2907,7 +3053,7 @@ struct query Queries2[] = { }, { - /* Q_GFSN - GET_FILESYS_BY_NFSPHYS */ /** Check to make sure the stmt_buf is long enough for this query! **/ + /* Q_GFSN - GET_FILESYS_BY_NFSPHYS */ "get_filesys_by_nfsphys", "gfsn", RETRIEVE, @@ -2916,9 +3062,9 @@ struct query Queries2[] = { "CHAR(fs.label), fs.type, CHAR(m.name), fs.name, fs.mount, fs.access, fs.comments, CHAR(u.login), CHAR(l.name), CHAR(fs.createflg), fs.lockertype, CHAR(fs.modtime), CHAR(fs.modby), fs.modwith FROM filesys fs, machine m, users u, list l, nfsphys np", gfsn_fields, 14, - "fs.mach_id = %d AND m.mach_id = fs.mach_id AND fs.owner = u.users_id AND fs.owners = l.list_id AND np.nfsphys_id = fs.phys_id AND np.dir = '%s' AND fs.type = 'NFS'", + "fs.mach_id = %d AND m.mach_id = fs.mach_id AND fs.owner = u.users_id AND fs.owners = l.list_id AND np.nfsphys_id = fs.phys_id AND np.dir LIKE '%s' ESCAPE '*' AND fs.type = 'NFS'", 2, - &gfsm_validate, + &gfsn_validate, }, { @@ -3003,10 +3149,10 @@ struct query Queries2[] = { APPEND, "fg", "fsgroup", - "INTO fsgroup (group_id,filsys_id,key) VALUES (filesys.filsys_id, %d, '%s')", + "INTO fsgroup (group_id,filsys_id,key) VALUES (%d, %d, '%s')", gfgm_fields, 2, - "filesys.filsys_id = %d AND filesys.type = 'FSGROUP'", + (char *)0, 1, &aftg_validate, }, @@ -3033,7 +3179,7 @@ struct query Queries2[] = { RETRIEVE, "np", "nfsphys", - "CHAR(m.name), np.dir, np.device, CHAR(np.status), CHAR(np.allocated), CHAR(np.size), CHAR(np.modtime), CHAR(np.modby), np.modwith FROM nfsphys np, machine m", + "CHAR(m.name), CHAR(np.dir), np.device, CHAR(np.status), CHAR(np.allocated), CHAR(np.partsize), CHAR(np.modtime), CHAR(np.modby), np.modwith FROM nfsphys np, machine m", ganf_fields, 9, "m.mach_id = np.mach_id", @@ -3048,10 +3194,10 @@ struct query Queries2[] = { RETRIEVE, "np", "nfsphys", - "CHAR(m.name), np.dir, np.device, CHAR(np.status), CHAR(np.allocated), CHAR(np.size), CHAR(np.modtime), CHAR(np.modby), np.modwith FROM nfsphys np, machine m", + "CHAR(m.name), CHAR(np.dir), np.device, CHAR(np.status), CHAR(np.allocated), CHAR(np.partsize), CHAR(np.modtime), CHAR(np.modby), np.modwith FROM nfsphys np, machine m", gnfp_fields, 9, - "np.mach_id = %d AND np.dir = '%s' AND m.mach_id = np.mach_id", + "np.mach_id = %d AND np.dir LIKE '%s' ESCAPE '*' AND m.mach_id = np.mach_id", 2, &gnfp_validate, }, @@ -3063,7 +3209,7 @@ struct query Queries2[] = { APPEND, "np", "nfsphys", - "INTO nfsphys (mach_id, dir, device, status, allocated, size, nfsphys_id) VALUES (%d, '%s', '%s', %s, %s, %s, %s)", + "INTO nfsphys (mach_id, dir, device, status, allocated, partsize, nfsphys_id) VALUES (%d, '%s', '%s', %s, %s, %s, %s)", ganf_fields, 6, 0, @@ -3078,10 +3224,10 @@ struct query Queries2[] = { UPDATE, "np", "nfsphys", - "nfsphys SET device = '%s', status = '%s', allocated = %s, size = %s", + "nfsphys SET device = '%s', status = '%s', allocated = %s, partsize = %s", gnfp_fields, 4, - "mach_id = %d AND dir = '%s'", + "mach_id = %d AND dir = '%s'", 2, &unfp_validate, }, @@ -3094,7 +3240,7 @@ struct query Queries2[] = { "np", "nfsphys", "nfsphys SET allocated = allocated + %s", - dnfp_fields, + ajnf_fields, 1, "mach_id = %d AND dir = '%s'", 2, @@ -3147,16 +3293,16 @@ struct query Queries2[] = { }, { - /* Q_AQOT - ADD_QUOTA */ /** Needs subselect */ + /* Q_AQOT - ADD_QUOTA */ /* prefetch_filsys() gets last 2 values */ "add_quota", "aqot", APPEND, "q", QUOTA, - "INTO quota (filsys_id, type, entity_id, quota, phys_id) VALUES (filesys.filsys_id, '%s', %d, %s, filesys.phys_id)", + "INTO quota (type, entity_id, quota, filsys_id, phys_id) VALUES (filesys.filsys_id, '%s', %d, %s, %s, %s)", aqot_fields, 3, - "filesys.filsys_id = %d", + (char *)0, 1, &aqot_validate, }, @@ -3201,7 +3347,7 @@ struct query Queries2[] = { "CHAR(fs.label), CHAR(u.login), CHAR(q.quota), CHAR(q.phys_id), CHAR(m.name), CHAR(q.modtime), CHAR(q.modby), q.modwith FROM quota q, filesys fs, users u, machine m", gnfq_fields, 8, - "fs.label = '%s' AND q.type = 'USER' AND q.entity_id = u.users_id AND fs.filsys_id = q.filsys_id AND m.mach_id = fs.mach_id AND u.login = '%s'", + "fs.label LIKE '%s' ESCAPE '*' AND q.type = 'USER' AND q.entity_id = u.users_id AND fs.filsys_id = q.filsys_id AND m.mach_id = fs.mach_id AND u.login = '%s'", 2, &gnfq_validate, }, @@ -3213,25 +3359,25 @@ struct query Queries2[] = { RETRIEVE, "q", QUOTA, - "CHAR(fs.label), CHAR(u.login), CHAR(q.quota), np.dir, CHAR(m.name) FROM quota q, filesys fs, users u, nfsphys np, machine m", + "CHAR(fs.label), CHAR(u.login), CHAR(q.quota), CHAR(np.dir), CHAR(m.name) FROM quota q, filesys fs, users u, nfsphys np, machine m", gnqp_fields, 5, - "np.mach_id = %d AND np.dir = '%s' AND q.phys_id = np.nfsphys_id AND fs.filsys_id = q.filsys_id AND q.type = 'USER' AND u.users_id = q.entity_id AND m.mach_id = np.mach_id", + "np.mach_id = %d AND np.dir LIKE '%s' ESCAPE '*' AND q.phys_id = np.nfsphys_id AND fs.filsys_id = q.filsys_id AND q.type = 'USER' AND u.users_id = q.entity_id AND m.mach_id = np.mach_id", 2, - &VDmach, + &gnqp_validate, }, { - /* Q_ANFQ - ADD_NFS_QUOTA */ /** Needs subselect */ + /* Q_ANFQ - ADD_NFS_QUOTA */ /* prefetch_filsys() gets last 2 values */ "add_nfs_quota", "anfq", APPEND, "q", QUOTA, - "INTO quota (filsys_id, type, entity_id, quota, phys_id) VALUES (filesys.filsys_id, 'USER', %d, %s, filesys.phys_id)", + "INTO quota (type, entity_id, quota, filsys_id, phys_id) VALUES ('USER', %d, %s, %s, %s)", anfq_fields, 2, - "filesys.filsys_id = %d", + (char *)0, 1, &anfq_validate, }, @@ -3277,8 +3423,8 @@ struct query Queries2[] = { glin_fields, 13, 0, - 1, - &glin_validate, + 1, + &glin_validate, }, { @@ -3293,7 +3439,7 @@ struct query Queries2[] = { 1, "name LIKE '%s' ESCAPE '*' AND list_id != 0", 1, - 0 + &VDwild0, }, { @@ -3486,7 +3632,7 @@ struct query Queries2[] = { "zephyr SET class = '%s', xmt_type = '%d', xmt_id = %d, sub_type = '%s', sub_id = %d, iws_type = '%s', iws_id = %d, iui_type = '%s', iui_id = %d", uzcl_fields, 9, - "class LIKE '%s' ESCAPE '*'", + "class = '%s'", 1, &uzcl_validate, }, @@ -3501,7 +3647,7 @@ struct query Queries2[] = { 0, uzcl_fields, 0, - "class LIKE '%s' ESCAPE '*'", + "class = '%s'", 1, &dzcl_validate, }, @@ -3518,7 +3664,7 @@ struct query Queries2[] = { 7, "name LIKE '%s' ESCAPE '*'", 1, - &VDsortf, + &VDwildsortf, }, { @@ -3546,7 +3692,7 @@ struct query Queries2[] = { 0, asvc_fields, 0, - "name LIKE '%s' ESCAPE '*'", + "name = '%s'", 1, &asvc_validate, }, @@ -3591,7 +3737,7 @@ struct query Queries2[] = { 0, apce_fields, 0, - "name LIKE '%s' ESCAPE '*'", + "name = '%s'", 1, &dpce_validate, }, @@ -3608,7 +3754,7 @@ struct query Queries2[] = { 8, "p.name LIKE '%s' ESCAPE '*' AND m.mach_id = p.mach_id", 1, - &VDsortf, + &VDwildsortf, }, { @@ -3621,7 +3767,7 @@ struct query Queries2[] = { 0, apce_fields, 0, - "name LIKE '%s' ESCAPE '*'", + "name = '%s'", 1, &dpce_validate, }, @@ -3638,7 +3784,7 @@ struct query Queries2[] = { 6, "p.name LIKE '%s' ESCAPE '*' AND m.mach_id = p.mach_id", 1, - &VDsortf, + &VDwildsortf, }, { @@ -3666,7 +3812,7 @@ struct query Queries2[] = { 0, apdm_fields, 0, - "name LIKE '%s' ESCAPE '*'", + "name = '%s'", 1, &dpdm_validate, }, @@ -3683,7 +3829,7 @@ struct query Queries2[] = { 3, "name LIKE '%s' ESCAPE '*' AND type LIKE '%s' ESCAPE '*' AND trans LIKE '%s' ESCAPE '*'", 3, - 0, + &VDwild3sort1, }, { @@ -3711,7 +3857,7 @@ struct query Queries2[] = { (char *)0, aali_fields, 0, - "name LIKE '%s' ESCAPE '*' AND type LIKE '%s' ESCAPE '*' AND trans LIKE '%s' ESCAPE '*'", + "name = '%s' AND type = '%s' AND trans = '%s'", 3, &dali_validate, }, @@ -3726,7 +3872,7 @@ struct query Queries2[] = { "CHAR(value) FROM numvalues", gval_fields, 1, - "name LIKE '%s' ESCAPE '*'", + "name = '%s'", 1, &gval_validate, }, @@ -3756,7 +3902,7 @@ struct query Queries2[] = { "numvalues SET value = %s", aval_fields, 1, - "name LIKE '%s' ESCAPE '*'", + "name = '%s'", 1, &aval_validate, }, @@ -3771,7 +3917,7 @@ struct query Queries2[] = { (char *)0, dval_fields, 0, - "name LIKE '%s' ESCAPE '*'", + "name = '%s'", 1, &aval_validate, }, -- 2.45.2