Search code examples
perlunixldap

How to create users on a LDAP server with Perl for Unix authentication?


I'm trying to create a web server which needs for some user authentication within the server itself. I need to do it with Perl so I decided to try to use an LDAP server in localhost.

I've been trying to use the script below. Everything is configured correctly (as i tried to search for entries aready configured), but, when I try to run the script, it tells me "Index generation failed"

my $ldap = Net::LDAP->new( '127.0.0.1' ) or die "$@";

my $mesg = $ldap->bind ('cn=admin, dc=ramal, dc=com',
                        password=>'<admin_password>'
                     );

#$mesg->code or die $mesg->error;

my $result = $ldap->add('uid=pruebaPerl, ou=User, dc=ramal, dc=com',
                        attrs=> [
                                'uid' => 'pruebaPerl',
                                'cn' => 'Usuario de prueba de Perl',
                                'objectclass' => ['account', 'posixAccount', 'shadowAccount'],
                                'userPassword' => '<hashed password>',
                                'loginShell' => '/bin/bash',
                                'uidNumber' => 2001,
                                'gidNumber' => 2001,
                                'homeDirectory' => '/home/pruebaPerl'
                        ]
                );

$result->code and warn "Failed to add entry: ", $result->error;

$mesg = $ldap->unbind

So, I think something's wrong in the arguments for add but I don't know what. Any help is welcomed.


Solution

  • Definitely an issue on the slapd side. Not a perl issue.

    This old thread https://www.openldap.org/lists/openldap-software/200407/msg00007.html suggests that maybe your test ldap structure got created wrong using slapadd instead of using ldapadd. Or you have a permission issue.

    Have you tried strace 'ing the slapd process ?

    Also try to remove the spaces in 'uid=pruebaPerl, ou=User, dc=ramal, dc=com' and 'cn=admin, dc=ramal, dc=com'