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