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