CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Net::LDAP Proxy addresses

 



unix8me
New User

Aug 4, 2017, 1:07 PM

Post #1 of 6 (2672 views)
Net::LDAP Proxy addresses Can't Post

I am trying to Add users with differing amounts of smtp aliases from a CSV file. I can't figure out how to allow for the differing amount. If I use $smtp[0-7] for the first address through the seventh. I get an error due to not all of them having 7 addresses. Is there a way to just use @Aliases to fix this?




Code
   $result = $ldap->add ("cn=$CN,ou=$OrgU,dc=quintecusa,dc=com", 
attr => [ 'cn' => ["$CN"],
'sn' => $Lastn,
'givenName' => $Firstn,
'userprincipalname' => $Emailaddr,
'proxyaddresses' => ["$smtp[0]","$smtp[1]"], ## This line is the issue!
'samaccountname' => $UserIdent,
'uid' => $UserIdent,
'mail' => $Emailaddr,
'objectclass' => [ 'top','person', 'organizationalPerson','user' ]
]


Laurent_R
Veteran / Moderator

Aug 5, 2017, 4:27 AM

Post #2 of 6 (2654 views)
Re: [unix8me] Net::LDAP Proxy addresses [In reply to] Can't Post

I don't know this module, but this:


Code
 $smtp[0-7]

is the wrong syntax for what you probably want. It should most probably be:

Code
@smtp[0..7]


This syntax:

Code
 $smtp[0-7]

tries to fetch the array element with subscript -7, i.e. seven places before the end of the array.

And, BTW, this would be an array with eight items, not seven.

If your array has less than eight addresses, you could probably use something like this:

Code
@smtp[0..$#smtp]


If you have "empty slots" (undefined elements) within your array, you might first need to remove these empty slots, for example using a grep command:

Code
@smtp = grep {defined $_} @smtp;



(This post was edited by Laurent_R on Aug 5, 2017, 4:33 AM)


unix8me
New User

Aug 5, 2017, 5:17 AM

Post #3 of 6 (2647 views)
Re: [Laurent_R] Net::LDAP Proxy addresses [In reply to] Can't Post

Laurent, thanks for your reply. I tried your snippet.

if I replace the proxy address line with:

'proxyaddresses' => @smtp[0..$#smtp],

or

'proxyaddresses' => @smtp,


I get the same error:

Use of uninitialized value $_[3] in concatenation (.) or string at /System/Library/Perl/Extras/5.18/Convert/ASN1/_encode.pm line 152, <$IN> line 1.
Result: Net::LDAP::Add=HASH(0x7fdd8b97a748)
failed to add entry: 00000057: LdapErr: DSID-0C090D87, comment: Error in attribute conversion operation, data 0, v23f0 at ./add_users.pl line 160, <$IN> line 1.

How ever if I know that an entry has two aliases I can use the below code fine, but since there are differing amounts of aliases this only works for two aliases..

'proxyaddresses' => ["$smtp[0]","$smtp[1]"],

Thanks in advance for any help.


FishMonger
Veteran / Moderator

Aug 5, 2017, 6:42 AM

Post #4 of 6 (2643 views)
Re: [unix8me] Net::LDAP Proxy addresses [In reply to] Can't Post

This is assigning a list.

Code
'proxyaddresses' => @smtp[0..$#smtp],


This is assigning an array.

Code
'proxyaddresses' => @smtp,


This is assigning a reference to an array due to the outer [ ] brackets. BTW, the quotes are not needed in this case.

Code
'proxyaddresses' => ["$smtp[0]","$smtp[1]"],


The value of a hash key can only be a single item; not a list or an array. The array ref is a single item.

Try this which assigns a reference to an array:

Code
'proxyaddresses' => \@smtp,



Laurent_R
Veteran / Moderator

Aug 5, 2017, 7:17 AM

Post #5 of 6 (2639 views)
Re: [unix8me] Net::LDAP Proxy addresses [In reply to] Can't Post

It this code line:

Code
'proxyaddresses' => ["$smtp[0]","$smtp[1]"],

works correctly, then it appears that you need to pass not an array, but an array reference (the outer square brackets are an array reference constructor).

Then you could just try this:


Code
'proxyaddresses' => \@smtp,


Update: oops, I had not seen FishMonger's answer when I wrote this. The good thing, though, is that we are suggesting the same solution. I hope it works.


(This post was edited by Laurent_R on Aug 5, 2017, 7:20 AM)


unix8me
New User

Aug 5, 2017, 7:43 AM

Post #6 of 6 (2634 views)
Re: [Laurent_R] Net::LDAP Proxy addresses [In reply to] Can't Post

Thanks Fishmonger and Laurent. That was it. I really appreciate the help.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives