Hi,

First of all, thanks for qpsmtpd :) It's really cool !

I wrote a little patch for qpsmtpd so it can get its configuration from
LDAP. I haven't tried it myself yet, but I'll do that tonight or
tomorrow. It should work quite te same as qmail-ldap-control and the
following files are needed in /var/qmail/control:

- me
- ldapbasedn
- ldapcontroldn
- ldapserver

and optionally (for authenticated binds):

- ldaplogin
- ldappassword

The rest of the configuration is then retrieved from ldap.
If the attributes aren't availlable in ldap, they will be retrieved from
/var/qmail/control or /var/qmail/control/config.

Anyway.. here's the patch, and thanks again, you'll hear more from me
soon :)

Regards,

Leon de Rooy
[EMAIL PROTECTED]
--- qpsmtpd     Wed Jul 24 16:45:15 2002
+++ qpsmtpd     Wed Jul 24 16:47:18 2002
@@ -30,7 +30,11 @@
 $TRACE = 0;
 
 my %config;
+my %config_cache;
 $config{me} = get_config('me') || hostname;
+
+get_ldap_config();
+
 $config{timeout} = get_config('timeoutsmtpd') || 1200;
 
 my (@commands) = qw(ehlo helo rset mail rcpt data help vrfy noop quit);
@@ -386,7 +390,6 @@
   return 0;
 }
 
-my %config_cache;
 sub get_config {
   my $config = shift;
   warn "$$ trying to get config for $config" if $TRACE > 4;
@@ -402,6 +405,42 @@
   warn "$$ returning get_config for $config ",Data::Dumper->Dump([\@config], 
[qw(config)]) if $TRACE > 4;
   $config_cache{$config} = \@config;
   return wantarray ? @config : $config[0];
+}
+
+sub get_ldap_config {
+       # If ldapcontroldn, ldapbasedn and ldapserver are defined, then try to fill 
+the %config_cache hash:
+       if ( ($config{ldapcontroldn} = get_config('ldapcontroldn')) &&
+            ($config{ldapbasedn} = get_config('ldapbasedn')) &&
+                        ($config{ldapserver} = get_config('ldapserver')) ) {
+
+               # Try to get ldaplogin and ldappassword for authenticated bind:
+               $config{ldaplogin} = get_config('ldaplogin');
+               $config{ldappassword} = get_config('ldappassword');
+
+               use Net::LDAP;
+
+         my $ldapconn = Net::LDAP -> new ( $config{ldapserver} );
+       
+               if ( ($config{ldaplogin}) && ($config{ldappassword}) ) {
+                       # Do an authenticated bind:
+                       $ldapconn -> bind ( $config{ldaplogin} , password => 
+$config{ldappassword} );
+         } else {
+                       # Do an anonymous bind:
+                       $ldapconn -> bind;
+               }
+
+               my $ldapmesg = $ldapconn -> search ( base => $config{ldapbasedn} , 
+filter => $config{ldapcontroldn} );
+               $ldapmesg -> code && die $ldapmesg -> error;
+
+               while (my $ldapentry = $ldapmesg->shift_entry()) {
+                       foreach my $ldapattr ( sort $ldapentry->attributes ) {
+                               my @ldapvalues = $ldapentry->get_value($ldapattr);
+                               # And cache these attributes:
+                       $config_cache{$ldapattr} = \@ldapvalues;
+                       }
+               }
+               $ldapconn -> unbind;
+       }
 }
 
 1;

Reply via email to