]> andersk Git - moira.git/blobdiff - clients/moira/user.c
This version seems to implement almost all correctly, more testing
[moira.git] / clients / moira / user.c
index 9a5d07f3fddbf3af427c246651ea300af6dd9cd8..649a8553cb7cbdc8f14db63e6407da573825dd36 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <stdio.h>
 #include <strings.h>
-#include <ctype.h>
 #include <sms.h>
 #include <menu.h>
 
 #define LOGIN 0
 #define UID   1
 #define BY_NAME  2
-#define QUOTA 3
-#define CLASS 4
+#define CLASS 3
 
-static void PrintQuota();      /* prints Quota info. */
-static void PrintUserInfo();   /* prints User info. */
-static int PrintPOBoxes();     /* prints PO Box information. */
+/*     Function Name: PrintUserName
+ *     Description: Print name of a user.
+ *     Arguments: info - the information about a user.
+ *     Returns: none.
+ */
+
+static void
+PrintUserName(info)
+char ** info;
+{
+    char buf[BUFSIZ], print_buf[BUFSIZ];
+    sprintf(buf, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]);
+    sprintf(print_buf, "%-40s User Name: %s", buf, info[U_NAME]);
+    Put_message(print_buf);
+}
+
+/*     Function Name: PrintUserInfo
+ *     Description: Prints Information about a user.
+ *     Arguments: info - an argument list with the user information
+ *                          in it.
+ *     Returns: none
+ */
+
+static void
+PrintUserInfo(info)
+char ** info;
+{
+    char name[BUFSIZ], buf[BUFSIZ];
+
+    sprintf(name, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]);
+    sprintf(buf, "Login name: %-10s Full name: %s", info[U_NAME], name);
+    Put_message(buf);
+    sprintf(buf, "User id: %-13s Login shell %-15s Class: %s", 
+           info[U_UID], info[U_SHELL], info[U_CLASS]);
+    Put_message(buf);
+    sprintf(buf, "Account is: %-10s Encrypted MIT ID number: %s",
+           atoi(info[U_STATE]) ? "active" : "inactive", info[U_MITID]);
+    Put_message(buf);
+    sprintf(buf, MOD_FORMAT, info[U_MODBY], info[U_MODTIME],info[U_MODWITH]);
+    Put_message(buf);
+}
+
+/*     Function Name: SetUserDefaults
+ *     Description: Sets the default values for add user.
+ *     Arguments: info - a blank user info array of char *'s.
+ *     Returns: args - the filled info structure.
+ */
+
+static char **
+SetUserDefaults(info)
+char ** info;
+{
+    info[U_NAME] = Strsave(UNIQUE_LOGIN);
+    info[U_UID] = Strsave(UNIQUE_UID);
+    info[U_SHELL] = Strsave(DEFAULT_NONE);
+    info[U_LAST] = Strsave(DEFAULT_NONE);
+    info[U_FIRST] = Strsave(DEFAULT_NONE);
+    info[U_MIDDLE] = Strsave(DEFAULT_NONE);
+    info[U_STATE] = Strsave(DEFAULT_NO);
+    info[U_MITID] = Strsave(DEFAULT_NONE);
+    info[U_CLASS] = Strsave(DEFAULT_NONE);
+    info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL;
+    return(info);
+}
 
 /*     Function Name: AskUserInfo.
  *     Description: This function askes the user for information about a 
@@ -56,24 +115,35 @@ AskUserInfo(info, name)
 char ** info;
 Bool name;
 {
-    char temp_buf[BUFSIZ], *newname;
-
-    sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[U_NAME]);
-    Put_message(temp_buf);
+    char temp_buf[BUFSIZ], *newname, *temp_ptr;
 
+    if (name) {
+       sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[U_NAME]);
+       Put_message(temp_buf);
+    }
     if (name) {
        newname = Strsave(info[U_NAME]);
-       GetValueFromUser("The new login name for this user.", &newname);
+       GetValueFromUser("The new login name for this user", &newname);
     }
-    GetValueFromUser("User's UID:", &info[U_UID]);
-    GetValueFromUser("User's shell:", &info[U_SHELL]);
-    GetValueFromUser("User's last name:", &info[U_LAST]);
-    GetValueFromUser("User's first name:", &info[U_FIRST]);
-    GetValueFromUser("User's middle name:", &info[U_MIDDLE]);
-    GetValueFromUser("User's status:", &info[U_STATE]);
-    GetValueFromUser("User's MIT ID number:", &info[U_MITID]);
-    RemoveHyphens(info[U_MITID]); /* zap'em */
-    GetValueFromUser("User's MIT Year (class):", &info[U_CLASS]);
+    else
+       GetValueFromUser("Login name for this user", &info[U_NAME]);
+
+    GetValueFromUser("User's UID", &info[U_UID]);
+    GetValueFromUser("User's shell", &info[U_SHELL]);
+    GetValueFromUser("User's last name", &info[U_LAST]);
+    GetValueFromUser("User's first name", &info[U_FIRST]);
+    GetValueFromUser("User's middle name", &info[U_MIDDLE]);
+    GetValueFromUser("User's status", &info[U_STATE]);
+    temp_ptr = Strsave(info[U_MITID]);
+    GetValueFromUser("User's MIT ID number", &temp_ptr);
+    if ( strcmp( temp_ptr, info[U_MITID] ) != 0) {
+       RemoveHyphens(temp_ptr); /* zap'em */
+       EncryptMITID(temp_buf, temp_ptr, info[U_FIRST], info[U_LAST]);
+       free(info[U_MITID]);
+       info[U_MITID] = Strsave(temp_buf);
+    }
+    free(temp_ptr);
+    GetValueFromUser("User's MIT Year (class)", &info[U_CLASS]);
     
     FreeAndClear(&info[U_MODTIME], TRUE);
     FreeAndClear(&info[U_MODBY], TRUE);
