]> andersk Git - moira.git/blobdiff - clients/moira/user.c
tcsh is dead. Long live bash.
[moira.git] / clients / moira / user.c
index 4f0a1e279e76ee3815b4d2e1d90535a3e9dc0a75..0ed1762ec22f3a7ff710a5e87b3fd9fd7ed68fbe 100644 (file)
-#ifndef lint
-  static char rcsid_module_c[] = "$Header$";
-#endif lint
-
-/*     This is the file user.c for allmaint, the SMS client that allows
- *      a user to maintaint most important parts of the SMS database.
- *     It Contains: the functions for usermaint.
- *     
+/* $Id$
+ *
+ *     This is the file user.c for the Moira Client, which allows users
+ *      to quickly and easily maintain most parts of the Moira database.
+ *     It Contains: Functions for manipulating user information.
+ *
  *     Created:        5/9/88
  *     By:             Chris D. Peterson
  *
- *      $Source$
- *      $Author$
- *      $Header$
- *     
- *     Copyright 1987, 1988 by the Massachusetts Institute of Technology.
- *
- *     For further information on copyright and distribution 
- *     see the file mit-copyright.h
+ * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
-#include <stdio.h>
-#include <strings.h>
+#include <mit-copyright.h>
+#include <moira.h>
+#include <moira_site.h>
+#include "defs.h"
+#include "f_defs.h"
+#include "globals.h"
+
 #include <ctype.h>
-#include <sms.h>
-#include <menu.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
 
-#include "mit-copyright.h"
-#include "allmaint.h"
-#include "allmaint_funcs.h"
-#include "globals.h"
-#include "infodefs.h"
+#include <krb.h>
+
+RCSID("$Header$");
+
+void CorrectCapitalization(char **name);
+char **AskUserInfo(char **info, Bool name);
+struct mqelem *GetUserInfo(int type, char *name1, char *name2);
+static void PrintLogin(char **info);
+struct mqelem *GetUserBySponsor(char *type, char *name);
 
 #define LOGIN 0
 #define UID   1
-#define NAME  2
-#define QUOTA 3
-#define CLASS 4
+#define BY_NAME  2
+#define CLASS 3
+#define ID 4
+
+#ifdef ATHENA
+#define DEFAULT_SHELL "/bin/athena/bash"
+#else
+#define DEFAULT_SHELL "/bin/bash"
+#endif
+#define DEFAULT_CLASS "?"
+
+#define DEFAULT_WINCONSOLESHELL "cmd"
+#define DEFAULT_WINHOMEDIR "[DFS]"
+#define DEFAULT_WINPROFILEDIR "[DFS]"
+
+/*     Function Name: UserState
+ *     Description: Convert a numeric state into a descriptive string.
+ *     Arguments: state value
+ *     Returns: pointer to statically allocated string.
+ */
+
+static char *states[] = {
+  "Registerable (0)",
+  "Active (1)",
+  "Half Registered (2)",
+  "Deleted (3)",
+  "Not registerable (4)",
+  "Enrolled/Registerable (5)",
+  "Enrolled/Not Registerable (6)",
+  "Half Enrolled (7)",
+  "Registerable, Kerberos only (8)",
+  "Active, Kerberos only (9)"
+};
+
+static char *UserState(int state)
+{
+  static char buf[BUFSIZ];
+
+  if (state < 0 || state >= US_END)
+    {
+      sprintf(buf, "Unknown (%d)", state);
+      return buf;
+    }
+  return states[state];
+}
+
+
+/*     Function Name: PrintUserName
+ *     Description: Print name of a user.
+ *     Arguments: info - the information about a user.
+ *     Returns: none.
+ */
+
+static void PrintUserName(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(char **info)
+{
+  char name[BUFSIZ], buf[BUFSIZ], sponsor[BUFSIZ];
+  int status;
+
+  sprintf(name, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]);
+  sprintf(buf, "Login name: %-20s Full name: %s", info[U_NAME], name);
+  Put_message(buf);
+  sprintf(buf, "User id: %-23s Login shell: %-10s",
+         info[U_UID], info[U_SHELL]);
+  Put_message(buf);
+  sprintf(buf, "Class: %-25s Windows Console Shell: %-10s",
+         info[U_CLASS], info[U_WINCONSOLESHELL]);
+  Put_message(buf);
+  sprintf(sponsor, "%s %s", info[U_SPONSOR_TYPE], info[U_SPONSOR_NAME]);
+  sprintf(buf, "Sponsor: %-23s Expiration date: %s", sponsor,  info[U_EXPIRATION]);
+  Put_message(buf);
+  sprintf(buf, "Account is: %-20s MIT ID number: %s",
+         UserState(atoi(info[U_STATE])), info[U_MITID]);
+  Put_message(buf);
+  sprintf(buf, "Windows Home Directory: %s", info[U_WINHOMEDIR]);
+  Put_message(buf);
+  sprintf(buf, "Windows Profile Directory: %s", info[U_WINPROFILEDIR]);
+  Put_message(buf);
+  status = atoi(info[U_STATE]);
+  if (status == 0 || status == 2)
+    {
+      sprintf(buf, "User %s secure Account Coupon to register",
+             atoi(info[U_SECURE]) ? "needs" : "does not need");
+      Put_message(buf);
+    }
+  sprintf(buf, "Comments: %s", info[U_COMMENT]);
+  Put_message(buf);
+  sprintf(buf, "Created  by %s on %s.", info[U_CREATOR], info[U_CREATED]);
+  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(char **info)
+{
+  info[U_NAME] = strdup(UNIQUE_LOGIN);
+  info[U_UID] = strdup(UNIQUE_UID);
+  info[U_SHELL] = strdup(DEFAULT_SHELL);
+  info[U_WINCONSOLESHELL] = strdup(DEFAULT_WINCONSOLESHELL);
+  info[U_LAST] = strdup(DEFAULT_NONE);
+  info[U_FIRST] = strdup(DEFAULT_NONE);
+  info[U_MIDDLE] = strdup(DEFAULT_NONE);
+  info[U_STATE] = strdup(DEFAULT_NO);
+  info[U_MITID] = strdup(DEFAULT_NONE);
+  info[U_CLASS] = strdup(DEFAULT_CLASS);
+  info[U_COMMENT] = strdup("");
+  info[U_SIGNATURE] = strdup("");
+  info[U_SECURE] = strdup("0");
+  info[U_WINHOMEDIR] = strdup(DEFAULT_WINHOMEDIR);
+  info[U_WINPROFILEDIR] = strdup(DEFAULT_WINPROFILEDIR);
+  info[U_SPONSOR_TYPE] = strdup("NONE");
+  info[U_SPONSOR_NAME] = strdup("NONE");
+  info[U_EXPIRATION] = strdup("");
+  info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL;
+  info[U_CREATED] = info[U_CREATOR] = NULL;
+  return info;
+}
+
+
+/* Check that the supplied name follows the capitalization rules, and
+ * offer to correct it if not.
+ */
+
+void CorrectCapitalization(char **name)
+{
+  char temp_buf[BUFSIZ], fixname[BUFSIZ];
+
+  strcpy(fixname, *name);
+  FixCase(fixname);
+  if (strcmp(fixname, *name))
+    {
+      Put_message("You entered a name which does not follow the capitalization conventions.");
+      sprintf(temp_buf, "Correct it to \"%s\"", fixname);
+      if (YesNoQuestion(temp_buf, 0) == TRUE)
+       {
+         free(*name);
+         *name = strdup(fixname);
+       }
+    }
+}
 
-static void PrintQuota();      /* prints Quota info. */
-static void PrintUserInfo();   /* prints User info. */
-static int PrintPOBoxes();     /* prints PO Box information. */
 
 /*     Function Name: AskUserInfo.
- *     Description: This function askes the user for information about a 
+ *     Description: This function askes the user for information about a
  *                   machine and saves it into a structure.
  *     Arguments: info - a pointer the the structure to put the info into.
  *                 flags - Flags asking us which info we want.
@@ -51,499 +209,676 @@ static int PrintPOBoxes();       /* prints PO Box information. */
  *             use the #defined names (e.g args[UID] is not the uid anymore).
  */
 
-char **
-AskUserInfo(info, name)
-char ** info;
-Bool name;
-{
-    char temp_buf[BUFSIZ], *newname;
-
-    sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[NAME]);
-    Put_message(temp_buf);
-
-    if (name) {
-       newname = Strsave(info[U_NAME]);
-       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]);
-    
-    FreeAndClear(&info[U_MODTIME], TRUE);
-    FreeAndClear(&info[U_MODBY], TRUE);
-    FreeAndClear(&info[U_MODWITH], TRUE);
-
-/* 
- * Slide the newname into the #2 slot, this screws up all future references 
- * to this list, since we slip the pointer into a info list it gets freed 
- * when the rest of the list gets freed.
- */
-    if (name)                  
-       SlipInNewName(info, newname);
+char **AskUserInfo(char **info, Bool name)
+{
+  int state;
+  char temp_buf[BUFSIZ], *newname;
 
-    return(info);
+  if (name)
+    {
+      sprintf(temp_buf, "\nChanging Attributes of user %s.\n", info[U_NAME]);
+      Put_message(temp_buf);
+    }
+  else
+    {
+      struct mqelem *elem = NULL;
+      char *argv[3];
+
+      if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
+       return NULL;
+      CorrectCapitalization(&info[U_LAST]);
+      if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
+       return NULL;
+      CorrectCapitalization(&info[U_FIRST]);
+      if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR)
+       return NULL;
+      CorrectCapitalization(&info[U_MIDDLE]);
+      argv[0] = info[U_FIRST];
+      argv[1] = info[U_LAST];
+      if (do_mr_query("get_user_account_by_name", 2, argv,
+                     StoreInfo, &elem) == MR_SUCCESS)
+       {
+         Put_message("A user by that name already exists in the database.");
+         Loop(QueueTop(elem), PrintUserInfo);
+         Loop(QueueTop(elem), FreeInfo);
+         FreeQueue(elem);
+         if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
+           return NULL;
+       }
+    }
+  if (name)
+    {
+      newname = strdup(info[U_NAME]);
+      if (GetValueFromUser("The new login name for this user", &newname) ==
+         SUB_ERROR)
+       return NULL;
+    }
+  else if (GetValueFromUser("Login name for this user", &info[U_NAME]) ==
+          SUB_ERROR)
+    return NULL;
+
+  strcpy(temp_buf, info[U_UID]);
+  if (GetValueFromUser("User's UID", &info[U_UID]) == SUB_ERROR)
+    return NULL;
+  if (strcmp(info[U_UID], UNIQUE_UID) && strcmp(info[U_UID], temp_buf))
+    {
+      struct mqelem *elem = NULL;
+      if (do_mr_query("get_user_account_by_uid", 1, &info[U_UID],
+                     StoreInfo, &elem) == MR_SUCCESS)
+       {
+         Put_message("A user with that uid already exists in the database.");
+         Loop(QueueTop(elem), PrintUserInfo);
+         Loop(QueueTop(elem), FreeInfo);
+         FreeQueue(elem);
+         if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
+           return NULL;
+       }
+    }
+
+  if (GetValueFromUser("User's shell", &info[U_SHELL]) == SUB_ERROR)
+    return NULL;
+  if (GetValueFromUser("Windows console shell", &info[U_WINCONSOLESHELL])
+      == SUB_ERROR)
+    return NULL;
+  if (name)
+    {
+      if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
+       return NULL;
+      CorrectCapitalization(&info[U_LAST]);
+      if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
+       return NULL;
+      CorrectCapitalization(&info[U_FIRST]);
+      if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR)
+       return NULL;
+      CorrectCapitalization(&info[U_MIDDLE]);
+    }
+  while (1)
+    {
+      int i;
+      if (GetValueFromUser("User's status (? for help)", &info[U_STATE]) ==
+         SUB_ERROR)
+       return NULL;
+      if (isdigit(info[U_STATE][0]))
+       break;
+      Put_message("Valid status numbers:");
+      for (i = 0; i < US_END; i++)
+       {
+         sprintf(temp_buf, "  %d: %s", i, states[i]);
+         Put_message(temp_buf);
+       }
+    }
+  if (GetValueFromUser("User's MIT ID number", &info[U_MITID]) == SUB_ERROR)
+    return NULL;
+  RemoveHyphens(info[U_MITID]);
+  if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) ==
+      SUB_ERROR)
+    return NULL;
+  if (GetValueFromUser("Comments", &info[U_COMMENT]) == SUB_ERROR)
+    return NULL;
+
+  if (GetValueFromUser("Windows Home Directory", &info[U_WINHOMEDIR]) ==
+      SUB_ERROR)
+    return NULL;
+
+  if (GetValueFromUser("Windows Profile Directory", &info[U_WINPROFILEDIR]) ==
+      SUB_ERROR)
+    return NULL;
+
+  if (GetTypeFromUser("User's sponsor type", "ace_type", &info[U_SPONSOR_TYPE])
+      == SUB_ERROR)
+    return NULL;
+  if (strcmp(info[U_SPONSOR_TYPE], "NONE") &&
+      GetValueFromUser("Sponsor's Name", &info[U_SPONSOR_NAME]) == SUB_ERROR)
+    return NULL;
+
+  if (GetValueFromUser("Expiration date", &info[U_EXPIRATION]) == SUB_ERROR)
+    return NULL;
+
+  state = atoi(info[U_STATE]);
+  if (!name || state == 0 || state == 2)
+    {
+      if (YesNoQuestion("User needs secure Account Coupon to register",
+                       atoi(info[U_SECURE]) ? TRUE : FALSE) == FALSE)
+       {
+         free(info[U_SECURE]);
+         info[U_SECURE] = strdup("0");
+       }
+      else
+       {
+         free(info[U_SECURE]);
+         info[U_SECURE] = strdup("1");
+       }
+    }
+
+  info[U_SIGNATURE] = strdup("");
+
+  FreeAndClear(&info[U_MODTIME], TRUE);
+  FreeAndClear(&info[U_MODBY], TRUE);
+  FreeAndClear(&info[U_MODWITH], TRUE);
+
+  /*
+   * Slide the newname into the #2 slot, this screws up all future references
+   * to this list, since we slip the pointer into a info list it gets freed
+   * when the rest of the list gets freed.
+   */
+  if (name)
+    SlipInNewName(info, newname);
+
+  return info;
 }
 
 /*     Function Name: GetUserInfo
  *     Description: Stores the user information in a queue.
  *     Arguments: type - type of field given to get info, one of:
- *                        LOGIN, UID, NAME, CLASS.
+ *                        LOGIN, UID, BY_NAME, CLASS.
  *                 name1 - name of thing specified by type (wildcards okay)
  *                 name2 - other name, only used in get user by first and last.
  *                         (wildcards okay).
  *     Returns: the first element of the queue containing the user info.
+ *
  */
 
