#include <moira.h>
#include <moira_site.h>
#include <menu.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ctype.h>
#include "mit-copyright.h"
#include "defs.h"
#define DEFAULT_OWNERS (user)
#define DEFAULT_CREATE DEFAULT_YES
#define DEFAULT_L_TYPE ("PROJECT")
+#define DEFAULT_CELL ("athena.mit.edu")
/* Function Name: SetDefaults
* Description: sets the default values for filesystem additions.
case LABEL:
if ( (stat = do_mr_query("get_filesys_by_label", 1, &name,
StoreInfo, (char *)&elem)) != 0) {
- com_err(program_name, stat, NULL);
+ com_err(program_name, stat, " in GetFSInfo");
return(NULL);
}
break;
case MACHINE:
if ( (stat = do_mr_query("get_filesys_by_machine", 1, &name,
StoreInfo, (char *)&elem)) != 0) {
- com_err(program_name, stat, NULL);
+ com_err(program_name, stat, " in GetFSInfo");
return(NULL);
}
break;
case GROUP:
if ( (stat = do_mr_query("get_filesys_by_group", 1, &name,
StoreInfo, (char *)&elem)) != 0) {
- com_err(program_name, stat, NULL);
+ com_err(program_name, stat, " in GetFSInfo");
return(NULL);
}
break;
FORMFEED;
- if (!strcmp(info[FS_TYPE], "FSGROUP")) {
+ if (!strcmp(info[FS_TYPE], "FSGROUP") || !strcmp(info[FS_TYPE], "MUL")) {
int stat;
struct qelem *elem = NULL;
- sprintf(print_buf,"%20s Filesystem Group: %s", " ", info[FS_NAME]);
+ if (!strcmp(info[FS_TYPE], "MUL"))
+ sprintf(print_buf,"%20s Multiple Filesystem: %s", " ", info[FS_NAME]);
+ else
+ sprintf(print_buf,"%20s Filesystem Group: %s", " ", info[FS_NAME]);
Put_message(print_buf);
- sprintf(print_buf,"Comments; %s",info[FS_COMMENTS]);
+ sprintf(print_buf,"Comments: %s",info[FS_COMMENTS]);
Put_message(print_buf);
sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
info[FS_MODWITH]);
if (stat == MR_NO_MATCH)
Put_message(" [no members]");
else
- com_err(program_name, stat, NULL);
+ com_err(program_name, stat, " in PrintFSInfo");
} else {
fsgCount = 1;
Loop(QueueTop(elem), (void *) PrintFSGMembers);
sprintf(print_buf,"Default Access: %-2s Packname: %-17s Mountpoint %s ",
info[FS_ACCESS], info[FS_PACK], info[FS_M_POINT]);
Put_message(print_buf);
- sprintf(print_buf,"Comments; %s",info[FS_COMMENTS]);
+ sprintf(print_buf,"Comments: %s",info[FS_COMMENTS]);
Put_message(print_buf);
sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
info[FS_OWNER], info[FS_OWNERS]);
return(info[FS_NAME]);
}
+
+char *canonicalize_cell(c)
+char *c;
+{
+ struct stat stbuf;
+ char path[512];
+ int count;
+
+ sprintf(path, "/afs/%s", c);
+ if (lstat(path, &stbuf) || !stbuf.st_mode&S_IFLNK)
+ return(c);
+ count = readlink(path, path, sizeof(path));
+ if (count < 1) return(c);
+ path[count] = 0;
+ free(c);
+ return(strsave(path));
+}
+
+
+int GetAliasValue(argc, argv, retval)
+int argc;
+char **argv;
+char **retval;
+{
+ *retval = strsave(argv[2]);
+ return(MR_CONT);
+}
+
/* Function Name: AskFSInfo.
* Description: This function askes the user for information about a
* machine and saves it into a structure.
char ** info;
Bool name;
{
- char temp_buf[BUFSIZ], *newname;
- int fsgroup = 0;
+ char temp_buf[BUFSIZ], *newname, access_type[32];
+ int fsgroup = 0, newdefaults = 0;
Put_message("");
sprintf(temp_buf, "Changing Attributes of filesystem %s.",
if (name) {
newname = Strsave(info[FS_NAME]);
- GetValueFromUser("The new name for this filesystem",
- &newname);
+ if (GetValueFromUser("The new name for this filesystem",
+ &newname) == SUB_ERROR)
+ return(NULL);
}
- GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]);
- if (!strcasecmp(info[FS_TYPE], "FSGROUP"))
+ strcpy(temp_buf, info[FS_TYPE]);
+ if (GetTypeFromUser("Filesystem's Type", "filesys", &info[FS_TYPE]) ==
+ SUB_ERROR)
+ return(NULL);
+ if (!strcasecmp(info[FS_TYPE], "FSGROUP") ||
+ !strcasecmp(info[FS_TYPE], "MUL"))
fsgroup++;
- if (fsgroup || !strcasecmp(info[FS_TYPE], "AFS")) {
+ if (strcasecmp(info[FS_TYPE], temp_buf))
+ newdefaults++;
+ if (fsgroup) {
free(info[FS_MACHINE]);
info[FS_MACHINE] = Strsave(NO_MACHINE);
} else {
free(info[FS_MACHINE]);
info[FS_MACHINE] = Strsave(NO_MACHINE);
}
- GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]);
- info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]);
+ if (!strcasecmp(info[FS_TYPE], "AFS")) {
+ if (!name || newdefaults) {
+ free(info[FS_MACHINE]);
+ info[FS_MACHINE] = strsave(DEFAULT_CELL);
+ }
+ if (GetValueFromUser("Filesystem's Cell", &info[FS_MACHINE]) ==
+ SUB_ERROR)
+ return(NULL);
+ info[FS_MACHINE] = canonicalize_cell(info[FS_MACHINE]);
+ } else {
+ if (GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]) ==
+ SUB_ERROR)
+ return(NULL);
+ info[FS_MACHINE] = canonicalize_hostname(info[FS_MACHINE]);
+ }
}
if (!fsgroup) {
- GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]);
- GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]);
- GetValueFromUser("Filesystem's Default Access", &info[FS_ACCESS]);
+ if (!strcasecmp(info[FS_TYPE], "AFS")) {
+ char *path, *args[3], *p;
+ int status, depth, i;
+ if (GetTypeFromUser("Filesystem's lockertype", "lockertype",
+ &info[FS_L_TYPE]) == SUB_ERROR)
+ return(NULL);
+ if (!name || newdefaults) {
+ free(info[FS_PACK]);
+ lowercase(info[FS_MACHINE]);
+ sprintf(temp_buf, "%s:%s", info[FS_MACHINE], info[FS_L_TYPE]);
+ args[0] = temp_buf;
+ args[1] = "AFSPATH";
+ args[2] = "*";
+ path = "???";
+ status = do_mr_query("get_alias", 3, args,
+ GetAliasValue, &path);
+ if (status == MR_SUCCESS) {
+ p = index(path, ':');
+ if (p) {
+ *p = 0;
+ depth = atoi(++p);
+ } else
+ depth = 0;
+ sprintf(temp_buf, "/afs/%s/%s", info[FS_MACHINE], path);
+ if (depth >= 0) {
+ for (p=info[FS_NAME]; *p&&(p-info[FS_NAME])<depth; p++) {
+ if (islower(*p)) {
+ strcat(temp_buf, "/x");
+ temp_buf[strlen(temp_buf)-1] = *p;
+ } else {
+ sprintf(temp_buf, "/afs/%s/%s/other", info[FS_MACHINE], path);
+ break;
+ }
+ }
+ } else if (depth = -1) {
+ if (isdigit(info[FS_NAME][0])) {
+ strcat(temp_buf, "/");
+ depth = strlen(temp_buf);
+ for (p = info[FS_NAME]; *p && isdigit(*p); p++) {
+ temp_buf[depth++] = *p;
+ temp_buf[depth] = 0;
+ }
+ } else
+ strcat(temp_buf, "/other");
+ } else {
+ /* no default */
+ }
+ strcat(temp_buf, "/");
+ strcat(temp_buf, info[FS_NAME]);
+ free(path);
+ } else {
+ sprintf(temp_buf, "/afs/%s/%s/%s", info[FS_MACHINE],
+ lowercase(info[FS_L_TYPE]), info[FS_NAME]);
+ }
+ info[FS_PACK] = strsave(temp_buf);
+ }
+ }
+ if (GetValueFromUser("Filesystem's Pack Name", &info[FS_PACK]) ==
+ SUB_ERROR)
+ return(NULL);
+ if (GetValueFromUser("Filesystem's Mount Point", &info[FS_M_POINT]) ==
+ SUB_ERROR)
+ return(NULL);
+ sprintf(access_type, "fs_access_%s", info[FS_TYPE]);
+ if (GetTypeFromUser("Filesystem's Default Access", access_type,
+ &info[FS_ACCESS]) == SUB_ERROR)
+ return(NULL);
}
- GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]);
- GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]);
- GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]);
+ if (GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS])
+ == SUB_ERROR)
+ return(NULL);
+ if (GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]) ==
+ SUB_ERROR)
+ return(NULL);
+ if (GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]) ==
+ SUB_ERROR)
+ return(NULL);
if (!fsgroup)
- GetYesNoValueFromUser("Automatically create this filesystem",
- &info[FS_CREATE]);
- GetTypeFromUser("Filesystem's lockertype", "lockertype", &info[FS_L_TYPE]);
+ if (GetYesNoValueFromUser("Automatically create this filesystem",
+ &info[FS_CREATE]) == SUB_ERROR)
+ return(NULL);
+ if (strcasecmp(info[FS_TYPE], "AFS")) {
+ if (GetTypeFromUser("Filesystem's lockertype", "lockertype",
+ &info[FS_L_TYPE]) == SUB_ERROR)
+ return(NULL);
+ }
FreeAndClear(&info[FS_MODTIME], TRUE);
FreeAndClear(&info[FS_MODBY], TRUE);
return(info);
}
+
/* --------------- Filesystem Menu ------------- */
/* Function Name: GetFS
return (DM_NORMAL);
}
+/* Function Name: GetFSM
+ * Description: Get Filesystem information by machine.
+ * Arguments: argc, argv - name of server in argv[1].
+ * Returns: DM_NORMAL.
+ */
+
+/* ARGSUSED */
+int
+GetFSM(argc, argv)
+int argc;
+char **argv;
+{
+ struct qelem *top;
+
+ argv[1] = canonicalize_hostname(strsave(argv[1]));
+ top = GetFSInfo(MACHINE, argv[1]); /* get info. */
+ Loop(top, (void *) PrintFSInfo);
+ FreeQueue(top); /* clean the queue. */
+ return (DM_NORMAL);
+}
+
/* Function Name: RealDeleteFS
* Description: Does the real deletion work.
* Arguments: info - array of char *'s containing all useful info.
Bool junk;
{
int stat;
- char ** args = AskFSInfo(info, TRUE);
+ char ** args;
extern Menu nfsphys_menu;
+ args = AskFSInfo(info, TRUE);
+ if (args == NULL) {
+ Put_message("Aborted.");
+ return;
+ }
stat = do_mr_query("update_filesys", CountArgs(args), args,
NullFunc, NULL);
switch (stat) {
case MR_NFS:
Put_message("That NFS filesystem is not exported.");
- if (YesNoQuestion("Fix this now (Y/N)")) {
+ if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) {
Do_menu(&nfsphys_menu, 0, NULL);
- if (YesNoQuestion("Retry filesystem update now (Y/N)")) {
+ if (YesNoQuestion("Retry filesystem update now (Y/N)", TRUE)
+ == TRUE) {
if (stat = do_mr_query("update_filesys", CountArgs(args), args,
NullFunc, NULL))
com_err(program_name, stat, " filesystem not updated");
return(DM_NORMAL);
}
- args = AskFSInfo(SetDefaults(info, argv[1]), FALSE );
+ if ((args = AskFSInfo(SetDefaults(info, argv[1]), FALSE )) == NULL) {
+ Put_message("Aborted.");
+ return(DM_NORMAL);
+ }
stat = do_mr_query("add_filesys", CountArgs(args), args, NullFunc, NULL);
switch (stat) {
case MR_NFS:
Put_message("That NFS filesystem is not exported.");
- if (YesNoQuestion("Fix this now (Y/N)")) {
+ if (YesNoQuestion("Fix this now (Y/N)", TRUE) == TRUE) {
Do_menu(&nfsphys_menu, 0, NULL);
- if (YesNoQuestion("Retry filesystem creation now (Y/N)")) {
+ if (YesNoQuestion("Retry filesystem creation now (Y/N)", TRUE)
+ == TRUE) {
if (stat = do_mr_query("add_filesys", CountArgs(args), args,
NullFunc, NULL))
com_err(program_name, stat, " in AddFS");
if (stat == MR_SUCCESS && !strcasecmp(info[FS_L_TYPE], "HOMEDIR")) {
static char *val[] = {"def_quota", NULL};
static char *def_quota = NULL;
- char *argv[3];
+ char *argv[Q_QUOTA + 1];
struct qelem *top = NULL;
if (def_quota == NULL) {
if (def_quota != NULL) {
sprintf(buf, "Give user %s a quota of %s on filesys %s (Y/N)",
info[FS_NAME], def_quota, info[FS_NAME]);
- if (YesNoQuestion(buf, 1)) {
- argv[Q_LOGIN] = argv[Q_FILESYS] = info[FS_NAME];
+ if (YesNoQuestion(buf, 1) == TRUE) {
+ argv[Q_NAME] = argv[Q_FILESYS] = info[FS_NAME];
+ if (!strcmp(info[FS_TYPE], "NFS"))
+ argv[Q_TYPE] = "USER";
+ else
+ argv[Q_TYPE] = "ANY";
argv[Q_QUOTA] = def_quota;
- if ((stat = do_mr_query("add_nfs_quota", 3, argv, Scream,
+ if ((stat = do_mr_query("add_quota", Q_QUOTA+1, argv, Scream,
(char *) NULL)) != MR_SUCCESS) {
com_err(program_name, stat, " while adding quota");
}
}
}
+ } else if (stat == MR_SUCCESS) {
+ if (YesNoQuestion("Assign a quota on this filesystem (Y/N)", 1)
+ == TRUE) {
+ parsed_argc = 1;
+ parsed_argv[0] = info[FS_NAME];
+ AddQuota();
+ }
}
FreeInfo(info);
Loop(elem, (void *) PrintFSGMembers);
sprintf(buf, "%d", QueueCount(elem));
bufp = Strsave(buf);
- stat = GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp);
+ if (GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp) == SUB_ERROR)
+ return(DM_NORMAL);
count = atoi(bufp);
free(bufp);
args[2] = SortAfter(elem, count);
char **argv;
int argc;
{
- int stat, src, dst;
- struct qelem *elem = NULL, *top;
+ int stat, src, dst, i;
+ struct qelem *elem = NULL, *top, *tmpelem;
char buf[BUFSIZ], *bufp, *args[3];
if ((stat = do_mr_query("get_fsgroup_members", 1, argv+1, StoreInfo,
(char *)&elem)) != 0) {
if (stat == MR_NO_MATCH) {
- sprintf(buf, "Ether %s is not a filesystem group or it has no members", argv[1]);
+ sprintf(buf,
+ "Ether %s is not a filesystem group or it has no members",
+ argv[1]);
Put_message(buf);
} else
com_err(program_name, stat, " in ChangeFSGroupOrder");
Loop(top, (void *) PrintFSGMembers);
while (1) {
bufp = Strsave("1");
- stat = GetValueFromUser("Enter number of the filesystem to move:",
- &bufp);
+ if (GetValueFromUser("Enter number of the filesystem to move:",
+ &bufp) == SUB_ERROR)
+ return(DM_NORMAL);
src = atoi(bufp);
free(bufp);
if (src < 0) {
Put_message("Aborted.");
return(DM_NORMAL);
}
- for (elem = top; src-- > 1 && elem->q_forw; elem = elem->q_forw);
- if (src > 1) {
+ for (elem = top, i = src; i-- > 1 && elem->q_forw; elem = elem->q_forw);
+ if (i > 0) {
Put_message("You entered a number that is too high");
continue;
}
break;
}
- bufp = Strsave("0");
- stat = GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp);
- dst = atoi(bufp);
- free(bufp);
- if (src == dst || src == dst + 1) {
- Put_message("That has no effect on the sorting order!");
- return(DM_NORMAL);
+ while (1) {
+ bufp = Strsave("0");
+ if (GetValueFromUser("Enter number of filesystem it should follow (0 to make it first):", &bufp) == SUB_ERROR)
+ return(DM_NORMAL);
+ dst = atoi(bufp);
+ free(bufp);
+ if (src == dst || src == dst + 1) {
+ Put_message("That has no effect on the sorting order!");
+ return(DM_NORMAL);
+ }
+ if (dst < 0) {
+ Put_message("You must enter a non-negative number.");
+ continue;
+ }
+ for (tmpelem = top, i = dst;
+ i-- > 1 && tmpelem->q_forw;
+ tmpelem = tmpelem->q_forw);
+ if (i > 0) {
+ Put_message("You entered a number that is too high");
+ continue;
+ }
+ break;
}
args[2] = SortAfter(top, dst);
args[0] = argv[1];
return(DM_NORMAL);
}
- args[ALIAS_TRANS]= args[ALIAS_END] = NULL; /* set to NULL initially. */
- GetValueFromUser("Which filesystem will this alias point to?",
- &args[ALIAS_TRANS]);
+ args[ALIAS_TRANS]= Strsave("");
+ args[ALIAS_END] = NULL;
+ if (GetValueFromUser("Which filesystem will this alias point to?",
+ &args[ALIAS_TRANS]) == SUB_ERROR)
+ return(DM_NORMAL);
if ( (stat = do_mr_query("add_alias", 3, args, NullFunc, NULL)) != 0)
com_err(program_name, stat, " in CreateFSAlias.");