3 * This is the file user.c for the Moira Client, which allows users
4 * to quickly and easily maintain most parts of the Moira database.
5 * It Contains: Functions for manipulating user information.
8 * By: Chris D. Peterson
10 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
11 * For copying and distribution information, please see the file
15 #include <mit-copyright.h>
17 #include <moira_site.h>
32 void CorrectCapitalization(char **name);
33 char **AskUserInfo(char **info, Bool name);
34 struct mqelem *GetUserInfo(int type, char *name1, char *name2);
35 static void PrintLogin(char **info);
36 struct mqelem *GetUserBySponsor(char *type, char *name);
45 #define DEFAULT_SHELL "/bin/athena/tcsh"
47 #define DEFAULT_SHELL "/bin/csh"
49 #define DEFAULT_CLASS "?"
51 #define DEFAULT_WINCONSOLESHELL "cmd"
52 #define DEFAULT_WINHOMEDIR "[DFS]"
53 #define DEFAULT_WINPROFILEDIR "[DFS]"
55 /* Function Name: UserState
56 * Description: Convert a numeric state into a descriptive string.
57 * Arguments: state value
58 * Returns: pointer to statically allocated string.
61 static char *states[] = {
64 "Half Registered (2)",
66 "Not registerable (4)",
67 "Enrolled/Registerable (5)",
68 "Enrolled/Not Registerable (6)",
70 "Registerable, Kerberos only (8)",
71 "Active, Kerberos only (9)"
74 static char *UserState(int state)
76 static char buf[BUFSIZ];
78 if (state < 0 || state >= US_END)
80 sprintf(buf, "Unknown (%d)", state);
87 /* Function Name: PrintUserName
88 * Description: Print name of a user.
89 * Arguments: info - the information about a user.
93 static void PrintUserName(char **info)
95 char buf[BUFSIZ], print_buf[BUFSIZ];
96 sprintf(buf, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]);
97 sprintf(print_buf, "%-40s User Name: %s", buf, info[U_NAME]);
98 Put_message(print_buf);
101 /* Function Name: PrintUserInfo
102 * Description: Prints Information about a user.
103 * Arguments: info - an argument list with the user information
108 static void PrintUserInfo(char **info)
110 char name[BUFSIZ], buf[BUFSIZ], sponsor[BUFSIZ];
113 sprintf(name, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]);
114 sprintf(buf, "Login name: %-20s Full name: %s", info[U_NAME], name);
116 sprintf(buf, "User id: %-23s Login shell: %-10s",
117 info[U_UID], info[U_SHELL]);
119 sprintf(buf, "Class: %-25s Windows Console Shell: %-10s",
120 info[U_CLASS], info[U_WINCONSOLESHELL]);
122 sprintf(sponsor, "%s %s", info[U_SPONSOR_TYPE], info[U_SPONSOR_NAME]);
123 sprintf(buf, "Sponsor: %-23s Expiration date: %s", sponsor, info[U_EXPIRATION]);
125 sprintf(buf, "Account is: %-20s MIT ID number: %s",
126 UserState(atoi(info[U_STATE])), info[U_MITID]);
128 sprintf(buf, "Windows Home Directory: %s", info[U_WINHOMEDIR]);
130 sprintf(buf, "Windows Profile Directory: %s", info[U_WINPROFILEDIR]);
132 status = atoi(info[U_STATE]);
133 if (status == 0 || status == 2)
135 sprintf(buf, "User %s secure Account Coupon to register",
136 atoi(info[U_SECURE]) ? "needs" : "does not need");
139 sprintf(buf, "Comments: %s", info[U_COMMENT]);
141 sprintf(buf, "Created by %s on %s.", info[U_CREATOR], info[U_CREATED]);
143 sprintf(buf, MOD_FORMAT, info[U_MODBY], info[U_MODTIME], info[U_MODWITH]);
147 /* Function Name: SetUserDefaults
148 * Description: Sets the default values for add user.
149 * Arguments: info - a blank user info array of char *'s.
150 * Returns: args - the filled info structure.
153 static char **SetUserDefaults(char **info)
155 info[U_NAME] = strdup(UNIQUE_LOGIN);
156 info[U_UID] = strdup(UNIQUE_UID);
157 info[U_SHELL] = strdup(DEFAULT_SHELL);
158 info[U_WINCONSOLESHELL] = strdup(DEFAULT_WINCONSOLESHELL);
159 info[U_LAST] = strdup(DEFAULT_NONE);
160 info[U_FIRST] = strdup(DEFAULT_NONE);
161 info[U_MIDDLE] = strdup(DEFAULT_NONE);
162 info[U_STATE] = strdup(DEFAULT_NO);
163 info[U_MITID] = strdup(DEFAULT_NONE);
164 info[U_CLASS] = strdup(DEFAULT_CLASS);
165 info[U_COMMENT] = strdup("");
166 info[U_SIGNATURE] = strdup("");
167 info[U_SECURE] = strdup("0");
168 info[U_WINHOMEDIR] = strdup(DEFAULT_WINHOMEDIR);
169 info[U_WINPROFILEDIR] = strdup(DEFAULT_WINPROFILEDIR);
170 info[U_SPONSOR_TYPE] = strdup("NONE");
171 info[U_SPONSOR_NAME] = strdup("NONE");
172 info[U_EXPIRATION] = strdup("");
173 info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL;
174 info[U_CREATED] = info[U_CREATOR] = NULL;
179 /* Check that the supplied name follows the capitalization rules, and
180 * offer to correct it if not.
183 void CorrectCapitalization(char **name)
185 char temp_buf[BUFSIZ], fixname[BUFSIZ];
187 strcpy(fixname, *name);
189 if (strcmp(fixname, *name))
191 Put_message("You entered a name which does not follow the capitalization conventions.");
192 sprintf(temp_buf, "Correct it to \"%s\"", fixname);
193 if (YesNoQuestion(temp_buf, 0) == TRUE)
196 *name = strdup(fixname);
202 /* Function Name: AskUserInfo.
203 * Description: This function askes the user for information about a
204 * machine and saves it into a structure.
205 * Arguments: info - a pointer the the structure to put the info into.
206 * flags - Flags asking us which info we want.
207 * Returns: the args to pass to the query.
208 * NOTES: the return args are not necessarily in the correct order to
209 * use the #defined names (e.g args[UID] is not the uid anymore).
212 char **AskUserInfo(char **info, Bool name)
215 char temp_buf[BUFSIZ], *newname;
219 sprintf(temp_buf, "\nChanging Attributes of user %s.\n", info[U_NAME]);
220 Put_message(temp_buf);
224 struct mqelem *elem = NULL;
227 if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
229 CorrectCapitalization(&info[U_LAST]);
230 if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
232 CorrectCapitalization(&info[U_FIRST]);
233 if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR)
235 CorrectCapitalization(&info[U_MIDDLE]);
236 argv[0] = info[U_FIRST];
237 argv[1] = info[U_LAST];
238 if (do_mr_query("get_user_account_by_name", 2, argv,
239 StoreInfo, &elem) == MR_SUCCESS)
241 Put_message("A user by that name already exists in the database.");
242 Loop(QueueTop(elem), PrintUserInfo);
243 Loop(QueueTop(elem), FreeInfo);
245 if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
251 newname = strdup(info[U_NAME]);
252 if (GetValueFromUser("The new login name for this user", &newname) ==
256 else if (GetValueFromUser("Login name for this user", &info[U_NAME]) ==
260 strcpy(temp_buf, info[U_UID]);
261 if (GetValueFromUser("User's UID", &info[U_UID]) == SUB_ERROR)
263 if (strcmp(info[U_UID], UNIQUE_UID) && strcmp(info[U_UID], temp_buf))
265 struct mqelem *elem = NULL;
266 if (do_mr_query("get_user_account_by_uid", 1, &info[U_UID],
267 StoreInfo, &elem) == MR_SUCCESS)
269 Put_message("A user with that uid already exists in the database.");
270 Loop(QueueTop(elem), PrintUserInfo);
271 Loop(QueueTop(elem), FreeInfo);
273 if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
278 if (GetValueFromUser("User's shell", &info[U_SHELL]) == SUB_ERROR)
280 if (GetValueFromUser("Windows console shell", &info[U_WINCONSOLESHELL])
285 if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
287 CorrectCapitalization(&info[U_LAST]);
288 if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
290 CorrectCapitalization(&info[U_FIRST]);
291 if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR)
293 CorrectCapitalization(&info[U_MIDDLE]);
298 if (GetValueFromUser("User's status (? for help)", &info[U_STATE]) ==
301 if (isdigit(info[U_STATE][0]))
303 Put_message("Valid status numbers:");
304 for (i = 0; i < US_END; i++)
306 sprintf(temp_buf, " %d: %s", i, states[i]);
307 Put_message(temp_buf);
310 if (GetValueFromUser("User's MIT ID number", &info[U_MITID]) == SUB_ERROR)
312 RemoveHyphens(info[U_MITID]);
313 if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) ==
316 if (GetValueFromUser("Comments", &info[U_COMMENT]) == SUB_ERROR)
319 if (GetValueFromUser("Windows Home Directory", &info[U_WINHOMEDIR]) ==
323 if (GetValueFromUser("Windows Profile Directory", &info[U_WINPROFILEDIR]) ==
327 if (GetTypeFromUser("User's sponsor type", "ace_type", &info[U_SPONSOR_TYPE])
330 if (strcmp(info[U_SPONSOR_TYPE], "NONE") &&
331 GetValueFromUser("Sponsor's Name", &info[U_SPONSOR_NAME]) == SUB_ERROR)
334 if (GetValueFromUser("Expiration date", &info[U_EXPIRATION]) == SUB_ERROR)
337 state = atoi(info[U_STATE]);
338 if (!name || state == 0 || state == 2)
340 if (YesNoQuestion("User needs secure Account Coupon to register",
341 atoi(info[U_SECURE]) ? TRUE : FALSE) == FALSE)
343 free(info[U_SECURE]);
344 info[U_SECURE] = strdup("0");
348 free(info[U_SECURE]);
349 info[U_SECURE] = strdup("1");
353 info[U_SIGNATURE] = strdup("");
355 FreeAndClear(&info[U_MODTIME], TRUE);
356 FreeAndClear(&info[U_MODBY], TRUE);
357 FreeAndClear(&info[U_MODWITH], TRUE);
360 * Slide the newname into the #2 slot, this screws up all future references
361 * to this list, since we slip the pointer into a info list it gets freed
362 * when the rest of the list gets freed.
365 SlipInNewName(info, newname);
370 /* Function Name: GetUserInfo
371 * Description: Stores the user information in a queue.
372 * Arguments: type - type of field given to get info, one of:
373 * LOGIN, UID, BY_NAME, CLASS.
374 * name1 - name of thing specified by type (wildcards okay)
375 * name2 - other name, only used in get user by first and last.
377 * Returns: the first element of the queue containing the user info.
381 struct mqelem *GetUserInfo(int type, char *name1, char *name2)
385 struct mqelem *elem = NULL;
391 if ((status = do_mr_query("get_user_account_by_login", 1, args,
394 com_err(program_name, status,
395 " when attempting to get_user_account_by_login.");
401 if ((status = do_mr_query("get_user_account_by_uid", 1, args,
404 com_err(program_name, status,
405 " when attempting to get_user_account_by_uid.");
412 if ((status = do_mr_query("get_user_account_by_name", 2, args,
415 com_err(program_name, status,
416 " when attempting to get_user_account_by_name.");
422 if ((status = do_mr_query("get_user_account_by_class", 1, args,
425 com_err(program_name, status,
426 " when attempting to get_user_account_by_class.");
432 if ((status = do_mr_query("get_user_account_by_id", 1, args,
435 com_err(program_name, status,
436 " when attempting to get_user_account_by_id.");
441 return QueueTop(elem) ;
444 /* Function Name: AddNewUser
445 * Description: Adds a new user to the database.
447 * Returns: DM_NORMAL.
450 int AddNewUser(int argc, char **argv)
453 char **args, *info[MAX_ARGS_SIZE];
455 if (!(args = AskUserInfo(SetUserDefaults(info), FALSE)))
457 Put_message("Aborted.");
460 if ((status = do_mr_query("add_user_account", CountArgs(args),
462 com_err(program_name, status, " in add_user_account");
464 Put_message("New user added to database.");
470 /* Function Name: GetLoginName
471 * Description: Asks the user for a login name and reserves
474 * Returns: a malloced login name for the user.
477 static char *GetLoginName(void)
482 if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR)
484 Put_message("KERBEROS code not added, did not reserve name with kerberos.");
489 /* Function Name: ChooseUser
490 * Description: Choose a user from a list and return the uid.
491 * Arguments: top - a queue of user information.
492 * Returns: uid - the malloced uid of the user that was chosen.
495 static char *ChooseUser(struct mqelem *elem)
499 char **info = elem->q_data;
501 switch (YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE))
504 return strdup(info[U_UID]);
507 default: /* quit or ^C. */
515 /* Function Name: GetUidNumberFromName
516 * Description: Gets the users uid number, from the name.
518 * Returns: uid - a malloced string containing the uid.
521 static char *GetUidNumberFromName(void)
523 char *args[5], *uid, first[BUFSIZ], last[BUFSIZ];
525 struct mqelem *top = NULL;
527 if (!Prompt_input("First Name: ", first, BUFSIZ))
529 if (!Prompt_input("Last Name: ", last, BUFSIZ))
537 switch ((status = do_mr_query("get_user_account_by_name", 2, args,
543 Put_message("There is no user in the database with that name.");
546 com_err(program_name, status, " in get_account_user_by_name.");
551 if (QueueCount(top) == 1) /* This is a unique name. */
553 char **info = top->q_data;
554 Put_message("User ID Number retrieved for the user: ");
557 uid = strdup(info[U_UID]);
562 Put_message("That name is not unique, choose the user that you want.");
563 uid = ChooseUser(top);
568 /* Function Name: SetUserPassword
569 * Description: Set the new kerberos password for this user.
570 * Arguments: name - kerberos principle name for this user, (login name).
574 static void SetUserPassword(char *name)
576 name = name; /* make saber happy. */
577 Put_message("Kerberos password not changed, code non-existant.");
578 /* clever message to call account_admin, if this fails. */
581 /* Function Name: GiveBackLogin
582 * Description: Gives back previously reserved kerberous principle.
583 * Arguments: name - principle to give back.
587 static void GiveBackLogin(char *name)
589 name = name; /* make saber happy. */
590 Put_message("kerberos code not implemented, name not given back.");
591 /* send mail to db maintainer if this fails. */
594 /* Function Name: RegisterUser
595 * Description: This function registers a user.
597 * Returns: DM_NORMAL.
600 int RegisterUser(int argc, char **argv)
602 char *args[MAX_ARGS_SIZE];
603 char *login, *potype = NULL;
604 char temp_buf[BUFSIZ];
607 for (i = 0; i < MAX_ARGS_SIZE; i++)
610 Put_message("This function has NO kerberos support, so strange things");
611 Put_message("may happen if you use it to register a user.");
613 switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE))
616 Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ);
617 args[0] = strdup(temp_buf);
620 if (!(args[0] = GetUidNumberFromName()))
627 sprintf(temp_buf, "u%s", args[0]);
628 login = strdup(temp_buf);
629 if (GetValueFromUser("Login name for this user? ", &login) == SUB_ERROR)
632 FreeInfo(args); /* This work because the NULL temination is ok. */
635 Put_message("KERBEROS code not added, did not reserve name with kerberos.");
638 sprintf(temp_buf, "IMAP");
639 potype = strdup(temp_buf);
640 if (GetValueFromUser("P.O. Box Type for this user? ", &potype) == SUB_ERROR)
646 if (strcmp(potype, "POP") && strcmp(potype, "IMAP"))
648 sprintf(temp_buf, "Unknown P.O. Box type.");
649 Put_message(temp_buf);
656 switch ((status = do_mr_query("register_user", CountArgs(args),
660 sprintf(temp_buf, "User %s successfully registered.", login);
661 Put_message(temp_buf);
662 SetUserPassword(login);
665 GiveBackLogin(login);
666 sprintf(temp_buf, "The username %s is already in use.", login);
667 Put_message(temp_buf);
670 com_err(program_name, status, " in register_user");
677 /* Function Name: RealUpdateUser
678 * Description: actuall updates the user information.
679 * Arguments: info - all current information for the user fields.
680 * junk - an UNUSED boolean.
684 static void RealUpdateUser(char **info, Bool junk)
687 char error_buf[BUFSIZ];
688 char **args = AskUserInfo(info, TRUE);
692 Put_message("Aborted.");
695 if ((status = do_mr_query("update_user_account", CountArgs(args),
698 com_err(program_name, status, " in ModifyFields");
699 sprintf(error_buf, "User %s not updated due to errors.", info[NAME]);
700 Put_message(error_buf);
704 /* Function Name: UpdateUser
705 * Description: Modify some of the information about a user.
706 * Arguments: argc, argv - login name of the user in argv[1].
707 * Returns: DM_NORMAL.
710 int UpdateUser(int argc, char **argv)
714 elem = GetUserInfo(LOGIN, argv[1], NULL);
715 QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user");
721 /* Function Name: RealDeactivateUser
722 * Description: sets the user's status to 3.
723 * Arguments: info - all current information for the user fields
724 * one_item - indicates the user hasn't been queried yet
728 static void RealDeactivateUser(char **info, Bool one_item)
731 char txt_buf[BUFSIZ];
732 char *qargs[2], **args;
733 struct mqelem *elem = NULL;
737 sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]);
738 if (YesNoQuestion(txt_buf, FALSE) != TRUE)
742 qargs[0] = info[NAME];
744 if ((status = do_mr_query("update_user_status", 2, qargs, NULL, NULL)))
746 com_err(program_name, status, " in update_user_status");
747 sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]);
748 Put_message(txt_buf);
750 else if (YesNoQuestion("Also deactivate matching list and filesystem (y/n)",
753 status = do_mr_query("get_list_info", 1, &(info[NAME]), StoreInfo,
755 if (status == MR_SUCCESS)
757 args = QueueTop(elem)->q_data;
758 free(args[L_ACTIVE]);
759 args[L_ACTIVE] = strdup("0");
760 FreeAndClear(&args[L_MODTIME], TRUE);
761 FreeAndClear(&args[L_MODBY], TRUE);
762 FreeAndClear(&args[L_MODWITH], TRUE);
763 SlipInNewName(args, strdup(args[L_NAME]));
764 if ((status = do_mr_query("update_list", CountArgs(args), args,
767 com_err(program_name, status, " updating list, "
768 "not deactivating list or filesystem");
777 else if (status != MR_NO_MATCH)
779 com_err(program_name, status, " getting list info, "
780 "not deactivating list or filesystem");
784 if ((status = do_mr_query("get_filesys_by_label", 1, &(info[NAME]),
787 com_err(program_name, status, " getting filsys info, "
788 "not deactivating filesystem");
791 args = QueueTop(elem)->q_data;
793 args[FS_TYPE] = strdup("ERR");
794 free(args[FS_COMMENTS]);
795 args[FS_COMMENTS] = strdup("Locker disabled; call 3-1325 for help");
796 FreeAndClear(&args[FS_MODTIME], TRUE);
797 FreeAndClear(&args[FS_MODBY], TRUE);
798 FreeAndClear(&args[FS_MODWITH], TRUE);
799 SlipInNewName(args, strdup(args[FS_NAME]));
800 if ((status = do_mr_query("update_filesys", CountArgs(args), args,
803 com_err(program_name, status, " updating filesystem, "
804 "not deactivating filesystem");
815 /* Function Name: DeactivateUser
816 * Description: sets the user's status to 3.
817 * Arguments: argc, argv - login name of the user in argv[1].
818 * Returns: DM_NORMAL.
821 int DeactivateUser(int argc, char **argv)
825 elem = GetUserInfo(LOGIN, argv[1], NULL);
826 QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user");
833 /* ------------------------- Top Menu ------------------------- */
835 /* DeleteUser() in delete.c */
837 /* Function Name: DeleteUserByUid
838 * Description: Deletes the user given a uid number.
839 * Arguments: argc, argv - uid if user in argv[1].
840 * Returns: DM_NORMAL.
841 * NOTES: This just gets the username from the mr server
842 * and performs a DeleteUser().
845 int DeleteUserByUid(int argc, char **argv)
848 struct mqelem *elem = NULL;
851 if (!ValidName(argv[1]))
854 if ((status = do_mr_query("get_user_account_by_uid", 1, argv + 1, StoreInfo,
856 com_err(program_name, status, " in get_user_account_by_uid");
859 argv[1] = info[U_NAME];
861 DeleteUser(argc, argv);
865 /* ------------------------- Show User Information ------------------------- */
867 /* Function Name: ShowUserByLogin
868 * Description: Shows user information given a login name.
869 * Arguments: argc, argv - login name in argv[1].
873 int ShowUserByLogin(int argc, char *argv[])
875 struct mqelem *top, *elem;
877 elem = top = GetUserInfo(LOGIN, argv[1], NULL);
878 Loop(elem, PrintUserInfo);
884 /* Function Name: RetrieveUserByName
885 * Description: Show information on a user give fist and/or last name.
886 * Arguments: argc, argv - argv[1] - first name.
887 * argv[2] - last name.
888 * Returns: DM_NORMAL.
891 int ShowUserByName(int argc, char *argv[])
896 top = GetUserInfo(BY_NAME, argv[1], argv[2]);
898 if (!top) /* if there was an error then return. */
901 if (!PromptWithDefault("Print full information, or just the names (f/n)?",
909 Loop(top, PrintUserInfo);
913 Loop(top, PrintUserName);
921 /* Function Name: ShowUserByClass
922 * Description: Shows real and login names of all users in class.
923 * Arguments: argc, argv - argv[1] contains the class.
927 int ShowUserByClass(int argc, char **argv)
931 if (YesNoQuestion("This will take a long time. Are you sure", 0) == FALSE)
933 top = GetUserInfo(CLASS, argv[1], NULL);
934 Loop(top, PrintUserName);
941 /* Function Name: ShowUserById
942 * Description: Shows user information given an ID number.
943 * Arguments: argc, argv - ID number in argv[1].
947 int ShowUserById(int argc, char *argv[])
949 struct mqelem *top, *elem;
951 elem = top = GetUserInfo(ID, argv[1], NULL);
952 Loop(elem, PrintUserInfo);
959 /* Function Name: GetKrbmap
960 * Description: Shows user <-> Kerberos mappings
961 * Arguments: argc, argv - argv[1] contains the user login name,
962 * argv[2] contains the principal
966 int GetKrbmap(int argc, char **argv)
969 struct mqelem *elem = NULL, *top;
972 if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1],
975 com_err(program_name, stat, " in GetKrbMap.");
979 top = elem = QueueTop(elem);
983 char **info = elem->q_data;
984 sprintf(buf, "User: %-9s Principal: %s",
985 info[KMAP_USER], info[KMAP_PRINCIPAL]);
990 FreeQueue(QueueTop(top));
995 /* Function Name: AddKrbmap
996 * Description: Add a new user <-> Kerberos mapping
997 * Arguments: argc, argv - argv[1] contains the user login name,
998 * argv[2] contains the principal
1002 int AddKrbmap(int argc, char **argv)
1006 if (!strchr(argv[KMAP_PRINCIPAL + 1], '@'))
1008 Put_message("Please specify a realm for the kerberos principal.");
1011 if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1],
1014 com_err(program_name, stat, " in AddKrbMap.");
1015 if (stat == MR_EXISTS)
1016 Put_message("No user or principal may have more than one mapping.");
1022 /* Function Name: DeleteKrbmap
1023 * Description: Remove a user <-> Kerberos mapping
1024 * Arguments: argc, argv - argv[1] contains the user login name,
1025 * argv[2] contains the principal
1029 int DeleteKrbmap(int argc, char **argv)
1033 if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1],
1035 com_err(program_name, stat, " in DeleteKrbMap.");
1039 int GetUserReservations(int argc, char **argv)
1042 struct mqelem *elem = NULL, *top;
1045 if ((stat = do_mr_query("get_user_reservations", 1, &argv[1],
1048 com_err(program_name, stat, " in GetUserReservations.");
1052 top = elem = QueueTop(elem);
1055 Put_message("No reservations for that user.");
1058 char **info = elem->q_data;
1059 sprintf(buf, "Reservation: %s", info[0]);
1061 elem = elem->q_forw;
1064 FreeQueue(QueueTop(top));
1068 int AddUserReservation(int argc, char **argv)
1073 switch (stat = do_mr_query("add_user_reservation", 2, &argv[1],
1079 sprintf(buf, "The reservation %s is not valid.", argv[2]);
1081 PrintReservationTypes();
1084 com_err(program_name, stat, " in AddUserReservation.");
1091 int DelUserReservation(int argc, char **argv)
1096 switch (stat = do_mr_query("delete_user_reservation", 2, &argv[1],
1102 sprintf(buf, "The reservation %s is not valid.", argv[2]);
1104 PrintReservationTypes();
1107 com_err(program_name, stat, " in DelUserReservation.");
1114 int GetUserByReservation(int argc, char **argv)
1117 struct mqelem *elem = NULL, *top;
1120 switch (stat = do_mr_query("get_user_by_reservation", 1, &argv[1],
1126 sprintf(buf, "The reservation %s is not valid.", argv[1]);
1128 PrintReservationTypes();
1131 com_err(program_name, stat, " in GetUserByReservation.");
1135 top = elem = QueueTop(elem);
1139 char **info = elem->q_data;
1140 sprintf(buf, "User: %s", info[0]);
1142 elem = elem->q_forw;
1145 FreeQueue(QueueTop(top));
1149 void PrintReservationTypes(void)
1152 struct mqelem *elem = NULL, *top;
1156 Put_message("Valid types of reservations are: ");
1159 qargs[1] = "RESERVE";
1161 if ((stat = do_mr_query("get_alias", 3, &qargs[0],
1164 com_err(program_name, stat, "in PrintReservationTypes.");
1166 top = elem = QueueTop(elem);
1169 char **info = elem->q_data;
1170 sprintf(buf, "%s", info[2]);
1172 elem = elem->q_forw;
1175 FreeQueue(QueueTop(top));
1178 int UserBySponsor(int argc, char **argv)
1180 char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name;
1183 type = strdup("USER");
1184 if (GetTypeFromUser("Type of sponsor", "ace_type", &type) == SUB_ERROR)
1187 sprintf(buf, "Name of %s", type);
1188 name = strdup(user);
1189 if (GetValueFromUser(buf, &name) == SUB_ERROR)
1192 switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE))
1195 sprintf(temp_buf, "R%s", type); /* "USER to "RUSER", etc. */
1197 type = strdup(temp_buf);
1205 top = GetUserBySponsor(type, name);
1206 Loop(top, PrintLogin);
1212 static void PrintLogin(char **info)
1216 sprintf(buf, "Login: %s", info[U_NAME]);
1220 struct mqelem *GetUserBySponsor(char *type, char *name)
1223 struct mqelem *elem = NULL;
1228 if ((status = do_mr_query("get_user_account_by_sponsor", 2, args, StoreInfo,
1231 com_err(program_name, status, " in get_user_account_by_sponsor");
1234 return QueueTop(elem);