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