@@ -115,7 +185,7 @@ char *name1, *name2;
        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.");
+                   " when attempting to get_user_by_login.");
            return (NULL);               
        }
        break;
@@ -124,17 +194,17 @@ char *name1, *name2;
        if ( (status = sms_query("get_user_by_uid", 1, args,
                               StoreInfo, (char *) &elem)) != 0) {
            com_err(program_name, status, 
-                   " when attempting to get_use_by_uid.");
+                   " when attempting to get_user_by_uid.");
            return (NULL);      
        }
        break;
     case BY_NAME:
        args[0] = name1;
        args[1] = name2;    
-       if ( (status = sms_query("get_user_by_name", 1, args,
+       if ( (status = sms_query("get_user_by_name", 2, args,
                               StoreInfo, (char *) &elem)) != 0) {
            com_err(program_name, status, 
-                   " when attempting to get_use_by_name.");
+                   " when attempting to get_user_by_name.");
            return (NULL);      
        }
        break;
@@ -143,384 +213,303 @@ char *name1, *name2;
        if ( (status = sms_query("get_user_by_class", 1, args,
                               StoreInfo, (char *) &elem)) != 0) {
            com_err(program_name, status, 
-                   " when attempting to get_use_by_class.");
+                   " when attempting to get_user_by_class.");
            return (NULL);      
        }
        break;
-    case QUOTA:
-       args[0] = name1;
-       if ( (status = sms_query("get_nquotas_by_user", 1, args,
-                              StoreInfo, (char *) &elem)) != 0) {
-           com_err(program_name, status, " in get_nfs_quotas_by_user");
-           return (DM_NORMAL);
-       }
-       break;
     }
     return( QueueTop(elem) );
 }
 
-/* -------------------------- Change Menu -------------------------- */
-
-/*     Function Name: ModifyUser
- *     Description: Modify some of the information about a user.
- *     Arguments: argc, argv - login name of the user in argv[1].
+/*     Function Name: AddNewUser
+ *     Description: Adds a new user to the database.
+ *     Arguments: none.
  *     Returns: DM_NORMAL.
  */
 
 /* ARGSUSED */
 int
