|
0
|
1 |
// Copyright (C) 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 <stdlib.h>
|
|
|
19 |
#include <sys/stat.h>
|
|
|
20 |
#include "daemon.h"
|
|
|
21 |
|
|
|
22 |
response build_forwards(const command& args, int offset,
|
|
|
23 |
vpwentry* vpw, vdomain& domain)
|
|
|
24 |
{
|
|
|
25 |
bool first = true;
|
|
|
26 |
for(unsigned i = offset; i < args.count(); i++) {
|
|
|
27 |
if(!!args[i]) {
|
|
|
28 |
OK_RESPONSE(domain.validate_forward(args[i]));
|
|
|
29 |
if(!first)
|
|
|
30 |
vpw->forwards = vpw->forwards + mystring::NUL + args[i];
|
|
|
31 |
else {
|
|
|
32 |
vpw->forwards = args[i];
|
|
|
33 |
first = false;
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
RETURN(ok, "");
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
CMD(adduser2)
|
|
|
41 |
// Usage: adduser2 baseuser-virtuser adminpass newpass dirname [forwards ...]
|
|
|
42 |
// If <newpass> is empty, a null-password is used.
|
|
|
43 |
// If <dirname> is empty, no user directory is created.
|
|
|
44 |
// <dirname> should normally be the same as virtuser.
|
|
|
45 |
{
|
|
|
46 |
mystring fulluser = args[0];
|
|
|
47 |
mystring adminpass = args[1];
|
|
|
48 |
mystring newpass = args[2];
|
|
|
49 |
mystring dirname = args[3];
|
|
|
50 |
args[1] = LOG_ADMINPASS;
|
|
|
51 |
args[2] = LOG_NEWPASS;
|
|
|
52 |
logcommand(args);
|
|
|
53 |
|
|
|
54 |
pwentry* pw;
|
|
|
55 |
vpwentry* vpw;
|
|
|
56 |
OK_RESPONSE(lookup_and_validate(fulluser, pw, vpw, adminpass, false));
|
|
|
57 |
OK_RESPONSE(build_forwards(args, 4, vpw, state->domain));
|
|
|
58 |
if(!!newpass)
|
|
|
59 |
vpw->pass = pwcrypt(newpass);
|
|
|
60 |
if(!!dirname)
|
|
|
61 |
vpw->mailbox = "./" + state->domain.userdir(dirname);
|
|
|
62 |
return state->domain.set(vpw, true, vpw->mailbox);
|
|
|
63 |
}
|