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