-ModifyUser(argc, argv)
-int argc;
-char **argv;
+AddNewUser()
 {
-    int status;
-    char *temp_buf, error_buf[BUFSIZ];
-    struct qelem * elem, * local;
-
-    local = elem = GetUserInfo(LOGIN, argv[1], (char *) NULL);
-
-    while (local != NULL) {
-       char ** info = (char **) local->q_data;
-       char ** args = AskUserInfo(info, TRUE);
-
-       if ( (status = sms_query("update_user", CountArgs(args), 
-                                args, Scream, NULL)) != 0) {
-           com_err(program_name, status, " in ModifyFields");
-           if (local->q_forw == NULL)
-               temp_buf = "";
-           else
-               temp_buf = ", Continuing to next user";
-           sprintf(error_buf,"User %s not updated due to error%s.",
-                   info[NAME], temp_buf);
-           Put_message(error_buf);
-       }
-       local = local->q_forw;
-    }
-    FreeQueue(elem);
+    register int status;
+    char ** args, *info[MAX_ARGS_SIZE];
+
+    args = AskUserInfo(SetUserDefaults(info), FALSE);
+    if ( (status = sms_query("add_user", CountArgs(args), 
+                            args, Scream, (char *) NULL)) != SMS_SUCCESS)
+       com_err(program_name, status, " in add_user");
+    else
+       Put_message("New user added to database.");
+    FreeInfo(args);
     return(DM_NORMAL);
 }
 
 
-/*     Function Name: POType
- *     Description: Asks the SMS server if it is of type pop, of
- *                   of type local. If neither, we assume that it's 
- *                   of type foreign. 
- *     Arguments: machine - a canonicalized machine name, 
- *     Returns: the PO Type, one of: pop, local, foreign.
+/*     Function Name: GetLoginName
+ *     Description: Asks the user for a login name and reserves
+ *                   it with kerberous.
+ *     Arguments: none.
+ *     Returns: a malloced login name for the user.
  */
 
-char *
-POType(machine)
-char *machine;
+static char *
+GetLoginName()
 {
-    int status;
-    char * type;
-    struct qelem *top, *elem = NULL;
-
-    type = "pop";
-    status = sms_query("get_server_locations", 1, &type,
-                      StoreInfo, &elem);
-    if (status && (status != SMS_NO_MATCH)) {
-       com_err(program_name, status, (char *) NULL);
-       return( (char *) NULL);
-    }
+    char name[BUFSIZ];
+
+    Prompt_input("Login name for this user? ", name, BUFSIZ);
+    
+    Put_message(
+             "KERBEROS code not added, did not reserve name with kerberos.");
+
+    return(Strsave(name));
+}
+
+
+/*     Function Name: ChooseUser
+ *     Description: Choose a user from a list and return the uid.
+ *     Arguments: top - a queue of user information.
+ *     Returns: uid - the malloced uid of the user that was chosen.
+ */
 
-    top = elem = QueueTop(elem);
+static char *
+ChooseUser(elem)
+struct qelem * elem;
+{
     while (elem != NULL) {
-       char ** info = (char **) elem->q_data;
-       if (strcmp (info[1], machine) == 0) {
-           FreeQueue(top);
-           return( Strsave("POP") );
+       char ** info = (char **)  elem->q_data;
+       PrintUserInfo(info);
+       switch(YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE)) {
+       case TRUE:
+           return(Strsave(info[U_UID]));
+       case FALSE:
+           break;
+       default:                /* quit or ^C. */
+           return(NULL);
        }
        elem = elem->q_forw;
     }
-    FreeQueue(top);
-    return ( Strsave("SMTP") );
+    return(NULL);
 }
 
-/*     Function Name: ChangeUserPOBox
- *     Description: Changes The P.O. Box for a user.
- *     Arguments: argc, argv - the login name of the user in argv[1].
- *     Returns: DM_NORMAL.
+/*     Function Name: GetUidNumberFromName
+ *     Description: Gets the users uid number, from the name.
+ *     Arguments: none.
+ *     Returns: uid - a malloced string containing the uid.
  */
 