-struct qelem *
-GetUserInfo(type, name1, name2)
-int type;
-char *name1, *name2;
+struct mqelem *GetUserInfo(int type, char *name1, char *name2)
 {
-    char * args[2];
-    register int status;
-    struct qelem * elem = NULL;
+  char *args[2];
+  int status;
+  struct mqelem *elem = NULL;
 
-    switch(type) {
+  switch (type)
+    {
     case LOGIN:
-       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.");
-           return (NULL);               
+      args[0] = name1;
+      if ((status = do_mr_query("get_user_account_by_login", 1, args,
+                               StoreInfo, &elem)))
+       {
+         com_err(program_name, status,
+                 " when attempting to get_user_account_by_login.");
+         return NULL;
        }
-       break;
+      break;
     case UID:
-       args[0] = name1;
-       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.");
-           return (NULL);      
+      args[0] = name1;
+      if ((status = do_mr_query("get_user_account_by_uid", 1, args,
+                               StoreInfo, &elem)))
+       {
+         com_err(program_name, status,
+                 " when attempting to get_user_account_by_uid.");
+         return NULL;
        }
-       break;
-    case NAME:
-       args[0] = name1;
-       args[1] = name2;    
-       if ( (status = sms_query("get_user_by_name", 1, args,
-                              StoreInfo, (char *) &elem)) != 0) {
-           com_err(program_name, status, 
-                   " when attempting to get_use_by_name.");
-           return (NULL);      
+      break;
+    case BY_NAME:
+      args[0] = name1;
+      args[1] = name2;
+      if ((status = do_mr_query("get_user_account_by_name", 2, args,
+                               StoreInfo, &elem)))
+       {
+         com_err(program_name, status,
+                 " when attempting to get_user_account_by_name.");
+         return NULL;
        }
-       break;
+      break;
     case CLASS:
-       args[0] = name1;
-       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.");
-           return (NULL);      
+      args[0] = name1;
+      if ((status = do_mr_query("get_user_account_by_class", 1, args,
+                               StoreInfo, &elem)))
+       {
+         com_err(program_name, status,
+                 " when attempting to get_user_account_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;
+    case ID:
+      args[0] = name1;
+      if ((status = do_mr_query("get_user_account_by_id", 1, args,
+                               StoreInfo, &elem)))
+       {
+         com_err(program_name, status,
+                 " when attempting to get_user_account_by_id.");
+         return NULL;
        }
-       break;
+      break;
     }
-    return( QueueTop(elem) );
+  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;
-{
-    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;
+int AddNewUser(int argc, char **argv)
+{
+  int status;
+  char **args, *info[MAX_ARGS_SIZE];
+
+  if (!(args = AskUserInfo(SetUserDefaults(info), FALSE)))
+    {
+      Put_message("Aborted.");
+      return DM_NORMAL;
     }
-    FreeQueue(elem);
-    return(DM_NORMAL);
+  if ((status = do_mr_query("add_user_account", CountArgs(args),
+                           args, NULL, NULL)))
+    com_err(program_name, status, " in add_user_account");
+  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(void)
 {
-    int status;
-    char * type;
-    struct qelem *top, *elem = NULL;
+  char *name;
+
+  name = strdup("");
+  if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR)
+    return NULL;
+  Put_message("KERBEROS code not added, did not reserve name with kerberos.");
+  return name;
+}
 
-    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);
-    }
 
-    top = elem = QueueTop(elem);
-    while (elem != NULL) {
-       char ** info = (char **) elem->q_data;
-       if (strcmp (info[1], machine) == 0) {
-           FreeQueue(top);
-           return( Strsave("POP") );
+/*     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.
+ */
+
+static char *ChooseUser(struct mqelem *elem)
+{
+  while (elem)
+    {
+      char **info = elem->q_data;
+      PrintUserInfo(info);
+      switch (YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE))
+       {
+       case TRUE:
+         return strdup(info[U_UID]);
+       case FALSE:
+         break;
+       default:                /* quit or ^C. */
+         return NULL;
        }
-       elem = elem->q_forw;
+      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;
-{
-    register int status;
-    struct qelem * poqueue, *local;
-    char *type, buf[BUFSIZ], *pohost;
-    static char *po[4];
-    poqueue = NULL;
-
-    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.");
-    
-    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); 
+static char *GetUidNumberFromName(void)
+{
+  char *args[5], *uid, first[BUFSIZ], last[BUFSIZ];
+  int status;
+  struct mqelem *top = NULL;
+
+  if (!Prompt_input("First Name: ", first, BUFSIZ))
+    return NULL;
+  if (!Prompt_input("Last  Name: ", last, BUFSIZ))
+    return NULL;
+  FixCase(first);
+  FixCase(last);
+
+  args[0] = first;
+  args[1] = last;
+
+  switch ((status = do_mr_query("get_user_account_by_name", 2, args,
+                               StoreInfo, &top)))
+    {
+    case MR_SUCCESS:
+      break;
+    case MR_NO_MATCH:
+      Put_message("There is no user in the database with that name.");
+      return NULL;
+    default:
+      com_err(program_name, status, " in get_account_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 = top->q_data;
+      Put_message("User ID Number retrieved for the user: ");
+      Put_message("");
+      PrintUserName(info);
+      uid = strdup(info[U_UID]);
+      FreeQueue(top);
+      return strdup(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(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");
+  name = name;                 /* make saber happy. */
+  Put_message("Kerberos password not changed, code non-existant.");
+  /* clever message to call account_admin, if this fails. */
+}
 
-    return(DM_NORMAL);
-} 
+/*     Function Name:  GiveBackLogin
+ *     Description: Gives back previously reserved kerberous principle.
+ *     Arguments: name - principle to give back.
+ *     Returns: void.
+ */
 
-/* ------------------------- Show Quota Info ------------------------- */
+static void GiveBackLogin(char *name)
+{
+  name = name;                 /* make saber happy. */
+  Put_message("kerberos code not implemented, name not given back.");
+  /* send mail to db maintainer if this fails. */
+}
 
-/*     Function Name: ShowDefaultQuota
- *     Description: This prints out a default quota for the system.
- *     Arguments: none
+/*     Function Name: RegisterUser
+ *     Description: This function registers a user.
+ *     Arguments: none.
  *     Returns: DM_NORMAL.
  */
 
-int
-ShowDefaultQuota()
+int RegisterUser(int argc, char **argv)
 {
-    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");
+  char *args[MAX_ARGS_SIZE];
+  char *login, *potype = NULL;
+  char temp_buf[BUFSIZ];
+  int status, i;
+
+  for (i = 0; i < MAX_ARGS_SIZE; i++)
+    args[i] = NULL;
+
+  Put_message("This function has NO kerberos support, so strange 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] = strdup(temp_buf);
+      break;
+    case FALSE:
+      if (!(args[0] = GetUidNumberFromName()))
+       return DM_NORMAL;
+      break;
+    default:
+      return DM_NORMAL;
+    }
 
-    return (DM_NORMAL);
+  sprintf(temp_buf, "u%s", args[0]);
+  login = strdup(temp_buf);
+  if (GetValueFromUser("Login name for this user? ", &login) == SUB_ERROR)
+    {
+      args[1] = login;
+      FreeInfo(args);     /* This work because the NULL temination is ok. */
+      return DM_NORMAL;
+    }
+  Put_message("KERBEROS code not added, did not reserve name with kerberos.");
+  args[1] = login;
+  
+  sprintf(temp_buf, "IMAP");
+  potype = strdup(temp_buf);
+  if (GetValueFromUser("P.O. Box Type for this user? ", &potype) == SUB_ERROR)
+    {
+      args[2] = potype;
+      FreeInfo(args);
+      return DM_NORMAL;
+    }
+  if (strcmp(potype, "POP") && strcmp(potype, "IMAP") && strcmp(potype, "EXCHANGE"))
+    {
+      sprintf(temp_buf, "Unknown P.O. Box type.");
+      Put_message(temp_buf);
+      FreeInfo(args);
+      return DM_NORMAL;
+    }
+  args[2] = potype;
+  args[3] = NULL;
+
+  switch ((status = do_mr_query("register_user", CountArgs(args),
+                               args, NULL, NULL)))
+    {
+    case MR_SUCCESS:
+      sprintf(temp_buf, "User %s successfully registered.", login);
+      Put_message(temp_buf);
+      SetUserPassword(login);
+      break;
+    case MR_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: ShowUserQuota
- *     Description: Shows the quota of a user.
- *     Arguments: argc, argv - users login name is 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
-ShowUserQuota(argc, argv)
-int argc;
-char **argv;
+static void RealUpdateUser(char **info, Bool junk)
 {
-    struct qelem *elem, *top;
-    top = elem = GetUserInfo(QUOTA, argv[1], (char *) NULL);
-    
-    while (elem != NULL) {
-       char ** info = (char **) elem->q_data;
-       PrintQuota(info);
-       elem = elem->q_forw;
+  int status;
+  char error_buf[BUFSIZ];
+  char **args = AskUserInfo(info, TRUE);
+
+  if (!args)
+    {
+      Put_message("Aborted.");
+      return;
+    }
+  if ((status = do_mr_query("update_user_account", CountArgs(args),
+                           args, NULL, NULL)))
+    {
+      com_err(program_name, status, " in ModifyFields");
+      sprintf(error_buf, "User %s not updated due to errors.", info[NAME]);
+      Put_message(error_buf);
     }
-    FreeQueue(top);
-    return (DM_NORMAL);
 }
 
-/*     Function Name: ChangeDefaultQuota
- *     Description: Changes the System Wide default quota.
- *     Arguments: argc, argv - New quota in argv[1].
+/*     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*/
-int
-ChangeDefaultQuota(argc, argv)
-int argc;
-char *argv[];
-{
-    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");
-    }
-    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.
- *     Returns: DM_NORMAL.
+int UpdateUser(int argc, char **argv)
+{
+  struct mqelem *elem;
+
+  elem = GetUserInfo(LOGIN, argv[1], NULL);
+  QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user");
+
+  FreeQueue(elem);
+  return DM_NORMAL;
+}
+
+/*     Function Name: RealDeactivateUser
+ *     Description: sets the user's status to 3.
+ *     Arguments: info - all current information for the user fields
+ *                one_item - indicates the user hasn't been queried yet
+ *     Returns: none.
  */
 
-/*ARGSUSED*/
-int
-AddUserLocker(argc, argv)
-int argc;
-char **argv;
+static void RealDeactivateUser(char **info, Bool one_item)
 {
-    int status;
-    char *args[4];
+  int status;
+  char txt_buf[BUFSIZ];
+  char *qargs[2], **args;
+  struct mqelem *elem = NULL;
+
+  if (one_item)
+    {
+      sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]);
+      if (YesNoQuestion(txt_buf, FALSE) != TRUE)
+       return;
+    }
 
-    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];
+  qargs[0] = info[NAME];
+  qargs[1] = "3";
+  if ((status = do_mr_query("update_user_status", 2, qargs, NULL, NULL)))
+    {
+      com_err(program_name, status, " in update_user_status");
+      sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]);
+      Put_message(txt_buf);
     }
-    
-    if (status = sms_query("add_locker", 4, args, Scream, NULL) != 0)
-       com_err(program_name, status, " in add_user_locker");
+  else if (YesNoQuestion("Also deactivate matching list and filesystem (y/n)",
+                        FALSE) == TRUE)
+    {
+      status = do_mr_query("get_list_info", 1, &(info[NAME]), StoreInfo,
+                          &elem);
+      if (status == MR_SUCCESS)
+       {
+         args = QueueTop(elem)->q_data;
+         free(args[L_ACTIVE]);
+         args[L_ACTIVE] = strdup("0");
+         FreeAndClear(&args[L_MODTIME], TRUE);
+         FreeAndClear(&args[L_MODBY], TRUE);
+         FreeAndClear(&args[L_MODWITH], TRUE);
+         SlipInNewName(args, strdup(args[L_NAME]));
+         if ((status = do_mr_query("update_list", CountArgs(args), args,
+                                   NULL, NULL)))
+           {
+             com_err(program_name, status, " updating list, "
+                     "not deactivating list or filesystem");
+             FreeInfo(args);
+             FreeQueue(elem);
+             return;
+           }
+         FreeInfo(args);
+         FreeQueue(elem);
+         elem = NULL;
+       }
+      else if (status != MR_NO_MATCH)
+       {
+         com_err(program_name, status, " getting list info, "
+                 "not deactivating list or filesystem");
+         return;
+       }
 
-    return(DM_NORMAL);
+      if ((status = do_mr_query("get_filesys_by_label", 1, &(info[NAME]),
+                               StoreInfo, &elem)))
+       {
+         com_err(program_name, status, " getting filsys info, "
+                 "not deactivating filesystem");
+         return;
+       }
+      args = QueueTop(elem)->q_data;
+      free(args[FS_TYPE]);
+      args[FS_TYPE] = strdup("ERR");
+      free(args[FS_COMMENTS]);
+      args[FS_COMMENTS] = strdup("Locker disabled; call 3-1325 for help");
+      FreeAndClear(&args[FS_MODTIME], TRUE);
+      FreeAndClear(&args[FS_MODBY], TRUE);
+      FreeAndClear(&args[FS_MODWITH], TRUE);
+      SlipInNewName(args, strdup(args[FS_NAME]));
+      if ((status = do_mr_query("update_filesys", CountArgs(args), args,
+                               NULL, NULL)))
+       {
+         com_err(program_name, status, " updating filesystem, "
+                 "not deactivating filesystem");
+         FreeInfo(args);
+         FreeQueue(elem);
+         return;
+       }
+      FreeInfo(args);
+      FreeQueue(elem);
+    }
 }
 
-/* needs to be fixed - CDP 6/10/88 */
 
-/*     Function Name: DeleteUserLocker
- *     Description: Deletes a locker - BOOM.
- *     Arguments: arc, argv - the name of the locker in argv[1]/
+/*     Function Name: DeactivateUser
+ *     Description: sets the user's status to 3.
+ *     Arguments: argc, argv - login name of the user in argv[1].
  *     Returns: DM_NORMAL.
  */
 
-/*ARGSUSED*/
-int
-DeleteUserLocker(argc, argv)
-int argc;
-char **argv;
+int DeactivateUser(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 mqelem *elem;
+
+  elem = GetUserInfo(LOGIN, argv[1], NULL);
+  QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user");
 
-    return(DM_NORMAL);
+  FreeQueue(elem);
+  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].
+
+/* ------------------------- Top Menu ------------------------- */
+
+/* DeleteUser() 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.
+ *      NOTES: This just gets the username from the mr server
+ *             and performs a DeleteUser().
  */
 
-/* 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);
+int DeleteUserByUid(int argc, char **argv)
+{
+  int status;
+  struct mqelem *elem = NULL;
+  char **info;
+
+  if (!ValidName(argv[1]))
+    return DM_NORMAL;
+
+  if ((status = do_mr_query("get_user_account_by_uid", 1, argv + 1, StoreInfo,
+                           &elem)))
+    com_err(program_name, status, " in get_user_account_by_uid");
+
+  info = elem->q_data;
+  argv[1] = info[U_NAME];
+
+  DeleteUser(argc, argv);
+  return DM_NORMAL;
 }
 
+/* ------------------------- Show User Information ------------------------- */
+
 /*     Function Name: ShowUserByLogin
  *     Description: Shows user information given a login name.
  *     Arguments: argc, argv - login name in argv[1].
  *     Returns: DM_NORMAL
  */
 
-/* ARGSUSED */
-int
-ShowUserByLogin(argc, argv)
-int argc;
-char *argv[];
+int ShowUserByLogin(int argc, char *argv[])
 {
-    struct qelem *top, *elem;
+  struct mqelem *top, *elem;
 
-    elem = top = GetUserInfo(LOGIN, argv[1], (char *) NULL);
-    while (elem != NULL) {
-       PrintUserInfo( (char **) elem->q_data, FALSE);
-       elem = elem->q_forw;
-    }
+  elem = top = GetUserInfo(LOGIN, argv[1], NULL);
+  Loop(elem, PrintUserInfo);
 
-    FreeQueue(top);
-    return (DM_NORMAL);
+  FreeQueue(top);
+  return DM_NORMAL;
 }
 
 /*     Function Name: RetrieveUserByName
@@ -553,37 +888,34 @@ char *argv[];
  *     Returns: DM_NORMAL.
  */
 
-/* ARGSUSED */
-int
-ShowUserByName(argc, argv)
-int argc;
-char *argv[];
-{
-    struct qelem *top, *elem;
-    char buf;
-
-    elem = top = GetUserInfo(NAME, argv[1], argv[2]);
-
-    if (!PromptWithDefault("Print full information, or just the names (F/N)?",
-                          &buf, 1, "F"))
-       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;
+int ShowUserByName(int argc, char *argv[])
+{
+  struct mqelem *top;
+  char buf[BUFSIZ];
+
+  top = GetUserInfo(BY_NAME, argv[1], argv[2]);
+
+  if (!top)            /* if there was an error then return. */
+    return DM_NORMAL;
+
+  if (!PromptWithDefault("Print full information, or just the names (f/n)?",
+                        buf, 2, "f"))
+    return DM_NORMAL;
+
+  switch (buf[0])
+    {
+    case 'F':
+    case 'f':
+      Loop(top, PrintUserInfo);
+      break;
+    case 'N':
+    case 'n':
+      Loop(top, PrintUserName);
+      break;
     }
 
-    FreeQueue(top);
-    return (DM_NORMAL);
+  FreeQueue(top);
+  return DM_NORMAL;
 }
 
 /*     Function Name: ShowUserByClass
@@ -592,119 +924,312 @@ char *argv[];
  *     Returns: none.
  */
 
-/* ARGSUSED */
-int
-ShowUserByClass(argc, argv)
-int argc;
-char **argv;
+int ShowUserByClass(int argc, char **argv)
 {
-    struct qelem *top, *elem;
+  struct mqelem *top;
+
+  if (YesNoQuestion("This will take a long time.  Are you sure", 0) == FALSE)
+    return DM_NORMAL;
+  top = GetUserInfo(CLASS, argv[1], NULL);
+  Loop(top, PrintUserName);
+
+  FreeQueue(top);
+  return DM_NORMAL;
+}
+
+
+/*     Function Name: ShowUserById
+ *     Description: Shows user information given an ID number.
+ *     Arguments: argc, argv - ID number in argv[1].
+ *     Returns: DM_NORMAL
+ */
+
+int ShowUserById(int argc, char *argv[])
+{
+  struct mqelem *top, *elem;
+
+  elem = top = GetUserInfo(ID, argv[1], NULL);
+  Loop(elem, PrintUserInfo);
+
+  FreeQueue(top);
+  return DM_NORMAL;
+}
+
 
-    elem = top = GetUserInfo(CLASS, argv[1], (char *) NULL);
+/*     Function Name: GetKrbmap
+ *     Description: Shows user <-> Kerberos mappings
+ *     Arguments: argc, argv - argv[1] contains the user login name,
+ *             argv[2] contains the principal
+ *     Returns: none.
+ */
 
-    while (elem != NULL) {
-       PrintUserInfo( (char **) elem->q_data, TRUE);
-       elem = elem->q_forw;
+int GetKrbmap(int argc, char **argv)
+{
+  int stat;
+  struct mqelem *elem = NULL, *top;
+  char buf[BUFSIZ];
+
+  if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1],
+                         StoreInfo, &elem)))
+    {
+      com_err(program_name, stat, " in GetKrbMap.");
+      return DM_NORMAL;
     }
 
-    FreeQueue(top);
-    return (DM_NORMAL);
+  top = elem = QueueTop(elem);
+  Put_message("");
+  while (elem)
+    {
+      char **info = elem->q_data;
+      sprintf(buf, "User: %-9s Principal: %s",
+             info[KMAP_USER], info[KMAP_PRINCIPAL]);
+      Put_message(buf);
+      elem = elem->q_forw;
+    }
+
+  FreeQueue(QueueTop(top));
+  return DM_NORMAL;
 }
 
 
-/*     Function Name: PrintQuota
- *     Description: Prints a users quota information.
- *     Arguments: info - a pointer to the quota information:
+/*     Function Name: AddKrbmap
+ *     Description: Add a new user <-> Kerberos mapping
+ *     Arguments: argc, argv - argv[1] contains the user login name,
+ *             argv[2] contains the principal
  *     Returns: none.
  */
 
-static void
-PrintQuota(info)
-char ** info;
+int AddKrbmap(int argc, char **argv)
 {
-    char buf[BUFSIZ];
+  int stat;
 
-    sprintf(buf, "Machine: %s\t\tDirectory: %s\t\tQuota: %s",
-                  info[Q_MACHINE], info[Q_DIRECTORY], info[Q_QUOTA]);
-    Put_message(buf);
+  if (!strchr(argv[KMAP_PRINCIPAL + 1], '@'))
+    {
+      Put_message("Please specify a realm for the kerberos principal.");
+      return DM_NORMAL;
+    }
+  if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1],
+                         NULL, NULL)))
+    {
+      com_err(program_name, stat, " in AddKrbMap.");
+      if (stat == MR_EXISTS)
+       Put_message("No user or principal may have more than one mapping.");
+    }
+  return DM_NORMAL;
 }
 
-/*     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
+
+/*     Function Name: DeleteKrbmap
+ *     Description: Remove a user <-> Kerberos mapping
+ *     Arguments: argc, argv - argv[1] contains the user login name,
+ *             argv[2] contains the principal
+ *     Returns: none.
  */
 
-/* ARGSUSED */
-static int
-PrintPOBoxes(argc, argv, junk)
-int argc;
-char **argv;
-char * junk;
+int DeleteKrbmap(int argc, char **argv)
 {
-    char buf[BUFSIZ];
-    /* no newline 'cause Put_message adds one */
+  int stat;
 
-    (void) sprintf(buf, "Address: %s@%s\t\tType: %s", argv[PO_BOX],
-                  argv[PO_MACHINE], argv[PO_TYPE]);
-    (void) Put_message(buf);
+  if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1],
+                         NULL, NULL)))
+    com_err(program_name, stat, " in DeleteKrbMap.");
+  return DM_NORMAL;
+}
 
