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