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);
43 #define DEFAULT_SHELL "/bin/athena/tcsh"
45 #define DEFAULT_SHELL "/bin/csh"
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];
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(buf, "Account is: %-20s MIT ID number: %s",
121 UserState(atoi(info[U_STATE])), info[U_MITID]);
123 sprintf(buf, "Windows Home Directory: %s", info[U_WINHOMEDIR]);
125 sprintf(buf, "Windows Profile Directory: %s", info[U_WINPROFILEDIR]);
127 status = atoi(info[U_STATE]);
128 if (status == 0 || status == 2)
130 sprintf(buf, "User %s secure Account Coupon to register",
131 atoi(info[U_SECURE]) ? "needs" : "does not need");
134 sprintf(buf, "Comments: %s", info[U_COMMENT]);
136 sprintf(buf, "Created by %s on %s.", info[U_CREATOR], info[U_CREATED]);
138 sprintf(buf, MOD_FORMAT, info[U_MODBY], info[U_MODTIME], info[U_MODWITH]);
142 /* Function Name: SetUserDefaults
143 * Description: Sets the default values for add user.
144 * Arguments: info - a blank user info array of char *'s.
145 * Returns: args - the filled info structure.
148 static char **SetUserDefaults(char **info)
150 info[U_NAME] = strdup(UNIQUE_LOGIN);
151 info[U_UID] = strdup(UNIQUE_UID);
152 info[U_SHELL] = strdup(DEFAULT_SHELL);
153 info[U_WINCONSOLESHELL] = strdup(DEFAULT_WINCONSOLESHELL);
154 info[U_LAST] = strdup(DEFAULT_NONE);
155 info[U_FIRST] = strdup(DEFAULT_NONE);
156 info[U_MIDDLE] = strdup(DEFAULT_NONE);
157 info[U_STATE] = strdup(DEFAULT_NO);
158 info[U_MITID] = strdup(DEFAULT_NONE);
159 info[U_CLASS] = strdup(DEFAULT_CLASS);
160 info[U_COMMENT] = strdup("");
161 info[U_SIGNATURE] = strdup("");
162 info[U_SECURE] = strdup("0");
163 info[U_WINHOMEDIR] = strdup(DEFAULT_WINHOMEDIR);
164 info[U_WINPROFILEDIR] = strdup(DEFAULT_WINPROFILEDIR);
165 info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL;
166 info[U_CREATED] = info[U_CREATOR] = NULL;
171 /* Check that the supplied name follows the capitalization rules, and
172 * offer to correct it if not.
175 void CorrectCapitalization(char **name)
177 char temp_buf[BUFSIZ], fixname[BUFSIZ];
179 strcpy(fixname, *name);
181 if (strcmp(fixname, *name))
183 Put_message("You entered a name which does not follow the capitalization conventions.");
184 sprintf(temp_buf, "Correct it to \"%s\"", fixname);
185 if (YesNoQuestion(temp_buf, 0) == TRUE)
188 *name = strdup(fixname);
194 /* Function Name: AskUserInfo.
195 * Description: This function askes the user for information about a
196 * machine and saves it into a structure.
197 * Arguments: info - a pointer the the structure to put the info into.
198 * flags - Flags asking us which info we want.
199 * Returns: the args to pass to the query.
200 * NOTES: the return args are not necessarily in the correct order to
201 * use the #defined names (e.g args[UID] is not the uid anymore).
204 char **AskUserInfo(char **info, Bool name)
207 char temp_buf[BUFSIZ], *newname;
211 sprintf(temp_buf, "\nChanging Attributes of user %s.\n", info[U_NAME]);
212 Put_message(temp_buf);
216 struct mqelem *elem = NULL;
219 if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
221 CorrectCapitalization(&info[U_LAST]);
222 if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
224 CorrectCapitalization(&info[U_FIRST]);
225 if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR)
227 CorrectCapitalization(&info[U_MIDDLE]);
228 argv[0] = info[U_FIRST];
229 argv[1] = info[U_LAST];
230 if (do_mr_query("get_user_account_by_name", 2, argv,
231 StoreInfo, &elem) == MR_SUCCESS)
233 Put_message("A user by that name already exists in the database.");
234 Loop(QueueTop(elem), PrintUserInfo);
235 Loop(QueueTop(elem), FreeInfo);
237 if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
243 newname = strdup(info[U_NAME]);
244 if (GetValueFromUser("The new login name for this user", &newname) ==
248 else if (GetValueFromUser("Login name for this user", &info[U_NAME]) ==
252 strcpy(temp_buf, info[U_UID]);
253 if (GetValueFromUser("User's UID", &info[U_UID]) == SUB_ERROR)
255 if (strcmp(info[U_UID], UNIQUE_UID) && strcmp(info[U_UID], temp_buf))
257 struct mqelem *elem = NULL;
258 if (do_mr_query("get_user_account_by_uid", 1, &info[U_UID],
259 StoreInfo, &elem) == MR_SUCCESS)
261 Put_message("A user with that uid already exists in the database.");
262 Loop(QueueTop(elem), PrintUserInfo);
263 Loop(QueueTop(elem), FreeInfo);
265 if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
270 if (GetValueFromUser("User's shell", &info[U_SHELL]) == SUB_ERROR)
272 if (GetValueFromUser("Windows console shell", &info[U_WINCONSOLESHELL])
277 if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
279 CorrectCapitalization(&info[U_LAST]);
280 if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
282 CorrectCapitalization(&info[U_FIRST]);
283 if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR)
285 CorrectCapitalization(&info[U_MIDDLE]);
290 if (GetValueFromUser("User's status (? for help)", &info[U_STATE]) ==
293 if (isdigit(info[U_STATE][0]))
295 Put_message("Valid status numbers:");
296 for (i = 0; i < US_END; i++)
298 sprintf(temp_buf, " %d: %s", i, states[i]);
299 Put_message(temp_buf);
302 if (GetValueFromUser("User's MIT ID number", &info[U_MITID]) == SUB_ERROR)
304 RemoveHyphens(info[U_MITID]);
305 if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) ==
308 if (GetValueFromUser("Comments", &info[U_COMMENT]) == SUB_ERROR)
311 if (GetValueFromUser("Windows Home Directory", &info[U_WINHOMEDIR]) ==
315 if (GetValueFromUser("Windows Profile Directory", &info[U_WINPROFILEDIR]) ==
319 state = atoi(info[U_STATE]);
320 if (!name || state == 0 || state == 2)
322 if (YesNoQuestion("User needs secure Account Coupon to register",
323 atoi(info[U_SECURE]) ? TRUE : FALSE) == FALSE)
325 free(info[U_SECURE]);
326 info[U_SECURE] = strdup("0");
330 free(info[U_SECURE]);
331 info[U_SECURE] = strdup("1");
335 info[U_SIGNATURE] = strdup("");
337 FreeAndClear(&info[U_MODTIME], TRUE);
338 FreeAndClear(&info[U_MODBY], TRUE);
339 FreeAndClear(&info[U_MODWITH], TRUE);
342 * Slide the newname into the #2 slot, this screws up all future references
343 * to this list, since we slip the pointer into a info list it gets freed
344 * when the rest of the list gets freed.
347 SlipInNewName(info, newname);
352 /* Function Name: GetUserInfo
353 * Description: Stores the user information in a queue.
354 * Arguments: type - type of field given to get info, one of:
355 * LOGIN, UID, BY_NAME, CLASS.
356 * name1 - name of thing specified by type (wildcards okay)
357 * name2 - other name, only used in get user by first and last.
359 * Returns: the first element of the queue containing the user info.
363 struct mqelem *GetUserInfo(int type, char *name1, char *name2)
367 struct mqelem *elem = NULL;
373 if ((status = do_mr_query("get_user_account_by_login", 1, args,
376 com_err(program_name, status,
377 " when attempting to get_user_account_by_login.");
383 if ((status = do_mr_query("get_user_account_by_uid", 1, args,
386 com_err(program_name, status,
387 " when attempting to get_user_account_by_uid.");
394 if ((status = do_mr_query("get_user_account_by_name", 2, args,
397 com_err(program_name, status,
398 " when attempting to get_user_account_by_name.");
404 if ((status = do_mr_query("get_user_account_by_class", 1, args,
407 com_err(program_name, status,
408 " when attempting to get_user_account_by_class.");
414 if ((status = do_mr_query("get_user_account_by_id", 1, args,
417 com_err(program_name, status,
418 " when attempting to get_user_account_by_id.");
423 return QueueTop(elem) ;
426 /* Function Name: AddNewUser
427 * Description: Adds a new user to the database.
429 * Returns: DM_NORMAL.
432 int AddNewUser(int argc, char **argv)
435 char **args, *info[MAX_ARGS_SIZE];
437 if (!(args = AskUserInfo(SetUserDefaults(info), FALSE)))
439 Put_message("Aborted.");
442 if ((status = do_mr_query("add_user_account", CountArgs(args),
444 com_err(program_name, status, " in add_user_account");
446 Put_message("New user added to database.");
452 /* Function Name: GetLoginName
453 * Description: Asks the user for a login name and reserves
456 * Returns: a malloced login name for the user.
459 static char *GetLoginName(void)
464 if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR)
466 Put_message("KERBEROS code not added, did not reserve name with kerberos.");
471 /* Function Name: ChooseUser
472 * Description: Choose a user from a list and return the uid.
473 * Arguments: top - a queue of user information.
474 * Returns: uid - the malloced uid of the user that was chosen.
477 static char *ChooseUser(struct mqelem *elem)
481 char **info = elem->q_data;
483 switch (YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE))
486 return strdup(info[U_UID]);
489 default: /* quit or ^C. */
497 /* Function Name: GetUidNumberFromName
498 * Description: Gets the users uid number, from the name.
500 * Returns: uid - a malloced string containing the uid.
503 static char *GetUidNumberFromName(void)
505 char *args[5], *uid, first[BUFSIZ], last[BUFSIZ];
507 struct mqelem *top = NULL;
509 if (!Prompt_input("First Name: ", first, BUFSIZ))
511 if (!Prompt_input("Last Name: ", last, BUFSIZ))
519 switch ((status = do_mr_query("get_user_account_by_name", 2, args,
525 Put_message("There is no user in the database with that name.");
528 com_err(program_name, status, " in get_account_user_by_name.");
533 if (QueueCount(top) == 1) /* This is a unique name. */
535 char **info = top->q_data;
536 Put_message("User ID Number retrieved for the user: ");
539 uid = strdup(info[U_UID]);
544 Put_message("That name is not unique, choose the user that you want.");
545 uid = ChooseUser(top);
550 /* Function Name: SetUserPassword
551 * Description: Set the new kerberos password for this user.
552 * Arguments: name - kerberos principle name for this user, (login name).
556 static void SetUserPassword(char *name)
558 name = name; /* make saber happy. */
559 Put_message("Kerberos password not changed, code non-existant.");
560 /* clever message to call account_admin, if this fails. */
563 /* Function Name: GiveBackLogin
564 * Description: Gives back previously reserved kerberous principle.
565 * Arguments: name - principle to give back.
569 static void GiveBackLogin(char *name)
571 name = name; /* make saber happy. */
572 Put_message("kerberos code not implemented, name not given back.");
573 /* send mail to db maintainer if this fails. */
576 /* Function Name: RegisterUser
577 * Description: This function registers a user.
579 * Returns: DM_NORMAL.
582 int RegisterUser(int argc, char **argv)
584 char *args[MAX_ARGS_SIZE];
585 char *login, *potype = NULL;
586 char temp_buf[BUFSIZ];
589 for (i = 0; i < MAX_ARGS_SIZE; i++)
592 Put_message("This function has NO kerberos support, so strange things");
593 Put_message("may happen if you use it to register a user.");
595 switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE))
598 Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ);
599 args[0] = strdup(temp_buf);
602 if (!(args[0] = GetUidNumberFromName()))
609 sprintf(temp_buf, "u%s", args[0]);
610 login = strdup(temp_buf);
611 if (GetValueFromUser("Login name for this user? ", &login) == SUB_ERROR)
614 FreeInfo(args); /* This work because the NULL temination is ok. */
617 Put_message("KERBEROS code not added, did not reserve name with kerberos.");
620 sprintf(temp_buf, "IMAP");
621 potype = strdup(temp_buf);
622 if (GetValueFromUser("P.O. Box Type for this user? ", &potype) == SUB_ERROR)
628 if (strcmp(potype, "POP") && strcmp(potype, "IMAP"))
630 sprintf(temp_buf, "Unknown P.O. Box type.");
631 Put_message(temp_buf);
638 switch ((status = do_mr_query("register_user", CountArgs(args),
642 sprintf(temp_buf, "User %s successfully registered.", login);
643 Put_message(temp_buf);
644 SetUserPassword(login);
647 GiveBackLogin(login);
648 sprintf(temp_buf, "The username %s is already in use.", login);
649 Put_message(temp_buf);
652 com_err(program_name, status, " in register_user");
659 /* Function Name: RealUpdateUser
660 * Description: actuall updates the user information.
661 * Arguments: info - all current information for the user fields.
662 * junk - an UNUSED boolean.
666 static void RealUpdateUser(char **info, Bool junk)
669 char error_buf[BUFSIZ];
670 char **args = AskUserInfo(info, TRUE);
674 Put_message("Aborted.");
677 if ((status = do_mr_query("update_user_account", CountArgs(args),
680 com_err(program_name, status, " in ModifyFields");
681 sprintf(error_buf, "User %s not updated due to errors.", info[NAME]);
682 Put_message(error_buf);
686 /* Function Name: UpdateUser
687 * Description: Modify some of the information about a user.
688 * Arguments: argc, argv - login name of the user in argv[1].
689 * Returns: DM_NORMAL.
692 int UpdateUser(int argc, char **argv)
696 elem = GetUserInfo(LOGIN, argv[1], NULL);
697 QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user");
703 /* Function Name: RealDeactivateUser
704 * Description: sets the user's status to 3.
705 * Arguments: info - all current information for the user fields
706 * one_item - indicates the user hasn't been queried yet
710 static void RealDeactivateUser(char **info, Bool one_item)
713 char txt_buf[BUFSIZ];
714 char *qargs[2], **args;
715 struct mqelem *elem = NULL;
719 sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]);
720 if (YesNoQuestion(txt_buf, FALSE) != TRUE)
724 qargs[0] = info[NAME];
726 if ((status = do_mr_query("update_user_status", 2, qargs, NULL, NULL)))
728 com_err(program_name, status, " in update_user_status");
729 sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]);
730 Put_message(txt_buf);
732 else if (YesNoQuestion("Also deactivate matching list and filesystem (y/n)",
735 status = do_mr_query("get_list_info", 1, &(info[NAME]), StoreInfo,
737 if (status == MR_SUCCESS)
739 args = QueueTop(elem)->q_data;
740 free(args[L_ACTIVE]);
741 args[L_ACTIVE] = strdup("0");
742 FreeAndClear(&args[L_MODTIME], TRUE);
743 FreeAndClear(&args[L_MODBY], TRUE);
744 FreeAndClear(&args[L_MODWITH], TRUE);
745 SlipInNewName(args, strdup(args[L_NAME]));
746 if ((status = do_mr_query("update_list", CountArgs(args), args,
749 com_err(program_name, status, " updating list, "
750 "not deactivating list or filesystem");
759 else if (status != MR_NO_MATCH)
761 com_err(program_name, status, " getting list info, "
762 "not deactivating list or filesystem");
766 if ((status = do_mr_query("get_filesys_by_label", 1, &(info[NAME]),
769 com_err(program_name, status, " getting filsys info, "
770 "not deactivating filesystem");
773 args = QueueTop(elem)->q_data;
775 args[FS_TYPE] = strdup("ERR");
776 free(args[FS_COMMENTS]);
777 args[FS_COMMENTS] = strdup("Locker disabled; call 3-1325 for help");
778 FreeAndClear(&args[FS_MODTIME], TRUE);
779 FreeAndClear(&args[FS_MODBY], TRUE);
780 FreeAndClear(&args[FS_MODWITH], TRUE);
781 SlipInNewName(args, strdup(args[FS_NAME]));
782 if ((status = do_mr_query("update_filesys", CountArgs(args), args,
785 com_err(program_name, status, " updating filesystem, "
786 "not deactivating filesystem");
797 /* Function Name: DeactivateUser
798 * Description: sets the user's status to 3.
799 * Arguments: argc, argv - login name of the user in argv[1].
800 * Returns: DM_NORMAL.
803 int DeactivateUser(int argc, char **argv)
807 elem = GetUserInfo(LOGIN, argv[1], NULL);
808 QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user");
815 /* ------------------------- Top Menu ------------------------- */
817 /* DeleteUser() in delete.c */
819 /* Function Name: DeleteUserByUid
820 * Description: Deletes the user given a uid number.
821 * Arguments: argc, argv - uid if user in argv[1].
822 * Returns: DM_NORMAL.
823 * NOTES: This just gets the username from the mr server
824 * and performs a DeleteUser().
827 int DeleteUserByUid(int argc, char **argv)
830 struct mqelem *elem = NULL;
833 if (!ValidName(argv[1]))
836 if ((status = do_mr_query("get_user_account_by_uid", 1, argv + 1, StoreInfo,
838 com_err(program_name, status, " in get_user_account_by_uid");
841 argv[1] = info[U_NAME];
843 DeleteUser(argc, argv);
847 /* ------------------------- Show User Information ------------------------- */
849 /* Function Name: ShowUserByLogin
850 * Description: Shows user information given a login name.
851 * Arguments: argc, argv - login name in argv[1].
855 int ShowUserByLogin(int argc, char *argv[])
857 struct mqelem *top, *elem;
859 elem = top = GetUserInfo(LOGIN, argv[1], NULL);
860 Loop(elem, PrintUserInfo);
866 /* Function Name: RetrieveUserByName
867 * Description: Show information on a user give fist and/or last name.
868 * Arguments: argc, argv - argv[1] - first name.
869 * argv[2] - last name.
870 * Returns: DM_NORMAL.
873 int ShowUserByName(int argc, char *argv[])
878 top = GetUserInfo(BY_NAME, argv[1], argv[2]);
880 if (!top) /* if there was an error then return. */
883 if (!PromptWithDefault("Print full information, or just the names (f/n)?",
891 Loop(top, PrintUserInfo);
895 Loop(top, PrintUserName);
903 /* Function Name: ShowUserByClass
904 * Description: Shows real and login names of all users in class.
905 * Arguments: argc, argv - argv[1] contains the class.
909 int ShowUserByClass(int argc, char **argv)
913 if (YesNoQuestion("This will take a long time. Are you sure", 0) == FALSE)
915 top = GetUserInfo(CLASS, argv[1], NULL);
916 Loop(top, PrintUserName);
923 /* Function Name: ShowUserById
924 * Description: Shows user information given an ID number.
925 * Arguments: argc, argv - ID number in argv[1].
929 int ShowUserById(int argc, char *argv[])
931 struct mqelem *top, *elem;
933 elem = top = GetUserInfo(ID, argv[1], NULL);
934 Loop(elem, PrintUserInfo);
941 /* Function Name: GetKrbmap
942 * Description: Shows user <-> Kerberos mappings
943 * Arguments: argc, argv - argv[1] contains the user login name,
944 * argv[2] contains the principal
948 int GetKrbmap(int argc, char **argv)
951 struct mqelem *elem = NULL, *top;
954 if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1],
957 com_err(program_name, stat, " in GetKrbMap.");
961 top = elem = QueueTop(elem);
965 char **info = elem->q_data;
966 sprintf(buf, "User: %-9s Principal: %s",
967 info[KMAP_USER], info[KMAP_PRINCIPAL]);
972 FreeQueue(QueueTop(top));
977 /* Function Name: AddKrbmap
978 * Description: Add a new user <-> Kerberos mapping
979 * Arguments: argc, argv - argv[1] contains the user login name,
980 * argv[2] contains the principal
984 int AddKrbmap(int argc, char **argv)
988 if (!strchr(argv[KMAP_PRINCIPAL + 1], '@'))
990 Put_message("Please specify a realm for the kerberos principal.");
993 if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1],
996 com_err(program_name, stat, " in AddKrbMap.");
997 if (stat == MR_EXISTS)
998 Put_message("No user or principal may have more than one mapping.");
1004 /* Function Name: DeleteKrbmap
1005 * Description: Remove a user <-> Kerberos mapping
1006 * Arguments: argc, argv - argv[1] contains the user login name,
1007 * argv[2] contains the principal
1011 int DeleteKrbmap(int argc, char **argv)
1015 if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1],
1017 com_err(program_name, stat, " in DeleteKrbMap.");
1021 int GetUserReservations(int argc, char **argv)
1024 struct mqelem *elem = NULL, *top;
1027 if ((stat = do_mr_query("get_user_reservations", 1, &argv[1],
1030 com_err(program_name, stat, " in GetUserReservations.");
1034 top = elem = QueueTop(elem);
1037 Put_message("No reservations for that user.");
1040 char **info = elem->q_data;
1041 sprintf(buf, "Reservation: %s", info[0]);
1043 elem = elem->q_forw;
1046 FreeQueue(QueueTop(top));
1050 int AddUserReservation(int argc, char **argv)
1055 switch (stat = do_mr_query("add_user_reservation", 2, &argv[1],
1061 sprintf(buf, "The reservation %s is not valid.", argv[2]);
1063 PrintReservationTypes();
1066 com_err(program_name, stat, " in AddUserReservation.");
1073 int DelUserReservation(int argc, char **argv)
1078 switch (stat = do_mr_query("delete_user_reservation", 2, &argv[1],
1084 sprintf(buf, "The reservation %s is not valid.", argv[2]);
1086 PrintReservationTypes();
1089 com_err(program_name, stat, " in DelUserReservation.");
1096 int GetUserByReservation(int argc, char **argv)
1099 struct mqelem *elem = NULL, *top;
1102 switch (stat = do_mr_query("get_user_by_reservation", 1, &argv[1],
1108 sprintf(buf, "The reservation %s is not valid.", argv[1]);
1110 PrintReservationTypes();
1113 com_err(program_name, stat, " in GetUserByReservation.");
1117 top = elem = QueueTop(elem);
1121 char **info = elem->q_data;
1122 sprintf(buf, "User: %s", info[0]);
1124 elem = elem->q_forw;
1127 FreeQueue(QueueTop(top));
1131 void PrintReservationTypes(void)
1134 struct mqelem *elem = NULL, *top;
1138 Put_message("Valid types of reservations are: ");
1141 qargs[1] = "RESERVE";
1143 if ((stat = do_mr_query("get_alias", 3, &qargs[0],
1146 com_err(program_name, stat, "in PrintReservationTypes.");
1148 top = elem = QueueTop(elem);
1151 char **info = elem->q_data;
1152 sprintf(buf, "%s", info[2]);
1154 elem = elem->q_forw;
1157 FreeQueue(QueueTop(top));