-/*ARGSUSED*/
-int
-ChangeUserPOBox(argc, argv)
-int argc;
-char **argv;
+static char *
+GetUidNumberFromName()
 {
+    char *args[5], *uid, first[BUFSIZ], last[BUFSIZ];
     register int status;
-    struct qelem * poqueue, *local;
-    char *type, buf[BUFSIZ], *pohost;
-    static char *po[4];
-    poqueue = NULL;
+    struct qelem * top = NULL;
+    
+    Prompt_input("First Name: ", first, BUFSIZ);
+    Prompt_input("Last  Name: ", last, BUFSIZ);
 
-    sprintf(buf,"Current pobox for user %s: \n", argv[1]); 
-    Put_message(buf);
-    status = sms_query("get_pobox", 1, argv + 1, PrintPOBoxes, NULL);
-    if (status != SMS_NO_MATCH && status != 0) {
-       com_err(program_name, status, "in ChangeUserPOBox.");
-        return(DM_NORMAL);
-    }
-    else if (status == SMS_NO_MATCH) 
-       Put_message("This user has no P.O. Box.");
+    args[0] = first;
+    args[1] = last;
     
-    if (YesNoQuestion("Shall we use the least loaded Post Office?", TRUE)) {
-       po[0] = "pop";
-       po[1] = "*";
-       if ( status = sms_query ("get_server_host_info", 2, po,
-                                StoreInfo, (char *) &poqueue) != 0) {
-           com_err(program_name, status, 
-                   " in ChangeUserPOBox (get_server_host_info).");
-           return(DM_NORMAL);
-       }
-       local = poqueue;
-       while (local != NULL) {
-           char ** args = (char **) local->q_data;
-           int new_space, old_space = -1 ;
-           if ( !isdigit(*args[6]) || !isdigit(*args[7]) )
-               Put_message(
-                   "non-digit value in server_host_info, this is a bug.");
-           else {
-               new_space = atoi(argv[7]) - atoi(args[6]);
-               if ( (new_space < old_space) || (old_space == -1) ) {
-                   old_space = new_space;
-                   strcpy(buf, args[1]);
-               }
-           }
-           local = local->q_forw;
-       }
-       pohost = Strsave(buf);
-       FreeQueue(poqueue);
-       type = "POP";
-       (void) sprintf(buf, "The Post Office %s was chosen.",
-                      pohost);
-       Put_message(buf);
-    }
-    else if( (Prompt_input("Which Machine for Post Office?", 
-                          buf, BUFSIZ)) ) {
-       if ( (pohost = CanonicalizeHostname(buf)) == NULL) {
-           Put_message("\nNameserver doesn't know that machine, sorry.");
-           return (DM_NORMAL);
-       }
-       type = POType(pohost); 
+    switch (status = sms_query("get_user_by_name", 2, args,
+                              StoreInfo, &top)) {
+    case SMS_SUCCESS:
+       break;
+    case SMS_NO_MATCH:
+       Put_message("There is no user in the database with that name.");
+       return(NULL);
+    default:
+       com_err(program_name, status, " in get_user_by_name.");
+       return(NULL);
     }
     
-    sprintf(buf, "%s %s's %s %s?", "Are you sure that you want to replace all",
-           argv[1], "P.O. Boxes\n with ** ONE ** on the machine", pohost);
-
-    if(Confirm(buf)) {
-       po[0] = argv[1];
-       po[1] = type;
-       po[2] = pohost;
-       po[3] = po[0];
-       if (status = sms_query("set_pobox", 4, po, Scream, NULL) != 0 )
-           com_err(program_name, status, " in ChangeUserPOBox");
-    } else 
-       Put_message("Operation Aborted.");
+    top = QueueTop(top);
+    if (QueueCount(top) == 1) /* This is a unique name. */ {
+       char ** info = (char **) top->q_data;
+       Put_message("User ID Number retrieved for the user: ");
+       Put_message("");
+       PrintUserName(info);
+       uid = Strsave(info[U_UID]);
+       FreeQueue(top);
+       return(Strsave(uid));
+    }
 
-    return (DM_NORMAL);
+    Put_message("That name is not unique, choose the user that you want.");
+    uid = ChooseUser(top);
+    FreeQueue(top);
+    return(uid);
 }
 
-/* ------------------------- Top Menu ------------------------- */
-
-/* delete user in delete.c */
-
-/*     Function Name: DeleteUserByUid
- *     Description: Deletes the user given a uid number.
- *     Arguments: argc, argv - uid if user in argv[1].
- *     Returns: DM_NORMAL.
+/*     Function Name: SetUserPassword
+ *     Description: Set the new kerberos password for this user.
+ *     Arguments: name - kerberos principle name for this user, (login name).
+ *     Returns: none.
  */
 
-/*ARGSUSED*/
-int
-DeleteUserByUid(argc, argv)
-int argc;
-char **argv;
+static void
+SetUserPassword(name)
+char * name;
 {
-    int status;
-
-    if (Confirm("Are you sure you want to remove this user"))
-       if ( (status = sms_query("delete_user_by_uid", 1, argv+1, Scream,
-                              (char * ) NULL)) != 0)
-           com_err(program_name, status, " in DeleteUserByUid");
-
-    return(DM_NORMAL);
-} 
-
-/* ------------------------- Show Quota Info ------------------------- */
+    name = name;                       /* make saber happy. */
+    Put_message("Kerberos password not changed, code non-existant.");
+    /* clever message to call account_admin, if this fails. */
+}
 
