]> andersk Git - moira.git/commitdiff
This is an intermidiate version that has attach.c and cluster.c pretty well
authorkit <kit>
Mon, 27 Jun 1988 16:11:20 +0000 (16:11 +0000)
committerkit <kit>
Mon, 27 Jun 1988 16:11:20 +0000 (16:11 +0000)
debugged, the rest is still to be done.

clients/moira/attach.c
clients/moira/cluster.c
clients/moira/delete.c
clients/moira/lists.c
clients/moira/main.c
clients/moira/menus.c
clients/moira/nfs.c
clients/moira/user.c
clients/moira/utils.c

index 58522cd18b6d383c4961d42db5b680700f3ce9e8..8acac5f0f7349f04fd30bfc68447d9c58a076927 100644 (file)
 #define GROUP        2
 #define ALIAS        3
 
+#define DEFAULT_TYPE     ("NFS")
+#define DEFAULT_MACHINE  DEFAULT_NONE
+#define DEFAULT_PACK     DEFAULT_NONE
+#define DEFAULT_M_POINT  DEFAULT_NONE
+#define DEFAULT_ACCESS   ("r")
+#define DEFAULT_COMMENTS DEFAULT_COMMENT
+#define DEFAULT_OWNER    (user)
+#define DEFAULT_OWNERS   (user)
+#define DEFAULT_CREATE   DEFAULT_YES
+#define DEFAULT_L_TYPE   ("HOMEDIR")
+
+/*     Function Name: SetDefaults
+ *     Description: sets the default values for filesystem additions.
+ *     Arguments: info - an array of char pointers to recieve defaults. 
+ *     Returns: char ** (this array, now filled).
+ */
+
+static char ** 
+SetDefaults(info, name)
+char ** info;
+char * name;
+{
+    info[FS_NAME] =     Strsave(name);
+    info[FS_TYPE] =     Strsave(DEFAULT_TYPE);
+    info[FS_MACHINE] =  Strsave(DEFAULT_MACHINE);
+    info[FS_PACK] =     Strsave(DEFAULT_PACK);
+    info[FS_M_POINT] =  Strsave(DEFAULT_M_POINT);
+    info[FS_ACCESS] =   Strsave(DEFAULT_ACCESS);
+    info[FS_COMMENTS] = Strsave(DEFAULT_COMMENTS);
+    info[FS_OWNER] =    Strsave(DEFAULT_OWNER);
+    info[FS_OWNERS] =   Strsave(DEFAULT_OWNERS);
+    info[FS_CREATE] =   Strsave(DEFAULT_CREATE);
+    info[FS_L_TYPE] =   Strsave(DEFAULT_L_TYPE);
+    info[FS_MODTIME] = info[FS_MODBY] = info[FS_MODWITH] = info[FS_END] = NULL;
+    return(info);
+}
+
 /*     Function Name: GetFSInfo
  *     Description: Stores the info in a queue.
  *     Arguments: type - type of information to get.
@@ -54,7 +91,7 @@ char *name;
 {
     int stat;
     struct qelem * elem = NULL;
-    char * args[2];
+    char * args[5];
 
     switch (type) {
     case LABEL:
@@ -79,9 +116,10 @@ char *name;
        }
        break;
     case ALIAS:
-       args[0] = name;
-       args[1] = FS_ALIAS_TYPE;
-       if ( (stat = sms_query("get_alias", 2, args, StoreInfo, &elem)) != 0) {
+       args[ALIAS_NAME] = name;
+       args[ALIAS_TYPE] = FS_ALIAS_TYPE;
+       args[ALIAS_TRANS] = "*";
+       if ( (stat = sms_query("get_alias", 3, args, StoreInfo, &elem)) != 0) {
            com_err(program_name, stat, " in get_alias.");
            return(NULL);
        }
@@ -90,6 +128,23 @@ char *name;
     return(QueueTop(elem));
 }
 
+/*     Function Name: PrintFSAlias
+ *     Description: Prints a filesystem alias
+ *     Arguments: info - an array contains the strings of info.
+ *     Returns: none.
+ */
+
+static void
+PrintFSAlias(info)
+char ** info;
+{
+    char buf[BUFSIZ];
+
+    sprintf(buf,"Alias: %-25s Filesystem: %s",info[ALIAS_NAME], 
+           info[ALIAS_TRANS]);
+    Put_message(buf);
+}
+
 /*     Function Name: PrintFSInfo
  *     Description: Prints the filesystem information.
  *     Arguments: info - a pointer to the filesystem information.
@@ -101,50 +156,29 @@ PrintFSInfo(info)
 char ** info;
 {
     char print_buf[BUFSIZ];
-    sprintf(print_buf,"Information about filesystem: %s", info[FS_NAME]);
+    FORMFEED;
+    sprintf(print_buf,"%20s Filesystem: %s", 
+           " ",info[FS_NAME]);
     Put_message(print_buf);
-    sprintf(print_buf,"Type: %s\t\tMachine: %s\t\tPackname: %s",info[FS_TYPE],
-           info[FS_MACHINE], info[FS_PACK]);
+    sprintf(print_buf,"Type: %-40s Machine: %-15s",
+           info[FS_TYPE], info[FS_MACHINE]);
     Put_message(print_buf);
-    sprintf(print_buf,"Mountpoint %s\t\t Default Access: %s",info[FS_M_POINT],
-           info[FS_ACCESS]);
+    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]);
     Put_message(print_buf);
-    sprintf(print_buf, "User Ownership: %s,\t\tGroup Ownership:\t\t%s",
+    sprintf(print_buf, "User Ownership: %-30s Group Ownership: %s",
            info[FS_OWNER], info[FS_OWNERS]);
     Put_message(print_buf);
-    sprintf(print_buf, "Auto Create %s\t\tLocker Type: %s",info[FS_CREATE], 
+    sprintf(print_buf, "Auto Create %-34s Locker Type: %s",info[FS_CREATE], 
            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, "Last Modified at %s, by %s with %s",
+           info[FS_MODTIME], info[FS_MODBY], info[FS_MODWITH]);
     Put_message(print_buf);
 }
 
-/*     Function Name: PrintAllFSInfo
- *     Description: Prints all infomation about a filesystem, stored in
- *                   a queue.
- *     Arguments: elem - a pointer to the first elem in the queue.
- *     Returns: none.
- */
-
-void
-PrintAllFSInfo(elem)
-struct qelem * elem;
-{
-/* 
- * Not nescessary, but makes it clear that we are not changing this value.
- */
-    struct qelem * local = elem;       
-                               
-    while(local != NULL) {
-       char ** info = (char **) local->q_data;
-       PrintFSInfo(info);
-       local = local->q_forw;
-    }
-}
-
 /*     Function Name: AskFSInfo.
  *     Description: This function askes the user for information about a 
  *                   machine and saves it into a structure.
@@ -161,25 +195,29 @@ Bool name;
 {
     char temp_buf[BUFSIZ], *newname;
 
-    sprintf(temp_buf, "\nChanging Attributes of user %s.\n", info[FS_NAME]);
+    sprintf(temp_buf, "\nChanging Attributes of filesystem: %s.\n", 
+           info[FS_NAME]);
     Put_message(temp_buf);
 
     if (name) {
        newname = Strsave(info[FS_NAME]);
-       GetValueFromUser("The new login 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]);
+    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("Commants about this Filesystem:", &info[FS_COMMENTS]);
+    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_COMMENTS]);
+                    &info[FS_CREATE]);
     GetValueFromUser("Filesystem's lockertype:", &info[FS_L_TYPE]);
 
     FreeAndClear(&info[FS_MODTIME], TRUE);
@@ -206,11 +244,15 @@ GetFS(argc, argv)
 int argc;
 char **argv;
 {
-    struct qelem *elem;
+    struct qelem *top, *elem;
 
-    elem = GetFSInfo(LABEL, argv[1]); /* get info. */
-    PrintAllFSInfo(elem);      /* print it all. */
-    FreeQueue(elem);           /* clean the queue. */
+    top = elem = GetFSInfo(LABEL, argv[1]); /* get info. */
+    while(elem != NULL) {
+       char ** info = (char **) elem->q_data;
+       PrintFSInfo(info);
+       elem = elem->q_forw;
+    }
+    FreeQueue(top);            /* clean the queue. */
     return (DM_NORMAL);
 }
 
