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