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