From: Yann R. <at...@at...> - 2000-08-26 19:34:08
|
Hi, Using the following code snippet under Net::LDAP 0.19 worked fine, but once I went to 0.20, it broke, and is now returning an array??? Is there something wrong with my code? $ref is the DN, and $field is usualy 'cn' or 'uidnumber', both of which exist. sub get_user_var { my ($self, $ref, $field) = @_; my $mesg = $self->{LDAP}->search ( base => $ref, filter => "(objectclass=*)" ); my @entries = $mesg->entries; if (!@entries) { return; } my $entr = $entries[0]; my @entry = $entr->get($field); my $e = $entry[0]; return $e; } -- -------------------------------------------------------------------- Yann Ramin at...@at... Atrus Trivalie Productions www.redshift.com/~yramin Monterey High IT www.montereyhigh.com ICQ 46805627 AIM oddatrus Marina, CA IRM Developer Network Toaster Developer SNTS Developer KLevel Developer (yes, this .signature is way too big) "All cats die. Socrates is dead. Therefore Socrates is a cat." - The Logician THE STORY OF CREATION In the beginning there was data. The data was without form and null, and darkness was upon the face of the console; and the Spirit of IBM was moving over the face of the market. And DEC said, "Let there be registers"; and there were registers. And DEC saw that they carried; and DEC seperated the data from the instructions. DEC called the data Stack, and the instructions they called Code. And there was evening and there was a maorning, one interrupt... -- Rico Tudor William Safire's Rules for Writers: Remembe |
From: Graham B. <gb...@po...> - 2000-08-29 08:01:49
|
On Sat, Aug 26, 2000 at 12:33:32PM -0700, Yann Ramin wrote: > Hi, > > Using the following code snippet under Net::LDAP 0.19 worked fine, but > once I went to 0.20, it broke, and is now returning an array??? Is there > something wrong with my code? In 0.20 ->get was changed to match it's documentation. However it seems that what get now returns is not what is "expected" In the version in CVS, and what will be in 0.21, ->get has been returned to it's previous implementation, but has also been depricated. ->get has been replaced by ->get_value which is described below. I would appriciate any feedback on this. Graham. =item get_value ( ATTR [, OPTIONS ] ) Get the values for the attribute ATTR. In a list context returns all values for the given attribute, or the empty list if the attribute does not exist. In a scalar context returns the first value for the attribute or undef if the attribute does not exist. The return value may be changed by OPTIONS, which is a list of name => value pairs, valid options are :- =over 4 =item alloptions If TRUE then the result will be a hash reference. The keys of the hash will be the options and the hash value will be the values for those attributes. For example if an entry had name: Graham Barr name;en-us: Bob Then a get for attribute "name" with alloptions set would return { '' => [ 'Graham Barr' ], ';en-us' => [ 'Bob' ] } =item asref If TRUE then the result will be a reference to an array containing all the values for the attribute, or undef if the attribute does not exist. =back B<NOTE>: In the interest of performance the array references returned by C<get_value> are references to structures held inside the entry object. These values and thier contents should B<NOT> be modified directly. > $ref is the DN, and $field is usualy 'cn' or 'uidnumber', both of which > exist. > > sub get_user_var { > my ($self, $ref, $field) = @_; > > my $mesg = $self->{LDAP}->search ( > base => $ref, > filter => "(objectclass=*)" > ); > > my @entries = $mesg->entries; > if (!@entries) { return; } > my $entr = $entries[0]; > my @entry = $entr->get($field); > my $e = $entry[0]; > return $e; > > } |
From: Jim H. <ha...@us...> - 2000-08-29 13:49:47
|
Graham, I applaud your trying to make get or a rename of it function more as expected by an inexperienced person. As much as I dislike using longis names when short ones are great, I think the approach of deprecating "get" is correct. Note that you used "get" instead of get_value twice in the doc below, though. Once in Then a get for attribute "name" with alloptions set would return and again in my @entry = $entr->get($field); --Jim On Tue, 29 Aug 2000, Graham Barr wrote: > On Sat, Aug 26, 2000 at 12:33:32PM -0700, Yann Ramin wrote: > > Hi, > > > > Using the following code snippet under Net::LDAP 0.19 worked fine, but > > once I went to 0.20, it broke, and is now returning an array??? Is there > > something wrong with my code? > > In 0.20 ->get was changed to match it's documentation. However it > seems that what get now returns is not what is "expected" > > In the version in CVS, and what will be in 0.21, ->get has been > returned to it's previous implementation, but has also been > depricated. > > ->get has been replaced by ->get_value which is described below. > > I would appriciate any feedback on this. > > Graham. > > > =item get_value ( ATTR [, OPTIONS ] ) > > Get the values for the attribute ATTR. In a list context returns all > values for the given attribute, or the empty list if the attribute does > not exist. In a scalar context returns the first value for the attribute > or undef if the attribute does not exist. > > The return value may be changed by OPTIONS, which is a list of name => value > pairs, valid options are :- > > =over 4 > > =item alloptions > > If TRUE then the result will be a hash reference. The keys of the hash > will be the options and the hash value will be the values for those attributes. > For example if an entry had > > name: Graham Barr > name;en-us: Bob > > Then a get for attribute "name" with alloptions set would return > > { > '' => [ 'Graham Barr' ], > ';en-us' => [ 'Bob' ] > } > > =item asref > > If TRUE then the result will be a reference to an array containing all the > values for the attribute, or undef if the attribute does not exist. > > =back > > B<NOTE>: In the interest of performance the array references returned by C<get_value> > are references to structures held inside the entry object. These values and > thier contents should B<NOT> be modified directly. > > > $ref is the DN, and $field is usualy 'cn' or 'uidnumber', both of which > > exist. > > > > sub get_user_var { > > my ($self, $ref, $field) = @_; > > > > my $mesg = $self->{LDAP}->search ( > > base => $ref, > > filter => "(objectclass=*)" > > ); > > > > my @entries = $mesg->entries; > > if (!@entries) { return; } > > my $entr = $entries[0]; > > my @entry = $entr->get($field); > > my $e = $entry[0]; > > return $e; > > > > } > |
From: Graham B. <gb...@po...> - 2000-08-29 14:29:32
|
On Tue, Aug 29, 2000 at 09:48:56AM -0400, Jim Harle wrote: > Graham, > I applaud your trying to make get or a rename of it function more as > expected by an inexperienced person. As much as I dislike using longis > names when short ones are great, I think the approach of deprecating "get" > is correct. I also dislike longish names. Maybe when nobody is using ->get we can have it as an alias for get_value :) > Note that you used "get" instead of get_value twice in the > doc below, though. Once in > Then a get for attribute "name" with alloptions set would return > and again in Thanks. > my @entry = $entr->get($field); That was an extract of code from the original mail. Thanks, Graham. > On Tue, 29 Aug 2000, Graham Barr wrote: > > > On Sat, Aug 26, 2000 at 12:33:32PM -0700, Yann Ramin wrote: > > > Hi, > > > > > > Using the following code snippet under Net::LDAP 0.19 worked fine, but > > > once I went to 0.20, it broke, and is now returning an array??? Is there > > > something wrong with my code? > > > > In 0.20 ->get was changed to match it's documentation. However it > > seems that what get now returns is not what is "expected" > > > > In the version in CVS, and what will be in 0.21, ->get has been > > returned to it's previous implementation, but has also been > > depricated. > > > > ->get has been replaced by ->get_value which is described below. > > > > I would appriciate any feedback on this. > > > > Graham. > > > > > > =item get_value ( ATTR [, OPTIONS ] ) > > > > Get the values for the attribute ATTR. In a list context returns all > > values for the given attribute, or the empty list if the attribute does > > not exist. In a scalar context returns the first value for the attribute > > or undef if the attribute does not exist. > > > > The return value may be changed by OPTIONS, which is a list of name => value > > pairs, valid options are :- > > > > =over 4 > > > > =item alloptions > > > > If TRUE then the result will be a hash reference. The keys of the hash > > will be the options and the hash value will be the values for those attributes. > > For example if an entry had > > > > name: Graham Barr > > name;en-us: Bob > > > > Then a get for attribute "name" with alloptions set would return > > > > { > > '' => [ 'Graham Barr' ], > > ';en-us' => [ 'Bob' ] > > } > > > > =item asref > > > > If TRUE then the result will be a reference to an array containing all the > > values for the attribute, or undef if the attribute does not exist. > > > > =back > > > > B<NOTE>: In the interest of performance the array references returned by C<get_value> > > are references to structures held inside the entry object. These values and > > thier contents should B<NOT> be modified directly. > > > > > $ref is the DN, and $field is usualy 'cn' or 'uidnumber', both of which > > > exist. > > > > > > sub get_user_var { > > > my ($self, $ref, $field) = @_; > > > > > > my $mesg = $self->{LDAP}->search ( > > > base => $ref, > > > filter => "(objectclass=*)" > > > ); > > > > > > my @entries = $mesg->entries; > > > if (!@entries) { return; } > > > my $entr = $entries[0]; > > > my @entry = $entr->get($field); > > > my $e = $entry[0]; > > > return $e; > > > > > > } > > > > > |
From: Jie G. <J....@is...> - 2000-08-29 23:10:47
|
Hi All, I have been trying to use Net::LDAP within mod_perl, and have encountered the following: 1. Getting a message upon starting Apache: Constant subroutine cTAG redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine cTYPE redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine cVAR redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine cLOOP redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine cOPT redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine cCHILD redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opUNKNOWN redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opBOOLEAN redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opINTEGER redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opBITSTR redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opSTRING redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opNULL redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opOBJID redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opREAL redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opSEQUENCE redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opSET redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opUTIME redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opGTIME redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opUTF8 redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opANY redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. Constant subroutine opCHOICE redefined at /usr/local/lib/perl5/site_perl/5.005/Convert/ASN1.pm line 47. I know this is only used by Net::LDAP on this server. What was it that caused this? 2. Getting wrong returned results intermittently, or with a pattern (every a few clicks). Debugging shows that password is to sent every time: Here's the debugging output of a "bad" access: --------------------------------------------------------------------------- Net::LDAP=HASH(0x982aa4) sending: 30 3E 02 01 04 60 39 02 01 02 04 32 6C 6F 67 69 0>...`9....2logi 6E 6E 61 6D 65 3D 68 61 6E 64 79 6D 61 6E 2C 6F nname=handyman,o 75 3D 70 65 6F 70 6C 65 2C 64 63 3D 75 63 63 2C u=people,dc=ucc, 64 63 3D 75 73 79 64 2E 65 64 75 2E 61 75 80 00 dc=usyd.edu.au.. 0000 30 62: SEQUENCE { 0002 02 1: INTEGER = 4 0005 60 57: [APPLICATION 0] { 0007 02 1: INTEGER = 2 000A 04 50: STRING = 'loginname=handyman,ou=people,dc=ucc,dc=usyd.edu.au' 003E 80 0: [CONTEXT 0] 0040 : } 0040 : } Net::LDAP=HASH(0x982aa4) received: 30 0C 02 01 04 61 07 0A 01 00 04 00 04 00 __ __ 0....a........ 0000 30 12: SEQUENCE { 0002 02 1: INTEGER = 4 0005 61 7: [APPLICATION 1] { 0007 0A 1: ENUM = 0 000A 04 0: STRING = '' 000C 04 0: STRING = '' 000E : } 000E : } Net::LDAP=HASH(0x982aa4) sending: 30 53 02 01 05 6E 4E 04 30 6C 6F 67 69 6E 6E 61 0S...nN.0loginna 6D 65 3D 6A 69 65 67 61 6F 2C 6F 75 3D 70 65 6F me=jiegao,ou=peo 70 6C 65 2C 64 63 3D 75 63 63 2C 64 63 3D 75 73 ple,dc=ucc,dc=us 79 64 2E 65 64 75 2E 61 75 30 1A 04 07 63 6F 75 yd.edu.au0...cou 72 73 65 73 04 0F 32 30 30 30 3A 70 63 6F 6C 32 rses..2000:pcol2 30 30 31 3A 31 __ __ __ __ __ __ __ __ __ __ __ 001:1 0000 30 83: SEQUENCE { 0002 02 1: INTEGER = 5 0005 6E 78: [APPLICATION 14] { 0007 04 48: STRING = 'loginname=jiegao,ou=people,dc=ucc,dc=usyd.edu.au' 0039 30 26: SEQUENCE { 003B 04 7: STRING = 'courses' 0044 04 15: STRING = '2000:pcol2001:1' 0055 : } 0055 : } 0055 : } Net::LDAP=HASH(0x982aa4) received: 30 0C 02 01 05 6F 07 0A 01 32 04 00 04 00 __ __ 0....o...2.... 0000 30 12: SEQUENCE { 0002 02 1: INTEGER = 5 0005 6F 7: [APPLICATION 15] { 0007 0A 1: ENUM = 50 000A 04 0: STRING = '' 000C 04 0: STRING = '' 000E : } 000E : } status: The client does not have sufficient access to perform the requested operation --------------------------------------------------------------------------- With a "good" access, I would see the password there, and the compare operation would return ENUM = 6. Here's the subroutine that I use in a mod_perl handler: --------------------------------------------------------------------------- sub get_crs_enrol_status ($$$) { my ($self, $r, @crs_allowed) = @_; my $status = ''; my $debug = $r->dir_config("AuthCookieDebug") || 0; my $user = $r->connection->user; #$user = 'jcho1625'; my $ldap = Net::LDAP->new('directory.usyd.edu.au', debug => 255) or die "$@"; my $mesg = $ldap->bind( dn => 'loginname=handyman,ou=people,dc=ucc,dc=usyd.edu.au', password => 'test' ); #warn ldap_error_text($mesg->code) if $mesg->code; my $dn = "loginname=$user,ou=people,dc=ucc,dc=usyd.edu.au"; foreach my $i (@crs_allowed) { my $mesg_inner = $ldap->compare ( $dn, attr => 'courses', value => "$i" ); $status = ldap_error_text($mesg_inner->code) if $mesg_inner->code; if (defined $status && $status =~ /given is in/i) { print STDERR "status: $status\n"; $status = 'Yes'; print STDERR "$user is enrolled in $i\n" if $debug; last; } elsif (defined $status && $status =~ /not/) { print STDERR "status: $status\n"; $status = ''; print STDERR "$user is NOT enrolled in $i\n" if $debug; } } $mesg = $ldap->unbind; #warn ldap_error_text($mesg->code) if $mesg->code; if (defined $status && $status) { $status = ''; return 'Yes'; } else { return 'No'; } } --------------------------------------------------------------------------- I can't see anything wrong here, and there doesn't seem to be a closure problem in particular. Any help is appreciated. Jie |