-/*     Function Name: ShowDefaultQuota
- *     Description: This prints out a default quota for the system.
- *     Arguments: none
- *     Returns: DM_NORMAL.
+/*     Function Name:  GiveBackLogin
+ *     Description: Gives back previously reserved kerberous principle.
+ *     Arguments: name - principle to give back.
+ *     Returns: void.
  */
 
-int
-ShowDefaultQuota()
+static void
+GiveBackLogin(name)
+char * name;
 {
-    int status;
-    static char *val[] = {"def_quota"};
-
-    if (status = sms_query("get_value", 1, val, Print, (char *) NULL) != 0)
-       com_err(program_name, status, " in ShowDefaultQuota");
-
-    return (DM_NORMAL);
+    name = name;                       /* make saber happy. */
+    Put_message("kerberos code not implimented, name not given back.");
+    /* send mail to db maintainer if this fails. */
 }
 
-/*     Function Name: ShowUserQuota
- *     Description: Shows the quota of a user.
- *     Arguments: argc, argv - users login name is argv[1].
- *     Returns: DM_NORMAL
+/*     Function Name: RegisterUser
+ *     Description: This function registers a user.
+ *     Arguments: none.
+ *     Returns: DM_NORMAL.
  */
 
-/*ARGSUSED*/
 int
-ShowUserQuota(argc, argv)
-int argc;
-char **argv;
+RegisterUser()
 {
-    struct qelem *elem, *top;
-    top = elem = GetUserInfo(QUOTA, argv[1], (char *) NULL);
+    char * args[MAX_ARGS_SIZE];
+    char *login, *fstype = NULL;
+    char temp_buf[BUFSIZ];
+    register int status;
     
-    while (elem != NULL) {
-       char ** info = (char **) elem->q_data;
-       PrintQuota(info);
-       elem = elem->q_forw;
+    Put_message("This function has NO kerberos support, so stange things");
+    Put_message("may happen if you use it to register a user.");
+
+    switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE)) {
+    case TRUE:
+       Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ);
+       args[0] = Strsave(temp_buf);
+       break;
+    case FALSE:
+       if ( (args[0] = GetUidNumberFromName()) == NULL)
+           return(DM_NORMAL);
+       break;
+    default:
+       return(DM_NORMAL);
     }
