]>
Commit | Line | Data |
---|---|---|
402461ad | 1 | #if (!defined(lint) && !defined(SABER)) |
08345b74 | 2 | static char rcsid_module_c[] = "$Header$"; |
3 | #endif lint | |
4 | ||
8defc06b | 5 | /* This is the file user.c for the MOIRA Client, which allows a nieve |
6 | * user to quickly and easily maintain most parts of the MOIRA database. | |
0a2c64cb | 7 | * It Contains: Functions for manipulating user information. |
08345b74 | 8 | * |
9 | * Created: 5/9/88 | |
10 | * By: Chris D. Peterson | |
11 | * | |
12 | * $Source$ | |
13 | * $Author$ | |
14 | * $Header$ | |
15 | * | |
0a2c64cb | 16 | * Copyright 1988 by the Massachusetts Institute of Technology. |
08345b74 | 17 | * |
18 | * For further information on copyright and distribution | |
19 | * see the file mit-copyright.h | |
20 | */ | |
21 | ||
08345b74 | 22 | #include <stdio.h> |
23 | #include <strings.h> | |
8defc06b | 24 | #include <moira.h> |
25 | #include <moira_site.h> | |
08345b74 | 26 | #include <menu.h> |
1e80e2f4 | 27 | #include <ctype.h> |
08345b74 | 28 | |
461c03b6 | 29 | #include "mit-copyright.h" |
0a2c64cb | 30 | #include "defs.h" |
31 | #include "f_defs.h" | |
461c03b6 | 32 | #include "globals.h" |
461c03b6 | 33 | |
08345b74 | 34 | #define LOGIN 0 |
35 | #define UID 1 | |
402461ad | 36 | #define BY_NAME 2 |
075fe5bb | 37 | #define CLASS 3 |
08345b74 | 38 | |
07b2e652 | 39 | #define DEFAULT_SHELL "/bin/csh" |
40 | #define DEFAULT_CLASS "?" | |
41 | ||
42 | ||
32de30b0 | 43 | /* Function Name: UserState |
44 | * Description: Convert a numeric state into a descriptive string. | |
45 | * Arguments: state value | |
46 | * Returns: pointer to statically allocated string. | |
47 | */ | |
48 | ||
78fce9fa | 49 | static char *states[] = { "Registerable (0)", |
50 | "Active (1)", | |
51 | "Half Registered (2)", | |
52 | "Deleted (3)", | |
53 | "Not registerable (4)", | |
54 | "Enrolled/Registerable (5)", | |
377712b4 | 55 | "Enrolled/Not Registerable (6)", |
56 | "Half Enrolled (7)" }; | |
32de30b0 | 57 | |
58 | static char *UserState(state) | |
59 | int state; | |
60 | { | |
78fce9fa | 61 | char buf[BUFSIZ]; |
62 | ||
63 | if (state < 0 || state >= US_END) { | |
64 | sprintf(buf, "Unknown (%d)", state); | |
65 | return(buf); | |
66 | } | |
32de30b0 | 67 | return(states[state]); |
68 | } | |
69 | ||
70 | ||
075fe5bb | 71 | /* Function Name: PrintUserName |
72 | * Description: Print name of a user. | |
73 | * Arguments: info - the information about a user. | |
74 | * Returns: none. | |
75 | */ | |
76 | ||
77 | static void | |
78 | PrintUserName(info) | |
79 | char ** info; | |
80 | { | |
81 | char buf[BUFSIZ], print_buf[BUFSIZ]; | |
82 | sprintf(buf, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]); | |
83 | sprintf(print_buf, "%-40s User Name: %s", buf, info[U_NAME]); | |
84 | Put_message(print_buf); | |
85 | } | |
86 | ||
87 | /* Function Name: PrintUserInfo | |
88 | * Description: Prints Information about a user. | |
89 | * Arguments: info - an argument list with the user information | |
90 | * in it. | |
91 | * Returns: none | |
92 | */ | |
93 | ||
94 | static void | |
95 | PrintUserInfo(info) | |
96 | char ** info; | |
97 | { | |
98 | char name[BUFSIZ], buf[BUFSIZ]; | |
99 | ||
100 | sprintf(name, "%s, %s %s", info[U_LAST], info[U_FIRST], info[U_MIDDLE]); | |
1e80e2f4 | 101 | sprintf(buf, "Login name: %-20s Full name: %s", info[U_NAME], name); |
075fe5bb | 102 | Put_message(buf); |
1e80e2f4 | 103 | sprintf(buf, "User id: %-23s Login shell %-10s Class: %s", |
075fe5bb | 104 | info[U_UID], info[U_SHELL], info[U_CLASS]); |
105 | Put_message(buf); | |
1e80e2f4 | 106 | sprintf(buf, "Account is: %-20s Encrypted MIT ID number: %s", |
32de30b0 | 107 | UserState(atoi(info[U_STATE])), info[U_MITID]); |
075fe5bb | 108 | Put_message(buf); |
109 | sprintf(buf, MOD_FORMAT, info[U_MODBY], info[U_MODTIME],info[U_MODWITH]); | |
110 | Put_message(buf); | |
111 | } | |
112 | ||
113 | /* Function Name: SetUserDefaults | |
114 | * Description: Sets the default values for add user. | |
115 | * Arguments: info - a blank user info array of char *'s. | |
116 | * Returns: args - the filled info structure. | |
117 | */ | |
118 | ||
119 | static char ** | |
120 | SetUserDefaults(info) | |
121 | char ** info; | |
122 | { | |
123 | info[U_NAME] = Strsave(UNIQUE_LOGIN); | |
124 | info[U_UID] = Strsave(UNIQUE_UID); | |
07b2e652 | 125 | info[U_SHELL] = Strsave(DEFAULT_SHELL); |
075fe5bb | 126 | info[U_LAST] = Strsave(DEFAULT_NONE); |
127 | info[U_FIRST] = Strsave(DEFAULT_NONE); | |
128 | info[U_MIDDLE] = Strsave(DEFAULT_NONE); | |
129 | info[U_STATE] = Strsave(DEFAULT_NO); | |
130 | info[U_MITID] = Strsave(DEFAULT_NONE); | |
07b2e652 | 131 | info[U_CLASS] = Strsave(DEFAULT_CLASS); |
075fe5bb | 132 | info[U_MODTIME] = info[U_MODBY] = info[U_MODWITH] = info[U_END] = NULL; |
133 | return(info); | |
134 | } | |
461c03b6 | 135 | |
08345b74 | 136 | /* Function Name: AskUserInfo. |
137 | * Description: This function askes the user for information about a | |
138 | * machine and saves it into a structure. | |
139 | * Arguments: info - a pointer the the structure to put the info into. | |
140 | * flags - Flags asking us which info we want. | |
141 | * Returns: the args to pass to the query. | |
142 | * NOTES: the return args are not necessarily in the correct order to | |
143 | * use the #defined names (e.g args[UID] is not the uid anymore). | |
144 | */ | |
145 | ||
461c03b6 | 146 | char ** |
147 | AskUserInfo(info, name) | |
08345b74 | 148 | char ** info; |
149 | Bool name; | |
150 | { | |
075fe5bb | 151 | char temp_buf[BUFSIZ], *newname, *temp_ptr; |
08345b74 | 152 | |
075fe5bb | 153 | if (name) { |
154 | sprintf(temp_buf,"\nChanging Attributes of user %s.\n",info[U_NAME]); | |
155 | Put_message(temp_buf); | |
ebd96e37 | 156 | } else { |
157 | struct qelem *elem = NULL; | |
158 | char *argv[3]; | |
159 | ||
160 | GetValueFromUser("User's last name", &info[U_LAST]); | |
161 | GetValueFromUser("User's first name", &info[U_FIRST]); | |
162 | GetValueFromUser("User's middle name", &info[U_MIDDLE]); | |
163 | argv[0] = info[U_FIRST]; | |
164 | argv[1] = info[U_LAST]; | |
8defc06b | 165 | if (do_mr_query("get_user_by_name", 2, argv, |
ebd96e37 | 166 | StoreInfo, (char *) &elem) == 0) { |
167 | Put_message("A user by that name already exists in the database."); | |
168 | Loop(QueueTop(elem), PrintUserInfo); | |
169 | Loop(QueueTop(elem), FreeInfo); | |
170 | FreeQueue(elem); | |
171 | if (YesNoQuestion("Add new user anyway", TRUE) == FALSE) | |
172 | return(NULL); | |
173 | } | |
075fe5bb | 174 | } |
08345b74 | 175 | if (name) { |
176 | newname = Strsave(info[U_NAME]); | |
075fe5bb | 177 | GetValueFromUser("The new login name for this user", &newname); |
08345b74 | 178 | } |
075fe5bb | 179 | else |
180 | GetValueFromUser("Login name for this user", &info[U_NAME]); | |
181 | ||
182 | GetValueFromUser("User's UID", &info[U_UID]); | |
183 | GetValueFromUser("User's shell", &info[U_SHELL]); | |
ebd96e37 | 184 | if (name) { |
185 | GetValueFromUser("User's last name", &info[U_LAST]); | |
186 | GetValueFromUser("User's first name", &info[U_FIRST]); | |
187 | GetValueFromUser("User's middle name", &info[U_MIDDLE]); | |
188 | } | |
1e80e2f4 | 189 | while (1) { |
190 | int i; | |
191 | GetValueFromUser("User's status (? for help)", &info[U_STATE]); | |
192 | if (isdigit(info[U_STATE][0])) | |
193 | break; | |
194 | Put_message("Valid status numbers:"); | |
195 | for (i = 0; i < US_END; i++) { | |
196 | sprintf(temp_buf, " %d: %s", i, states[i]); | |
197 | Put_message(temp_buf); | |
198 | } | |
199 | } | |
075fe5bb | 200 | temp_ptr = Strsave(info[U_MITID]); |
07b2e652 | 201 | Put_message("User's MIT ID number (type a new unencrypted number, or keep same encryption)"); |
202 | GetValueFromUser("", &temp_ptr); | |
075fe5bb | 203 | if ( strcmp( temp_ptr, info[U_MITID] ) != 0) { |
b3e25186 | 204 | EncryptID(temp_buf, temp_ptr, info[U_FIRST], info[U_LAST]); |
075fe5bb | 205 | free(info[U_MITID]); |
206 | info[U_MITID] = Strsave(temp_buf); | |
207 | } | |
208 | free(temp_ptr); | |
07b2e652 | 209 | GetTypeFromUser("User's MIT Year (class)", "class", &info[U_CLASS]); |
08345b74 | 210 | |
211 | FreeAndClear(&info[U_MODTIME], TRUE); | |
212 | FreeAndClear(&info[U_MODBY], TRUE); | |
213 | FreeAndClear(&info[U_MODWITH], TRUE); | |
214 | ||
215 | /* | |
216 | * Slide the newname into the #2 slot, this screws up all future references | |
217 | * to this list, since we slip the pointer into a info list it gets freed | |
218 | * when the rest of the list gets freed. | |
219 | */ | |
220 | if (name) | |
221 | SlipInNewName(info, newname); | |
222 | ||
223 | return(info); | |
224 | } | |
225 | ||
226 | /* Function Name: GetUserInfo | |
227 | * Description: Stores the user information in a queue. | |
228 | * Arguments: type - type of field given to get info, one of: | |
402461ad | 229 | * LOGIN, UID, BY_NAME, CLASS. |
08345b74 | 230 | * name1 - name of thing specified by type (wildcards okay) |
231 | * name2 - other name, only used in get user by first and last. | |
232 | * (wildcards okay). | |
233 | * Returns: the first element of the queue containing the user info. | |
234 | */ | |
235 | ||
236 | struct qelem * | |
461c03b6 | 237 | GetUserInfo(type, name1, name2) |
08345b74 | 238 | int type; |
239 | char *name1, *name2; | |
240 | { | |
241 | char * args[2]; | |
461c03b6 | 242 | register int status; |
243 | struct qelem * elem = NULL; | |
08345b74 | 244 | |
245 | switch(type) { | |
246 | case LOGIN: | |
247 | args[0] = name1; | |
8defc06b | 248 | if ( (status = do_mr_query("get_user_by_login", 1, args, |
14f99d7d | 249 | StoreInfo, (char *) &elem)) != 0) { |
85ca828a | 250 | com_err(program_name, status, |
075fe5bb | 251 | " when attempting to get_user_by_login."); |
08345b74 | 252 | return (NULL); |
253 | } | |
254 | break; | |
255 | case UID: | |
256 | args[0] = name1; | |
8defc06b | 257 | if ( (status = do_mr_query("get_user_by_uid", 1, args, |
14f99d7d | 258 | StoreInfo, (char *) &elem)) != 0) { |
461c03b6 | 259 | com_err(program_name, status, |
075fe5bb | 260 | " when attempting to get_user_by_uid."); |
08345b74 | 261 | return (NULL); |
262 | } | |
263 | break; | |
402461ad | 264 | case BY_NAME: |
08345b74 | 265 | args[0] = name1; |
266 | args[1] = name2; | |
8defc06b | 267 | if ( (status = do_mr_query("get_user_by_name", 2, args, |
14f99d7d | 268 | StoreInfo, (char *) &elem)) != 0) { |
461c03b6 | 269 | com_err(program_name, status, |
075fe5bb | 270 | " when attempting to get_user_by_name."); |
08345b74 | 271 | return (NULL); |
272 | } | |
273 | break; | |
274 | case CLASS: | |
275 | args[0] = name1; | |
8defc06b | 276 | if ( (status = do_mr_query("get_user_by_class", 1, args, |
14f99d7d | 277 | StoreInfo, (char *) &elem)) != 0) { |
461c03b6 | 278 | com_err(program_name, status, |
075fe5bb | 279 | " when attempting to get_user_by_class."); |
08345b74 | 280 | return (NULL); |
281 | } | |
282 | break; | |
08345b74 | 283 | } |
284 | return( QueueTop(elem) ); | |
285 | } | |
286 | ||
075fe5bb | 287 | /* Function Name: AddNewUser |
288 | * Description: Adds a new user to the database. | |
289 | * Arguments: none. | |
08345b74 | 290 | * Returns: DM_NORMAL. |
291 | */ | |
292 | ||
293 | /* ARGSUSED */ | |
294 | int | |
075fe5bb | 295 | AddNewUser() |
08345b74 | 296 | { |
075fe5bb | 297 | register int status; |
298 | char ** args, *info[MAX_ARGS_SIZE]; | |
299 | ||
300 | args = AskUserInfo(SetUserDefaults(info), FALSE); | |
ebd96e37 | 301 | if (args == NULL) |
302 | return(DM_NORMAL); | |
8defc06b | 303 | if ( (status = do_mr_query("add_user", CountArgs(args), |
304 | args, Scream, (char *) NULL)) != MR_SUCCESS) | |
075fe5bb | 305 | com_err(program_name, status, " in add_user"); |
306 | else | |
307 | Put_message("New user added to database."); | |
308 | FreeInfo(args); | |
08345b74 | 309 | return(DM_NORMAL); |
310 | } | |
311 | ||
312 | ||
075fe5bb | 313 | /* Function Name: GetLoginName |
314 | * Description: Asks the user for a login name and reserves | |
315 | * it with kerberous. | |
316 | * Arguments: none. | |
317 | * Returns: a malloced login name for the user. | |
08345b74 | 318 | */ |
319 | ||
075fe5bb | 320 | static char * |
321 | GetLoginName() | |
08345b74 | 322 | { |
075fe5bb | 323 | char name[BUFSIZ]; |
324 | ||
325 | Prompt_input("Login name for this user? ", name, BUFSIZ); | |
326 | ||
327 | Put_message( | |
328 | "KERBEROS code not added, did not reserve name with kerberos."); | |
329 | ||
330 | return(Strsave(name)); | |
331 | } | |
332 | ||
333 | ||
334 | /* Function Name: ChooseUser | |
335 | * Description: Choose a user from a list and return the uid. | |
336 | * Arguments: top - a queue of user information. | |
337 | * Returns: uid - the malloced uid of the user that was chosen. | |
338 | */ | |
08345b74 | 339 | |
075fe5bb | 340 | static char * |
341 | ChooseUser(elem) | |
342 | struct qelem * elem; | |
343 | { | |
08345b74 | 344 | while (elem != NULL) { |
075fe5bb | 345 | char ** info = (char **) elem->q_data; |
346 | PrintUserInfo(info); | |
347 | switch(YesNoQuitQuestion("Is this the user you want (y/n/q)", FALSE)) { | |
348 | case TRUE: | |
349 | return(Strsave(info[U_UID])); | |
350 | case FALSE: | |
351 | break; | |
352 | default: /* quit or ^C. */ | |
353 | return(NULL); | |
08345b74 | 354 | } |
355 | elem = elem->q_forw; | |
356 | } | |
075fe5bb | 357 | return(NULL); |
08345b74 | 358 | } |
359 | ||
075fe5bb | 360 | /* Function Name: GetUidNumberFromName |
361 | * Description: Gets the users uid number, from the name. | |
362 | * Arguments: none. | |
363 | * Returns: uid - a malloced string containing the uid. | |
08345b74 | 364 | */ |
365 | ||
075fe5bb | 366 | static char * |
367 | GetUidNumberFromName() | |
08345b74 | 368 | { |
075fe5bb | 369 | char *args[5], *uid, first[BUFSIZ], last[BUFSIZ]; |
461c03b6 | 370 | register int status; |
075fe5bb | 371 | struct qelem * top = NULL; |
372 | ||
373 | Prompt_input("First Name: ", first, BUFSIZ); | |
374 | Prompt_input("Last Name: ", last, BUFSIZ); | |
08345b74 | 375 | |
075fe5bb | 376 | args[0] = first; |
377 | args[1] = last; | |
08345b74 | 378 | |
8defc06b | 379 | switch (status = do_mr_query("get_user_by_name", 2, args, |
14f99d7d | 380 | StoreInfo, (char *) &top)) { |
8defc06b | 381 | case MR_SUCCESS: |
075fe5bb | 382 | break; |
8defc06b | 383 | case MR_NO_MATCH: |
075fe5bb | 384 | Put_message("There is no user in the database with that name."); |
385 | return(NULL); | |
386 | default: | |
387 | com_err(program_name, status, " in get_user_by_name."); | |
388 | return(NULL); | |
08345b74 | 389 | } |
390 | ||
075fe5bb | 391 | top = QueueTop(top); |
392 | if (QueueCount(top) == 1) /* This is a unique name. */ { | |
393 | char ** info = (char **) top->q_data; | |
394 | Put_message("User ID Number retrieved for the user: "); | |
395 | Put_message(""); | |
396 | PrintUserName(info); | |
397 | uid = Strsave(info[U_UID]); | |
398 | FreeQueue(top); | |
399 | return(Strsave(uid)); | |
400 | } | |
08345b74 | 401 | |
075fe5bb | 402 | Put_message("That name is not unique, choose the user that you want."); |
403 | uid = ChooseUser(top); | |
404 | FreeQueue(top); | |
405 | return(uid); | |
08345b74 | 406 | } |
407 | ||
075fe5bb | 408 | /* Function Name: SetUserPassword |
409 | * Description: Set the new kerberos password for this user. | |
410 | * Arguments: name - kerberos principle name for this user, (login name). | |
411 | * Returns: none. | |
08345b74 | 412 | */ |
413 | ||
075fe5bb | 414 | static void |
415 | SetUserPassword(name) | |
416 | char * name; | |
08345b74 | 417 | { |
075fe5bb | 418 | name = name; /* make saber happy. */ |
419 | Put_message("Kerberos password not changed, code non-existant."); | |
420 | /* clever message to call account_admin, if this fails. */ | |
421 | } | |
08345b74 | 422 | |
075fe5bb | 423 | /* Function Name: GiveBackLogin |
424 | * Description: Gives back previously reserved kerberous principle. | |
425 | * Arguments: name - principle to give back. | |
426 | * Returns: void. | |
08345b74 | 427 | */ |
428 | ||
075fe5bb | 429 | static void |
430 | GiveBackLogin(name) | |
431 | char * name; | |
08345b74 | 432 | { |
075fe5bb | 433 | name = name; /* make saber happy. */ |
434 | Put_message("kerberos code not implimented, name not given back."); | |
435 | /* send mail to db maintainer if this fails. */ | |
08345b74 | 436 | } |
437 | ||
075fe5bb | 438 | /* Function Name: RegisterUser |
439 | * Description: This function registers a user. | |
440 | * Arguments: none. | |
441 | * Returns: DM_NORMAL. | |
08345b74 | 442 | */ |
443 | ||
08345b74 | 444 | int |
075fe5bb | 445 | RegisterUser() |
08345b74 | 446 | { |
075fe5bb | 447 | char * args[MAX_ARGS_SIZE]; |
448 | char *login, *fstype = NULL; | |
449 | char temp_buf[BUFSIZ]; | |
450 | register int status; | |
461c03b6 | 451 | |
075fe5bb | 452 | Put_message("This function has NO kerberos support, so stange things"); |
453 | Put_message("may happen if you use it to register a user."); | |
454 | ||
455 | switch (YesNoQuestion("Do you know the users UID Number (y/n)", FALSE)) { | |
456 | case TRUE: | |
457 | Prompt_input("What is the UID number of the user? ", temp_buf, BUFSIZ); | |
458 | args[0] = Strsave(temp_buf); | |
459 | break; | |
460 | case FALSE: | |
461 | if ( (args[0] = GetUidNumberFromName()) == NULL) | |
462 | return(DM_NORMAL); | |
463 | break; | |
464 | default: | |
465 | return(DM_NORMAL); | |
461c03b6 | 466 | } |
075fe5bb | 467 | |
468 | if ( ((login = args[1] = GetLoginName()) == NULL) || | |
4f91474a | 469 | ( GetFSTypes(&fstype, FALSE) == SUB_ERROR ) ) { |
075fe5bb | 470 | FreeInfo(args); /* This work because the NULL temination is ok. */ |
471 | return(DM_NORMAL); | |
472 | } | |
473 | args[2] = fstype; | |
474 | args[3] = NULL; | |
475 | ||
8defc06b | 476 | switch (status = do_mr_query("register_user", CountArgs(args), |
14f99d7d | 477 | args, Scream, (char *) NULL)) { |
8defc06b | 478 | case MR_SUCCESS: |
075fe5bb | 479 | sprintf(temp_buf, "User %s successfully registered.", login); |
480 | Put_message(temp_buf); | |
481 | SetUserPassword(login); | |
482 | break; | |
8defc06b | 483 | case MR_IN_USE: |
075fe5bb | 484 | GiveBackLogin(login); |
485 | sprintf(temp_buf, "The username %s is already in use.", login); | |
486 | Put_message(temp_buf); | |
487 | break; | |
488 | default: | |
489 | com_err(program_name, status, " in register_user"); | |
490 | break; | |
491 | } | |
492 | FreeInfo(args); | |
493 | return(DM_NORMAL); | |
08345b74 | 494 | } |
495 | ||
075fe5bb | 496 | /* Function Name: RealUpdateUser |
497 | * Description: actuall updates the user information. | |
498 | * Arguments: info - all current information for the user fields. | |
499 | * junk - an UNUSED boolean. | |
500 | * Returns: none. | |
08345b74 | 501 | */ |
502 | ||
075fe5bb | 503 | /* ARGSUSED */ |
504 | static void | |
505 | RealUpdateUser(info, junk) | |
506 | char ** info; | |
507 | Bool junk; | |
08345b74 | 508 | { |
075fe5bb | 509 | register int status; |
510 | char error_buf[BUFSIZ]; | |
511 | char ** args = AskUserInfo(info, TRUE); | |
512 | ||
8defc06b | 513 | if ( (status = do_mr_query("update_user", CountArgs(args), |
514 | args, Scream, (char *) NULL)) != MR_SUCCESS) { | |
075fe5bb | 515 | com_err(program_name, status, " in ModifyFields"); |
516 | sprintf(error_buf, "User %s not updated due to errors.", info[NAME]); | |
517 | Put_message(error_buf); | |
08345b74 | 518 | } |
08345b74 | 519 | } |
520 | ||
075fe5bb | 521 | /* Function Name: UpdateUser |
522 | * Description: Modify some of the information about a user. | |
523 | * Arguments: argc, argv - login name of the user in argv[1]. | |
08345b74 | 524 | * Returns: DM_NORMAL. |
525 | */ | |
526 | ||
075fe5bb | 527 | /* ARGSUSED */ |
08345b74 | 528 | int |
075fe5bb | 529 | UpdateUser(argc, argv) |
08345b74 | 530 | int argc; |
531 | char **argv; | |
532 | { | |
075fe5bb | 533 | struct qelem * elem; |
08345b74 | 534 | |
075fe5bb | 535 | elem = GetUserInfo(LOGIN, argv[1], (char *) NULL); |
536 | QueryLoop(elem, NullPrint, RealUpdateUser, "Update the user"); | |
08345b74 | 537 | |
075fe5bb | 538 | FreeQueue(elem); |
08345b74 | 539 | return(DM_NORMAL); |
540 | } | |
541 | ||
b3e25186 | 542 | /* Function Name: RealDeactivateUser |
543 | * Description: sets the user's status to 3. | |
544 | * Arguments: info - all current information for the user fields | |
545 | * one_item - indicates the user hasn't been queried yet | |
546 | * Returns: none. | |
547 | */ | |
548 | ||
549 | static void | |
550 | RealDeactivateUser(info, one_item) | |
551 | char ** info; | |
552 | Bool one_item; | |
553 | { | |
554 | register int status; | |
555 | char txt_buf[BUFSIZ]; | |
556 | char * qargs[2]; | |
557 | ||
558 | if (one_item) { | |
559 | sprintf(txt_buf, "Deactivate user %s (y/n)", info[NAME]); | |
334eb344 | 560 | if (!YesNoQuestion(txt_buf, 2)) |
b3e25186 | 561 | return; |
562 | } | |
563 | ||
564 | qargs[0] = info[NAME]; | |
565 | qargs[1] = "3"; | |
8defc06b | 566 | if ((status = do_mr_query("update_user_status", 2, qargs, Scream, |
567 | (char *) NULL)) != MR_SUCCESS) { | |
b3e25186 | 568 | com_err(program_name, status, " in update_user_status"); |
569 | sprintf(txt_buf, "User %s not deactivated due to errors.", info[NAME]); | |
570 | Put_message(txt_buf); | |
571 | } | |
572 | } | |
573 | ||
574 | ||
575 | /* Function Name: DeactivateUser | |
576 | * Description: sets the user's status to 3. | |
577 | * Arguments: argc, argv - login name of the user in argv[1]. | |
578 | * Returns: DM_NORMAL. | |
579 | */ | |
580 | ||
581 | /* ARGSUSED */ | |
582 | int | |
583 | DeactivateUser(argc, argv) | |
584 | int argc; | |
585 | char **argv; | |
586 | { | |
587 | struct qelem * elem; | |
588 | ||
589 | elem = GetUserInfo(LOGIN, argv[1], (char *) NULL); | |
590 | QueryLoop(elem, NullPrint, RealDeactivateUser, "Deactivate user"); | |
591 | ||
592 | FreeQueue(elem); | |
593 | return(DM_NORMAL); | |
594 | } | |
595 | ||
596 | ||
075fe5bb | 597 | /* ------------------------- Top Menu ------------------------- */ |
598 | ||
599 | /* DeleteUser() in delete.c */ | |
461c03b6 | 600 | |
075fe5bb | 601 | /* Function Name: DeleteUserByUid |
602 | * Description: Deletes the user given a uid number. | |
603 | * Arguments: argc, argv - uid if user in argv[1]. | |
08345b74 | 604 | * Returns: DM_NORMAL. |
8defc06b | 605 | * NOTES: This just gets the username from the mr server |
075fe5bb | 606 | * and performs a DeleteUser(). |
08345b74 | 607 | */ |
608 | ||
08345b74 | 609 | int |
075fe5bb | 610 | DeleteUserByUid(argc, argv) |
08345b74 | 611 | int argc; |
612 | char **argv; | |
613 | { | |
461c03b6 | 614 | int status; |
075fe5bb | 615 | struct qelem *elem = NULL; |
616 | char ** info; | |
617 | ||
618 | if(!ValidName(argv[1])) | |
619 | return(DM_NORMAL); | |
620 | ||
8defc06b | 621 | if ( (status = do_mr_query("get_user_by_uid", 1, argv+1, StoreInfo, |
622 | (char * ) &elem)) != MR_SUCCESS) | |
075fe5bb | 623 | com_err(program_name, status, " in get_user_by_uid"); |
624 | ||
625 | info = (char **) elem->q_data; | |
626 | argv[1] = info[U_NAME]; | |
08345b74 | 627 | |
075fe5bb | 628 | (void) DeleteUser(argc, argv); |
08345b74 | 629 | return(DM_NORMAL); |
075fe5bb | 630 | } |
08345b74 | 631 | |
075fe5bb | 632 | /* ------------------------- Show User Information ------------------------- */ |
08345b74 | 633 | |
634 | /* Function Name: ShowUserByLogin | |
635 | * Description: Shows user information given a login name. | |
636 | * Arguments: argc, argv - login name in argv[1]. | |
637 | * Returns: DM_NORMAL | |
638 | */ | |
639 | ||
640 | /* ARGSUSED */ | |
641 | int | |
642 | ShowUserByLogin(argc, argv) | |
643 | int argc; | |
644 | char *argv[]; | |
645 | { | |
646 | struct qelem *top, *elem; | |
647 | ||
648 | elem = top = GetUserInfo(LOGIN, argv[1], (char *) NULL); | |
075fe5bb | 649 | Loop(elem, PrintUserInfo); |
08345b74 | 650 | |
651 | FreeQueue(top); | |
652 | return (DM_NORMAL); | |
653 | } | |
654 | ||
655 | /* Function Name: RetrieveUserByName | |
656 | * Description: Show information on a user give fist and/or last name. | |
657 | * Arguments: argc, argv - argv[1] - first name. | |
658 | * argv[2] - last name. | |
659 | * Returns: DM_NORMAL. | |
660 | */ | |
661 | ||
662 | /* ARGSUSED */ | |
663 | int | |
664 | ShowUserByName(argc, argv) | |
665 | int argc; | |
666 | char *argv[]; | |
667 | { | |
075fe5bb | 668 | struct qelem *top; |
3c1a8806 | 669 | char buf[BUFSIZ]; |
08345b74 | 670 | |
075fe5bb | 671 | top = GetUserInfo(BY_NAME, argv[1], argv[2]); |
08345b74 | 672 | |
075fe5bb | 673 | if (top == NULL) /* if there was an error then return. */ |
08345b74 | 674 | return(DM_NORMAL); |
675 | ||
075fe5bb | 676 | if (!PromptWithDefault("Print full information, or just the names (f/n)?", |
334eb344 | 677 | buf, 2, "f")) |
075fe5bb | 678 | return(DM_NORMAL); |
08345b74 | 679 | |
3c1a8806 | 680 | switch(buf[0]) { |
075fe5bb | 681 | case 'F': |
682 | case 'f': | |
683 | Loop(top, PrintUserInfo); | |
684 | break; | |
685 | case 'N': | |
686 | case 'n': | |
687 | Loop(top, PrintUserName); | |
688 | break; | |
689 | } | |
690 | ||
08345b74 | 691 | FreeQueue(top); |
692 | return (DM_NORMAL); | |
693 | } | |
694 | ||
695 | /* Function Name: ShowUserByClass | |
696 | * Description: Shows real and login names of all users in class. | |
697 | * Arguments: argc, argv - argv[1] contains the class. | |
698 | * Returns: none. | |
699 | */ | |
700 | ||
85ca828a | 701 | /* ARGSUSED */ |
08345b74 | 702 | int |
703 | ShowUserByClass(argc, argv) | |
704 | int argc; | |
705 | char **argv; | |
706 | { | |
075fe5bb | 707 | struct qelem *top; |
08345b74 | 708 | |
075fe5bb | 709 | top = GetUserInfo(CLASS, argv[1], (char *) NULL); |
710 | Loop(top, PrintUserName); | |
08345b74 | 711 | |
712 | FreeQueue(top); | |
713 | return (DM_NORMAL); | |
714 | } | |
1e80e2f4 | 715 | |
716 | ||
717 | /* Function Name: GetKrbmap | |
718 | * Description: Shows user <-> Kerberos mappings | |
719 | * Arguments: argc, argv - argv[1] contains the user login name, | |
720 | * argv[2] contains the principal | |
721 | * Returns: none. | |
722 | */ | |
723 | ||
724 | /* ARGSUSED */ | |
725 | int | |
726 | GetKrbmap(argc, argv) | |
727 | int argc; | |
728 | char **argv; | |
729 | { | |
730 | int stat; | |
78fce9fa | 731 | struct qelem *elem = NULL, *top; |
1e80e2f4 | 732 | char buf[BUFSIZ]; |
733 | ||
8defc06b | 734 | if ((stat = do_mr_query("get_kerberos_user_map", 2, &argv[1], |
1e80e2f4 | 735 | StoreInfo, (char *)&elem)) != 0) { |
736 | com_err(program_name, stat, " in GetKrbMap."); | |
737 | return(DM_NORMAL); | |
738 | } | |
739 | ||
78fce9fa | 740 | top = elem = QueueTop(elem); |
1e80e2f4 | 741 | Put_message(""); |
742 | while (elem != NULL) { | |
743 | char **info = (char **) elem->q_data; | |
744 | sprintf(buf, "User: %-9s Principal: %s", | |
745 | info[KMAP_USER], info[KMAP_PRINCIPAL]); | |
746 | Put_message(buf); | |
747 | elem = elem->q_forw; | |
748 | } | |
749 | ||
78fce9fa | 750 | FreeQueue(QueueTop(top)); |
1e80e2f4 | 751 | return(DM_NORMAL); |
752 | } | |
753 | ||
754 | ||
755 | /* Function Name: AddKrbmap | |
756 | * Description: Add a new user <-> Kerberos mapping | |
757 | * Arguments: argc, argv - argv[1] contains the user login name, | |
758 | * argv[2] contains the principal | |
759 | * Returns: none. | |
760 | */ | |
761 | ||
762 | /* ARGSUSED */ | |
763 | int | |
764 | AddKrbmap(argc, argv) | |
765 | int argc; | |
766 | char **argv; | |
767 | { | |
768 | int stat; | |
769 | ||
770 | if (!index(argv[KMAP_PRINCIPAL + 1], '@')) { | |
771 | Put_message("Please specify a realm for the kerberos principal."); | |
772 | return(DM_NORMAL); | |
773 | } | |
8defc06b | 774 | if ((stat = do_mr_query("add_kerberos_user_map", 2, &argv[1], |
1e80e2f4 | 775 | Scream, NULL)) != 0) { |
776 | com_err(program_name, stat, " in AddKrbMap."); | |
8defc06b | 777 | if (stat == MR_EXISTS) |
1e80e2f4 | 778 | Put_message("No user or principal may have more than one mapping."); |
779 | } | |
780 | return(DM_NORMAL); | |
781 | } | |
782 | ||
783 | ||
784 | /* Function Name: DeleteKrbmap | |
785 | * Description: Remove a user <-> Kerberos mapping | |
786 | * Arguments: argc, argv - argv[1] contains the user login name, | |
787 | * argv[2] contains the principal | |
788 | * Returns: none. | |
789 | */ | |
790 | ||
791 | /* ARGSUSED */ | |
792 | int | |
793 | DeleteKrbmap(argc, argv) | |
794 | int argc; | |
795 | char **argv; | |
796 | { | |
797 | int stat; | |
798 | ||
8defc06b | 799 | if ((stat = do_mr_query("delete_kerberos_user_map", 2, &argv[1], |
1e80e2f4 | 800 | Scream, NULL)) != 0) { |
801 | com_err(program_name, stat, " in DeleteKrbMap."); | |
802 | } | |
803 | return(DM_NORMAL); | |
804 | } |