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