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