--- a/commands/vadduser.cc Sun Jan 20 00:12:17 2008 +0100
+++ b/commands/vadduser.cc Sun Jan 20 00:22:09 2008 +0100
@@ -23,13 +23,13 @@
#include "config/configrc.h"
#include "misc/pwcrypt.h"
#include "vcommand.h"
-#include "cli/cli.h"
+#include "cli++/cli++.h"
const char* cli_program = "vadduser";
const char* cli_help_prefix = "Add a user to a virtual domain\n";
const char* cli_help_suffix = "";
const char* cli_args_usage = "USERNAME [ALIAS1 ...]\n"
-"or vaddalias [-f ADDRESS] USERNAME [ALIAS1 ...]";
+"or vaddalias USERNAME [ALIAS1 ...]";
const int cli_args_min = 1;
const int cli_args_max = -1;
@@ -42,8 +42,9 @@
static int o_msgcount = 0;
static int o_expiry = 0;
static int o_password = true;
-static int o_domailbox = true;
+static int o_hasmailbox = true;
static int o_quiet = false;
+static const char* o_pwcrypt = 0;
// This program is used to set up a user within a virtual host.
// If this program is reading from a tty,
@@ -58,7 +59,7 @@
cli_option cli_options[] = {
{ 'c', "msgcount", cli_option::integer, 0, &o_msgcount,
"Set the user's message count limit", 0 },
- { 'D', "no-mailbox", cli_option::flag, false, &o_domailbox,
+ { 'D', "no-mailbox", cli_option::flag, false, &o_hasmailbox,
"Do not create a mailbox for this user", "true for vaddalias" },
{ 'd', "directory", cli_option::string, 0, &o_userdir,
"Set the path to the user's mailbox", 0 },
@@ -69,6 +70,8 @@
{ 'f', "forward", cli_option::stringlist, 0, &o_forwards,
"Add a forwarding address to this user", 0 },
// Add a forwarding address to this user (this may be used multiple times).
+ { 0, "password", cli_option::string, 0, &o_pwcrypt,
+ "Encrypted password", "asking for a password" },
{ 'P', "no-password", cli_option::flag, false, &o_password,
"Do not ask for a password", 0 },
// Do not ask for a password,
@@ -120,13 +123,11 @@
vpwentry* make_user(const mystring& name, const mystring& passcode)
{
mystring dir;
- if(o_domailbox) {
- if(o_userdir)
- dir = o_userdir;
- else
- dir = domain.userdir(name);
- dir = "./" + dir;
- }
+ if(o_userdir)
+ dir = o_userdir;
+ else
+ dir = domain.userdir(name);
+ dir = "./" + dir;
for(cli_stringlist* node = o_forwards; node; node = node->next) {
response r = domain.validate_forward(node->string);
@@ -139,9 +140,7 @@
}
vpwentry* vpw = new vpwentry(name.lower(), passcode, dir,
- list2str(o_forwards));
- vpw->set_defaults(true, true);
-
+ list2str(o_forwards), o_hasmailbox);
vpw->personal = o_personal;
vpw->hardquota = o_hardquota;
vpw->softquota = o_softquota;
@@ -156,15 +155,19 @@
void add_user(const mystring& user)
{
if(!domain.exists(user)) {
- mystring passcode = "*";
- if(o_password) {
+ mystring passcode;
+ if(o_pwcrypt)
+ passcode = o_pwcrypt;
+ else if(o_password) {
mystring passwd = getpasswd(argv0base);
if(passwd.length() == 0)
exit(1);
passcode = pwcrypt(passwd);
}
+ else
+ passcode = "*";
vpwentry* vpw = make_user(user, passcode);
- response resp = domain.set(vpw, true, vpw->mailbox);
+ response resp = domain.set(vpw, true);
delete vpw;
if(!resp) {
if(!o_quiet)
@@ -185,8 +188,7 @@
alias = alias.lower();
user = user.lower();
if(!domain.exists(alias)) {
- vpwentry vpw(alias, "*", 0, user);
- vpw.set_defaults(true, true);
+ vpwentry vpw(alias, "*", domain.userdir(alias), user, false);
response resp = domain.set(&vpw, true);
if(!resp)
if(!o_quiet)
@@ -208,7 +210,7 @@
void set_defaults()
{
if(!strcmp(argv0base, "vaddalias"))
- o_domailbox = false;
+ o_hasmailbox = false;
if(!o_hardquota)
o_hardquota = config->default_hardquota();
if(!o_softquota)