- type = argv[2];
- mach_id = *(int *)argv[3];
- name = argv[4];
- access = argv[6];
- fid = *(int *)argv[0];
- who = cl->client_id;
- entity = cl->entity;
-
- sprintf(ftype, "fs_access_%s", type);
- EXEC SQL SELECT COUNT(trans) INTO :ok FROM alias
- WHERE name = :ftype AND type='TYPE' AND trans = :access;
- if (ingres_errno) return(mr_errcode);
- if (ok == 0) return(MR_FILESYS_ACCESS);
-
- EXEC SQL SELECT type INTO :ftype FROM filesys
- WHERE filsys_id = :fid;
- strtrim(ftype);
- if (ingres_errno) return(mr_errcode);
-
- if (!strcmp(type, "NFS")) {
- status = check_nfs(mach_id, name, access);
- EXEC SQL UPDATE quota SET phys_id = :var_phys_id
- WHERE filsys_id = :fid;
- if (ingres_errno) return(mr_errcode);
- return(status);
- } else if (!strcmp(type, "AFS") && strcmp(ftype, "AFS")) {
- total = 0;
- EXEC SQL REPEATED DELETE FROM quota
- WHERE type = 'ANY' AND filsys_id = :fid;
- EXEC SQL SELECT SUM (quota) INTO :total:total_null FROM quota
- WHERE filsys_id = :fid AND phys_id != 0;
- if (ingres_errno) return(mr_errcode);
- if (!total_null && (total != 0)) {
-/*
- * append quota (quota = total, filsys_id = fid,
- * phys_id = 0, entity_id = 0, type = "ANY",
- * modtime = "now", modby = who, modwith = entity)
- */
- EXEC SQL INSERT INTO quota (quota, filsys_id, phys_id, entity_id,
- type, modtime, modby, modwith)
- VALUES (:total, :fid, 0, 0,
- 'ANY', 'now', :who, :entity) ;
- if (ingres_errno) return(mr_errcode);
- }
- } else {
- EXEC SQL UPDATE quota SET phys_id = 0 WHERE filsys_id = :fid;
- if (ingres_errno) return(mr_errcode);
- }
- return(MR_SUCCESS);
-}
-
-
-/* Find the NFS physical partition that the named directory is on.
- * This is done by comparing the dir against the mount point of the
- * partition. To make sure we get the correct match when there is
- * more than one, we sort the query in reverse order by dir name.
- */
-
-check_nfs(mach_id, name, access)
- EXEC SQL BEGIN DECLARE SECTION;
- int mach_id;
- EXEC SQL END DECLARE SECTION;
- char *name;
- char *access;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- char dir[81];
- EXEC SQL END DECLARE SECTION;
- char caccess;
- register int status;
- register char *cp1;
- register char *cp2;
-
- status = MR_NFS;
- EXEC SQL DECLARE csr101 CURSOR FOR
- SELECT nfsphys_id, TRIM (dir) FROM nfsphys
- WHERE mach_id = :mach_id
- ORDER BY 2 DESC;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr101;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr101 INTO :var_phys_id, :dir;
- if(sqlca.sqlcode != 0) break;
- cp1 = name;
- cp2 = dir;
- while (*cp2) {
- if (*cp1++ != *cp2) break;
- cp2++;
- }
- if (*cp2 == 0) {
- status = MR_SUCCESS;
- break;
- }
- }
- EXEC SQL CLOSE csr101;
- if (ingres_errno)
- return(mr_errcode);
- return(status);
-}
-
-
-/* setup_dfil: free any quota records and fsgroup info associated with
- * a filesystem when it is deleted. Also adjust the allocation numbers.
- */
-
-setup_dfil(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int id, total, phys_id;
- short int none;
- EXEC SQL END DECLARE SECTION;
-
- id = *(int *)argv[0];
- EXEC SQL REPEATED SELECT SUM (quota) INTO :total:none FROM quota
- WHERE filsys_id = :id;
-
- if(none) total=0;
-
- /** What if there are multiple phys_id's per f/s? (bad data) **/
- EXEC SQL REPEATED SELECT phys_id INTO :phys_id FROM filesys
- WHERE filsys_id = :id;
- EXEC SQL REPEATED UPDATE nfsphys SET allocated = allocated - :total
- WHERE nfsphys_id = :phys_id;
-
- if(!none) {
- EXEC SQL REPEATED DELETE FROM quota WHERE filsys_id = :id;
- }
- EXEC SQL REPEATED DELETE FROM fsgroup WHERE filsys_id = :id;
- EXEC SQL REPEATED DELETE FROM fsgroup WHERE group_id = :id;
- if (ingres_errno) return(mr_errcode);
- 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.
- */
-
-setup_dnfp(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int id, cnt;
- char *dir;
- EXEC SQL END DECLARE SECTION;
-
- id = *(int *)argv[0];
- dir = argv[1];
- EXEC SQL REPEATED SELECT fs.tid INTO :cnt FROM filesys fs, nfsphys np
- WHERE fs.mach_id = :id AND fs.phys_id = np.nfsphys_id
- AND np.mach_id = :id AND np.dir = :dir;
- if (cnt > 0)
- return(MR_IN_USE);
- if (ingres_errno)
- return(mr_errcode);
- return(MR_SUCCESS);
-}
-
-
-/* setup_dqot: Remove allocation from nfsphys before deleting quota.
- * argv[0] = filsys_id
- * argv[1] = type if "update_quota" or "delete_quota"
- * argv[2 or 1] = users_id or list_id
- */
-
-setup_dqot(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int quota, fs, id, physid;
- char *qtype;
- EXEC SQL END DECLARE SECTION;
-
- fs = *(int *)argv[0];
- if (!strcmp(q->name, "update_quota") || !strcmp(q->name, "delete_quota")) {
- qtype = argv[1];
- id = *(int *)argv[2];
- } else {
- qtype = "USER";
- id = *(int *)argv[1];
- }
-
- EXEC SQL REPEATED SELECT quota INTO :quota FROM quota
- WHERE type = :qtype AND entity_id = :id AND filsys_id = :fs;
- EXEC SQL REPEATED SELECT phys_id INTO :physid FROM filesys
- WHERE filsys_id = :fs;
- EXEC SQL REPEATED UPDATE nfsphys SET allocated = allocated - :quota
- WHERE nfsphys_id = :physid;
-
- if (ingres_errno) return(mr_errcode);
- return(MR_SUCCESS);
-}
-
-
-/* setup_sshi: don't exclusive lock the machine table during
- * set_server_host_internal.
- */
-/** Not allowed under (INGRES) SQL **/
-setup_sshi(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
-#if 0
-#ifsql INGRES
- EXEC SQL set lockmode session where readlock = system;
-#endsql
-#endif
- return(MR_SUCCESS);
-}
-
-
-/* setup add_kerberos_user_mapping: add the string to the string
- * table if necessary.
- */
-
-setup_akum(q, argv, cl)
-struct query *q;
-char **argv;
-client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int id, rowcount;
- char *name;
- EXEC SQL END DECLARE SECTION;
-
- name = argv[1];
- if (name_to_id(name, "STRING", &id) != MR_SUCCESS) {
- if (q->type != APPEND) return(MR_STRING);
- id=add_string(name);
- cache_entry(name, "STRING", id);
- }
- if (ingres_errno) return(mr_errcode);
- *(int *)argv[1] = id;
- return(MR_SUCCESS);
-}
-
-
-\f
-/* FOLLOWUP ROUTINES */
-
-/* generic set_modtime routine. This takes the table name from the query,
- * and will update the modtime, modby, and modwho fields in the entry in
- * the table whose name field matches argv[0].
- */
-
-set_modtime(q, argv, cl)
- struct query *q;
- char *argv[];
- client *cl;
-{
- char *name, *entity, *table;
- int who;
-
- entity = cl->entity;
- who = cl->client_id;
- table = q->rtable;
- name = argv[0];
-
- 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);
-}
-
-/* generic set_modtime_by_id routine. This takes the table name from
- * the query, and the id name from the validate record,
- * and will update the modtime, modby, and modwho fields in the entry in
- * the table whose id matches argv[0].
- */
-
-set_modtime_by_id(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- char *entity, *table, *id_name;
- int who, id;
-
- entity = cl->entity;
- who = cl->client_id;
- table = q->rtable;
- id_name = q->validate->object_id;
-
- id = *(int *)argv[0];
- sprintf(stmt_buf,"UPDATE %s SET modtime = 'now', modby = %d, \
-modwith = '%s' WHERE %s.%s = %d",table,who,entity,table,id_name,id);
- EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
- return(MR_SUCCESS);
-}
-
-
-/* Sets the finger modtime on a user record. The users_id will be in argv[0].
- */
-
-set_finger_modtime(q, argv, cl)
- struct query *q;
- char *argv[];
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int users_id, who;
- char *entity;
- EXEC SQL END DECLARE SECTION;
-
- entity = cl->entity;
- who = cl->client_id;
- users_id = *(int *)argv[0];
-
- EXEC SQL UPDATE users SET fmodtime='now', fmodby = :who, fmodwith = :entity
- WHERE users.users_id = :users_id;
-
- return(MR_SUCCESS);
-}
-
-
-/* Sets the pobox modtime on a user record. The users_id will be in argv[0].
- */
-
-set_pobox_modtime(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int users_id, who;
- char *entity;
- EXEC SQL END DECLARE SECTION;
-
- entity = cl->entity;
- 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;
-
- return(MR_SUCCESS);
-}
-
-
-/* Like set_modtime, but uppercases the name first.
- */
-
-set_uppercase_modtime(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- char *name, *entity, *table;
- int who;
-
- entity = cl->entity;
- who = cl->client_id;
- table = q->rtable;
- name = argv[0];
-
- 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);
-}
-
-
-/* Sets the modtime on the machine whose mach_id is in argv[0]. This routine
- * is necessary for add_machine_to_cluster becuase the table that query
- * operates on is "mcm", not "machine".
- */
-
-set_mach_modtime_by_id(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- char *entity;
- int who, id;
- EXEC SQL END DECLARE SECTION;
-
- entity = cl->entity;
- who = cl->client_id;
- id = *(int *)argv[0];
- EXEC SQL UPDATE machine SET modtime='now', modby = :who, modwith = :entity
- WHERE machine.mach_id = :id;
-
- return(MR_SUCCESS);
-}
-
-
-/* Sets the modtime on the cluster whose mach_id is in argv[0]. This routine
- * is necessary for add_cluster_data and delete_cluster_data becuase the
- * table that query operates on is "svc", not "cluster".
- */
-
-set_cluster_modtime_by_id(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- char *entity;
- int who, id;
- EXEC SQL END DECLARE SECTION;
-
- entity = cl->entity;
- who = cl->client_id;
-
- id = *(int *)argv[0];
- EXEC SQL UPDATE cluster SET modtime='now', modby = :who, modwith = :entity
- WHERE cluster.clu_id = :id;
- return(MR_SUCCESS);
-}
-
-
-/* sets the modtime on the serverhost where the service name is in argv[0]
- * and the mach_id is in argv[1].
- */
-
-set_serverhost_modtime(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- char *entity, *serv;
- int who, id;
- EXEC SQL END DECLARE SECTION;
-
- entity = cl->entity;
- who = cl->client_id;
-
- serv = argv[0];
- id = *(int *)argv[1];
- EXEC SQL UPDATE serverhosts
- SET modtime = 'now', modby = :who, modwith = :entity
- WHERE service = :serv AND mach_id = :id;
- return(MR_SUCCESS);
-}
-
-
-/* sets the modtime on the nfsphys where the mach_id is in argv[0] and the
- * directory name is in argv[1].
- */
-
-set_nfsphys_modtime(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- char *entity, *dir;
- int who, id;
- EXEC SQL END DECLARE SECTION;
-
- entity = cl->entity;
- who = cl->client_id;
-
- id = *(int *)argv[0];
- dir = argv[1];
- EXEC SQL UPDATE nfsphys SET modtime = 'now', modby = :who, modwith = :entity
- WHERE dir = :dir AND mach_id = :id;
- return(MR_SUCCESS);
-}
-
-
-/* sets the modtime on a filesystem, where argv[0] contains the filesys
- * label.
- */
-
-set_filesys_modtime(q, argv, cl)
- struct query *q;
- char *argv[];
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- char *label, *entity;
- int who;
- EXEC SQL END DECLARE SECTION;
-
- entity = cl->entity;
- who = cl->client_id;
-
- label = argv[0];
- if (!strcmp(q->shortname, "ufil"))
- label = argv[1];
-
- EXEC SQL UPDATE filesys SET modtime = 'now', modby = :who,
- modwith = :entity, phys_id = :var_phys_id
- WHERE label = LEFT(:label,SIZE(label));
- return(MR_SUCCESS);
-}
-
-
-/* sets the modtime on a zephyr class, where argv[0] contains the class
- * name.
- */
-
-set_zephyr_modtime(q, argv, cl)
- struct query *q;
- char *argv[];
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- char *class, *entity;
- int who;
- EXEC SQL END DECLARE SECTION;
-
- entity = cl->entity;
- who = cl->client_id;
-
- class = argv[0];
-
- EXEC SQL UPDATE zephyr SET modtime = 'now', modby = :who, modwith = :entity
- WHERE class = LEFT(:class,SIZE(class));
-
- return(MR_SUCCESS);
-}
-
-
-/* fixes the modby field. This will be the second to last thing in the
- * argv, the argv length is determined from the query structure. It is
- * passed as a pointer to an integer. This will either turn it into a
- * username, or # + the users_id.
- */
-followup_fix_modby(q, sq, v, action, actarg, cl)
- struct query *q;
- register struct save_queue *sq;
- struct validate *v;
- register int (*action)();
- register int actarg;
- client *cl;
-{
- register int i, j;
- char **argv, *malloc();
- int id, status;
-
- i = q->vcnt - 2;
- while (sq_get_data(sq, &argv)) {
- id = atoi(argv[i]);
- if (id > 0)
- status = id_to_name(id, "USER", &argv[i]);
- else
- status = id_to_name(-id, "STRING", &argv[i]);
- if (status && status != MR_NO_MATCH)
- return(status);
- (*action)(q->vcnt, argv, actarg);
- for (j = 0; j < q->vcnt; j++)
- free(argv[j]);
- free(argv);
- }
- sq_destroy(sq);
- return(MR_SUCCESS);
-}
-
-
-/* After retrieving a user account, fix the modby field and signature.
- * The modby field is the second to last thing in the
- * argv, the argv length is determined from the query structure. It is
- * passed as a pointer to an integer. This will either turn it into a
- * username, or # + the users_id. Only "gua*" queries have a signature,
- * these are ones with U_END return values. "gub*" queries also use this
- * routine but don't have a signature.
- */
-followup_guax(q, sq, v, action, actarg, cl)
- struct query *q;
- register struct save_queue *sq;
- struct validate *v;
- register int (*action)();
- register int actarg;
- client *cl;
-{
- register int i, j;
- char **argv, *malloc();
-#ifdef GDSS
- unsigned char sigbuf[256];
- char *kname;
- SigInfo si;
- EXEC SQL BEGIN DECLARE SECTION;
- int timestamp, who;
- char *login;
- varchar struct { short data_size; char data_buf[257];} rsig;
- EXEC SQL END DECLARE SECTION;
-#endif /* GDSS */
- int id, status;
-
- i = q->vcnt - 2;
- while (sq_get_data(sq, &argv)) {
-#ifdef DEBUG
- com_err(whoami, 0, "argv[SIGNATURE] = \"%s\"", argv[U_SIGNATURE]);
-#endif /* DEBUG */
- id = atoi(argv[i]);
- if (id > 0)
- status = id_to_name(id, "USER", &argv[i]);
- else
- status = id_to_name(-id, "STRING", &argv[i]);
- if (status && status != MR_NO_MATCH)
- return(status);
-#ifdef GDSS
- if (q->vcnt == U_END && strlen(argv[U_SIGNATURE])) {
- login = argv[U_NAME];
- EXEC SQL REPEATED SELECT signature, sigdate, sigwho
- INTO :rsig, :timestamp, :who FROM users
- WHERE login = :login;
- /** What about (INGRES) error handling? **/
- kname = malloc(1);
- status = id_to_name(who, "STRING", &kname);
- si.timestamp = timestamp;
- si.SigInfoVersion = 0; /* XXXXX this isn't used */
- kname_parse(si.pname, si.pinst, si.prealm, kname);
- free(kname);
- rsig.data_buf[rsig.data_size] = 0;
- si.rawsig = (unsigned char *)strsave(rsig.data_buf);
- if (log_flags & LOG_GDSS)
- com_err(whoami, 0, "rawsig length = %d, sig=\"%s\"", strlen(si.rawsig), si.rawsig);
- GDSS_Recompose(&si, sigbuf);
- free(si.rawsig);
- free(argv[U_SIGNATURE]);
- argv[U_SIGNATURE] = strsave(sigbuf);
- if (log_flags & LOG_GDSS)
- com_err(whoami, 0, "generated signature length %d", strlen(sigbuf));
- }
-#endif /* GDSS */
- (*action)(q->vcnt, argv, actarg);
- for (j = 0; j < q->vcnt; j++)
- free(argv[j]);
- free(argv);
- }
- sq_destroy(sq);
- return(MR_SUCCESS);
-}
-
-
-/**
- ** followup_ausr - add finger and pobox entries, set_user_modtime
- **
- ** Inputs:
- ** argv[0] - login (add_user)
- ** argv[3] - last name
- ** argv[4] - first name
- ** argv[5] - middle name
- **
- **/
-
-followup_ausr(q, argv, cl)
- struct query *q;
- char *argv[];
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int who, status, id;
- char *login, *entity, *src, *dst, *name;
- char fullname[129];
- EXEC SQL END DECLARE SECTION;
-#ifdef GDSS
- char databuf[32], *kname_unparse();
- EXEC SQL BEGIN DECLARE SECTION;
- char rawsig[128];
- int sigwho, timestamp;
- EXEC SQL END DECLARE SECTION;
- SigInfo si;
-#endif /* GDSS */
-
- /* build fullname */
- if (strlen(argv[4]) && strlen(argv[5]))
- sprintf(fullname, "%s %s %s", argv[4], argv[5], argv[3]);
- else if (strlen(argv[4]))
- sprintf(fullname, "%s %s", argv[4], argv[3]);
- else
- sprintf(fullname, "%s", argv[3]);
-
-#ifdef GDSS
- if (q->vcnt == U_END && *argv[U_SIGNATURE]) {
- /* unquote ' chars in signature */
- for (dst = src = argv[U_SIGNATURE]; *src; ) {
- if (*src == '\'')
- src++;
- *dst++ = *src++;
- }
- *dst = 0;
- sprintf(databuf, "%s:%s", argv[U_NAME], argv[U_MITID]);
- /* skip bytes for timestamp & kname */
- si.rawsig = (unsigned char *) rawsig;
- status = GDSS_Verify(databuf, strlen(databuf), argv[U_SIGNATURE], &si);
- if (strlen(rawsig) > mr_sig_length) {
- com_err(whoami, 0, "GDSS signature would be truncated."); /** untested **/
- return(MR_INTERNAL);
- }
- if (status == 0) {
- name = kname_unparse(si.pname, si.pinst, si.prealm);
- status = name_to_id(name, "STRING", &sigwho);
- if (status == MR_NO_MATCH) {
- sigwho=add_string(name);
- } else if (status)
- return(status);
- timestamp = si.timestamp;
- } else {
- if (log_flags & LOG_GDSS)
- hex_dump(argv[U_SIGNATURE]);
- return(gdss2et(status));
- }
- } else {
- rawsig[0] = 0;
- sigwho = 0;
- timestamp = 0;
- }
-#endif /* GDSS */
-
- login = argv[0];
- who = cl->client_id;
- entity = cl->entity;
-
- /* create finger entry, pobox & set modtime on user */
-#ifdef GDSS
- EXEC SQL REPEATED UPDATE users
- SET modtime='now', modby=:who, modwith = :entity,
- fullname = :fullname, affiliation = type,
- signature = :rawsig, sigdate = :timestamp, sigwho = :sigwho,
- fmodtime='now', fmodby = :who, fmodwith = :entity,
- potype='NONE', pmodtime='now', pmodby = :who, pmodwith = :entity
- WHERE login = :login;
-#else /* GDSS */
- EXEC SQL REPEATED UPDATE users
- SET modtime='now', modby=:who, modwith = :entity,
- fullname = :fullname, affiliation = type,
- fmodtime='now', fmodby = :who, fmodwith = :entity,
- potype='NONE', pmodtime='now', pmodby = :who, pmodwith = :entity
- WHERE login = :login;
-#endif /* GDSS */
-
- return(MR_SUCCESS);
-}
-
-
-/**
- ** followup_uusr - do signature, set_user_modtime
- **
- ** Inputs:
- ** argv[0] - login (add_user)
- ** argv[U_SIGNATURE] - sig
- **
- **/
-
-followup_uuac(q, argv, cl)
- struct query *q;
- char *argv[];
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int who, status, id;
- char *entity, *name, *src, *dst;
- EXEC SQL END DECLARE SECTION;
-#ifdef GDSS
- char databuf[32], *kname_unparse();
- EXEC SQL BEGIN DECLARE SECTION;
- char rawsig[128];
- char *login;
- int sigwho, timestamp;
- EXEC SQL END DECLARE SECTION;
- SigInfo si;
-#endif /* GDSS */
-
- id = *(int *)argv[0];
- who = cl->client_id;
- entity = cl->entity;
-
-#ifdef GDSS
- if (q->vcnt == U_MODTIME && *argv[U_SIGNATURE + 1]) {
- /* unquote ' chars in signature */
- for (dst = src = argv[U_SIGNATURE+1]; *src; ) {
- if (*src == '\'')
- src++;
- *dst++ = *src++;
- }
- *dst = 0;
- login = malloc(1);
- status = id_to_name(id, "USER", &login);
- sprintf(databuf, "%s:%s", login, argv[U_MITID+1]);
- free(login);
- /* skip bytes for timestamp & kname */
- si.rawsig = (unsigned char *) rawsig;
-#ifdef DEBUG
- com_err(whoami, 0, "verifying sig");
-#endif /* DEBUG */
- status = GDSS_Verify(databuf, strlen(databuf), argv[U_SIGNATURE+1], &si);
-#ifdef DEBUG
- com_err(whoami, 0, "verified");
-#endif /* DEBUG */
- if (strlen(rawsig) > mr_sig_length) {
- com_err(whoami, 0, "GDSS signature would be truncated."); /** untested **/
- return(MR_INTERNAL);
- }
- if (status == 0) {
- name = kname_unparse(si.pname, si.pinst, si.prealm);
- status = name_to_id(name, "STRING", &sigwho);
- if (status == MR_NO_MATCH) {
- sigwho=add_string(name);
- } else if (status)
- return(status);
- timestamp = si.timestamp;
- } else {
- if (log_flags & LOG_GDSS)
- hex_dump(argv[U_SIGNATURE+1]);
- return(gdss2et(status));
- }
- } else {
- rawsig[0] = 0;
- sigwho = 0;
- timestamp = 0;
- }
-#endif /* GDSS */
-
- /* create finger entry, pobox & set modtime on user */
-
-#ifdef GDSS
- EXEC SQL REPEATED UPDATE users SET modtime='now', modby = :who, modwith = :entity,
- signature = :rawsig, sigdate = :timestamp, sigwho = :sigwho
- WHERE users_id = :id;
-#else /* GDSS */
- EXEC SQL REPEATED UPDATE users SET modtime='now', modby = :who, modwith = :entity
- WHERE users_id = :id;
-#endif /* GDSS */
- return(MR_SUCCESS);
-}
-
-
-/* followup_gpob: fixes argv[2] based on the IDs currently there and the
- * type in argv[1]. Then completes the upcall to the user.
- *
- * argv[2] is of the form "123:234" where the first integer is the machine
- * ID if it is a pop box, and the second is the string ID if it is an SMTP
- * box. argv[1] should be "POP", "SMTP", or "NONE". Boxes of type NONE
- * are skipped.
- */
-
-followup_gpob(q, sq, v, action, actarg, cl)
- register struct query *q;
- register struct save_queue *sq;
- register struct validate *v;
- register int (*action)();
- int actarg;
- client *cl;
-{
- char **argv, *index();
- char *ptype, *p;
- int mid, sid, status, i;
-
- /* for each row */
- while (sq_get_data(sq, &argv)) {
- mr_trim_args(2, argv);
- ptype = argv[1];
- p = index(argv[2], ':');
- *p++ = 0;
- mid = atoi(argv[2]);
- sid = atoi(p);
-
- if (!strcmp(ptype, "POP")) {
- status = id_to_name(mid, "MACHINE", &argv[2]);
- if (status == MR_NO_MATCH)
- return(MR_MACHINE);
- } else if (!strcmp(ptype, "SMTP")) {
- status = id_to_name(sid, "STRING", &argv[2]);
- if (status == MR_NO_MATCH)
- return(MR_STRING);
- } else /* ptype == "NONE" */ {
- goto skip;
- }
- if (status) return(status);
-
- if (!strcmp(q->shortname, "gpob")) {
- sid = atoi(argv[4]);
- if (sid > 0)
- status = id_to_name(sid, "USER", &argv[4]);
- else
- status = id_to_name(-sid, "STRING", &argv[4]);
- }
- if (status && status != MR_NO_MATCH) return(status);
-
- (*action)(q->vcnt, argv, actarg);
- skip:
- /* free saved data */
- for (i = 0; i < q->vcnt; i++)
- free(argv[i]);
- free(argv);
- }
-
- sq_destroy(sq);
- return (MR_SUCCESS);
-}
-
-
-/* followup_glin: fix the ace_name in argv[8]. argv[7] will contain the
- * ace_type: "LIST", "USER", or "NONE". Decode the id in argv[8] into the
- * proper name based on the type, and repace that string in the argv.
- * Also fixes the modby field by called followup_fix_modby.
- */
-
-followup_glin(q, sq, v, action, actarg, cl)
- register struct query *q;
- register struct save_queue *sq;
- register struct validate *v;
- register int (*action)();
- int actarg;
- client *cl;
-{
- char **argv, *malloc(), *realloc(), *type;
- int id, i, idx, status;
-
- idx = 8;
- if (!strcmp(q->shortname, "gsin"))
- idx = 12;
-
- while (sq_get_data(sq, &argv)) {
- mr_trim_args(q->vcnt, argv);
-
- id = atoi(argv[i = q->vcnt - 2]);
- if (id > 0)
- status = id_to_name(id, "USER", &argv[i]);
- else
- status = id_to_name(-id, "STRING", &argv[i]);
- if (status && status != MR_NO_MATCH)
- return(status);
-
- id = atoi(argv[idx]);
- type = argv[idx - 1];
-
- if (!strcmp(type, "LIST")) {
- status = id_to_name(id, "LIST", &argv[idx]);
- } else if (!strcmp(type, "USER")) {
- status = id_to_name(id, "USER", &argv[idx]);
- } else if (!strcmp(type, "KERBEROS")) {
- status = id_to_name(id, "STRING", &argv[idx]);
- } else if (!strcmp(type, "NONE")) {
- status = 0;
- free(argv[idx]);
- argv[idx] = strsave("NONE");
- } else {
- status = 0;
- free(argv[idx]);
- argv[idx] = strsave("???");
- }
- if (status && status != MR_NO_MATCH)
- return(status);
-
- if (!strcmp(q->shortname, "glin") && atoi(argv[6]) == -1) {
- argv[6] = realloc(argv[6], strlen(UNIQUE_GID) + 1);
- strcpy(argv[6], UNIQUE_GID);
- }
-
- /* send the data */
- (*action)(q->vcnt, argv, actarg);
-
- /* free saved data */
- for (i = 0; i < q->vcnt; i++)
- free(argv[i]);
- free(argv);
- }
-
- sq_destroy(sq);
- return (MR_SUCCESS);
-}
-
-
-/* followup_gqot: Fix the entity name, directory name & modby fields
- * argv[0] = filsys_id
- * argv[1] = type
- * argv[2] = entity_id
- * argv[3] = ascii(quota)
- */
-
-followup_gqot(q, sq, v, action, actarg, cl)
- struct query *q;
- register struct save_queue *sq;
- struct validate *v;
- register int (*action)();
- register int actarg;
- client *cl;
-{
- register int j;
- char **argv, *malloc();
- EXEC SQL BEGIN DECLARE SECTION;
- int id;
- char *name, *label;
- EXEC SQL END DECLARE SECTION;
- int status, idx;
-
- if (!strcmp(q->name, "get_quota") ||
- !strcmp(q->name, "get_quota_by_filesys"))
- idx = 4;
- else
- idx = 3;
- while (sq_get_data(sq, &argv)) {
- if (idx == 4) {
- switch (argv[1][0]) {
- case 'U':
- status = id_to_name(atoi(argv[2]), "USER", &argv[2]);
- break;
- case 'G':
- case 'L':
- status = id_to_name(atoi(argv[2]), "LIST", &argv[2]);
- break;
- case 'A':
- free(argv[2]);
- argv[2] = strsave("system:anyuser");
- break;
- default:
- id = atoi(argv[2]);
- argv[2] = malloc(8);
- sprintf(argv[2], "%d", id);
- }
- }
- id = atoi(argv[idx]);
- free(argv[idx]);
- argv[idx] = malloc(256);
- name = argv[idx];
- if (id == 0) {
- label = argv[0];
- EXEC SQL REPEATED SELECT name INTO :name FROM filesys
- WHERE label = :label;
- } else {
- EXEC SQL REPEATED SELECT dir INTO :name FROM nfsphys
- WHERE nfsphys_id = :id;
- }
- if (sqlca.sqlerrd[2] != 1) {
- sprintf(argv[idx], "#%d", id);
- }
-
- id = atoi(argv[idx+3]);
- if (id > 0)
- status = id_to_name(id, "USER", &argv[idx+3]);
- else
- status = id_to_name(-id, "STRING", &argv[idx+3]);
- if (status && status != MR_NO_MATCH)
- return(status);
- (*action)(q->vcnt, argv, actarg);
- for (j = 0; j < q->vcnt; j++)
- free(argv[j]);
- free(argv);
- }
- sq_destroy(sq);
- return(MR_SUCCESS);
-}
-
-
-/* followup_aqot: Add allocation to nfsphys after creating quota.
- * argv[0] = filsys_id
- * argv[1] = type if "add_quota" or "update_quota"
- * argv[2 or 1] = id
- * argv[3 or 2] = ascii(quota)
- */
-
-followup_aqot(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int quota, id, fs, who, physid;
- char *entity, *qtype, *table_name;
- EXEC SQL END DECLARE SECTION;
- char incr_qual[60];
- char *incr_argv[2];
- int status;
-
- table_name=q->rtable;
- fs = *(int *)argv[0];
- EXEC SQL REPEATED SELECT phys_id INTO :physid FROM filesys
- WHERE filsys_id = :fs;
- if(ingres_errno)
- return(mr_errcode);
-
- if (!strcmp(q->shortname, "aqot") || !strcmp(q->shortname, "uqot")) {
- qtype = argv[1];
- id = *(int *)argv[2];
- quota = atoi(argv[3]);
- sprintf(incr_qual,"q.filsys_id = %d",fs);
- } else {
- qtype = "USER";
- id = *(int *)argv[1];
- quota = atoi(argv[2]);
- sprintf(incr_qual,"q.filsys_id=%d AND q.type='%s' AND q.entity_id=%d",
- fs,qtype,id);
- }
-
- /* quota case of incremental_{before|after} only looks at slot 1 */
- incr_argv[1]=qtype;
-
- /* Follows one of many possible gross hacks to fix these particular
- * conflicts between what is possible in the query table and what
- * is possible in SQL.
- */
- if(q->type==APPEND) {
- incremental_clear_before();
- EXEC SQL INSERT INTO quota
- (filsys_id, type, entity_id, quota, phys_id)
- VALUES (:fs, :qtype, :id, :quota, :physid);
- incremental_after(table_name, incr_qual, incr_argv);
- } else {
- incremental_before(table_name, incr_qual, incr_argv);
- EXEC SQL UPDATE quota SET quota = :quota
- WHERE filsys_id = :fs AND type = :qtype AND entity_id = :id;
- status = mr_errcode;
- incremental_after(table_name, incr_qual, incr_argv);
- }
-
- if (ingres_errno)
- return(mr_errcode);
- flush_name(argv[0], q->rtable);
- if(q->type==APPEND) {
- EXEC SQL UPDATE tblstats SET appends = appends + 1, modtime = 'now'
- WHERE table_name = :table_name;
- } else {
- EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = 'now'
- WHERE table_name = :table_name;
- }
-
- /* Proceed with original followup */
- who = cl->client_id;
- entity = cl->entity;
-
- EXEC SQL REPEATED UPDATE quota
- SET modtime = 'now', modby = :who, modwith = :entity
- WHERE filsys_id = :fs and type = :qtype and entity_id = :id;
- EXEC SQL REPEATED UPDATE nfsphys SET allocated = allocated + :quota
- WHERE nfsphys_id = :physid;
- if (ingres_errno) return(mr_errcode);
- return(MR_SUCCESS);
-}
-
-
-/* Necessitated by the requirement of a correlation name by the incremental
- * routines, since query table deletes don't provide one.
- */
-followup_dqot(q,argv,cl)
- struct query *q;
- char **argv;
- struct client *cl;
-{
- char *qtype;
- int id, fs;
- char *incr_argv[2];
- EXEC SQL BEGIN DECLARE SECTION;
- char incr_qual[80];
- char *tblname;
- EXEC SQL END DECLARE SECTION;
-
- fs = *(int *)argv[0];
- if (!strcmp(q->shortname, "dqot")) {
- qtype = argv[1];
- id = *(int *)argv[2];
- } else {
- qtype = "USER";
- id = *(int *)argv[1];
- }
- sprintf(incr_qual,"q.filsys_id=%d AND q.type='%s' AND q.entity_id=%d",
- fs,qtype,id);
-
- /* quota case of incremental_{before|after} only looks at slot 1 */
- incr_argv[1]=qtype;
-
- incremental_before(q->rtable, incr_qual, incr_argv);
- EXEC SQL DELETE FROM quota q WHERE :incr_qual;
- incremental_clear_after();
-
- if (ingres_errno)
- return(mr_errcode);
- flush_name(argv[0], q->rtable);
-
- tblname = q->rtable;
- EXEC SQL UPDATE tblstats SET deletes = deletes + 1, modtime = 'now'
- WHERE table_name = :tblname;
- return(MR_SUCCESS);
-}
-
-
-followup_gpce(q, sq, v, action, actarg, cl)
- struct query *q;
- register struct save_queue *sq;
- struct validate *v;
- register int (*action)();
- register int actarg;
- client *cl;
-{
- register int i, j;
- char **argv, *malloc();
- int id, status;
-
- i = q->vcnt - 2;
- while (sq_get_data(sq, &argv)) {
- id = atoi(argv[PCAP_QSERVER]);
- status = id_to_name(id, "MACHINE", &argv[PCAP_QSERVER]);
- if (status) return (status);
- id = atoi(argv[i]);
- if (id > 0)
- status = id_to_name(id, "USER", &argv[i]);
- else
- status = id_to_name(-id, "STRING", &argv[i]);
- if (status && status != MR_NO_MATCH)
- return(status);
- (*action)(q->vcnt, argv, actarg);
- for (j = 0; j < q->vcnt; j++)
- free(argv[j]);
- free(argv);
- }
- sq_destroy(sq);
- return(MR_SUCCESS);
-}
-
-
-/* followup_gzcl:
- */
-
-followup_gzcl(q, sq, v, action, actarg, cl)
- register struct query *q;
- register struct save_queue *sq;
- register struct validate *v;
- register int (*action)();
- int actarg;
- client *cl;
-{
- int id, i, status;
- char **argv;
-
- while (sq_get_data(sq, &argv)) {
- mr_trim_args(q->vcnt, argv);
-
- id = atoi(argv[i = q->vcnt - 2]);
- if (id > 0)
- status = id_to_name(id, "USER", &argv[i]);
- else
- status = id_to_name(-id, "STRING", &argv[i]);
- if (status && status != MR_NO_MATCH)
- return(status);
-
- for (i = 1; i < 8; i+=2) {
- id = atoi(argv[i+1]);
- if (!strcmp(argv[i], "LIST")) {
- status = id_to_name(id, "LIST", &argv[i+1]);
- } else if (!strcmp(argv[i], "USER")) {
- status = id_to_name(id, "USER", &argv[i+1]);
- } else if (!strcmp(argv[i], "KERBEROS")) {
- status = id_to_name(id, "STRING", &argv[i+1]);
- } else if (!strcmp(argv[i], "NONE")) {
- status = 0;
- free(argv[i+1]);
- argv[i+1] = strsave("NONE");
- } else {
- status = 0;
- free(argv[i+1]);
- argv[i+1] = strsave("???");
- }
- if (status && status != MR_NO_MATCH)
- return(status);
- }
-
- /* send the data */
- (*action)(q->vcnt, argv, actarg);
-
- /* free saved data */
- for (i = 0; i < q->vcnt; i++)
- free(argv[i]);
- free(argv);
- }
- sq_destroy(sq);
- return(MR_SUCCESS);
-}
-
-
-/* followup_gsha:
- */
-
-followup_gsha(q, sq, v, action, actarg, cl)
- register struct query *q;
- register struct save_queue *sq;
- register struct validate *v;
- register int (*action)();
- int actarg;
- client *cl;
-{
- char **argv;
- int i, id, status;
-
- while (sq_get_data(sq, &argv)) {
- mr_trim_args(q->vcnt, argv);
-
- id = atoi(argv[4]);
- if (id > 0)
- status = id_to_name(id, "USER", &argv[4]);
- else
- status = id_to_name(-id, "STRING", &argv[4]);
- if (status && status != MR_NO_MATCH)
- return(status);
-
- id = atoi(argv[2]);
- if (!strcmp(argv[1], "LIST")) {
- status = id_to_name(id, "LIST", &argv[2]);
- } else if (!strcmp(argv[1], "USER")) {
- status = id_to_name(id, "USER", &argv[2]);
- } else if (!strcmp(argv[1], "KERBEROS")) {
- status = id_to_name(id, "STRING", &argv[2]);
- } else if (!strcmp(argv[1], "NONE")) {
- status = 0;
- free(argv[2]);
- argv[2] = strsave("NONE");
- } else {
- status = 0;
- free(argv[2]);
- argv[2] = strsave("???");
- }
- if (status && status != MR_NO_MATCH)
- return(status);
-
- /* send the data */
- (*action)(q->vcnt, argv, actarg);
-
- /* free saved data */
- for (i = 0; i < q->vcnt; i++)
- free(argv[i]);
- free(argv);
- }
- sq_destroy(sq);
- return(MR_SUCCESS);
-}
-
-
-\f
-/* Special query routines */
-
-/* set_pobox - this does all of the real work.
- * argv = user_id, type, box
- * if type is POP, then box should be a machine, and its ID should be put in
- * pop_id. If type is SMTP, then box should be a string and its ID should
- * be put in box_id. If type is NONE, then box doesn't matter.
- */
-
-int set_pobox(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int user, id;
- char *box, potype[9];
- EXEC SQL END DECLARE SECTION;
- int status;
-
- box = argv[2];
- user = *(int *)argv[0];
-
- EXEC SQL REPEATED SELECT pop_id, potype INTO :id, :potype FROM users
- WHERE users_id = :user;
- if (ingres_errno) return(mr_errcode);
- if (!strcmp(strtrim(potype), "POP"))
- set_pop_usage(id, -1);
-
- if (!strcmp(argv[1], "POP")) {
- status = name_to_id(box, "MACHINE", &id);
- if (status == MR_NO_MATCH)
- return(MR_MACHINE);
- else if (status)
- return(status);
- EXEC SQL REPEATED UPDATE users SET potype = 'POP', pop_id = :id
- WHERE users_id = :user;
- set_pop_usage(id, 1);
- } else if (!strcmp(argv[1], "SMTP")) {
- if (index(box, '/') || index(box, '|'))
- return(MR_BAD_CHAR);
- status = name_to_id(box, "STRING", &id);
- if (status == MR_NO_MATCH) {
- id=add_string(box);
- } else if (status)
- return(status);
- EXEC SQL REPEATED UPDATE users SET potype='SMTP', box_id = :id
- WHERE users_id = :user;
- } else /* argv[1] == "NONE" */ {
- EXEC SQL REPEATED UPDATE users SET potype='NONE'
- WHERE users_id = :user;
- }
-
- set_pobox_modtime(q, argv, cl);
- EXEC SQL REPEATED UPDATE tblstats SET updates = updates+1, modtime='now'
- WHERE table_name='users';
- if (ingres_errno) return(mr_errcode);
- return(MR_SUCCESS);
-}
-
-
-/* get_list_info: passed a wildcard list name, returns lots of stuff about
- * each list. This is tricky: first build a queue of all requested
- * data. Rest of processing consists of fixing gid, ace_name, and modby.
- */
-
-get_list_info(q, aargv, cl, action, actarg)
- register struct query *q;
- char **aargv;
- client *cl;
- register int (*action)();
- int actarg;
-{
- char *argv[13], *malloc(), *realloc();
- EXEC SQL BEGIN DECLARE SECTION;
- char *name, acl_type[9], listname[33], active[5], public[5], hidden[5];
- char maillist[5], grouplist[5], gid_str[6], acl_name[256], desc[256];
- char modtime[27], modby[256], modwith[9];
- int id, rowcount, acl_id, hid, modby_id;
- char qual[80];
- EXEC SQL END DECLARE SECTION;
- int returned, status;
- struct save_queue *sq, *sq_create();
-
- returned = rowcount = 0;
- name = aargv[0];
- convert_wildcards(name);
-
- sq = sq_create();
- sprintf(qual,"name LIKE '%s' ESCAPE '*'",name);
- optimize_sql_stmt(qual);
- EXEC SQL DECLARE csr102 CURSOR FOR SELECT list_id FROM list
- WHERE :qual;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr102;
- if (ingres_errno)
- return(mr_errcode);
- while(1)
- {
- EXEC SQL FETCH csr102 INTO :id;
- if(sqlca.sqlcode!=0) break;
- sq_save_data(sq, id);
- rowcount++;
- }
- EXEC SQL CLOSE csr102;
-
- if (ingres_errno) return(mr_errcode);
- if (rowcount == 0)
- return(MR_NO_MATCH);
-
- argv[0] = listname; argv[1] = active; argv[2] = public; argv[3] = hidden;
- argv[4] = maillist; argv[5] = grouplist; argv[6] = gid_str;
- argv[7] = acl_type; argv[9] = desc; argv[10] = modtime; argv[12] = modwith;
-
- while (sq_get_data(sq, &id)) {
- if (id == 0)
- continue;
- argv[6] = gid_str;
- 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
- INTO :listname, :active, :public, :hidden, :hid, :maillist,
- :grouplist, :gid_str, :acl_type, :acl_id, :desc,
- :modtime, :modby_id, :modwith
- FROM list WHERE list_id = :id;
-
- if (ingres_errno) return(mr_errcode);
-
- if (atoi(gid_str) == -1)
- argv[6] = UNIQUE_GID;
-
- argv[8] = malloc(0);
- if (!strcmp(acl_type, "LIST")) {
- status = id_to_name(acl_id, "LIST", &argv[8]);
- } else if (!strcmp(acl_type, "USER")) {
- status = id_to_name(acl_id, "USER", &argv[8]);
- } else if (!strcmp(acl_type, "KERBEROS")) {
- status = id_to_name(acl_id, "STRING", &argv[8]);
- } else if (!strcmp(acl_type, "NONE")) {
- status = 0;
- free(argv[8]);
- argv[8] = strsave("NONE");
- } else {
- status = 0;
- free(argv[8]);
- argv[8] = strsave("???");
- }
- if (status && status != MR_NO_MATCH) return(status);
-
- argv[11] = malloc(0);
- if (modby_id > 0)
- status = id_to_name(modby_id, "USER", &argv[11]);
- else
- status = id_to_name(-modby_id, "STRING", &argv[11]);
- if (status && status != MR_NO_MATCH) return(status);
-
- mr_trim_args(q->vcnt, argv);
- returned++;
- (*action)(q->vcnt, argv, actarg);
- free(argv[8]);
- free(argv[11]);
- }
-
- sq_destroy(sq);
- if (ingres_errno) return(mr_errcode);
- return (MR_SUCCESS);
-}
-
-
-/* Add_member_to_list: do list flattening as we go! MAXLISTDEPTH is
- * how many different ancestors a member is allowed to have.
- */
-
-#define MAXLISTDEPTH 1024
-
-int add_member_to_list(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int id, lid, mid, error, who, ref, rowcnt;
- char *mtype, dtype[9], *entity;
- EXEC SQL END DECLARE SECTION;
- int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
- int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
- int status;
- char *dtypes[MAXLISTDEPTH];
- char *iargv[3], *buf;
-
- lid = *(int *)argv[0];
- mtype = argv[1];
- mid = *(int *)argv[2];
- /* if the member is already a direct member of the list, punt */
- EXEC SQL REPEATED SELECT COUNT(list_id) INTO :rowcnt FROM imembers
- WHERE list_id = :lid AND member_id = :mid
- AND member_type = :mtype AND direct = 1;
- if (rowcnt > 0)
- return(MR_EXISTS);
- if (!strcasecmp(mtype, "STRING")) {
- buf = malloc(0);
- status = id_to_name(mid, "STRING", &buf);
- if (status) return(status);
- if (index(buf, '/') || index(buf, '|')) {
- free(buf);
- return(MR_BAD_CHAR);
- }
- free(buf);
- }
-
- ancestors[0] = lid;
- aref[0] = 1;
- acount = 1;
- EXEC SQL DECLARE csr103 CURSOR FOR
- SELECT list_id, ref_count FROM imembers
- WHERE member_id = :lid AND member_type='LIST';
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr103;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr103 INTO :id, :ref;
- if(sqlca.sqlcode != 0) break;
- aref[acount] = ref;
- ancestors[acount++] = id;
- if (acount >= MAXLISTDEPTH) break;
- }
- EXEC SQL CLOSE csr103;
- if (ingres_errno) return(mr_errcode);
- if (acount >= MAXLISTDEPTH) {
- return(MR_INTERNAL);
- }
- descendants[0] = mid;
- dtypes[0] = mtype;
- dref[0] = 1;
- dcount = 1;
- error = 0;
- if (!strcmp(mtype, "LIST")) {
- EXEC SQL DECLARE csr104 CURSOR FOR
- SELECT member_id, member_type, ref_count
- FROM imembers
- WHERE list_id = :mid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr104;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr104 INTO :id, :dtype, :ref;
- if(sqlca.sqlcode != 0) break;
- switch (dtype[0]) {
- case 'L':
- dtypes[dcount] = "LIST";
- break;
- case 'U':
- dtypes[dcount] = "USER";
- break;
- case 'S':
- dtypes[dcount] = "STRING";
- break;
- case 'K':
- dtypes[dcount] = "KERBEROS";
- break;
- default:
- error++;
- break;
- }
- dref[dcount] = ref;
- descendants[dcount++] = id;
- if (dcount >= MAXLISTDEPTH) {
- error++;
- break;
- }
- }
- EXEC SQL CLOSE csr104;
- if (ingres_errno) return(mr_errcode);
- if (error)
- return(MR_INTERNAL);
- }
- for (a = 0; a < acount; a++) {
- lid = ancestors[a];
- for (d = 0; d < dcount; d++) {
- mid = descendants[d];
- mtype = dtypes[d];
- if (mid == lid && !strcmp(mtype, "LIST")) {
- return(MR_LISTLOOP);
- }
- EXEC SQL REPEATED SELECT COUNT(ref_count) INTO :rowcnt
- FROM imembers
- WHERE list_id = :lid AND member_id = :mid
- AND member_type = :mtype;
- ref = aref[a] * dref[d];
- if (rowcnt > 0) {
- if (a == 0 && d == 0) {
- EXEC SQL UPDATE imembers
- SET ref_count = ref_count+:ref, direct=1
- WHERE list_id = :lid AND member_id = :mid
- AND member_type = :mtype;
- } else {
- EXEC SQL UPDATE imembers
- SET ref_count = ref_count+:ref
- WHERE list_id = :lid AND member_id = :mid
- AND member_type = :mtype;
- }
- } else {
- incremental_clear_before();
- if (a == 0 && d == 0) {
- EXEC SQL INSERT INTO imembers
- (list_id, member_id, direct, member_type, ref_count)
- VALUES (:lid, :mid, 1, :mtype, 1);
- } else {
- EXEC SQL INSERT INTO imembers
- (list_id, member_id, member_type, ref_count)
- VALUES (:lid, :mid, :mtype, 1);
- }
- iargv[0] = (char *)lid;
- iargv[1] = mtype;
- iargv[2] = (char *)mid;
- incremental_after("members", 0, iargv);
- }
- }
- }
- lid = *(int *)argv[0];
- entity = cl->entity;
- who = cl->client_id;
- EXEC SQL REPEATED UPDATE list
- SET modtime='now', modby = :who, modwith = :entity
- WHERE list_id = :lid;
- if (ingres_errno) return(mr_errcode);
- return(MR_SUCCESS);
-}
-
-
-/* Delete_member_from_list: do list flattening as we go!
- */
-
-int delete_member_from_list(q, argv, cl)
- struct query *q;
- char **argv;
- client *cl;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int id, lid, mid, cnt, error, who, ref;
- char *mtype, dtype[9], *entity;
- EXEC SQL END DECLARE SECTION;
- int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
- int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
- char *dtypes[MAXLISTDEPTH];
- char *iargv[3];
-
- lid = *(int *)argv[0];
- mtype = argv[1];
- mid = *(int *)argv[2];
- /* if the member is not a direct member of the list, punt */
- EXEC SQL REPEATED SELECT COUNT(list_id) INTO :cnt FROM imembers
- WHERE list_id = :lid AND member_id = :mid
- AND member_type = :mtype AND direct = 1;
- if (ingres_errno) return(mr_errcode);
- if (cnt == 0)
- return(MR_NO_MATCH);
- ancestors[0] = lid;
- aref[0] = 1;
- acount = 1;
- EXEC SQL DECLARE csr105 CURSOR FOR
- SELECT list_id, ref_count FROM imembers
- WHERE member_id = :lid AND member_type = 'LIST';
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr105;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr105 INTO :id, :ref;
- if(sqlca.sqlcode!=0) break;
- aref[acount] = ref;
- ancestors[acount++] = id;
- if (acount >= MAXLISTDEPTH) break;
- }
- EXEC SQL CLOSE csr105;
- if (ingres_errno)
- return(mr_errcode);
- if (acount >= MAXLISTDEPTH)
- return(MR_INTERNAL);
- descendants[0] = mid;
- dtypes[0] = mtype;
- dref[0] = 1;
- dcount = 1;
- error = 0;
- if (!strcmp(mtype, "LIST")) {
- EXEC SQL DECLARE csr106 CURSOR FOR
- SELECT member_id, member_type, ref_count FROM imembers
- WHERE list_id = :mid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr106;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr106 INTO :id, :dtype, :ref;
- if(sqlca.sqlcode!=0) break;
- switch (dtype[0]) {
- case 'L':
- dtypes[dcount] = "LIST";
- break;
- case 'U':
- dtypes[dcount] = "USER";
- break;
- case 'S':
- dtypes[dcount] = "STRING";
- break;
- case 'K':
- dtypes[dcount] = "KERBEROS";
- break;
- default:
- error++;
- break;
- }
- dref[dcount] = ref;
- descendants[dcount++] = id;
- if (dcount >= MAXLISTDEPTH) break;
- }
- EXEC SQL CLOSE csr106;
- if (ingres_errno)
- return(mr_errcode);
- if (error)
- return(MR_INTERNAL);
- }
- for (a = 0; a < acount; a++) {
- lid = ancestors[a];
- for (d = 0; d < dcount; d++) {
- mid = descendants[d];
- mtype = dtypes[d];
- if (mid == lid && !strcmp(mtype, "LIST")) {
- return(MR_LISTLOOP);
- }
- EXEC SQL REPEATED SELECT ref_count INTO :cnt FROM imembers
- WHERE list_id = :lid AND member_id = :mid AND member_type = :mtype;
- ref = aref[a] * dref[d];
- if (cnt <= ref) {
- iargv[0] = (char *)lid;
- iargv[1] = mtype;
- iargv[2] = (char *)mid;
- incremental_before("members", 0, iargv);
- EXEC SQL DELETE FROM imembers
- WHERE list_id = :lid AND member_id = :mid
- AND member_type= :mtype;
- incremental_clear_after();
- } else if (a == 0 && d == 0) {
- EXEC SQL UPDATE imembers
- SET ref_count = ref_count - :ref, direct = 0
- WHERE list_id = :lid AND member_id = :mid
- AND member_type = :mtype;
- } else {
- EXEC SQL UPDATE imembers
- SET ref_count = ref_count - :ref
- WHERE list_id = :lid AND member_id = :mid
- AND member_type = :mtype;
- }
- }
- }
- lid = *(int *)argv[0];
- entity = cl->entity;
- who = cl->client_id;
- EXEC SQL UPDATE list SET modtime = 'now', modby = :who, modwith = :entity
- WHERE list_id = :lid;
- if (ingres_errno) return(mr_errcode);
- return(MR_SUCCESS);
-}
-
-
-/* get_ace_use - given a type and a name, return a type and a name.
- * The ace_type is one of "LIST", "USER", "RLIST", or "RUSER" in argv[0],
- * and argv[1] will contain the ID of the entity in question. The R*
- * types mean to recursively look at every containing list, not just
- * when the object in question is a direct member. On return, the
- * usage type will be one of LIST, SERVICE, FILESYS, QUOTA, QUERY, or ZEPHYR.
- */
-
-int get_ace_use(q, argv, cl, action, actarg)
- struct query *q;
- char *argv[];
- client *cl;
- int (*action)();
- int actarg;
-{
- int found = 0;
- EXEC SQL BEGIN DECLARE SECTION;
- char *atype;
- int aid, listid, id;
- EXEC SQL END DECLARE SECTION;
- struct save_queue *sq, *sq_create();
-
- atype = argv[0];
- aid = *(int *)argv[1];
- if (!strcmp(atype, "LIST") || !strcmp(atype, "USER") ||
- !strcmp(atype, "KERBEROS")) {
- return(get_ace_internal(atype, aid, action, actarg));
- }
-
- sq = sq_create();
- if (!strcmp(atype, "RLIST")) {
- sq_save_data(sq, aid);
- /* get all the list_id's of containing lists */
- EXEC SQL DECLARE csr107 CURSOR FOR
- SELECT list_id FROM imembers
- WHERE member_type='LIST' AND member_id = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr107;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr107 INTO :listid;
- if(sqlca.sqlcode != 0) break;
- sq_save_unique_data(sq, listid);
- }
- EXEC SQL CLOSE csr107;
- /* now process each one */
- while (sq_get_data(sq, &id)) {
- if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS)
- found++;
- }
- }
-
- if (!strcmp(atype, "RUSER")) {
- EXEC SQL DECLARE csr108 CURSOR FOR
- SELECT list_id FROM imembers
- WHERE member_type='USER' AND member_id = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr108;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr108 INTO :listid;
- if(sqlca.sqlcode != 0) break;
- sq_save_data(sq, listid);
- }
- EXEC SQL CLOSE csr108;
- /* now process each one */
- while (sq_get_data(sq, &id)) {
- if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS)
- found++;
- }
- if (get_ace_internal("USER", aid, action, actarg) == MR_SUCCESS)
- found++;
- }
-
- if (!strcmp(atype, "RKERBERO")) {
- EXEC SQL DECLARE csr109 CURSOR FOR
- SELECT list_id FROM imembers
- WHERE member_type='KERBEROS' AND member_id = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr109;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr109 INTO :listid;
- if(sqlca.sqlcode != 0) break;
- sq_save_data(sq, listid);
- }
- EXEC SQL CLOSE csr109;
- /* now process each one */
- while (sq_get_data(sq, &id)) {
- if (get_ace_internal("LIST", id, action, actarg) == MR_SUCCESS)
- found++;
- }
- if (get_ace_internal("KERBEROS", aid, action, actarg) == MR_SUCCESS)
- found++;
- }
-
- sq_destroy(sq);
- if (ingres_errno) return(mr_errcode);
- if (!found) return(MR_NO_MATCH);
- return(MR_SUCCESS);
-}
-
-
-/* This looks up a single list or user for ace use. atype must be "USER"
- * or "LIST", and aid is the ID of the corresponding object. This is used
- * by get_ace_use above.
- */
-
-get_ace_internal(atype, aid, action, actarg)
- EXEC SQL BEGIN DECLARE SECTION;
- char *atype;
- int aid;
- EXEC SQL END DECLARE SECTION;
- int (*action)();
- int actarg;
-{
- char *rargv[2];
- int found = 0;
- EXEC SQL BEGIN DECLARE SECTION;
- char name[33];
- EXEC SQL END DECLARE SECTION;
-
- rargv[1] = name;
- if (!strcmp(atype, "LIST")) {
- rargv[0] = "FILESYS";
- EXEC SQL DECLARE csr110 CURSOR FOR
- SELECT label FROM filesys
- WHERE owners = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr110;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr110 INTO :name;
- if(sqlca.sqlcode != 0) break;
- (*action)(2, rargv, actarg);
- found++;
- }
- EXEC SQL CLOSE csr110;
-
- rargv[0] = "QUERY";
- EXEC SQL DECLARE csr111 CURSOR FOR
- SELECT capability FROM capacls
- WHERE list_id = :aid ;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr111;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr111 INTO :name ;
- if(sqlca.sqlcode != 0) break;
- (*action)(2, rargv, actarg);
- found++;
- }
- EXEC SQL CLOSE csr111;
- } else if (!strcmp(atype, "USER")) {
- rargv[0] = "FILESYS";
- EXEC SQL DECLARE csr112 CURSOR FOR
- SELECT label FROM filesys
- WHERE owner = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr112;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr112 INTO :name ;
- if(sqlca.sqlcode != 0) break;
- (*action)(2, rargv, actarg);
- found++;
- }
- EXEC SQL CLOSE csr112;
- }
-
- rargv[0] = "LIST";
- EXEC SQL DECLARE csr113 CURSOR FOR
- SELECT name FROM list
- WHERE acl_type = :atype AND acl_id = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr113;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr113 INTO :name;
- if(sqlca.sqlcode != 0) break;
- (*action)(2, rargv, actarg);
- found++;
- }
- EXEC SQL CLOSE csr113;
-
- rargv[0] = "SERVICE";
- EXEC SQL DECLARE csr114 CURSOR FOR
- SELECT name FROM servers
- WHERE acl_type = :atype AND acl_id = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr114;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr114 INTO :name;
- if(sqlca.sqlcode != 0) break;
- (*action)(2, rargv, actarg);
- found++;
- }
- EXEC SQL CLOSE csr114;
-
- rargv[0] = "HOSTACCESS";
- EXEC SQL DECLARE csr115 CURSOR FOR
- SELECT name FROM machine m, hostaccess ha
- WHERE m.mach_id = ha.mach_id AND ha.acl_type = :atype
- AND ha.acl_id = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr115;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr115 INTO :name;
- if(sqlca.sqlcode != 0) break;
- (*action)(2, rargv, actarg);
- found++;
- }
- EXEC SQL CLOSE csr115;
-
- rargv[0] = "ZEPHYR";
- EXEC SQL DECLARE csr116 CURSOR FOR
- SELECT class FROM zephyr z
- WHERE z.xmt_type = :atype AND z.xmt_id = :aid
- OR z.sub_type = :atype AND z.sub_id = :aid
- OR z.iws_type = :atype AND z.iws_id = :aid
- OR z.iui_type = :atype AND z.iui_id = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr116;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr116 INTO :name;
- if(sqlca.sqlcode != 0) break;
- (*action)(2, rargv, actarg);
- found++;
- }
- EXEC SQL CLOSE csr116;
-
- if (!found) return(MR_NO_MATCH);
- return(MR_SUCCESS);
-}
-
-
-/* get_lists_of_member - given a type and a name, return the name and flags
- * of all of the lists of the given member. The member_type is one of
- * "LIST", "USER", "STRING", "RLIST", "RUSER", or "RSTRING" in argv[0],
- * and argv[1] will contain the ID of the entity in question. The R*
- * types mean to recursively look at every containing list, not just
- * when the object in question is a direct member.
- */
-
-int get_lists_of_member(q, argv, cl, action, actarg)
- struct query *q;
- char *argv[];
- client *cl;
- int (*action)();
- int actarg;
-{
- int found = 0, direct = 1;
- char *rargv[6];
- EXEC SQL BEGIN DECLARE SECTION;
- char *atype;
- int aid, listid, id;
- char name[33], active[5], public[5], hidden[5], maillist[5], grouplist[5];
- EXEC SQL END DECLARE SECTION;
-
- atype = argv[0];
- aid = *(int *)argv[1];
- if (!strcmp(atype, "RLIST")) {
- atype = "LIST";
- direct = 0;
- }
- if (!strcmp(atype, "RUSER")) {
- atype = "USER";
- direct = 0;
- }
- if (!strcmp(atype, "RSTRING")) {
- atype = "STRING";
- direct = 0;
- }
- if (!strcmp(atype, "RKERBEROS")) {
- atype = "KERBEROS";
- direct = 0;
- }
-
- rargv[0] = name;
- rargv[1] = active;
- rargv[2] = public;
- rargv[3] = hidden;
- rargv[4] = maillist;
- rargv[5] = grouplist;
- if (direct) {
- EXEC SQL DECLARE csr117a CURSOR FOR
- SELECT l.name, CHAR(l.active), CHAR(l.publicflg), CHAR(l.hidden),
- CHAR(l.maillist), CHAR(l.grouplist)
- FROM list l, imembers im
- WHERE l.list_id = im.list_id AND im.direct = 1
- AND im.member_type = :atype AND im.member_id = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr117a;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr117a
- INTO :name, :active, :public, :hidden, :maillist, :grouplist;
- if(sqlca.sqlcode != 0) break;
- (*action)(6, rargv, actarg);
- found++;
- }
- EXEC SQL CLOSE csr117a;
- } else {
- EXEC SQL DECLARE csr117b CURSOR FOR
- SELECT l.name, CHAR(l.active), CHAR(l.publicflg), CHAR(l.hidden),
- CHAR(l.maillist), CHAR(l.grouplist)
- FROM list l, imembers im
- WHERE l.list_id = im.list_id
- AND im.member_type = :atype AND im.member_id = :aid;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr117b;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr117b
- INTO :name, :active, :public, :hidden, :maillist, :grouplist;
- if(sqlca.sqlcode != 0) break;
- (*action)(6, rargv, actarg);
- found++;
- }
- EXEC SQL CLOSE csr117b;
- }
-
- if (ingres_errno) return(mr_errcode);
- if (!found) return(MR_NO_MATCH);
- return(MR_SUCCESS);
-}
-
-
-/* qualified_get_lists: passed "TRUE", "FALSE", or "DONTCARE" for each of
- * the five flags associated with each list. It will return the name of
- * each list that meets the quailifications. It does this by building a
- * where clause based on the arguments, then doing a retrieve.
- */
-
-static char *lflags[5] = { "active", "publicflg", "hidden", "maillist", "grouplist" };
-
-int qualified_get_lists(q, argv, cl, action, actarg)
- struct query *q;
- char *argv[];
- client *cl;
- int (*action)();
- int actarg;
-{
- return(qualified_get(q, argv, action, actarg, "l.list_id != 0",
- "l", "name", lflags));
-}
-
-
-/* get_members_of_list - this gets only direct members */
-
-get_members_of_list(q, argv, cl, action, actarg)
- struct query *q;
- char *argv[];
- client *cl;
- int (*action)();
- int actarg;
-{
- return(gmol_internal(q, argv, cl, action, actarg, 1));
-}
-
-/* get_end_members_of_list - this gets direct or indirect members */
-
-get_end_members_of_list(q, argv, cl, action, actarg)
- struct query *q;
- char *argv[];
- client *cl;
- int (*action)();
- int actarg;
-{
- return(gmol_internal(q, argv, cl, action, actarg, 0));
-}
-
-/** gmol_internal - optimized query for retrieval of list members
- ** used by both get_members_of_list and get_end_members_of_list
- **
- ** Inputs:
- ** argv[0] - list_id
- **
- ** Description:
- ** - retrieve USER members, then LIST members, then STRING members
- **/
-
-gmol_internal(q, argv, cl, action, actarg, flag)
- struct query *q;
- char *argv[];
- client *cl;
- int (*action)();
- int actarg;
- int flag;
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int list_id, member_id, direct;
- char member_name[129], member_type[9];
- EXEC SQL END DECLARE SECTION;
- char *targv[2];
- int members;
- struct save_queue *sq;
-
- /* true/false flag indicates whether to display only direct members. */
- if (flag)
- direct = 0;
- else
- direct = -1;
-
- list_id = *(int *)argv[0];
- members = 0;
- sq = sq_create();
-
- EXEC SQL DECLARE csr118 CURSOR FOR
- SELECT member_type, member_id FROM imembers
- WHERE list_id = :list_id AND direct > :direct;
- if (ingres_errno)
- return(mr_errcode);
- EXEC SQL OPEN csr118;
- if (ingres_errno)
- return(mr_errcode);
- while(1) {
- EXEC SQL FETCH csr118 INTO :member_type, :member_id;
- if (sqlca.sqlcode != 0) break;
- if (members++ > 49)
- break;
- sq_save_data(sq, ((int)member_type[0] << 24) | (member_id & 0xffffff));
- }
- EXEC SQL CLOSE csr118;
-
- if (members <= 49) {
- targv[1] = malloc(0);
- while (sq_remove_data(sq, &member_id)) {
- switch (member_id >> 24) {
- case 'U':
- targv[0] = "USER";
- id_to_name(member_id & 0xffffff, "USER", &targv[1]);
- (*action)(2, targv, actarg);
- break;
- case 'L':
- targv[0] = "LIST";
- id_to_name(member_id & 0xffffff, "LIST", &targv[1]);
- (*action)(2, targv, actarg);
- break;
- case 'S':
- targv[0] = "STRING";
- id_to_name(member_id & 0xffffff, "STRING", &targv[1]);
- (*action)(2, targv, actarg);
- break;
- case 'K':
- targv[0] = "KERBEROS";
- id_to_name(member_id & 0xffffff, "STRING", &targv[1]);
- (*action)(2, targv, actarg);
- break;
- default:
- sq_destroy(sq);
- return(MR_INTERNAL);
- }