-    FreeQueue(top);
-    return (DM_NORMAL);
+
+    if ( ((login = args[1] = GetLoginName()) == NULL) ||
+       ( GetFSTypes(&fstype) == SUB_ERROR ) ) {
+       FreeInfo(args);    /* This work because the NULL temination is ok. */
+       return(DM_NORMAL);
+    }
+    args[2] = fstype;
+    args[3] = NULL;
+    
+    switch (status = sms_query("register_user", CountArgs(args),
+                              args, Scream, (char *) NULL)) {
+    case SMS_SUCCESS:
+       sprintf(temp_buf, "User %s successfully registered.", login);
+       Put_message(temp_buf);
+       SetUserPassword(login);
+       break;
+    case SMS_IN_USE:
+       GiveBackLogin(login);
+       sprintf(temp_buf, "The username %s is already in use.", login);
+       Put_message(temp_buf);
+       break;
+    default:
+       com_err(program_name, status, " in register_user");
+       break;
+    }
+    FreeInfo(args);
+    return(DM_NORMAL);
 }
 
-/*     Function Name: ChangeDefaultQuota
- *     Description: Changes the System Wide default quota.
- *     Arguments: argc, argv - New quota in argv[1].
- *     Returns: DM_NORMAL.
+/*     Function Name: RealUpdateUser
+ *     Description: actuall updates the user information.
+ *     Arguments: info - all current information for the user fields.
+ *                 junk - an UNUSED boolean.
+ *     Returns: none.
  */
 
-/*ARGSUSED*/
-int
-ChangeDefaultQuota(argc, argv)
-int argc;
-char *argv[];
+/* ARGSUSED */
+static void
+RealUpdateUser(info, junk)
+char ** info;
+Bool junk;
 {
-    char buf[BUFSIZ];
-    int status;
-    static char *newval[] = {
-       "update_value", "def_quota", NULL,
-    };
-
-    sprintf(buf,"%s%s",
-           "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];
-       if (status = sms_query("update_value", 3, newval, Scream, NULL) != 0)
-           com_err(program_name, status, " in update_value");
+    register int status;
+    char error_buf[BUFSIZ];
+    char ** args = AskUserInfo(info, TRUE);
+    
+    if ( (status = sms_query("update_user", CountArgs(args), 
+                            args, Scream, (char *) NULL)) != SMS_SUCCESS) {
+       com_err(program_name, status, " in ModifyFields");
+       sprintf(error_buf, "User %s not updated due to errors.", info[NAME]);
+       Put_message(error_buf);
     }
-    else
-       Put_message("Quota not changed.");
-
-    return (DM_NORMAL);
 }
 
-/* ---------------------- User Locker Manipultation -------------------- */
-
-/*     Function Name: AddUserLocker
- *     Description: Add a new locker for a user.
- *     Arguments: arc, argv - 
- *                             argv[1] login name of user.
- *                             argv[2] server host name.
- *                             argv[3] Directory on host.
- *                             argv[4] quota in Kb.
+/*     Function Name: UpdateUser
+ *     Description: Modify some of the information about a user.
+ *     Arguments: argc, argv - login name of the user in argv[1].
  *     Returns: DM_NORMAL.
  */
 
-/*ARGSUSED*/
+/* ARGSUSED */
 int
-AddUserLocker(argc, argv)
+UpdateUser(argc, argv)
 int argc;
 char **argv;
 {
-    int status;
-    char *args[4];
+    struct qelem * elem;
 
-    args[0] = argv[1];
-    args[2] = argv[3];
-    args[3] = argv[4];
-    
-    args[1] = CanonicalizeHostname(argv[2]);
-    if (args[1] == (char *)NULL) {
-       Put_message("Could not canonicalize hostname; continuing..");
-       args[1] = argv[2];
-    }
+    elem = GetUserInfo(LOGIN, argv[1], (char *) NULL);
+    QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user");
     
-    if (status = sms_query("add_locker", 4, args, Scream, NULL) != 0)
-       com_err(program_name, status, " in add_user_locker");
-
+    FreeQueue(elem);
     return(DM_NORMAL);
 }
 
-/* needs to be fixed - CDP 6/10/88 */
+/* ------------------------- Top Menu ------------------------- */
+
+/* DeleteUser() in delete.c */
 
-/*     Function Name: DeleteUserLocker
- *     Description: Deletes a locker - BOOM.
- *     Arguments: arc, argv - the name of the locker in argv[1]/
+/*     Function Name: DeleteUserByUid
+ *     Description: Deletes the user given a uid number.
+ *     Arguments: argc, argv - uid if user in argv[1].
  *     Returns: DM_NORMAL.
+ *      NOTES: This just gets the username from the sms server 
+ *             and performs a DeleteUser().
  */
 
-/*ARGSUSED*/
 int
-DeleteUserLocker(argc, argv)
+DeleteUserByUid(argc, argv)
 int argc;
 char **argv;
 {
     int status;
-    if (status = sms_query("delete_locker", 1, argv + 1,
-                          Scream, (char *)NULL) != 0) 
-           com_err(program_name, status, " in delete_locker");
+    struct qelem *elem = NULL;
+    char ** info;
+
+    if(!ValidName(argv[1]))
+       return(DM_NORMAL);
+    
+    if ( (status = sms_query("get_user_by_uid", 1, argv+1, StoreInfo,
+                            (char * ) &elem)) != SMS_SUCCESS)
+       com_err(program_name, status, " in get_user_by_uid");
+    
+    info = (char **) elem->q_data;
+    argv[1] = info[U_NAME];
 
+    (void) DeleteUser(argc, argv);
     return(DM_NORMAL);
-}
+} 
 
