pretty well.
-#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.
* Returns: a pointer to the first element in the queue.
*/
-struct qelem *
+static struct qelem *
GetFSInfo(type, name)
int type;
char *name;
/* 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, "Last Modified at %s, by %s with %s",
info[FS_MODTIME], info[FS_MODBY], 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]);
+ GetValueFromUser("Automatically create this filsystem (0/1)",
&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);
top = elem = GetFSInfo(LABEL, argv[1]); /* get info. */
while(elem != NULL) {
char ** info = (char **) elem->q_data;
- PrintFSInfo(info);
+ (void) PrintFSInfo(info);
elem = elem->q_forw;
}
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);
}
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);
}
-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
#endif lint
* Returns: info - the array.
*/
-char **
+static char **
SetMachineDefaults(info, name)
char ** info, *name;
{
* Returns: info - the array.
*/
-char **
+static char **
SetClusterDefaults(info, name)
char ** info, *name;
{
return(info);
}
-/* Function Name: SetClusterDataDefaults
- * Description: Sets cluster data defaults.
- * Arguments: info - an array to put the defaults into.
- * name - name of the Cluster.
- * Returns: info - the array.
- */
-
-char **
-SetClusterDataDefaults(info, name)
-char ** info, *name;
-{
- info[CD_NAME] = Strsave(name);
- info[CD_LABEL] = Strsave(CD_DEFAULT_LABEL);
- info[CD_DATA] = Strsave(CD_DEFAULT_DATA);
-/*info[CD_MODBY] = info[CD_MODTIME] = info[CD_MODWITH] = info[CD_END] = NULL;*/
- info[CD_END] = NULL;
- return(info);
-}
-
/* -------------------- General Functions -------------------- */
/* Function Name: PrintMachInfo
* Description: This function Prints out the Machine info in
* a coherent form.
* Arguments: info - array of information about a machine.
- * Returns: none.
+ * Returns: The name of the Machine
*/
-void
+static char *
PrintMachInfo(info)
char ** info;
{
sprintf(buf, "Last Modified at %s, by %s with %s",info[M_MODTIME],
info[M_MODBY], info[M_MODWITH]);
Put_message(buf);
+ return(info[M_NAME]);
}
/* Function Name: PrintClusterInfo
* Description: This function Prints out the cluster info
* in a coherent form.
* Arguments: info - array of information about a cluster.
- * Returns: none.
+ * Returns: The name of the cluster.
*/
-void
+static char *
PrintClusterInfo(info)
char ** info;
{
sprintf(buf, "Last Modified at %s, by %s with %s",info[C_MODTIME],
info[C_MODBY], info[C_MODWITH]);
Put_message(buf);
+ return(info[C_NAME]);
}
/* Function Name: PrintClusterData
* Description: Prints the Data on a cluster
* Arguments: info a pointer to the data array.
- * Returns: none
+ * Returns: The name of the cluster.
*/
-void
+static char *
PrintClusterData(info)
char ** info;
{
sprintf(buf, "Cluster: %-20s Label: %-15s Data: %s",
info[CD_NAME], info[CD_LABEL], info[CD_DATA]);
Put_message(buf);
+ return(info[CD_NAME]);
}
/* Function Name: PrintMCMap
* Returns: none
*/
-void
+static char *
PrintMCMap(info)
char ** info;
{
sprintf(buf, "Cluster: %-30s Machine: %-20s",
info[MAP_CLUSTER], info[MAP_MACHINE]);
Put_message(buf);
+ return(""); /* Used by QueryLoop(). */
}
/* Function Name: GetMCInfo.
int argc;
char **argv;
{
- struct qelem *elem, *top;
-
- top = elem = GetMCInfo(MACHINE, CanonicalizeHostname(argv[1]),
- (char *) NULL);
-
- while (elem != NULL) {
- char **info = (char **) elem->q_data;
- PrintMachInfo(info);
- elem = elem->q_forw;
- }
+ struct qelem *top;
+ top = GetMCInfo(MACHINE, CanonicalizeHostname(argv[1]), (char *) NULL);
+ Loop(top, ( (void *) PrintMachInfo) );
FreeQueue(top);
return(DM_NORMAL);
}
{
char **args, *info[MAX_ARGS_SIZE], *name;
int stat;
+
+ if (!ValidName(argv[1])) /* Checks for wildcards. */
+ return(DM_NORMAL);
/*
* Check to see if this machine already exists.
*/
return(DM_NORMAL);
}
+/* Function Name: RealUpdateMachine
+ * Description: Performs the actual update of the machine data.
+ * Arguments: info - the information on the machine to update.
+ * junk - an UNUSED Boolean.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+static void
+RealUpdateMachine(info, junk)
+char ** info;
+Bool junk;
+{
+ register int stat;
+ char ** args = AskMCDInfo(info, MACHINE, TRUE);
+ if ( (stat = sms_query("update_machine", CountArgs(args),
+ args, Scream, NULL)) != 0)
+ com_err(program_name, stat, " in UpdateMachine.");
+ else
+ Put_message("Machine sucessfully updated.");
+}
+
/* Function Name: UpdateMachine
* Description: This function adds a new machine to the database.
* Arguments: argc, argv - the name of the machine in argv[1].
int argc;
char **argv;
{
- struct qelem *elem, *top;
- int stat;
- char **args, **info, temp_buf[BUFSIZ];
- Bool one_machine, update_it;
-
- elem = top = GetMCInfo( MACHINE, CanonicalizeHostname(argv[1]),
- (char *) NULL);
+ struct qelem *top = GetMCInfo( MACHINE, CanonicalizeHostname(argv[1]),
+ (char *) NULL);
+ QueryLoop(top, NullPrint, RealUpdateMachine, "Update the machine");
- one_machine = (QueueCount(top) == 1);
- while (elem != NULL) {
- info = (char **) elem->q_data;
- if (one_machine)
- update_it = TRUE;
- else {
- sprintf(temp_buf, "Update %s (y/n/q) ? ", info[M_NAME]);
- switch(YesNoQuitQuestion(temp_buf, FALSE)) {
- case TRUE:
- update_it = TRUE;
- break;
- case FALSE:
- update_it = FALSE;
- break;
- default:
- Put_message("Aborting...");
- FreeQueue(top);
- return(DM_NORMAL);
- }
- }
- if (update_it) {
- args = AskMCDInfo(info, MACHINE, TRUE);
- if ( (stat = sms_query("update_machine", CountArgs(args),
- args, Scream, NULL)) != 0)
- com_err(program_name, stat, " in UpdateMachine.");
- }
- elem = elem->q_forw;
- }
FreeQueue(top);
return(DM_NORMAL);
}
char *args[10], temp_buf[BUFSIZ], *ptr;
struct qelem *top, *elem = NULL;
- ret_value = SUB_NORMAL;
+ ret_value = SUB_NORMAL; /* initialize ret_value. */
args[0] = name;
args[1] = "*";
stat = sms_query("get_machine_to_cluster_map", 2, args,
com_err(program_name, stat, " in get_machine_to_cluster_map.");
return(DM_NORMAL);
}
- if (stat == 0) {
+ if (stat == SMS_SUCCESS) {
elem = top = QueueTop(elem);
if (ask_user) {
sprintf(temp_buf, "%s is assigned to the following clusters.",
name);
Put_message(temp_buf);
- while (elem != NULL) {
- char **info = (char **) elem->q_data;
- Print(1, &info[MAP_CLUSTER], (char *) NULL);
- elem = elem->q_forw;
- }
+ Loop(top, (void *) PrintMCMap);
ptr = "Remove this machine from ** ALL ** these clusters?";
-
if (YesNoQuestion(ptr, FALSE) == TRUE) /* may return -1. */
delete_it = TRUE;
else {
delete_it = TRUE;
if (delete_it) {
- elem = top;
- while (elem != 0) {
+ while (elem != NULL) {
char **info = (char **) elem->q_data;
if ( (stat = sms_query( "delete_machine_from_cluster",
2, info, Scream, NULL)) != 0) {
return(ret_value);
}
+/* Function Name: RealDeleteMachine
+ * Description: Actually Deletes the Machine.
+ * Arguments: info - nescessary information stored as an array of char *'s
+ * one_machine - a boolean, true if there is only one item in
+ * the query.
+ * Returns: none.
+ */
+
+static void
+RealDeleteMachine(info, one_machine)
+char ** info;
+Bool one_machine;
+{
+ register int stat;
+ char temp_buf[BUFSIZ];
+
+ sprintf(temp_buf, "Are you sure you want to delete the machine %s (y/n)? ",
+ info[M_NAME]);
+ if(!one_machine || Confirm(temp_buf)) {
+ if (CheckAndRemoveFromCluster(info[M_NAME], TRUE) != SUB_ERROR) {
+ if ( (stat = sms_query("delete_machine", 1,
+ &info[M_NAME], Scream, NULL)) != 0) {
+ com_err(program_name, stat, " in DeleteMachine.");
+ sprintf(temp_buf, "%s ** NOT ** deleted.",
+ info[M_NAME]);
+ Put_message(temp_buf);
+ }
+ else {
+ sprintf(temp_buf, "%s successfully Deleted.", info[M_NAME]);
+ Put_message(temp_buf);
+ }
+ }
+ }
+}
+
/* Function Name: DeleteMachine
* Description: This function removes a machine from the data base.
* Arguments: argc, argv - the machines name int argv[1].
int argc;
char **argv;
{
- int stat;
- Bool one_machine, delete_it = FALSE;
- char *name, temp_buf[BUFSIZ];
- struct qelem *top, *elem = NULL;
-
- name = CanonicalizeHostname(argv[1]);
- top = elem = GetMCInfo(MACHINE, name, (char *) NULL);
+ struct qelem *top;
- one_machine = (QueueCount(top) == 1);
- while (elem != NULL) {
- char **info = (char **) elem->q_data;
- if (one_machine) {
- if(Confirm("Are you sure that you want to delete this machine?"))
- delete_it = TRUE;
- }
- else {
- sprintf(temp_buf, "Delete the machine %s (y/n/q)? ", info[M_NAME]);
- switch (YesNoQuitQuestion(temp_buf, FALSE)) {
- case TRUE:
- delete_it = TRUE;
- break;
- case FALSE:
- delete_it = FALSE;
- sprintf(temp_buf, "%s not Deleted.", info[M_NAME]);
- Put_message(temp_buf);
- break;
- default: /* quit. */
- Put_message("Aborting...");
- FreeQueue(top);
- return(DM_NORMAL);
- }
- }
- if (delete_it) {
- if (CheckAndRemoveFromCluster(info[M_NAME], TRUE) != SUB_ERROR) {
- if ( (stat = sms_query("delete_machine", 1,
- &info[M_NAME], Scream, NULL)) != 0) {
- com_err(program_name, stat, " in DeleteMachine.");
- sprintf(temp_buf, "%s ** NOT ** deleted.",
- info[M_NAME]);
- Put_message(temp_buf);
- }
- else {
- sprintf(temp_buf, "%s sucesfully Deleted.", info[M_NAME]);
- Put_message(temp_buf);
- }
- }
- }
- elem = elem->q_forw;
- }
+ top = GetMCInfo(MACHINE, CanonicalizeHostname(argv[1]), (char *) NULL);
+ QueryLoop(top, PrintMachInfo, RealDeleteMachine, "Delete the machine");
FreeQueue(top);
return(DM_NORMAL);
}
one_machine = (QueueCount(mtop) == 1);
one_cluster = (QueueCount(ctop) == 1);
+ /* No good way to use QueryLoop() here, sigh */
+
while (melem != NULL) {
char ** minfo = (char **) melem->q_data;
while (celem != NULL) {
return(DM_NORMAL);
}
+/* Function Name: RealRemoveMachineFromCluster
+ * Description: This function actually removes the machine from its
+ * cluster.
+ * Arguments: info - all information nescessary to perform the removal.
+ * one_map - True if there is only one case, and we should
+ * confirm.
+ * Returns: none.
+ */
+
+static void
+RealRemoveMachineFromCluster(info, one_map)
+char ** info;
+Bool one_map;
+{
+ char temp_buf[BUFSIZ];
+ register int stat;
+
+ sprintf(temp_buf, "Remove %s from the cluster %s",
+ info[MAP_MACHINE], info[MAP_MACHINE]);
+ if (!one_map || Confirm(temp_buf)) {
+ if ( (stat = sms_query("delete_machine_from_cluster", 2,
+ info, Scream, NULL)) != 0 )
+ com_err(program_name, stat, " in delete_machine_from_cluster");
+ else {
+ sprintf(temp_buf, "%s has been removed from the cluster %s.",
+ info[MAP_MACHINE], info[MAP_CLUSTER]);
+ Put_message(temp_buf);
+ }
+ }
+ else
+ Put_message("Machine not removed.");
+}
+
/* Function Name: RemoveMachineFromCluster
* Description: Removes this machine form a specific cluster.
* Arguments: argc, argv - Name of machine in argv[1].
int argc;
char ** argv;
{
- int stat;
- Bool remove_machine, one_item;
- struct qelem *top, *elem = NULL;
+ struct qelem *elem = NULL;
char buf[BUFSIZ], * args[10];
+ register int stat;
args[MAP_MACHINE] = CanonicalizeHostname(argv[1]);
args[MAP_CLUSTER] = argv[2];
if (stat)
com_err(program_name, stat, " in delete_machine_from_cluster");
- top = elem = QueueTop(elem);
- one_item = (QueueCount(top) == 1);
- while (elem != NULL) {
- char **info = (char **) elem->q_data;
- if (one_item)
- remove_machine = TRUE;
- else {
- sprintf(buf, "Remove %s from the cluster %s? (y/n/q)",
- info[MAP_MACHINE], info[MAP_CLUSTER]);
- switch (YesNoQuitQuestion(buf, FALSE)) {
- case TRUE:
- remove_machine = TRUE;
- break;
- case FALSE:
- remove_machine = FALSE;
- break;
- default:
- Put_message("Aborting");
- FreeQueue(top);
- return(DM_NORMAL);
- }
- }
- if (remove_machine)
- if ( (stat = sms_query("delete_machine_from_cluster", 2,
- info, Scream, NULL)) != 0 )
- com_err(program_name, stat,
- " in delete_machine_from_cluster");
- else {
- sprintf(buf, "%s has been removed from the cluster %s.",
- info[MAP_MACHINE], info[MAP_CLUSTER]);
- Put_message(buf);
- }
- elem = elem->q_forw;
- }
- FreeQueue(top);
+ elem = QueueTop(elem);
+ QueryLoop(elem, PrintMCMap, RealRemoveMachineFromCluster,
+ "Remove this machine from this cluster");
+
+ FreeQueue(elem);
return(DM_NORMAL);
}
int argc;
char ** argv;
{
- char **info;
- struct qelem *elem, *top;
+ struct qelem *top;
- top = elem = GetMCInfo( CLUSTER, CanonicalizeHostname(argv[1]),
- (char *) NULL);
- while (elem != NULL) {
- info = (char **) elem->q_data;
- PrintClusterInfo(info);
- elem = elem->q_forw;
- }
+ top = GetMCInfo(CLUSTER, CanonicalizeHostname(argv[1]), (char *) NULL);
+ Loop(top, (void *) PrintClusterInfo);
FreeQueue(top);
return(DM_NORMAL);
}
int argc;
char ** argv;
{
- char **args, *info[MAX_ARGS_SIZE], *name;
+ char **args, *info[MAX_ARGS_SIZE], *name = argv[1];
int stat;
/*
- * Check to see if this machine already exists.
+ * Check to see if this cluster already exists.
*/
- name = argv[1];
+ if (!ValidName(name))
+ return(DM_NORMAL);
- if ( (stat = sms_query("get_cluster", 1, &name, NullFunc, NULL)) == 0) {
+ if ( (stat = sms_query("get_cluster", 1, &name,
+ NullFunc, NULL)) == SMS_SUCCESS) {
Put_message("This cluster already exists.");
return(DM_NORMAL);
}
com_err(program_name, stat, " in AddCluster.");
return(DM_NORMAL);
}
-
args = AskMCDInfo(SetClusterDefaults(info, name), CLUSTER, FALSE);
-
/*
* Actually create the new Cluster.
*/
-
if ( (stat = sms_query("add_cluster", CountArgs(args),
args, Scream, NULL)) != 0)
com_err(program_name, stat, " in AddCluster.");
return(DM_NORMAL);
}
+/* Function Name: RealUpdateCluster
+ * Description: This function actually performs the cluster update.
+ * Arguments: info - all information nesc. for updating the cluster.
+ * junk - an UNUSED boolean.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+static void
+RealUpdateCluster(info, junk)
+char ** info;
+Bool junk;
+{
+ register int stat;
+ char ** args = AskMCDInfo(info, CLUSTER, TRUE);
+ if ( (stat = sms_query("update_cluster", CountArgs(args),
+ args, Scream, NULL)) != 0)
+ com_err(program_name, stat, " in UpdateCluster.");
+ else
+ Put_message("Cluster successfully updated.");
+}
+
/* Function Name: UpdateCluster
* Description: This Function Updates a cluster
* Arguments: name of the cluster in argv[1].
int argc;
char ** argv;
{
- struct qelem *elem, *top;
- char **args, **info, temp_buf[BUFSIZ];
- int stat;
- Bool one_cluster, update_it;
-
- elem = top = GetMCInfo( CLUSTER, argv[1], (char *) NULL );
+ struct qelem *top;
+ top = GetMCInfo( CLUSTER, argv[1], (char *) NULL );
+ QueryLoop(top, NullPrint, RealUpdateCluster, "Update the cluster");
- one_cluster = (QueueCount(top) == 1);
- while (elem != NULL) {
- info = (char **) elem->q_data;
- if (one_cluster)
- update_it = TRUE;
- else {
- sprintf(temp_buf, "Update Cluster %s (y/n/q) ? ", info[C_NAME]);
- switch(YesNoQuitQuestion(temp_buf, FALSE)) {
- case TRUE:
- update_it = TRUE;
- break;
- case FALSE:
- update_it = FALSE;
- break;
- default:
- Put_message("Aborting...");
- FreeQueue(top);
- return(DM_NORMAL);
- }
- }
- if (update_it) {
- args = AskMCDInfo(info, CLUSTER, TRUE);
- if ( (stat = sms_query("update_cluster", CountArgs(args),
- args, Scream, NULL)) != 0)
- com_err(program_name, stat, " in UpdateCluster.");
- }
- elem = elem->q_forw;
- }
FreeQueue(top);
return(DM_NORMAL);
}
return(ret_value);
}
+/* Function Name: RealDeleteCluster
+ * Description: Actually performs the cluster deletion.
+ * Arguments: info - all information about this cluster.
+ * one_cluster - If true then there was only one cluster in
+ * the queue, and we should confirm.
+ * Returns: none.
+ */
+
+static void
+RealDeleteCluster(info, one_cluster)
+char ** info;
+Bool one_cluster;
+{
+ register int stat;
+ char temp_buf[BUFSIZ];
+
+ sprintf(temp_buf,
+ "Are you sure the you want to delete the cluster %s (y/n) ?",
+ info[C_NAME]);
+ if (!one_cluster || Confirm(temp_buf)) {
+ if (CheckAndRemoveMachines(info[C_NAME], TRUE) != SUB_ERROR) {
+ if ( (stat = sms_query("delete_cluster", 1,
+ &info[C_NAME], Scream, NULL)) != 0) {
+ com_err(program_name, stat, " in delete_cluster.");
+ sprintf(temp_buf, "Cluster %s ** NOT ** deleted.",
+ info[C_NAME]);
+ Put_message(temp_buf);
+ }
+ else {
+ sprintf(temp_buf, "cluster %s sucesfully deleted.",
+ info[C_NAME]);
+ Put_message(temp_buf);
+ }
+ }
+ }
+}
/* Function Name: DeleteCluster
* Description: This function removes a cluster from the database.
int argc;
char ** argv;
{
- char temp_buf[BUFSIZ];
- int stat;
- Bool one_cluster, delete_it = FALSE;
- struct qelem *elem, *top;
+ struct qelem *top;
- top = elem = GetMCInfo( CLUSTER, argv[1], (char *) NULL );
+ top = GetMCInfo( CLUSTER, argv[1], (char *) NULL );
+ QueryLoop(top, PrintClusterInfo, RealDeleteCluster, "Delete the cluster");
- one_cluster = (QueueCount(top) == 1);
- while (elem != NULL) {
- char **info = (char **) elem->q_data;
- if (one_cluster) {
- if(Confirm("Are you sure that you want to delete this cluster?"))
- delete_it = TRUE;
- }
- else {
- PrintClusterInfo(info);
- sprintf(temp_buf, "Delete the cluster %s (y/n/q)? ", info[C_NAME]);
- switch (YesNoQuitQuestion(temp_buf, FALSE)) {
- case TRUE:
- delete_it = TRUE;
- break;
- case FALSE:
- delete_it = FALSE;
- sprintf(temp_buf, "%s not Deleted.", info[C_NAME]);
- Put_message(temp_buf);
- break;
- default: /* quit. */
- Put_message("Aborting...");
- FreeQueue(top);
- return(DM_NORMAL);
- }
- }
- if (delete_it) {
- if (CheckAndRemoveMachines(info[C_NAME], TRUE) != SUB_ERROR) {
- if ( (stat = sms_query("delete_cluster", 1,
- &info[C_NAME], Scream, NULL)) != 0) {
- com_err(program_name, stat, " in DeleteCluster.");
- sprintf(temp_buf, "Cluster %s ** NOT ** deleted.",
- info[C_NAME]);
- Put_message(temp_buf);
- }
- else {
- sprintf(temp_buf, "cluster %s sucesfully Deleted.",
- info[C_NAME]);
- Put_message(temp_buf);
- }
- }
- }
- elem = elem->q_forw;
- }
FreeQueue(top);
return(DM_NORMAL);
}
-
+
/* ----------- Cluster Data Menu -------------- */
/* Function Name: ShowClusterData
}
+/* Function Name: RealRemoveClusterData
+ * Description: actually removes the cluster data.
+ * Arguments: info - all info necessary to remove the cluster, in an array
+ * of strings.
+ * one_item - if true then the queue has only one elem and we
+ * should confirm.
+ * Returns: none.
+ */
+
+static void
+RealRemoveClusterData(info, one_item)
+char ** info;
+Bool one_item;
+{
+ register int stat;
+ char * temp_ptr;
+
+ Put_message(" ");
+ temp_ptr = "Are you sure that you want to remove this cluster (y/n) ?";
+ if (!one_item) PrintClusterData(info);
+ if (!one_item || Confirm(temp_ptr)) {
+ if( (stat = sms_query("delete_cluster_data", 3, info,
+ Scream, (char *) NULL)) != 0) {
+ com_err(program_name, stat, " in DeleteClusterData.");
+ Put_message("Data not removed.");
+ }
+ else
+ Put_message("Removal sucessful.");
+ }
+}
+
/* Function Name: RemoveClusterData
* Description: This function removes data on a given cluster.
* Arguments: argv, argc: argv[1] - the name of the cluster.
int argc;
char ** argv;
{
- Bool one_piece_of_data, remove_it;
- int stat;
- struct qelem *elem, *top;
+ struct qelem *top;
- top = elem = GetMCInfo(DATA, argv[1], argv[2]);
+ top = GetMCInfo(DATA, argv[1], argv[2]);
+ QueryLoop(top, PrintClusterData, RealRemoveClusterData,
+ "Remove this cluster data");
- one_piece_of_data = (QueueCount(elem) == 1);
- while (elem != NULL) {
- char **info = (char **) elem->q_data;
- if (one_piece_of_data) {
- if(Confirm("Do you really want to remove this data?"))
- remove_it = TRUE;
- else
- Put_message("Operation aborted.\n");
- }
- else {
- PrintClusterData(info);
- switch (YesNoQuitQuestion
- ("Remove this piece of cluster data (y/n/q) ? ", FALSE)) {
- case TRUE:
- remove_it = TRUE;
- break;
- case FALSE:
- remove_it = FALSE;
- break;
- default:
- Put_message("Aborting");
- FreeQueue(top);
- return(DM_NORMAL);
- }
- }
- if (remove_it) {
- if( (stat = sms_query("delete_cluster_data", 3, info,
- Scream, (char *) NULL)) != 0) {
- com_err(program_name, stat, " in DeleteClusterData.");
- Put_message("Data not removed.");
- }
- else
- Put_message("Removal sucessful.");
- }
- elem = elem->q_forw;
- }
FreeQueue(top);
return(DM_NORMAL);
}
-/* Perhaps an interactive delete cluster data would be nice. */
-
/* Function Name: MachineToClusterMap
* Description: This Retrieves the mapping between machine and cluster
* Arguments: argc, argv - argv[1] -> machine name or wildcard.
-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
#endif lint
if (status == SMS_NO_MATCH)
return(SUB_NORMAL);
- if (status != 0) {
+ if (status != SMS_SUCCESS) {
com_err(program_name, status, " in DeleteList (get_lists_of_member).");
return(SUB_ERROR);
}
local = *elem;
while (local != NULL) {
char ** info = (char **) local->q_data;
- Print( CountArgs(info), info, NULL);
+ Print( 1, &info[GLOM_NAME], (char *) NULL);
local = local->q_forw;
}
sprintf(temp_buf,"Remove %s %s from these lists? ", type, name);
*/
local = *elem;
- args[1] = name;
- args[2] = type;
+ args[DM_LIST] = name;
+ args[DM_TYPE] = type;
while (local != NULL) {
char ** info = (char **) local->q_data;
- args[0] = info[0];
+ args[DM_MEMBER] = info[GLOM_NAME];
if ( (status = sms_query("delete_member_from_list",
3, args, Scream, NULL)) != 0) {
com_err(program_name, status, " in delete_member\nAborting\n");
com_err(program_name, status, ": list not deleted");
return(SUB_ERROR);
}
- (void) sprintf(buf, "List %s deleted./n", name);
+ (void) sprintf(buf, "List %s deleted.", name);
Put_message(buf);
+ Put_message("");
return(SUB_NORMAL);
}
* 1) try to delet it, if this fails in a known error then
* a) try to clean up each of those known methods, or
* at least explain why we failed.
- * Arguments: list - name of list.
+ * Arguments: list_info - info about this list.
* ask_first - (T/F) query user before preparing for deletion,
* and cleaning up?
* Returns: none - all is taken care of and error messages printed
*/
void
-AttemptToDeleteList(name, ask_first)
-char * name;
+AttemptToDeleteList(list_info, ask_first)
+char ** list_info;
Bool ask_first;
{
int status;
- struct qelem *local, *member_of, *list_info;
- char ** info;
- member_of = list_info = NULL;
+ struct qelem *local, *member_of;
+ char *name = list_info[L_NAME];
+ member_of = NULL;
/*
* Attempt delete. - will only work if:
*/
if ( (CheckIfAcl(name, "list", ask_first) == SUB_NORMAL) &&
+ (RemoveMembersOfList(name, ask_first) == SUB_NORMAL) &&
(RemoveItemFromLists(name, "list",
&member_of, ask_first) == SUB_NORMAL) &&
- (RemoveMembersOfList(name, ask_first) == SUB_NORMAL) &&
(RealDeleteList(name) == SUB_NORMAL) )
{ /* if... */
- info = (char **) list_info->q_data;
- CheckAcl(info[L_ACL_TYPE], info[L_ACL_NAME], ask_first);
+ CheckAcl(list_info[L_ACL_TYPE], list_info[L_ACL_NAME], ask_first);
local = member_of;
while (local != NULL) {
- info = (char **) local->q_data;
+ char ** info = (char **) local->q_data;
CheckListForDeletion(info[LM_LIST], ask_first);
local = local->q_forw;
}
+ FreeQueue(member_of);
}
- FreeQueue(list_info);
- FreeQueue(member_of); /* bug here somwhere... */
break;
default:
com_err(program_name, status, " in DeleteList (delete_list).");
return(DM_NORMAL);
*/ case SMS_NO_MATCH:
case SMS_LIST:
- Put_message("There is not list that matches that name.");
+ Put_message("There is no list that matches that name.");
return(DM_NORMAL);
default:
com_err(program_name, status, " in DeleteList (get_list_info).");
while (list != NULL) {
char ** info = (char**) list->q_data;
if (one_list) {
- if (Confirm("Are you sure that you want to delete this list?"))
- AttemptToDeleteList(info[L_NAME], TRUE);
+ sprintf( buf, "Are you sure that you want to delete the list %s",
+ info[L_NAME]);
+ if ( Confirm(buf) ) AttemptToDeleteList(info, TRUE);
}
else {
sprintf(buf, "Delete the list %s", info[L_NAME]);
switch( YesNoQuestion( buf, FALSE ) ) {
case TRUE:
- AttemptToDeleteList(info[L_NAME], TRUE);
+ AttemptToDeleteList(info, TRUE);
break;
case FALSE:
break;
-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
#endif lint
-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
#endif lint
#define GLOM 2
#define ACL_USE 3
-#define YES ("1")
-#define NO ("0")
-
#define DEFAULT_ACTIVE DEFAULT_YES
#define DEFAULT_PUBLIC DEFAULT_YES
#define DEFAULT_HIDDEN DEFAULT_NO
static char current_list[BUFSIZ];
+/* Function Name: PrintListAcl
+ * Description: This function prints the list acl information.
+ * Arguments: info - an info structure.
+ * Returns: none.
+ */
+
+static void
+PrintListAcl(info)
+char ** info;
+{
+ char buf[BUFSIZ];
+
+ Put_message(" ");
+ sprintf(buf, "Item Administered: %-20s Name: %s", info[ACL_TYPE],
+ info[ACL_NAME]);
+ Put_message(buf);
+}
+
/* Function Name: PrintListInfo
* Description: This function Prints out the List info in a coherent form.
* Arguments: info - the List info.
* Returns: none.
*/
-void
+static void
PrintListInfo(info)
char ** info;
{
char buf[BUFSIZ];
- (void) sprintf(buf, "\n%20sList: %s", "", info[L_NAME]);
+ Put_message(" ");
+ (void) sprintf(buf, "%20sList: %s", "", info[L_NAME]);
(void) Put_message(buf);
(void) sprintf(buf, "Description: %s", info[L_DESC]);
(void) Put_message(buf);
Put_message(buf);
}
else
- Put_message("This is NOT a Group.");
+ Put_message("This list is NOT a Group.");
if (strcmp(info[L_ACL_TYPE],"NONE") == 0)
Put_message("This list has no Administrator, how strange?!");
else {
- sprintf(buf, "The List Administrator of this list is the %s: %s",
+ sprintf(buf, "The Administrator of this list is the %s: %s",
info[L_ACL_TYPE], info[L_ACL_NAME]);
Put_message(buf);
}
case GLOM:
args[0] = name1;
args[1] = name2;
- if ( (status = sms_query("get_list_of_member", 2, args,
+ if ( (status = sms_query("get_lists_of_member", 2, args,
StoreInfo, (char *) &elem)) != 0) {
com_err(program_name, status, " in get_list_of_members");
return (NULL);
{
char temp_buf[BUFSIZ], *newname;
- sprintf(temp_buf,"\nSetting information of list %s.\n",info[L_NAME]);
+ Put_message(" ");
+ sprintf(temp_buf,"Setting information of list %s.",info[L_NAME]);
Put_message(temp_buf);
+ Put_message(" ");
if (name) {
newname = Strsave(info[L_NAME]);
return(DM_NORMAL);
}
+/* Function Name: RealUpdateList
+ * Description: performs the actual update of the list.
+ * Arguments: info - all information needed to update the list.
+ * junk - an UNUSED boolean.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+static void
+RealUpdateList(info, junk)
+char ** info;
+Bool junk;
+{
+ register int stat;
+ char ** args;
+
+ args = AskListInfo(info, TRUE);
+ if ( (stat = sms_query("update_list", CountArgs(args), args,
+ Scream, (char *) NULL)) != SMS_SUCCESS) {
+ com_err(program_name, stat, " in UpdateList.");
+ Put_message("List ** NOT ** Updated.");
+ }
+ else
+ Put_message("List successfully updated.");
+}
+
/* Function Name: UpdateList
* Description: updates the information on a list.
* Arguments: argc, argv - name of list in argv[1].
int argc;
char **argv;
{
- char buf[BUFSIZ];
- struct qelem *top, *list;
- int status;
- Bool one_list, update_it;
+ struct qelem *top;
+
+ top = GetListInfo(LIST, argv[1], (char *) NULL);
+ QueryLoop(top, NullPrint, RealUpdateList, "Update the list");
- list = top = GetListInfo(LIST, argv[1], (char *) NULL);
-
- one_list = (QueueCount(top) == 1);
- while (list != NULL) {
- char **up_args, **info = (char **) list->q_data;
- if (one_list)
- update_it = TRUE;
- else {
- sprintf(buf, "Update the list %s (y/n/q) ? ",info[L_NAME]);
- switch (YesNoQuitQuestion(buf, FALSE)) {
- case TRUE:
- update_it = TRUE;
- break;
- case FALSE:
- update_it = FALSE;
- break;
- default:
- Put_message("Aborting...");
- FreeQueue(top);
- return(DM_NORMAL);
- }
- }
- if (update_it) {
- up_args = AskListInfo(info, TRUE);
- if ( (status = sms_query("update_list", CountArgs(up_args),
- up_args, Scream, (char *) NULL)) != 0) {
- com_err(program_name, status, " in UpdateList.");
- Put_message("List Not Updated.");
- }
- }
- list = list->q_forw;
- }
FreeQueue(top);
return(DM_NORMAL);
}
/* Function Name: AddList
* Description:
* Arguments: argc, argv - name of list in argv[1].
- * Returns: DM Status code.
+ * Returns: SUB_ERROR if list not created.
*/
/* ARGSUSED */
char **argv;
{
static char *info[MAX_ARGS_SIZE], **add_args;
- int status;
+ int status, ret_code = SUB_NORMAL;
- if (!ValidName(argv[1])) /* Check if list name is valid. */
- return(DM_QUIT);
-
status = sms_query("get_list_info", 1, argv + 1, NullFunc,
(char *) NULL);
if (status != SMS_NO_MATCH) {
- if (status == 0)
+ if (status == SMS_SUCCESS)
Put_message("This list already exists.");
else
com_err(program_name, status, " in AddList.");
- return(DM_QUIT);
+ return(SUB_ERROR);
}
add_args = AskListInfo(SetDefaults(info,argv[1]), FALSE);
if ( (status = sms_query("add_list", CountArgs(add_args), add_args,
- Scream, (char *) NULL)) != 0) {
+ Scream, (char *) NULL)) != SMS_SUCCESS) {
com_err(program_name, status, " in AddList.");
Put_message("List Not Created.");
+ ret_code = SUB_ERROR;
}
FreeInfo(info);
- return(DM_NORMAL);
+ return(ret_code);
}
/* Function Name: Instructions
ListHelp()
{
static char * message[] = {
- "Listmaint handles the creation, deletion, and updating of lists.\n",
- "A list can be a mailing list, a group list, or both.\n",
+ "Listmaint handles the creation, deletion, and updating of lists.",
+ "A list can be a mailing list, a group list, or both.",
"The concept behind lists is that a list has an owner",
- "- administrator - and members.\n",
- "The administrator of a list may be another list.\n",
+ "- administrator - and members.",
+ "The administrator of a list may be another list.",
"The members of a list can be users (login names), other lists,",
- "or address strings.\n",
+ "or address strings.",
"You can use certain keys to do the following:",
- " Refresh the screen - Type ctrl-L.\n",
- " Escape from a function - Type ctrl-C.\n",
- " Suspend the program (temporarily) - Type ctrl-Z.\n",
+ " Refresh the screen - Type ctrl-L.",
+ " Escape from a function - Type ctrl-C.",
+ " Suspend the program (temporarily) - Type ctrl-Z.",
NULL,
};
{
char temp_buf[BUFSIZ];
char *list_name = argv[1];
+
+ if (!ValidName(list_name))
+ return(DM_QUIT);
if (*argv[0] == 'a') { /* add_list */
- /* actually, AddList no longer returns DM_QUIT.
- * Maybe later, when com_err no longer blows out there.
- */
- if (AddList(argc, argv) == DM_QUIT)
+ if (AddList(argc, argv) == SUB_ERROR)
return(DM_QUIT);
(void) sprintf(temp_buf, "List '%s' created. Do you want to %s",
- list_name, "change its membership?");
+ list_name, "change its membership (y/n)? ");
if (YesNoQuestion(temp_buf, TRUE) != TRUE )
return(DM_QUIT);
}
- else if (!ValidName(list_name)) {
- (void) sprintf(temp_buf, "Bad list: '%s'", list_name);
- Put_message(temp_buf);
- return(DM_QUIT);
- }
(void) sprintf(temp_buf,
"Change/Display membership of '%s'", list_name);
{
char temp_buf[BUFSIZ];
register int status;
+ char * args[10];
+
+ args[0] = current_list;
+ args[1] = NULL;
found_some = FALSE;
- if ( (status = sms_query("get_members_of_list", 1, current_list,
+ if ( (status = sms_query("get_members_of_list", CountArgs(args), args,
PrintByType, type)) != 0)
- com_err(program_name, status, " in ListMembersByType\n");
+ com_err(program_name, status, " in ListMembersByType");
if (!found_some) {
if (type == NULL)
Put_message("List is empty (no members).");
com_err(program_name, status, NULL);
return(SUB_ERROR);
}
- PromptWithDefault("Type of member (USER, LIST, or STRING)",
- ret_buf, BUFSIZ, "USER");
+ PromptWithDefault("Type of member (user, list, or string)",
+ ret_buf, BUFSIZ, "user");
ret_argv[LM_TYPE]= Strsave(ret_buf);
- sprintf(temp_buf,"Name of member to %s", action);
+ sprintf(temp_buf,"Name of %s to %s", ret_argv[LM_TYPE], action);
PromptWithDefault(temp_buf, ret_buf, BUFSIZ, user);
ret_argv[LM_MEMBER] = Strsave(ret_buf);
- ret_argv[LM_END] = NULL; /* null terminat this list. */
+ ret_argv[LM_END] = NULL; /* NULL terminate this list. */
+
+ if (!ValidName( ret_argv[LM_MEMBER] ) ) {
+ FreeInfo(ret_argv);
+ return(SUB_ERROR);
+ }
return(SUB_NORMAL);
}
int
AddMember()
{
- char *args[10];
+ char *args[10], temp_buf[BUFSIZ];
register int status;
- if( GetMemberInfo("add", args) == SUB_ERROR )
+ if ( GetMemberInfo("add", args) == SUB_ERROR )
return(DM_NORMAL);
- if (status = sms_query("add_member_to_list", CountArgs(args), args,
- Scream, NULL) != 0)
- com_err(program_name, status, " in AddMember\n");
+ if ( (status = sms_query("add_member_to_list", CountArgs(args), args,
+ Scream, NULL)) != SMS_SUCCESS) {
+ if (status == SMS_EXISTS) {
+ sprintf(temp_buf, "The %s %s is already a member of LIST %s.",
+ args[LM_TYPE], args[LM_MEMBER], args[LM_LIST]);
+ Put_message(temp_buf);
+ }
+ else
+ com_err(program_name, status, " in AddMember");
+ }
FreeInfo(args);
- return (DM_NORMAL);
+ return(DM_NORMAL);
}
/* Function Name: DeleteMember
if (Confirm("Are you sure you want to delete this member?") ) {
if (status = sms_query("delete_member_from_list", CountArgs(args),
args, Scream, NULL))
- com_err(program_name, status, " in DeleteMember\n");
+ com_err(program_name, status, " in DeleteMember");
else
Put_message("Deletion Completed.");
}
return(DM_NORMAL);
}
-
/* Function Name: InterRemoveItemFromLists
* Description: This function allows interactive removal of an item
* (user, string, list) for all list that it is on.
* Arguments: none.
* Returns: DM_NORMAL.
+ * NOTES: QueryLoop() does not work here because info does not have
+ * enough information in it to delete the member from the list.
*/
int
InterRemoveItemFromLists()
{
register int status;
- char type[BUFSIZ], name[BUFSIZ], *args[10];
+ char type[BUFSIZ], name[BUFSIZ], *args[10], buf[BUFSIZ];
struct qelem *top, *elem;
- if ( !(PromptWithDefault("Type of member (user, list, string)? ", type,
+ if ( !(PromptWithDefault("Type of member (user, list, string)", type,
BUFSIZ, "user")) )
return(DM_NORMAL);
- if ( !(PromptWithDefault("Name of member? ", name, BUFSIZ, user)) ) {
+ sprintf(buf, "Name of %s", type);
+ if ( !(PromptWithDefault(buf, name, BUFSIZ, user)) ) {
return(DM_NORMAL);
}
+ if (!ValidName(name))
+ return(DM_NORMAL);
+
top = elem = GetListInfo(GLOM, type, name);
while(elem != NULL) {
- char line[BUFSIZ], buf[BUFSIZ];
+ char line[BUFSIZ];
char ** info = (char **) elem->q_data;
- sprintf(line, "Delete %s from the list \"%s\" [Y/N/Q]? ", name,
- info[0]);
- PromptWithDefault(line, buf, BUFSIZ, "N" );
- if (buf[0] == 'y' || buf[0] == 'Y') {
+ sprintf(line, "Delete %s %s from the list \"%s\" (y/n/q)? ", type,
+ name, info[GLOM_NAME]);
+ switch (YesNoQuitQuestion(line, FALSE)) {
+ case TRUE:
Put_message("deleting...");
args[DM_LIST] = info[GLOM_NAME];
args[DM_TYPE] = type;
args[DM_MEMBER] = name;
if ( (status = sms_query("delete_member_from_list", 3, args,
Scream, (char *) NULL)) != 0)
- /* should check to delete list. */
+ /* should probabally check to delete list. */
com_err(program_name, status, " in delete_member");
- }
- else if (buf[0] == 'q' || buf[0] == 'Q') {
- Put_message("Quitting.");
break;
+ case FALSE:
+ break;
+ default:
+ Put_message("Aborting...");
+ FreeQueue(top);
+ return(DM_NORMAL);
}
elem = elem->q_forw;
}
int
ListByMember()
{
- char buf[BUFSIZ], *type, *name, **info;
+ char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name, **info;
Bool maillist, group;
struct qelem *top, *elem;
- if ( !(PromptWithDefault("Type of member (user, list, string)? ", buf,
+ if ( !(PromptWithDefault("Type of member (user, list, string)", buf,
BUFSIZ, "user")) )
return(DM_NORMAL);
- sprintf(buf, "R%s", buf); /* What we really want is a recursive search */
- type = Strsave(buf);
-
- if ( !(PromptWithDefault("Name of member? ", buf, BUFSIZ, user)) ) {
+ /* What we really want is a recursive search */
+ sprintf(temp_buf, "R%s", buf);
+ type = Strsave(temp_buf);
+
+ sprintf(temp_buf, "Name of %s", buf);
+ if ( !(PromptWithDefault(temp_buf, buf, BUFSIZ, user)) ) {
free(type);
return(DM_NORMAL);
}
int
ListByAdministrator()
{
- char buf[BUFSIZ], *type, *name;
- struct qelem *top, *elem;
+ char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name;
+ struct qelem *top;
- if ( !(PromptWithDefault("Type of member (user, list, string)? ", buf,
+ if ( !(PromptWithDefault("Type of member (user, list, string)", buf,
BUFSIZ, "user")) )
return(DM_NORMAL);
- if ( YesNoQuestion("Do you want a recursive search?",TRUE) == 1 )
- sprintf(buf,"R%s",buf); /* "USER" to "RUSER" etc. */
- type = Strsave(buf);
+ if ( YesNoQuestion("Do you want a recursive search (y/n)", TRUE) == 1 ) {
+ sprintf(temp_buf, "R%s", buf); /* "USER" to "RUSER" etc. */
+ type = Strsave(temp_buf);
+ }
+ else
+ type = Strsave(buf);
- if ( !(PromptWithDefault("Name of member? ", buf, BUFSIZ, user)) ) {
+ sprintf(temp_buf, "Name of %s", buf);
+ if ( !(PromptWithDefault(temp_buf, buf, BUFSIZ, user)) ) {
free(type);
return(DM_NORMAL);
}
name = Strsave(buf);
- top = elem = GetListInfo(ACL_USE, type, name);
- while (elem != NULL) {
- char ** info = (char **) elem->q_data;
- sprintf(buf, "Type: %s,\tName: %s", info[0], info[1]);
- Put_message(buf);
- elem = elem->q_forw;
- }
+ top = GetListInfo(ACL_USE, type, name);
+ Loop(top, PrintListAcl);
+
FreeQueue(top);
return (DM_NORMAL);
}
TRUE) == TRUE )
if (status = sms_query("qualified_get_lists", 5, args,
Print, (char *) NULL) != 0)
- com_err(program_name, status, " in ListAllGroups\n");
+ com_err(program_name, status, " in ListAllGroups");
return (DM_NORMAL);
}
TRUE) == TRUE )
if (status = sms_query("qualified_get_lists", 5, args,
Print, (char *) NULL) != 0)
- com_err(program_name, status, " in ListAllGroups\n");
+ com_err(program_name, status, " in ListAllGroups");
return (DM_NORMAL);
}
TRUE) == TRUE )
if (status = sms_query("qualified_get_lists", 5, args,
Print, (char *) NULL) != 0)
- com_err(program_name, status, " in ListAllGroups\n");
+ com_err(program_name, status, " in ListAllGroups");
return (DM_NORMAL);
}
-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
#endif lint
extern Menu sms_top_menu;
-static void ErrorExit(), Usage(), SignalHandler();
+#ifndef DEBUG
+static void SignalHandler();
+#endif DEBUG
+
+static void ErrorExit(), Usage();
char *getlogin();
uid_t getuid();
struct passwd *getpwuid();
exit(1);
}
+#ifndef DEBUG
/* Function Name: SignalHandler
* Description: This function cleans up from a signal interrupt.
* Arguments: none.
sms_disconnect();
exit(1);
}
+#endif DEBUG
-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
#endif lint
SIMPLEFUNC("member",
"List all lists to which a given member belongs",
ListByMember),
- SIMPLEFUNC("administrator",
- "List all lists which a given user can administer",
+ SIMPLEFUNC("admin",
+ "List all items which a given member can administer",
ListByAdministrator),
SIMPLEFUNC("groups", "List all lists which are groups",
ListAllGroups),
ListmaintMemberMenuEntry,
ListmaintMemberMenuExit,
NULL,
- 6,
+ 7,
{
- SIMPLEFUNC("add", "Add a member to the list",
+ SIMPLEFUNC("add", "Add a member to this list",
AddMember),
- SIMPLEFUNC("delete", "Delete a member from the list",
+ SIMPLEFUNC("remove", "Remove a member from this list",
DeleteMember),
- SIMPLEFUNC("all", "Show the members of the list",
+ SIMPLEFUNC("all", "Show the members of this list",
ListAllMembers),
SIMPLEFUNC("user", "Show the members of type USER",
ListUserMembers),
SIMPLEFUNC("list", "Show the members of type LIST",
ListListMembers),
SIMPLEFUNC("string", "Show the members of type STRING",
- ListStringMembers)
+ ListStringMembers),
+ SIMPLEFUNC("verbose", "Toggle Verbosity of Delete",
+ ToggleVerboseMode)
}
};
} },
{ NULLFUNC, &listmaint_member_menu, 2, {
{"add", "Create new List"},
- {"list name", "Name of list (do not use wildcards): "}
+ {"list name", "Name of list: "}
} },
{ UpdateList, NULLMENU, 2, {
{"update", "Update characteristics of a list"},
} },
{ NULLFUNC, &listmaint_member_menu, 2, {
{"members", "Change/Display the membership of a list"},
- {"list name", "Name of list (do not use wildcards): "}
+ {"list name", "Name of list: "}
} },
SIMPLEFUNC("query_remove",
"Interactively remove an item from all lists",
-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
#endif lint
-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
#endif lint
#define LOGIN 0
#define UID 1
-#define NAME 2
+#define BY_NAME 2
#define QUOTA 3
#define CLASS 4
{
char temp_buf[BUFSIZ], *newname;
- sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[NAME]);
+ sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[U_NAME]);
Put_message(temp_buf);
if (name) {
/* Function Name: GetUserInfo
* Description: Stores the user information in a queue.
* Arguments: type - type of field given to get info, one of:
- * LOGIN, UID, NAME, CLASS.
+ * LOGIN, UID, BY_NAME, CLASS.
* name1 - name of thing specified by type (wildcards okay)
* name2 - other name, only used in get user by first and last.
* (wildcards okay).
return (NULL);
}
break;
- case NAME:
+ case BY_NAME:
args[0] = name1;
args[1] = name2;
if ( (status = sms_query("get_user_by_name", 1, args,
struct qelem *top, *elem;
char buf;
- elem = top = GetUserInfo(NAME, argv[1], argv[2]);
+ elem = top = GetUserInfo(BY_NAME, argv[1], argv[2]);
if (!PromptWithDefault("Print full information, or just the names (F/N)?",
&buf, 1, "F"))
-#ifndef lint
+#if (!defined(lint) && !defined(SABER))
static char rcsid_module_c[] = "$Header$";
#endif lint
char ** argv;
char * data;
{
- char ** info = (char **) malloc( MAX_ARGS_SIZE * sizeof(char *) );
+ char ** info = (char **) malloc( MAX_ARGS_SIZE * sizeof(char *));
struct qelem ** old_elem = (struct qelem **) data;
struct qelem * new_elem = (struct qelem *) malloc (sizeof (struct qelem));
int count;
+ if ( (new_elem == (struct qelem *) NULL) || (info == (char **) NULL) ) {
+ Put_message("Could Not allocate more memory.");
+ FreeQueue(*old_elem);
+ *old_elem = (struct qelem *) NULL;
+ return(SMS_ABORT);
+ }
+
for (count = 0; count < argc; count++)
info[count] = Strsave(argv[count]);
info[count] = NULL; /* NULL terminate this sucker. */
Put_message("Please use a non-empty name.");
else if (index(s, ' '))
Put_message("You cannot use space (' ') in this name.");
+ else if (index(s, WILDCARD))
+ Put_message("Wildcards not accepted here.");
else
return TRUE;
return FALSE;
return(DM_NORMAL);
}
+/* Function Name: Loop
+ * Description: This function goes through the entire queue, and
+ * and executes the given function on each element.
+ * Arguments: elem - top element of the queue.
+ * func - the function to execute.
+ * Returns: none.
+ */
+
+void
+Loop(elem, func)
+FVoid func;
+struct qelem * elem;
+{
+ while (elem != NULL) {
+ char ** info = (char **) elem->q_data;
+ (*func) (info);
+ elem = elem->q_forw;
+ }
+}
+
+
+/* Function Name: QueryLoop
+ * Description: This functions loops through a queue containing
+ * information about some item that we want to perform
+ * an operation on, and then calls the correct routine
+ * perform that operation.
+ * Arguments: top - top of the queue of information.
+ * print_func - print function.
+ * op_function - operation to be performed.
+ * query_string - string the prompts the user whether or not
+ * to perform this operation.
+ * Returns: none.
+ * NOTES:
+ * print_opt - should expect one arguent, the info array
+ * of char *'s.
+ * is expected to return the name of the item.
+ * op_func - should expect two arguments.
+ * 1) the info array of char *'s.
+ * 2) a boolean the is true if there only
+ * one item in this queue, used for delete
+ * confirmation.
+ * query_string - this should be of such a form that when the
+ * name of the object and '(y/n/q) ?' are appended
+ * then it should still make sense, an example is
+ * "Delete the list"
+ */
+
+void
+QueryLoop(elem, print_func, op_func, query_string)
+struct qelem *elem;
+FVoid op_func;
+FCharStar print_func;
+char * query_string;
+{
+ Bool one_item;
+ char temp_buf[BUFSIZ], *name;
+
+ one_item = (QueueCount(elem) == 1);
+ while (elem != NULL) {
+ char **info = (char **) elem->q_data;
+
+ if (one_item)
+ (*op_func) (info, one_item);
+ else {
+ name = (*print_func) (info); /* call print function. */
+ sprintf(temp_buf,"%s %s (y/n/q) ?", query_string, name);
+ switch(YesNoQuitQuestion(temp_buf, FALSE)) {
+ case TRUE:
+ (*op_func) (info, one_item);
+ break;
+ case FALSE:
+ break;
+ default: /* Quit. */
+ Put_message("Aborting...");
+ return;
+ }
+ }
+ elem = elem->q_forw;
+ }
+}
+
+/* Function Name: NullPrint
+ * Description: print function that returns nothing.
+ * Arguments: info - a pointer to the info array - Not used.
+ * Returns: none.
+ */
+
+char *
+NullPrint(info)
+char ** info;
+{
+ return(info[NAME]);
+}
+
/*
* Local Variables:
* mode: c
#include "mit-copyright.h"
+#define NAME 0
+
+/* get_acl_use */
+
+#define ACL_TYPE 0
+#define ACL_NAME 1
+#define ACL_END 2
+
/* alias queries. */
-#define ALIAS_NAME 0
+#define ALIAS_NAME NAME
#define ALIAS_TYPE 1
#define ALIAS_TRANS 2
#define ALIAS_END 3
/* Cluster information queries */
-#define C_NAME 0
+#define C_NAME NAME
#define C_DESCRIPT 1
#define C_LOCATION 2
#define C_MODTIME 3
/* Cluster Data information queries */
-#define CD_NAME 0
+#define CD_NAME NAME
#define CD_LABEL 1
#define CD_DATA 2
#define CD_END 3
/* Filesys queries (attachmaint) */
-#define FS_NAME 0
+#define FS_NAME NAME
#define FS_TYPE 1
#define FS_MACHINE 2
#define FS_PACK 3
/* Get List Of Member queries. */
-#define GLOM_NAME 0
+#define GLOM_NAME NAME
#define GLOM_ACTIVE 1
#define GLOM_PUBLIC 2
#define GLOM_HIDDEN 3
/* General List information Queries. */
-#define L_NAME 0
+#define L_NAME NAME
#define L_ACTIVE 1
#define L_PUBLIC 2
#define L_HIDDEN 3
#define L_ACL_NAME 8
#define L_DESC 9
#define L_MODTIME 10
-#define L_MODBY 11
+#define L_MODBY 11
#define L_MODWITH 12
#define L_END 13
/* Machine information queries */
-#define M_NAME 0
+#define M_NAME NAME
#define M_TYPE 1
#define M_MODTIME 2
#define M_MODBY 3
/* NFS phys. queries. */
-#define NFS_NAME 0
+#define NFS_NAME NAME
#define NFS_DIR 1
#define NFS_DEVICE 2
#define NFS_STATUS 3
/* PO box infomarion queries */
-#define PO_NAME 0
+#define PO_NAME NAME
#define PO_TYPE 1
#define PO_MACHINE 2
#define PO_BOX 3
/* User Information queries */
-#define U_NAME 0
+#define U_NAME NAME
#define U_NEWNAME 1
#define U_UID 2
#define U_SHELL 3