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