@@ -246,10 +288,10 @@ char **argv;
     while (temp_elem != NULL) {
        char **info = (char **) temp_elem->q_data;
        
-       if (one_filsys) {
+       if (!one_filsys) {
            PrintFSInfo(info);
        
-           answer = YesNoQuitQuestion("\nDelete this filesys?", FALSE); 
+           answer = YesNoQuitQuestion("\nDelete this filesystem?", FALSE); 
            switch(answer) {
            case TRUE:
                delete = TRUE;
@@ -312,10 +354,8 @@ int argc;
     one_filsys = (QueueCount(elem) == 1);
     while (temp_elem != NULL) {
        char ** info = (char **) temp_elem->q_data;
-       if (one_filsys) {
-           sprintf(buf, "%s %s %s (y/n/q)? ", "Would you like to change the",
-                   "information about the filesystem:", 
-                   info[FS_NAME]);
+       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) {
@@ -338,7 +378,7 @@ int argc;
            char ** args = AskFSInfo(info, TRUE);
            if ( (stat = sms_query("update_filesys", CountArgs(args), 
                                   args, NullFunc, NULL)) != 0)
-               com_err(program_name, stat, " in filesystem not updated");
+               com_err(program_name, stat, ", filesystem not updated");
            else
                Put_message("filesystem sucessfully updated.");
        }
@@ -361,7 +401,7 @@ char **argv;
 int argc;
 {
     char *info[MAX_ARGS_SIZE], **args;
-    int stat, count;
+    int stat;
 
     if ( !ValidName(argv[1]) )
        return(DM_NORMAL);
@@ -375,12 +415,10 @@ int argc;
        return(DM_NORMAL);
     } 
 
-    for (count = 0; count < 100; count++)
-       info[count] = NULL;
-    args = AskFSInfo(info, FALSE );
+    args = AskFSInfo(SetDefaults(info, argv[1]), FALSE );
 
-    if (stat = sms_query("add_filesys", CountArgs(args), args, 
-                        NullFunc, NULL) != 0)
+    if ( (stat = sms_query("add_filesys", CountArgs(args), args, 
+                        NullFunc, NULL)) != 0)
        com_err(program_name, stat, " in AddFS");
 
     FreeInfo(info);
@@ -403,16 +441,14 @@ GetFSAlias(argc, argv)
 int argc;
 char **argv;
 {
-    char **info, buf[BUFSIZ];
     struct qelem *top, *elem;
 
     top = elem = GetFSInfo(ALIAS, argv[1]);
 
+    Put_message(" ");          /* blank line. */
     while (elem != NULL) {
-       info = (char **) elem->q_data;
-       sprintf(buf,"Alias: %s\tFilesystem: %s",info[ALIAS_NAME], 
-               info[ALIAS_TRANS]);
-       Put_message(buf);
+       char **info = (char **) elem->q_data;
+       PrintFSAlias(info);
        elem = elem->q_forw;
     }
 
@@ -445,17 +481,18 @@ char **argv;
 
     args[ALIAS_NAME] = Strsave(argv[1]);
     args[ALIAS_TYPE] = Strsave(FS_ALIAS_TYPE);
+    args[ALIAS_TRANS] = Strsave("*");
 
 /*
  * Check to see if this alias already exists in the database, if so then
  * print out values, free memory used and then exit.
  */
 
-    if ( (stat = sms_query("get_alias", 2, args, StoreInfo, &elem)) == 0) {
-       top = elem;
+    if ( (stat = sms_query("get_alias", 3, args, StoreInfo, &elem)) == 0) {
+       top = elem = QueueTop(elem);
        while (elem != NULL) {
            info = (char **) elem->q_data;          
-           sprintf(buf,"The alias: %s\tcurrently describes the filesystem %s",
+           sprintf(buf,"The alias: %s currently describes the filesystem %s",
                    info[ALIAS_NAME], info[ALIAS_TRANS]);
            Put_message(buf);
            elem = elem->q_forw;
@@ -494,7 +531,7 @@ int argc;
 char **argv;
 {
     register int stat;
-    char buf[BUFSIZ];
+    char *ptr;
     struct qelem *elem, *top;
     Bool one_alias, delete;
 
@@ -515,15 +552,13 @@ char **argv;
     while (elem != NULL) {
        char **info = (char **) elem->q_data;
 
-       if (one_alias) {
+       Put_message(" ");       /* blank line. */
+       PrintFSAlias(info);
+       if (!one_alias) {
            int answer;
-
-           sprintf(buf, "%s %s for the filesystem %s? (y/n)",
-                   "Confirm that you want to delete\n the alias",
-                   info[ALIAS_NAME], info[ALIAS_TRANS]);
-           Put_message(buf);
            
-           answer = YesNoQuitQuestion(buf, FALSE); 
+           ptr = "Do you want to delete this alias (y/n/q)? ",
+           answer = YesNoQuitQuestion(ptr, FALSE); 
            switch(answer) {
            case TRUE:
                delete = TRUE;
@@ -538,17 +573,16 @@ char **argv;
            }
        }
        else {
-           sprintf(buf, "Are you sure that you want to delete %s",
-                   "this filesystem alias?");
-           delete = Confirm(buf);
+           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_filesys", 1,
-                                    &info[ALIAS_NAME], Scream, NULL)) != 0)
+           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.");
@@ -572,16 +606,15 @@ int
 AttachHelp()
 {
     static char *message[] = {
-       "These are the options:\n",
-       "get - get information about a filesystem.",
-       "add - add a new filesystem to the data base.",
-       "update - update the information in the database on a filesystem.",
-       "delete - delete a filesystem from the database.\n",
-       "check - check information about association of a name and a filesys.",
-       "alias - associate a name with a filsystem.",
-       "unalias - disassociate a name with a filesystem.",
-       "\twhere a name is: user, group, or project\n",
-       "verbose - toggle the request for delete confirmation\n",
+      "These are the options:\n\n",
+      "get - get information about a filesystem.\n",
+      "add - add a new filesystem to the data base.\n",
+      "update - update the information in the database on a filesystem.\n",
+      "delete - delete a filesystem from the database.\n",
+      "check - check information about association of a name and a filesys.\n",
+      "alias - associate a name with a filsystem.\n",
+      "unalias - disassociate a name with a filesystem.\n",
+      "verbose - toggle the request for delete confirmation.\n",
        NULL,
     };
 
index 7452c89c7025e52a9fb36dd471da4b91c21e5ba7..adf9ad3cb09f88e39e0aa16df6fddd0159b52bcb 100644 (file)
 #define DATA     2
 #define MAP      3
 
+#define M_DEFAULT_TYPE     DEFAULT_NONE
+
+#define C_DEFAULT_DESCRIPT DEFAULT_NONE
+#define C_DEFAULT_LOCATION DEFAULT_NONE
+
+#define CD_DEFAULT_LABEL   DEFAULT_NONE
+#define CD_DEFAULT_DATA    DEFAULT_NONE
+
+/* -------------------- Set Defaults -------------------- */
+
+/*     Function Name: SetMachineDefaults
+ *     Description: sets machine defaults.
+ *     Arguments: info - an array to put the defaults into.
+ *                 name - Canonacalized name of the machine.
+ *     Returns: info - the array.
+ */
+
+char **
+SetMachineDefaults(info, name)
+char ** info, *name;
+{
+    info[M_NAME] = Strsave(name);
+    info[M_TYPE] = Strsave(M_DEFAULT_TYPE);
+    info[M_MODBY] = info[M_MODTIME] = info[M_MODWITH] = info[M_END] = NULL;
+    return(info);
+}
+
+/*     Function Name: SetClusterDefaults
+ *     Description: sets Cluster defaults.
+ *     Arguments: info - an array to put the defaults into.
+ *                 name - name of the Cluster.
+ *     Returns: info - the array.
+ */
+
+char **
+SetClusterDefaults(info, name)
+char ** info, *name;
+{
+    info[C_NAME] = Strsave(name);
+    info[C_DESCRIPT] = Strsave(C_DEFAULT_DESCRIPT);
+    info[C_LOCATION] = Strsave(C_DEFAULT_LOCATION);
+    info[C_MODBY] = info[C_MODTIME] = info[C_MODWITH] = info[C_END] = NULL;
+    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.
@@ -51,7 +117,8 @@ char ** info;
 {
     char buf[BUFSIZ];
 
-    sprintf(buf, "Machine: %s\tType: %s", info[M_NAME], info[M_TYPE]);
+    Put_message("");
+    sprintf(buf, "Machine: %-30s Type: %s", info[M_NAME], info[M_TYPE]);
     Put_message(buf);
     sprintf(buf, "Last Modified at %s, by %s with %s",info[M_MODTIME],
            info[M_MODBY], info[M_MODWITH]);
@@ -71,10 +138,12 @@ char ** info;
 {
     char buf[BUFSIZ];
 
-    sprintf(buf, "Cluster: %s", info[C_NAME]);
+    Put_message("");
+    sprintf(buf, "Cluster:     %s", info[C_NAME]);
+    Put_message(buf);
+    sprintf(buf, "Description: %s", info[C_DESCRIPT]);
     Put_message(buf);
-    sprintf(buf,"Description: %-20s, Location: %-20s", info[C_DESCRIPT], 
-           info[C_LOCATION]);
+    sprintf(buf, "Location:    %s", info[C_LOCATION]);
     Put_message(buf);
     sprintf(buf, "Last Modified at %s, by %s with %s",info[C_MODTIME],
            info[C_MODBY], info[C_MODWITH]);
@@ -92,7 +161,9 @@ PrintClusterData(info)
 char ** info;
 {
     char buf[BUFSIZ];
-    sprintf(buf, "Cluster: %-30s Label: %-20s Data: %-20s",
+
+    Put_message("");
+    sprintf(buf, "Cluster: %-20s Label: %-15s Data: %s",
            info[CD_NAME], info[CD_LABEL], info[CD_DATA]);
     Put_message(buf);
 }
@@ -188,16 +259,16 @@ Bool name;
 
     switch (type) {
     case MACHINE:
-       sprintf(temp_buf, "Changing the information for the Machine %s.",
-               name);
+       sprintf(temp_buf, "Setting the information for the Machine %s.",
+               info[M_NAME]);
        break;
     case CLUSTER:
-       sprintf(temp_buf, "Changing the information for the Cluster %s.",
-               name);
+       sprintf(temp_buf, "Setting the information for the Cluster %s.",
+               info[C_NAME]);
        break;
     case DATA:
-       sprintf(temp_buf, "Changing the Data for the Cluster %s.",
-               name);
+       sprintf(temp_buf, "Setting the Data for the Cluster %s.",
+               info[CD_NAME]);
        break;
     }
     Put_message(temp_buf);
@@ -206,8 +277,10 @@ Bool name;
        switch (type) {
        case MACHINE:
            newname = Strsave(info[M_NAME]);
-           GetValueFromUser("The new name for this machine? ",
-                            &newname);
+           GetValueFromUser("The new name for this machine? ", &newname);
+           strcpy(temp_buf, CanonicalizeHostname(newname));
+           free(newname);
+           newname = Strsave(temp_buf);
            break;
        case CLUSTER:
            newname = Strsave(info[C_NAME]);
@@ -264,14 +337,13 @@ ShowMachineInfo(argc, argv)
 int argc;
 char **argv;
 {
-    char **info;
     struct qelem *elem, *top;
 
     top = elem = GetMCInfo(MACHINE, CanonicalizeHostname(argv[1]),
                           (char *) NULL);
 
     while (elem != NULL) {
-       info = (char **) elem->q_data;
+       char **info = (char **) elem->q_data;
        PrintMachInfo(info);
        elem = elem->q_forw;
     }
@@ -308,8 +380,7 @@ char **argv;
        return(DM_NORMAL);
     }
 
-    info[0] = name;
-    args = AskMCDInfo(info, MACHINE, FALSE);
+    args = AskMCDInfo(SetMachineDefaults(info, name), MACHINE, FALSE);
 
 /*
  * Actually create the new Machine.
@@ -337,30 +408,124 @@ 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);
 
+    one_machine = (QueueCount(top) == 1);
     while (elem != NULL) {
-       char ** args;
-       char ** info = (char **) elem->q_data;
-       args = AskMCDInfo(info, MACHINE, TRUE);
-       if ( (stat = sms_query("update_machine", CountArgs(args), 
-                              args, Scream, NULL)) != 0)
-           com_err(program_name, stat, " in UpdateMachine.");
+       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);
 }
 
+/*     Function Name: CheckAndRemoveFromCluster
+ *     Description: This func tests to see if a machine is in a cluster.
+ *                   and if so then removes it
+ *     Arguments: name - name of the machine (already Canonocalized).
+ *                 ask_user- query the user before removing if from clusters?
+ *     Returns: SMS_ERROR if machine left in a cluster, or sms_error.
+ */
+
+int 
+CheckAndRemoveFromCluster(name, ask_user)
+char * name;
+Bool ask_user;
+{
+    register int stat, ret_value;
+    Bool delete_it;
+    char *args[10], temp_buf[BUFSIZ], *ptr;
+    struct qelem *top, *elem = NULL;
+    
+    ret_value = SUB_NORMAL;
+    args[0] = name;
+    args[1] = "*";
+    stat = sms_query("get_machine_to_cluster_map", 2, args, 
+                        StoreInfo, &elem);
+    if (stat && stat != SMS_NO_MATCH) {
+       com_err(program_name, stat, " in get_machine_to_cluster_map.");
+       return(DM_NORMAL);
+    }
+    if (stat == 0) {
+       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;
+           }
+           ptr = "Remove this machine from ** ALL ** these clusters?";
+
+           if (YesNoQuestion(ptr, FALSE) == TRUE) /* may return -1. */
+               delete_it = TRUE;
+           else {
+               Put_message("Aborting...");
+               FreeQueue(top);
+               return(SUB_ERROR);
+           }
+       }
+       else
+           delete_it = TRUE;
+
+       if (delete_it) {
+           elem = top;
+           while (elem != 0) {
+               char **info = (char **) elem->q_data;
+               if ( (stat = sms_query( "delete_machine_from_cluster",
+                                      2, info, Scream, NULL)) != 0) {
+                   ret_value = SUB_ERROR;
+                   com_err(program_name, stat, 
+                           " in delete_machine_from_cluster.");
+                   sprintf(temp_buf, 
+                           "Machine %s ** NOT ** removed from cluster %s.",
+                           info[MAP_MACHINE], info[MAP_CLUSTER]);
+                   Put_message(temp_buf);
+               }
+               elem = elem->q_forw;
+           }
+       }
+    }
+    return(ret_value);
+}
+
 /*     Function Name: DeleteMachine
  *     Description: This function removes a machine from the data base.
  *     Arguments: argc, argv - the machines name int argv[1].
  *     Returns: DM_NORMAL.
  */
 
+/* Perhaps we should remove the cluster if it has no machine now. */
+
 /* ARGSUSED */
 int
 DeleteMachine(argc, argv)
@@ -368,49 +533,55 @@ int argc;
 char **argv;
 {
     int stat;
-    char * args[2], *name, temp_buf[BUFSIZ];
+    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);
 
-/* Should probabally check for wildcards, none allowed. */
-/* Perhaps we should remove the cluster if it has no machine now. */
-
-    args[0] = name;
-    args[1] = "*";
-    stat = sms_query("get_machine_to_cluster_map", 2, args, StoreInfo, &elem);
-    if (stat && stat != SMS_NO_MATCH) {
-       com_err(program_name, stat, " in DeleteMachine.");
-       return(DM_NORMAL);
-    }
-    if (stat == 0) {
-       top = elem;
-       while (elem != NULL) {
-           sprintf(temp_buf, "%s is assigned to cluster %s.",
-                   args[0], args[1]);
-           Put_message(temp_buf);
-           if ( YesNoQuestion(
-                 "Would you like to remove it from this cluster?", FALSE)) {
-               if ( (stat = sms_query( "delete_machine_from_cluster",
-                                      1, args, Scream, NULL)) != 0)
-                   com_err(program_name, stat, 
-                           " in delete_machine_from_cluster.");
+    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 {
-                   Put_message("Aborting...");
-                   FreeQueue(top);
-                   return(DM_NORMAL);
+                   sprintf(temp_buf, "%s sucesfully Deleted.", info[M_NAME]);
+                   Put_message(temp_buf);
                }
            }
-           elem = elem->q_forw;
        }
+       elem = elem->q_forw;
     }
-    if(Confirm("Are you sure that you want to delete this machine?")) {
-       if ( (stat = sms_query("delete_machine", 1, &name, Scream, NULL)) != 0)
-           com_err(program_name, stat, " in DeleteMachine.");
-    }
-    else 
-       Put_message("Operation aborted.");
-
+    FreeQueue(top);
     return(DM_NORMAL);
 }
 
@@ -428,17 +599,74 @@ int argc;
 char ** argv;
 {
     int stat;
-
-    if ( (stat = sms_query("add_machine_to_cluster", 2, argv + 1,
-                                 Scream, NULL) != 0))
-       com_err(program_name, stat, " in AddMachineToCluster.");
-
+    char *machine, *cluster, temp_buf[BUFSIZ], *args[10];
+    Bool add_it, one_machine, one_cluster;
+    struct qelem * melem, *mtop, *celem, *ctop;
+
+    machine = CanonicalizeHostname(argv[1]);
+    cluster = argv[2];
+
+    celem = ctop = GetMCInfo(CLUSTER,  cluster, (char *) NULL);
+    melem = mtop = GetMCInfo(MACHINE,  machine, (char *) NULL);
+
+    one_machine = (QueueCount(mtop) == 1);
+    one_cluster = (QueueCount(ctop) == 1);
+
+    while (melem != NULL) {
+       char ** minfo = (char **) melem->q_data;
+       while (celem != NULL) {
+           char ** cinfo = (char **) celem->q_data;
+           if (one_machine && one_cluster) 
+               add_it = TRUE;
+           else {
+               sprintf(temp_buf,"Add machine %s to cluster %s (y/n/q) ?",
+                       minfo[M_NAME], cinfo[C_NAME]);
+               switch (YesNoQuitQuestion(temp_buf, FALSE)) {
+               case TRUE:
+                   add_it = TRUE;
+                   break;
+               case FALSE:
+                   add_it = FALSE;
+                   break;
+               default:
+                   Put_message("Aborting...");
+                   FreeQueue(ctop);
+                   FreeQueue(mtop);
+                   return(DM_NORMAL);
+               }
+           }
+           if (add_it) {
+               args[0] = minfo[M_NAME];
+               args[1] = cinfo[C_NAME];
+               stat = sms_query("add_machine_to_cluster", 2, args,
+                                Scream, NULL);
+               switch (stat) {
+               case SMS_SUCCESS:
+                   break;
+               case SMS_EXISTS:
+                   sprintf(temp_buf, "%s is already in cluster %s",
+                           minfo[M_NAME], cinfo[C_NAME]);
+                   Put_message(temp_buf);
+                   break;
+               default:
+                   com_err(program_name, stat, " in AddMachineToCluster.");
+                   break;
+               }
+           }
+           celem = celem->q_forw;
+       }
+       celem = ctop;           /* reset cluster element. */
+       melem = melem->q_forw;
+    }
+    FreeQueue(ctop);
+    FreeQueue(mtop);               
     return(DM_NORMAL);
 }
 
 /*     Function Name: RemoveMachineFromCluster
  *     Description: Removes this machine form a specific cluster.
  *     Arguments: argc, argv - Name of machine in argv[1].
+ *                              Name of cluster in argv[2].
  *     Returns: none.
  */
 
@@ -448,44 +676,60 @@ RemoveMachineFromCluster(argc, argv)
 int argc;
 char ** argv;
 {
-    int stat, ans;
-    struct qelem *elem, *top;
-    char ** info, buf[BUFSIZ];
-    
-    elem = top = GetMCInfo(CLUSTER,  CanonicalizeHostname(argv[1]), "*");
-
-    Put_message("This machine is the following clusters:");
-    while (elem != NULL) {
-       info = (char **) elem->q_data;
-       Put_message(info[MAP_CLUSTER]);
-       elem = elem->q_forw;
-    }
-    elem = top;
-
-    if ( Confirm("Remove this machine from ** ALL ** these clusters?") ) {
-       while (elem != NULL) {  /* delete all */
-           info = (char **) elem->q_data;       
-           if ( (stat =sms_query("delete_machine_from_cluster", 2, 
-                                 info, Scream, NULL)) != 0 )
-               com_err(program_name, stat, " in delete_machine_from_cluster");
-           elem = elem->q_forw;
-       }
+    int stat;
+    Bool remove_machine, one_item;
+    struct qelem *top, *elem = NULL;
+    char buf[BUFSIZ], * args[10];
+
+    args[MAP_MACHINE] = CanonicalizeHostname(argv[1]);
+    args[MAP_CLUSTER] = argv[2];
+    args[MAP_END] = NULL;
+
+    stat = sms_query("get_machine_to_cluster_map", CountArgs(args), args,
+                    StoreInfo, &elem);
+    if (stat == SMS_NO_MATCH) {
+       sprintf(buf, "The machine %s is not is the cluster %s.",
+               args[MAP_MACHINE], args[MAP_CLUSTER]);
+       Put_message(buf);
+       return(DM_NORMAL);
     }
-    else 
-       while (elem != NULL) {  /* query delete. */
-           info = (char **) elem->q_data;      
-           sprintf(buf, "Remove %13s from the cluster %30s? (y/n/q)", 
+    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]);
-           ans = YesNoQuitQuestion(buf, FALSE);
-           if (ans == TRUE) 
-               if ( (stat =sms_query("delete_machine_from_cluster", 2, 
-                                     info, Scream, NULL)) != 0 )
-                   com_err(program_name, stat, " in delete_machine_from_cluster");
-           else if (ans != FALSE) /* quit. or ^C */
+           switch (YesNoQuitQuestion(buf, FALSE)) {
+           case TRUE:
+               remove_machine = TRUE;
+           break;
+           case FALSE:
+               remove_machine = FALSE;
                break;
-           elem = elem->q_forw;
+           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);
     return(DM_NORMAL);
 }
@@ -507,7 +751,7 @@ char ** argv;
     char **info;
     struct qelem *elem, *top;
 
-    top = elem = GetMCInfo( MACHINE, CanonicalizeHostname(argv[1]),
+    top = elem = GetMCInfo( CLUSTER, CanonicalizeHostname(argv[1]),
                           (char *) NULL);
     while (elem != NULL) {
        info = (char **) elem->q_data;
@@ -546,8 +790,7 @@ char ** argv;
        return(DM_NORMAL);
     }
 
-    info[0] = name;
-    args = AskMCDInfo(info, CLUSTER, FALSE);
+    args = AskMCDInfo(SetClusterDefaults(info, name), CLUSTER, FALSE);
 
 /*
  * Actually create the new Cluster.
@@ -574,24 +817,119 @@ int argc;
 char ** argv;
 {
     struct qelem *elem, *top;    
-    char **args, **info;
+    char **args, **info, temp_buf[BUFSIZ];
     int stat;
+    Bool one_cluster, update_it;
     
     elem = top = GetMCInfo( CLUSTER, argv[1], (char *) NULL );
 
+    one_cluster = (QueueCount(top) == 1);
     while (elem != NULL) {
        info = (char **) elem->q_data;
-       args = AskMCDInfo(info, CLUSTER, TRUE);
-       if ( (stat = sms_query("update_cluter", CountArgs(args), 
-                              args, Scream, NULL)) != 0)
-           com_err(program_name, stat, " in UpdateCluster.");
+       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);
 }
 
+/*     Function Name: CheckAndRemoveMachine
+ *     Description: This function checks and removes all machines from a
+ *                   cluster.
+ *     Arguments: name - name of the cluster.
+ *                 ask_first - if TRUE, then we will query the user, before
+ *                             deletion.
+ *     Returns: SUB_ERROR if all machines not removed.
+ */
+
+int
+CheckAndRemoveMachines(name, ask_first)
+char * name;
+Bool ask_first;
+{
+    register int stat, ret_value;
+    Bool delete_it;
+    char *args[10], temp_buf[BUFSIZ], *ptr;
+    struct qelem *top, *elem = NULL;
+    
+    ret_value = SUB_NORMAL;
+    args[MAP_MACHINE] = "*";
+    args[MAP_CLUSTER] = name;
+    stat = sms_query("get_machine_to_cluster_map", 2, args, 
+                        StoreInfo, &elem);
+    if (stat && stat != SMS_NO_MATCH) {
+       com_err(program_name, stat, " in get_machine_to_cluster_map.");
+       return(DM_NORMAL);
+    }
+    if (stat == 0) {
+       elem = top = QueueTop(elem);
+       if (ask_first) {
+           sprintf(temp_buf,
+                   "The cluster %s has the following machines in it:",
+                   name);
+           Put_message(temp_buf);
+           while (elem != NULL) {
+               char **info = (char **) elem->q_data;
+               Print(1, &info[MAP_MACHINE], (char *) NULL);
+               elem = elem->q_forw;
+           }
+           ptr = "Remove ** ALL ** these machines from this cluster?";
+
+           if (YesNoQuestion(ptr, FALSE) == TRUE) /* may return -1. */
+               delete_it = TRUE;
+           else {
+               Put_message("Aborting...");
+               FreeQueue(top);
+               return(SUB_ERROR);
+           }
+       }
+       else
+           delete_it = TRUE;
+
+       if (delete_it) {
+           elem = top;
+           while (elem != 0) {
+               char **info = (char **) elem->q_data;
+               if ( (stat = sms_query( "delete_machine_from_cluster",
+                                      2, info, Scream, NULL)) != 0) {
+                   ret_value = SUB_ERROR;
+                   com_err(program_name, stat, 
+                           " in delete_machine_from_cluster.");
+                   sprintf(temp_buf, 
+                           "Machine %s ** NOT ** removed from cluster %s.",
+                           info[MAP_MACHINE], info[MAP_CLUSTER]);
+                   Put_message(temp_buf);
+               }
+               elem = elem->q_forw;
+           }
+       }
+    }
+    return(ret_value);
+}
+
+
 /*     Function Name: DeleteCluster
  *     Description: This function removes a cluster from the database.
  *     Arguments: argc, argv - the name of the cluster is stored in argv[1].
@@ -604,42 +942,60 @@ DeleteCluster(argc, argv)
 int argc;
 char ** argv;
 {
-    char * args[3], temp_buf[BUFSIZ];
+    char temp_buf[BUFSIZ];
     int stat;
+    Bool one_cluster, delete_it = FALSE;
+    struct qelem *elem, *top;
 
-/* Should probabally check for wildcards, none allowed. */
-
-    args[MAP_MACHINE] = "*";
-    args[MAP_CLUSTER] = argv[1];
+    top = elem = GetMCInfo( CLUSTER, argv[1], (char *) NULL );
 
-    stat = sms_query("get_machine_to_cluster_map", 2, args, 
-                    NullFunc, (char *) NULL);
-    if (stat & stat != SMS_NO_MATCH) {
-       com_err(program_name, stat, " in DeleteCluster.");
-       return(DM_NORMAL);
-    }
-    if (stat != SMS_NO_MATCH) {
-       sprintf(temp_buf, "Cluster %s still has machines in it.",argv[1]);
-       Put_message(temp_buf);
-       if ( YesNoQuestion("Would you like a list? (y/n)", TRUE) == TRUE ) {
-           args[0] = "foo";    /* not used. */
-           args[1] = "*";
-           args[2] = argv[1];
-           MachineToClusterMap(3, args);
+    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;
        }
-       return(DM_NORMAL);
-    }
-    if(Confirm("Are you sure that you want to delete this cluster? ")) {
-       if ( (stat = sms_query("delete_cluster", 
-                              1, &args[MAP_CLUSTER], Scream, NULL)) != 0)
-           com_err(program_name, stat, " in DeleteCluster.");
+       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;
     }
-    else 
-       Put_message("Operation aborted.");
-
+    FreeQueue(top);
     return(DM_NORMAL);
 }
-    
+
 /* ----------- Cluster Data Menu -------------- */
 
 /*     Function Name: ShowClusterData
@@ -649,6 +1005,7 @@ char ** argv;
  *     Returns: DM_NORMAL.
  */
 
+/* ARGSUSED */
 int
 ShowClusterData(argc, argv)
 int argc; 
@@ -703,15 +1060,49 @@ RemoveClusterData(argc, argv)
 int argc; 
 char ** argv; 
 {
+    Bool one_piece_of_data, remove_it;
     int stat;
+    struct qelem *elem, *top;
 
-    if(Confirm("Do you really want to delete this data?")) {
-       if( (stat = sms_query("delete_cluster_data", 3, argv + 1,
-                             Scream, (char *) NULL)) != 0)
-           com_err(program_name, stat, " in DeleteClusterData.");
-    } else 
-       Put_message("Operation aborted.\n");
+    top = elem = GetMCInfo(DATA, argv[1], argv[2]);
 
+    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);
 }
 
@@ -734,6 +1125,7 @@ char **argv;
 
     top = elem = GetMCInfo(MAP, CanonicalizeHostname(argv[1]), argv[2]);
   
+    Put_message("");           /* blank line on screen */
     while (elem != NULL) {
        char ** info = (char **) elem->q_data;
        PrintMCMap(info);
@@ -752,7 +1144,7 @@ char **argv;
 
 /* ARGSUSED */
 int
-MachinesInCluster(argv,argc)
+MachinesInCluster(argc, argv)
 int argc;
 char **argv;
 {
index ef25d034cbe75f29b44583ad1519167ce279d29a..1419afcd79dbf7d5b72b6c3cfa164ad44ba5ba65 100644 (file)
@@ -30,7 +30,7 @@
 #include "globals.h"
 #include "infodefs.h"
 
-static int RealDeleteList(), RealDeleteUser();
+static int RealDeleteUser();
 
 /*     Function Name: CheckListForDeletion
  *     Description: Check one of the lists in which we just removed a member.
@@ -145,15 +145,15 @@ Bool verbose;
        com_err(program_name, status, " in CheckIfAcl (get_acl_use).");
        return(SUB_ERROR);
     }  
+    local = elem = QueueTop(elem);
     if (verbose) {
        sprintf(buf, "%s %s %s %s", type, name,
                "is the Access Control List (ACL) for the following data",
                "objects:\n");
        Put_message(buf);
-       local = elem;
        while (local != NULL) {
            char ** info = (char **) local->q_data;
-           Print( QueueCount(elem), info, NULL);
+           Print( CountArgs(info), info, NULL);
            local = local->q_forw;
        }
        Put_message("The ACL for each of these items must be changed before");
@@ -180,7 +180,7 @@ struct qelem ** elem;
 int verbose;
 {
     struct qelem *local;
-    char *args[2], temp_buf[BUFSIZ];
+    char *args[10], temp_buf[BUFSIZ];
     int status, ans;
     
     args[0] = type;
@@ -191,7 +191,7 @@ int verbose;
  * Get all list of which this list is a member, and store them in a queue.
  */
 
-    status = sms_query("get_list_of_member", 2, args, StoreInfo,
+    status = sms_query("get_lists_of_member", 2, args, StoreInfo,
                       (char *) elem);
 
     if (status == SMS_NO_MATCH)
@@ -280,11 +280,10 @@ Bool verbose;
 /*
  * If verbose mode, then ask the user if we should delete.
  */
-
+    local = elem = QueueTop(elem);
     if (verbose) {
        sprintf(buf, "List %s has %d member(s):", name, QueueCount(elem) );
        Put_message(buf);
-       local = elem;
        while (local != NULL) {
            char ** info = (char **) local->q_data;
            Print( CountArgs(info), info, NULL);
@@ -427,10 +426,10 @@ int verbose;
        com_err(program_name, status, " in delete_filesystem.");
        return(SUB_ERROR);
     }
+    local = elem = QueueTop(elem);
     if (verbose) {
        sprintf(buf, "User %s has quotas on the following filsystems:");
        Put_message(buf);
-       local = elem;
        while (local != NULL) {
            char ** info = (char **) local->q_data;
            sprintf(buf, "Filesystem:\t%s\t\tQuota(in Kb):\t%s",
@@ -466,105 +465,155 @@ int verbose;
     return(SUB_NORMAL);
 }
 
-/*     Function Name: DeleteList
- *     Description: deletes a list
- *     Arguments: argc, argv - standard SMS argc and argv.
- *     Returns: DM Status Code.
+/*     Function Name: RealDeleteList
+ *     Description: Just Deletes the list.
+ *     Arguments: name - name of list to delete
+ *     Returns: SUB_ERROR if the deletion failed.
  */
 
-int
-DeleteList(argc, argv)
-int argc;
-char *argv[];
+static int
+RealDeleteList(name)
+char * name;
 {
-    char *list, **info;
-    struct qelem *local, *member_of, *list_info;
+    char buf[BUFSIZ];
     int status;
 
-    member_of = list_info = NULL;
-
-    list = argv[1];
-    if (!Confirm("Are you sure that you want to delete this list?"))
-       return(DM_NORMAL);
-/*
- * Get Information about a list.
- */
-    if ( (status = sms_query("get_list_info", 1, &list, StoreInfo, 
-                      (char *) &list_info)) != 0) {
-       com_err(program_name, status,   " in DeleteList (delete_list).");
-       return(DM_NORMAL);
+    if ( (status = sms_query("delete_list", 1, &name, Scream, 
+                            (char *) NULL)) != SMS_SUCCESS) {
+       com_err(program_name, status, ": list not deleted");
+       return(SUB_ERROR);
     }
+    (void) sprintf(buf, "List %s deleted./n", name);
+    Put_message(buf);
+    return(SUB_NORMAL);
+}
 
-/*
- * Attempt delete. - will only work if:
- * 1) This list has no members.
- * 2) This list in a member of no other lists.
- * 3) This list is not an acl of another object.
+/*     Function Name: AttemptToDeleteList
+ *     Description: Atempts to delete list, in the following manner:
+ *                   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.
+ *                 ask_first - (T/F) query user before preparing for deletion,
+ *                             and cleaning up?
+ *     Returns: none - all is taken care of and error messages printed
+ *                      one way or the other.
  */
 
-    status = sms_query("delete_list", 1, &list, Scream, (char *) NULL);
-    if (status != SMS_IN_USE && status != 0) {
-       com_err(program_name, status,   " in DeleteList (delete_list).");
-       return(DM_NORMAL);
-    }
-    if (status == 0) {
+void
+AttemptToDeleteList(name, ask_first)
+char * name;
+Bool ask_first;
+{
+    int status;
+    struct qelem *local, *member_of, *list_info;
+    char ** info;
+    member_of = list_info = NULL;
+    
+    /*
+     * Attempt delete. - will only work if:
+     * 1) This list has no members.
+     * 2) This list in a member of no other lists.
+     * 3) This list is not an acl of another object.
+     */
+    
+    switch (status = sms_query("delete_list", 1, &name,
+                              Scream, (char *) NULL)) {
+    case SMS_SUCCESS:
        Put_message("List Sucessfully Deleted.");
-    }
-    else  {                    /* status = SMS_IN_USE. */
-
-/* 
- * This list is in use.  Try to find out why, and for the cases where we
- * have a good idea of what to do we will query and then do it.
- */
-
-       if ( (CheckIfAcl(list, "list", TRUE) == SUB_ERROR) ||
-           (RemoveItemFromLists(list, "list",
-                                &member_of, TRUE) == SUB_ERROR) ||
-           (RemoveMembersOfList(list, TRUE) == SUB_ERROR) ||
-           (RealDeleteList(list) == SUB_ERROR) ) {
+       break;
+    case SMS_IN_USE:
+       /* 
+        * This list is in use.  Try to find out why, 
+        * and for the cases where we have a good idea of 
+        * what to do we will query and then do it.
+        */
+       
+       if ( (CheckIfAcl(name, "list", 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);
            
-           FreeQueue(list_info);
-           FreeQueue(member_of);
-           return(DM_NORMAL);  
+           local = member_of;
+           while (local != NULL) {
+               info = (char **) local->q_data;
+               CheckListForDeletion(info[LM_LIST], ask_first);
+               local = local->q_forw;
+           }
        }
+       FreeQueue(list_info);
+       FreeQueue(member_of);   /* bug here somwhere... */
+       break;
+    default:
+       com_err(program_name, status, " in DeleteList (delete_list).");
+       break;
     }
-
-    info = (char **) list_info->q_data;
-    CheckAcl(info[L_ACL_TYPE], info[L_ACL_NAME], TRUE);
-
-    local = member_of;
-    while (local != NULL) {
-       info = (char **) local->q_data;
-       CheckListForDeletion(info[LM_LIST], TRUE);
-       local = local->q_forw;
-    }
-
-    FreeQueue(list_info);
-    FreeQueue(member_of);
-    return(DM_NORMAL);
 }
 
-/*     Function Name: RealDeleteList
- *     Description: Just Deletes the list.
- *     Arguments: name - name of list to delete
- *     Returns: SUB_ERROR if the deletion failed.
+/*     Function Name: DeleteList
+ *     Description: deletes a list
+ *     Arguments: argc, argv - standard SMS argc and argv.
+ *     Returns: DM Status Code.
  */
 
-static int
-RealDeleteList(name)
-char * name;
+/* ARGSUSED */
+int
+DeleteList(argc, argv)
+int argc;
+char *argv[];
 {
     char buf[BUFSIZ];
-    int status;
+    struct qelem *top, *list;
+    register int status;
+    Bool one_list;
 
-    if ( (status = sms_query("delete_list", 1, &name, Scream, 
-                            (char *) NULL)) == NULL) {
-       com_err(program_name, status, ": list not deleted");
-       return(SUB_ERROR);
+    list = NULL;
+    
+    switch(status = sms_query("get_list_info", 1, argv + 1, StoreInfo, &list)){
+    case SMS_SUCCESS:
+       break;
+/*    case SMS_NO_WILDCARD:
+       Put_message("Wildcards are not accepted here.");
+       return(DM_NORMAL);
+*/  case SMS_NO_MATCH:
+    case SMS_LIST:
+       Put_message("There is not list that matches that name.");
+       return(DM_NORMAL);
+    default:
+       com_err(program_name, status,   " in DeleteList (get_list_info).");
+       return(DM_NORMAL);
     }
-    (void) sprintf(buf, "List %s deleted./n", name);
-    Put_message(buf);
-    return(SUB_NORMAL);
+    
+    top = list = QueueTop(list);
+    one_list = (QueueCount(list) == 1);
+    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);
+       }
+       else {
+           sprintf(buf, "Delete the list %s", info[L_NAME]);
+           switch( YesNoQuestion( buf, FALSE ) ) {
+           case TRUE:
+               AttemptToDeleteList(info[L_NAME], TRUE);
+               break;
+           case FALSE:
+               break;
+           default:
+               Put_message ("Aborting...");
+               FreeQueue(top);
+               return(DM_NORMAL);
+           }
+       }
+       list = list->q_forw;
+    }
+    FreeQueue(top);
+    return(DM_NORMAL);
 }
 
 /*     Function Name: DeleteUser
@@ -573,11 +622,15 @@ char * name;
  *     Returns: DM_NORMAL.
  */
 
+/* ARGSUSED */
 int
 DeleteUser(argc, argv)
 int argc;
 char ** argv;
 {
+
+/* Make this handle wildcards. */
+
     int status;
     char buf[BUFSIZ];
     char * name = argv[1];     /* name of the user we are deleting. */
index 732ff53f1f62796664ad0138a9c41955c4307dec..15398ad8d8aa0fee68c47f2ea7d2c2e268a3c6a5 100644 (file)
 #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
+#define DEFAULT_MAILLIST    DEFAULT_YES
+#define DEFAULT_GROUP       DEFAULT_NO
+#define DEFAULT_GID         UNIQUE_GID
+#define DEFAULT_ACL_TYPE    "user"
+#define DEFAULT_ACL_NAME    (user)
+#define DEFAULT_DESCRIPTION DEFAULT_COMMENT
+
 /* globals only for this file. */
 
-static char * current_list;
+static char current_list[BUFSIZ];
 
 /*     Function Name: PrintListInfo
  *     Description: This function Prints out the List info in a coherent form.
@@ -51,9 +64,9 @@ char ** info;
 {
     char buf[BUFSIZ];
 
-    (void) sprintf(buf, "List: %s",info[L_NAME]);
+    (void) sprintf(buf, "\n%20sList: %s", "", info[L_NAME]);
     (void) Put_message(buf);
-    (void) sprintf(buf, "\nDescription: %s", info[L_DESC]);
+    (void) sprintf(buf, "Description: %s", info[L_DESC]);
     (void) Put_message(buf);
     if ( atoi(info[L_MAILLIST]))
        Put_message("This list is a mailing list.");
@@ -76,9 +89,9 @@ char ** info;
     }
 
     (void) sprintf(buf, "This list is: %s, %s, and %s",
-                  info[L_ACTIVE] ? "active" : "inactive",
-                  info[L_PUBLIC] ? "public" : "private",
-                  info[L_HIDDEN] ? "hidden" : "visible");
+                  atoi(info[L_ACTIVE]) ? "active" : "inactive",
+                  atoi(info[L_PUBLIC]) ? "public" : "private",
+                  atoi(info[L_HIDDEN]) ? "hidden" : "visible");
     (void) Put_message(buf);
     (void) sprintf(buf, "Last modification at %s, by %s using the program %s",
                   info[L_MODTIME], info[L_MODBY], info[L_MODWITH]);
@@ -107,7 +120,7 @@ char * name1, *name2;
        args[0] = name1;
        if ( (status = sms_query("get_list_info", 1, args,
                               StoreInfo, (char *) &elem)) != 0) {
-           com_err(program_name, status, " in get_nfs_quotas_by_user");
+           com_err(program_name, status, " in get_list_info");
            return (NULL);
        }
        break;
@@ -115,7 +128,7 @@ char * name1, *name2;
        args[0] = name1;
        if ( (status = sms_query("get_members_of_list", 1, args,
                               StoreInfo, (char *) &elem)) != 0) {
-           com_err(program_name, status, " in get_nfs_quotas_by_user");
+           com_err(program_name, status, " in get_members_of_list");
            return (NULL);
        }
        break;
@@ -124,7 +137,7 @@ char * name1, *name2;
        args[1] = name2;        
        if ( (status =  sms_query("get_list_of_member", 2, args,
                               StoreInfo, (char *) &elem)) != 0) {
-           com_err(program_name, status, " in get_nfs_quotas_by_user");
+           com_err(program_name, status, " in get_list_of_members");
            return (NULL);
        }
        break;
@@ -133,7 +146,7 @@ char * name1, *name2;
        args[1] = name2;        
        if ( (status =  sms_query("get_acl_use", 2, args,
                               StoreInfo, (char *) &elem)) != 0) {
-           com_err(program_name, status, " in get_nfs_quotas_by_user");
+           com_err(program_name, status, " in get_acl_use");
            return (NULL);
        }
        break;
@@ -157,7 +170,7 @@ Bool name;
 {
     char temp_buf[BUFSIZ], *newname;
 
-    sprintf(temp_buf,"\nChanging Attributes of list %s.\n",info[L_NAME]);
+    sprintf(temp_buf,"\nSetting information of list %s.\n",info[L_NAME]);
     Put_message(temp_buf);
 
     if (name) {
@@ -169,11 +182,9 @@ Bool name;
     GetValueFromUser("Is this list hidden (1/0): ", &info[L_HIDDEN]);
     GetValueFromUser("Is this a maillist  (1/0): ", &info[L_MAILLIST]);
     GetValueFromUser("is this a group     (1/0): ", &info[L_GROUP]);
-    if (atoi(info[L_GROUP])) {
-       sprintf(temp_buf, "What is the Gid for this group, %s",
-               "'#' gets unique gid:");
-       GetValueFromUser(temp_buf, &info[L_GID]);
-    }
+    if (atoi(info[L_GROUP]))
+       GetValueFromUser("What is the GID for this group.", &info[L_GID]);
+
     GetValueFromUser("What Type of Administrator (none, user, list): ",
                     &info[L_ACL_TYPE]);
     if ( (strcmp(info[L_ACL_TYPE], "USER") == 0) || 
@@ -207,6 +218,7 @@ Bool name;
  *     Returns: DM status code.
  */
 
+/* ARGSUSED */
 int
 ShowListInfo(argc, argv)
 int argc;
@@ -225,43 +237,91 @@ char **argv;
 }
 
 /*     Function Name: UpdateList
- *     Description: 
+ *     Description: updates the information on a list.
  *     Arguments: argc, argv - name of list in argv[1].
  *     Returns: DM Status code.
  */
 
+/* ARGSUSED */
 int
 UpdateList(argc, argv)
 int argc;
 char **argv;
 {
-    char **info, **up_args;
+    char buf[BUFSIZ];
     struct qelem *top, *list;
     int status;
+    Bool one_list, update_it;
 
     list = top = GetListInfo(LIST, argv[1], (char *) NULL);
     
+    one_list = (QueueCount(top) == 1);
     while (list != NULL) {
-       info = (char **) list->q_data;
-       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;
+       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: SetDefaults
+ *     Description: sets defaults for AddList function
+ *     Arguments: info - the array to add them to.
+ *                 name - name of the program to add.
+ *     Returns: defaults - the default information.
+ */
+
+static char **
+SetDefaults(info, name)
+char ** info;
+char * name;
+{
+   info[L_NAME] =     Strsave(name);
+   info[L_ACTIVE] =   Strsave(DEFAULT_ACTIVE);
+   info[L_PUBLIC] =   Strsave(DEFAULT_PUBLIC);
+   info[L_HIDDEN] =   Strsave(DEFAULT_HIDDEN);
+   info[L_MAILLIST] = Strsave(DEFAULT_MAILLIST);
+   info[L_GROUP] =    Strsave(DEFAULT_GROUP);
+   info[L_GID] =      Strsave(DEFAULT_GID);
+   info[L_ACL_TYPE] = Strsave(DEFAULT_ACL_TYPE);
+   info[L_ACL_NAME] = Strsave(DEFAULT_ACL_NAME);
+   info[L_DESC] =     Strsave(DEFAULT_DESCRIPTION);
+   info[L_MODTIME] = info[L_MODBY] = info[L_MODWITH] = info[L_END] = NULL;
+   return(info);
+}
+
 /*     Function Name: AddList
  *     Description: 
  *     Arguments: argc, argv - name of list in argv[1].
  *     Returns: DM Status code.
  */
 
+/* ARGSUSED */
 int
 AddList(argc, argv)
 int argc;
@@ -283,7 +343,7 @@ char **argv;
        return(DM_QUIT);
     }
 
-    add_args = AskListInfo(info, FALSE);
+    add_args = AskListInfo(SetDefaults(info,argv[1]), FALSE);
 
     if ( (status = sms_query("add_list", CountArgs(add_args), add_args,
                             Scream, (char *) NULL)) != 0) {
@@ -396,8 +456,8 @@ char * type;
     register int status;
 
     found_some = FALSE;
-    if ( (status = sms_query("get_members_of_list", 1, &current_list, 
-                          PrintByType, type)) != 0)
+    if ( (status = sms_query("get_members_of_list", 1, current_list, 
+                            PrintByType, type)) != 0)
        com_err(program_name, status, " in ListMembersByType\n");
     if (!found_some) {
        if (type == NULL)
@@ -477,18 +537,21 @@ char *action, **ret_argv;
 
     ret_argv[LM_LIST] = Strsave(current_list);
     ret_argv[LM_MEMBER] = "nobody";
+    ret_argv[LM_TYPE]= "user";
 
-    PromptWithDefault("Type of member (USER, LIST, or STRING)",
-                       ret_buf, BUFSIZ, "USER");
-    ret_argv[LM_TYPE]= Strsave(ret_buf);
-
-    status = sms_access("add_member_to_list", 3, ret_argv);
-    if (status == SMS_TYPE) {
-       Put_message("\"type\" must be one of 'STRING', 'LIST', or 'USER'.");
+    switch (status = sms_access("add_member_to_list", 3, ret_argv)) {
+    case SMS_SUCCESS:
+       break;
+    case SMS_PERM:
+       Put_message("You are not allowed to add members to this list.");
        return(SUB_ERROR);
-    } else if (status) {
+    default:
        com_err(program_name, status, NULL);
+       return(SUB_ERROR);
     }
+    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);
     PromptWithDefault(temp_buf, ret_buf, BUFSIZ, user);
index abe0d8087a2ecba14841405beaa3cf642e202a5c..57c772fa5fcfc00578c0899d89812dc0c31dce09 100644 (file)
 #include "allmaint_funcs.h"
 #include "globals.h"
 
-extern Menu allmaint_top_menu;
+char * whoami;                 /* used by menu.c ugh!!! */
+
+extern Menu sms_top_menu;
+
 static void ErrorExit(), Usage(), SignalHandler();
 char *getlogin();
 uid_t getuid();
@@ -78,7 +81,10 @@ main(argc, argv)
       Usage();
       break;
     }
-    
+
+    program_name = Strsave(program_name);
+    whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
+
     if ( status = sms_connect() ) 
        ErrorExit("\nConnection to SMS server failed", status);
 
@@ -89,17 +95,20 @@ main(argc, argv)
  * These signals should not be set until just before we fire up the menu
  * system. 
  */
+
+#ifndef DEBUG
     (void) signal(SIGHUP, SignalHandler);
-    (void) signal(SIGINT, SignalHandler);
+    (void) signal(SIGINT, SignalHandler); 
     (void) signal(SIGQUIT, SignalHandler);
+#endif DEBUG
 
     if (use_menu) {            /* Start menus that execute program */
         Start_paging();
-       Start_menu(&allmaint_top_menu);
+       Start_menu(&sms_top_menu);
        Stop_paging();
     }
     else                       /* Start program without menus. */
-       Start_no_menu(&allmaint_top_menu);
+       Start_no_menu(&sms_top_menu);
 
     sms_disconnect();
     exit(0);
@@ -141,7 +150,7 @@ Usage()
  *     Returns: doesn't
  */
 
-void
+static void
 SignalHandler()
 {
     Put_message("Signal caught - exiting");
index c572ea8822ab7d443c160517a8e2b8adf774d14b..ba7ff93e6dbfc2912d815c84c337cd67ad21638f 100644 (file)
@@ -60,23 +60,23 @@ Menu attachmaint_top_menu = {
   NULLFUNC, 
   NULLFUNC, 
   "Attach/Filesystem Maintenance", 
-  7,
+  6,
   {
     SUBMENU("filesystem", "Filesystem Work", &attachmaint_filemenu),
     { GetFSAlias, NULLMENU, 2, {
-      {"check", "Check An Association."},
-      {"name", "name (user/group/course): "}
+      {"check", "Check An Association"},
+      {"name", "alias name : "}
     } },
     { CreateFSAlias, NULLMENU, 2, {
-      {"alais", "Associate with a Filesystem."},
-      {"name", "name (user/course/project): "},
+      {"alias", "Associate with a Filesystem"},
+      {"name", "alias name : "},
     } },
     { DeleteFSAlias, NULLMENU, 2, {
-      {"unalias", "Disassociate from a Filesystem."},
-      {"name", "name (user/course/project): "},
+      {"unalias", "Disassociate from a Filesystem"},
+      {"name", "alias name : "},
     } },
-    SIMPLEFUNC("verbose", "Toggle Verbosity of Delete.", ToggleVerboseMode),
-    SIMPLEFUNC("help", "Help ...", AttachHelp)
+    SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode),
+    SIMPLEFUNC("help", "Help ..", AttachHelp)
   }
 };
 
@@ -88,37 +88,38 @@ Menu clustermaint_machine_menu = {
   NULLFUNC,
   NULLFUNC,
   "Machine Maintenence",
-  6,
+  7,
   {
     { ShowMachineInfo, NULLMENU, 2, {
-      {"Show","Get machine information."},
+      {"show","Get machine information"},
       {"name","Machine's Name: "}
     } },
     { AddMachine, NULLMENU, 2, {
-      {"Add","Add a new machine."},
+      {"add","Add a new machine"},
       {"name","Machine's Name: "},
     } },
     { UpdateMachine, NULLMENU, 2, {
-      {"Update","Update machine information."},
+      {"update","Update machine information"},
       {"name","Machine's Name: "},
     } },
     { DeleteMachine, NULLMENU, 2, {
-      {"Delete","Delete this machine."},
+      {"delete","Delete this machine"},
       {"name","Machine's Name: "}
     } },
     { MachineToClusterMap, NULLMENU, 3, {
-      {"Map", "Show Machine to cluster mapping."},
-      {"name", "Machine's Name:"},
-      {"cluster", "Cluster's Name:"},
+      {"map", "Show Machine to cluster mapping"},
+      {"name", "Machine's Name: "},
+      {"cluster", "Cluster's Name: "},
     } },
     { AddMachineToCluster, NULLMENU, 3, {
-      {"AddCluster","Add this machine to a cluster."},
+      {"addcluster","Add machines to a clusters"},
       {"name","Machine's Name: "},
-      {"cluster", "Cluster's Name:"},
+      {"cluster", "Cluster's Name: "},
     } },
-    { RemoveMachineFromCluster, NULLMENU, 2, {
-      {"RemoveCluster", "Remove this machine from a cluster."},
+    { RemoveMachineFromCluster, NULLMENU, 3, {
+      {"remcluster", "Remove machines from clusters"},
       {"name","Machine's Name: "},
+      {"cluster", "Cluster's Name: "},
     } },
   }
 };
@@ -127,53 +128,63 @@ Menu clustermaint_cluster_menu = {
   NULLFUNC,
   NULLFUNC,
   "Cluster Information",
-  5,
+  7,
   {
     { ShowClusterInfo, NULLMENU, 2, {
-      {"Show", "Get cluster information."},
+      {"show", "Get cluster information"},
       {"name", "Cluster's Name: "}
     } },
     { MachinesInCluster, NULLMENU, 2, {
-      {"Machines", "List all machines in a cluster."},
+      {"machines", "List all machines in a cluster"},
       {"clus", "Cluster's Name: "}
     } },
     { AddCluster, NULLMENU, 2, {
-      {"add", "Add a new cluster."},
+      {"add", "Add a new cluster"},
       {"name","Cluster's Name: "},
     } },
     { UpdateCluster, NULLMENU, 2, {
-      {"update", "Update cluster information."},
+      {"update", "Update cluster information"},
       {"name","Cluster's Name: "},
     } },
     { DeleteCluster, NULLMENU, 2, {
-      {"delete", "Delete this cluster."},
+      {"delete", "Delete this cluster"},
       {"name", "Cluster's Name: "}
     } },
+    { AddMachineToCluster, NULLMENU, 3, {
+      {"addcluster","Add machines to a clusters"},
+      {"name","Machine's Name: "},
+      {"cluster", "Cluster's Name: "},
+    } },
+    { RemoveMachineFromCluster, NULLMENU, 3, {
+      {"remcluster", "Remove machines from clusters"},
+      {"name","Machine's Name: "},
+      {"cluster", "Cluster's Name: "},
+    } },
   }
 };
 
-Menu clustermaint_data_menu= {
+Menu clustermaint_data_menu = {
   NULLFUNC,
   NULLFUNC,
   "Cluster Data Maintenence",
   3,
   {
     { ShowClusterData, NULLMENU, 3, {
-      {"show_one", "Show Data on a given Cluster"},
+      {"show", "Show Data on a given Cluster"},
       {"clus", "Cluster's Name: "},
-      {"label", "Label Identifing the data"},
+      {"label", "Label Identifing the data"},
     } },
     { AddClusterData, NULLMENU, 4, {
       {"add", "Add Data to a given Cluster"},
       {"clus", "Cluster Name: "},
-      {"label", "Label Identifing the data"},
-      {"data", "The data to be added"},
+      {"label", "Label Identifing the data"},
+      {"data", "The data to be added"},
     } },
     { RemoveClusterData, NULLMENU, 4, {
       {"delete", "Remove Data to a given Cluster"},
       {"clus", "Cluster's Name: "},
-      {"label", "Label Identifing the data"},
-      {"data", "The data to be removed"},
+      {"label", "Label Identifing the data"},
+      {"data", "The data to be removed"},
     } } 
   }
 };
@@ -186,7 +197,7 @@ Menu clustermaint_top_menu = {
   {
     SUBMENU("machine", "Work on Machines", &clustermaint_machine_menu),
     SUBMENU("cluster", "Work on Clusters", &clustermaint_cluster_menu),
-    SUBMENU("service", "Service Clusters", &clustermaint_data_menu),
+    SUBMENU("data", "Work with cluster data", &clustermaint_data_menu),
     {MachineToClusterMap, NULLMENU, 3, {
       {"map", "Machine to Cluster Mapping"},
       {"machine", "Machine Name: "},
@@ -311,31 +322,33 @@ Menu listmaint_top_menu = {
     "List Maintenance Menu",
     8,
     {
-        { NULLFUNC, &listmaint_member_menu, 2, {
-           {"add", "Create new List"},
-           {"list name", "Name of list: "}
-       } },
-       { DeleteList, NULLMENU, 2, {
-           {"delete", "Delete a List"},
-           {"list name", "Name of list: "}
-       } },
        { ShowListInfo, NULLMENU, 2, {
            {"show", "Display information about a list"},
            {"list name", "Name of list: "}
        } },
+        { NULLFUNC, &listmaint_member_menu, 2, {
+           {"add", "Create new List"},
+           {"list name", "Name of list (do not use wildcards): "}
+       } },
        { UpdateList, NULLMENU, 2, {
            {"update", "Update characteristics of a list"},
            {"list name", "Name of list: "}
        } },
+       { DeleteList, NULLMENU, 2, {
+           {"delete", "Delete a List"},
+           {"list name", "Name of list: "}
+       } },
        { NULLFUNC, &listmaint_member_menu, 2, {
            {"members", "Change/Display the membership of a list"},
-           {"list name", "Name of list: "}
+           {"list name", "Name of list (do not use wildcards): "}
        } },
        SIMPLEFUNC("query_remove",
                   "Interactively remove an item from all lists",
                   InterRemoveItemFromLists),
        SUBMENU("list_lists", "Display inventory of lists",
                &listmaint_list_menu),
+       SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", 
+                  ToggleVerboseMode),
        SIMPLEFUNC("help", "How to use this program", ListHelp)
     } 
 };
@@ -351,7 +364,7 @@ Menu nfsmaint_top_menu = {
   5,
   {
     { ShowNFSService, NULLMENU, 3, {
-      { "show", "Show an NFS server " },
+      { "show", "Show an NFS server" },
       { "machine", "Machine Name: "},
       { "device", "Directory: "}
     } },
@@ -479,12 +492,12 @@ Menu usermaint_top_menu = {
        {"login name", "Desired login name: "}
      } },
     {ShowUserByName, NULLMENU, 3, {
-      {"full", "Show user information by name."},
+      {"full", "Show user information by name"},
       {"first", "First name: "},
       {"last", "Last name: "}
     } },
     {ShowUserByClass, NULLMENU, 2, {
-       {"login", "Show names of users in a given class."},
+       {"login", "Show names of users in a given class"},
        {"login name", "Desired class: "}
      } },    
     {ModifyUser, NULLMENU, 2, {
@@ -525,13 +538,13 @@ Menu usermaint_top_menu = {
 };
 
 /* 
- * Allmaint top menu
+ * Sms top menu
  */
 
-Menu allmaint_top_menu = {
+Menu sms_top_menu = {
   NULLFUNC,
   NULLFUNC,
-  "All Maint Top Level Menu",
+  "Sms Database Manipulation",
   5,
   {
     SUBMENU("attachmaint","open the attachmaint menu",&attachmaint_top_menu),
index f20e092d968fc461cc19776ed6469d550508c3e8..117a4895deedad1fadbfd8c458004829603452fe 100644 (file)
@@ -100,6 +100,7 @@ char ** info;
  *     Returns: DM_NORMAL.
  */
 
+/* ARGSUSED */
 int 
 ShowNFSService(argc, argv)
 int argc;
@@ -130,6 +131,7 @@ char **argv;
  *     Returns: DM_NORMAL.
  */
 
+/* ARGSUSED */
 int
 AddNFSService(argc, argv)
 char **argv;
@@ -200,7 +202,7 @@ int argc;
        return (DM_NORMAL);
     }
 
-    top = elem;
+    top = elem = QueueTop(elem);
     one_service = ( QueueCount(top) == 1 );
     while (elem != NULL) {
        info = (char **) elem->q_data;
@@ -273,7 +275,7 @@ char **argv;
        com_err(program_name, stat, " while checking usage of partition");
 
     length = strlen( dir );
-    top = elem;
+    top = elem = QueueTop(elem);
     while (elem != NULL) {
        char buf[BUFSIZ];
        char ** info = (char ** ) elem->q_data;
index 78701088fc2237d73db80b7b414306c3a834322d..4f0a1e279e76ee3815b4d2e1d90535a3e9dc0a75 100644 (file)
@@ -114,7 +114,8 @@ char *name1, *name2;
        args[0] = name1;
        if ( (status = sms_query("get_user_by_login", 1, args,
                               StoreInfo, (char *) &elem)) != 0) {
-           com_err(program_name, status, " when attempting to get_use_by_login.");
+           com_err(program_name, status, 
+                   " when attempting to get_use_by_login.");
            return (NULL);               
        }
        break;
@@ -224,7 +225,7 @@ char *machine;
        return( (char *) NULL);
     }
 
-    top = elem;
+    top = elem = QueueTop(elem);
     while (elem != NULL) {
        char ** info = (char **) elem->q_data;
        if (strcmp (info[1], machine) == 0) {
@@ -411,7 +412,7 @@ char *argv[];
     };
 
     sprintf(buf,"%s%s",
-           "Are you sure that you want to change the default quota\n"
+           "Are you sure that you want to change the default quota\n",
            "for all new users? (y/n) ");
     if(!Confirm(buf)) {
        newval[2] = argv[1];
@@ -591,6 +592,7 @@ char *argv[];
  *     Returns: none.
  */
 
+/* ARGSUSED */
 int
 ShowUserByClass(argc, argv)
 int argc;
@@ -639,7 +641,7 @@ char ** info;
  */
 
 /* ARGSUSED */
-int
+static int
 PrintPOBoxes(argc, argv, junk)
 int argc;
 char **argv;
@@ -663,7 +665,7 @@ char * junk;
  *     Returns: none
  */
 
-void
+static void
 PrintUserInfo(info, name_only)
 char ** info;
 Bool name_only;
index d6e6b9dce8552f66411a28da364561ded75d85be..f747dd7f2a8e58c3738c6ef4b40f1770ac54e2cf 100644 (file)
@@ -46,9 +46,8 @@ void
 FreeInfo(info)
 char ** info;
 {
-    char *pointer = *info;
-    while (pointer != NULL) 
-       free(pointer++);
+    while (*info != NULL)
+       FreeAndClear(info++, TRUE);
 }
 
 /*     Function Name: FreeAndClear        - I couldn't resist the name.
@@ -104,7 +103,7 @@ struct qelem * elem;
        FreeInfo( info ); /* free info fields */
        free(elem->q_data);             /* free info array itself. */
     }
-    remque(elem);              /* remove this element from the queue */
+    RemoveQueue(elem);         /* remove this element from the queue */
     free(elem);                        /* free its space. */
 }
 
@@ -127,6 +126,40 @@ struct qelem * elem;
     }
 }
 
+/*     Function Name: AddQueue
+ *     Description: Adds an element to a queue
+ *     Arguments: elem, pred - element and its predecessor.
+ *     Returns: none.
+ */
+
+AddQueue(elem, pred)
+struct qelem * elem, *pred;
+{
+    if (pred == NULL) {
+       elem->q_forw = NULL;
+       elem->q_back = NULL;
+       return;
+    }
+    elem->q_back = pred;
+    elem->q_forw = pred->q_forw;
+    pred->q_forw = elem;
+}
+
+/*     Function Name: RemoveQueue
+ *     Description: removes an element from a queue.
+ *     Arguments: elem.
+ *     Returns: none.
+ */
+
+RemoveQueue(elem)
+struct qelem *elem;
+{
+    if (elem->q_forw != NULL) 
+       (elem->q_forw)->q_back = elem->q_back;
+    if (elem->q_back != NULL)
+       (elem->q_back)->q_forw = elem->q_forw;
+}
+
 /*     Function Name: QueueCount
  *     Description: Counts the number of elements in a queue
  *     Arguments: elem - any element in the queue.
@@ -146,7 +179,6 @@ struct qelem * elem;
     return(count);
 }
 
-/* ARGSUSED */
 int
 StoreInfo(argc, argv, data)
 int argc;
@@ -162,14 +194,8 @@ char * data;
        info[count] = Strsave(argv[count]);
     info[count] = NULL;                /* NULL terminate this sucker. */
 
-    if (*old_elem == (struct qelem *) NULL) {   /* first elem. */
-       new_elem->q_data = (char *) info;
-       new_elem->q_forw = new_elem->q_back = (struct qelem *) NULL;
-    }
-    else {                     /* all other elements. */
-       new_elem->q_data = (char *) info;
-       insque(new_elem, *old_elem);
-    }
+    new_elem->q_data = (char *) info;
+    AddQueue(new_elem, *old_elem);
 
     *old_elem = new_elem;
     return(SMS_CONT);
@@ -316,7 +342,7 @@ int
 Confirm(prompt)
 char * prompt;
 {
-  return( ~verbose || YesNoQuestion(prompt,FALSE) );
+  return( !verbose || YesNoQuestion(prompt,FALSE) );
 }
 
 /*     Function Name: ValidName
@@ -348,7 +374,7 @@ int
 ToggleVerboseMode()
 {
 
-  verbose = ~verbose;
+  verbose = !verbose;
 
   if (verbose)
     Put_message("Delete functions will first confirm\n");
@@ -376,7 +402,7 @@ NullFunc()
  *     Arguments: info - list that needs this name slipped into it.
  *                 name - the name to slip into the list.
  *     Returns: a pointer to the new list.
- *      NOTE:  This screws up the numbers if the elements of the array in a
+ *      NOTE:  This screws up the numbers of the elements of the array in a
  *             big way.
  */
 
@@ -388,9 +414,9 @@ char * name;
 
     /* This also pushes the NULL down. */
     for (i = CountArgs(info); i > 1; i--) { 
-       info[i+i] = info[i];
+       info[i] = info[i-1];
     }
-    info[1] = Strsave(name);   /* now slip in the name. */
+    info[1] = name;    /* now slip in the name. */
 }
 
 /*     Function Name: GetValueFromUser
@@ -409,7 +435,7 @@ char * prompt, ** pointer;
     char buf[BUFSIZ];
 
     PromptWithDefault(prompt, buf, BUFSIZ, *pointer);
-    if ( pointer != NULL)
+    if (*pointer != NULL)
        free(*pointer);
     *pointer = Strsave(buf);
 }
@@ -427,14 +453,9 @@ char *machine;
     struct hostent *hostinfo;
 
     hostinfo = gethostbyname(machine);
+/* If this fails then we just return what we were passed. */
     if (hostinfo != (struct hostent *) NULL)
        machine = hostinfo->h_name;
-    else                       
-/*
- *  gethostbyname failed.  This should be very rare, since we're
- *  dealing with local hosts, so no fancy error recovery. 
- */
-       machine = (char *) NULL;
     return (machine);
 }
 
This page took 0.205925 seconds and 5 git commands to generate.