-    return (SMS_CONT);
+int GetUserReservations(int argc, char **argv)
+{
+  int stat;
+  struct mqelem *elem = NULL, *top;
+  char buf[BUFSIZ];
+
+  if ((stat = do_mr_query("get_user_reservations", 1, &argv[1],
+                         StoreInfo, &elem)))
+    {
+      com_err(program_name, stat, " in GetUserReservations.");
+      return DM_NORMAL;
+    }
+
+  top = elem = QueueTop(elem);
+  Put_message("");
+  if (!elem)
+    Put_message("No reservations for that user.");
+  while (elem)
+    {
+      char **info = elem->q_data;
+      sprintf(buf, "Reservation: %s", info[0]);
+      Put_message(buf);
+      elem = elem->q_forw;
+    }
+
+  FreeQueue(QueueTop(top));
+  return DM_NORMAL;  
 }
 
-/*     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
- */
+int AddUserReservation(int argc, char **argv)
+{
+  int stat;
+  char buf[BUFSIZ];
+  
+  switch (stat = do_mr_query("add_user_reservation", 2, &argv[1],
+                            NULL, NULL))
+    {
+    case MR_SUCCESS:
+      break;
+    case MR_STRING:
+      sprintf(buf, "The reservation %s is not valid.", argv[2]);
+      Put_message(buf);
+      PrintReservationTypes();
+      break;
+    default:
+      com_err(program_name, stat, " in AddUserReservation.");
+      break;
+    }
+  
+  return DM_NORMAL;
+}
 
