Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Updating a binary value in Net::LDAP

by wardmw (Initiate)
on Dec 31, 2012 at 13:50 UTC ( #1011061=perlquestion: print w/ replies, xml ) Need Help??
wardmw has asked for the wisdom of the Perl Monks concerning the following question:

Good day all,

I have been banging my head on this problem for some time now, have searched the Internet for solutions but I can find nothing so I turn to you, who know all (well, most) concerning Perl.

I have a list of IP addresses, @mynets, and I want to store them in an LDAP database using the Net::LDAP module. The attribute that this list will be stored in is a binary one as the contents of the attribute are downloaded to a flat file by a different tool.

How do I add/update a binary value with the contents of a list using Net::LDAP? I have tried:

$result = $ldap->add( "cn=mynetworks,$ldapFileDN", attrs => [ 'fileStore' => [ @mynets ], 'homeDirectory' => '/etc/postfix' ] );
but it fails as it thinks I am trying to add multiple values to 'filestore'.

Any ideas or suggestions as to other ways to do it?

|\/|

Comment on Updating a binary value in Net::LDAP
Select or Download Code
Re: Updating a binary value in Net::LDAP
by NetWallah (Abbot) on Dec 31, 2012 at 16:06 UTC
    If we call it an "octet string", instead of "binary", a concatenated octet string can be generated and stored like this (untested):
    use Socket qw( inet_aton ); ... fileStore => join ('', map {inet_aton $_} @mynets),
    This will be a concatenated string of 32-bit binary IP addresses (assuming IPv4), and can be written to a file.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

      Many thanks NetWallah,

      Looking at my original post I neglected to point out that the output sound have been a list of IP addresses with the text " OK" appended to each entry so the inet_aton() function was not going to work. However your suggestion to use the map() function was exactly what I needed and with your guidance the code below does what I need:

      fileStore => join ('', map {$_ .= "\tok\n" } @mynets),
      Just what I needed, thank you for your speedy response.

      |\/|

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1011061]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2015-07-06 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls