]>
Commit | Line | Data |
---|---|---|
c441a31a | 1 | /* $Id$ |
7ac48069 | 2 | * |
3 | * This is the file user.c for the Moira Client, which allows users | |
59ec8dae | 4 | * to quickly and easily maintain most parts of the Moira database. |
0a2c64cb | 5 | * It Contains: Functions for manipulating user information. |
5eaef520 | 6 | * |
08345b74 | 7 | * Created: 5/9/88 |
8 | * By: Chris D. Peterson | |
9 | * | |
7ac48069 | 10 | * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology. |
11 | * For copying and distribution information, please see the file | |
12 | * <mit-copyright.h>. | |
08345b74 | 13 | */ |
14 | ||
7ac48069 | 15 | #include <mit-copyright.h> |
8defc06b | 16 | #include <moira.h> |
17 | #include <moira_site.h> | |
7ac48069 | 18 | #include "defs.h" |
19 | #include "f_defs.h" | |
20 | #include "globals.h" | |
21 | ||
1e80e2f4 | 22 | #include <ctype.h> |
7ac48069 | 23 | #include <stdio.h> |
24 | #include <stdlib.h> | |
25 | #include <string.h> | |
26 | #include <time.h> | |
ea0caf4a | 27 | |
28 | #include <krb.h> | |
7ac48069 | 29 | |
30 | RCSID("$Header$"); | |
31 | ||
32 | void CorrectCapitalization(char **name); | |
33 | char **AskUserInfo(char **info, Bool name); | |
600b459e | 34 | struct mqelem *GetUserInfo(int type, char *name1, char *name2); |
461c03b6 | 35 | |
08345b74 | 36 | #define LOGIN 0 |
37 | #define UID 1 | |
402461ad | 38 | #define BY_NAME 2 |
075fe5bb | 39 | #define CLASS 3 |
81701699 | 40 | #define ID 4 |
08345b74 | 41 | |
d6db948b | 42 | #ifdef ATHENA |
43 | #define DEFAULT_SHELL "/bin/athena/tcsh" | |
44 | #else | |
07b2e652 | 45 | #define DEFAULT_SHELL "/bin/csh" |
d6db948b | 46 | #endif |
07b2e652 | 47 | #define DEFAULT_CLASS "?" |
48 | ||
032f07aa | 49 | #define DEFAULT_WINCONSOLESHELL "cmd" |
07b2e652 | 50 | |
32de30b0 | 51 | /* Function Name: UserState |
52 | * Description: Convert a numeric state into a descriptive string. | |
53 | * Arguments: state value | |
54 | * Returns: pointer to statically allocated string. | |
55 | */ | |
56 | ||
5eaef520 | 57 | static char *states[] = { |
58 | "Registerable (0)", | |
59 | "Active (1)", | |
60 | "Half Registered (2)", | |
61 | "Deleted (3)", | |
62 | "Not registerable (4)", | |
63 | "Enrolled/Registerable (5)", | |
64 | "Enrolled/Not Registerable (6)", | |
65 | "Half Enrolled (7)" | |
66 | }; | |
67 | ||
68 | static char *UserState(int state) | |
32de30b0 | 69 | { |
5eaef520 | 70 | static char buf[BUFSIZ]; |
78fce9fa | 71 | |
5eaef520 | 72 | if (state < 0 || state >= US_END) |
73 | { | |
74 | sprintf(buf, "Unknown (%d)", state); | |
75 | return buf; | |
78fce9fa | 76 | } |
5eaef520 | 77 | return states[state]; |
32de30b0 | 78 | } |
79 | ||
80 | ||
075fe5bb | 81 | /* Function Name: PrintUserName |
82 | * Description: Print name of a user. | |
83 | * Arguments: info - the information about a user. | |
84 | * Returns: none. | |
85 | */ | |
86 | ||
5eaef520 | 87 | static void PrintUserName(char **info) |
075fe5bb | 88 | { |
5eaef520 | 89 | char buf[BUFSIZ], print_buf[BUFSIZ]; |
90 | sprintf(buf, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]); | |
91 | sprintf(print_buf, "%-40s User Name: %s", buf, info[U_NAME]); | |
92 | Put_message(print_buf); | |
075fe5bb | 93 | } |
94 | ||
95 | /* Function Name: PrintUserInfo | |
96 | * Description: Prints Information about a user. | |
97 | * Arguments: info - an argument list with the user information | |
98 | * in it. | |
99 | * Returns: none | |
100 | */ | |
101 | ||
5eaef520 | 102 | static void PrintUserInfo(char **info) |
075fe5bb | 103 | { |
5eaef520 | 104 | char name[BUFSIZ], buf[BUFSIZ]; |
105 | int status; | |
075fe5bb | 106 | |
5eaef520 | 107 | sprintf(name, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]); |
108 | sprintf(buf, "Login name: %-20s Full name: %s", info[U_NAME], name); | |
109 | Put_message(buf); | |
032f07aa | 110 | sprintf(buf, "User id: %-23s Login shell: %-10s", |
111 | info[U_UID], info[U_SHELL]); | |
112 | Put_message(buf); | |
113 | sprintf(buf, "Class: %-25s Windows Console Shell: %-10s", | |
114 | info[U_CLASS], info[U_WINCONSOLESHELL]); | |
5eaef520 | 115 | Put_message(buf); |
d55429b2 | 116 | sprintf(buf, "Account is: %-20s MIT ID number: %s", |
117 | UserState(atoi(info[U_STATE])), info[U_MITID]); | |
5eaef520 | 118 | Put_message(buf); |
c1c303a7 | 119 | status = atoi(info[U_STATE]); |
120 | if (status == 0 || status == 2) | |
a5cdbea8 | 121 | { |
122 | sprintf(buf, "User %s secure Account Coupon to register", | |
123 | atoi(info[U_SECURE]) ? "needs" : "does not need"); | |
124 | Put_message(buf); | |
125 | } | |
5eaef520 | 126 | sprintf(buf, "Comments: %s", info[U_COMMENT]); |
127 | Put_message(buf); | |
128 | sprintf(buf, MOD_FORMAT, info[U_MODBY], info[U_MODTIME], info[U_MODWITH]); | |
129 | Put_message(buf); | |
075fe5bb | 130 | } |
131 | ||
132 | /* Function Name: SetUserDefaults | |
133 | * Description: Sets the default values for add user. | |
134 | * Arguments: info - a blank user info array of char *'s. | |
135 | * Returns: args - the filled info structure. | |
136 | */ | |
137 | ||
5eaef520 | 138 | static char **SetUserDefaults(char **info) |
075fe5bb | 139 | { |
7ac48069 | 140 | info[U_NAME] = strdup(UNIQUE_LOGIN); |
141 | info[U_UID] = strdup(UNIQUE_UID); | |
142 | info[U_SHELL] = strdup(DEFAULT_SHELL); | |
032f07aa | 143 | info[U_WINCONSOLESHELL] = strdup(DEFAULT_WINCONSOLESHELL); |
7ac48069 | 144 | info[U_LAST] = strdup(DEFAULT_NONE); |
145 | info[U_FIRST] = strdup(DEFAULT_NONE); | |
146 | info[U_MIDDLE] = strdup(DEFAULT_NONE); | |
147 | info[U_STATE] = strdup(DEFAULT_NO); | |
148 | info[U_MITID] = strdup(DEFAULT_NONE); | |
149 | info[U_CLASS] = strdup(DEFAULT_CLASS); | |
150 | info[U_COMMENT] = strdup(""); | |
151 | info[U_SIGNATURE] = strdup(""); | |
152 | info[U_SECURE] = strdup("0"); | |
5eaef520 | 153 | info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL; |
154 | return info; | |
075fe5bb | 155 | } |
461c03b6 | 156 | |
f0a54771 | 157 | |
5eaef520 | 158 | /* Check that the supplied name follows the capitalization rules, and |
f0a54771 | 159 | * offer to correct it if not. |
160 | */ | |
161 | ||
7ac48069 | 162 | void CorrectCapitalization(char **name) |
f0a54771 | 163 | { |
5eaef520 | 164 | char temp_buf[BUFSIZ], fixname[BUFSIZ]; |
165 | ||
166 | strcpy(fixname, *name); | |
167 | FixCase(fixname); | |
168 | if (strcmp(fixname, *name)) | |
169 | { | |
170 | Put_message("You entered a name which does not follow the capitalization conventions."); | |
171 | sprintf(temp_buf, "Correct it to \"%s\"", fixname); | |
91bea8bb | 172 | if (YesNoQuestion(temp_buf, 0) == TRUE) |
5eaef520 | 173 | { |
174 | free(*name); | |
7ac48069 | 175 | *name = strdup(fixname); |
f0a54771 | 176 | } |
177 | } | |
178 | } | |
179 | ||
180 | ||
08345b74 | 181 | /* Function Name: AskUserInfo. |
5eaef520 | 182 | * Description: This function askes the user for information about a |
08345b74 | 183 | * machine and saves it into a structure. |
184 | * Arguments: info - a pointer the the structure to put the info into. | |
185 | * flags - Flags asking us which info we want. | |
186 | * Returns: the args to pass to the query. | |
187 | * NOTES: the return args are not necessarily in the correct order to | |
188 | * use the #defined names (e.g args[UID] is not the uid anymore). | |
189 | */ | |
190 | ||
5eaef520 | 191 | char **AskUserInfo(char **info, Bool name) |
08345b74 | 192 | { |
533bacb3 | 193 | int state; |
5eaef520 | 194 | char temp_buf[BUFSIZ], *newname; |
195 | ||
196 | if (name) | |
197 | { | |
198 | sprintf(temp_buf, "\nChanging Attributes of user %s.\n", info[U_NAME]); | |
199 | Put_message(temp_buf); | |
200 | } | |
201 | else | |
202 | { | |
600b459e | 203 | struct mqelem *elem = NULL; |
5eaef520 | 204 | char *argv[3]; |
205 | ||
206 | if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR) | |
207 | return NULL; | |
208 | CorrectCapitalization(&info[U_LAST]); | |
209 | if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR) | |
210 | return NULL; | |
211 | CorrectCapitalization(&info[U_FIRST]); | |
212 | if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR) | |
213 | return NULL; | |
214 | CorrectCapitalization(&info[U_MIDDLE]); | |
215 | argv[0] = info[U_FIRST]; | |
216 | argv[1] = info[U_LAST]; | |
217 | if (do_mr_query("get_user_account_by_name", 2, argv, | |
7ac48069 | 218 | StoreInfo, &elem) == MR_SUCCESS) |
5eaef520 | 219 | { |
220 | Put_message("A user by that name already exists in the database."); | |
221 | Loop(QueueTop(elem), PrintUserInfo); | |
222 | Loop(QueueTop(elem), FreeInfo); | |
223 | FreeQueue(elem); | |
224 | if (YesNoQuestion("Add new user anyway", TRUE) != TRUE) | |
225 | return NULL; | |
ebd96e37 | 226 | } |
075fe5bb | 227 | } |
5eaef520 | 228 | if (name) |
229 | { | |
7ac48069 | 230 | newname = strdup(info[U_NAME]); |
5eaef520 | 231 | if (GetValueFromUser("The new login name for this user", &newname) == |
232 | SUB_ERROR) | |
233 | return NULL; | |
ebd96e37 | 234 | } |
5eaef520 | 235 | else if (GetValueFromUser("Login name for this user", &info[U_NAME]) == |
236 | SUB_ERROR) | |
237 | return NULL; | |
238 | ||
46a9277b | 239 | strcpy(temp_buf, info[U_UID]); |
5eaef520 | 240 | if (GetValueFromUser("User's UID", &info[U_UID]) == SUB_ERROR) |
241 | return NULL; | |
46a9277b | 242 | if (strcmp(info[U_UID], UNIQUE_UID) && strcmp(info[U_UID], temp_buf)) |
243 | { | |
244 | struct mqelem *elem = NULL; | |
245 | if (do_mr_query("get_user_account_by_uid", 1, &info[U_UID], | |
246 | StoreInfo, &elem) == MR_SUCCESS) | |
247 | { | |
248 | Put_message("A user with that uid already exists in the database."); | |
249 | Loop(QueueTop(elem), PrintUserInfo); | |
250 | Loop(QueueTop(elem), FreeInfo); | |
251 | FreeQueue(elem); | |
252 | if (YesNoQuestion("Add new user anyway", TRUE) != TRUE) | |
253 | return NULL; | |
254 | } | |
255 | } | |
256 | ||
5eaef520 | 257 | if (GetValueFromUser("User's shell", &info[U_SHELL]) == SUB_ERROR) |
258 | return NULL; | |
032f07aa | 259 | if (GetValueFromUser("Windows console shell", &info[U_WINCONSOLESHELL]) |
260 | == SUB_ERROR) | |
261 | return NULL; | |
5eaef520 | 262 | if (name) |
263 | { | |
264 | if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR) | |
265 | return NULL; | |
266 | CorrectCapitalization(&info[U_LAST]); | |
267 | if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR) | |
268 | return NULL; | |
269 | CorrectCapitalization(&info[U_FIRST]); | |
270 | if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) == SUB_ERROR) | |
271 | return NULL; | |
272 | CorrectCapitalization(&info[U_MIDDLE]); | |
273 | } | |
274 | while (1) | |
275 | { | |
276 | int i; | |
277 | if (GetValueFromUser("User's status (? for help)", &info[U_STATE]) == | |
278 | SUB_ERROR) | |
279 | return NULL; | |
280 | if (isdigit(info[U_STATE][0])) | |
281 | break; | |
282 | Put_message("Valid status numbers:"); | |
283 | for (i = 0; i < US_END; i++) | |
284 | { | |
285 | sprintf(temp_buf, " %d: %s", i, states[i]); | |
286 | Put_message(temp_buf); | |
1e80e2f4 | 287 | } |
288 | } | |
5eaef520 | 289 | if (GetValueFromUser("User's MIT ID number", &info[U_MITID]) == SUB_ERROR) |
290 | return NULL; | |
291 | RemoveHyphens(info[U_MITID]); | |
292 | if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) == | |
293 | SUB_ERROR) | |
294 | return NULL; | |
295 | if (GetValueFromUser("Comments", &info[U_COMMENT]) == SUB_ERROR) | |
296 | return NULL; | |
297 | ||
c1c303a7 | 298 | state = atoi(info[U_STATE]); |
299 | if (!name || state == 0 || state == 2) | |
5eaef520 | 300 | { |
a5cdbea8 | 301 | if (YesNoQuestion("User needs secure Account Coupon to register", |
302 | atoi(info[U_SECURE]) ? TRUE : FALSE) == FALSE) | |
303 | { | |
304 | free(info[U_SECURE]); | |
305 | info[U_SECURE] = strdup("0"); | |
306 | } | |
307 | else | |
308 | { | |
309 | free(info[U_SECURE]); | |
310 | info[U_SECURE] = strdup("1"); | |
311 | } | |
559fe7ab | 312 | } |
313 | ||
7ac48069 | 314 | info[U_SIGNATURE] = strdup(""); |
b8322cb3 | 315 | |
5eaef520 | 316 | FreeAndClear(&info[U_MODTIME], TRUE); |
317 | FreeAndClear(&info[U_MODBY], TRUE); | |
318 | FreeAndClear(&info[U_MODWITH], TRUE); | |
08345b74 | 319 | |
5eaef520 | 320 | /* |
321 | * Slide the newname into the #2 slot, this screws up all future references | |
322 | * to this list, since we slip the pointer into a info list it gets freed | |
323 | * when the rest of the list gets freed. | |
324 | */ | |
325 | if (name) | |
326 | SlipInNewName(info, newname); | |
08345b74 | 327 | |
5eaef520 | 328 | return info; |
08345b74 | 329 | } |
330 | ||
331 | /* Function Name: GetUserInfo | |
332 | * Description: Stores the user information in a queue. | |
333 | * Arguments: type - type of field given to get info, one of: | |
402461ad | 334 | * LOGIN, UID, BY_NAME, CLASS. |
08345b74 | 335 | * name1 - name of thing specified by type (wildcards okay) |
336 | * name2 - other name, only used in get user by first and last. | |
337 | * (wildcards okay). | |
338 | * Returns: the first element of the queue containing the user info. | |
dcfa270a | 339 | * |
08345b74 | 340 | */ |
341 | ||
600b459e | 342 | struct mqelem *GetUserInfo(int type, char *name1, char *name2) |
08345b74 | 343 | { |
5eaef520 | 344 | char *args[2]; |
44d12d58 | 345 | int status; |
600b459e | 346 | struct mqelem *elem = NULL; |
08345b74 | 347 | |
5eaef520 | 348 | switch (type) |
349 | { | |
08345b74 | 350 | case LOGIN: |
5eaef520 | 351 | args[0] = name1; |
352 | if ((status = do_mr_query("get_user_account_by_login", 1, args, | |
7ac48069 | 353 | StoreInfo, &elem))) |
5eaef520 | 354 | { |
355 | com_err(program_name, status, | |
356 | " when attempting to get_user_account_by_login."); | |
357 | return NULL; | |
08345b74 | 358 | } |
5eaef520 | 359 | break; |
08345b74 | 360 | case UID: |
5eaef520 | 361 | args[0] = name1; |
362 | if ((status = do_mr_query("get_user_account_by_uid", 1, args, | |
7ac48069 | 363 | StoreInfo, &elem))) |
5eaef520 | 364 | { |
365 | com_err(program_name, status, | |
366 | " when attempting to get_user_account_by_uid."); | |
367 | return NULL; | |
08345b74 | 368 | } |
5eaef520 | 369 | break; |
402461ad | 370 | case BY_NAME: |
5eaef520 | 371 | args[0] = name1; |
372 | args[1] = name2; | |
373 | if ((status = do_mr_query("get_user_account_by_name", 2, args, | |
7ac48069 | 374 | StoreInfo, &elem))) |
5eaef520 | 375 | { |
376 | com_err(program_name, status, | |
377 | " when attempting to get_user_account_by_name."); | |
378 | return NULL; | |
08345b74 | 379 | } |
5eaef520 | 380 | break; |
08345b74 | 381 | case CLASS: |
5eaef520 | 382 | args[0] = name1; |
383 | if ((status = do_mr_query("get_user_account_by_class", 1, args, | |
7ac48069 | 384 | StoreInfo, &elem))) |
5eaef520 | 385 | { |
386 | com_err(program_name, status, | |
387 | " when attempting to get_user_account_by_class."); | |
388 | return NULL; | |
08345b74 | 389 | } |
5eaef520 | 390 | break; |
81701699 | 391 | case ID: |
5eaef520 | 392 | args[0] = name1; |
393 | if ((status = do_mr_query("get_user_account_by_id", 1, args, | |
7ac48069 | 394 | StoreInfo, &elem))) |
5eaef520 | 395 | { |
396 | com_err(program_name, status, | |
397 | " when attempting to get_user_account_by_id."); | |
398 | return NULL; | |
81701699 | 399 | } |
5eaef520 | 400 | break; |
08345b74 | 401 | } |
5eaef520 | 402 | return QueueTop(elem) ; |
08345b74 | 403 | } |
404 | ||
075fe5bb | 405 | /* Function Name: AddNewUser |
406 | * Description: Adds a new user to the database. | |
407 | * Arguments: none. | |
08345b74 | 408 | * Returns: DM_NORMAL. |
409 | */ | |
410 | ||
7ac48069 | 411 | int AddNewUser(int argc, char **argv) |
08345b74 | 412 | { |
44d12d58 | 413 | int status; |
5eaef520 | 414 | char **args, *info[MAX_ARGS_SIZE]; |
075fe5bb | 415 | |
5eaef520 | 416 | if (!(args = AskUserInfo(SetUserDefaults(info), FALSE))) |
417 | { | |
418 | Put_message("Aborted."); | |
419 | return DM_NORMAL; | |
e4f91beb | 420 | } |
5eaef520 | 421 | if ((status = do_mr_query("add_user_account", CountArgs(args), |
7ac48069 | 422 | args, NULL, NULL))) |
5eaef520 | 423 | com_err(program_name, status, " in add_user_account"); |
424 | else | |
425 | Put_message("New user added to database."); | |
426 | FreeInfo(args); | |
427 | return DM_NORMAL; | |
08345b74 | 428 | } |
429 | ||
430 | ||
075fe5bb | 431 | /* Function Name: GetLoginName |
432 | * Description: Asks the user for a login name and reserves | |
433 | * it with kerberous. | |
434 | * Arguments: none. | |
435 | * Returns: a malloced login name for the user. | |
08345b74 | 436 | */ |
437 | ||
5eaef520 | 438 | static char *GetLoginName(void) |
08345b74 | 439 | { |
5eaef520 | 440 | char *name; |
075fe5bb | 441 | |
7ac48069 | 442 | name = strdup(""); |
5eaef520 | 443 | if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR) |
444 | return NULL; | |
445 | Put_message("KERBEROS code not added, did not reserve name with kerberos."); | |
446 | return name; | |
075fe5bb | 447 | } |
448 | ||
449 | ||
450 | /* Function Name: ChooseUser | |
451 | * Description: Choose a user from a list and return the uid. | |
452 | * Arguments: top - a queue of user information. | |
453 | * Returns: uid - the malloced uid of the user that was chosen. | |
454 | */ | |
08345b74 | 455 | |
600b459e | 456 | static char *ChooseUser(struct mqelem *elem) |
075fe5bb | 457 | { |
5eaef520 | 458 | while (elem) |
459 | { | |
7ac48069 | 460 | char **info = elem->q_data; |
5eaef520 | 461 | PrintUserInfo(info); |
462 | switch (YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE)) | |
463 | { | |
075fe5bb | 464 | case TRUE: |
7ac48069 | 465 | return strdup(info[U_UID]); |
075fe5bb | 466 | case FALSE: |
5eaef520 | 467 | break; |
075fe5bb | 468 | default: /* quit or ^C. */ |
5eaef520 | 469 | return NULL; |
08345b74 | 470 | } |
5eaef520 | 471 | elem = elem->q_forw; |
08345b74 | 472 | } |
5eaef520 | 473 | return NULL; |
08345b74 | 474 | } |
475 | ||
075fe5bb | 476 | /* Function Name: GetUidNumberFromName |
477 | * Description: Gets the users uid number, from the name. | |
478 | * Arguments: none. | |
479 | * Returns: uid - a malloced string containing the uid. | |
08345b74 | 480 | */ |
481 | ||
5eaef520 | 482 | static char *GetUidNumberFromName(void) |
08345b74 | 483 | { |
5eaef520 | 484 | char *args[5], *uid, first[BUFSIZ], last[BUFSIZ]; |
44d12d58 | 485 | int status; |
600b459e | 486 | struct mqelem *top = NULL; |
5eaef520 | 487 | |
488 | if (!Prompt_input("First Name: ", first, BUFSIZ)) | |
489 | return NULL; | |
490 | if (!Prompt_input("Last Name: ", last, BUFSIZ)) | |
491 | return NULL; | |
492 | FixCase(first); | |
493 | FixCase(last); | |
494 | ||
495 | args[0] = first; | |
496 | args[1] = last; | |
497 | ||
498 | switch ((status = do_mr_query("get_user_account_by_name", 2, args, | |
7ac48069 | 499 | StoreInfo, &top))) |
5eaef520 | 500 | { |
8defc06b | 501 | case MR_SUCCESS: |
5eaef520 | 502 | break; |
8defc06b | 503 | case MR_NO_MATCH: |
5eaef520 | 504 | Put_message("There is no user in the database with that name."); |
505 | return NULL; | |
075fe5bb | 506 | default: |
5eaef520 | 507 | com_err(program_name, status, " in get_account_user_by_name."); |
508 | return NULL; | |
08345b74 | 509 | } |
5eaef520 | 510 | |
511 | top = QueueTop(top); | |
512 | if (QueueCount(top) == 1) /* This is a unique name. */ | |
513 | { | |
7ac48069 | 514 | char **info = top->q_data; |
5eaef520 | 515 | Put_message("User ID Number retrieved for the user: "); |
516 | Put_message(""); | |
517 | PrintUserName(info); | |
7ac48069 | 518 | uid = strdup(info[U_UID]); |
5eaef520 | 519 | FreeQueue(top); |
7ac48069 | 520 | return strdup(uid); |
075fe5bb | 521 | } |
08345b74 | 522 | |
5eaef520 | 523 | Put_message("That name is not unique, choose the user that you want."); |
524 | uid = ChooseUser(top); | |
525 | FreeQueue(top); | |
526 | return uid; | |
08345b74 | 527 | } |
528 | ||
075fe5bb | 529 | /* Function Name: SetUserPassword |
530 | * Description: Set the new kerberos password for this user. | |
531 | * Arguments: name - kerberos principle name for this user, (login name). | |
532 | * Returns: none. | |
08345b74 | 533 | */ |
534 | ||
5eaef520 | 535 | static void SetUserPassword(char *name) |
08345b74 | 536 | { |
5eaef520 | 537 | name = name; /* make saber happy. */ |
538 | Put_message("Kerberos password not changed, code non-existant."); | |
539 | /* clever message to call account_admin, if this fails. */ | |
075fe5bb | 540 | } |
08345b74 | 541 | |
075fe5bb | 542 | /* Function Name: GiveBackLogin |
543 | * Description: Gives back previously reserved kerberous principle. | |
544 | * Arguments: name - principle to give back. | |
545 | * Returns: void. | |
08345b74 | 546 | */ |
547 | ||
5eaef520 | 548 | static void GiveBackLogin(char *name) |
08345b74 | 549 | { |
5eaef520 | 550 | name = name; /* make saber happy. */ |
c02509d6 | 551 | Put_message("kerberos code not implemented, name not given back."); |
5eaef520 | 552 | /* send mail to db maintainer if this fails. */ |
08345b74 | 553 | } |
554 | ||
075fe5bb | 555 | /* Function Name: RegisterUser |
556 | * Description: This function registers a user. | |
557 | * Arguments: none. | |
558 | * Returns: DM_NORMAL. | |
08345b74 | 559 | */ |
560 | ||
7ac48069 | 561 | int RegisterUser(int argc, char **argv) |
08345b74 | 562 | { |
5eaef520 | 563 | char *args[MAX_ARGS_SIZE]; |
a41a1a03 | 564 | char *login, *potype = NULL; |
5eaef520 | 565 | char temp_buf[BUFSIZ]; |
10da9e53 | 566 | int status, i; |
5eaef520 | 567 | |
cdf64006 | 568 | for (i = 0; i < MAX_ARGS_SIZE; i++) |
10da9e53 | 569 | args[i] = NULL; |
cdf64006 | 570 | |
5eaef520 | 571 | Put_message("This function has NO kerberos support, so strange things"); |
572 | Put_message("may happen if you use it to register a user."); | |
573 | ||
574 | switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE)) | |
575 | { | |
075fe5bb | 576 | case TRUE: |
5eaef520 | 577 | Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ); |
7ac48069 | 578 | args[0] = strdup(temp_buf); |
5eaef520 | 579 | break; |
075fe5bb | 580 | case FALSE: |
5eaef520 | 581 | if (!(args[0] = GetUidNumberFromName())) |
582 | return DM_NORMAL; | |
583 | break; | |
075fe5bb | 584 | default: |
5eaef520 | 585 | return DM_NORMAL; |
461c03b6 | 586 | } |
075fe5bb | 587 | |
5eaef520 | 588 | sprintf(temp_buf, "u%s", args[0]); |
7ac48069 | 589 | login = strdup(temp_buf); |
a41a1a03 | 590 | if (GetValueFromUser("Login name for this user? ", &login) == SUB_ERROR) |
5eaef520 | 591 | { |
592 | args[1] = login; | |
593 | FreeInfo(args); /* This work because the NULL temination is ok. */ | |
594 | return DM_NORMAL; | |
075fe5bb | 595 | } |
5eaef520 | 596 | Put_message("KERBEROS code not added, did not reserve name with kerberos."); |
597 | args[1] = login; | |
a41a1a03 | 598 | |
599 | sprintf(temp_buf, "IMAP"); | |
600 | potype = strdup(temp_buf); | |
601 | if (GetValueFromUser("P.O. Box Type for this user? ", &potype) == SUB_ERROR) | |
602 | { | |
603 | args[2] = potype; | |
604 | FreeInfo(args); | |
605 | return DM_NORMAL; | |
606 | } | |
607 | if (strcmp(potype, "POP") && strcmp(potype, "IMAP")) | |
608 | { | |
609 | sprintf(temp_buf, "Unknown P.O. Box type."); | |
610 | Put_message(temp_buf); | |
611 | FreeInfo(args); | |
612 | return DM_NORMAL; | |
613 | } | |
614 | args[2] = potype; | |
5eaef520 | 615 | args[3] = NULL; |
616 | ||
617 | switch ((status = do_mr_query("register_user", CountArgs(args), | |
7ac48069 | 618 | args, NULL, NULL))) |
5eaef520 | 619 | { |
8defc06b | 620 | case MR_SUCCESS: |
5eaef520 | 621 | sprintf(temp_buf, "User %s successfully registered.", login); |
622 | Put_message(temp_buf); | |
623 | SetUserPassword(login); | |
624 | break; | |
8defc06b | 625 | case MR_IN_USE: |
5eaef520 | 626 | GiveBackLogin(login); |
627 | sprintf(temp_buf, "The username %s is already in use.", login); | |
628 | Put_message(temp_buf); | |
629 | break; | |
075fe5bb | 630 | default: |
5eaef520 | 631 | com_err(program_name, status, " in register_user"); |
632 | break; | |
075fe5bb | 633 | } |
5eaef520 | 634 | FreeInfo(args); |
635 | return DM_NORMAL; | |
08345b74 | 636 | } |
637 | ||
075fe5bb | 638 | /* Function Name: RealUpdateUser |
639 | * Description: actuall updates the user information. | |
640 | * Arguments: info - all current information for the user fields. | |
641 | * junk - an UNUSED boolean. | |
642 | * Returns: none. | |
08345b74 | 643 | */ |
644 | ||
5eaef520 | 645 | static void RealUpdateUser(char **info, Bool junk) |
08345b74 | 646 | { |
44d12d58 | 647 | int status; |
5eaef520 | 648 | char error_buf[BUFSIZ]; |
649 | char **args = AskUserInfo(info, TRUE); | |
650 | ||
651 | if (!args) | |
652 | { | |
653 | Put_message("Aborted."); | |
654 | return; | |
e4f91beb | 655 | } |
5eaef520 | 656 | if ((status = do_mr_query("update_user_account", CountArgs(args), |
7ac48069 | 657 | args, NULL, NULL))) |
5eaef520 | 658 | { |
659 | com_err(program_name, status, " in ModifyFields"); | |
660 | sprintf(error_buf, "User %s not updated due to errors.", info[NAME]); | |
661 | Put_message(error_buf); | |
08345b74 | 662 | } |
08345b74 | 663 | } |
664 | ||
075fe5bb | 665 | /* Function Name: UpdateUser |
666 | * Description: Modify some of the information about a user. | |
667 | * Arguments: argc, argv - login name of the user in argv[1]. | |
08345b74 | 668 | * Returns: DM_NORMAL. |
669 | */ | |
670 | ||
5eaef520 | 671 | int UpdateUser(int argc, char **argv) |
08345b74 | 672 | { |
600b459e | 673 | struct mqelem *elem; |
5eaef520 | 674 | |
675 | elem = GetUserInfo(LOGIN, argv[1], NULL); | |
676 | QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user"); | |
08345b74 | 677 | |
5eaef520 | 678 | FreeQueue(elem); |
679 | return DM_NORMAL; | |
08345b74 | 680 | } |
681 | ||
b3e25186 | 682 | /* Function Name: RealDeactivateUser |
683 | * Description: sets the user's status to 3. | |
684 | * Arguments: info - all current information for the user fields | |
685 | * one_item - indicates the user hasn't been queried yet | |
686 | * Returns: none. | |
687 | */ | |
688 | ||
5eaef520 | 689 | static void RealDeactivateUser(char **info, Bool one_item) |
b3e25186 | 690 | { |
44d12d58 | 691 | int status; |
5eaef520 | 692 | char txt_buf[BUFSIZ]; |
693 | char *qargs[2], **args; | |
600b459e | 694 | struct mqelem *elem = NULL; |
5eaef520 | 695 | |
696 | if (one_item) | |
697 | { | |
698 | sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]); | |
699 | if (YesNoQuestion(txt_buf, FALSE) != TRUE) | |
700 | return; | |
b3e25186 | 701 | } |
702 | ||
5eaef520 | 703 | qargs[0] = info[NAME]; |
704 | qargs[1] = "3"; | |
7ac48069 | 705 | if ((status = do_mr_query("update_user_status", 2, qargs, NULL, NULL))) |
5eaef520 | 706 | { |
707 | com_err(program_name, status, " in update_user_status"); | |
708 | sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]); | |
709 | Put_message(txt_buf); | |
710 | } | |
711 | else if (YesNoQuestion("Also deactivate matching list and filesystem (y/n)", | |
712 | FALSE) == TRUE) | |
713 | { | |
714 | status = do_mr_query("get_list_info", 1, &(info[NAME]), StoreInfo, | |
7ac48069 | 715 | &elem); |
5eaef520 | 716 | if (status == MR_SUCCESS) |
717 | { | |
7ac48069 | 718 | args = QueueTop(elem)->q_data; |
5eaef520 | 719 | free(args[L_ACTIVE]); |
7ac48069 | 720 | args[L_ACTIVE] = strdup("0"); |
5eaef520 | 721 | FreeAndClear(&args[L_MODTIME], TRUE); |
722 | FreeAndClear(&args[L_MODBY], TRUE); | |
723 | FreeAndClear(&args[L_MODWITH], TRUE); | |
533bacb3 | 724 | SlipInNewName(args, strdup(args[L_NAME])); |
5eaef520 | 725 | if ((status = do_mr_query("update_list", CountArgs(args), args, |
7ac48069 | 726 | NULL, NULL))) |
5eaef520 | 727 | { |
728 | com_err(program_name, status, " updating list, " | |
729 | "not deactivating list or filesystem"); | |
730 | FreeInfo(args); | |
731 | FreeQueue(elem); | |
732 | return; | |
28da9b65 | 733 | } |
5eaef520 | 734 | FreeInfo(args); |
735 | FreeQueue(elem); | |
736 | elem = NULL; | |
737 | } | |
738 | else if (status != MR_NO_MATCH) | |
739 | { | |
740 | com_err(program_name, status, " getting list info, " | |
741 | "not deactivating list or filesystem"); | |
742 | return; | |
00d4c0ba | 743 | } |
28da9b65 | 744 | |
5eaef520 | 745 | if ((status = do_mr_query("get_filesys_by_label", 1, &(info[NAME]), |
7ac48069 | 746 | StoreInfo, &elem))) |
5eaef520 | 747 | { |
748 | com_err(program_name, status, " getting filsys info, " | |
749 | "not deactivating filesystem"); | |
5eaef520 | 750 | return; |
00d4c0ba | 751 | } |
7ac48069 | 752 | args = QueueTop(elem)->q_data; |
5eaef520 | 753 | free(args[FS_TYPE]); |
7ac48069 | 754 | args[FS_TYPE] = strdup("ERR"); |
5eaef520 | 755 | free(args[FS_COMMENTS]); |
7ac48069 | 756 | args[FS_COMMENTS] = strdup("Locker disabled; call 3-1325 for help"); |
5eaef520 | 757 | FreeAndClear(&args[FS_MODTIME], TRUE); |
758 | FreeAndClear(&args[FS_MODBY], TRUE); | |
759 | FreeAndClear(&args[FS_MODWITH], TRUE); | |
533bacb3 | 760 | SlipInNewName(args, strdup(args[FS_NAME])); |
5eaef520 | 761 | if ((status = do_mr_query("update_filesys", CountArgs(args), args, |
7ac48069 | 762 | NULL, NULL))) |
5eaef520 | 763 | { |
764 | com_err(program_name, status, " updating filesystem, " | |
765 | "not deactivating filesystem"); | |
766 | FreeInfo(args); | |
767 | FreeQueue(elem); | |
768 | return; | |
00d4c0ba | 769 | } |
5eaef520 | 770 | FreeInfo(args); |
771 | FreeQueue(elem); | |
b3e25186 | 772 | } |
773 | } | |
774 | ||
775 | ||
776 | /* Function Name: DeactivateUser | |
777 | * Description: sets the user's status to 3. | |
778 | * Arguments: argc, argv - login name of the user in argv[1]. | |
779 | * Returns: DM_NORMAL. | |
780 | */ | |
781 | ||
5eaef520 | 782 | int DeactivateUser(int argc, char **argv) |
b3e25186 | 783 | { |
600b459e | 784 | struct mqelem *elem; |
b3e25186 | 785 | |
5eaef520 | 786 | elem = GetUserInfo(LOGIN, argv[1], NULL); |
787 | QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user"); | |
788 | ||
789 | FreeQueue(elem); | |
790 | return DM_NORMAL; | |
b3e25186 | 791 | } |
792 | ||
793 | ||
075fe5bb | 794 | /* ------------------------- Top Menu ------------------------- */ |
795 | ||
796 | /* DeleteUser() in delete.c */ | |
461c03b6 | 797 | |
075fe5bb | 798 | /* Function Name: DeleteUserByUid |
799 | * Description: Deletes the user given a uid number. | |
800 | * Arguments: argc, argv - uid if user in argv[1]. | |
08345b74 | 801 | * Returns: DM_NORMAL. |
5eaef520 | 802 | * NOTES: This just gets the username from the mr server |
075fe5bb | 803 | * and performs a DeleteUser(). |
08345b74 | 804 | */ |
805 | ||
5eaef520 | 806 | int DeleteUserByUid(int argc, char **argv) |
08345b74 | 807 | { |
5eaef520 | 808 | int status; |
600b459e | 809 | struct mqelem *elem = NULL; |
5eaef520 | 810 | char **info; |
811 | ||
812 | if (!ValidName(argv[1])) | |
813 | return DM_NORMAL; | |
814 | ||
815 | if ((status = do_mr_query("get_user_account_by_uid", 1, argv + 1, StoreInfo, | |
7ac48069 | 816 | &elem))) |
5eaef520 | 817 | com_err(program_name, status, " in get_user_account_by_uid"); |
818 | ||
7ac48069 | 819 | info = elem->q_data; |
5eaef520 | 820 | argv[1] = info[U_NAME]; |
821 | ||
822 | DeleteUser(argc, argv); | |
823 | return DM_NORMAL; | |
824 | } | |
08345b74 | 825 | |
075fe5bb | 826 | /* ------------------------- Show User Information ------------------------- */ |
08345b74 | 827 | |
828 | /* Function Name: ShowUserByLogin | |
829 | * Description: Shows user information given a login name. | |
830 | * Arguments: argc, argv - login name in argv[1]. | |
831 | * Returns: DM_NORMAL | |
832 | */ | |
833 | ||
5eaef520 | 834 | int ShowUserByLogin(int argc, char *argv[]) |
08345b74 | 835 | { |
600b459e | 836 | struct mqelem *top, *elem; |
08345b74 | 837 | |
5eaef520 | 838 | elem = top = GetUserInfo(LOGIN, argv[1], NULL); |
839 | Loop(elem, PrintUserInfo); | |
08345b74 | 840 | |
5eaef520 | 841 | FreeQueue(top); |
842 | return DM_NORMAL; | |
08345b74 | 843 | } |
844 | ||
845 | /* Function Name: RetrieveUserByName | |
846 | * Description: Show information on a user give fist and/or last name. | |
847 | * Arguments: argc, argv - argv[1] - first name. | |
848 | * argv[2] - last name. | |
849 | * Returns: DM_NORMAL. | |
850 | */ | |
851 | ||
5eaef520 | 852 | int ShowUserByName(int argc, char *argv[]) |
08345b74 | 853 | { |
600b459e | 854 | struct mqelem *top; |
5eaef520 | 855 | char buf[BUFSIZ]; |
08345b74 | 856 | |
5eaef520 | 857 | top = GetUserInfo(BY_NAME, argv[1], argv[2]); |
08345b74 | 858 | |
5eaef520 | 859 | if (!top) /* if there was an error then return. */ |
860 | return DM_NORMAL; | |
08345b74 | 861 | |
5eaef520 | 862 | if (!PromptWithDefault("Print full information, or just the names (f/n)?", |
863 | buf, 2, "f")) | |
864 | return DM_NORMAL; | |
08345b74 | 865 | |
5eaef520 | 866 | switch (buf[0]) |
867 | { | |
075fe5bb | 868 | case 'F': |
869 | case 'f': | |
5eaef520 | 870 | Loop(top, PrintUserInfo); |
871 | break; | |
075fe5bb | 872 | case 'N': |
873 | case 'n': | |
5eaef520 | 874 | Loop(top, PrintUserName); |
875 | break; | |
075fe5bb | 876 | } |
5eaef520 | 877 | |
878 | FreeQueue(top); | |
879 | return DM_NORMAL; | |
08345b74 | 880 | } |
881 | ||
882 | /* Function Name: ShowUserByClass | |
883 | * Description: Shows real and login names of all users in class. | |
884 | * Arguments: argc, argv - argv[1] contains the class. | |
885 | * Returns: none. | |
886 | */ | |
887 | ||
5eaef520 | 888 | int ShowUserByClass(int argc, char **argv) |
08345b74 | 889 | { |
600b459e | 890 | struct mqelem *top; |
08345b74 | 891 | |
5eaef520 | 892 | if (YesNoQuestion("This will take a long time. Are you sure", 0) == FALSE) |
893 | return DM_NORMAL; | |
894 | top = GetUserInfo(CLASS, argv[1], NULL); | |
895 | Loop(top, PrintUserName); | |
08345b74 | 896 | |
5eaef520 | 897 | FreeQueue(top); |
898 | return DM_NORMAL; | |
08345b74 | 899 | } |
1e80e2f4 | 900 | |
901 | ||
81701699 | 902 | /* Function Name: ShowUserById |
903 | * Description: Shows user information given an ID number. | |
904 | * Arguments: argc, argv - ID number in argv[1]. | |
905 | * Returns: DM_NORMAL | |
906 | */ | |
907 | ||
5eaef520 | 908 | int ShowUserById(int argc, char *argv[]) |
81701699 | 909 | { |
600b459e | 910 | struct mqelem *top, *elem; |
81701699 | 911 | |
5eaef520 | 912 | elem = top = GetUserInfo(ID, argv[1], NULL); |
913 | Loop(elem, PrintUserInfo); | |
81701699 | 914 | |
5eaef520 | 915 | FreeQueue(top); |
916 | return DM_NORMAL; | |
81701699 | 917 | } |
918 | ||
919 | ||
1e80e2f4 | 920 | /* Function Name: GetKrbmap |
921 | * Description: Shows user <-> Kerberos mappings | |
922 | * Arguments: argc, argv - argv[1] contains the user login name, | |
923 | * argv[2] contains the principal | |
924 | * Returns: none. | |
925 | */ | |
926 | ||
5eaef520 | 927 | int GetKrbmap(int argc, char **argv) |
1e80e2f4 | 928 | { |
5eaef520 | 929 | int stat; |
600b459e | 930 | struct mqelem *elem = NULL, *top; |
5eaef520 | 931 | char buf[BUFSIZ]; |
932 | ||
933 | if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1], | |
7ac48069 | 934 | StoreInfo, &elem))) |
5eaef520 | 935 | { |
936 | com_err(program_name, stat, " in GetKrbMap."); | |
937 | return DM_NORMAL; | |
1e80e2f4 | 938 | } |
939 | ||
5eaef520 | 940 | top = elem = QueueTop(elem); |
941 | Put_message(""); | |
942 | while (elem) | |
943 | { | |
7ac48069 | 944 | char **info = elem->q_data; |
5eaef520 | 945 | sprintf(buf, "User: %-9s Principal: %s", |
946 | info[KMAP_USER], info[KMAP_PRINCIPAL]); | |
947 | Put_message(buf); | |
948 | elem = elem->q_forw; | |
1e80e2f4 | 949 | } |
950 | ||
5eaef520 | 951 | FreeQueue(QueueTop(top)); |
952 | return DM_NORMAL; | |
1e80e2f4 | 953 | } |
954 | ||
955 | ||
956 | /* Function Name: AddKrbmap | |
957 | * Description: Add a new user <-> Kerberos mapping | |
958 | * Arguments: argc, argv - argv[1] contains the user login name, | |
959 | * argv[2] contains the principal | |
960 | * Returns: none. | |
961 | */ | |
962 | ||
5eaef520 | 963 | int AddKrbmap(int argc, char **argv) |
1e80e2f4 | 964 | { |
5eaef520 | 965 | int stat; |
1e80e2f4 | 966 | |
5eaef520 | 967 | if (!strchr(argv[KMAP_PRINCIPAL + 1], '@')) |
968 | { | |
969 | Put_message("Please specify a realm for the kerberos principal."); | |
970 | return DM_NORMAL; | |
1e80e2f4 | 971 | } |
5eaef520 | 972 | if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1], |
7ac48069 | 973 | NULL, NULL))) |
5eaef520 | 974 | { |
975 | com_err(program_name, stat, " in AddKrbMap."); | |
976 | if (stat == MR_EXISTS) | |
977 | Put_message("No user or principal may have more than one mapping."); | |
1e80e2f4 | 978 | } |
5eaef520 | 979 | return DM_NORMAL; |
1e80e2f4 | 980 | } |
981 | ||
982 | ||
983 | /* Function Name: DeleteKrbmap | |
984 | * Description: Remove a user <-> Kerberos mapping | |
985 | * Arguments: argc, argv - argv[1] contains the user login name, | |
986 | * argv[2] contains the principal | |
987 | * Returns: none. | |
988 | */ | |
989 | ||
5eaef520 | 990 | int DeleteKrbmap(int argc, char **argv) |
1e80e2f4 | 991 | { |
5eaef520 | 992 | int stat; |
1e80e2f4 | 993 | |
5eaef520 | 994 | if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1], |
7ac48069 | 995 | NULL, NULL))) |
5eaef520 | 996 | com_err(program_name, stat, " in DeleteKrbMap."); |
997 | return DM_NORMAL; | |
1e80e2f4 | 998 | } |
41c81c11 | 999 | |
1000 | int GetUserReservations(int argc, char **argv) | |
1001 | { | |
1002 | int stat; | |
1003 | struct mqelem *elem = NULL, *top; | |
1004 | char buf[BUFSIZ]; | |
1005 | ||
1006 | if ((stat = do_mr_query("get_user_reservations", 1, &argv[1], | |
1007 | StoreInfo, &elem))) | |
1008 | { | |
1009 | com_err(program_name, stat, " in GetUserReservations."); | |
1010 | return DM_NORMAL; | |
1011 | } | |
1012 | ||
1013 | top = elem = QueueTop(elem); | |
1014 | Put_message(""); | |
1015 | if (!elem) | |
1016 | Put_message("No reservations for that user."); | |
1017 | while (elem) | |
1018 | { | |
1019 | char **info = elem->q_data; | |
1020 | sprintf(buf, "Reservation: %s", info[0]); | |
1021 | Put_message(buf); | |
1022 | elem = elem->q_forw; | |
1023 | } | |
1024 | ||
1025 | FreeQueue(QueueTop(top)); | |
1026 | return DM_NORMAL; | |
1027 | } | |
1028 | ||
1029 | int AddUserReservation(int argc, char **argv) | |
1030 | { | |
1031 | int stat; | |
1032 | char buf[BUFSIZ]; | |
1033 | ||
e093b868 | 1034 | switch (stat = do_mr_query("add_user_reservation", 2, &argv[1], |
1035 | NULL, NULL)) | |
1036 | { | |
1037 | case MR_SUCCESS: | |
1038 | break; | |
1039 | case MR_STRING: | |
1040 | sprintf(buf, "The reservation %s is not valid.", argv[2]); | |
1041 | Put_message(buf); | |
1042 | PrintReservationTypes(); | |
1043 | break; | |
1044 | default: | |
41c81c11 | 1045 | com_err(program_name, stat, " in AddUserReservation."); |
e093b868 | 1046 | break; |
1047 | } | |
41c81c11 | 1048 | |
1049 | return DM_NORMAL; | |
1050 | } | |
1051 | ||
1052 | int DelUserReservation(int argc, char **argv) | |
1053 | { | |
1054 | int stat; | |
1055 | char buf[BUFSIZ]; | |
1056 | ||
e093b868 | 1057 | switch (stat = do_mr_query("delete_user_reservation", 2, &argv[1], |
1058 | NULL, NULL)) | |
41c81c11 | 1059 | { |
e093b868 | 1060 | case MR_SUCCESS: |
1061 | break; | |
1062 | case MR_STRING: | |
41c81c11 | 1063 | sprintf(buf, "The reservation %s is not valid.", argv[2]); |
1064 | Put_message(buf); | |
1065 | PrintReservationTypes(); | |
e093b868 | 1066 | break; |
1067 | default: | |
1068 | com_err(program_name, stat, " in DelUserReservation."); | |
1069 | break; | |
41c81c11 | 1070 | } |
41c81c11 | 1071 | |
1072 | return DM_NORMAL; | |
1073 | } | |
1074 | ||
1075 | int GetUserByReservation(int argc, char **argv) | |
1076 | { | |
1077 | int stat; | |
1078 | struct mqelem *elem = NULL, *top; | |
1079 | char buf[BUFSIZ]; | |
1080 | ||
e093b868 | 1081 | switch (stat = do_mr_query("get_user_by_reservation", 1, &argv[1], |
1082 | StoreInfo, &elem)) | |
41c81c11 | 1083 | { |
e093b868 | 1084 | case MR_SUCCESS: |
1085 | break; | |
1086 | case MR_STRING: | |
41c81c11 | 1087 | sprintf(buf, "The reservation %s is not valid.", argv[1]); |
1088 | Put_message(buf); | |
1089 | PrintReservationTypes(); | |
1090 | return DM_NORMAL; | |
e093b868 | 1091 | default: |
41c81c11 | 1092 | com_err(program_name, stat, " in GetUserByReservation."); |
1093 | return DM_NORMAL; | |
1094 | } | |
1095 | ||
1096 | top = elem = QueueTop(elem); | |
1097 | Put_message(""); | |
1098 | while (elem) | |
1099 | { | |
1100 | char **info = elem->q_data; | |
1101 | sprintf(buf, "User: %s", info[0]); | |
1102 | Put_message(buf); | |
1103 | elem = elem->q_forw; | |
1104 | } | |
1105 | ||
1106 | FreeQueue(QueueTop(top)); | |
1107 | return DM_NORMAL; | |
1108 | } | |
1109 | ||
1110 | void PrintReservationTypes(void) | |
1111 | { | |
1112 | int stat; | |
1113 | struct mqelem *elem = NULL, *top; | |
1114 | char buf[BUFSIZ]; | |
1115 | char *qargs[2]; | |
1116 | ||
1117 | Put_message("Valid types of reservations are: "); | |
1118 | Put_message(""); | |
1119 | qargs[0] = "*"; | |
1120 | qargs[1] = "RESERVE"; | |
1121 | qargs[2] = "*"; | |
1122 | if ((stat = do_mr_query("get_alias", 3, &qargs[0], | |
1123 | StoreInfo, &elem))) | |
1124 | { | |
1125 | com_err(program_name, stat, "in PrintReservationTypes."); | |
1126 | } | |
1127 | top = elem = QueueTop(elem); | |
1128 | while (elem) | |
1129 | { | |
1130 | char **info = elem->q_data; | |
1131 | sprintf(buf, "%s", info[2]); | |
1132 | Put_message(buf); | |
1133 | elem = elem->q_forw; | |
1134 | } | |
1135 | ||
1136 | FreeQueue(QueueTop(top)); | |
1137 | } | |
1138 |