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