checlking in initial version of 2.2 scripts so I can start updating them
[jra/samba/.git] / examples / LDAP / smbldap-tools / smbldap-groupdel.pl
1 #!/usr/bin/perl 
2
3 #  This code was developped by IDEALX (http://IDEALX.org/) and
4 #  contributors (their names can be found in the CONTRIBUTORS file).
5 #
6 #                 Copyright (C) 2001-2002 IDEALX
7 #
8 #  This program is free software; you can redistribute it and/or
9 #  modify it under the terms of the GNU General Public License
10 #  as published by the Free Software Foundation; either version 2
11 #  of the License, or (at your option) any later version.
12 #
13 #  This program is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #  GNU General Public License for more details.
17 #
18 #  You should have received a copy of the GNU General Public License
19 #  along with this program; if not, write to the Free Software
20 #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 #  USA.
22
23 # Purpose of smbldap-groupdel : group (posix) deletion
24
25 use strict;
26 use smbldap_tools;
27 use smbldap_conf;
28
29 #####################
30
31 use Getopt::Std;
32 my %Options;
33
34 my $ok = getopts('?', \%Options);
35 if ( (!$ok) || (@ARGV < 1) || ($Options{'?'}) ) {
36         print "Usage: $0 groupname\n";
37         print "  -?     show this help message\n";
38         exit (1);
39 }
40
41 my $_groupName = $ARGV[0];
42
43 my $dn_line;
44 if (!defined($dn_line = get_group_dn($_groupName))) {
45     print "$0: group $_groupName doesn't exist\n";
46     exit (6);
47 }
48
49 my $dn = get_dn_from_line($dn_line);
50
51 my $rc = system "$ldapdelete $dn >/dev/null";
52 die "$0: error while deleting group $_groupName\n"
53     unless ($rc == 0);
54
55 my $nscd_status = system "/etc/init.d/nscd status >/dev/null 2>&1";
56
57 if ($nscd_status == 0) {
58    system "/etc/init.d/nscd restart > /dev/null 2>&1";
59 }
60
61 #if (defined($dn_line = get_group_dn($_groupName))) {
62 #    print "$0: failed to delete group\n";
63 #    exit (7);
64 #}
65
66
67 exit (0);
68
69 ############################################################
70
71 =head1 NAME
72
73        smbldap-groupdel.pl - Delete a group
74
75 =head1 SYNOPSIS
76
77        smbldap-groupdel.pl group
78
79 =head1 DESCRIPTION
80
81        The smbldap-groupdel.pl command modifies the system account files,
82        deleting all entries that refer to group. The named group must exist.
83
84        You must manually check all filesystems to insure that no files remain
85        with the named group as the file group ID.
86
87 =head1 SEE ALSO
88
89        groupdel(1)
90
91 =cut
92
93 #'