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