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