* Copyright (C) 1987 by the Massachusetts Institute of Technology
*
* $Log$
- * Revision 1.5 1987-07-30 14:54:13 wesommer
- * Added debugging code in an attempt to catch a flakey problem.
+ * Revision 1.11 1987-08-28 14:55:45 mike
+ * Modified delete_locker to require only one argument, the login name.
+ * Modified get_groups_of_all_users and get_all_poboxes to disable INGRES
+ * table locking.
*
+Revision 1.10 87/08/25 15:56:54 mike
+- Fixed bugs in get_groups_of_all_users
+- Added tblstats updates to add_user_group
+- Added routines: add_hostaccess (ashi), delete_hostaccess (dshi),
+ followup_ushp, and followup_usha
+
+Revision 1.9 87/08/22 17:41:34 wesommer
+More of Mike's changes.
+
+Revision 1.8 87/08/18 15:05:20 wesommer
+Fixed definition of add_locker.
+
+Revision 1.7 87/08/04 01:49:41 wesommer
+Rearranged messages.
+
+Revision 1.6 87/08/04 01:10:02 wesommer
+Changes by mike; checked in prior to my hacking.
+
+Revision 1.5 87/07/30 14:54:13 wesommer
+Added debugging code in an attempt to catch a flakey problem.
+
Revision 1.4 87/07/30 00:30:21 wesommer
replaced appends = appends+1 with appends = tbs.appends+1
return(SMS_SUCCESS);
##}
+
+/**
+ ** access_maillist - access_list + disallow adding user-group to maillists
+ **
+ ** Inputs:
+ ** argv[0] - list_id
+ **
+ **/
+
+access_maillist(q, argv, cl)
+ struct query *q;
+ char *argv[];
+ client *cl;
+##{
+## int list_id;
+## int exists;
+## char list_name[32];
+ int status;
+
+ status = access_list(q, argv, cl);
+ if (status != SMS_SUCCESS) return(status);
+ if (bcmp(q->name, "add_maillist", 12)) return(status);
+
+ list_id = *(int *)argv[0];
+## range of g is groups
+## repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id))
+ if (!exists) return(SMS_SUCCESS);
+## repeat retrieve (list_name = list.name) where list.#list_id = @list_id
+## repeat retrieve (exists = any(users.login where users.login = @list_name))
+ return ((exists) ? SMS_USER_GROUP : SMS_SUCCESS);
+##}
+
+/**
+ ** Setup routine for add_group
+ **
+ ** Inputs: none
+ **
+ ** Description: allocate next gid and store in values table
+ **
+ **/
+
+setup_add_group(q, argv, cl, access_check)
+ struct query *q;
+ char *argv[];
+ client *cl;
+ int access_check;
+##{
+## int ngid;
+## int exists;
+ int status;
+
+ status = access_list(q, argv, cl);
+
+ if (status != SMS_SUCCESS || access_check) return(status);
+
+## range of g is groups
+## range of v is values
+## repeat retrieve (ngid = v.value) where v.name = "gid"
+ exists = 1;
+ while (exists) {
+ ngid++;
+## repeat retrieve (exists = any(g.#gid where g.#gid = @ngid))
+ }
+
+## repeat replace v (value = @ngid) where v.name = "gid"
+ return(SMS_SUCCESS);
+##}
\f
/**
** Setup routine for add_user
##}
/**
- ** Setup routine for add_group
+ ** followup_add_user - add finger entry, set_user_modtime
+ ** followup_delete_user - delete finger entry
**
- ** Inputs: none
+ ** Inputs:
+ ** argv[0] - login (add_user)
+ ** argv[0] - users_id (delete_user)
**
- ** Description: allocate next gid and store in values table
+ **/
+
+followup_add_user(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## char *login;
+## int users_id;
+## char first[33];
+## char middle[33];
+## char last[33];
+## char fullname[128];
+ register char *cp1;
+ register char *cp2;
+
+ login = argv[0];
+
+ /* get user information */
+## range of u is users
+## repeat retrieve (users_id = u.#users_id, last = u.#last,
+## first = u.#first, middle = u.#middle)
+## where u.#login = @login
+
+ /* build fullname */
+ cp2 = fullname;
+ cp1 = first;
+ while (*cp1) *cp2++ = *cp1++;
+ *cp2++ = ' ';
+ cp1 = middle;
+ if (*cp1 == 0) cp2--;
+ while (*cp1) *cp2++ = *cp1++;
+ *cp2++ = ' ';
+ cp1 = last;
+ while (*cp2++ = *cp1++) ;
+
+ /* create a finger entry */
+## repeat append finger (#users_id = @users_id, #fullname = @fullname)
+
+ /* set modtime (creation time) on user */
+## repeat replace u (modtime = "now") where u.#users_id = @users_id
+
+ return(SMS_SUCCESS);
+##}
+
+followup_delete_user(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## int users_id;
+
+ users_id = *(int *)argv[0];
+## repeat delete finger where finger.#users_id = @users_id
+ return(SMS_SUCCESS);
+##}
+\f
+/**
+ ** setup_add_filesys - verify existance of referenced file systems
+ ** setup_update_filesys - same, except argv[1..5] --> argv[2..6]
+ **
+ ** Inputs: Add Update
+ ** argv[0] - label label
+ ** argv[1] - type new label
+ ** argv[2] - mach_id type
+ ** argv[3] - name mach_id
+ ** argv[4] - mount name
+ ** argv[5] - access mount
+ ** argv[6] - access
+ **
+ ** Description:
+ ** - for type = RVD:
+ ** * verify mach_id/name in rvdvirt
+ ** * verify access in {r, x, R, X}
+ ** - for type = NFS:
+ ** * extract directory prefix from name
+ ** * verify mach_id/dir in nfsphys
+ ** * verify access in {r, w, R, W}
+ **
+ ** Errors:
+ ** SMS_RVD - no such rvd
+ ** SMS_NFS - specified directory not exported
+ ** SMS_FILESYS_ACCESS - invalid filesys access
**
**/
-setup_add_group(q, argv, cl, access_check)
+setup_add_filesys(q, argv)
struct query *q;
char *argv[];
- client *cl;
- int access_check;
+{
+ char *type;
+ int mach_id;
+ char *name;
+ char *access;
+
+ type = argv[1];
+ mach_id = *(int *)argv[2];
+ name = argv[3];
+ access = argv[5];
+
+ if (!bcmp(type, "RVD", 3))
+ return (check_rvd(mach_id, name, access));
+ else if (!bcmp(type, "NFS", 3))
+ return (check_nfs(mach_id, name, access));
+ else
+ return(SMS_SUCCESS);
+}
+
+setup_update_filesys(q, argv)
+ struct query *q;
+ char *argv[];
+{
+ char *type;
+ int mach_id;
+ char *name;
+ char *access;
+
+ type = argv[2];
+ mach_id = *(int *)argv[3];
+ name = argv[4];
+ access = argv[6];
+
+ if (!bcmp(type, "RVD", 3))
+ return (check_rvd(mach_id, name, access));
+ else if (!bcmp(type, "NFS", 3))
+ return (check_nfs(mach_id, name, access));
+ else
+ return(SMS_SUCCESS);
+}
+
+##check_rvd(mach_id, name, access)
+## int mach_id;
+## char *name;
+ char *access;
##{
-## int ngid;
-## int exists;
+## int rowcount;
+ char caccess;
- if (access_check) return(SMS_SUCCESS);
+## range of rv is rvdvirt
+## retrieve (rowcount = any(rv.#name where rv.#mach_id = mach_id and
+## rv.#name = name))
+ if (rowcount == 0) return(SMS_RVD);
-## range of g is groups
-## range of v is values
-## repeat retrieve (ngid = v.value) where v.name = "gid"
- exists = 1;
- while (exists) {
- ngid++;
-## repeat retrieve (exists = any(g.#gid where g.#gid = @ngid))
- }
+ caccess = (isupper(*access)) ? tolower(*access) : *access;
+ if (caccess != 'r' && caccess != 'x') return(SMS_FILESYS_ACCESS);
-## repeat replace v (value = @ngid) where v.name = "gid"
return(SMS_SUCCESS);
##}
+
+##check_nfs(mach_id, name, access)
+## int mach_id;
+ char *name;
+ char *access;
+##{
+## int rowcount;
+## char dir[32];
+ char caccess;
+ register char *cp1;
+ register char *cp2;
+
+ caccess = (isupper(*access)) ? tolower(*access) : *access;
+ if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS);
+
+## range of np is nfsphys
+## retrieve (dir = np.#dir) where np.#mach_id = mach_id
+## {
+ cp1 = name;
+ cp2 = dir;
+ while (*cp2) {
+ if (*cp1++ != *cp2) break;
+ cp2++;
+ }
+ if (*cp2 == 0) return(SMS_SUCCESS);
+## }
+
+ return(SMS_NFS);
+##}
\f
/* Followup Routines */
## repeat replace f (modtime = "now") where f.#users_id = @users_id
return(SMS_SUCCESS);
##}
+\f
+/**
+ ** followup_amtl - followup for amtl and dmfl; when adding a list
+ ** member to a maillist, add list to maillist table,
+ ** unless list is a user-group.
+ ** Then set_list_modtime_by_id.
+ **
+ ** Inputs:
+ ** argv[0] - list_id
+ ** argv[1] - member_type
+ ** argv[2] - member_id
+ **
+ **/
+
+followup_amtl(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## int list_id;
+## int member_id;
+## int exists;
+## char list_name[33];
+
+ list_id = *(int *)argv[0];
+
+## repeat replace list (modtime = "now") where list.#list_id = @list_id
+
+ /* if query is not amtl or if member_type is not LIST then return */
+ if (bcmp(q->shortname, "amtl", 4) || bcmp(argv[1], "LIST", 4))
+ return(SMS_SUCCESS);
+
+ member_id = *(int *)argv[2];
+## range of l is list
+## range of ml is maillists
+## range of g is groups
+
+ /* is parent list a mailing list? */
+## repeat retrieve (exists = any(ml.#list_id where ml.#list_id=@list_id))
+
+ /* if not then return */
+ if (!exists) return(SMS_SUCCESS);
+
+ /* is member_list a user-group? */
+ /* is it a group? */
+## repeat retrieve (exists = any(g.#list_id where g.#list_id = @member_id))
+ if (exists) {
+ /* get list_name */
+## repeat retrieve (list_name = l.#name) where l.#list_id = @member_id
+ /* is list_name a username? */
+## repeat retrieve (exists = any(users.login
+## where users.login = @list_name))
+ /* yes, return error */
+ if (exists) return(SMS_USER_GROUP);
+ }
+
+ /* list is not a user-group; add list to maillist table */
+## repeat append maillists (#list_id = @member_id, ltid = l.tid)
+## where l.#list_id = @member_id
+
+ return(SMS_SUCCESS);
+##}
+\f
+/**
+ ** followup_add_pobox
+ ** followup_delete_pobox - followup routines for pobox queries
+ **
+ ** Description:
+ ** add_pobox: set pobox creation time
+ ** increment pop usage in serverhosts
+ **
+ ** delete_pobox: decrement pop usage in serverhosts
+ **
+ **/
+
+followup_add_pobox(q, argv)
+ struct query *q;
+ char *argv[];
+{
+ set_pobox_creation(q, argv);
+ set_pop_usage(q, argv, 1);
+ return(SMS_SUCCESS);
+}
+
+followup_delete_pobox(q, argv)
+ struct query *q;
+ char *argv[];
+{
+ set_pop_usage(q, argv, -1);
+ return(SMS_SUCCESS);
+}
+
+set_pobox_creation(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## int users_id;
+## int mach_id;
+## char *type;
+## char *box;
+
+ users_id = *(int *)argv[0];
+ type = argv[1];
+ mach_id = *(int *)argv[2];
+ box = argv[3];
+
+## range of p is pobox
+## repeat replace p (created = "now")
+## where p.#users_id = @users_id and p.#type = @type and
+## p.#mach_id = @mach_id and p.#box = @box
+
+ return (SMS_SUCCESS);
+##}
/**
** set_pop_usage - incr/decr usage count for pop server in serverhosts talbe
**
** Inputs:
** q->name - "add_pobox" or "delete_pobox"
+ ** argv[1] - type
** argv[2] - mach_id
**
** Description:
**
**/
-set_pop_usage(q, argv)
+set_pop_usage(q, argv, count)
struct query *q;
char *argv[];
##{
## int mach_id;
+## int n;
+
+ if (bcmp(argv[1], "POP", 3)) return(SMS_SUCCESS);
mach_id = *(int *)argv[2];
+ n = count;
+
## range of sh is serverhosts
+## repeat replace sh (value1 = sh.value1 + @n)
+## where sh.service = "pop" and sh.#mach_id = @mach_id
- if (!bcmp(q->name, "add_pobox", 10)) {
-## repeat replace sh (value1 = sh.value1 + 1)
-## where sh.service = "pop" and sh.#mach_id = @mach_id
- } else if (!bcmp(q->name, "delete_pobox", 13)) {
+ return(SMS_SUCCESS);
+##}
+
+/**
+ ** delete_user_poboxes - delete all poboxes for a user
+ **
+ ** Inputs:
+ ** argv[0] - users_id
+ **
+ **/
+
+delete_user_poboxes(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## int users_id;
+## int n;
+## int mach_id;
+ register int i;
+ int mach_ids[10];
+
+ users_id = *(int *)argv[0];
+
+ /* get machine ids for pop server(s) on which the user currently exists */
+## range of p is pobox
+ i = 0;
+## repeat retrieve (mach_id = p.#mach_id)
+## where p.#users_id = @users_id and p.type = "POP"
+## {
+ mach_ids[i++] = mach_id;
+ if (i == 10) {
+## endretrieve
+ }
+## }
+
+ /* decrement counts on serverhost entries */
+## range of sh is serverhosts
+ while (--i >= 0) {
+ mach_id = mach_ids[i];
## repeat replace sh (value1 = sh.value1 - 1)
## where sh.service = "pop" and sh.#mach_id = @mach_id
}
+ /* delete user's poboxes */
+## repeat delete p where p.#users_id = @users_id
+
+ return(SMS_SUCCESS);
+##}
+
+\f
+/**
+ ** add_new_quota
+ ** delete_current_quota - adjust nfsphys values on xxx_quota queries.
+ **
+ ** Inputs:
+ ** argv[0] - mach_id
+ ** argv[1] - device
+ ** argv[2] - users_id
+ ** argv[3] - quota (add_new_quota only)
+ **
+ ** Description:
+ ** delete_current_quota:
+ ** - find nfsquota entry
+ ** - decrement nfsphys.allocated by nfsquota.quota
+ ** add_new_quota
+ ** - increment nfsphys.allocated by quota
+ **
+ **/
+
+add_new_quota(q, argv)
+ struct query *q;
+ register char *argv[];
+##{
+## int mach_id;
+## char *device;
+## int quota;
+
+ mach_id = *(int*)argv[0];
+ device = argv[1];
+ quota = *(int *)argv[3];
+
+## range of np is nfsphys
+## repeat replace np (allocated = np.allocated + @quota)
+## where np.#mach_id = @mach_id and np.#device = @device
+
return(SMS_SUCCESS);
##}
+delete_current_quota(q, argv, cl, access_check)
+ struct query *q;
+ register char *argv[];
+ client *cl;
+ int access_check;
+##{
+## int mach_id;
+## int users_id;
+## char *device;
+## int quota;
+
+ if (access_check) return(SMS_SUCCESS);
+
+ mach_id = *(int *)argv[0];
+ device = argv[1];
+ users_id = *(int *)argv[2];
+
+## range of np is nfsphys
+## range of nq is nfsquota
+## repeat retrieve (quota = nq.#quota)
+## where nq.#mach_id = @mach_id and nq.#device = @device and
+## nq.#users_id = @users_id
+## repeat replace np (allocated = np.allocated - @quota)
+## where np.#mach_id = @mach_id and np.#device = @device
+
+ return(SMS_SUCCESS);
+##}
+\f
+/**
+ ** add_hostaccess - create entry in hostaccess table upon adding a new
+ ** machine to the serverhosts table where service =
+ ** "hostaccess".
+ **
+ ** Inputs:
+ ** argv[0] - service
+ ** argv[1] - mach_id
+ **
+ **/
+
+add_hostaccess(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## int mach_id;
+
+ /* only work with service = "hostaccess" */
+ if (bcmp(argv[0], "hostaccess", 10)) return(SMS_SUCCESS);
+
+ mach_id = *(int *)argv[1];
+## repeat append hostaccess (#mach_id = @mach_id, status = 0)
+## repeat replace tblstats (modtime = "now", appends = tblstats.appends + 1)
+## where tblstats.table = "hostaccess"
+ return(SMS_SUCCESS);
+##}
+
+/* followup to delete_server_host_info */
+
+delete_hostaccess(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## int mach_id;
+
+ /* only work with service = "hostaccess" */
+ if (bcmp(argv[0], "hostaccess", 10)) return(SMS_SUCCESS);
+
+ mach_id = *(int *)argv[1];
+## repeat delete hostaccess where hostaccess.#mach_id = @mach_id
+## repeat replace tblstats (modtime = "now", deletes = tblstats.deletes + 1)
+## where tblstats.table = "hostaccess"
+ return(SMS_SUCCESS);
+##}
+
+followup_ushp(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## int mach_id;
+## int status;
+
+ mach_id = *(int *)argv[0];
+## range of ha is hostaccess
+## repeat retrieve (status = ha.#status) where ha.#mach_id = @mach_id
+ status |= 1;
+## repeat replace ha (#status = @status) where ha.#mach_id = @mach_id
+ return(SMS_SUCCESS);
+##}
+
+followup_usha(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## int mach_id;
+## int status;
+
+ mach_id = *(int *)argv[0];
+## range of ha is hostaccess
+## repeat retrieve (status = ha.#status) where ha.#mach_id = @mach_id
+ status |= 2;
+## repeat replace ha (#status = @status) where ha.#mach_id = @mach_id
+ return(SMS_SUCCESS);
+##}
+\f
/**
** delete_list_members - called after the delete_list query to clean up
** members table.
## repeat replace s (#refc = @refc) where s.#string_id = @string_id
}
}
- sq_destroy(sq);
-
-## repeat delete m where m.#list_id = @list_id
+ sq_destroy(sq);
+
+## repeat delete m where m.#list_id = @list_id
+
+ return(SMS_SUCCESS);
+##}
+\f
+/**
+ ** followup_grvd - Support routine for get_rvd_servers query
+ **
+ ** Inputs:
+ ** q - grvd query structure
+ ** sq - save_queue struture: contains list of {machine, oper_acl_id,
+ ** admin_acl_id, shutdown_acl_id} records.
+ ** v - validate structure (not used)
+ ** action - action routine
+ ** actarg - action routine argument
+ **
+ ** Description:
+ ** - translate acl_ids to list names
+ **
+ **/
+
+followup_grvd(q, sq, v, action, actarg)
+ struct query *q;
+ struct save_queue *sq;
+ struct validate *v;
+ int (*action)();
+ int actarg;
+##{
+ char **argv;
+ char *targv[4];
+## char oper[33];
+## char admin[33];
+## char shutdown[33];
+## int list_id;
+
+ targv[0] = oper;
+ targv[1] = admin;
+ targv[2] = shutdown;
+
+## range of l is list
+
+ while (sq_get_data(sq, &argv)) {
+ sscanf(argv[0], "%d", &list_id);
+## repeat retrieve (oper = l.name) where l.#list_id = @list_id
+ sscanf(argv[1], "%d", &list_id);
+## repeat retrieve (admin = l.name) where l.#list_id = @list_id
+ sscanf(argv[2], "%d", &list_id);
+## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
+
+ (*action)(3, targv, actarg);
+ free(argv[0]);
+ free(argv[1]);
+ free(argv[2]);
+ }
+ sq_destroy(sq);
return(SMS_SUCCESS);
##}
-/**
- ** grvd_support - Support routine for get_rvd_servers query
- **
- ** Inputs:
- ** q - grvd query structure
- ** sq - save_queue struture: contains list of {machine, oper_acl_id,
- ** admin_acl_id, shutdown_acl_id} records.
- ** v - validate structure (not used)
- ** action - action routine
- ** actarg - action routine argument
- **
- ** Description:
- ** - translate acl_ids to list names
- **
- **/
-
-grvd_support(q, sq, v, action, actarg)
+followup_gars(q, sq, v, action, actarg)
struct query *q;
struct save_queue *sq;
struct validate *v;
## char shutdown[33];
## int list_id;
- targv[0] = oper;
- targv[1] = admin;
- targv[2] = shutdown;
+ targv[1] = oper;
+ targv[2] = admin;
+ targv[3] = shutdown;
## range of l is list
while (sq_get_data(sq, &argv)) {
- sscanf(argv[0], "%d", &list_id);
-## repeat retrieve (oper = l.name) where l.#list_id = @list_id
sscanf(argv[1], "%d", &list_id);
-## repeat retrieve (admin = l.name) where l.#list_id = @list_id
+## repeat retrieve (oper = l.name) where l.#list_id = @list_id
sscanf(argv[2], "%d", &list_id);
+## repeat retrieve (admin = l.name) where l.#list_id = @list_id
+ sscanf(argv[3], "%d", &list_id);
## repeat retrieve (shutdown = l.name) where l.#list_id = @list_id
- (*action)(3, targv, actarg);
+ targv[0] = argv[0];
+ (*action)(4, targv, actarg);
free(argv[0]);
free(argv[1]);
free(argv[2]);
+ free(argv[3]);
}
sq_destroy(sq);
return(SMS_SUCCESS);
##}
-
+\f
/**
** set_next_object_id - set next object id in values table
**
last_get_time = argv[1];
table = q1->rtable;
- if (q1->type != RETRIEVE || table == (char *)0) return(SMS_NO_MATCH);
+ if (q1->type != RETRIEVE) return(SMS_NO_MATCH);
## range of tbs is tblstats
## repeat retrieve (need = any(tbs.modtime where tbs.#table = @table and
return(SMS_SUCCESS);
##}
+/**
+ ** get_list_is_group
+ ** get_list_is_maillist
+ **
+ ** Inputs:
+ ** argv[0] - list_id
+ **
+ ** Returns:
+ ** {true | false}
+ **
+ **/
+
+get_list_is_group(q, argv, action, actarg)
+ struct query *q;
+ char *argv[];
+ int (*action)();
+ int actarg;
+##{
+## int exists;
+## int list_id;
+ char *result;
+
+ list_id = *(int *)argv[0];
+
+## range of g is groups
+## repeat retrieve (exists = any(g.#list_id where g.#list_id = @list_id))
+
+ result = (exists) ? "true" : "false";
+ (*action)(1, &result, actarg);
+ return(SMS_SUCCESS);
+##}
+
+get_list_is_maillist(q, argv, action, actarg)
+ struct query *q;
+ char *argv[];
+ int (*action)();
+ int actarg;
+##{
+## int exists;
+## int list_id;
+ char *result;
+
+ list_id = *(int *)argv[0];
+
+## range of ml is maillists
+## repeat retrieve (exists = any(ml.#list_id where ml.#list_id = @list_id))
+
+ result = (exists) ? "true" : "false";
+ (*action)(1, &result, actarg);
+ return(SMS_SUCCESS);
+##}
+
\f
/**
** add_locker - special query routine for creating a user locker
printf("np.mach_id = %d and np.device = %s\n", mach_id, device);
## repeat retrieve (dir = np.#dir, allocated = np.#allocated)
-## where np.#mach_id = @mach_id and np.#device = device
+## where np.#mach_id = @mach_id and np.#device = @device
## inquire_equel (rowcount = "rowcount")
if (rowcount == 0) return(SMS_NFSPHYS);
**
** Inputs:
** argv[0] - users_id
- ** argv[1] - machine_id
- ** argv[2] - device
- ** argv[3] - quota
**
** Description:
+ ** - get login name from users_id
+ ** - get filesys entry from login
+ ** - use filesys.mach_id and filesys.name to determine machine/device
+ ** pair for nfsphys and nfsquota
** - delete filesys entry (label=<login>)
** - decrement allocated in nfsphys by quota
** - delete nfsquota entry
##{
## int users_id;
## int mach_id;
-## char *device;
## int quota;
## int rowcount;
## char login[9];
+## char lname[64];
+## char ndev[32];
+ register char *c;
/* copy arguments */
users_id = *(int *)argv[0];
- mach_id = *(int *)argv[1];
- device = argv[2];
- sscanf(argv[3], "%d", "a);
## range of u is users
## range of f is filesys
/* get login name */
## repeat retrieve (login = u.#login) where u.#users_id = @users_id
- /* delete the filesys entry */
-## repeat delete f where f.label = @login
+ /* get mach_id and locker name from filesys entry; then delete it */
+## repeat retrieve (mach_id = f.#mach_id, lname = f.#name)
+## where f.#label = @login
## inquire_equel (rowcount = "rowcount")
if (rowcount == 0) return(SMS_FILESYS);
+## repeat delete f where f.#label = @login
+
+ /* get prefix directory */
+ c = (char *)rindex(lname, '/');
+ *c = 0;
+
+ /* get nfs device */
+## repeat retrieve (ndev = np.device)
+## where np.#mach_id = @mach_id and np.dir = @lname
+
+ /* get quota from nfsquota entry; then delete entry */
+## repeat retrieve (quota = nq.#quota)
+## where nq.#mach_id = @mach_id and nq.#device = @ndev and
+## nq.#users_id = @users_id
+## repeat delete nq where nq.#mach_id = @mach_id and nq.#device = @ndev and
+## nq.#users_id = @users_id
+
+ /* decrement nfsphys.allocated */
+## repeat replace np (allocated = np.allocated - @quota)
+## where np.#mach_id = @mach_id and np.#device = @ndev
+
+ /* adjust table statistics */
## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
## where tbs.table = "filesys"
-
- /* decrement usage count in nfsphys table */
-## replace np (#allocated = np.#allocated - quota)
-## where np.#mach_id = mach_id and np.#device = device
## repeat replace tbs (updates = tbs.updates + 1, modtime = "now")
## where tbs.table = "nfsphys"
-
- /* delete nfsquota entry */
-## delete nq where nq.#users_id = users_id and nq.#mach_id = mach_id and
-## nq.#device = device
## repeat replace tbs (deletes = tbs.deletes + 1, modtime = "now")
## where tbs.table = "nfsquota"
return(SMS_SUCCESS);
##}
\f
+/**
+ ** add_user_group - create a group for a user and add user to group
+ **
+ ** Inputs:
+ ** argv[0] - login
+ **
+ ** Description:
+ ** - verify specified user exists
+ ** - create a list of same name as user
+ ** - add user as a member of the list
+ **
+ **/
+
+add_user_group(q, argv)
+ struct query *q;
+ char *argv[];
+##{
+## char *login;
+## int exists;
+## int users_id;
+## int list_id;
+## int gid;
+
+ login = argv[0];
+
+ /* verify user exists */
+## repeat retrieve (users_id = users.#users_id) where users.#login = @login
+## inquire_equel (exists = "rowcount")
+ if (exists != 1) return(SMS_USER);
+
+ /* verify list does not exist */
+## repeat retrieve (exists = any(list.name where list.name = @login))
+ if (exists) return(SMS_LIST);
+
+ /* get new list_id */
+## repeat retrieve (list_id = values.value) where values.name = "list_id"
+ list_id++;
+## repeat replace values (value = @list_id) where values.name = "list_id"
+
+ /* create the list */
+## range of tbs is tblstats
+## repeat append list (name = @login, #list_id = @list_id, flags = 1,
+## desc = "User Group", acl_id = @list_id,
+## expdate = "today" + "5 years", modtime = "now")
+## repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
+## where tbs.table = "list"
+
+ /* add user to list */
+## repeat append members (#list_id = @list_id, member_type = "USER",
+## member_id = @users_id)
+## repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
+## where tbs.table = "members"
+
+ /* get new gid */
+## range of g is groups
+## range of v is values
+## repeat retrieve (gid = v.value) where v.name = "gid"
+ exists = 1;
+ while (exists) {
+ gid++;
+## repeat retrieve (exists = any(g.#gid where g.#gid = @gid))
+ }
+## repeat replace v (value = @gid) where v.name = "gid"
+
+ /* add list to group table */
+## repeat append groups (#list_id = @list_id, ltid = list.tid, #gid = @gid)
+## where list.#list_id = @list_id
+## repeat replace tbs (modtime = "now", appends = tbs.appends + 1)
+## where tbs.table = "members"
+
+ /* and we're done */
+ return(SMS_SUCCESS);
+##}
+
+\f
+/**
+ ** get_members_of_list - optimized query for retrieval of list members
+ **
+ ** Inputs:
+ ** argv[0] - list_id
+ **
+ ** Description:
+ ** - retrieve USER members, then LIST members, then STRING members
+ **
+ **/
+
+get_members_of_list(q, argv, action, actarg)
+ struct query *q;
+ char *argv[];
+ int (*action)();
+ int actarg;
+##{
+## int list_id;
+## char member_name[129];
+ char *targv[2];
+
+ list_id = *(int *)argv[0];
+ targv[0] = "USER";
+ targv[1] = member_name;
+
+## range of m is members
+## repeat retrieve (member_name = users.login)
+## where m.#list_id = @list_id and m.member_type = "USER"
+## and m.member_id = users.users_id
+## sort by #member_name
+## {
+ (*action)(2, targv, actarg);
+## }
+
+ targv[0] = "LIST";
+## repeat retrieve (member_name = list.name)
+## where m.#list_id = @list_id and m.member_type = "LIST"
+## and m.member_id = list.#list_id
+## sort by #member_name
+## {
+ (*action)(2, targv, actarg);
+## }
+
+ targv[0] = "STRING";
+## repeat retrieve (member_name = strings.string)
+## where m.#list_id = @list_id and m.member_type = "STRING"
+## and m.member_id = strings.string_id
+## sort by #member_name
+## {
+ (*action)(2, targv, actarg);
+## }
+
+ return(SMS_SUCCESS);
+##}
+
+/**
+ ** get_groups_of_user - optimized query for retrieval of all groups to
+ ** which a user belongs
+ **
+ **/
+
+get_groups_of_user(q, argv, action, actarg)
+ struct query *q;
+ char *argv[];
+ int (*action)();
+ int actarg;
+##{
+## int users_id;
+## char list_name[33];
+## char gid[11];
+## int rowcount;
+ char *targv[2];
+
+ users_id = *(int *)argv[0];
+ targv[0] = list_name;
+ targv[1] = gid;
+
+## range of m is members
+
+## repeat retrieve (list_name = list.name, gid = text(groups.#gid))
+## where m.member_id = @users_id and m.member_type = "USER" and
+## m.list_id = groups.list_id and groups.ltid = list.tid
+## sort by #list_name
+## {
+ (*action)(2, targv, actarg);
+## }
+## inquire_equel (rowcount = "rowcount")
+
+ return ((rowcount = 0) ? SMS_NO_MATCH : SMS_SUCCESS);
+##}
+
+get_groups_of_all_users(q, argv, action, actarg)
+ struct query *q;
+ char *argv[];
+ int (*action)();
+ int actarg;
+##{
+## char login[9];
+## char group[33];
+## char gid[11];
+ char *targv[3];
+## int errorno;
+
+ targv[0] = login;
+ targv[1] = group;
+ targv[2] = gid;
+
+## range of u is users
+## range of l is list
+## range of m is members
+## range of g is groups
+
+## set lockmode session where readlock = nolock
+
+## repeat retrieve (login = u.#login, group = l.name, gid = text(g.#gid))
+## where m.member_type = "USER" and m.member_id = u.users_id and
+## u.status != 0 and m.list_id = g.list_id and
+## g.ltid = l.tid
+## sort by #login, #group
+## {
+ (*action)(3, targv, actarg);
+## }
+
+## inquire_equel (errorno = "errorno")
+## set lockmode session where readlock = system
+
+ return((errorno) ? SMS_INGRES_ERR : SMS_SUCCESS);
+##}
+\f
+/**
+ ** get_all_poboxes - optimized query for retrieval of all poboxes
+ **
+ ** Description:
+ ** - retrieve LOCAL boxes, then POP boxes, then FOREIGN boxes
+ **
+ **/
+
+get_all_poboxes(q, argv, action, actarg)
+ struct query *q;
+ char *argv[];
+ int (*action)();
+ int actarg;
+##{
+## char login[9];
+## char machine[129];
+## char box[129];
+ char *targv[4];
+
+ targv[0] = login;
+ targv[2] = machine;
+ targv[3] = box;
+
+ targv[1] = "LOCAL";
+
+## set lockmode session where readlock = nolock
+## range of p is pobox
+## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
+## where p.type = "LOCAL" and p.users_id = users.users_id
+## and p.mach_id = #machine.mach_id
+## {
+ (*action)(4, targv, actarg);
+## }
+
+ targv[1] = "POP";
+## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
+## where p.type = "POP" and p.users_id = users.users_id
+## and p.mach_id = #machine.mach_id
+## {
+ (*action)(4, targv, actarg);
+## }
+
+ targv[1] = "FOREIGN";
+## repeat retrieve (login=users.#login, machine=strings.string, box=p.#box)
+## where p.type = "FOREIGN" and p.users_id = users.users_id
+## and p.mach_id = strings.string_id
+## {
+ (*action)(4, targv, actarg);
+## }
+## set lockmode session where readlock = system
+
+ return(SMS_SUCCESS);
+##}
+
+get_new_poboxes(q, argv, action, actarg)
+ struct query *q;
+ char *argv[];
+ int (*action)();
+ int actarg;
+##{
+## char *created;
+## char login[9];
+## char machine[129];
+## char box[129];
+ char *targv[4];
+
+ created = argv[0];
+
+ targv[0] = login;
+ targv[2] = machine;
+ targv[3] = box;
+
+ targv[1] = "LOCAL";
+## range of p is pobox
+## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
+## where p.type = "LOCAL" and p.users_id = users.users_id
+## and p.mach_id = #machine.mach_id and
+## p.#created > @created
+## {
+ (*action)(4, targv, actarg);
+## }
+
+ targv[1] = "POP";
+## repeat retrieve (login=users.#login, machine = #machine.name, box=p.#box)
+## where p.type = "POP" and p.users_id = users.users_id
+## and p.mach_id = #machine.mach_id and
+## p.#created > @created
+## {
+ (*action)(4, targv, actarg);
+## }
+
+ targv[1] = "FOREIGN";
+## repeat retrieve (login=users.#login, machine=strings.string, box=p.#box)
+## where p.type = "FOREIGN" and p.users_id = users.users_id
+## and p.mach_id = strings.string_id and
+## p.#created > @created
+## {
+ (*action)(4, targv, actarg);
+## }
+
+ return(SMS_SUCCESS);
+##}
+\f
/* Validation Routines */
validate_row(q, argv, v)
table = q->rtable;
name = v->field;
- /* tell the logfile what we're doing */
- com_err(whoami, 0, "validating row");
- com_err(whoami, 0, qual);
-
+ if (log_flags & LOG_RES)
+ /* tell the logfile what we're doing */
+ com_err(whoami, 0, "validating row: %s", qual);
+
/* look for the record */
## range of rvar is table
## retrieve (rowcount = count(rvar.name where qual))
- com_err(whoami, 0, "row validated");
if (rowcount == 0) return(SMS_NO_MATCH);
if (rowcount > 1) return(SMS_NOT_UNIQUE);
return(SMS_EXISTS);
register int n;
{
register int status;
- char buf[64];
while (--n >= 0) {
switch (vo->type) {
case V_NAME:
- sprintf(buf, "validating %s in %s: %s",
+ if (log_flags & LOG_RES)
+ com_err(whoami, 0, "validating %s in %s: %s",
vo->namefield, vo->table, argv[vo->index]);
- com_err(whoami, 0, buf);
status = validate_name(argv, vo);
break;
case V_ID:
- sprintf(buf, "validating %s in %s: %s",
+ if (log_flags & LOG_RES)
+ com_err(whoami, 0, "validating %s in %s: %s",
vo->idfield, vo->table, argv[vo->index]);
- com_err(whoami, 0, buf);
status = validate_id(argv, vo);
break;
+ case V_DATE:
+ if (log_flags & LOG_RES)
+ com_err(whoami, 0, "validating date: %s", argv[vo->index]);
+ status = validate_date(argv, vo);
+ break;
+
case V_TYPE:
- sprintf(buf, "validating %s type: %s",
+ if (log_flags & LOG_RES)
+ com_err(whoami, 0, "validating %s type: %s",
vo->table, argv[vo->index]);
- com_err(whoami, 0, buf);
status = validate_type(argv, vo);
break;
case V_TYPEDATA:
- sprintf(buf, "validating type-specific data: %s",
- argv[vo->index]);
- com_err(whoami, 0, buf);
+ if (log_flags & LOG_RES)
+ com_err(whoami, 0, "validating typed data (%s): %s",
+ argv[vo->index - 1], argv[vo->index]);
status = validate_typedata(q, argv, vo);
break;
status = SMS_EXISTS;
break;
+ case V_SORT:
+ status = SMS_EXISTS;
+ break;
+
}
if (status != SMS_EXISTS) return(status);
return ((rowcount == 1) ? SMS_EXISTS : vo->error);
##}
+validate_date(argv, vo)
+ char *argv[];
+ struct valobj *vo;
+##{
+## char *idate;
+## double dd;
+## int errorno;
+
+ idate = argv[vo->index];
+
+## retrieve (dd = interval("years", date(idate) - date("today")))
+## inquire_equel (errorno = "errorno")
+ if (errorno != 0 || dd > 5.0) return(SMS_DATE);
+ return(SMS_SUCCESS);
+##}
+
validate_type(argv, vo)
char *argv[];
register struct valobj *vo;
## int id;
## int refc;
## int rowcount;
+ register char *c;
/* get named object */
name = argv[vo->index];
} else if (!strcmp(data_type, "machine")) {
/* MACHINE */
+ for (c = name; *c; c++) if (islower(*c)) *c = toupper(*c);
## repeat retrieve (id = machine.mach_id) where machine.#name = @name
## inquire_equel (rowcount = "rowcount")
if (rowcount != 1) return(SMS_MACHINE);