daemon/adduser.cc
changeset 2 b3afb9f1e801
equal deleted inserted replaced
1:30113bfbe723 2:b3afb9f1e801
       
     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 static response do_adduser(command& args, int minargc)
       
    41 {
       
    42   mystring fulluser = args[0];
       
    43   mystring adminpass = args[1];
       
    44   mystring newpass = args[2];
       
    45   mystring directory = args[3];
       
    46   args[1] = LOG_ADMINPASS;
       
    47   args[2] = LOG_NEWPASS;
       
    48   logcommand(args);
       
    49   
       
    50   pwentry* pw;
       
    51   vpwentry* vpw;
       
    52   OK_RESPONSE(lookup_and_validate(fulluser, pw, vpw, adminpass, false));
       
    53   OK_RESPONSE(build_forwards(args, minargc, vpw, state->domain));
       
    54   if(!!newpass)
       
    55     vpw->pass = pwcrypt(newpass);
       
    56   if(!directory)
       
    57     directory = vpw->name;
       
    58   vpw->directory = "./" + state->domain.userdir(directory);
       
    59   vpw->has_mailbox = !!args[minargc-1];
       
    60   return state->domain.set(vpw, true);
       
    61 }
       
    62 
       
    63 CMD(adduser2)
       
    64   // Usage: adduser2 baseuser-virtuser adminpass newpass dirname [forwards ...]
       
    65   // If <newpass> is empty, a null-password is used.
       
    66   // If <dirname> is empty, no mailbox directory is created.
       
    67   // <dirname> should normally be the same as virtuser.
       
    68 {
       
    69   return do_adduser(args, 4);
       
    70 }
       
    71 
       
    72 CMD(adduser3)
       
    73   // Usage: adduser3 baseuser-virtuser adminpass newpass dirname has_mailbox [forwards ...]
       
    74   // If <newpass> is empty, a null-password is used.
       
    75   // If <dirname> is empty, <virtuser> is used in its place
       
    76   // If <has_mailbox> is empty, no mailbox is created,
       
    77   // just the account directory
       
    78 {
       
    79   return do_adduser(args, 5);
       
    80 }