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