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