-/*     Function Name: ChangeUserQuota
- *     Description: This function allows all quotas to be updated for a user.
- *     Arguments: arg, argv - the name of the user in argv[1].
- *     Returns: DM_NORMAL.
- */
-
-/* ARGSUSED */
-int
-ChangeUserQuota(argc, argv)
-int argc;
-char *argv[];
-{
-    int status;
-    char error_buf[BUFSIZ];
-    struct qelem *elem, *local;
-    
-    elem = GetUserInfo(QUOTA, argv[1], (char *) NULL);
-
-    local = elem;
-    while (local != NULL) {
-       char **info;
-       info = (char **) local->q_data;
-       PrintQuota(info);
-       GetValueFromUser("New quota (in KB): ", &info[Q_QUOTA]);
-       
-       if (status = sms_query("update_nfs_quota", 3, info,
-                              Scream, (char *) NULL) != 0) {
-           com_err(program_name, status, " in update_nfs_quota");
-           sprintf(error_buf,"Could not perform quota change on %s",
-                   info[Q_FILESYS]); 
-           Put_message(error_buf);
-       }
-       local = local->q_forw;
-    }
-    FreeQueue(elem);
-    return (DM_NORMAL);
-}
+/* ------------------------- Show User Information ------------------------- */
 
 /*     Function Name: ShowUserByLogin
  *     Description: Shows user information given a login name.
@@ -537,10 +526,7 @@ char *argv[];
     struct qelem *top, *elem;
 
     elem = top = GetUserInfo(LOGIN, argv[1], (char *) NULL);
-    while (elem != NULL) {
-       PrintUserInfo( (char **) elem->q_data, FALSE);
-       elem = elem->q_forw;
-    }
+    Loop(elem, PrintUserInfo);
 
     FreeQueue(top);
     return (DM_NORMAL);
@@ -559,29 +545,29 @@ ShowUserByName(argc, argv)
 int argc;
 char *argv[];
 {
-    struct qelem *top, *elem;
+    struct qelem *top;
     char buf;
 
-    elem = top = GetUserInfo(BY_NAME, argv[1], argv[2]);
+    top = GetUserInfo(BY_NAME, argv[1], argv[2]);
 
-    if (!PromptWithDefault("Print full information, or just the names (F/N)?",
-                          &buf, 1, "F"))
+    if (top == NULL)           /* if there was an error then return. */
        return(DM_NORMAL);
 
-    while (elem != NULL) {
-       switch(buf) {
-       case 'F':
-       case 'f':
-           PrintUserInfo( (char **) elem->q_data, FALSE);
-           break;
-       case 'N':
-       case 'n':
-           PrintUserInfo( (char **) elem->q_data, TRUE);
-           break;
-       }
-       elem = elem->q_forw;
-    }
+    if (!PromptWithDefault("Print full information, or just the names (f/n)?",
+                          &buf, 1, "f"))
+       return(DM_NORMAL);
 
