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>
30 void CorrectCapitalization(char **name);
31 char **AskUserInfo(char **info, Bool name);
32 struct mqelem *GetUserInfo(int type, char *name1, char *name2);
33 static void PrintLogin(char **info);
34 struct mqelem *GetUserBySponsor(char *type, char *name);
43 #define DEFAULT_SHELL "/bin/athena/bash"
45 #define DEFAULT_SHELL "/bin/bash"
47 #define DEFAULT_CLASS "?"
49 #define DEFAULT_WINCONSOLESHELL "cmd"
50 #define DEFAULT_WINHOMEDIR "[DFS]"
51 #define DEFAULT_WINPROFILEDIR "[DFS]"
53 /* Function Name: UserState
54 * Description: Convert a numeric state into a descriptive string.
55 * Arguments: state value
56 * Returns: pointer to statically allocated string.
59 static char *states[] = {
62 "Half Registered (2)",
64 "Not registerable (4)",
65 "Enrolled/Registerable (5)",
66 "Enrolled/Not Registerable (6)",
68 "Registerable, Kerberos only (8)",
69 "Active, Kerberos only (9)"
72 static char *UserState(int state)
74 static char buf[BUFSIZ];
76 if (state < 0 || state >= US_END)
78 sprintf(buf, "Unknown (%d)", state);
85 /* Function Name: PrintUserName
86 * Description: Print name of a user.
87 * Arguments: info - the information about a user.
91 static void PrintUserName(char **info)
93 char buf[BUFSIZ], print_buf[BUFSIZ];
94 sprintf(buf, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]);
95 sprintf(print_buf, "%-40s User Name: %s", buf, info[U_NAME]);
96 Put_message(print_buf);
99 /* Function Name: PrintUserInfo
100 * Description: Prints Information about a user.
101 * Arguments: info - an argument list with the user information
106 static void PrintUserInfo(char **info)
108 char name[BUFSIZ], buf[BUFSIZ], sponsor[BUFSIZ];
111 sprintf(name, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]);
112 sprintf(buf, "Login name: %-20s Full name: %s", info[U_NAME], name);
114 sprintf(buf, "User id: %-23s Login shell: %-10s",
115 info[U_UID], info[U_SHELL]);
117 sprintf(buf, "Class: %-25s Windows Console Shell: %-10s",
118 info[U_CLASS], info[U_WINCONSOLESHELL]);
120 sprintf(sponsor, "%s %s", info[U_SPONSOR_TYPE], info[U_SPONSOR_NAME]);
121 sprintf(buf, "Sponsor: %-23s Expiration date: %s", sponsor, info[U_EXPIRATION]);
123 sprintf(buf, "Account is: %-20s MIT ID number: %s",
124 UserState(atoi(info[U_STATE])), info[U_MITID]);
126 sprintf(buf, "Windows Home Directory: %s", info[U_WINHOMEDIR]);
128 sprintf(buf, "Windows Profile Directory: %s", info[U_WINPROFILEDIR]);
130 status = atoi(info[U_STATE]);
131 if (status == 0 || status == 2)
133 sprintf(buf, "User %s secure Account Coupon to register",
134 atoi(info[U_SECURE]) ? "needs" : "does not need");
137 sprintf(buf, "Comments: %s", info[U_COMMENT]);
139 sprintf(buf, "Created by %s on %s.", info[U_CREATOR], info[U_CREATED]);
141 sprintf(buf, MOD_FORMAT, info[U_MODBY], info[U_MODTIME], info[U_MODWITH]);
145 /* Function Name: SetUserDefaults
146 * Description: Sets the default values for add user.
147 * Arguments: info - a blank user info array of char *'s.
148 * Returns: args - the filled info structure.
151 static char **SetUserDefaults(char **info)
153 info[U_NAME] = strdup(UNIQUE_LOGIN);
154 info[U_UID] = strdup(UNIQUE_UID);
155 info[U_SHELL] = strdup(DEFAULT_SHELL);
156 info[U_WINCONSOLESHELL] = strdup(DEFAULT_WINCONSOLESHELL);
157 info[U_LAST] = strdup(DEFAULT_NONE);
158 info[U_FIRST] = strdup(DEFAULT_NONE);
159 info[U_MIDDLE] = strdup(DEFAULT_NONE);
160 info[U_STATE] = strdup(DEFAULT_NO);
161 info[U_MITID] = strdup(DEFAULT_NONE);
162 info[U_CLASS] = strdup(DEFAULT_CLASS);
163 info[U_COMMENT] = strdup("");
164 info[U_SIGNATURE] = strdup("");
165 info[U_SECURE] = strdup("0");
166 info[U_WINHOMEDIR] = strdup(DEFAULT_WINHOMEDIR);
167 info[U_WINPROFILEDIR] = strdup(DEFAULT_WINPROFILEDIR);
168 info[U_SPONSOR_TYPE] = strdup("NONE");
169 info[U_SPONSOR_NAME] = strdup("NONE");
170 info[U_EXPIRATION] = strdup("");
171 info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL;
172 info[U_CREATED] = info[U_CREATOR] = NULL;
177 /* Check that the supplied name follows the capitalization rules, and
178 * offer to correct it if not.
181 void CorrectCapitalization(char **name)
183 char temp_buf[BUFSIZ], fixname[BUFSIZ];
185 strcpy(fixname, *name);
187 if (strcmp(fixname, *name))
189 Put_message("You entered a name which does not follow the capitalization conventions.");
190 sprintf(temp_buf, "Correct it to \"%s\"", fixname);
191 if (YesNoQuestion(temp_buf, 0) == TRUE)
194 *name = strdup(fixname);
200 /* Function Name: AskUserInfo.
201 * Description: This function askes the user for information about a
202 * machine and saves it into a structure.
203 * Arguments: info - a pointer the the structure to put the info into.
204 * flags - Flags asking us which info we want.
205 * Returns: the args to pass to the query.
206 * NOTES: the return args are not necessarily in the correct order to
207 * use the #defined names (e.g args[UID] is not the uid anymore).
210 char **AskUserInfo(char **info, Bool name)
213 char temp_buf[BUFSIZ], *newname;
217 sprintf(temp_buf, "\nChanging Attributes of user %s.\n", info[U_NAME]);
218 Put_message(temp_buf);
222 struct mqelem *elem = NULL;
225 if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
227 CorrectCapitalization(&info[U_LAST]);
228 if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
230 CorrectCapitalization(&info[U_FIRST]);
231 if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR)
233 CorrectCapitalization(&info[U_MIDDLE]);
234 argv[0] = info[U_FIRST];
235 argv[1] = info[U_LAST];
236 if (do_mr_query("get_user_account_by_name", 2, argv,
237 StoreInfo, &elem) == MR_SUCCESS)
239 Put_message("A user by that name already exists in the database.");
240 Loop(QueueTop(elem), PrintUserInfo);
241 Loop(QueueTop(elem), FreeInfo);
243 if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
249 newname = strdup(info[U_NAME]);
250 if (GetValueFromUser("The new login name for this user", &newname) ==
254 else if (GetValueFromUser("Login name for this user", &info[U_NAME]) ==
258 strcpy(temp_buf, info[U_UID]);
259 if (GetValueFromUser("User's UID", &info[U_UID]) == SUB_ERROR)
261 if (strcmp(info[U_UID], UNIQUE_UID) && strcmp(info[U_UID], temp_buf))
263 struct mqelem *elem = NULL;
264 if (do_mr_query("get_user_account_by_uid", 1, &info[U_UID],
265 StoreInfo, &elem) == MR_SUCCESS)
267 Put_message("A user with that uid already exists in the database.");
268 Loop(QueueTop(elem), PrintUserInfo);
269 Loop(QueueTop(elem), FreeInfo);
271 if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
276 if (GetValueFromUser("User's shell", &info[U_SHELL]) == SUB_ERROR)
278 if (GetValueFromUser("Windows console shell", &info[U_WINCONSOLESHELL])
283 if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
285 CorrectCapitalization(&info[U_LAST]);
286 if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
288 CorrectCapitalization(&info[U_FIRST]);
289 if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR)
291 CorrectCapitalization(&info[U_MIDDLE]);
296 if (GetValueFromUser("User's status (? for help)", &info[U_STATE]) ==
299 if (isdigit(info[U_STATE][0]))
301 Put_message("Valid status numbers:");
302 for (i = 0; i < US_END; i++)
304 sprintf(temp_buf, " %d: %s", i, states[i]);
305 Put_message(temp_buf);
308 if (GetValueFromUser("User's MIT ID number", &info[U_MITID]) == SUB_ERROR)
310 RemoveHyphens(info[U_MITID]);
311 if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) ==
314 if (GetValueFromUser("Comments", &info[U_COMMENT]) == SUB_ERROR)
317 if (GetValueFromUser("Windows Home Directory", &info[U_WINHOMEDIR]) ==
321 if (GetValueFromUser("Windows Profile Directory", &info[U_WINPROFILEDIR]) ==
325 if (GetTypeFromUser("User's sponsor type", "ace_type", &info[U_SPONSOR_TYPE])
328 if (strcmp(info[U_SPONSOR_TYPE], "NONE") &&
329 GetValueFromUser("Sponsor's Name", &info[U_SPONSOR_NAME]) == SUB_ERROR)
332 if (GetValueFromUser("Expiration date", &info[U_EXPIRATION]) == SUB_ERROR)
335 state = atoi(info[U_STATE]);
336 if (!name || state == 0 || state == 2)
338 if (YesNoQuestion("User needs secure Account Coupon to register",
339 atoi(info[U_SECURE]) ? TRUE : FALSE) == FALSE)
341 free(info[U_SECURE]);
342 info[U_SECURE] = strdup("0");
346 free(info[U_SECURE]);
347 info[U_SECURE] = strdup("1");
351 info[U_SIGNATURE] = strdup("");
353 FreeAndClear(&info[U_MODTIME], TRUE);
354 FreeAndClear(&info[U_MODBY], TRUE);
355 FreeAndClear(&info[U_MODWITH], TRUE);
358 * Slide the newname into the #2 slot, this screws up all future references
359 * to this list, since we slip the pointer into a info list it gets freed
360 * when the rest of the list gets freed.
363 SlipInNewName(info, newname);
368 /* Function Name: GetUserInfo
369 * Description: Stores the user information in a queue.
370 * Arguments: type - type of field given to get info, one of:
371 * LOGIN, UID, BY_NAME, CLASS.
372 * name1 - name of thing specified by type (wildcards okay)
373 * name2 - other name, only used in get user by first and last.
375 * Returns: the first element of the queue containing the user info.
379 struct mqelem *GetUserInfo(int type, char *name1, char *name2)
383 struct mqelem *elem = NULL;
389 if ((status = do_mr_query("get_user_account_by_login", 1, args,
392 com_err(program_name, status,
393 " when attempting to get_user_account_by_login.");
399 if ((status = do_mr_query("get_user_account_by_uid", 1, args,
402 com_err(program_name, status,
403 " when attempting to get_user_account_by_uid.");
410 if ((status = do_mr_query("get_user_account_by_name", 2, args,
413 com_err(program_name, status,
414 " when attempting to get_user_account_by_name.");
420 if ((status = do_mr_query("get_user_account_by_class", 1, args,
423 com_err(program_name, status,
424 " when attempting to get_user_account_by_class.");
430 if ((status = do_mr_query("get_user_account_by_id", 1, args,
433 com_err(program_name, status,
434 " when attempting to get_user_account_by_id.");
439 return QueueTop(elem) ;
442 /* Function Name: AddNewUser
443 * Description: Adds a new user to the database.
445 * Returns: DM_NORMAL.
448 int AddNewUser(int argc, char **argv)
451 char **args, *info[MAX_ARGS_SIZE];
453 if (!(args = AskUserInfo(SetUserDefaults(info), FALSE)))
455 Put_message("Aborted.");
458 if ((status = do_mr_query("add_user_account", CountArgs(args),
460 com_err(program_name, status, " in add_user_account");
462 Put_message("New user added to database.");
468 /* Function Name: GetLoginName
469 * Description: Asks the user for a login name and reserves
472 * Returns: a malloced login name for the user.
475 static char *GetLoginName(void)
480 if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR)
482 Put_message("KERBEROS code not added, did not reserve name with kerberos.");
487 /* Function Name: ChooseUser
488 * Description: Choose a user from a list and return the uid.
489 * Arguments: top - a queue of user information.
490 * Returns: uid - the malloced uid of the user that was chosen.
493 static char *ChooseUser(struct mqelem *elem)
497 char **info = elem->q_data;
499 switch (YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE))
502 return strdup(info[U_UID]);
505 default: /* quit or ^C. */
513 /* Function Name: GetUidNumberFromName
514 * Description: Gets the users uid number, from the name.
516 * Returns: uid - a malloced string containing the uid.
519 static char *GetUidNumberFromName(void)
521 char *args[5], *uid, first[BUFSIZ], last[BUFSIZ];
523 struct mqelem *top = NULL;
525 if (!Prompt_input("First Name: ", first, BUFSIZ))
527 if (!Prompt_input("Last Name: ", last, BUFSIZ))
535 switch ((status = do_mr_query("get_user_account_by_name", 2, args,
541 Put_message("There is no user in the database with that name.");
544 com_err(program_name, status, " in get_account_user_by_name.");
549 if (QueueCount(top) == 1) /* This is a unique name. */
551 char **info = top->q_data;
552 Put_message("User ID Number retrieved for the user: ");
555 uid = strdup(info[U_UID]);
560 Put_message("That name is not unique, choose the user that you want.");
561 uid = ChooseUser(top);
566 /* Function Name: SetUserPassword
567 * Description: Set the new kerberos password for this user.
568 * Arguments: name - kerberos principle name for this user, (login name).
572 static void SetUserPassword(char *name)
574 name = name; /* make saber happy. */
575 Put_message("Kerberos password not changed, code non-existant.");
576 /* clever message to call account_admin, if this fails. */
579 /* Function Name: GiveBackLogin
580 * Description: Gives back previously reserved kerberous principle.
581 * Arguments: name - principle to give back.
585 static void GiveBackLogin(char *name)
587 name = name; /* make saber happy. */
588 Put_message("kerberos code not implemented, name not given back.");
589 /* send mail to db maintainer if this fails. */
592 /* Function Name: RegisterUser
593 * Description: This function registers a user.
595 * Returns: DM_NORMAL.
598 int RegisterUser(int argc, char **argv)
600 char *args[MAX_ARGS_SIZE];
601 char *login, *potype = NULL;
602 char temp_buf[BUFSIZ];
605 for (i = 0; i < MAX_ARGS_SIZE; i++)
608 Put_message("This function has NO kerberos support, so strange things");
609 Put_message("may happen if you use it to register a user.");
611 switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE))
614 Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ);
615 args[0] = strdup(temp_buf);
618 if (!(args[0] = GetUidNumberFromName()))
625 sprintf(temp_buf, "u%s", args[0]);
626 login = strdup(temp_buf);
627 if (GetValueFromUser("Login name for this user? ", &login) == SUB_ERROR)
630 FreeInfo(args); /* This work because the NULL temination is ok. */
633 Put_message("KERBEROS code not added, did not reserve name with kerberos.");
636 sprintf(temp_buf, "IMAP");
637 potype = strdup(temp_buf);
638 if (GetValueFromUser("P.O. Box Type for this user? ", &potype) == SUB_ERROR)
644 if (strcmp(potype, "POP") && strcmp(potype, "IMAP") && strcmp(potype, "EXCHANGE"))
646 sprintf(temp_buf, "Unknown P.O. Box type.");
647 Put_message(temp_buf);
654 switch ((status = do_mr_query("register_user", CountArgs(args),
658 sprintf(temp_buf, "User %s successfully registered.", login);
659 Put_message(temp_buf);
660 SetUserPassword(login);
663 GiveBackLogin(login);
664 sprintf(temp_buf, "The username %s is already in use.", login);
665 Put_message(temp_buf);
668 com_err(program_name, status, " in register_user");
675 /* Function Name: RealUpdateUser
676 * Description: actuall updates the user information.
677 * Arguments: info - all current information for the user fields.
678 * junk - an UNUSED boolean.
682 static void RealUpdateUser(char **info, Bool junk)
685 char error_buf[BUFSIZ];
686 char **args = AskUserInfo(info, TRUE);
690 Put_message("Aborted.");
693 if ((status = do_mr_query("update_user_account", CountArgs(args),
696 com_err(program_name, status, " in ModifyFields");
697 sprintf(error_buf, "User %s not updated due to errors.", info[NAME]);
698 Put_message(error_buf);
702 /* Function Name: UpdateUser
703 * Description: Modify some of the information about a user.
704 * Arguments: argc, argv - login name of the user in argv[1].
705 * Returns: DM_NORMAL.
708 int UpdateUser(int argc, char **argv)
712 elem = GetUserInfo(LOGIN, argv[1], NULL);
713 QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user");
719 /* Function Name: RealDeactivateUser
720 * Description: sets the user's status to 3.
721 * Arguments: info - all current information for the user fields
722 * one_item - indicates the user hasn't been queried yet
726 static void RealDeactivateUser(char **info, Bool one_item)
729 char txt_buf[BUFSIZ];
730 char *qargs[2], **args;
731 struct mqelem *elem = NULL;
735 sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]);
736 if (YesNoQuestion(txt_buf, FALSE) != TRUE)
740 qargs[0] = info[NAME];
742 if ((status = do_mr_query("update_user_status", 2, qargs, NULL, NULL)))
744 com_err(program_name, status, " in update_user_status");
745 sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]);
746 Put_message(txt_buf);
748 else if (YesNoQuestion("Also deactivate matching list and filesystem (y/n)",
751 status = do_mr_query("get_list_info", 1, &(info[NAME]), StoreInfo,
753 if (status == MR_SUCCESS)
755 args = QueueTop(elem)->q_data;
756 free(args[L_ACTIVE]);
757 args[L_ACTIVE] = strdup("0");
758 FreeAndClear(&args[L_MODTIME], TRUE);
759 FreeAndClear(&args[L_MODBY], TRUE);
760 FreeAndClear(&args[L_MODWITH], TRUE);
761 SlipInNewName(args, strdup(args[L_NAME]));
762 if ((status = do_mr_query("update_list", CountArgs(args), args,
765 com_err(program_name, status, " updating list, "
766 "not deactivating list or filesystem");
775 else if (status != MR_NO_MATCH)
777 com_err(program_name, status, " getting list info, "
778 "not deactivating list or filesystem");
782 if ((status = do_mr_query("get_filesys_by_label", 1, &(info[NAME]),
785 com_err(program_name, status, " getting filsys info, "
786 "not deactivating filesystem");
789 args = QueueTop(elem)->q_data;
791 args[FS_TYPE] = strdup("ERR");
792 free(args[FS_COMMENTS]);
793 args[FS_COMMENTS] = strdup("Locker disabled; call 3-1325 for help");
794 FreeAndClear(&args[FS_MODTIME], TRUE);
795 FreeAndClear(&args[FS_MODBY], TRUE);
796 FreeAndClear(&args[FS_MODWITH], TRUE);
797 SlipInNewName(args, strdup(args[FS_NAME]));
798 if ((status = do_mr_query("update_filesys", CountArgs(args), args,
801 com_err(program_name, status, " updating filesystem, "
802 "not deactivating filesystem");
813 /* Function Name: DeactivateUser
814 * Description: sets the user's status to 3.
815 * Arguments: argc, argv - login name of the user in argv[1].
816 * Returns: DM_NORMAL.
819 int DeactivateUser(int argc, char **argv)
823 elem = GetUserInfo(LOGIN, argv[1], NULL);
824 QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user");
831 /* ------------------------- Top Menu ------------------------- */
833 /* DeleteUser() in delete.c */
835 /* Function Name: DeleteUserByUid
836 * Description: Deletes the user given a uid number.
837 * Arguments: argc, argv - uid if user in argv[1].
838 * Returns: DM_NORMAL.
839 * NOTES: This just gets the username from the mr server
840 * and performs a DeleteUser().
843 int DeleteUserByUid(int argc, char **argv)
846 struct mqelem *elem = NULL;
849 if (!ValidName(argv[1]))
852 if ((status = do_mr_query("get_user_account_by_uid", 1, argv + 1, StoreInfo,
854 com_err(program_name, status, " in get_user_account_by_uid");
857 argv[1] = info[U_NAME];
859 DeleteUser(argc, argv);
863 /* ------------------------- Show User Information ------------------------- */
865 /* Function Name: ShowUserByLogin
866 * Description: Shows user information given a login name.
867 * Arguments: argc, argv - login name in argv[1].
871 int ShowUserByLogin(int argc, char *argv[])
873 struct mqelem *top, *elem;
875 elem = top = GetUserInfo(LOGIN, argv[1], NULL);
876 Loop(elem, PrintUserInfo);
882 /* Function Name: RetrieveUserByName
883 * Description: Show information on a user give fist and/or last name.
884 * Arguments: argc, argv - argv[1] - first name.
885 * argv[2] - last name.
886 * Returns: DM_NORMAL.
889 int ShowUserByName(int argc, char *argv[])
894 top = GetUserInfo(BY_NAME, argv[1], argv[2]);
896 if (!top) /* if there was an error then return. */
899 if (!PromptWithDefault("Print full information, or just the names (f/n)?",
907 Loop(top, PrintUserInfo);
911 Loop(top, PrintUserName);
919 /* Function Name: ShowUserByClass
920 * Description: Shows real and login names of all users in class.
921 * Arguments: argc, argv - argv[1] contains the class.
925 int ShowUserByClass(int argc, char **argv)
929 if (YesNoQuestion("This will take a long time. Are you sure", 0) == FALSE)
931 top = GetUserInfo(CLASS, argv[1], NULL);
932 Loop(top, PrintUserName);
939 /* Function Name: ShowUserById
940 * Description: Shows user information given an ID number.
941 * Arguments: argc, argv - ID number in argv[1].
945 int ShowUserById(int argc, char *argv[])
947 struct mqelem *top, *elem;
949 elem = top = GetUserInfo(ID, argv[1], NULL);
950 Loop(elem, PrintUserInfo);
957 /* Function Name: GetKrbmap
958 * Description: Shows user <-> Kerberos mappings
959 * Arguments: argc, argv - argv[1] contains the user login name,
960 * argv[2] contains the principal
964 int GetKrbmap(int argc, char **argv)
967 struct mqelem *elem = NULL, *top;
970 if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1],
973 com_err(program_name, stat, " in GetKrbMap.");
977 top = elem = QueueTop(elem);
981 char **info = elem->q_data;
982 sprintf(buf, "User: %-9s Principal: %s",
983 info[KMAP_USER], info[KMAP_PRINCIPAL]);
988 FreeQueue(QueueTop(top));
993 /* Function Name: AddKrbmap
994 * Description: Add a new user <-> Kerberos mapping
995 * Arguments: argc, argv - argv[1] contains the user login name,
996 * argv[2] contains the principal
1000 int AddKrbmap(int argc, char **argv)
1004 if (!strchr(argv[KMAP_PRINCIPAL + 1], '@'))
1006 Put_message("Please specify a realm for the kerberos principal.");
1009 if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1],
1012 com_err(program_name, stat, " in AddKrbMap.");
1013 if (stat == MR_EXISTS)
1014 Put_message("No user or principal may have more than one mapping.");
1020 /* Function Name: DeleteKrbmap
1021 * Description: Remove a user <-> Kerberos mapping
1022 * Arguments: argc, argv - argv[1] contains the user login name,
1023 * argv[2] contains the principal
1027 int DeleteKrbmap(int argc, char **argv)
1031 if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1],
1033 com_err(program_name, stat, " in DeleteKrbMap.");
1037 int GetUserReservations(int argc, char **argv)
1040 struct mqelem *elem = NULL, *top;
1043 if ((stat = do_mr_query("get_user_reservations", 1, &argv[1],
1046 com_err(program_name, stat, " in GetUserReservations.");
1050 top = elem = QueueTop(elem);
1053 Put_message("No reservations for that user.");
1056 char **info = elem->q_data;
1057 sprintf(buf, "Reservation: %s", info[0]);
1059 elem = elem->q_forw;
1062 FreeQueue(QueueTop(top));
1066 int AddUserReservation(int argc, char **argv)
1071 switch (stat = do_mr_query("add_user_reservation", 2, &argv[1],
1077 sprintf(buf, "The reservation %s is not valid.", argv[2]);
1079 PrintReservationTypes();
1082 com_err(program_name, stat, " in AddUserReservation.");
1089 int DelUserReservation(int argc, char **argv)
1094 switch (stat = do_mr_query("delete_user_reservation", 2, &argv[1],
1100 sprintf(buf, "The reservation %s is not valid.", argv[2]);
1102 PrintReservationTypes();
1105 com_err(program_name, stat, " in DelUserReservation.");
1112 int GetUserByReservation(int argc, char **argv)
1115 struct mqelem *elem = NULL, *top;
1118 switch (stat = do_mr_query("get_user_by_reservation", 1, &argv[1],
1124 sprintf(buf, "The reservation %s is not valid.", argv[1]);
1126 PrintReservationTypes();
1129 com_err(program_name, stat, " in GetUserByReservation.");
1133 top = elem = QueueTop(elem);
1137 char **info = elem->q_data;
1138 sprintf(buf, "User: %s", info[0]);
1140 elem = elem->q_forw;
1143 FreeQueue(QueueTop(top));
1147 void PrintReservationTypes(void)
1150 struct mqelem *elem = NULL, *top;
1154 Put_message("Valid types of reservations are: ");
1157 qargs[1] = "RESERVE";
1159 if ((stat = do_mr_query("get_alias", 3, &qargs[0],
1162 com_err(program_name, stat, "in PrintReservationTypes.");
1164 top = elem = QueueTop(elem);
1167 char **info = elem->q_data;
1168 sprintf(buf, "%s", info[2]);
1170 elem = elem->q_forw;
1173 FreeQueue(QueueTop(top));
1176 int UserBySponsor(int argc, char **argv)
1178 char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name;
1181 type = strdup("USER");
1182 if (GetTypeFromUser("Type of sponsor", "search_ace_type", &type) == SUB_ERROR)
1185 sprintf(buf, "Name of %s", type);
1186 name = strdup(user);
1187 if (GetValueFromUser(buf, &name) == SUB_ERROR)
1190 switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE))
1193 sprintf(temp_buf, "R%s", type); /* "USER to "RUSER", etc. */
1195 type = strdup(temp_buf);
1203 top = GetUserBySponsor(type, name);
1204 Loop(top, PrintLogin);
1210 static void PrintLogin(char **info)
1214 sprintf(buf, "Login: %s", info[U_NAME]);
1218 struct mqelem *GetUserBySponsor(char *type, char *name)
1221 struct mqelem *elem = NULL;
1226 if ((status = do_mr_query("get_user_account_by_sponsor", 2, args, StoreInfo,
1229 com_err(program_name, status, " in get_user_account_by_sponsor");
1232 return QueueTop(elem);