perl net::ldap problem using variable eg attr => [ $v1,$v2..]

J

Jadeja Tripal

Hi to all,


Some background about system.
perl perl, v5.6.1 (solaris 8)
perl-ldap-0.28

openldap 2.0.23-6.3 (debian)

The following works

---------

$addr = $ldap ->add(
dn => $dn,
attr => [ 'sn'=>$sn,

'givenName' => $givenName,
'cn' => $cn,
'mail' => $mail,
'o' => 'Comapany GmbH',
'c' => 'DE',
'preferredLanguage' => 'DE',
'gidNumber' => $gid,
'uid' => $uid,
'uidNumber' => $uidn,
'homeDirectory' => $home,
'userPassword' => $pw,
'objectClass' =>
['top','shadowAccount','posixAccount','person','inetOrgPerson']
]
);
--------------


Following fails with error

failed to add entry: 'c'=>: attribute description contains
inappropriate characters
--------

my $a_c = "\'c\' \=\> \'DE\'" ;
$addr = $ldap ->add (
dn => $dn,
attr => [ 'sn'=>$sn,


'givenName' => $givenName,
'cn' => $cn,
'mail' => $mail,
'o' => 'Comapany GmbH',
$a_c ,
#'c' => 'DE',
'preferredLanguage' => 'DE',
'gidNumber' => $gid,
'uid' => $uid,
'uidNumber' => $uidn,
'homeDirectory' => $home,
'userPassword' => $pw,
'objectClass' =>
['top','shadowAccount','posixAccount','person','inetOrgPerson']
]
);
-------------

I am stuck with this, please help.


Thanks in advance
tripal
 
P

Paul Lalli

Following fails with error
failed to add entry: 'c'=>: attribute description contains
inappropriate characters

This is one simple string.
$addr = $ldap ->add (
dn => $dn,
attr => [ 'sn'=>$sn,
'givenName' => $givenName,
this is a pair of scalars, two members of a list.
'cn' => $cn, so is this
'mail' => $mail, and this.
'o' => 'Comapany GmbH', etc.
$a_c ,
This is one simple string.

$a_c is a string. It is not a pair of values.
If for some odd reason you actually wanted to store this particular pair
of values in a variable, it should be in an array, not a scalar:

my @a_c = qw/c DE/;

You can then include @a_c inside your list.

By the way, why are you using what is traditionally hash syntax inside
an array reference? Your syntax makes it look like you're trying to
build a list of key/value pairs, but you're storing all these elements
inside an array reference. Are you sure that shouldn't be a hash
reference?

Paul Lalli

#'c' => 'DE',
'preferredLanguage' => 'DE',
'gidNumber' => $gid,
'uid' => $uid,
'uidNumber' => $uidn,
'homeDirectory' => $home,
'userPassword' => $pw,
'objectClass' =>
['top','shadowAccount','posixAccount','person','inetOrgPerson']
]
);
-------------

I am stuck with this, please help.


Thanks in advance
tripal
 
R

Richard Gration

Hi to all,
Some background about system.
perl perl, v5.6.1 (solaris 8)
perl-ldap-0.28
openldap 2.0.23-6.3 (debian)
The following works
---------

$addr = $ldap ->add(
dn => $dn,
attr => [ 'sn'=>$sn,

'givenName' => $givenName,
'cn' => $cn,
'mail' => $mail,
'o' => 'Comapany GmbH',
'c' => 'DE',

Here, 'c'=>'DE' is a pair of strings separated by a (fat) comma. The
first string is a single char, a lower case 'c', the second is a 2
character string, upper case 'DE'. The => operator is merely a comma
which automatically quotes barewords to its left.
'preferredLanguage' => 'DE',
'gidNumber' => $gid,
'uid' => $uid,
'uidNumber' => $uidn,
'homeDirectory' => $home,
'userPassword' => $pw,
'objectClass' =>
['top','shadowAccount','posixAccount','person','inetOrgPerson']
]
);
--------------
Following fails with error
failed to add entry: 'c'=>: attribute description contains
inappropriate characters
--------
my $a_c = "\'c\' \=\> \'DE\'" ;
$addr = $ldap ->add (
dn => $dn,
attr => [ 'sn'=>$sn,


'givenName' => $givenName,
'cn' => $cn,
'mail' => $mail,
'o' => 'Comapany GmbH',
$a_c ,

Here $a_c is a single string, "'c' => 'DE'". This is not decomposed into
2 strings because it has a fat comma (=>) inside it. The whole of this
string is taken to be a string in the attr arrayref. The error about
inappropriate characters is most likely bitching about the '=>', as it
mentions. Even if this were not the case, you would still have the
problem of having missed out a value string and this shuffling the later
strings so that keys become values and values become keys.

All this is because $a_c is a single string, regardless of its content,
and the construction here clearly needs 2 strings at this point.

You could achieve what you want by a variety of methods:

@a_c = (c=>'DE') then use @a_c in the attr def
%a_c = (c=>'DE') then use %a_c in the attr def
or even
$a_c = [c=>'DE'] then use @$a_c in the attr def
$a_c = {c=>'DE'} then use %$a_c in the attr def
#'c' => 'DE',
'preferredLanguage' => 'DE',
'gidNumber' => $gid,
'uid' => $uid,
'uidNumber' => $uidn,
'homeDirectory' => $home,
'userPassword' => $pw,
'objectClass' =>
['top','shadowAccount','posixAccount','person','inetOrgPerson']
]
);
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

By the way, why are you using what is traditionally hash syntax inside
an array reference? Your syntax makes it look like you're trying to
build a list of key/value pairs, but you're storing all these elements
inside an array reference. Are you sure that shouldn't be a hash
reference?

The Net::LDAP documentation calls for an arrayref. In rare cases
perhaps the order in which you add attributes to an LDAP entry is
important. Net::LDAP must be written to handle this syntax, since
I've used it to add entries and it's worked fine.

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBZA6uhVcNCxZ5ID8RAk+LAJ9YcghKIp2tUF5Xk/WqadtJyom3+gCgjxnh
yKJgkgI4vWYowxihlb+H9j8=
=J7pW
-----END PGP SIGNATURE-----
 
J

Jadeja Tripal

Many thanks to Paul, Richard, Keith,

It works now :). Error was exactly what you pointed out, thanks for
making basic fundamental clear to me.

tripal
 
B

Ben Morrow

Quoth Keith Keller said:
-----BEGIN PGP SIGNED MESSAGE-----

DON'T do that.
<...> Net::LDAP must be written to handle this syntax, since
I've used it to add entries and it's worked fine.

It's got nothing whatever to do with Net::LDAP. Look up => in perlop.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top