+    switch(buf) {
+    case 'F':
+    case 'f':
+       Loop(top, PrintUserInfo);
+       break;
+    case 'N':
+    case 'n':
+       Loop(top, PrintUserName);
+       break;
+    }
+    
     FreeQueue(top);
     return (DM_NORMAL);
 }
@@ -598,106 +584,15 @@ ShowUserByClass(argc, argv)
 int argc;
 char **argv;
 {
-    struct qelem *top, *elem;
+    struct qelem *top;
 
-    elem = top = GetUserInfo(CLASS, argv[1], (char *) NULL);
-
-    while (elem != NULL) {
-       PrintUserInfo( (char **) elem->q_data, TRUE);
-       elem = elem->q_forw;
-    }
+    top = GetUserInfo(CLASS, argv[1], (char *) NULL);
+    Loop(top, PrintUserName);
 
     FreeQueue(top);
     return (DM_NORMAL);
 }
 
-
-/*     Function Name: PrintQuota
- *     Description: Prints a users quota information.
- *     Arguments: info - a pointer to the quota information:
- *     Returns: none.
- */
-
-static void
-PrintQuota(info)
-char ** info;
-{
-    char buf[BUFSIZ];
-
-    sprintf(buf, "Machine: %s\t\tDirectory: %s\t\tQuota: %s",
-                  info[Q_MACHINE], info[Q_DIRECTORY], info[Q_QUOTA]);
-    Put_message(buf);
-}
-
-/*     Function Name: PrintPOBoxes
- *     Description: Yet another specialized print function.
- *     Arguments: argc, argv - 
- *                             argv[0] - login name.
- *                             argv[1] - type.
- *                             argv[2] - machine.
- *                             argv[3] - box name.
- *                 junk.  - NOT USED
- *     Returns: SMS_CONT
- */
-
-/* ARGSUSED */
-static int
-PrintPOBoxes(argc, argv, junk)
-int argc;
-char **argv;
-char * junk;
-{
-    char buf[BUFSIZ];
-    /* no newline 'cause Put_message adds one */
-
-    (void) sprintf(buf, "Address: %s@%s\t\tType: %s", argv[PO_BOX],
-                  argv[PO_MACHINE], argv[PO_TYPE]);
-    (void) Put_message(buf);
-
-    return (SMS_CONT);
-}
-
-/*     Function Name: PrintUserInfo
- *     Description: Prints Information about a user.
- *     Arguments: info - an argument list with the user information
- *                          in it.
- *                 name_only - if TRUE then print only the users name.
- *     Returns: none
- */
-
-static void
-PrintUserInfo(info, name_only)
-char ** info;
-Bool name_only;
-{
-    char buf[BUFSIZ];
-
-    if (name_only) {
-       sprintf(buf, "%s, %s %s", info[U_LAST],
-               info[U_FIRST], info[U_MIDDLE]);
-       sprintf(buf, "%-40s/tUser Name: %s", buf, info[U_NAME]);
-       Put_message(buf);
-    }
-    else {
-       (void) sprintf(buf, 
-                      "Login name: %-10s/tUser id: %-10s\tLogin shell %s",
-                      info[U_NAME], info[U_UID], info[U_SHELL]);
-       (void) Put_message(buf);
-       (void) sprintf(buf, "Full name: %s %s %s\tClass: %s", 
-                      info[U_FIRST], info[U_MIDDLE], 
-                      info[U_LAST], info[U_CLASS]);
-       (void) Put_message(buf);
-       (void) sprintf(buf,
-                      "Account status: %s\tEncrypted MIT ID number: %s",
-                      atoi(info[U_STATE]) ? "active" : "inactive",
-                      info[U_MITID]);
-       (void) Put_message(buf);
-       (void) sprintf(buf, "Last Modification by %s at %s with %s.",
-                      info[U_MODBY], info[U_MODTIME], info[U_MODWITH]);
-       (void) Put_message(buf);
-    }
-}
-
 /*
  * Local Variables:
  * mode: c
This page took 0.067246 seconds and 4 git commands to generate.