Author Topic: LDAP Problem  (Read 1752 times)

nontrivial

  • Zen Warrior
  • ***
  • Posts: 181
  • Karma: +16/-0
    • View Profile
LDAP Problem
« on: November 29, 2012, 10:26:36 pm »
I am trying to migrate a server from Zentyal 2.2 to 3.0. One of the issues is backups. I wrote a custom perl script that connected to the LDAP server, got a list of users, and then conditionally backed up their email by user based on the information I got out. I did a search and found that Zentyal no longer uses the default port, and I am past that problem. However, now that I can search, the search itself is failing. I am using the actual domain instead of "blahblah" indicated below. Even though I think it's a nice solution, I'm not set on using LDAP, so if there is a better way to get a list of users out of Zentyal from the command line I would be happy to use it. Here is a snippet from by script, and any help is appreciated.

use Net::LDAP;
    my $LDAP = Net::LDAP->new( 'localhost:390' ) or
      warn("Unable to connect to LDAP server: $@");
   
    my $Result = $LDAP->bind();
    if ($Result->code) {
      warn("Unable to bind to LDAP server: $Result->error");
    }
   
    $Result =$LDAP->search(base => "ou=Users,dc=blahblah,dc=com",
            attrs => ['uid','mail','description'],
            filter => "(objectClass=passwordHolder)");
    if ($Result->code) {
      warn("Unable to search to LDAP server: $Result->error");
    }
   
    foreach my $entry ($Result->entries) {
      my $UID = $entry->get_value('uid');
    }

mberglof

  • Zen Apprentice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: LDAP Problem
« Reply #1 on: March 12, 2013, 12:14:47 pm »
There are two handy ways of listing Zentyal (3.0) users from cli, zentyal shell or perl.

Shell:

Code: [Select]
bofh@zentyal:~/zentyal$ sudo /usr/share/zentyal/shell
zentyal> instance users
$users
zentyal> map { print $_->name() . "\n"; } @{$users->users()};

Or the same with more perl:

Code: [Select]
#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::Global;
use EBox::UsersAndGroups::User;

EBox::init();

my $users = EBox::Global->modInstance('users');

map { print $_->name() . "\n"; } @{$users->users()};


Have a look at EBox/UsersAndGroups/Users.pm for more info.