]> andersk Git - moira.git/blob - clients/moira/user.c
accept encrypted ID number in quotes
[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 Encrypted MIT ID number: %s",
107             UserState(atoi(info[U_STATE])), info[U_MITID]);
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
119 static char **
120 SetUserDefaults(info)
121 char ** info;
122 {
123     info[U_NAME] = Strsave(UNIQUE_LOGIN);
124     info[U_UID] = Strsave(UNIQUE_UID);
125     info[U_SHELL] = Strsave(DEFAULT_SHELL);
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);
131     info[U_CLASS] = Strsave(DEFAULT_CLASS);
132     info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL;
133     return(info);
134 }
135
136
137 /* Check that the supplied name follows the capitalization rules, and 
138  * offer to correct it if not.
139  */
140
141 CorrectCapitalization(name)
142 char **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);
151         if (YesNoQuestion(temp_buf, 1) == TRUE) {
152             free(*name);
153             *name = strsave(fixname);
154         }
155     }
156 }
157
158
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
169 char **
170 AskUserInfo(info, name)
171 char ** info;
172 Bool name;
173 {
174     char temp_buf[BUFSIZ], fixname[BUFSIZ], *newname, *temp_ptr;
175
176     if (name) {
177         sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[U_NAME]);
178         Put_message(temp_buf);
179     } else {
180         struct qelem *elem = NULL;
181         char *argv[3];
182
183         if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
184           return(NULL);
185         CorrectCapitalization(&info[U_LAST]);
186         if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
187           return(NULL);
188         CorrectCapitalization(&info[U_FIRST]);
189         if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) ==
190             SUB_ERROR)
191           return(NULL);
192         CorrectCapitalization(&info[U_MIDDLE]);
193         argv[0] = info[U_FIRST];
194         argv[1] = info[U_LAST];
195         if (do_mr_query("get_user_by_name", 2, argv,
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);
201             if (YesNoQuestion("Add new user anyway", TRUE) != TRUE)
202               return(NULL);
203         }
204     }
205     if (name) {
206         newname = Strsave(info[U_NAME]);
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);
218     if (name) {
219         if (GetValueFromUser("User's last name", &info[U_LAST]) == SUB_ERROR)
220           return(NULL);
221         CorrectCapitalization(&info[U_LAST]);
222         if (GetValueFromUser("User's first name", &info[U_FIRST]) == SUB_ERROR)
223           return(NULL);
224         CorrectCapitalization(&info[U_FIRST]);
225         if (GetValueFromUser("User's middle name", &info[U_MIDDLE]) ==
226             SUB_ERROR)
227           return(NULL);
228         CorrectCapitalization(&info[U_MIDDLE]);
229     }
230     while (1) {
231         int i;
232         if (GetValueFromUser("User's status (? for help)", &info[U_STATE]) ==
233             SUB_ERROR)
234           return(NULL);
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     }
243     temp_ptr = Strsave(info[U_MITID]);
244     Put_message("User's MIT ID number (unencrypted, or encryption in quotes)");
245     if (GetValueFromUser("", &temp_ptr) == SUB_ERROR)
246       return(NULL);
247     if ( strcmp( temp_ptr, info[U_MITID] ) != 0) {
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         }
258     }
259     free(temp_ptr);
260     if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) ==
261         SUB_ERROR)
262       return(NULL);
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:
282  *                        LOGIN, UID, BY_NAME, CLASS.
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
289 struct qelem *
290 GetUserInfo(type, name1, name2)
291 int type;
292 char *name1, *name2;
293 {
294     char * args[2];
295     register int status;
296     struct qelem * elem = NULL;
297
298     switch(type) {
299     case LOGIN:
300         args[0] = name1;
301         if ( (status = do_mr_query("get_user_by_login", 1, args,
302                                     StoreInfo, (char *) &elem)) != 0) {
303             com_err(program_name, status, 
304                     " when attempting to get_user_by_login.");
305             return (NULL);               
306         }
307         break;
308     case UID:
309         args[0] = name1;
310         if ( (status = do_mr_query("get_user_by_uid", 1, args,
311                                     StoreInfo, (char *) &elem)) != 0) {
312             com_err(program_name, status, 
313                     " when attempting to get_user_by_uid.");
314             return (NULL);      
315         }
316         break;
317     case BY_NAME:
318         args[0] = name1;
319         args[1] = name2;    
320         if ( (status = do_mr_query("get_user_by_name", 2, args,
321                                     StoreInfo, (char *) &elem)) != 0) {
322             com_err(program_name, status, 
323                     " when attempting to get_user_by_name.");
324             return (NULL);      
325         }
326         break;
327     case CLASS:
328         args[0] = name1;
329         if ( (status = do_mr_query("get_user_by_class", 1, args,
330                                     StoreInfo, (char *) &elem)) != 0) {
331             com_err(program_name, status, 
332                     " when attempting to get_user_by_class.");
333             return (NULL);      
334         }
335         break;
336     }
337     return( QueueTop(elem) );
338 }
339
340 /*      Function Name: AddNewUser
341  *      Description: Adds a new user to the database.
342  *      Arguments: none.
343  *      Returns: DM_NORMAL.
344  */
345
346 /* ARGSUSED */
347 int
348 AddNewUser()
349 {
350     register int status;
351     char ** args, *info[MAX_ARGS_SIZE];
352
353     if ((args = AskUserInfo(SetUserDefaults(info), FALSE)) == NULL) {
354         Put_message("Aborted.");
355         return(DM_NORMAL);
356     }
357     if (args == NULL)
358       return(DM_NORMAL);
359     if ( (status = do_mr_query("add_user", CountArgs(args), 
360                                 args, Scream, (char *) NULL)) != MR_SUCCESS)
361         com_err(program_name, status, " in add_user");
362     else
363         Put_message("New user added to database.");
364     FreeInfo(args);
365     return(DM_NORMAL);
366 }
367
368
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.
374  */
375
376 static char *
377 GetLoginName()
378 {
379     char *name;
380
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);
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  */
394
395 static char *
396 ChooseUser(elem)
397 struct qelem * elem;
398 {
399     while (elem != NULL) {
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);
409         }
410         elem = elem->q_forw;
411     }
412     return(NULL);
413 }
414
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.
419  */
420
421 static char *
422 GetUidNumberFromName()
423 {
424     char *args[5], *uid, first[BUFSIZ], last[BUFSIZ];
425     register int status;
426     struct qelem * top = NULL;
427     
428     if (!Prompt_input("First Name: ", first, BUFSIZ))
429       return(NULL);
430     if (!Prompt_input("Last  Name: ", last, BUFSIZ))
431       return(NULL);
432     FixCase(first);
433     FixCase(last);
434
435     args[0] = first;
436     args[1] = last;
437     
438     switch (status = do_mr_query("get_user_by_name", 2, args,
439                                   StoreInfo, (char *) &top)) {
440     case MR_SUCCESS:
441         break;
442     case MR_NO_MATCH:
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);
448     }
449     
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     }
460
461     Put_message("That name is not unique, choose the user that you want.");
462     uid = ChooseUser(top);
463     FreeQueue(top);
464     return(uid);
465 }
466
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.
471  */
472
473 static void
474 SetUserPassword(name)
475 char * name;
476 {
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 }
481
482 /*      Function Name:  GiveBackLogin
483  *      Description: Gives back previously reserved kerberous principle.
484  *      Arguments: name - principle to give back.
485  *      Returns: void.
486  */
487
488 static void
489 GiveBackLogin(name)
490 char * name;
491 {
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. */
495 }
496
497 /*      Function Name: RegisterUser
498  *      Description: This function registers a user.
499  *      Arguments: none.
500  *      Returns: DM_NORMAL.
501  */
502
503 int
504 RegisterUser()
505 {
506     char * args[MAX_ARGS_SIZE];
507     char *login, *fstype = NULL;
508     char temp_buf[BUFSIZ];
509     register int status;
510     
511     Put_message("This function has NO kerberos support, so stange things");
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);
525     }
526
527     if ( ((login = args[1] = GetLoginName()) == NULL) ||
528         ( GetFSTypes(&fstype, FALSE) == SUB_ERROR ) ) {
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     
535     switch (status = do_mr_query("register_user", CountArgs(args),
536                                   args, Scream, (char *) NULL)) {
537     case MR_SUCCESS:
538         sprintf(temp_buf, "User %s successfully registered.", login);
539         Put_message(temp_buf);
540         SetUserPassword(login);
541         break;
542     case MR_IN_USE:
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);
553 }
554
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.
560  */
561
562 /* ARGSUSED */
563 static void
564 RealUpdateUser(info, junk)
565 char ** info;
566 Bool junk;
567 {
568     register int status;
569     char error_buf[BUFSIZ];
570     char ** args = AskUserInfo(info, TRUE);
571
572     if (args == NULL) {
573         Put_message("Aborted.");
574         return;
575     }
576     if ( (status = do_mr_query("update_user", CountArgs(args), 
577                                 args, Scream, (char *) NULL)) != MR_SUCCESS) {
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);
581     }
582 }
583
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].
587  *      Returns: DM_NORMAL.
588  */
589
590 /* ARGSUSED */
591 int
592 UpdateUser(argc, argv)
593 int argc;
594 char **argv;
595 {
596     struct qelem * elem;
597
598     elem = GetUserInfo(LOGIN, argv[1], (char *) NULL);
599     QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user");
600     
601     FreeQueue(elem);
602     return(DM_NORMAL);
603 }
604
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
612 static void
613 RealDeactivateUser(info, one_item)
614 char ** info;
615 Bool 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]);
623         if (YesNoQuestion(txt_buf, FALSE) != TRUE)
624             return;
625     }
626
627     qargs[0] = info[NAME];
628     qargs[1] = "3";
629     if ((status = do_mr_query("update_user_status", 2, qargs, Scream,
630                                (char *) NULL)) != MR_SUCCESS) {
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 */
645 int
646 DeactivateUser(argc, argv)
647 int argc;
648 char **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
660 /* ------------------------- Top Menu ------------------------- */
661
662 /* DeleteUser() in delete.c */
663
664 /*      Function Name: DeleteUserByUid
665  *      Description: Deletes the user given a uid number.
666  *      Arguments: argc, argv - uid if user in argv[1].
667  *      Returns: DM_NORMAL.
668  *      NOTES: This just gets the username from the mr server 
669  *             and performs a DeleteUser().
670  */
671
672 int
673 DeleteUserByUid(argc, argv)
674 int argc;
675 char **argv;
676 {
677     int status;
678     struct qelem *elem = NULL;
679     char ** info;
680
681     if(!ValidName(argv[1]))
682         return(DM_NORMAL);
683     
684     if ( (status = do_mr_query("get_user_by_uid", 1, argv+1, StoreInfo,
685                                 (char * ) &elem)) != MR_SUCCESS)
686         com_err(program_name, status, " in get_user_by_uid");
687     
688     info = (char **) elem->q_data;
689     argv[1] = info[U_NAME];
690
691     (void) DeleteUser(argc, argv);
692     return(DM_NORMAL);
693
694
695 /* ------------------------- Show User Information ------------------------- */
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 */
704 int
705 ShowUserByLogin(argc, argv)
706 int argc;
707 char *argv[];
708 {
709     struct qelem *top, *elem;
710
711     elem = top = GetUserInfo(LOGIN, argv[1], (char *) NULL);
712     Loop(elem, PrintUserInfo);
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 */
726 int
727 ShowUserByName(argc, argv)
728 int argc;
729 char *argv[];
730 {
731     struct qelem *top;
732     char buf[BUFSIZ];
733
734     top = GetUserInfo(BY_NAME, argv[1], argv[2]);
735
736     if (top == NULL)            /* if there was an error then return. */
737         return(DM_NORMAL);
738
739     if (!PromptWithDefault("Print full information, or just the names (f/n)?",
740                            buf, 2, "f"))
741         return(DM_NORMAL);
742
743     switch(buf[0]) {
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     
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
764 /* ARGSUSED */
765 int
766 ShowUserByClass(argc, argv)
767 int argc;
768 char **argv;
769 {
770     struct qelem *top;
771
772     top = GetUserInfo(CLASS, argv[1], (char *) NULL);
773     Loop(top, PrintUserName);
774
775     FreeQueue(top);
776     return (DM_NORMAL);
777 }
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 */
788 int
789 GetKrbmap(argc, argv)
790 int argc;
791 char **argv;
792 {
793     int stat;
794     struct qelem *elem = NULL, *top;
795     char buf[BUFSIZ];
796
797     if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1],
798                              StoreInfo, (char *)&elem)) != 0) {
799         com_err(program_name, stat, " in GetKrbMap.");
800         return(DM_NORMAL);
801     }
802
803     top = elem = QueueTop(elem);
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
813     FreeQueue(QueueTop(top));
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 */
826 int
827 AddKrbmap(argc, argv)
828 int argc;
829 char **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     }
837     if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1],
838                              Scream, NULL)) != 0) {
839         com_err(program_name, stat, " in AddKrbMap.");
840         if (stat == MR_EXISTS)
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 */
855 int
856 DeleteKrbmap(argc, argv)
857 int argc;
858 char **argv;
859 {
860     int stat;
861
862     if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1],
863                              Scream, NULL)) != 0) {
864         com_err(program_name, stat, " in DeleteKrbMap.");
865     }
866     return(DM_NORMAL);
867 }
This page took 0.121084 seconds and 5 git commands to generate.