#!/usr/bin/perl -wT
use strict;
# generate-auto.home
# written by Aaron Thompson
# notes:
# => checks * in gidnumber 2000 and uses math_fac and cs_fac groups
# to determine which of the people w/ the gidnumber=2000 will get
# ~ from math-cs. (if someone is in math_fac or cs_fac and does
# NOT have a gidnumber=2000 in their LDAP entry they will NOT show
# up in the output. If they need to be added to the output add them
# to the include file.
#
# => include file
# -> file used is specified by the global variable $includeFile
# -> valid lines start with a username folowed by one or more
# spaces (or tabs) then the server's full dns name
# example:
# thompson math-cs.cns.uni.edu
#
# => exclude file
# -> file used is specified by the global variable $excludeFile
# -> valid lines contain only a username to exclude a line for
#
# Changed by Michael Janssen 09/2001
# added $ldapsearchParams, options that persist through all executions of $ldapsearch
#
# Changed by Aaron Thompson 2003
# cleaned up code adding configuation section.
#Configuration.
my $includeFile = "/usr/local/etc/generate-autohome.include";
# line ex: ->thompson math-cs.cns.uni.edu<-
my $excludeFile = "/usr/local/etc/generate-autohome.exclude";
# line ex: ->thompson<-
my $DefaultMount = "* -intr,nosuid henon.cns.uni.edu:/home/&\n";
my $ldapsearchParams = " -x -P 2";
my $ldapsearchArgs = "";
my $ldapsearch = "/usr/bin/ldapsearch";
#globals variabls
my @temp; my @temp2;
my %faculty; my %math_cs;
my %include; my @exclude;
my $temp = ""; my $temp2 = "";
my $math_csFlag = ""; my $excludeFlag = "";
#Get it on.
&clearENV;
&loadExclude;
&loadInclude;
if (-e $ldapsearch){
#get list of all faculty members
$ldapsearchArgs = " gidnumber=2000 dn";
@temp = `$ldapsearch $ldapsearchParams $ldapsearchArgs`;
foreach $temp (@temp){if($temp =~ /uid=(\w{1,}).*/){$faculty{$1} = 1;}}#hcaerof
#get list of all math_cs members
$ldapsearchArgs = " cn=math_fac memberuid";
@temp = `$ldapsearch $ldapsearchParams $ldapsearchArgs`;
foreach $temp (@temp){if($temp =~ /memberuid: (\w{1,}).*/){$math_cs{$1} = 1;}}#hcaerof
$ldapsearchArgs = " cn=cs_fac memberuid";
@temp = `$ldapsearch $ldapsearchParams $ldapsearchArgs`;
foreach $temp (@temp){if($temp =~ /memberuid: (\w{1,}).*/){$math_cs{$1} = 1;}}#hcaerof
#empty @temp
while(@temp){pop(@temp);}#elihw
while(@temp2){pop(@temp2);}#elihw
delete @faculty{@exclude};
delete @faculty{keys %math_cs};
delete @math_cs{@exclude};
#print faculty lines
foreach $temp (keys %faculty){
print "$temp -intr,nosuid faculty.cns.uni.edu:/home/$temp\n";
}#hcaerof
#print math-cs lines
foreach $temp (keys %math_cs){
print "$temp -intr,nosuid math-cs.cns.uni.edu:/home/$temp\n";
}#hcaerof
#print include lines
delete @include{@exclude};
foreach $temp (sort(keys(%include))){
print "$temp -intr,nosuid $include{$temp}:/home/$temp\n";
}#hcaerof
#print auto for the students.
print "$DefaultMount";
}
else{
die "$ldapsearch not available!\n";
}#fi
exit(0);
######################################################################
sub clearENV{
$ENV{PATH} = "";
$ENV{BASH_ENV} = "";
}#VNEraelc
######################################################################
sub loadExclude{
my $temp = "";
if(-e $excludeFile){
open (IN, "$excludeFile") or die "$excludeFile could not be loaded";
@temp = <IN>;
close(IN);
}#fi
foreach $temp (@temp){
if($temp =~ /(\w{1,}[\-\_]{0,1}\w{0,})/){push(@exclude,$1);}#fi
}#hcaerof
}#edulcxEdaol
######################################################################
sub loadInclude{
if(-e $includeFile){
open(IN, "$includeFile") or die "$includeFile could not be loaded";;
while(<IN>){
if (/(\w{1,}[\-\_]{0,1}\w{0,})\s{1,}(\w{1,}[\-\_]{0,1}\w{0,}[\.]{1}\w{1,}[\-\_]{0,1}\w{0,}[\.]{1}\w{1,}[\-\_]{0,1}\w{0,}[\.]{1}\w{1,}[\-\_]{0,1}\w{0,}[\.]{1}\w{1,}[\-\_]{0,1}\w{0,})/){
$include{$1} = $2;
}
elsif (/(\w{1,}[\-\_]{0,1}\w{0,})\s{1,}(\w{1,}[\-\_]{0,1}\w{0,}[\.]{1}\w{1,}[\-\_]{0,1}\w{0,}[\.]{1}\w{1,}[\-\_]{0,1}\w{0,}[\.]{1}\w{1,}[\-\_]{0,1}\w{0,})/){
$include{$1} = $2;
}
elsif (/(\w{1,}[\-\_]{0,1}\w{0,})\s{1,}(\w{1,}[\-\_]{0,1}\w{0,}[\.]{1}\w{1,}[\-\_]{0,1}\w{0,}[\.]{1}\w{1,}[\-\_]{0,1}\w{0,})/){
$include{$1} = $2;
}#fi
}#elihw
close(IN);
}#fi
}#edulcnIdaol
syntax highlighted by Code2HTML, v. 0.9.1
Return to generate-autohome page