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