|
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 <stdlib.h> |
|
20 #include "mystring/mystring.h" |
|
21 #include "misc/passwdfn.h" |
|
22 #include "config/configrc.h" |
|
23 #include "cli/cli.h" |
|
24 #include "vcommand.h" |
|
25 |
|
26 const char* cli_program = "vchattr"; |
|
27 const char* cli_help_prefix = "Changes the attributes on one or more virtual users\n"; |
|
28 const char* cli_help_suffix = ""; |
|
29 const char* cli_args_usage = "VALUE USERNAME ..."; |
|
30 const int cli_args_min = 2; |
|
31 const int cli_args_max = -1; |
|
32 |
|
33 static int o_attr = 0; |
|
34 static int o_quiet = false; |
|
35 |
|
36 // This program changes the value of one attribute on a set of virtual |
|
37 // users. It cannot be used to change the user's password or forwarding |
|
38 // addresses -- use B<vpasswd> and B<vchforwards> to accomplish those |
|
39 // tasks. |
|
40 |
|
41 cli_option cli_options[] = { |
|
42 { 'c', "msgcount", cli_option::flag, vdomain::ATTR_MSGCOUNT, &o_attr, |
|
43 "Set the user's message count limit", 0 }, |
|
44 { 'e', "expiry", cli_option::flag, vdomain::ATTR_EXPIRY, &o_attr, |
|
45 "Set the account's expiry time (in seconds)", 0 }, |
|
46 { 'E', "enabled", cli_option::flag, vdomain::ATTR_MAILBOX_ENABLED, &o_attr, |
|
47 "Enable or disable delivery to the account's mailbox", 0 }, |
|
48 // Enable (C<1>) or disable (C<0>) delivery to the virtual user's mailbox |
|
49 // directory. This does not delete the mailbox or any of the messages |
|
50 // contained in or, nor prevent the user from logging in. |
|
51 { 'p', "personal", cli_option::flag, vdomain::ATTR_PERSONAL, &o_attr, |
|
52 "Set the user's personal information", 0 }, |
|
53 { 'q', "softquota", cli_option::flag, vdomain::ATTR_SOFTQUOTA, &o_attr, |
|
54 "Set the user's soft quota (in bytes)", 0 }, |
|
55 { 'Q', "hardquota", cli_option::flag, vdomain::ATTR_HARDQUOTA, &o_attr, |
|
56 "Set the user's hard quota (in bytes)", 0 }, |
|
57 { 0, "quiet", cli_option::flag, true, &o_quiet, |
|
58 "Suppress all status messages", 0 }, |
|
59 { 'z', "msgsize", cli_option::flag, vdomain::ATTR_MSGSIZE, &o_attr, |
|
60 "Set the user's message size limit (in bytes)", 0 }, |
|
61 {0} |
|
62 }; |
|
63 |
|
64 // RETURN VALUE |
|
65 // |
|
66 // 0 if the given attribute was successfully changed for all users, |
|
67 // non-zero otherwise. |
|
68 // If any of the steps fail, a diagnostic message is printed. |
|
69 |
|
70 // SEE ALSO |
|
71 // |
|
72 // vadduser(1) |
|
73 |
|
74 // NOTES |
|
75 // |
|
76 // This program expects the environment variable C<HOME> to be set, and |
|
77 // executes a change directory to the contents of it before starting. It |
|
78 // is also required that you change user to the domain owner before using |
|
79 // these utilities. |
|
80 |
|
81 int cli_main(int argc, char* argv[]) |
|
82 { |
|
83 if(!o_attr) { |
|
84 if(!o_quiet) |
|
85 ferr << "vchattr: Must select an attribute to change." << endl; |
|
86 return 1; |
|
87 } |
|
88 |
|
89 if(!go_home()) |
|
90 return 1; |
|
91 |
|
92 mystring value = argv[0]; |
|
93 unsigned errors = 0; |
|
94 |
|
95 for(int i = 1; i < argc; i++) { |
|
96 mystring username = argv[i]; |
|
97 username = username.lower(); |
|
98 |
|
99 response resp = domain.chattr(username, o_attr, value); |
|
100 |
|
101 if(!resp) { |
|
102 if(!o_quiet) |
|
103 ferr << "vchattr: error changing the attribute for user '" |
|
104 << username << "':\n " << resp.msg << endl; |
|
105 errors++; |
|
106 } |
|
107 else |
|
108 if(!o_quiet) |
|
109 fout << "vchattr: attribute for user '" << username |
|
110 << "' successfully changed." << endl; |
|
111 } |
|
112 return errors; |
|
113 } |