2 Domtool (http://hcoop.sf.net/)
3 Copyright (C) 2005-2007 Adam Chlipala
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // Setting a virtual mailbox's password if you know its current password
29 int validDomain(const char *dom
) {
31 if (*dom
!= '.' && *dom
!= '_' && *dom
!= '-' && !isalnum(*dom
))
36 int main(int argc
, char *argv
[]) {
37 char *domain
, addr
[1024], cmd
[1024], *crypted
;
42 puts("Wrong number of arguments");
46 if (strlen(argv
[1]) >= 1024) {
47 puts("Address too long");
50 strcpy(addr
, argv
[1]);
52 domain
= strchr(addr
, '@');
55 puts("No @-sign found in address");
61 if (!validDomain(addr
)) {
62 puts("Invalid local part");
65 if (!validDomain(domain
)) {
66 puts("Invalid domain");
70 sprintf(cmd
, "/usr/sbin/userdb -show \"%s/%s\" | /bin/grep ^systempw=", domain
, argv
[1]);
73 puts("popen failure");
77 if (fscanf(pw
, "systempw=%1023[^\n]", cmd
) != 1) {
78 puts("Error parsing userdb output");
87 crypted
= crypt(argv
[2], addr
);
90 puts("Error encrypting");
94 if (strlen(crypted
) > 200){
95 puts("Encrypted password too long");
99 if (strcmp(crypted
, cmd
)) {
100 puts("Wrong password");
104 sprintf(cmd
, "/usr/sbin/userdbpw | /usr/sbin/userdb \"%s/%s\" set systempw", domain
, argv
[1]);
105 pw
= popen(cmd
, "w");
108 puts("Error running userdbpw");
117 puts("userdbpw error");
121 return system("/usr/local/sbin/domtool-publish courier");