script/netgroupcache.pl untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 50 CC 2 SCAR 12.0
CC
2
Cov
0%
get_entries
6.0
write_output
2.0
BEGIN
2.0
CRAP 3.3
1 #!/usr/local/bin/perl
2  
3 =head1 NAME
4  
5 netgroupcache.pl - a programme to make a local cache of LDAP netgroups.
6  
7 =head1 SYNOPSIS
8  
9 This programme pulls a copy of netgroups from the LDAP server, prefixes their name with 'local'
10 and places them in the /etc/netgroups file
11  
12 by doing this, you can configure access.conf to also allow these local netgroups. thus
13 allowing login even if the LDAP server is not online to answer netgroup queries.
14  
15 This script should be run from cron at an appropriate interval.
16  
17 =head1 CONFIG
18  
19 A configuration file is required in /etc/netgroupcache.conf An example is below:
20  
21 #Global config
22 #These options are passed to OSS::LDAPops and are all required.
23 $GLOBAL::config =
24 {
25 LDAPHOST => 'ldap01.mydomain.net',
26 BINDDN => 'uid=webportal, ou=writeaccess, dc=auth, dc=mydomain,dc=net',
27 BASEDN => 'dc=auth,dc=mydomain,dc=net',
28 NISDOMAIN => 'auth.mydomain.net',
29 PASSWORD => 'xyzzy'
30  
31 };
32  
33 #This 1 is required!
34 1;
35  
36 This example is also included in the source distribution.
37  
38 =head USAGE
39  
40 netgroupcache.pl <netgroup> <netgroup> <netgroup> .....
41  
42 \* may be used as a wildcard, including as the only argument
43 to get all netgroups.
44  
45 (you can add as many netgroups as you like)
46  
47 This code uses OSS::LDAPops Please see the OSS::LDAPops manual for more details.
48  
49 =cut
50  
51  
52 #use strict pragma.
53 use strict;
54  
55 #Use OSS::LDAPops object.
56 use OSS::LDAPops;
57  
58 #Load config
59 require '/etc/netgroupcache.conf';
60  
61  
62 #Instantiate new object.
63 my($ldapopsobj) = OSS::LDAPops->new($GLOBAL::config);
64 if (ref($ldapopsobj) !~ m/OSS::LDAPops/ ) {die("Error instantiating object: $ldapopsobj")};
65 my($ret);
66 my(@retu);
67  
68 #Get netgroup entries
69 sub get_entries
70 {
71 my(@out);
72 my($ngref);
73 $ldapopsobj->bind;
74 foreach my $netgroup (@ARGV)
75 {
76 @retu = $ldapopsobj->searchnetgroup($netgroup);
77 die($retu[0]) if (($retu[0] ne undef) and (ref($retu[0]) !~ m/Net::LDAP::Entry/) );
78 foreach my $entry (@retu)
79 {
80 $ngref = $entry->get_value('nisNetgroupTriple', asref => 1);
81 foreach my $ngt (@$ngref)
82 {
83 push(@out, 'local'.$entry->get_value('cn').' '.$ngt."\n");
84 };
85 };
86 };
87 return(@out);
88 };
89  
90 #Write output to /etc/netgroup
91 sub write_output
92 {
93 my(@file) = @_;
94 open(FILE, '>'.'/etc/netgroup') or die($!);
95 print(FILE @file);
96 close(@file);
97  
98 };
99  
100 &write_output(&get_entries);