]> andersk Git - moira.git/blob - clients/moira/user.c
no longer encrypt ID numbers
[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",
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], *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     if (GetValueFromUser("User's MIT ID number", &info[U_MITID]) == SUB_ERROR)
244       return(NULL);
245     if (GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]) ==
246         SUB_ERROR)
247       return(NULL);
248     
249     FreeAndClear(&info[U_MODTIME], TRUE);
250     FreeAndClear(&info[U_MODBY], TRUE);
251     FreeAndClear(&info[U_MODWITH], TRUE);
252
253 /* 
254  * Slide the newname into the #2 slot, this screws up all future references 
255  * to this list, since we slip the pointer into a info list it gets freed 
256  * when the rest of the list gets freed.
257  */
258     if (name)                   
259         SlipInNewName(info, newname);
260
261     return(info);
262 }
263
264 /*      Function Name: GetUserInfo
265  *      Description: Stores the user information in a queue.
266  *      Arguments: type - type of field given to get info, one of:
267  *                        LOGIN, UID, BY_NAME, CLASS.
268  *                 name1 - name of thing specified by type (wildcards okay)
269  *                 name2 - other name, only used in get user by first and last.
270  *                         (wildcards okay).
271  *      Returns: the first element of the queue containing the user info.
272  */
273
274 struct qelem *
275 GetUserInfo(type, name1, name2)
276 int type;
277 char *name1, *name2;
278 {
279     char * args[2];
280     register int status;
281     struct qelem * elem = NULL;
282
283     switch(type) {
284     case LOGIN:
285         args[0] = name1;
286         if ( (status = do_mr_query("get_user_by_login", 1, args,
287                                     StoreInfo, (char *) &elem)) != 0) {
288             com_err(program_name, status, 
289                     " when attempting to get_user_by_login.");
290             return (NULL);               
291         }
292         break;
293     case UID:
294         args[0] = name1;
295         if ( (status = do_mr_query("get_user_by_uid", 1, args,
296                                     StoreInfo, (char *) &elem)) != 0) {
297             com_err(program_name, status, 
298                     " when attempting to get_user_by_uid.");
299             return (NULL);      
300         }
301         break;
302     case BY_NAME:
303         args[0] = name1;
304         args[1] = name2;    
305         if ( (status = do_mr_query("get_user_by_name", 2, args,
306                                     StoreInfo, (char *) &elem)) != 0) {
307             com_err(program_name, status, 
308                     " when attempting to get_user_by_name.");
309             return (NULL);      
310         }
311         break;
312     case CLASS:
313         args[0] = name1;
314         if ( (status = do_mr_query("get_user_by_class", 1, args,
315                                     StoreInfo, (char *) &elem)) != 0) {
316             com_err(program_name, status, 
317                     " when attempting to get_user_by_class.");
318             return (NULL);      
319         }
320         break;
321     }
322     return( QueueTop(elem) );
323 }
324
325 /*      Function Name: AddNewUser
326  *      Description: Adds a new user to the database.
327  *      Arguments: none.
328  *      Returns: DM_NORMAL.
329  */
330
331 /* ARGSUSED */
332 int
333 AddNewUser()
334 {
335     register int status;
336     char ** args, *info[MAX_ARGS_SIZE];
337
338     if ((args = AskUserInfo(SetUserDefaults(info), FALSE)) == NULL) {
339         Put_message("Aborted.");
340         return(DM_NORMAL);
341     }
342     if (args == NULL)
343       return(DM_NORMAL);
344     if ( (status = do_mr_query("add_user", CountArgs(args), 
345                                 args, Scream, (char *) NULL)) != MR_SUCCESS)
346         com_err(program_name, status, " in add_user");
347     else
348         Put_message("New user added to database.");
349     FreeInfo(args);
350     return(DM_NORMAL);
351 }
352
353
354 /*      Function Name: GetLoginName
355  *      Description: Asks the user for a login name and reserves
356  *                   it with kerberous.
357  *      Arguments: none.
358  *      Returns: a malloced login name for the user.
359  */
360
361 static char *
362 GetLoginName()
363 {
364     char *name;
365
366     name = strsave("");
367     if (GetValueFromUser("Login name for this user? ", &name) == SUB_ERROR)
368       return(NULL);
369     Put_message("KERBEROS code not added, did not reserve name with kerberos.");
370     return(name);
371 }
372
373
374 /*      Function Name: ChooseUser
375  *      Description: Choose a user from a list and return the uid.
376  *      Arguments: top - a queue of user information.
377  *      Returns: uid - the malloced uid of the user that was chosen.
378  */
379
380 static char *
381 ChooseUser(elem)
382 struct qelem * elem;
383 {
384     while (elem != NULL) {
385         char ** info = (char **)  elem->q_data;
386         PrintUserInfo(info);
387         switch(YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE)) {
388         case TRUE:
389             return(Strsave(info[U_UID]));
390         case FALSE:
391             break;
392         default:                /* quit or ^C. */
393             return(NULL);
394         }
395         elem = elem->q_forw;
396     }
397     return(NULL);
398 }
399
400 /*      Function Name: GetUidNumberFromName
401  *      Description: Gets the users uid number, from the name.
402  *      Arguments: none.
403  *      Returns: uid - a malloced string containing the uid.
404  */
405
406 static char *
407 GetUidNumberFromName()
408 {
409     char *args[5], *uid, first[BUFSIZ], last[BUFSIZ];
410     register int status;
411     struct qelem * top = NULL;
412     
413     if (!Prompt_input("First Name: ", first, BUFSIZ))
414       return(NULL);
415     if (!Prompt_input("Last  Name: ", last, BUFSIZ))
416       return(NULL);
417     FixCase(first);
418     FixCase(last);
419
420     args[0] = first;
421     args[1] = last;
422     
423     switch (status = do_mr_query("get_user_by_name", 2, args,
424                                   StoreInfo, (char *) &top)) {
425     case MR_SUCCESS:
426         break;
427     case MR_NO_MATCH:
428         Put_message("There is no user in the database with that name.");
429         return(NULL);
430     default:
431         com_err(program_name, status, " in get_user_by_name.");
432         return(NULL);
433     }
434     
435     top = QueueTop(top);
436     if (QueueCount(top) == 1) /* This is a unique name. */ {
437         char ** info = (char **) top->q_data;
438         Put_message("User ID Number retrieved for the user: ");
439         Put_message("");
440         PrintUserName(info);
441         uid = Strsave(info[U_UID]);
442         FreeQueue(top);
443         return(Strsave(uid));
444     }
445
446     Put_message("That name is not unique, choose the user that you want.");
447     uid = ChooseUser(top);
448     FreeQueue(top);
449     return(uid);
450 }
451
452 /*      Function Name: SetUserPassword
453  *      Description: Set the new kerberos password for this user.
454  *      Arguments: name - kerberos principle name for this user, (login name).
455  *      Returns: none.
456  */
457
458 static void
459 SetUserPassword(name)
460 char * name;
461 {
462     name = name;                        /* make saber happy. */
463     Put_message("Kerberos password not changed, code non-existant.");
464     /* clever message to call account_admin, if this fails. */
465 }
466
467 /*      Function Name:  GiveBackLogin
468  *      Description: Gives back previously reserved kerberous principle.
469  *      Arguments: name - principle to give back.
470  *      Returns: void.
471  */
472
473 static void
474 GiveBackLogin(name)
475 char * name;
476 {
477     name = name;                        /* make saber happy. */
478     Put_message("kerberos code not implimented, name not given back.");
479     /* send mail to db maintainer if this fails. */
480 }
481
482 /*      Function Name: RegisterUser
483  *      Description: This function registers a user.
484  *      Arguments: none.
485  *      Returns: DM_NORMAL.
486  */
487
488 int
489 RegisterUser()
490 {
491     char * args[MAX_ARGS_SIZE];
492     char *login, *fstype = NULL;
493     char temp_buf[BUFSIZ];
494     register int status;
495     
496     Put_message("This function has NO kerberos support, so strange things");
497     Put_message("may happen if you use it to register a user.");
498
499     switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE)) {
500     case TRUE:
501         Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ);
502         args[0] = Strsave(temp_buf);
503         break;
504     case FALSE:
505         if ( (args[0] = GetUidNumberFromName()) == NULL)
506             return(DM_NORMAL);
507         break;
508     default:
509         return(DM_NORMAL);
510     }
511
512     if ( ((login = args[1] = GetLoginName()) == NULL) ||
513         ( GetFSTypes(&fstype, FALSE) == SUB_ERROR ) ) {
514         FreeInfo(args);    /* This work because the NULL temination is ok. */
515         return(DM_NORMAL);
516     }
517     args[2] = fstype;
518     args[3] = NULL;
519     
520     switch (status = do_mr_query("register_user", CountArgs(args),
521                                   args, Scream, (char *) NULL)) {
522     case MR_SUCCESS:
523         sprintf(temp_buf, "User %s successfully registered.", login);
524         Put_message(temp_buf);
525         SetUserPassword(login);
526         break;
527     case MR_IN_USE:
528         GiveBackLogin(login);
529         sprintf(temp_buf, "The username %s is already in use.", login);
530         Put_message(temp_buf);
531         break;
532     default:
533         com_err(program_name, status, " in register_user");
534         break;
535     }
536     FreeInfo(args);
537     return(DM_NORMAL);
538 }
539
540 /*      Function Name: RealUpdateUser
541  *      Description: actuall updates the user information.
542  *      Arguments: info - all current information for the user fields.
543  *                 junk - an UNUSED boolean.
544  *      Returns: none.
545  */
546
547 /* ARGSUSED */
548 static void
549 RealUpdateUser(info, junk)
550 char ** info;
551 Bool junk;
552 {
553     register int status;
554     char error_buf[BUFSIZ];
555     char ** args = AskUserInfo(info, TRUE);
556
557     if (args == NULL) {
558         Put_message("Aborted.");
559         return;
560     }
561     if ( (status = do_mr_query("update_user", CountArgs(args), 
562                                 args, Scream, (char *) NULL)) != MR_SUCCESS) {
563         com_err(program_name, status, " in ModifyFields");
564         sprintf(error_buf, "User %s not updated due to errors.", info[NAME]);
565         Put_message(error_buf);
566     }
567 }
568
569 /*      Function Name: UpdateUser
570  *      Description: Modify some of the information about a user.
571  *      Arguments: argc, argv - login name of the user in argv[1].
572  *      Returns: DM_NORMAL.
573  */
574
575 /* ARGSUSED */
576 int
577 UpdateUser(argc, argv)
578 int argc;
579 char **argv;
580 {
581     struct qelem * elem;
582
583     elem = GetUserInfo(LOGIN, argv[1], (char *) NULL);
584     QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user");
585     
586     FreeQueue(elem);
587     return(DM_NORMAL);
588 }
589
590 /*      Function Name: RealDeactivateUser
591  *      Description: sets the user's status to 3.
592  *      Arguments: info - all current information for the user fields
593  *                 one_item - indicates the user hasn't been queried yet
594  *      Returns: none.
595  */
596
597 static void
598 RealDeactivateUser(info, one_item)
599 char ** info;
600 Bool one_item;
601 {
602     register int status;
603     char txt_buf[BUFSIZ];
604     char * qargs[2];
605
606     if (one_item) {
607         sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]);
608         if (YesNoQuestion(txt_buf, FALSE) != TRUE)
609             return;
610     }
611
612     qargs[0] = info[NAME];
613     qargs[1] = "3";
614     if ((status = do_mr_query("update_user_status", 2, qargs, Scream,
615                                (char *) NULL)) != MR_SUCCESS) {
616         com_err(program_name, status, " in update_user_status");
617         sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]);
618         Put_message(txt_buf);
619     }
620 }
621
622
623 /*      Function Name: DeactivateUser
624  *      Description: sets the user's status to 3.
625  *      Arguments: argc, argv - login name of the user in argv[1].
626  *      Returns: DM_NORMAL.
627  */
628
629 /* ARGSUSED */
630 int
631 DeactivateUser(argc, argv)
632 int argc;
633 char **argv;
634 {
635     struct qelem * elem;
636
637     elem = GetUserInfo(LOGIN, argv[1], (char *) NULL);
638     QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user");
639     
640     FreeQueue(elem);
641     return(DM_NORMAL);
642 }
643
644
645 /* ------------------------- Top Menu ------------------------- */
646
647 /* DeleteUser() in delete.c */
648
649 /*      Function Name: DeleteUserByUid
650  *      Description: Deletes the user given a uid number.
651  *      Arguments: argc, argv - uid if user in argv[1].
652  *      Returns: DM_NORMAL.
653  *      NOTES: This just gets the username from the mr server 
654  *             and performs a DeleteUser().
655  */
656
657 int
658 DeleteUserByUid(argc, argv)
659 int argc;
660 char **argv;
661 {
662     int status;
663     struct qelem *elem = NULL;
664     char ** info;
665
666     if(!ValidName(argv[1]))
667         return(DM_NORMAL);
668     
669     if ( (status = do_mr_query("get_user_by_uid", 1, argv+1, StoreInfo,
670                                 (char * ) &elem)) != MR_SUCCESS)
671         com_err(program_name, status, " in get_user_by_uid");
672     
673     info = (char **) elem->q_data;
674     argv[1] = info[U_NAME];
675
676     (void) DeleteUser(argc, argv);
677     return(DM_NORMAL);
678
679
680 /* ------------------------- Show User Information ------------------------- */
681
682 /*      Function Name: ShowUserByLogin
683  *      Description: Shows user information given a login name.
684  *      Arguments: argc, argv - login name in argv[1].
685  *      Returns: DM_NORMAL
686  */
687
688 /* ARGSUSED */
689 int
690 ShowUserByLogin(argc, argv)
691 int argc;
692 char *argv[];
693 {
694     struct qelem *top, *elem;
695
696     elem = top = GetUserInfo(LOGIN, argv[1], (char *) NULL);
697     Loop(elem, PrintUserInfo);
698
699     FreeQueue(top);
700     return (DM_NORMAL);
701 }
702
703 /*      Function Name: RetrieveUserByName
704  *      Description: Show information on a user give fist and/or last name.
705  *      Arguments: argc, argv - argv[1] - first name.
706  *                              argv[2] - last name.
707  *      Returns: DM_NORMAL.
708  */
709
710 /* ARGSUSED */
711 int
712 ShowUserByName(argc, argv)
713 int argc;
714 char *argv[];
715 {
716     struct qelem *top;
717     char buf[BUFSIZ];
718
719     top = GetUserInfo(BY_NAME, argv[1], argv[2]);
720
721     if (top == NULL)            /* if there was an error then return. */
722         return(DM_NORMAL);
723
724     if (!PromptWithDefault("Print full information, or just the names (f/n)?",
725                            buf, 2, "f"))
726         return(DM_NORMAL);
727
728     switch(buf[0]) {
729     case 'F':
730     case 'f':
731         Loop(top, PrintUserInfo);
732         break;
733     case 'N':
734     case 'n':
735         Loop(top, PrintUserName);
736         break;
737     }
738     
739     FreeQueue(top);
740     return (DM_NORMAL);
741 }
742
743 /*      Function Name: ShowUserByClass
744  *      Description: Shows real and login names of all users in class.
745  *      Arguments: argc, argv - argv[1] contains the class.
746  *      Returns: none.
747  */
748
749 /* ARGSUSED */
750 int
751 ShowUserByClass(argc, argv)
752 int argc;
753 char **argv;
754 {
755     struct qelem *top;
756
757     top = GetUserInfo(CLASS, argv[1], (char *) NULL);
758     Loop(top, PrintUserName);
759
760     FreeQueue(top);
761     return (DM_NORMAL);
762 }
763
764
765 /*      Function Name: GetKrbmap
766  *      Description: Shows user <-> Kerberos mappings
767  *      Arguments: argc, argv - argv[1] contains the user login name,
768  *              argv[2] contains the principal
769  *      Returns: none.
770  */
771
772 /* ARGSUSED */
773 int
774 GetKrbmap(argc, argv)
775 int argc;
776 char **argv;
777 {
778     int stat;
779     struct qelem *elem = NULL, *top;
780     char buf[BUFSIZ];
781
782     if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1],
783                              StoreInfo, (char *)&elem)) != 0) {
784         com_err(program_name, stat, " in GetKrbMap.");
785         return(DM_NORMAL);
786     }
787
788     top = elem = QueueTop(elem);
789     Put_message("");
790     while (elem != NULL) {
791         char **info = (char **) elem->q_data;
792         sprintf(buf, "User: %-9s Principal: %s",
793                 info[KMAP_USER], info[KMAP_PRINCIPAL]);
794         Put_message(buf);
795         elem = elem->q_forw;
796     }
797
798     FreeQueue(QueueTop(top));
799     return(DM_NORMAL);
800 }
801
802
803 /*      Function Name: AddKrbmap
804  *      Description: Add a new user <-> Kerberos mapping
805  *      Arguments: argc, argv - argv[1] contains the user login name,
806  *              argv[2] contains the principal
807  *      Returns: none.
808  */
809
810 /* ARGSUSED */
811 int
812 AddKrbmap(argc, argv)
813 int argc;
814 char **argv;
815 {
816     int stat;
817
818     if (!index(argv[KMAP_PRINCIPAL + 1], '@')) {
819         Put_message("Please specify a realm for the kerberos principal.");
820         return(DM_NORMAL);
821     }
822     if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1],
823                              Scream, NULL)) != 0) {
824         com_err(program_name, stat, " in AddKrbMap.");
825         if (stat == MR_EXISTS)
826           Put_message("No user or principal may have more than one mapping.");
827     }
828     return(DM_NORMAL);
829 }
830
831
832 /*      Function Name: DeleteKrbmap
833  *      Description: Remove a user <-> Kerberos mapping
834  *      Arguments: argc, argv - argv[1] contains the user login name,
835  *              argv[2] contains the principal
836  *      Returns: none.
837  */
838
839 /* ARGSUSED */
840 int
841 DeleteKrbmap(argc, argv)
842 int argc;
843 char **argv;
844 {
845     int stat;
846
847     if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1],
848                              Scream, NULL)) != 0) {
849         com_err(program_name, stat, " in DeleteKrbMap.");
850     }
851     return(DM_NORMAL);
852 }
This page took 0.109092 seconds and 5 git commands to generate.