Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Convert 10.3x LDAP database to UNIX passwd file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Convert 10.3x LDAP database to UNIX passwd file
Authored by: kholburn on Aug 03, '04 03:24:55AM
Here's a script I have used to dump a linux LDAP database to an /etc/password format. You have to have authorisation to access the data:

more ldapusers.sh
#!/bin/sh

#ldapsearch -x -v -D "uid=manager,o=mycompany.com" -w -b \
#"o=mycompany.com" '(objectclass=posixaccount)' \
#uid uidnumber gidnumber gecos homedirectory loginshell |\
#

ldapsearch -x -v \
  '(uidnumber=*)' \
  uid uidnumber gidnumber gecos homedirectory loginshell |\
  perl -e '
    $line = 0;
    while () {
      chomp;
      if (/^#/) { next; }
      if (/^$/) { $state=2; }
      elsif (/^uid/ && /,ou=People,/) { $state+=1; }
      else {
        if (/^uid: /i) { s/^uid: //i; $entry[0]=$_; }
        elsif (/^uidnumber: /i) { s/^uidnumber: //i; $entry[2]=$_; }
        elsif (/^gidnumber: /i) { s/^gidnumber: //i; $entry[3]=$_; }
        elsif (/^gecos: /i) { s/^gecos: //i; $entry[4]=$_; }
        elsif (/^homedirectory: /i) 
          { s/^homedirectory: //i; $entry[5]=$_; }
        elsif (/^loginshell: /i) { s/^loginshell: //i; $entry[6]=$_; }
      } 
      if ($state>1) {
        if (scalar @entry) {
          $entry[1]="x"; print join (":", @entry), "\n"; @entry=();
        }
        $state=0;
      }
    }
    if (scalar @entry) {
      $entry[1]="x"; print join (":", @entry), "\n"; @entry=();
    }
  '


[ Reply to This | # ]