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