21 #include "misc/passwdfn.h" |
21 #include "misc/passwdfn.h" |
22 #include "mystring/mystring.h" |
22 #include "mystring/mystring.h" |
23 #include "config/configrc.h" |
23 #include "config/configrc.h" |
24 #include "misc/pwcrypt.h" |
24 #include "misc/pwcrypt.h" |
25 #include "vcommand.h" |
25 #include "vcommand.h" |
26 #include "cli/cli.h" |
26 #include "cli++/cli++.h" |
27 |
27 |
28 const char* cli_program = "vadduser"; |
28 const char* cli_program = "vadduser"; |
29 const char* cli_help_prefix = "Add a user to a virtual domain\n"; |
29 const char* cli_help_prefix = "Add a user to a virtual domain\n"; |
30 const char* cli_help_suffix = ""; |
30 const char* cli_help_suffix = ""; |
31 const char* cli_args_usage = "USERNAME [ALIAS1 ...]\n" |
31 const char* cli_args_usage = "USERNAME [ALIAS1 ...]\n" |
32 "or vaddalias [-f ADDRESS] USERNAME [ALIAS1 ...]"; |
32 "or vaddalias USERNAME [ALIAS1 ...]"; |
33 const int cli_args_min = 1; |
33 const int cli_args_min = 1; |
34 const int cli_args_max = -1; |
34 const int cli_args_max = -1; |
35 |
35 |
36 static const char* o_userdir = 0; |
36 static const char* o_userdir = 0; |
37 static cli_stringlist* o_forwards = 0; |
37 static cli_stringlist* o_forwards = 0; |
40 static int o_hardquota = 0; |
40 static int o_hardquota = 0; |
41 static int o_msgsize = 0; |
41 static int o_msgsize = 0; |
42 static int o_msgcount = 0; |
42 static int o_msgcount = 0; |
43 static int o_expiry = 0; |
43 static int o_expiry = 0; |
44 static int o_password = true; |
44 static int o_password = true; |
45 static int o_domailbox = true; |
45 static int o_hasmailbox = true; |
46 static int o_quiet = false; |
46 static int o_quiet = false; |
|
47 static const char* o_pwcrypt = 0; |
47 |
48 |
48 // This program is used to set up a user within a virtual host. |
49 // This program is used to set up a user within a virtual host. |
49 // If this program is reading from a tty, |
50 // If this program is reading from a tty, |
50 // it will then ask for a password (twice, to make sure you typed it in |
51 // it will then ask for a password (twice, to make sure you typed it in |
51 // correctly), otherwise it will read the password from the input with no |
52 // correctly), otherwise it will read the password from the input with no |
56 // It will also add an entry for each of the named aliases. |
57 // It will also add an entry for each of the named aliases. |
57 |
58 |
58 cli_option cli_options[] = { |
59 cli_option cli_options[] = { |
59 { 'c', "msgcount", cli_option::integer, 0, &o_msgcount, |
60 { 'c', "msgcount", cli_option::integer, 0, &o_msgcount, |
60 "Set the user's message count limit", 0 }, |
61 "Set the user's message count limit", 0 }, |
61 { 'D', "no-mailbox", cli_option::flag, false, &o_domailbox, |
62 { 'D', "no-mailbox", cli_option::flag, false, &o_hasmailbox, |
62 "Do not create a mailbox for this user", "true for vaddalias" }, |
63 "Do not create a mailbox for this user", "true for vaddalias" }, |
63 { 'd', "directory", cli_option::string, 0, &o_userdir, |
64 { 'd', "directory", cli_option::string, 0, &o_userdir, |
64 "Set the path to the user's mailbox", 0 }, |
65 "Set the path to the user's mailbox", 0 }, |
65 // Set the path to the user's mailbox. |
66 // Set the path to the user's mailbox. |
66 // Note that this directory is unconditionally prefixed with "./". |
67 // Note that this directory is unconditionally prefixed with "./". |
67 { 'e', "expiry", cli_option::integer, 0, &o_expiry, |
68 { 'e', "expiry", cli_option::integer, 0, &o_expiry, |
68 "Set the account's expiry time (in seconds)", 0 }, |
69 "Set the account's expiry time (in seconds)", 0 }, |
69 { 'f', "forward", cli_option::stringlist, 0, &o_forwards, |
70 { 'f', "forward", cli_option::stringlist, 0, &o_forwards, |
70 "Add a forwarding address to this user", 0 }, |
71 "Add a forwarding address to this user", 0 }, |
71 // Add a forwarding address to this user (this may be used multiple times). |
72 // Add a forwarding address to this user (this may be used multiple times). |
|
73 { 0, "password", cli_option::string, 0, &o_pwcrypt, |
|
74 "Encrypted password", "asking for a password" }, |
72 { 'P', "no-password", cli_option::flag, false, &o_password, |
75 { 'P', "no-password", cli_option::flag, false, &o_password, |
73 "Do not ask for a password", 0 }, |
76 "Do not ask for a password", 0 }, |
74 // Do not ask for a password, |
77 // Do not ask for a password, |
75 // and instead set the pass phrase field to an unusable value. |
78 // and instead set the pass phrase field to an unusable value. |
76 { 'p', "personal", cli_option::string, 0, &o_personal, |
79 { 'p', "personal", cli_option::string, 0, &o_personal, |
154 } |
153 } |
155 |
154 |
156 void add_user(const mystring& user) |
155 void add_user(const mystring& user) |
157 { |
156 { |
158 if(!domain.exists(user)) { |
157 if(!domain.exists(user)) { |
159 mystring passcode = "*"; |
158 mystring passcode; |
160 if(o_password) { |
159 if(o_pwcrypt) |
|
160 passcode = o_pwcrypt; |
|
161 else if(o_password) { |
161 mystring passwd = getpasswd(argv0base); |
162 mystring passwd = getpasswd(argv0base); |
162 if(passwd.length() == 0) |
163 if(passwd.length() == 0) |
163 exit(1); |
164 exit(1); |
164 passcode = pwcrypt(passwd); |
165 passcode = pwcrypt(passwd); |
165 } |
166 } |
|
167 else |
|
168 passcode = "*"; |
166 vpwentry* vpw = make_user(user, passcode); |
169 vpwentry* vpw = make_user(user, passcode); |
167 response resp = domain.set(vpw, true, vpw->mailbox); |
170 response resp = domain.set(vpw, true); |
168 delete vpw; |
171 delete vpw; |
169 if(!resp) { |
172 if(!resp) { |
170 if(!o_quiet) |
173 if(!o_quiet) |
171 ferr << argv0base << ": error adding the virtual user:\n " |
174 ferr << argv0base << ": error adding the virtual user:\n " |
172 << resp.msg << endl; |
175 << resp.msg << endl; |