]>
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 delete.c for the MOIRA Client, which allows a nieve |
6 | * user to quickly and easily maintain most parts of the MOIRA database. | |
08345b74 | 7 | * It Contains: functions for deleting users and lists. |
8 | * | |
9 | * Created: 5/18/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> |
27 | ||
461c03b6 | 28 | #include "mit-copyright.h" |
0a2c64cb | 29 | #include "defs.h" |
30 | #include "f_defs.h" | |
461c03b6 | 31 | #include "globals.h" |
461c03b6 | 32 | |
08345b74 | 33 | /* Function Name: CheckListForDeletion |
34 | * Description: Check one of the lists in which we just removed a member. | |
35 | * if the list is empty then it will delete it. | |
36 | * Arguments: name - name of the list to check. | |
37 | * verbose - verbose mode? | |
38 | * Returns: none. | |
39 | */ | |
40 | ||
225ce369 | 41 | int |
08345b74 | 42 | CheckListForDeletion(name, verbose) |
43 | char * name; | |
44 | Bool verbose; | |
45 | { | |
461c03b6 | 46 | struct qelem *elem = NULL; |
075fe5bb | 47 | int status; |
461c03b6 | 48 | char *args[2], buf[BUFSIZ], **info; |
08345b74 | 49 | |
8defc06b | 50 | if ( (status = do_mr_query("count_members_of_list", 1, &name, StoreInfo, |
14f99d7d | 51 | (char *) &elem)) != 0) { |
461c03b6 | 52 | com_err(program_name, status, |
53 | " in DeleteList (count_members_of_list)."); | |
225ce369 | 54 | return(SUB_NORMAL); |
08345b74 | 55 | } |
461c03b6 | 56 | info = (char **) elem->q_data; |
0a2c64cb | 57 | if ( strcmp(info[NAME],"0") == 0) { |
461c03b6 | 58 | if (verbose) { |
59 | sprintf(buf, "Delete the empty list %s? ", name); | |
225ce369 | 60 | switch (YesNoQuestion(buf, FALSE)) { |
61 | case TRUE: | |
62 | break; | |
63 | case FALSE: | |
64 | Put_message("Not deleting this list."); | |
65 | FreeQueue(elem); | |
66 | return(SUB_NORMAL); | |
67 | default: | |
461c03b6 | 68 | Put_message("Aborting Deletion!"); |
69 | FreeQueue(elem); | |
225ce369 | 70 | return(SUB_ERROR); |
461c03b6 | 71 | } |
08345b74 | 72 | } |
461c03b6 | 73 | args[0] = "foo"; /* not used. */ |
74 | args[1] = name; | |
75 | DeleteList(2, args); | |
08345b74 | 76 | } |
461c03b6 | 77 | FreeQueue(elem); |
225ce369 | 78 | return(SUB_NORMAL); |
08345b74 | 79 | } |
80 | ||
075fe5bb | 81 | /* Function Name: CheckAce |
82 | * Description: Checks an ace to see of we should delete it. | |
83 | * Arguments: type - the type of this ace. | |
84 | * name - the name of the ace. | |
08345b74 | 85 | * verbose - query user? |
86 | * Returns: none. | |
87 | */ | |
88 | ||
89 | void | |
075fe5bb | 90 | CheckAce(type, name, verbose) |
08345b74 | 91 | char * type, *name; |
92 | Bool verbose; | |
93 | { | |
94 | char *args[2], buf[BUFSIZ]; | |
075fe5bb | 95 | int status; |
08345b74 | 96 | |
461c03b6 | 97 | if ( strcmp(type, "LIST") != 0 ) |
075fe5bb | 98 | return; /* If the ace is not a list the ignore it. */ |
08345b74 | 99 | |
100 | args[0] = type; | |
101 | args[1] = name; | |
8defc06b | 102 | status = do_mr_query("get_ace_use", 2, args, NullFunc, (char *) NULL); |
103 | if (status != MR_NO_MATCH) | |
075fe5bb | 104 | return; /* If this query fails the ace will |
461c03b6 | 105 | not be deleted even if it is empty. */ |
08345b74 | 106 | if (verbose) { |
0a2c64cb | 107 | sprintf(buf, "Delete the unused Access Control Entity (ACE) %s? ", |
108 | name); | |
075fe5bb | 109 | if ( YesNoQuestion(buf, FALSE) != TRUE) { |
461c03b6 | 110 | Put_message("Aborting Deletion!"); |
111 | return; | |
112 | } | |
08345b74 | 113 | } |
114 | /* | |
075fe5bb | 115 | * Delete the ACE. |
08345b74 | 116 | * |
117 | * NOTE: Delete list expects only the name of the list to delete in argv[1]. | |
118 | * since, 'args' already satisfies this, there is no need to create | |
119 | * a special argument list. | |
120 | */ | |
121 | DeleteList(2, args); | |
122 | } | |
123 | ||
124 | ||
075fe5bb | 125 | /* Function Name: CheckIfAce |
126 | * Description: Checks to see if this is an ace of another data object. | |
08345b74 | 127 | * Arguments: name - name of the object. |
253517e2 | 128 | * Returns: SUB_ERROR if this list is an ace, or if the query did not |
08345b74 | 129 | * succeed. |
130 | */ | |
131 | ||
132 | int | |
075fe5bb | 133 | CheckIfAce(name, type, verbose) |
461c03b6 | 134 | char * name, * type; |
08345b74 | 135 | Bool verbose; |
136 | { | |
253517e2 | 137 | char * args[2], buf[BUFSIZ], **info; |
075fe5bb | 138 | struct qelem *local, *elem; |
461c03b6 | 139 | int status; |
08345b74 | 140 | elem = NULL; |
141 | ||
142 | args[0] = type; | |
143 | args[1] = name; | |
8defc06b | 144 | switch (status = do_mr_query("get_ace_use", 2, args, |
14f99d7d | 145 | StoreInfo, (char *) &elem)) { |
8defc06b | 146 | case MR_NO_MATCH: |
075fe5bb | 147 | return(DM_NORMAL); |
8defc06b | 148 | case MR_SUCCESS: |
075fe5bb | 149 | local = elem = QueueTop(elem); |
253517e2 | 150 | info = (char **) local->q_data; |
151 | if (QueueCount(elem) == 1 && | |
152 | !strcmp(info[0], "LIST") && | |
153 | !strcmp(info[1], name)) { | |
154 | FreeQueue(elem); | |
155 | return(DM_NORMAL); | |
156 | } | |
075fe5bb | 157 | if (verbose) { |
219bbe64 | 158 | sprintf(buf, "%s %s %s", type, name, |
159 | "is the ACE for the following data objects:"); | |
075fe5bb | 160 | Put_message(buf); |
219bbe64 | 161 | Put_message(""); |
1da21bb3 | 162 | for (; local != NULL; local = local->q_forw) { |
253517e2 | 163 | info = (char **) local->q_data; |
164 | if (!strcmp(info[0], "LIST") && | |
165 | !strcmp(info[1], name)) | |
166 | continue; | |
8429393f | 167 | Print(CountArgs(info), info, NULL); |
075fe5bb | 168 | } |
8429393f | 169 | Put_message(""); |
170 | Put_message( | |
171 | "The ACE for each of these items must be changed before"); | |
075fe5bb | 172 | sprintf(buf,"the %s %s can be deleted.\n", type, name); |
8429393f | 173 | Put_message(buf); |
08345b74 | 174 | } |
075fe5bb | 175 | break; |
176 | default: | |
8429393f | 177 | com_err(program_name, status, " in CheckIfAce (get_ace_use)."); |
178 | return(SUB_ERROR); | |
08345b74 | 179 | } |
8429393f | 180 | FreeQueue(elem); |
181 | return(SUB_ERROR); | |
08345b74 | 182 | } |
183 | ||
8429393f | 184 | /* Function Name: RemoveItemFromLists |
185 | * Description: this function removes a list from all other lists of | |
08345b74 | 186 | * which it is a member. |
8429393f | 187 | * Arguments: name - name of the item |
188 | * elem - a pointer to a queue element. RETURNED | |
08345b74 | 189 | * verbose - verbose mode. |
8429393f | 190 | * Returns: SUB_ERROR if there is an error. |
08345b74 | 191 | */ |
192 | ||
193 | int | |
8429393f | 194 | RemoveItemFromLists(name, type, elem, verbose) |
461c03b6 | 195 | char * name, *type; |
196 | struct qelem ** elem; | |
08345b74 | 197 | int verbose; |
198 | { | |
461c03b6 | 199 | struct qelem *local; |
8429393f | 200 | char *args[10], temp_buf[BUFSIZ]; |
0a2c64cb | 201 | int lists; |
075fe5bb | 202 | register int status; |
08345b74 | 203 | |
204 | args[0] = type; | |
205 | args[1] = name; | |
8429393f | 206 | *elem = NULL; |
08345b74 | 207 | |
208 | /* | |
8429393f | 209 | * Get all list of which this item is a member, and store them in a queue. |
08345b74 | 210 | */ |
211 | ||
8defc06b | 212 | status = do_mr_query("get_lists_of_member", 2, args, StoreInfo, |
14f99d7d | 213 | (char *) elem); |
08345b74 | 214 | |
8defc06b | 215 | if (status == MR_NO_MATCH) |
8429393f | 216 | return(SUB_NORMAL); |
08345b74 | 217 | |
8defc06b | 218 | if (status != MR_SUCCESS) { |
8429393f | 219 | com_err(program_name, status, " in DeleteList (get_lists_of_member)."); |
220 | return(SUB_ERROR); | |
08345b74 | 221 | } |
222 | ||
223 | /* | |
8429393f | 224 | * If verbose mode, ask user of we should remove our list from |
08345b74 | 225 | * all these lists. |
226 | */ | |
227 | ||
8429393f | 228 | local = *elem = QueueTop(*elem); |
229 | lists = QueueCount(*elem); | |
0a2c64cb | 230 | if (lists == 0) |
8429393f | 231 | return(SUB_NORMAL); |
08345b74 | 232 | if (verbose) { |
0a2c64cb | 233 | sprintf(temp_buf, "%s %s is a member of %d other list%s.\n", type, |
234 | name, lists, ((lists == 1) ? "" : "s") ); | |
8429393f | 235 | Put_message(temp_buf); |
236 | while (local != NULL) { | |
461c03b6 | 237 | char ** info = (char **) local->q_data; |
8429393f | 238 | Print( 1, &info[GLOM_NAME], (char *) NULL); |
08345b74 | 239 | local = local->q_forw; |
240 | } | |
8429393f | 241 | Put_message(" "); /* Blank Line. */ |
242 | sprintf(temp_buf,"Remove %s %s from these lists? ", type, name); | |
243 | if (YesNoQuestion(temp_buf, FALSE) != TRUE) { | |
244 | Put_message("Aborting..."); | |
245 | FreeQueue(*elem); | |
246 | *elem = NULL; | |
247 | return(SUB_ERROR); | |
08345b74 | 248 | } |
249 | } | |
250 | ||
251 | /* | |
8429393f | 252 | * Remove this list from all lists that it is a member of. |
08345b74 | 253 | */ |
254 | ||
255 | local = *elem; | |
8429393f | 256 | args[DM_MEMBER] = name; |
257 | args[DM_TYPE] = type; | |
258 | while (local != NULL) { | |
461c03b6 | 259 | char ** info = (char **) local->q_data; |
8429393f | 260 | args[DM_LIST] = info[GLOM_NAME]; |
8defc06b | 261 | if ( (status = do_mr_query("delete_member_from_list", |
14f99d7d | 262 | 3, args, Scream, NULL)) != 0) { |
8429393f | 263 | com_err(program_name, status, " in delete_member\nAborting\n"); |
264 | FreeQueue(*elem); | |
265 | return(SUB_ERROR); | |
08345b74 | 266 | } |
267 | local = local->q_forw; | |
268 | } | |
8429393f | 269 | return(SUB_NORMAL); |
08345b74 | 270 | } |
271 | ||
8429393f | 272 | /* Function Name: RemoveMembersOfList |
273 | * Description: Deletes the members of the list. | |
274 | * Arguments: name - name of the list. | |
08345b74 | 275 | * verbose - query user, about deletion? |
8429393f | 276 | * Returns: SUB_ERROR - if we could not delete, or the user abouted. |
08345b74 | 277 | */ |
278 | ||
279 | int | |
8429393f | 280 | RemoveMembersOfList(name, verbose) |
08345b74 | 281 | char * name; |
8429393f | 282 | Bool verbose; |
08345b74 | 283 | { |
8429393f | 284 | char buf[BUFSIZ], *args[10]; |
285 | struct qelem *local, *elem = NULL; | |
0a2c64cb | 286 | int status, members; |
08345b74 | 287 | /* |
8429393f | 288 | * Get the members of this list. |
08345b74 | 289 | */ |
8defc06b | 290 | status = do_mr_query("get_members_of_list", 1, &name, StoreInfo, |
14f99d7d | 291 | (char *) &elem); |
8defc06b | 292 | if (status == MR_NO_MATCH) |
8429393f | 293 | return(SUB_NORMAL); |
08345b74 | 294 | |
295 | if (status != 0) { | |
8429393f | 296 | com_err(program_name, status, " in DeleteList (get_members_of_list)."); |
297 | return(SUB_ERROR); | |
08345b74 | 298 | } |
08345b74 | 299 | /* |
8429393f | 300 | * If verbose mode, then ask the user if we should delete. |
08345b74 | 301 | */ |
8429393f | 302 | local = elem = QueueTop(elem); |
303 | if ( (members = QueueCount(elem)) == 0) | |
304 | return(SUB_NORMAL); | |
08345b74 | 305 | if (verbose) { |
8429393f | 306 | sprintf(buf, "List %s has %d member%s:", name, QueueCount(elem), |
0a2c64cb | 307 | ((members == 1) ? "" : "s") ); |
8429393f | 308 | Put_message(buf); |
309 | Put_message(" "); /* Blank Line. */ | |
310 | while (local != NULL) { | |
461c03b6 | 311 | char ** info = (char **) local->q_data; |
8429393f | 312 | Print( CountArgs(info), info, NULL); |
08345b74 | 313 | local = local->q_forw; |
314 | } | |
8429393f | 315 | Put_message(" "); /* Blank Line. */ |
316 | sprintf(buf, "Remove th%s member%s from list %s? ", | |
0a2c64cb | 317 | ((members == 1) ? "is" : "ese"), |
219bbe64 | 318 | ((members == 1) ? "" : "s"), name ); |
8429393f | 319 | if ( YesNoQuestion(buf, FALSE) != TRUE) { |
320 | Put_message("Aborting..."); | |
321 | FreeQueue(elem); | |
322 | return(SUB_ERROR); | |
08345b74 | 323 | } |
324 | } | |
08345b74 | 325 | /* |
8429393f | 326 | * Perform The Removal. |
08345b74 | 327 | */ |
08345b74 | 328 | local = elem; |
329 | args[0] = name; | |
8429393f | 330 | while (local != NULL) { |
461c03b6 | 331 | char ** info = (char **) local->q_data; |
08345b74 | 332 | args[1] = info[0]; |
333 | args[2] = info[1]; | |
8defc06b | 334 | if ( (status = do_mr_query("delete_member_from_list", |
14f99d7d | 335 | 3, args, Scream, NULL)) != 0) { |
8429393f | 336 | com_err(program_name, status, " in delete_member\nAborting\n"); |
337 | FreeQueue(elem); | |
338 | return(SUB_ERROR); | |
08345b74 | 339 | } |
340 | local = local->q_forw; | |
341 | } | |
8429393f | 342 | return(SUB_NORMAL); |
08345b74 | 343 | } |
344 | ||
8429393f | 345 | /* Function Name: DeleteUserGroup |
346 | * Description: Deletes the list given by name if it exists. | |
08345b74 | 347 | * intended to be used to delete user groups |
348 | * Arguments: name - the name of the list to delete. | |
349 | * verbose - flag that if TRUE queries the user to | |
350 | * ask if list should be deleted. | |
8defc06b | 351 | * Returns: MR_ERROR if there is an error. |
08345b74 | 352 | */ |
353 | ||
354 | int | |
355 | DeleteUserGroup(name, verbose) | |
356 | char * name; | |
357 | Bool verbose; | |
358 | { | |
359 | int status, ans; | |
461c03b6 | 360 | char buf[BUFSIZ], *args[10]; |
08345b74 | 361 | |
8defc06b | 362 | status = do_mr_query("get_list_info", 1, &name, NullFunc, (char *) NULL); |
08345b74 | 363 | if (status == 0) { |
364 | if (verbose) { | |
365 | sprintf(buf, "There is also a list named %s, delete it?", name); | |
075fe5bb | 366 | ans = YesNoQuestion(buf, FALSE); |
08345b74 | 367 | if (ans == FALSE) { |
368 | Put_message("Leaving group alone."); | |
461c03b6 | 369 | return(SUB_NORMAL); |
08345b74 | 370 | } |
371 | if (ans < 0) { | |
372 | Put_message("Aborting...\n"); | |
373 | return(SUB_ERROR); | |
374 | } | |
375 | } | |
376 | /* ans == TRUE || ~verbose */ | |
377 | args[0] = "foo"; /* not used. */ | |
378 | args[1] = name; | |
379 | DeleteList(2, args); | |
380 | } | |
8defc06b | 381 | else if (status != MR_NO_MATCH) { |
461c03b6 | 382 | com_err(program_name, status, " Aborting Delete User."); |
08345b74 | 383 | return(SUB_ERROR); |
384 | } | |
461c03b6 | 385 | return(SUB_NORMAL); |
08345b74 | 386 | } |
387 | ||
388 | /* Function Name: DeleteHomeFilesys | |
389 | * Description: Delete the home filesystem for the named user. | |
390 | * Arguments: name - name of the user (and filsystem) to delete. | |
391 | * verbose - if TRUE query user. | |
392 | * Returns: SUB_NORMAL if home filesystem deleted, or nonexistant. | |
393 | */ | |
394 | ||
395 | int | |
396 | DeleteHomeFilesys(name, verbose) | |
397 | char * name; | |
398 | Bool verbose; | |
399 | { | |
075fe5bb | 400 | int status; |
08345b74 | 401 | char buf[BUFSIZ]; |
402 | ||
8defc06b | 403 | switch (status = do_mr_query("get_filesys_by_label", 1, &name, NullFunc, |
14f99d7d | 404 | (char *) NULL)) { |
8defc06b | 405 | case MR_NO_MATCH: |
075fe5bb | 406 | break; |
8defc06b | 407 | case MR_SUCCESS: |
08345b74 | 408 | if (verbose) { |
409 | sprintf(buf, "Delete the filesystem named %s (y/n)?", name); | |
075fe5bb | 410 | switch (YesNoQuestion(buf, FALSE)) { |
411 | case FALSE: | |
412 | Put_message("Filesystem Not Deleted, continuing...\n"); | |
413 | return(SUB_NORMAL); | |
414 | case TRUE: | |
415 | break; | |
416 | default: | |
08345b74 | 417 | Put_message("Filesystem Not Deleted, aborting...\n\n"); |
461c03b6 | 418 | return(SUB_ERROR); |
08345b74 | 419 | } |
420 | } | |
8defc06b | 421 | if ( (status = do_mr_query("delete_filesys", 1, &name, Scream, |
422 | (char *) NULL) ) != MR_SUCCESS) { | |
075fe5bb | 423 | com_err(program_name, status, " in delete_filesys."); |
08345b74 | 424 | return(SUB_ERROR); |
425 | } | |
075fe5bb | 426 | else |
427 | Put_message("Filesystem Successfully Deleted."); | |
428 | break; | |
429 | default: | |
430 | com_err(program_name, status, " in get_filesystem_by_label)."); | |
431 | return(SUB_ERROR); | |
08345b74 | 432 | } |
075fe5bb | 433 | return(SUB_NORMAL); |
08345b74 | 434 | } |
435 | ||
beeb13bf | 436 | #ifndef ATHENA |
075fe5bb | 437 | /* Function Name: RealDeleteUser |
438 | * Description: Just Deletes the user. | |
439 | * Arguments: name - name of User to delete | |
440 | * Returns: SUB_ERROR if the deletion failed. | |
08345b74 | 441 | */ |
442 | ||
075fe5bb | 443 | static int |
444 | RealDeleteUser(name) | |
08345b74 | 445 | char * name; |
08345b74 | 446 | { |
075fe5bb | 447 | char buf[BUFSIZ]; |
448 | int status; | |
449 | ||
8defc06b | 450 | if ( (status = do_mr_query("delete_user", 1, &name, Scream, |
451 | (char *) NULL)) != MR_SUCCESS) { | |
075fe5bb | 452 | com_err(program_name, status, ": user not deleted"); |
08345b74 | 453 | return(SUB_ERROR); |
454 | } | |
075fe5bb | 455 | (void) sprintf(buf, "User %s deleted.", name); |
456 | Put_message(buf); | |
08345b74 | 457 | return(SUB_NORMAL); |
458 | } | |
beeb13bf | 459 | #endif |
08345b74 | 460 | |
85ca828a | 461 | /* Function Name: RealDeleteList |
462 | * Description: Just Deletes the list. | |
463 | * Arguments: name - name of list to delete | |
464 | * Returns: SUB_ERROR if the deletion failed. | |
08345b74 | 465 | */ |
466 | ||
85ca828a | 467 | static int |
468 | RealDeleteList(name) | |
469 | char * name; | |
08345b74 | 470 | { |
85ca828a | 471 | char buf[BUFSIZ]; |
461c03b6 | 472 | int status; |
08345b74 | 473 | |
8defc06b | 474 | if ( (status = do_mr_query("delete_list", 1, &name, Scream, |
475 | (char *) NULL)) != MR_SUCCESS) { | |
85ca828a | 476 | com_err(program_name, status, ": list not deleted"); |
477 | return(SUB_ERROR); | |
08345b74 | 478 | } |
402461ad | 479 | (void) sprintf(buf, "List %s deleted.", name); |
85ca828a | 480 | Put_message(buf); |
402461ad | 481 | Put_message(""); |
85ca828a | 482 | return(SUB_NORMAL); |
483 | } | |
08345b74 | 484 | |
85ca828a | 485 | /* Function Name: AttemptToDeleteList |
486 | * Description: Atempts to delete list, in the following manner: | |
487 | * 1) try to delet it, if this fails in a known error then | |
488 | * a) try to clean up each of those known methods, or | |
489 | * at least explain why we failed. | |
402461ad | 490 | * Arguments: list_info - info about this list. |
85ca828a | 491 | * ask_first - (T/F) query user before preparing for deletion, |
492 | * and cleaning up? | |
493 | * Returns: none - all is taken care of and error messages printed | |
494 | * one way or the other. | |
08345b74 | 495 | */ |
496 | ||
85ca828a | 497 | void |
402461ad | 498 | AttemptToDeleteList(list_info, ask_first) |
499 | char ** list_info; | |
85ca828a | 500 | Bool ask_first; |
501 | { | |
502 | int status; | |
402461ad | 503 | struct qelem *local, *member_of; |
504 | char *name = list_info[L_NAME]; | |
505 | member_of = NULL; | |
85ca828a | 506 | |
507 | /* | |
508 | * Attempt delete. - will only work if: | |
509 | * 1) This list has no members. | |
510 | * 2) This list in a member of no other lists. | |
075fe5bb | 511 | * 3) This list is not an ace of another object. |
85ca828a | 512 | */ |
513 | ||
8defc06b | 514 | switch (status = do_mr_query("delete_list", 1, &name, |
14f99d7d | 515 | Scream, (char *) NULL)) { |
8defc06b | 516 | case MR_SUCCESS: |
08345b74 | 517 | Put_message("List Sucessfully Deleted."); |
0a2c64cb | 518 | CheckAce(list_info[L_ACE_TYPE], list_info[L_ACE_NAME], ask_first); |
85ca828a | 519 | break; |
8defc06b | 520 | case MR_IN_USE: |
85ca828a | 521 | /* |
522 | * This list is in use. Try to find out why, | |
523 | * and for the cases where we have a good idea of | |
524 | * what to do we will query and then do it. | |
525 | */ | |
526 | ||
60b3185f | 527 | if ((CheckIfAce(name, "list", ask_first) != SUB_NORMAL) || |
85ca828a | 528 | (RemoveItemFromLists(name, "list", |
60b3185f | 529 | &member_of, ask_first) != SUB_NORMAL)) |
530 | break; | |
531 | /* | |
532 | * If the list is it's own ACL, then make the person performing | |
533 | * the delete the owner before removing this person from the list | |
534 | */ | |
535 | if (!strcmp(list_info[L_ACE_TYPE], "LIST") && | |
536 | !strcmp(list_info[L_ACE_NAME], list_info[L_NAME])) { | |
537 | free(list_info[L_ACE_TYPE]); | |
538 | free(list_info[L_ACE_NAME]); | |
539 | list_info[L_ACE_TYPE] = Strsave("USER"); | |
540 | list_info[L_ACE_NAME] = Strsave(user); | |
541 | SlipInNewName(list_info, Strsave(list_info[L_NAME])); | |
8defc06b | 542 | if ((status = do_mr_query("update_list", CountArgs(list_info)-3, |
60b3185f | 543 | list_info, Scream, (char *) NULL)) |
8defc06b | 544 | != MR_SUCCESS) { |
60b3185f | 545 | com_err(program_name, status, " while updating list owner"); |
546 | Put_message("List may be only partly deleted."); | |
547 | } | |
548 | } | |
549 | if ((RemoveMembersOfList(name, ask_first) == SUB_NORMAL) && | |
85ca828a | 550 | (RealDeleteList(name) == SUB_NORMAL) ) |
551 | { /* if... */ | |
075fe5bb | 552 | CheckAce(list_info[L_ACE_TYPE], list_info[L_ACE_NAME], ask_first); |
08345b74 | 553 | |
0a2c64cb | 554 | local = QueueTop(member_of); |
85ca828a | 555 | while (local != NULL) { |
402461ad | 556 | char ** info = (char **) local->q_data; |
225ce369 | 557 | if (CheckListForDeletion(info[LM_LIST], ask_first) == SUB_ERROR) |
558 | break; | |
85ca828a | 559 | local = local->q_forw; |
560 | } | |
402461ad | 561 | FreeQueue(member_of); |
08345b74 | 562 | } |
85ca828a | 563 | break; |
564 | default: | |
565 | com_err(program_name, status, " in DeleteList (delete_list)."); | |
566 | break; | |
08345b74 | 567 | } |
08345b74 | 568 | } |
569 | ||
85ca828a | 570 | /* Function Name: DeleteList |
571 | * Description: deletes a list | |
8defc06b | 572 | * Arguments: argc, argv - standard MR argc and argv. |
85ca828a | 573 | * Returns: DM Status Code. |
08345b74 | 574 | */ |
575 | ||
85ca828a | 576 | /* ARGSUSED */ |
577 | int | |
578 | DeleteList(argc, argv) | |
579 | int argc; | |
580 | char *argv[]; | |
08345b74 | 581 | { |
582 | char buf[BUFSIZ]; | |
85ca828a | 583 | struct qelem *top, *list; |
584 | register int status; | |
585 | Bool one_list; | |
08345b74 | 586 | |
85ca828a | 587 | list = NULL; |
588 | ||
8defc06b | 589 | switch(status = do_mr_query("get_list_info", 1, argv + 1, |
14f99d7d | 590 | StoreInfo, (char *) &list)){ |
8defc06b | 591 | case MR_SUCCESS: |
85ca828a | 592 | break; |
8defc06b | 593 | /* case MR_NO_WILDCARD: |
85ca828a | 594 | Put_message("Wildcards are not accepted here."); |
595 | return(DM_NORMAL); | |
8defc06b | 596 | */ case MR_NO_MATCH: |
597 | case MR_LIST: | |
402461ad | 598 | Put_message("There is no list that matches that name."); |
85ca828a | 599 | return(DM_NORMAL); |
600 | default: | |
601 | com_err(program_name, status, " in DeleteList (get_list_info)."); | |
602 | return(DM_NORMAL); | |
08345b74 | 603 | } |
85ca828a | 604 | |
605 | top = list = QueueTop(list); | |
606 | one_list = (QueueCount(list) == 1); | |
607 | while (list != NULL) { | |
608 | char ** info = (char**) list->q_data; | |
609 | if (one_list) { | |
402461ad | 610 | sprintf( buf, "Are you sure that you want to delete the list %s", |
611 | info[L_NAME]); | |
612 | if ( Confirm(buf) ) AttemptToDeleteList(info, TRUE); | |
85ca828a | 613 | } |
614 | else { | |
615 | sprintf(buf, "Delete the list %s", info[L_NAME]); | |
616 | switch( YesNoQuestion( buf, FALSE ) ) { | |
617 | case TRUE: | |
402461ad | 618 | AttemptToDeleteList(info, TRUE); |
85ca828a | 619 | break; |
620 | case FALSE: | |
621 | break; | |
622 | default: | |
623 | Put_message ("Aborting..."); | |
624 | FreeQueue(top); | |
225ce369 | 625 | return(DM_QUIT); |
85ca828a | 626 | } |
627 | } | |
628 | list = list->q_forw; | |
629 | } | |
630 | FreeQueue(top); | |
631 | return(DM_NORMAL); | |
08345b74 | 632 | } |
633 | ||
634 | /* Function Name: DeleteUser | |
635 | * Description: Deletes a user from the database. | |
636 | * Arguments: argc, argv - name of the user in argv[1]. | |
637 | * Returns: DM_NORMAL. | |
638 | */ | |
639 | ||
85ca828a | 640 | /* ARGSUSED */ |
08345b74 | 641 | int |
642 | DeleteUser(argc, argv) | |
643 | int argc; | |
644 | char ** argv; | |
645 | { | |
646 | int status; | |
647 | char buf[BUFSIZ]; | |
648 | char * name = argv[1]; /* name of the user we are deleting. */ | |
beeb13bf | 649 | #ifndef ATHENA |
461c03b6 | 650 | struct qelem *local, *member_of = NULL; |
beeb13bf | 651 | #endif |
08345b74 | 652 | |
075fe5bb | 653 | if (!ValidName(name)) |
654 | return(DM_NORMAL); | |
655 | ||
08345b74 | 656 | if (!Confirm("Are you sure that you want to delete this user?")) |
657 | return(DM_NORMAL); | |
658 | ||
8defc06b | 659 | status = do_mr_query("delete_user", 1, &name, Scream, (char *) NULL); |
660 | if (status != MR_IN_USE && status != 0) { | |
8429393f | 661 | com_err(program_name, status, ": user not deleted"); |
08345b74 | 662 | return(DM_NORMAL); |
663 | } | |
664 | if (status == 0) { | |
665 | sprintf(buf,"User %s deleted.", name); | |
666 | Put_message(buf); | |
beeb13bf | 667 | #ifdef ATHENA |
75e021c5 | 668 | /* delete this return if the policy decision below is reversed */ |
669 | return(DM_NORMAL); | |
beeb13bf | 670 | #endif |
08345b74 | 671 | } |
beeb13bf | 672 | #ifdef ATHENA |
8429393f | 673 | /* Design decision not to allow registered users to be deleted. |
253517e2 | 674 | */ |
a52461dc | 675 | Put_message("Sorry, registered users cannot be deleted from the database."); |
676 | Put_message("Deactivate the user now, and the system manager will expunge later."); | |
beeb13bf | 677 | #else |
8defc06b | 678 | else if (status == MR_IN_USE) { |
08345b74 | 679 | |
680 | /* | |
681 | * Check: | |
075fe5bb | 682 | * 1) Query - Delete home filesytem. |
683 | * 2) Query - Delete user Group. | |
684 | * 2) Is the user an ACE of any object in the database? | |
685 | * 3) Query - Remove user from all list of which he is a member. | |
08345b74 | 686 | * |
687 | * If all these have been accomplished, then attempt to delete the user again. | |
688 | */ | |
075fe5bb | 689 | if ( (DeleteHomeFilesys(name, TRUE) == SUB_ERROR) || |
690 | (DeleteUserGroup(name, TRUE) == SUB_ERROR) || | |
691 | (CheckIfAce(name, "user", TRUE) == SUB_ERROR) || | |
08345b74 | 692 | (RemoveItemFromLists(name, "user", |
693 | &member_of, TRUE) == SUB_ERROR) || | |
694 | (RealDeleteUser(name) == SUB_ERROR) ) { | |
08345b74 | 695 | return(DM_NORMAL); |
696 | } | |
697 | } | |
698 | ||
699 | /* | |
08345b74 | 700 | * Query - Delete all empty lists created by removing this user from them. |
701 | */ | |
702 | ||
08345b74 | 703 | local = member_of; |
704 | while (local != NULL) { | |
461c03b6 | 705 | char ** info = (char **) local->q_data; |
225ce369 | 706 | if (CheckListForDeletion(info[0], TRUE) == SUB_ERROR) |
707 | break; | |
461c03b6 | 708 | local = local->q_forw; |
08345b74 | 709 | } |
710 | ||
711 | FreeQueue(member_of); /* Free memory and return. */ | |
253517e2 | 712 | #endif |
08345b74 | 713 | return(DM_NORMAL); |
714 | } |