X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/59ec8daed689fed26f4fc6cbd94d5e4d1961c407..0041862dcee4646f8bc7fea981e1fb7007cc066f:/gen/nfs.pc diff --git a/gen/nfs.pc b/gen/nfs.pc index b76cdb83..877a2622 100644 --- a/gen/nfs.pc +++ b/gen/nfs.pc @@ -1,32 +1,41 @@ -/* $Header$ +/* $Id$ * * This generates the files necessary to load an nfs server. * - * (c) Copyright 1988, 1990 by the Massachusetts Institute of Technology. - * For copying and distribution information, please see the file - * . + * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology. + * For copying and distribution information, please see the file + * . */ #include -#include -#include -#include #include #include -#include + #include -#include +#include + +#include +#include +#include +#include + +#include "util.h" + EXEC SQL INCLUDE sqlca; +RCSID("$Header$"); #define min(x, y) ((x) < (y) ? (x) : (y)) char *whoami = "nfs.gen"; char *db = "moira/moira"; -char *strsave(); -char nfs_dir[64]; +char nfs_dir[MAXPATHLEN]; struct hash *users, *groups; +int do_nfs(void); +int do_lists(struct save_queue *lists); +void do_everyone(void); +int do_machs(struct save_queue *machs); int main(int argc, char **argv) { @@ -73,7 +82,7 @@ int main(int argc, char **argv) int do_nfs(void) { EXEC SQL BEGIN DECLARE SECTION; - char machname[41], listname[33]; + char machname[MACHINE_NAME_SIZE], listname[SERVERHOSTS_VALUE3_SIZE]; EXEC SQL END DECLARE SECTION; struct save_queue *machs, *lists; int changed; @@ -97,8 +106,8 @@ int do_nfs(void) EXEC SQL FETCH s_cursor INTO :machname, :listname; if (sqlca.sqlcode) break; - sq_save_unique_string(machs, strsave(strtrim(machname))); - sq_save_unique_string(lists, strsave(strtrim(listname))); + sq_save_unique_string(machs, strdup(strtrim(machname))); + sq_save_unique_string(lists, strdup(strtrim(listname))); } EXEC SQL CLOSE s_cursor; @@ -118,30 +127,14 @@ sqlerr: int do_lists(struct save_queue *lists) { - char file[64], *u; - struct stat sb; + char file[MAXPATHLEN], *u; FILE *fd; EXEC SQL BEGIN DECLARE SECTION; - char *listname, *lsname, lname[33], uname[9]; - int uid, id, flag1, flag2, flag3, flag4; + char *listname; + int id; EXEC SQL END DECLARE SECTION; sprintf(file, "%s/list-", nfs_dir); -#if 0 - if (stat(file, &sb) == 0) - { - if ((ModDiff (&flag1, "users", sb.st_mtime)) || - (ModDiff (&flag2, "list", sb.st_mtime)) || - (ModDiff (&flag3, "imembers", sb.st_mtime)) || - (ModDiff (&flag4, "serverhosts", sb.st_mtime))) - exit(MR_DATE); - if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) - { - fprintf(stderr, "The lists do not need to be rebuilt.\n"); - return 0; - } - } -#endif /* build the list of everyone, and store it in a file whose name * corresponds to the empty list. @@ -200,26 +193,26 @@ struct grp { struct grp *next; char *lid; }; + struct user { - char name[9]; + char name[USERS_LOGIN_SIZE]; int uid; struct grp *lists; }; -do_everyone(void) +void do_everyone(void) { - char buf[BUFSIZ], *l; + const buflen = MAXPATHLEN; + char buf[MAXPATHLEN], *l; struct user *u; struct grp *g; struct bucket *b, **p; EXEC SQL BEGIN DECLARE SECTION; - char name[33]; - int gid, id, lid, maxid, uid; + char name[USERS_LOGIN_SIZE]; + int gid, id, lid, uid; EXEC SQL END DECLARE SECTION; FILE *fd; - int i; - struct save_queue *sq; fprintf(stderr, "Building the list of everybody\n"); sprintf(buf, "%s/list-", nfs_dir); @@ -237,7 +230,7 @@ do_everyone(void) EXEC SQL DECLARE l_cursor CURSOR FOR SELECT gid, list_id FROM list - WHERE grouplist != 0 AND active != 0 + WHERE nfsgroup != 0 AND grouplist != 0 AND active != 0 ORDER BY list_id; EXEC SQL OPEN l_cursor; while (1) @@ -246,7 +239,7 @@ do_everyone(void) if (sqlca.sqlcode) break; sprintf(buf, ":%d", gid); - hash_store(groups, lid, strsave(buf)); + hash_store(groups, lid, strdup(buf)); } EXEC SQL CLOSE l_cursor; @@ -282,8 +275,7 @@ do_everyone(void) EXEC SQL FETCH m_cursor2 INTO :lid, :id; if (sqlca.sqlcode) break; - if ((u = (struct user *) hash_lookup(users, id)) && - (l = hash_lookup(groups, lid))) + if ((u = hash_lookup(users, id)) && (l = hash_lookup(groups, lid))) { g = malloc(sizeof(struct grp)); g->next = u->lists; @@ -298,16 +290,26 @@ do_everyone(void) for (b = *p; b; b = b->next) { u = (struct user *)b->data; - sprintf(buf, "%s:%d", u->name, u->uid); + sprintf(buf, "%s:%d:101", u->name, u->uid); for (g = u->lists; g; g = g->next) - strcat(buf, g->lid); - b->data = strsave(buf); + { + if ((strlen(buf) + strlen(g->lid)) <= buflen) + strcat(buf, g->lid); + else + { + com_err(whoami, 0, "truncated server-side grp list for %s", + u->name); + break; + } + } + b->data = strdup(buf); fprintf(fd, "%s\n", buf); } } fclose(fd); - return 1; + return; + sqlerr: db_error(sqlca.sqlcode); exit(MR_DBMS_ERR); @@ -321,10 +323,12 @@ sqlerr: int do_machs(struct save_queue *machs) { EXEC SQL BEGIN DECLARE SECTION; - char *machname, listname[33], dev[33], dir[81], fstype[9]; - int uid, quota, id, gid, flag1, flag2, flag3, flag4; + char *machname, listname[SERVERHOSTS_VALUE3_SIZE]; + char dev[NFSPHYS_DEVICE_SIZE], dir[FILESYS_NAME_SIZE]; + char fstype[FILESYS_LOCKERTYPE_SIZE]; + int uid, quota, id, gid, flag1, flag2, flag3; EXEC SQL END DECLARE SECTION; - char file[64], f1[64], f2[64], *cp; + char file[MAXPATHLEN], f1[MAXPATHLEN], f2[MAXPATHLEN], *cp; int prevuid, quotasum, olddev, oldmach; FILE *fd; struct hash *machines; @@ -376,10 +380,10 @@ int do_machs(struct save_queue *machs) fclose(fd); olddev = flag1; oldmach = flag2; - while (cp = strchr(dev, '/')) + while ((cp = strchr(dev, '/'))) *cp = '@'; sprintf(file, "%s/%s.%s.quotas", nfs_dir, - hash_lookup(machines, flag2), strtrim(dev)); + (char *)hash_lookup(machines, flag2), strtrim(dev)); fd = fopen(file, "w"); if (!fd) { @@ -440,10 +444,10 @@ int do_machs(struct save_queue *machs) fclose(fd); olddev = flag1; oldmach = flag2; - while (cp = strchr(dev, '/')) + while ((cp = strchr(dev, '/'))) *cp = '@'; sprintf(file, "%s/%s.%s.quotas", nfs_dir, - hash_lookup(machines, flag2), strtrim(dev)); + (char *)hash_lookup(machines, flag2), strtrim(dev)); fd = fopen(file, "w"); if (!fd) { @@ -455,7 +459,7 @@ int do_machs(struct save_queue *machs) } if (gid != prevuid) { - if (cp = hash_lookup(groups, prevuid)) + if ((cp = hash_lookup(groups, prevuid))) prevuid = atoi(cp + 1); if (quotasum) fprintf(fd, "%d %d\n", prevuid, quotasum); @@ -501,10 +505,10 @@ int do_machs(struct save_queue *machs) fclose(fd); olddev = flag1; oldmach = flag2; - while (cp = strchr(dev, '/')) + while ((cp = strchr(dev, '/'))) *cp = '@'; sprintf(file, "%s/%s.%s.dirs", nfs_dir, - hash_lookup(machines, flag2), strtrim(dev)); + (char *)hash_lookup(machines, flag2), strtrim(dev)); fd = fopen(file, "w"); if (!fd) { @@ -525,3 +529,4 @@ sqlerr: db_error(sqlca.sqlcode); exit(MR_DBMS_ERR); } +