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