|
1 // Copyright (C) 1999,2000 Bruce Guenter <bruceg@em.ca> |
|
2 // |
|
3 // This program is free software; you can redistribute it and/or modify |
|
4 // it under the terms of the GNU General Public License as published by |
|
5 // the Free Software Foundation; either version 2 of the License, or |
|
6 // (at your option) any later version. |
|
7 // |
|
8 // This program is distributed in the hope that it will be useful, |
|
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 // GNU General Public License for more details. |
|
12 // |
|
13 // You should have received a copy of the GNU General Public License |
|
14 // along with this program; if not, write to the Free Software |
|
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 #include <config.h> |
|
18 #include "fdbuf/fdbuf.h" |
|
19 #include "config/configrc.h" |
|
20 #include "cli/cli.h" |
|
21 #include "vcommand.h" |
|
22 |
|
23 const char* cli_program = "vdeluser"; |
|
24 const char* cli_help_prefix = "Delete users from a virtual domain\n"; |
|
25 const char* cli_help_suffix = ""; |
|
26 const char* cli_args_usage = "USER1 [USER2 ...]"; |
|
27 const int cli_args_min = 1; |
|
28 const int cli_args_max = -1; |
|
29 |
|
30 static int o_quiet = false; |
|
31 static int o_domailbox = true; |
|
32 |
|
33 // This program will take the steps necessary to |
|
34 // remove a user from a virtual domain. |
|
35 // |
|
36 // For each user listed on the command line, it does the following: |
|
37 // |
|
38 // 1. It removes the named user's entry from the local password file. |
|
39 // |
|
40 // 2. It removes any qmail delivery files that point to the named user's |
|
41 // mail directory. |
|
42 // |
|
43 // 3. It removes the user's mail directory and all of its contents |
|
44 // (recursively). |
|
45 // |
|
46 // If any of the above steps fail, a warning is issued and processing |
|
47 // continues. |
|
48 |
|
49 cli_option cli_options[] = { |
|
50 { 'D', "no-mailbox", cli_option::flag, false, &o_domailbox, |
|
51 "Do not delete users that have a mailbox", 0 }, |
|
52 { 0, "quiet", cli_option::flag, true, &o_quiet, |
|
53 "Suppress all status messages", 0 }, |
|
54 {0} |
|
55 }; |
|
56 |
|
57 // NOTES |
|
58 // |
|
59 // You must have either created the users subdirectory by hand or run the |
|
60 // F<vsetup> program before using this program. |
|
61 // |
|
62 // This program expects the environment variable C<HOME> to be set, and |
|
63 // executes a change directory to the contents of it before starting. It |
|
64 // is also required that you change user to the domain owner before using |
|
65 // these utilities. |
|
66 |
|
67 int cli_main(int argc, char* argv[]) |
|
68 { |
|
69 if(!go_home()) |
|
70 return 1; |
|
71 int errors = 0; |
|
72 for(int i = 0; i < argc; i++) { |
|
73 response r = domain.deluser(argv[i], o_domailbox); |
|
74 if(!r) { |
|
75 errors++; |
|
76 if(!o_quiet) |
|
77 ferr << "vdeluser: error deleting user '" << argv[i] << "':\n " |
|
78 << r.msg << endl; |
|
79 } |
|
80 else |
|
81 if(!o_quiet) |
|
82 fout << "vdeluser: user '" << argv[i] << "' successfully deleted." |
|
83 << endl; |
|
84 } |
|
85 if(errors) { |
|
86 if(!o_quiet) |
|
87 ferr << "vdeluser: " << errors << " errors were encountered." << endl; |
|
88 return 1; |
|
89 } |
|
90 return 0; |
|
91 } |