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