-/* $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
- * <mit-copyright.h>.
+ * Copyright (C) 1988-1998 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 <stdlib.h>
-#include <string.h>
#include <moira.h>
#include <moira_site.h>
-#include <sys/types.h>
+
#include <sys/stat.h>
-#include <sys/time.h>
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#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)
{
if (argc == 2)
{
sprintf(cmd, "cd %s; cp %s/nfs/* .; tar cf %s .",
- nfs_dir, SMS_DIR, argv[1]);
+ nfs_dir, MOIRA_DIR, argv[1]);
if (system(cmd))
exit(MR_TAR_FAIL);
}
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;
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;
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.
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);
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)
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;
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;
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);
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;
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)
{
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)
{
}
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);
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)
{
db_error(sqlca.sqlcode);
exit(MR_DBMS_ERR);
}
+