From: Peter Palfrader Date: Tue, 25 Dec 2007 19:30:50 +0000 (+0100) Subject: ud-host: cleanup X-Git-Tag: userdir-ldap-0.3.16~27 X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=288100e09adf06a0d8c7fb999f5b36346163f73b;hp=c16437263020faa76c84a91b383c8d8b45d41d13;p=mirror%2Fuserdir-ldap.git ud-host: cleanup Replace local copy HBaseDn of the centrally configured HostBaseDn --- diff --git a/debian/changelog b/debian/changelog index fd610c2..5d81ac5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,8 +10,14 @@ userdir-ldap (0.3.15+xxx) XXunstable; urgency=low * Change the build dependency on python-support to be versioned >= 0.3. * ud-roleadd: Do not try to make role accounts of objectClass inetOrgPerson, that doesn't work. - - -- Peter Palfrader Tue, 25 Dec 2007 13:08:50 +0100 + * ud-fingerserv: implement daemonize() for non-inetd mode [sgran]. + * ud-useradd: support usergroups [HE]. + * ud-host/userdir-ldap.schema: Add 'purpose', 'physicalHost' to + debianServer schema and teach ud-host about [HE]. + * ud-host: cleanup: Replace local copy HBaseDn of the centrally + configured HostBaseDn [HE]. + + -- Peter Palfrader Tue, 25 Dec 2007 20:30:17 +0100 userdir-ldap (0.3.15) unstable; urgency=low diff --git a/ud-fingerserv b/ud-fingerserv index 1a944e7..1c977d8 100755 --- a/ud-fingerserv +++ b/ud-fingerserv @@ -17,7 +17,7 @@ use Net::LDAP qw(:all); # Global settings... my %config = &Util::ReadConfigFile; my %opts; -getopts("iqhv", \%opts); +getopts("fiqhvl:", \%opts); my $use_inetd = $config{use_inetd} || $opts{i}; $| = 1; @@ -41,20 +41,42 @@ $SIG{INT} = \&DieHandler; $SIG{CHLD} = \&Reaper; &help if (defined($opts{h})); -#my $logfh = STDOUT; #TODO + +my $logfh; +unless ($opt{i} || $opt{f}) { + die "Need logfile unless running foreground\n" unless (defined($opt{l})); + open ($logfh, $opt{l}) or die "Can't open logfile: $!\n"; +} else { + $logfh = \*STDOUT; +} &log("Binding to LDAP server at $config{ldaphost}") if (defined($opts{v})); my $ldap = Net::LDAP->new($config{ldaphost}) || die $1; $ldap->bind; if (!$use_inetd) { + + unless ($opts{f}) { + use POSIX 'setsid'; + chdir '/' or die "Can't chdir to /: $!"; + open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; + open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; + my $pid; + defined($pid = fork) or die "Can't fork: $!"; + exit if $pid; + setsid or die "Can't start a new session: $!"; + defined($pid = fork) or die "Can't fork: $!"; + exit if $pid; + open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; + } + &log("Binding to port 79") if (defined($opts{v})); my $server = IO::Socket::INET->new(Proto => 'tcp', LocalPort => 'finger(79)', Listen => SOMAXCONN, Reuse => 1); - die "Cannot listen on finger port" unless $server; + mydie "Cannot listen on finger port" unless $server; &log("[Server listening for connections]"); my ($pid, $client, $hostinfo); @@ -62,7 +84,7 @@ if (!$use_inetd) { while ($client = $server->accept()) { &log("Forking to handle client request") if (defined($opts{v})); next if $pid = fork; # parent - die "fork: $!" unless defined $pid; + mydie "fork: $!" unless defined $pid; # child $client->autoflush(1); @@ -118,7 +140,7 @@ sub ProcessQuery { &log("Looking up $uid at $config{basedn}, uid=$uid"); $mesg = $ldap->search(base => $config{basedn}, filter => "uid=$uid"); - $mesg->code && die $mesg->error; + $mesg->code && mydie $mesg->error; $entries = $mesg->as_struct; if ($mesg->count == 0) { @@ -168,11 +190,13 @@ sub ProcessQuery { } sub help { - print "fingerserv [-i | -q | -v | -h]\n"; + print "fingerserv [-f | -l | -i | -q | -v | -h]\n"; + print "-f = foreground; do not detach from tty\n"; print "-i = inetd mode; otherwise runs standalone\n"; print "-q = quiet mode; no output\n"; print "-v = verbose mode\n"; print "-h = this help message\n"; + print "-l = log file. Necessary if not using -f or -i\n"; exit 0; } @@ -181,7 +205,13 @@ sub log { return if (defined($opts{q})); my $time = localtime; - print STDERR "$time $msg\n"; + print $logfh "$time $msg\n"; +} + +sub mydie { + my $msg = shift; + log($msg); + exit 1; } sub readdata { @@ -192,9 +222,9 @@ sub readdata { my $ret; my $flags= fcntl($fh, F_GETFL, 0) - or die "Can't get flags for socket: $!\n"; + or mydie "Can't get flags for socket: $!\n"; fcntl($fh, F_SETFL, $flags | O_NONBLOCK) - or die "Can't make socket nonblocking: $!\n"; + or mydie "Can't make socket nonblocking: $!\n"; while (($bytesread < 1024) && ($out !~ /\n/)) { $ret = sysread($fh, $in, 1024);