|
0
|
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 <ctype.h>
|
|
|
19 |
#include "vdomain.h"
|
|
|
20 |
#include "misc/pwcrypt.h"
|
|
|
21 |
#include "misc/autodelete.h"
|
|
|
22 |
#include "misc/strtou.h"
|
|
|
23 |
|
|
|
24 |
static const response
|
|
|
25 |
resp_invalid_number(response::err, "Invalid number"),
|
|
|
26 |
resp_attribute_changed(response::ok, "Attribute value changed");
|
|
|
27 |
|
|
|
28 |
response vdomain::chattr(mystring username, unsigned attr, mystring newval)
|
|
|
29 |
{
|
|
|
30 |
autodelete<vpwentry> vpw = table()->getbyname(username);
|
|
|
31 |
if(!vpw)
|
|
|
32 |
RETURN(err, "Invalid or unknown virtual user");
|
|
|
33 |
return chattr(vpw, attr, newval);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
static response chunsigned(unsigned* value, mystring newval)
|
|
|
37 |
{
|
|
|
38 |
const char* end;
|
|
|
39 |
*value = strtou(newval.c_str(), &end);
|
|
|
40 |
if(*end)
|
|
|
41 |
return resp_invalid_number;
|
|
|
42 |
else
|
|
|
43 |
return resp_attribute_changed;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
response vdomain::chpass(vpwentry* vpw, mystring pass)
|
|
|
47 |
{
|
|
|
48 |
vpw->pass = pwcrypt(pass);
|
|
|
49 |
RETURN(ok, "Password changed");
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
response vdomain::chdest(vpwentry* vpw, mystring dest)
|
|
|
53 |
{
|
|
|
54 |
if(!!dest) {
|
|
|
55 |
for(mystring_iter iter = dest; iter; ++iter) {
|
|
|
56 |
response r = validate_forward(*iter);
|
|
|
57 |
if(!r)
|
|
|
58 |
return r;
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
vpw->forwards = dest;
|
|
|
62 |
RETURN(ok, "Forwarding address(es) changed");
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
static response chbool(bool* value, mystring newval)
|
|
|
66 |
{
|
|
|
67 |
const char* end;
|
|
|
68 |
unsigned i = strtou(newval.c_str(), &end);
|
|
|
69 |
if(*end)
|
|
|
70 |
return resp_invalid_number;
|
|
|
71 |
*value = !!i;
|
|
|
72 |
return resp_attribute_changed;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
#define CHATTR(V,X) do{ response tmp=ch##X(&(V),newval); if(!tmp) return tmp; okmsg=tmp.msg; }while(0)
|
|
|
76 |
|
|
|
77 |
response vdomain::chattr(const vpwentry* vpw, unsigned attr, mystring newval)
|
|
|
78 |
{
|
|
|
79 |
vpwentry newpw(*vpw);
|
|
|
80 |
mystring okmsg;
|
|
|
81 |
switch(attr) {
|
|
|
82 |
case ATTR_PASS: CHATTR(newpw,pass); break;
|
|
|
83 |
case ATTR_DEST: CHATTR(newpw,dest); break;
|
|
|
84 |
case ATTR_HARDQUOTA: CHATTR(newpw.hardquota,unsigned); break;
|
|
|
85 |
case ATTR_SOFTQUOTA: CHATTR(newpw.softquota,unsigned); break;
|
|
|
86 |
case ATTR_MSGSIZE: CHATTR(newpw.msgsize,unsigned); break;
|
|
|
87 |
case ATTR_MSGCOUNT: CHATTR(newpw.msgcount,unsigned); break;
|
|
|
88 |
case ATTR_EXPIRY: CHATTR(newpw.expiry,unsigned); break;
|
|
|
89 |
case ATTR_MAILBOX_ENABLED: CHATTR(newpw.is_mailbox_enabled,bool); break;
|
|
|
90 |
case ATTR_PERSONAL:
|
|
|
91 |
newpw.personal = newval;
|
|
|
92 |
okmsg = "Personal information changed.";
|
|
|
93 |
break;
|
|
|
94 |
default:
|
|
|
95 |
RETURN(bad, "Invalid attribute type");
|
|
|
96 |
}
|
|
|
97 |
if(!table()->set(&newpw))
|
|
|
98 |
RETURN(err, "Error changing the password table");
|
|
|
99 |
RETURN(ok, okmsg);
|
|
|
100 |
}
|