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