Perlã§LDAPæ¤ç´¢ããããå ¨æ¤ç´¢
æ®éã«Net::LDAP㧠bind ããã¨é常ã«éããããã
20ä¸ä»¶ä»¥ä¸ã¨ã³ããªã¼ã®ããLDAPãå¼ãã¦ã¿ãã¨ãããOut Of Memory!! ãåºåããã¦ãã¾ã£ãã
ããã§ldapsearchããã¤ãã§Parseããäºã«ãããã§æç¶é«éåãå³ããã¤ã¡ã¢ãªä½¿ç¨éãè¥å¤§åããã«æ¸ãçã ã
ldapsearchããã¤ãã§Perlã«æ¸¡ã
./ldap_parse.sh
#!/bin/sh ldapsearch -x -LLL -h xxx.xxx.xxx.xxx -D "cn=admin,o=enecom,c=com" -w password -b c=com '(cn=*)' | ./ldap_parse.pl exit 0
./ldap_parse.pl
#!/usr/bin/perl use strict; use Net::LDAP::LDIF; my $ldif = Net::LDAP::LDIF->new(); while( not $ldif->eof() ) { my $entry = $ldif->read_entry(); if ( $ldif->error() ) { print "Error msg: ", $ldif->error(), "\n"; print "Error lines:\n", $ldif->error_lines(), "\n"; } else { # some code } } $ldif->done(); exit(0);
LDAPæ¥ç¶ã®æ®µéããPerlã§è¡ã
./ldap_get.pl
#!/usr/bin/perl use strict; use Net::LDAP; my $ldap_host = 'xxx.xxx.xxx.xxx'; my $bind_dn = 'cn=admin,o=example,c=com'; my $bind_pw = 'password'; my $base = 'c=com'; my $filter = '(cn=*)'; my $ldap = Net::LDAP->new( $ldap_host ) or die "$@ $!"; $ldap->bind( $bind_dn, password => $bind_pw ) or die "$@ $!"; my $mesg = $ldap->search( base => $base, filter => $filter ); $mesg->code and die $mesg->error; for my $entry ( $mesg->all_entries ) { # some code } $ldap->unbind; exit(0);