lib/vdomain/deluser.cc
author "Tomas Zeman <tzeman@volny.cz>"
Sun, 20 Jan 2008 00:22:09 +0100
changeset 2 b3afb9f1e801
parent 0 6f7a81934006
permissions -rw-r--r--
Imported vmailmgr-0.97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
     1
// Copyright (C) 1999,2000 Bruce Guenter <bruceg@em.ca>
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
     2
//
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
     3
// This program is free software; you can redistribute it and/or modify
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
     4
// it under the terms of the GNU General Public License as published by
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
     5
// the Free Software Foundation; either version 2 of the License, or
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
     6
// (at your option) any later version.
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
     7
//
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
     8
// This program is distributed in the hope that it will be useful,
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
     9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    11
// GNU General Public License for more details.
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    12
//
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    13
// You should have received a copy of the GNU General Public License
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    14
// along with this program; if not, write to the Free Software
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    15
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    16
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    17
#include <config.h>
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    18
#include "vdomain.h"
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    19
#include "misc/autodelete.h"
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    20
#include "misc/maildir.h"
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    21
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    22
response vdomain::deluser(mystring user, bool del_mailbox)
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    23
{
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    24
  user = user.lower();
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    25
  autodelete<vpwentry> vpw = table()->getbyname(user);
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    26
  if(!vpw)
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    27
    RETURN(err, "User does not exist");
2
b3afb9f1e801 Imported vmailmgr-0.97
"Tomas Zeman <tzeman@volny.cz>"
parents: 0
diff changeset
    28
  if(!del_mailbox && vpw->has_mailbox)
0
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    29
    RETURN(err, "User has a mailbox");
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    30
  if(!table()->del(vpw->name))
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    31
    RETURN(err, "Couldn't delete user from the password file");
2
b3afb9f1e801 Imported vmailmgr-0.97
"Tomas Zeman <tzeman@volny.cz>"
parents: 0
diff changeset
    32
  if(!!vpw->directory && !delete_directory(vpw->directory))
b3afb9f1e801 Imported vmailmgr-0.97
"Tomas Zeman <tzeman@volny.cz>"
parents: 0
diff changeset
    33
    RETURN(err, "Couldn't delete user's directory");
0
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    34
  RETURN(ok, "Deleted user.");
6f7a81934006 Imported vmailmgr-0.96.9
"Tomas Zeman <tzeman@volny.cz>"
parents:
diff changeset
    35
}