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