source: npl/fileserver/smb-ldap-tool/modified/smbldap-userdel @ d849d83

gcc484ntopperl-5.22
Last change on this file since d849d83 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 3.4 KB
Line 
1#!/usr/bin/perl
2
3# $Id: smbldap-userdel 2643 2006-09-15 09:12:49Z erwin $
4#
5#  This code was developped by IDEALX (http://IDEALX.org/) and
6#  contributors (their names can be found in the CONTRIBUTORS file).
7#
8#                 Copyright (C) 2001-2002 IDEALX
9#
10#  This program is free software; you can redistribute it and/or
11#  modify it under the terms of the GNU General Public License
12#  as published by the Free Software Foundation; either version 2
13#  of the License, or (at your option) any later version.
14#
15#  This program is distributed in the hope that it will be useful,
16#  but WITHOUT ANY WARRANTY; without even the implied warranty of
17#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18#  GNU General Public License for more details.
19#
20#  You should have received a copy of the GNU General Public License
21#  along with this program; if not, write to the Free Software
22#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
23#  USA.
24
25# Purpose of smbldap-userdel : user (posix,shadow,samba) deletion
26
27use strict;
28use FindBin;
29use FindBin qw($RealBin);
30use lib "$RealBin/";
31use smbldap_tools;
32
33
34#####################
35
36use Getopt::Std;
37my %Options;
38
39my $ok = getopts('rR?', \%Options);
40
41if ( (!$ok) || (@ARGV < 1) || ($Options{'?'}) ) {
42  print_banner;
43  print "Usage: $0 [-r?] username\n";
44  print "  -r   remove home directory\n";
45  print "  -R   remove home directory interactively\n";
46  exit (1);
47}
48
49# Read only first @ARGV
50my $user = $ARGV[0];
51
52my $ldap_master=connect_ldap_master();
53
54my $dn;
55# user must not exist in LDAP
56if (!defined($dn=get_user_dn($user))) {
57  print "$0: user $user does not exist\n";
58  exit (6);
59}
60
61if ($< != 0) {
62  print "You must be root to delete an user\n";
63  exit (1);
64}
65
66my $homedir;
67if (defined($Options{'r'}) || defined($Options{'R'})) {
68  $homedir=get_homedir($user);
69  if ($homedir !~ /^\/.+\/(.*)$user/) {
70    print "Refusing to delete this home directory: $homedir\n";
71    exit (1);
72  }
73}
74
75# remove user from groups
76my @groups = &find_groups_of($user);
77foreach my $gname (@groups) {
78  if ($gname ne "") {
79    group_remove_member($gname, $user);
80  }
81}
82
83my $del1 = $ldap_master->modify ("cn=AddressAdmins,o=AddressBook,$config{suffix}",delete => { member  => "uid=$user,$config{usersdn}" });
84$del1->code && warn "failed to delete entry: ", $del1->error ;
85
86
87# XXX
88delete_user($user);
89
90# delete dir -- be sure that homeDir is not a strange value
91if ($homedir) {
92  my @rmargs = ( '-r' );
93  if (defined($Options{'R'})) {
94    push(@rmargs, '-i');
95  } elsif (defined($Options{'r'})) {
96    push(@rmargs, '-f');
97  }
98  # print "rm @rmargs $homedir\n";
99  system('rm', @rmargs, $homedir);
100}
101
102my $nscd_status = system "/etc/init.d/nscd status >/dev/null 2>&1";
103
104if ($nscd_status == 0) {
105  system "/etc/init.d/nscd restart > /dev/null 2>&1";
106}
107
108$ldap_master->unbind;           # take down session
109
110exit (0);
111
112############################################################
113
114=head1 NAME
115
116smbldap-userdel - Delete a user account and related files
117
118=head1 SYNOPSIS
119
120smbldap-userdel [-r] login
121
122=head1 DESCRIPTION
123
124The smbldap-userdel command modifies the system account files, deleting all entries that refer to user defined in "login". The named user must exist.
125
126-r
127  Files in the user's home directory will be removed along with the home directory itself. Files located in other file systems will have to be searched for and deleted manually.
128
129=head1 SEE ALSO
130
131       userdel(1)
132
133=cut
134
135#'
Note: See TracBrowser for help on using the repository browser.