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