-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
-#endif lint
+#endif
-/* This is the file attach.c for allmaint, the SMS client that allows
- * a user to maintaint most important parts of the SMS database.
+/* This is the file attach.c for the SMS Client, which allows a nieve
+ * user to quickly and easily maintain most parts of the SMS database.
* It Contains: Functions for maintaining data used by Hesiod
* to map courses/projects/users to their file systems,
* and maintain filesys info.
*
* Created: 5/4/88
* By: Chris D. Peterson
- * Based Upon: attach.c 87/07/24 marcus
*
* $Source$
* $Author$
* $Header$
*
- * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
+ * Copyright 1988 by the Massachusetts Institute of Technology.
*
* For further information on copyright and distribution
* see the file mit-copyright.h
#include <menu.h>
#include "mit-copyright.h"
-#include "allmaint.h"
-#include "allmaint_funcs.h"
+#include "defs.h"
+#include "f_defs.h"
#include "globals.h"
#include "infodefs.h"
* Returns: a pointer to the first element in the queue.
*/
-struct qelem *
+static struct qelem *
GetFSInfo(type, name)
int type;
char *name;
switch (type) {
case LABEL:
if ( (stat = sms_query("get_filesys_by_label", 1, &name,
- StoreInfo, &elem)) != 0) {
+ StoreInfo, (char *)&elem)) != 0) {
com_err(program_name, stat, NULL);
return(NULL);
}
break;
case MACHINE:
if ( (stat = sms_query("get_filesys_by_machine", 1, &name,
- StoreInfo, &elem)) != 0) {
+ StoreInfo, (char *)&elem)) != 0) {
com_err(program_name, stat, NULL);
return(NULL);
}
break;
case GROUP:
if ( (stat = sms_query("get_filesys_by_group", 1, &name,
- StoreInfo, &elem)) != 0) {
+ StoreInfo, (char *)&elem)) != 0) {
com_err(program_name, stat, NULL);
return(NULL);
}
args[ALIAS_NAME] = name;
args[ALIAS_TYPE] = FS_ALIAS_TYPE;
args[ALIAS_TRANS] = "*";
- if ( (stat = sms_query("get_alias", 3, args, StoreInfo, &elem)) != 0) {
+ if ( (stat = sms_query("get_alias", 3, args, StoreInfo,
+ (char *) &elem)) != 0) {
com_err(program_name, stat, " in get_alias.");
return(NULL);
}
/* Function Name: PrintFSAlias
* Description: Prints a filesystem alias
* Arguments: info - an array contains the strings of info.
- * Returns: none.
+ * Returns: the name of the filesys - used be QueryLoop().
*/
-static void
+static char *
PrintFSAlias(info)
char ** info;
{
sprintf(buf,"Alias: %-25s Filesystem: %s",info[ALIAS_NAME],
info[ALIAS_TRANS]);
Put_message(buf);
+ return(info[ALIAS_NAME]);
}
/* Function Name: PrintFSInfo
* Returns: none.
*/
-void
+static char *
PrintFSInfo(info)
char ** info;
{
sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
info[FS_OWNER], info[FS_OWNERS]);
Put_message(print_buf);
- sprintf(print_buf, "Auto Create %-34s Locker Type: %s",info[FS_CREATE],
+ sprintf(print_buf, "Auto Create: %-34s Locker Type: %s",
+ atoi(info[FS_CREATE]) ? "ON" : "OFF",
info[FS_L_TYPE]);
Put_message(print_buf);
- sprintf(print_buf, "Last Modified at %s, by %s with %s",
- info[FS_MODTIME], info[FS_MODBY], info[FS_MODWITH]);
+ sprintf(print_buf, MOD_FORMAT, info[FS_MODBY], info[FS_MODTIME],
+ info[FS_MODWITH]);
Put_message(print_buf);
+ return(info[FS_NAME]);
}
/* Function Name: AskFSInfo.
* Returns: none.
*/
-char **
+static char **
AskFSInfo(info, name)
char ** info;
Bool name;
{
char temp_buf[BUFSIZ], *newname;
- sprintf(temp_buf, "\nChanging Attributes of filesystem: %s.\n",
+ Put_message("");
+ sprintf(temp_buf, "Changing Attributes of filesystem %s.",
info[FS_NAME]);
Put_message(temp_buf);
+ Put_message("");
if (name) {
newname = Strsave(info[FS_NAME]);
- GetValueFromUser("The new name for this filesystem.",
+ GetValueFromUser("The new name for this filesystem",
&newname);
}
- GetValueFromUser("Filesystem's Type:", &info[FS_TYPE]);
- GetValueFromUser("Filesystem's Machine:", &info[FS_MACHINE]);
+ GetValueFromUser("Filesystem's Type", &info[FS_TYPE]);
+ GetValueFromUser("Filesystem's Machine", &info[FS_MACHINE]);
strcpy(temp_buf, CanonicalizeHostname(info[FS_MACHINE]));
free(info[FS_MACHINE]);
info[FS_MACHINE] = Strsave(temp_buf);
- 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]);
- GetValueFromUser("Comments about this Filesystem:", &info[FS_COMMENTS]);
- GetValueFromUser("Filesystem's owner (user):", &info[FS_OWNER]);
- GetValueFromUser("Filesystem's owners (group):", &info[FS_OWNERS]);
- GetValueFromUser("Automatically create this filsystem (0/1):",
+ 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]);
+ GetValueFromUser("Comments about this Filesystem", &info[FS_COMMENTS]);
+ GetValueFromUser("Filesystem's owner (user)", &info[FS_OWNER]);
+ GetValueFromUser("Filesystem's owners (group)", &info[FS_OWNERS]);
+ GetYesNoValueFromUser("Automatically create this filsystem",
&info[FS_CREATE]);
- GetValueFromUser("Filesystem's lockertype:", &info[FS_L_TYPE]);
+ GetValueFromUser("Filesystem's lockertype", &info[FS_L_TYPE]);
FreeAndClear(&info[FS_MODTIME], TRUE);
FreeAndClear(&info[FS_MODBY], TRUE);
int argc;
char **argv;
{
- struct qelem *top, *elem;
+ struct qelem *top;
- top = elem = GetFSInfo(LABEL, argv[1]); /* get info. */
- while(elem != NULL) {
- char ** info = (char **) elem->q_data;
- PrintFSInfo(info);
- elem = elem->q_forw;
- }
+ top = GetFSInfo(LABEL, 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.
+ * one_item - a Boolean that is true if only one item
+ * in queue that dumped us here.
+ * Returns: none.
+ */
+
+void
+RealDeleteFS(info, one_item)
+char ** info;
+Bool one_item;
+{
+ int stat;
+ char temp_buf[BUFSIZ];
+
+/*
+ * Deletetions are performed if the user hits 'y' on a list of multiple
+ * filesystem, or if the user confirms on a unique alias.
+ */
+ sprintf(temp_buf, "Are you sure that you want to delete filesystem %s",
+ info[FS_NAME]);
+ if(!one_item || Confirm(temp_buf)) {
+ if ( (stat = sms_query("delete_filesys", 1,
+ &info[FS_NAME], Scream, NULL)) != 0)
+ com_err(program_name, stat, " filesystem not deleted.");
+ else
+ Put_message("Filesystem deleted.");
+ }
+ else
+ Put_message("Filesystem not deleted.");
+}
+
/* Function Name: DeleteFS
* Description: Delete a filesystem give its name.
* Arguments: argc, argv - argv[1] is the name of the filesystem.
int argc;
char **argv;
{
- int stat, answer, delete;
- Bool one_filsys;
- struct qelem *elem, *temp_elem;
-
- if ( (temp_elem = elem = GetFSInfo(LABEL, argv[1])) ==
- (struct qelem *) NULL )
- return(DM_NORMAL);
-/*
- * 1) If there is no (zero) match then we exit immediately.
- * 2) If there is exactly 1 element then we ask for confirmation only if in
- * verbose mode, via the Confirm function.
- * 3) If there is more than 1 filesystem to be deleted then we ask
- * about each one, and delete on yes only, and about if the user hits
- * quit.
- */
- one_filsys = (QueueCount(elem) == 1);
- while (temp_elem != NULL) {
- char **info = (char **) temp_elem->q_data;
-
- if (!one_filsys) {
- PrintFSInfo(info);
-
- answer = YesNoQuitQuestion("\nDelete this filesystem?", FALSE);
- switch(answer) {
- case TRUE:
- delete = TRUE;
- break;
- case FALSE:
- delete = FALSE;
- break;
- default: /* Quit. */
- Put_message("Aborting Delete Operation.");
- FreeQueue(elem);
- return(DM_NORMAL);
- }
- }
- else
- delete =
- Confirm("Are you sure that you want to delete this filsystem.");
-/*
- * Deletetions are performed if the user hits 'y' on a list of multiple
- * filesystem, or if the user confirms on a unique alias.
- */
- if (delete) {
- if ( (stat = sms_query("delete_filesys", 1,
- &info[FS_NAME], Scream, NULL)) != 0)
- com_err(program_name, stat, " filesystem not deleted.");
- else
- Put_message("Filesystem deleted.");
- }
- else
- Put_message("Filesystem not deleted.");
- temp_elem = temp_elem->q_forw;
- }
+ struct qelem *elem = GetFSInfo(LABEL, argv[1]);
+ QueryLoop(elem, PrintFSInfo, RealDeleteFS, "Delete the Filesystem");
- FreeQueue(elem); /* free all members of the queue. */
+ FreeQueue(elem);
return (DM_NORMAL);
}
+/* Function Name: RealChangeFS
+ * Description: performs the actual change to the filesys.
+ * Arguments: info - the information
+ * junk - an unused boolean.
+ * Returns: none.
+ */
+
+/* ARGSUSED. */
+static void
+RealChangeFS(info, junk)
+char ** info;
+Bool junk;
+{
+ int stat;
+ char ** args = AskFSInfo(info, TRUE);
+
+ if ( (stat = sms_query("update_filesys", CountArgs(args),
+ args, NullFunc, NULL)) != 0)
+ com_err(program_name, stat, ", filesystem not updated");
+ else
+ Put_message("filesystem sucessfully updated.");
+}
+
/* Function Name: ChangeFS
* Description: change the information in a filesys record.
* Arguments: arc, argv - value of filsys in argv[1].
char **argv;
int argc;
{
- struct qelem *elem, *temp_elem;
- int update, stat, answer;
- Bool one_filsys;
- char buf[BUFSIZ];
-
- elem = temp_elem = GetFSInfo(LABEL, argv[1]);
+ struct qelem *elem = GetFSInfo(LABEL, argv[1]);
+ QueryLoop(elem, NullPrint, RealChangeFS, "Update the Filesystem");
-/*
- * This uses the same basic method as the deletion routine above.
- */
-
- one_filsys = (QueueCount(elem) == 1);
- while (temp_elem != NULL) {
- char ** info = (char **) temp_elem->q_data;
- if (!one_filsys) {
- sprintf(buf, "Update filesystem %s (y/n/q)? ", info[FS_NAME]);
- info = (char **) temp_elem->q_data;
- answer = YesNoQuitQuestion(buf, FALSE);
- switch(answer) {
- case TRUE:
- update = TRUE;
- break;
- case FALSE:
- update = FALSE;
- break;
- default:
- Put_message("Aborting Operation.");
- FreeQueue(elem);
- return(DM_NORMAL);
- }
- }
- else
- update = TRUE;
-
- if (update) {
- char ** args = AskFSInfo(info, TRUE);
- if ( (stat = sms_query("update_filesys", CountArgs(args),
- args, NullFunc, NULL)) != 0)
- com_err(program_name, stat, ", filesystem not updated");
- else
- Put_message("filesystem sucessfully updated.");
- }
- temp_elem = temp_elem->q_forw;
- }
FreeQueue(elem);
return (DM_NORMAL);
}
int argc;
char **argv;
{
- struct qelem *top, *elem;
-
- top = elem = GetFSInfo(ALIAS, argv[1]);
+ struct qelem *top;
+ top = GetFSInfo(ALIAS, argv[1]);
Put_message(" "); /* blank line. */
- while (elem != NULL) {
- char **info = (char **) elem->q_data;
- PrintFSAlias(info);
- elem = elem->q_forw;
- }
-
+ Loop(top, (void *) PrintFSAlias);
FreeQueue(top);
return(DM_NORMAL);
}
* print out values, free memory used and then exit.
*/
- if ( (stat = sms_query("get_alias", 3, args, StoreInfo, &elem)) == 0) {
+ if ( (stat = sms_query("get_alias", 3, args, StoreInfo,
+ (char *)&elem)) == 0) {
top = elem = QueueTop(elem);
while (elem != NULL) {
info = (char **) elem->q_data;
FreeInfo(args);
return (DM_NORMAL);
}
+
+/* Function Name: RealDeleteFSAlias
+ * Description: Does the real deletion work.
+ * Arguments: info - array of char *'s containing all useful info.
+ * one_item - a Boolean that is true if only one item
+ * in queue that dumped us here.
+ * Returns: none.
+ */
+
+void
+RealDeleteFSAlias(info, one_item)
+char ** info;
+Bool one_item;
+{
+ int stat;
+ char temp_buf[BUFSIZ];
+
+/*
+ * Deletetions are performed if the user hits 'y' on a list of multiple
+ * filesystem, or if the user confirms on a unique alias.
+ */
+ sprintf(temp_buf,
+ "Are you sure that you want to delete the filesystem alias %s",
+ info[ALIAS_NAME]);
+ if(!one_item || Confirm(temp_buf)) {
+ if ( (stat = sms_query("delete_alias", CountArgs(info),
+ info, Scream, NULL)) != 0 )
+ com_err(program_name, stat, " filesystem alias not deleted.");
+ else
+ Put_message("Filesystem alias deleted.");
+ }
+ else
+ Put_message("Filesystem alias not deleted.");
+}
/* Function Name: DeleteFSAlias
* Description: Delete an alias name for a filsystem
int argc;
char **argv;
{
- register int stat;
- char *ptr;
- struct qelem *elem, *top;
- Bool one_alias, delete;
-
- if (!ValidName(argv[1]))
- return(DM_NORMAL);
-
- top = elem = GetFSInfo(ALIAS, argv[1]);
-
-/*
- * 1) If there are no (zero) match in elements then we exit immediately.
- * 2) If there is exactly 1 element then we ask for confirmation only if in
- * verbose mode, via the Confirm function.
- * 3) If there is more than 1 filesystem alias to be deleted then we ask
- * about each one, and delete on yes only, and about if the user hits
- * quit.
- */
- one_alias = ( QueueCount(top) == 1 );
- while (elem != NULL) {
- char **info = (char **) elem->q_data;
-
- Put_message(" "); /* blank line. */
- PrintFSAlias(info);
- if (!one_alias) {
- int answer;
-
- ptr = "Do you want to delete this alias (y/n/q)? ",
- answer = YesNoQuitQuestion(ptr, FALSE);
- switch(answer) {
- case TRUE:
- delete = TRUE;
- break;
- case FALSE:
- delete = FALSE;
- break;
- default: /* Quit. */
- Put_message("Aborting Delete Operation.");
- FreeQueue(top);
- return(DM_NORMAL);
- }
- }
- else {
- ptr = "Are you sure that you want to delete this alias?";
- delete = Confirm(ptr);
- }
-/*
- * Deletetions are performed if the user hits 'y' on a list of multiple
- * filesystem aliases, or if the user confirms on a unique alias.
- */
- if (delete) {
- if ( (stat = sms_query("delete_alias", CountArgs(info),
- info, Scream, NULL)) != 0)
- com_err(program_name, stat, " filesystem alias not deleted.");
- else
- Put_message("Filesystem alias deleted.");
- }
- else
- Put_message("Filesystem alias not deleted.");
- elem = elem->q_forw;
- }
-
- FreeQueue(top);
+ struct qelem *elem = GetFSInfo(ALIAS, argv[1]);
+ QueryLoop(elem, PrintFSAlias, RealDeleteFSAlias,
+ "Delete the Filesystem Alias");
+ FreeQueue(elem);
return (DM_NORMAL);
}