-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
- * c-indent-level: 4
- * c-continued-statement-offset: 4
- * c-brace-offset: -4
- * c-argdecl-indent: 4
- * c-label-offset: -4
- * End:
- */
+int DelUserReservation(int argc, char **argv)
+{
+  int stat;
+  char buf[BUFSIZ];
+
+  switch (stat = do_mr_query("delete_user_reservation", 2, &argv[1],
+                    NULL, NULL))
+    {
+    case MR_SUCCESS:
+      break;
+    case MR_STRING:
+      sprintf(buf, "The reservation %s is not valid.", argv[2]);
+      Put_message(buf);
+      PrintReservationTypes();
+      break;
+    default:
+      com_err(program_name, stat, " in DelUserReservation.");
+      break;
+    }
+  
+  return DM_NORMAL;
+}
+
+int GetUserByReservation(int argc, char **argv)
+{
+  int stat;
+  struct mqelem *elem = NULL, *top;
+  char buf[BUFSIZ];
+
+  switch (stat = do_mr_query("get_user_by_reservation", 1, &argv[1],
+                    StoreInfo, &elem))
+    {
+    case MR_SUCCESS:
+      break;
+    case MR_STRING:
+      sprintf(buf, "The reservation %s is not valid.", argv[1]);
+      Put_message(buf);
+      PrintReservationTypes();
+      return DM_NORMAL;
+    default:
+      com_err(program_name, stat, " in GetUserByReservation.");
+      return DM_NORMAL;
+    }
+  
+  top = elem = QueueTop(elem);
+  Put_message("");
+  while (elem)
+    {
+      char **info = elem->q_data;
+      sprintf(buf, "User: %s", info[0]);
+      Put_message(buf);
+      elem = elem->q_forw;
+    }
+
+  FreeQueue(QueueTop(top));
+  return DM_NORMAL;  
+}
+
+void PrintReservationTypes(void)
+{
+  int stat;
+  struct mqelem *elem = NULL, *top;
+  char buf[BUFSIZ];
+  char *qargs[2];
+
+  Put_message("Valid types of reservations are: ");
+  Put_message("");
+  qargs[0] = "*";
+  qargs[1] = "RESERVE";
+  qargs[2] = "*";
+  if ((stat = do_mr_query("get_alias", 3, &qargs[0],
+                         StoreInfo, &elem)))
+    {
+      com_err(program_name, stat, "in PrintReservationTypes.");
+    }
+  top = elem = QueueTop(elem);
+  while (elem)
+    {
+      char **info = elem->q_data;
+      sprintf(buf, "%s", info[2]);
+      Put_message(buf);
+      elem = elem->q_forw;
+    }
+
+  FreeQueue(QueueTop(top));  
+}
+
+int UserBySponsor(int argc, char **argv)
+{
+  char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name;
+  struct mqelem *top;
+
+  type = strdup("USER");
+  if (GetTypeFromUser("Type of sponsor", "search_ace_type", &type) == SUB_ERROR)
+    return DM_NORMAL;
+
+  sprintf(buf, "Name of %s", type);
+  name = strdup(user);
+  if (GetValueFromUser(buf, &name) == SUB_ERROR)
+    return DM_NORMAL;
+
+  switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE))
+    {
+    case TRUE:
+      sprintf(temp_buf, "R%s", type);     /* "USER to "RUSER", etc. */
+      free(type);
+      type = strdup(temp_buf);
+      break;
+    case FALSE:
+      break;
+    default:
+      return DM_NORMAL;
+    }
+
+  top = GetUserBySponsor(type, name);
+  Loop(top, PrintLogin);
+
+  FreeQueue(top);
+  return DM_NORMAL;
+}
+
+static void PrintLogin(char **info)
+{
+     char buf[BUFSIZ];
+
+     sprintf(buf, "Login: %s", info[U_NAME]);
+     Put_message(buf);
+}
+
+struct mqelem *GetUserBySponsor(char *type, char *name)
+{
+  char *args[2];
+  struct mqelem *elem = NULL;
+  int status;
+
+  args[0] = type;
+  args[1] = name;
+  if ((status = do_mr_query("get_user_account_by_sponsor", 2, args, StoreInfo,
+                           &elem)))
+    {
+      com_err(program_name, status, " in get_user_account_by_sponsor");
+      return NULL;
+    }
+  return QueueTop(elem);
+}
This page took 0.100072 seconds and 4 git commands to generate.