]> andersk Git - moira.git/blame - clients/moira/user.c
changed ATHENA.MIT.EDU to just MIT.EDU
[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 int status;
edd2ce4e 105#ifdef GDSS
559fe7ab 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;
edd2ce4e 209#ifdef GDSS
559fe7ab 210 SigInfo si;
edd2ce4e 211#endif
559fe7ab 212 char temp_buf[BUFSIZ], *newname, *temp_ptr, *sig, sig_buf[BUFSIZ];
08345b74 213
075fe5bb 214 if (name) {
215 sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[U_NAME]);
216 Put_message(temp_buf);
ebd96e37 217 } else {
218 struct qelem *elem = NULL;
219 char *argv[3];
220
e4f91beb 221 if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
222 return(NULL);
f0a54771 223 CorrectCapitalization(&info[U_LAST]);
e4f91beb 224 if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
225 return(NULL);
f0a54771 226 CorrectCapitalization(&info[U_FIRST]);
e4f91beb 227 if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) ==
228 SUB_ERROR)
229 return(NULL);
f0a54771 230 CorrectCapitalization(&info[U_MIDDLE]);
ebd96e37 231 argv[0] = info[U_FIRST];
232 argv[1] = info[U_LAST];
b8322cb3 233 if (do_mr_query("get_user_account_by_name", 2, argv,
ebd96e37 234 StoreInfo, (char *) &elem) == 0) {
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);
e4f91beb 239 if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
ebd96e37 240 return(NULL);
241 }
075fe5bb 242 }
08345b74 243 if (name) {
244 newname = Strsave(info[U_NAME]);
e4f91beb 245 if (GetValueFromUser("The new login name for this user", &newname) ==
246 SUB_ERROR)
247 return(NULL);
248 } else if (GetValueFromUser("Login name for this user", &info[U_NAME]) ==
249 SUB_ERROR)
250 return(NULL);
251
252 if (GetValueFromUser("User's UID", &info[U_UID]) == SUB_ERROR)
253 return(NULL);
254 if (GetValueFromUser("User's shell", &info[U_SHELL]) == SUB_ERROR)
255 return(NULL);
ebd96e37 256 if (name) {
e4f91beb 257 if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
258 return(NULL);
f0a54771 259 CorrectCapitalization(&info[U_LAST]);
e4f91beb 260 if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
261 return(NULL);
f0a54771 262 CorrectCapitalization(&info[U_FIRST]);
e4f91beb 263 if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) ==
264 SUB_ERROR)
265 return(NULL);
f0a54771 266 CorrectCapitalization(&info[U_MIDDLE]);
ebd96e37 267 }
1e80e2f4 268 while (1) {
269 int i;
e4f91beb 270 if (GetValueFromUser("User's status (? for help)", &info[U_STATE]) ==
271 SUB_ERROR)
272 return(NULL);
1e80e2f4 273 if (isdigit(info[U_STATE][0]))
274 break;
275 Put_message("Valid status numbers:");
276 for (i = 0; i < US_END; i++) {
277 sprintf(temp_buf, " %d: %s", i, states[i]);
278 Put_message(temp_buf);
279 }
280 }
b281b38b 281 if (GetValueFromUser("User's MIT ID number", &info[U_MITID]) == SUB_ERROR)
e4f91beb 282 return(NULL);
6ec067c7 283 RemoveHyphens(info[U_MITID]);
e4f91beb 284 if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) ==
285 SUB_ERROR)
286 return(NULL);
b8322cb3 287 if (GetValueFromUser("Comments", &info[U_COMMENT]) == SUB_ERROR)
288 return(NULL);
289
559fe7ab 290 if (YesNoQuestion("Secure password set",
291 atoi(info[U_SECURE]) ? TRUE : FALSE) == FALSE) {
292 free(info[U_SECURE]);
293 info[U_SECURE] = strsave("0");
294 } else if (!strcmp(info[U_SECURE], "0")) {
295 char buf[16];
296 struct timeval tv;
297
298 gettimeofday(&tv, (struct timezone *)NULL);
299 sprintf(buf, "%d", tv.tv_sec);
300 free(info[U_SECURE]);
301 info[U_SECURE] = strsave(buf);
302 }
303
b8322cb3 304 /* Sign record */
305#ifdef GDSS
559fe7ab 306 if (strcmp(info[U_NAME], UNIQUE_LOGIN)) {
00d4c0ba 307 if (name)
308 sprintf(temp_buf, "%s:%s", newname, info[U_MITID]);
309 else
310 sprintf(temp_buf, "%s:%s", info[U_NAME], info[U_MITID]);
559fe7ab 311 si.rawsig = NULL;
312 i = GDSS_Verify(temp_buf, strlen(temp_buf), info[U_SIGNATURE], &si);
313 /* If it's already signed OK, don't resign it. */
314 if (i != GDSS_SUCCESS) {
315 free(info[U_SIGNATURE]);
316 info[U_SIGNATURE] = malloc(GDSS_Sig_Size() * 2);
cd42d372 317 sign_again:
559fe7ab 318 i = GDSS_Sign(temp_buf, strlen(temp_buf), info[U_SIGNATURE]);
319 if (i != GDSS_SUCCESS)
320 com_err(program_name, gdss2et(i), "Failed to create signature");
cd42d372 321 else {
322 unsigned char buf[256];
323 si.rawsig = buf;
324 i = GDSS_Verify(temp_buf, strlen(temp_buf),
325 info[U_SIGNATURE], &si);
326 if (strlen(buf) > 68) {
327#ifdef DEBUG
328 Put_message("Signature too long, trying again");
329#endif /* DEBUG */
330 goto sign_again;
331 }
332 }
559fe7ab 333#ifdef DEBUG
d3e6bc1b 334 Put_message("Made signature:");
559fe7ab 335 } else {
336 Put_message("Don't need to remake signature");
337#endif /* DEBUG */
338 }
d3e6bc1b 339#ifdef DEBUG
340 hex_dump(info[U_SIGNATURE]);
341#endif /* DEBUG */
559fe7ab 342 }
b8322cb3 343#else /* GDSS */
344 info[U_SIGNATURE] = strsave("");
345#endif /* GDSS */
346
08345b74 347 FreeAndClear(&info[U_MODTIME], TRUE);
348 FreeAndClear(&info[U_MODBY], TRUE);
349 FreeAndClear(&info[U_MODWITH], TRUE);
350
351/*
352 * Slide the newname into the #2 slot, this screws up all future references
353 * to this list, since we slip the pointer into a info list it gets freed
354 * when the rest of the list gets freed.
355 */
356 if (name)
357 SlipInNewName(info, newname);
358
359 return(info);
360}
361
362/* Function Name: GetUserInfo
363 * Description: Stores the user information in a queue.
364 * Arguments: type - type of field given to get info, one of:
402461ad 365 * LOGIN, UID, BY_NAME, CLASS.
08345b74 366 * name1 - name of thing specified by type (wildcards okay)
367 * name2 - other name, only used in get user by first and last.
368 * (wildcards okay).
369 * Returns: the first element of the queue containing the user info.
370 */
371
372struct qelem *
461c03b6 373GetUserInfo(type, name1, name2)
08345b74 374int type;
375char *name1, *name2;
376{
377 char * args[2];
461c03b6 378 register int status;
379 struct qelem * elem = NULL;
08345b74 380
381 switch(type) {
382 case LOGIN:
383 args[0] = name1;
b8322cb3 384 if ( (status = do_mr_query("get_user_account_by_login", 1, args,
14f99d7d 385 StoreInfo, (char *) &elem)) != 0) {
85ca828a 386 com_err(program_name, status,
b8322cb3 387 " when attempting to get_user_account_by_login.");
08345b74 388 return (NULL);
389 }
390 break;
391 case UID:
392 args[0] = name1;
b8322cb3 393 if ( (status = do_mr_query("get_user_account_by_uid", 1, args,
14f99d7d 394 StoreInfo, (char *) &elem)) != 0) {
461c03b6 395 com_err(program_name, status,
b8322cb3 396 " when attempting to get_user_account_by_uid.");
08345b74 397 return (NULL);
398 }
399 break;
402461ad 400 case BY_NAME:
08345b74 401 args[0] = name1;
402 args[1] = name2;
b8322cb3 403 if ( (status = do_mr_query("get_user_account_by_name", 2, args,
14f99d7d 404 StoreInfo, (char *) &elem)) != 0) {
461c03b6 405 com_err(program_name, status,
b8322cb3 406 " when attempting to get_user_account_by_name.");
08345b74 407 return (NULL);
408 }
409 break;
410 case CLASS:
411 args[0] = name1;
b8322cb3 412 if ( (status = do_mr_query("get_user_account_by_class", 1, args,
14f99d7d 413 StoreInfo, (char *) &elem)) != 0) {
461c03b6 414 com_err(program_name, status,
b8322cb3 415 " when attempting to get_user_account_by_class.");
08345b74 416 return (NULL);
417 }
418 break;
08345b74 419 }
420 return( QueueTop(elem) );
421}
422
075fe5bb 423/* Function Name: AddNewUser
424 * Description: Adds a new user to the database.
425 * Arguments: none.
08345b74 426 * Returns: DM_NORMAL.
427 */
428
429/* ARGSUSED */
430int
075fe5bb 431AddNewUser()
08345b74 432{
075fe5bb 433 register int status;
434 char ** args, *info[MAX_ARGS_SIZE];
435
e4f91beb 436 if ((args = AskUserInfo(SetUserDefaults(info), FALSE)) == NULL) {
437 Put_message("Aborted.");
438 return(DM_NORMAL);
439 }
ebd96e37 440 if (args == NULL)
441 return(DM_NORMAL);
b8322cb3 442 if ( (status = do_mr_query("add_user_account", CountArgs(args),
8defc06b 443 args, Scream, (char *) NULL)) != MR_SUCCESS)
b8322cb3 444 com_err(program_name, status, " in add_user_account");
075fe5bb 445 else
446 Put_message("New user added to database.");
447 FreeInfo(args);
08345b74 448 return(DM_NORMAL);
449}
450
451
075fe5bb 452/* Function Name: GetLoginName
453 * Description: Asks the user for a login name and reserves
454 * it with kerberous.
455 * Arguments: none.
456 * Returns: a malloced login name for the user.
08345b74 457 */
458
075fe5bb 459static char *
460GetLoginName()
08345b74 461{
e4f91beb 462 char *name;
075fe5bb 463
e4f91beb 464 name = strsave("");
465 if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR)
466 return(NULL);
467 Put_message("KERBEROS code not added, did not reserve name with kerberos.");
468 return(name);
075fe5bb 469}
470
471
472/* Function Name: ChooseUser
473 * Description: Choose a user from a list and return the uid.
474 * Arguments: top - a queue of user information.
475 * Returns: uid - the malloced uid of the user that was chosen.
476 */
08345b74 477
075fe5bb 478static char *
479ChooseUser(elem)
480struct qelem * elem;
481{
08345b74 482 while (elem != NULL) {
075fe5bb 483 char ** info = (char **) elem->q_data;
484 PrintUserInfo(info);
485 switch(YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE)) {
486 case TRUE:
487 return(Strsave(info[U_UID]));
488 case FALSE:
489 break;
490 default: /* quit or ^C. */
491 return(NULL);
08345b74 492 }
493 elem = elem->q_forw;
494 }
075fe5bb 495 return(NULL);
08345b74 496}
497
075fe5bb 498/* Function Name: GetUidNumberFromName
499 * Description: Gets the users uid number, from the name.
500 * Arguments: none.
501 * Returns: uid - a malloced string containing the uid.
08345b74 502 */
503
075fe5bb 504static char *
505GetUidNumberFromName()
08345b74 506{
075fe5bb 507 char *args[5], *uid, first[BUFSIZ], last[BUFSIZ];
461c03b6 508 register int status;
075fe5bb 509 struct qelem * top = NULL;
510
e4f91beb 511 if (!Prompt_input("First Name: ", first, BUFSIZ))
512 return(NULL);
513 if (!Prompt_input("Last Name: ", last, BUFSIZ))
514 return(NULL);
f0a54771 515 FixCase(first);
516 FixCase(last);
08345b74 517
075fe5bb 518 args[0] = first;
519 args[1] = last;
08345b74 520
b8322cb3 521 switch (status = do_mr_query("get_user_account_by_name", 2, args,
14f99d7d 522 StoreInfo, (char *) &top)) {
8defc06b 523 case MR_SUCCESS:
075fe5bb 524 break;
8defc06b 525 case MR_NO_MATCH:
075fe5bb 526 Put_message("There is no user in the database with that name.");
527 return(NULL);
528 default:
b8322cb3 529 com_err(program_name, status, " in get_account_user_by_name.");
075fe5bb 530 return(NULL);
08345b74 531 }
532
075fe5bb 533 top = QueueTop(top);
534 if (QueueCount(top) == 1) /* This is a unique name. */ {
535 char ** info = (char **) top->q_data;
536 Put_message("User ID Number retrieved for the user: ");
537 Put_message("");
538 PrintUserName(info);
539 uid = Strsave(info[U_UID]);
540 FreeQueue(top);
541 return(Strsave(uid));
542 }
08345b74 543
075fe5bb 544 Put_message("That name is not unique, choose the user that you want.");
545 uid = ChooseUser(top);
546 FreeQueue(top);
547 return(uid);
08345b74 548}
549
075fe5bb 550/* Function Name: SetUserPassword
551 * Description: Set the new kerberos password for this user.
552 * Arguments: name - kerberos principle name for this user, (login name).
553 * Returns: none.
08345b74 554 */
555
075fe5bb 556static void
557SetUserPassword(name)
558char * name;
08345b74 559{
075fe5bb 560 name = name; /* make saber happy. */
561 Put_message("Kerberos password not changed, code non-existant.");
562 /* clever message to call account_admin, if this fails. */
563}
08345b74 564
075fe5bb 565/* Function Name: GiveBackLogin
566 * Description: Gives back previously reserved kerberous principle.
567 * Arguments: name - principle to give back.
568 * Returns: void.
08345b74 569 */
570
075fe5bb 571static void
572GiveBackLogin(name)
573char * name;
08345b74 574{
075fe5bb 575 name = name; /* make saber happy. */
576 Put_message("kerberos code not implimented, name not given back.");
577 /* send mail to db maintainer if this fails. */
08345b74 578}
579
075fe5bb 580/* Function Name: RegisterUser
581 * Description: This function registers a user.
582 * Arguments: none.
583 * Returns: DM_NORMAL.
08345b74 584 */
585
08345b74 586int
075fe5bb 587RegisterUser()
08345b74 588{
075fe5bb 589 char * args[MAX_ARGS_SIZE];
590 char *login, *fstype = NULL;
591 char temp_buf[BUFSIZ];
592 register int status;
461c03b6 593
160420e8 594 Put_message("This function has NO kerberos support, so strange things");
075fe5bb 595 Put_message("may happen if you use it to register a user.");
596
597 switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE)) {
598 case TRUE:
599 Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ);
600 args[0] = Strsave(temp_buf);
601 break;
602 case FALSE:
603 if ( (args[0] = GetUidNumberFromName()) == NULL)
604 return(DM_NORMAL);
605 break;
606 default:
607 return(DM_NORMAL);
461c03b6 608 }
075fe5bb 609
610 if ( ((login = args[1] = GetLoginName()) == NULL) ||
4f91474a 611 ( GetFSTypes(&fstype, FALSE) == SUB_ERROR ) ) {
075fe5bb 612 FreeInfo(args); /* This work because the NULL temination is ok. */
613 return(DM_NORMAL);
614 }
615 args[2] = fstype;
616 args[3] = NULL;
617
8defc06b 618 switch (status = do_mr_query("register_user", CountArgs(args),
14f99d7d 619 args, Scream, (char *) NULL)) {
8defc06b 620 case MR_SUCCESS:
075fe5bb 621 sprintf(temp_buf, "User %s successfully registered.", login);
622 Put_message(temp_buf);
623 SetUserPassword(login);
624 break;
8defc06b 625 case MR_IN_USE:
075fe5bb 626 GiveBackLogin(login);
627 sprintf(temp_buf, "The username %s is already in use.", login);
628 Put_message(temp_buf);
629 break;
630 default:
631 com_err(program_name, status, " in register_user");
632 break;
633 }
634 FreeInfo(args);
635 return(DM_NORMAL);
08345b74 636}
637
075fe5bb 638/* Function Name: RealUpdateUser
639 * Description: actuall updates the user information.
640 * Arguments: info - all current information for the user fields.
641 * junk - an UNUSED boolean.
642 * Returns: none.
08345b74 643 */
644
075fe5bb 645/* ARGSUSED */
646static void
647RealUpdateUser(info, junk)
648char ** info;
649Bool junk;
08345b74 650{
075fe5bb 651 register int status;
652 char error_buf[BUFSIZ];
653 char ** args = AskUserInfo(info, TRUE);
e4f91beb 654
655 if (args == NULL) {
656 Put_message("Aborted.");
657 return;
658 }
b8322cb3 659 if ( (status = do_mr_query("update_user_account", CountArgs(args),
8defc06b 660 args, Scream, (char *) NULL)) != MR_SUCCESS) {
075fe5bb 661 com_err(program_name, status, " in ModifyFields");
662 sprintf(error_buf, "User %s not updated due to errors.", info[NAME]);
663 Put_message(error_buf);
08345b74 664 }
08345b74 665}
666
075fe5bb 667/* Function Name: UpdateUser
668 * Description: Modify some of the information about a user.
669 * Arguments: argc, argv - login name of the user in argv[1].
08345b74 670 * Returns: DM_NORMAL.
671 */
672
075fe5bb 673/* ARGSUSED */
08345b74 674int
075fe5bb 675UpdateUser(argc, argv)
08345b74 676int argc;
677char **argv;
678{
075fe5bb 679 struct qelem * elem;
08345b74 680
075fe5bb 681 elem = GetUserInfo(LOGIN, argv[1], (char *) NULL);
682 QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user");
08345b74 683
075fe5bb 684 FreeQueue(elem);
08345b74 685 return(DM_NORMAL);
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
695static void
696RealDeactivateUser(info, one_item)
697char ** info;
698Bool one_item;
699{
700 register int status;
701 char txt_buf[BUFSIZ];
00d4c0ba 702 char * qargs[2], **args;
703 struct qelem *elem = NULL;
b3e25186 704
705 if (one_item) {
706 sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]);
e4f91beb 707 if (YesNoQuestion(txt_buf, FALSE) != TRUE)
b3e25186 708 return;
709 }
710
711 qargs[0] = info[NAME];
712 qargs[1] = "3";
8defc06b 713 if ((status = do_mr_query("update_user_status", 2, qargs, Scream,
714 (char *) NULL)) != MR_SUCCESS) {
b3e25186 715 com_err(program_name, status, " in update_user_status");
716 sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]);
717 Put_message(txt_buf);
00d4c0ba 718 } else if (YesNoQuestion("Also deactivate matching list and filesystem (y/n)",
719 FALSE) == TRUE) {
720 if (status = do_mr_query("get_list_info", 1, &(info[NAME]),
721 StoreInfo, (char *) &elem)) {
722 com_err(program_name, status, " getting list info, not deactivating list or filesystem");
723 return;
724 }
725 args =(char **) (QueueTop(elem)->q_data);
726 free(args[L_ACTIVE]);
727 args[L_ACTIVE] = strsave("0");
728 FreeAndClear(&args[L_MODTIME], TRUE);
729 FreeAndClear(&args[L_MODBY], TRUE);
730 FreeAndClear(&args[L_MODWITH], TRUE);
731 SlipInNewName(args, args[L_NAME]);
732 if (status = do_mr_query("update_list", CountArgs(args), args,
733 Scream, (char *) NULL)) {
734 com_err(program_name, status, " updating list, not deactivating list or filesystem");
735 FreeInfo(args);
736 FreeQueue(elem);
737 return;
738 }
739 FreeInfo(args);
740 FreeQueue(elem);
741 elem = (struct qelem *) NULL;
742 if (status = do_mr_query("get_filesys_by_label", 1, &(info[NAME]),
743 StoreInfo, (char *) &elem)) {
744 com_err(program_name, status, " getting filsys info, not deactivating filesystem");
745 FreeInfo(args);
746 FreeQueue(elem);
747 return;
748 }
749 args = (char **) (QueueTop(elem)->q_data);
750 free(args[FS_TYPE]);
751 args[FS_TYPE] = strsave("ERR");
752 free(args[FS_COMMENTS]);
753 args[FS_COMMENTS] = strsave("Locker disabled; call 3-1325 for help");
754 FreeAndClear(&args[FS_MODTIME], TRUE);
755 FreeAndClear(&args[FS_MODBY], TRUE);
756 FreeAndClear(&args[FS_MODWITH], TRUE);
757 SlipInNewName(args, args[FS_NAME]);
758 if (status = do_mr_query("update_filesys", CountArgs(args), args,
759 Scream, (char *) NULL)) {
760 com_err(program_name, status, " updating filesystem, not deactivating filesystem");
761 FreeInfo(args);
762 FreeQueue(elem);
763 return;
764 }
765 FreeInfo(args);
766 FreeQueue(elem);
b3e25186 767 }
768}
769
770
771/* Function Name: DeactivateUser
772 * Description: sets the user's status to 3.
773 * Arguments: argc, argv - login name of the user in argv[1].
774 * Returns: DM_NORMAL.
775 */
776
777/* ARGSUSED */
778int
779DeactivateUser(argc, argv)
780int argc;
781char **argv;
782{
783 struct qelem * elem;
784
785 elem = GetUserInfo(LOGIN, argv[1], (char *) NULL);
786 QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user");
787
788 FreeQueue(elem);
789 return(DM_NORMAL);
790}
791
792
075fe5bb 793/* ------------------------- Top Menu ------------------------- */
794
795/* DeleteUser() in delete.c */
461c03b6 796
075fe5bb 797/* Function Name: DeleteUserByUid
798 * Description: Deletes the user given a uid number.
799 * Arguments: argc, argv - uid if user in argv[1].
08345b74 800 * Returns: DM_NORMAL.
8defc06b 801 * NOTES: This just gets the username from the mr server
075fe5bb 802 * and performs a DeleteUser().
08345b74 803 */
804
08345b74 805int
075fe5bb 806DeleteUserByUid(argc, argv)
08345b74 807int argc;
808char **argv;
809{
461c03b6 810 int status;
075fe5bb 811 struct qelem *elem = NULL;
812 char ** info;
813
814 if(!ValidName(argv[1]))
815 return(DM_NORMAL);
816
b8322cb3 817 if ( (status = do_mr_query("get_user_account_by_uid", 1, argv+1, StoreInfo,
8defc06b 818 (char * ) &elem)) != MR_SUCCESS)
b8322cb3 819 com_err(program_name, status, " in get_user_account_by_uid");
075fe5bb 820
821 info = (char **) elem->q_data;
822 argv[1] = info[U_NAME];
08345b74 823
075fe5bb 824 (void) DeleteUser(argc, argv);
08345b74 825 return(DM_NORMAL);
075fe5bb 826}
08345b74 827
075fe5bb 828/* ------------------------- Show User Information ------------------------- */
08345b74 829
830/* Function Name: ShowUserByLogin
831 * Description: Shows user information given a login name.
832 * Arguments: argc, argv - login name in argv[1].
833 * Returns: DM_NORMAL
834 */
835
836/* ARGSUSED */
837int
838ShowUserByLogin(argc, argv)
839int argc;
840char *argv[];
841{
842 struct qelem *top, *elem;
843
844 elem = top = GetUserInfo(LOGIN, argv[1], (char *) NULL);
075fe5bb 845 Loop(elem, PrintUserInfo);
08345b74 846
847 FreeQueue(top);
848 return (DM_NORMAL);
849}
850
851/* Function Name: RetrieveUserByName
852 * Description: Show information on a user give fist and/or last name.
853 * Arguments: argc, argv - argv[1] - first name.
854 * argv[2] - last name.
855 * Returns: DM_NORMAL.
856 */
857
858/* ARGSUSED */
859int
860ShowUserByName(argc, argv)
861int argc;
862char *argv[];
863{
075fe5bb 864 struct qelem *top;
3c1a8806 865 char buf[BUFSIZ];
08345b74 866
075fe5bb 867 top = GetUserInfo(BY_NAME, argv[1], argv[2]);
08345b74 868
075fe5bb 869 if (top == NULL) /* if there was an error then return. */
08345b74 870 return(DM_NORMAL);
871
075fe5bb 872 if (!PromptWithDefault("Print full information, or just the names (f/n)?",
334eb344 873 buf, 2, "f"))
075fe5bb 874 return(DM_NORMAL);
08345b74 875
3c1a8806 876 switch(buf[0]) {
075fe5bb 877 case 'F':
878 case 'f':
879 Loop(top, PrintUserInfo);
880 break;
881 case 'N':
882 case 'n':
883 Loop(top, PrintUserName);
884 break;
885 }
886
08345b74 887 FreeQueue(top);
888 return (DM_NORMAL);
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
85ca828a 897/* ARGSUSED */
08345b74 898int
899ShowUserByClass(argc, argv)
900int argc;
901char **argv;
902{
075fe5bb 903 struct qelem *top;
08345b74 904
b8322cb3 905 if (YesNoQuestion("This will take a long time. Are you sure", 0) == FALSE)
906 return (DM_NORMAL);
075fe5bb 907 top = GetUserInfo(CLASS, argv[1], (char *) NULL);
908 Loop(top, PrintUserName);
08345b74 909
910 FreeQueue(top);
911 return (DM_NORMAL);
912}
1e80e2f4 913
914
915/* Function Name: GetKrbmap
916 * Description: Shows user <-> Kerberos mappings
917 * Arguments: argc, argv - argv[1] contains the user login name,
918 * argv[2] contains the principal
919 * Returns: none.
920 */
921
922/* ARGSUSED */
923int
924GetKrbmap(argc, argv)
925int argc;
926char **argv;
927{
928 int stat;
78fce9fa 929 struct qelem *elem = NULL, *top;
1e80e2f4 930 char buf[BUFSIZ];
931
8defc06b 932 if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1],
1e80e2f4 933 StoreInfo, (char *)&elem)) != 0) {
934 com_err(program_name, stat, " in GetKrbMap.");
935 return(DM_NORMAL);
936 }
937
78fce9fa 938 top = elem = QueueTop(elem);
1e80e2f4 939 Put_message("");
940 while (elem != NULL) {
941 char **info = (char **) elem->q_data;
942 sprintf(buf, "User: %-9s Principal: %s",
943 info[KMAP_USER], info[KMAP_PRINCIPAL]);
944 Put_message(buf);
945 elem = elem->q_forw;
946 }
947
78fce9fa 948 FreeQueue(QueueTop(top));
1e80e2f4 949 return(DM_NORMAL);
950}
951
952
953/* Function Name: AddKrbmap
954 * Description: Add a new user <-> Kerberos mapping
955 * Arguments: argc, argv - argv[1] contains the user login name,
956 * argv[2] contains the principal
957 * Returns: none.
958 */
959
960/* ARGSUSED */
961int
962AddKrbmap(argc, argv)
963int argc;
964char **argv;
965{
966 int stat;
967
968 if (!index(argv[KMAP_PRINCIPAL + 1], '@')) {
969 Put_message("Please specify a realm for the kerberos principal.");
970 return(DM_NORMAL);
971 }
8defc06b 972 if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1],
1e80e2f4 973 Scream, NULL)) != 0) {
974 com_err(program_name, stat, " in AddKrbMap.");
8defc06b 975 if (stat == MR_EXISTS)
1e80e2f4 976 Put_message("No user or principal may have more than one mapping.");
977 }
978 return(DM_NORMAL);
979}
980
981
982/* Function Name: DeleteKrbmap
983 * Description: Remove a user <-> Kerberos mapping
984 * Arguments: argc, argv - argv[1] contains the user login name,
985 * argv[2] contains the principal
986 * Returns: none.
987 */
988
989/* ARGSUSED */
990int
991DeleteKrbmap(argc, argv)
992int argc;
993char **argv;
994{
995 int stat;
996
8defc06b 997 if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1],
1e80e2f4 998 Scream, NULL)) != 0) {
999 com_err(program_name, stat, " in DeleteKrbMap.");
1000 }
1001 return(DM_NORMAL);
1002}
559fe7ab 1003
1004
1005hex_dump(p)
1006unsigned char *p;
1007{
1008 char buf[BUFSIZ];
1009 int i;
1010
1011 sprintf(buf, "Size: %d", strlen(p));
1012 Put_message(buf);
1013 while (strlen(p) >= 8) {
1014 sprintf(buf, "%02x %02x %02x %02x %02x %02x %02x %02x",
1015 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
1016 Put_message(buf);
1017 p += 8;
1018 }
1019 switch (strlen(p)) {
1020 case 7:
1021 sprintf(buf, "%02x %02x %02x %02x %02x %02x %02x",
1022 p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
1023 break;
1024 case 6:
1025 sprintf(buf, "%02x %02x %02x %02x %02x %02x",
1026 p[0], p[1], p[2], p[3], p[4], p[5]);
1027 break;
1028 case 5:
1029 sprintf(buf, "%02x %02x %02x %02x %02x",
1030 p[0], p[1], p[2], p[3], p[4]);
1031 break;
1032 case 4:
1033 sprintf(buf, "%02x %02x %02x %02x",
1034 p[0], p[1], p[2], p[3]);
1035 break;
1036 case 3:
1037 sprintf(buf, "%02x %02x %02x",
1038 p[0], p[1], p[2]);
1039 break;
1040 case 2:
1041 sprintf(buf, "%02x %02x",
1042 p[0], p[1]);
1043 break;
1044 case 1:
1045 sprintf(buf, "%02x",
1046 p[0]);
1047 break;
1048 default:
1049 return;
1050 }
1051 Put_message(buf);
1052}
This page took 0.237127 seconds and 5 git commands to generate.