/* $Header$
*
* This generates the files necessary to load an nfs server.
+ *
+ * (c) Copyright 1988 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
*/
+#include <mit-copyright.h>
#include <stdio.h>
#include <sms.h>
#include <sms_app.h>
#define min(x,y) ((x) < (y) ? (x) : (y))
-struct np {
- char mach[33];
- char dev[33];
- char list[33];
-};
-
-struct fs {
- int nfsphys;
- char *dir;
- int owner;
- int owners;
- struct qt *quota;
-};
-
-
+char *whoami = "nfs.gen";
char *malloc(), *strsave();
char *ingres_date_and_time(), *ingres_time(), *ingres_date();
char cmd[64];
struct stat sb;
int changed = 0;
+ int ingerr();
if (argc > 2) {
fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
exit(SMS_ARGS);
}
+ IIseterr(ingerr);
## ingres sms
-## set lockmode session where readlock = nolock
changed = do_nfs();
}
if (argc == 2) {
- sprintf(cmd, "cd %s; tar cf %s .", NFS_DIR, argv[1]);
+ sprintf(cmd, "cd %s; cp /u1/sms/bin/install_* .; tar cf %s .", NFS_DIR, argv[1]);
if (system(cmd))
exit(SMS_TAR_FAIL);
}
}
+/*
+ * ingerr: (supposedly) called when Ingres indicates an error.
+ * I have not yet been able to get this to work to intercept a
+ * database open error.
+ */
+#define INGRES_DEADLOCK 4700
+
+static int ingerr(num)
+ int *num;
+{
+ char buf[256];
+ int ingres_errno;
+
+ switch (*num) {
+ case INGRES_DEADLOCK:
+ ingres_errno = SMS_DEADLOCK;
+ break;
+ default:
+ ingres_errno = SMS_INGRES_ERR;
+ }
+ com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num);
+ critical_alert("DCM", "NFS build encountered INGRES ERROR %d", *num);
+ exit(ingres_errno);
+}
+
+
/* Generate the files. Returns zero if nothing changed, non-zero otherwise. */
int do_nfs()
int do_lists(lists)
struct save_queue *lists;
##{
- struct save_queue *sq;
+ struct save_queue *sq, *members;
char file[64], *u;
struct hash *users, *do_everyone();
struct stat sb;
}
sq = sq_create();
sq_save_data(sq, listname);
+ members = sq_create();
while (sq_get_data(sq, &lsname)) {
## repeat retrieve (lname = trim(l.name))
## where m.list_id = l1.list_id and l1.name = @lsname and
## m.member_type = "LIST" and m.member_id = l.list_id {
- sq_save_unique_string(sq, lname);
+ sq_save_unique_string(sq, strsave(lname));
## }
## repeat retrieve (id = m.member_id)
## where m.list_id = l1.list_id and l1.name = @lsname and
## m.member_type = "USER" {
- if (u = hash_lookup(users, id))
- fprintf(fd, "%s\n", u);
+ if (u = hash_lookup(users, id)) {
+ sq_save_unique_data(members, u);
+ }
## }
}
+ while (sq_get_data(members, &lsname))
+ fprintf(fd, "%s\n", lsname);
+ sq_destroy(members);
sq_destroy(sq);
if (fclose(fd)) {
fprintf(stderr, "error closing %s\n", file);
};
struct user {
char name[9];
+ int uid;
struct grp *lists;
};
## char name[33];
## int gid, id, lid, maxid, uid;
FILE *fd;
- int first;
+ int i;
struct save_queue *sq;
fprintf(stderr, "Building the list of everybody\n");
sq = sq_create();
## range of m is members
## retrieve (gid = list.#gid, lid = l.list_id)
-## where l.group = 0 and l.active != 0 and m.member_type = "LIST" and
+## where l.active != 0 and list.active != 0 and m.member_type = "LIST" and
## m.member_id = l.list_id and m.list_id = list.list_id and
## list.group != 0 {
if (l = hash_lookup(groups, lid)) {
## }
while (sq_get_data(sq, &id)) {
-## repeat retrieve (lid = l.list_id, gid = l.#gid)
-## where l.group = 0 and l.active != 0 and m.member_type = "LIST" and
-## m.member_id = l.list_id and m.list_id = @id {
+## repeat retrieve (lid = l.list_id) where l.active != 0 and
+## m.member_type = "LIST" and m.member_id = l.list_id and
+## m.list_id = @id {
if (l = hash_lookup(groups, lid)) {
sprintf(buf, "%s%s", l, hash_lookup(groups, id));
free(l);
+ l = strsave(buf);
} else {
- strcpy(buf, hash_lookup(groups, id));
+ l = hash_lookup(groups, id);
}
+ hash_store(groups, lid, l);
sq_save_unique_data(sq, lid);
## }
}
/* now do grplists */
users = create_hash(10000);
## range of u is users
-## retrieve (id = u.users_id, name = u.login) where u.status = 1 {
+## retrieve (id = u.users_id, name = u.login, uid = u.#uid)
+## where u.status = 1 {
u = (struct user *) malloc(sizeof(struct user));
strcpy(u->name, strtrim(name));
+ u->uid = uid;
u->lists = NULL;
hash_store(users, id, u);
## }
## repeat retrieve (lid = m.list_id, id = m.member_id)
## where m.member_type = "USER" {
- if (u = (struct user *) hash_lookup(users, id)) {
+ if ((u = (struct user *) hash_lookup(users, id)) &&
+ (hash_lookup(groups, lid) != NULL)) {
g = (struct grp *) malloc(sizeof(struct grp));
g->next = u->lists;
u->lists = g;
for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
for (b = *p; b; b = b->next) {
- strcpy(buf, ((struct user *)b->data)->name);
- for (g = ((struct user *)b->data)->lists; g; g = g->next)
- if (l = hash_lookup(groups, g->id))
- strcat(buf, l);
+ i = 0;
+ u = (struct user *)b->data;
+ sprintf(buf, "%s:%d", u->name, u->uid);
+ for (g = u->lists; g; g = g->next)
+ if (l = hash_lookup(groups, g->id)) {
+ i++;
+ strcat(buf, l);
+ }
/* should free stuff here... */
+ if (i > 1) {
+ remove_duplicate_groups(buf);
+ }
b->data = strsave(buf);
fprintf(fd, "%s\n", buf);
}
return(users);
##}
+#define MAXGROUPS 256
+
+remove_duplicate_groups(p)
+register char *p;
+{
+ register char *pp;
+ char *index();
+ register int *mp;
+ int memory[MAXGROUPS], i, *mg = &memory[MAXGROUPS-1];
+
+ bzero(memory, MAXGROUPS * sizeof(int));
+ p = index(p, ':');
+ p++;
+ while (p = index(p, ':')) {
+ i = atoi(++p);
+ pp = p;
+ for (mp = memory; *mp && mp < mg; mp++)
+ if (*mp == i) {
+ if (p = index(p, ':'))
+ strcpy(pp, ++p);
+ else {
+ *(--pp) = 0;
+ }
+ p = pp - 2;
+ break;
+ }
+ *mp = i;
+ }
+}
+
/* Now do each of the servers, linking the credentials list file and
* compiling the quota and dirs files.