niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle
PL/SQL accessing LDAP server
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
M Rothwell
*nix forums beginner


Joined: 09 May 2005
Posts: 4

PostPosted: Thu Feb 17, 2005 6:05 pm    Post subject: Re: PL/SQL accessing LDAP server Reply with quote

Mark Bole wrote:
Quote:

It's been a while since I've used this, but is it possible your
ldap_base isn't quite right? It would be easy to test without the
"cn=Users" piece.

-Mark Bole

I had tried that a couple times, but apparently with some other things
wrong. I finally came up with a combination that works.

Thanks.

I now have:

ldap_base := 'ou=People,o=mycomp.com';
....
retval := DBMS_LDAP.search_st( my_session, ldap_base,
DBMS_LDAP.SCOPE_SUBTREE,
'employeeNumber=00123456',
my_attrs,
0,
my_timeout,
my_message );
Back to top
Mark Bole
*nix forums Guru Wannabe


Joined: 29 Apr 2005
Posts: 188

PostPosted: Thu Feb 17, 2005 4:05 pm    Post subject: Re: PL/SQL accessing LDAP server Reply with quote

M Rothwell wrote:
Quote:
I am trying to get information from an LDAP server using the DBMS_LDAP
package. I got the following code from the sample directory that came
with the Oracle dist.

I have the correct LDAP server and port. I can init and bind, but when
I get to the search_st procedure it errors out with the following message:

Error Message : ORA-31202: DBMS_LDAP: LDAP client/server error: No such
object

I'm using Oracle 9i R2 on HP-UX.

I have tried different filters and scopes, but still get the same error.
Any help would be much appreciated.
[...]
ldap_base := 'cn=Users,o=mycomp,dc=com';
-- end of customizable settings
[...]


It's been a while since I've used this, but is it possible your
ldap_base isn't quite right? It would be easy to test without the
"cn=Users" piece.

-Mark Bole
Back to top
M Rothwell
*nix forums beginner


Joined: 09 May 2005
Posts: 4

PostPosted: Wed Feb 16, 2005 11:06 pm    Post subject: PL/SQL accessing LDAP server Reply with quote

I am trying to get information from an LDAP server using the DBMS_LDAP
package. I got the following code from the sample directory that came
with the Oracle dist.

I have the correct LDAP server and port. I can init and bind, but when
I get to the search_st procedure it errors out with the following message:

Error Message : ORA-31202: DBMS_LDAP: LDAP client/server error: No such
object

I'm using Oracle 9i R2 on HP-UX.

I have tried different filters and scopes, but still get the same error.
Any help would be much appreciated.



DECLARE
retval PLS_INTEGER;
my_session DBMS_LDAP.session;
my_attrs DBMS_LDAP.string_collection;
my_timeout DBMS_LDAP.timeval;
my_message DBMS_LDAP.message;
my_entry DBMS_LDAP.message;
entry_index PLS_INTEGER;
my_dn VARCHAR2(256);
my_attr_name VARCHAR2(256);
my_ber_elmt DBMS_LDAP.ber_element;
attr_index PLS_INTEGER;
i PLS_INTEGER;
my_vals DBMS_LDAP.STRING_COLLECTION ;
ldap_host VARCHAR2(256);
ldap_port VARCHAR2(256);
ldap_user VARCHAR2(256);
ldap_passwd VARCHAR2(256);
ldap_base VARCHAR2(256);
BEGIN
retval := -1;

-- Please customize the following variables as needed
ldap_host := 'ldap.mycomp.com';
ldap_port := '389';
ldap_user := null;
ldap_passwd:= null;
ldap_base := 'cn=Users,o=mycomp,dc=com';
-- end of customizable settings

DBMS_OUTPUT.PUT('DBMS_LDAP Search Example ');
DBMS_OUTPUT.PUT_LINE('to directory .. ');
DBMS_OUTPUT.PUT_LINE(RPAD('LDAP Host ',25,' ') || ': ' || ldap_host);
DBMS_OUTPUT.PUT_LINE(RPAD('LDAP Port ',25,' ') || ': ' || ldap_port);

-- Choosing exceptions to be raised by DBMS_LDAP library.
DBMS_LDAP.USE_EXCEPTION := TRUE;


my_session := DBMS_LDAP.init(ldap_host,ldap_port);

DBMS_OUTPUT.PUT_LINE (RPAD('Ldap session ',25,' ') || ': ' ||
RAWTOHEX(SUBSTR(my_session,1,Cool) ||
'(returned from init)');

-- bind to the directory
retval := DBMS_LDAP.simple_bind_s(my_session, ldap_user, ldap_passwd);

DBMS_OUTPUT.PUT_LINE(RPAD('simple_bind_s Returns ',25,' ') || ': '
|| TO_CHAR(retval));

-- issue the search
my_attrs(1) := '*'; -- retrieve all attributes
my_timeout.seconds := 10;
my_timeout.useconds := 0;
retval := DBMS_LDAP.search_st( my_session, ldap_base,
DBMS_LDAP.SCOPE_SUBTREE,
'employeeNumber=544032',
my_attrs,
0,
my_timeout,
my_message );

DBMS_OUTPUT.PUT_LINE(RPAD('search_s Returns ',25,' ') || ': '
|| TO_CHAR(retval));
DBMS_OUTPUT.PUT_LINE (RPAD('LDAP message ',25,' ') || ': ' ||
RAWTOHEX(SUBSTR(my_message,1,Cool) ||
'(returned from search_s)');

-- count the number of entries returned
retval := DBMS_LDAP.count_entries(my_session, my_message);
DBMS_OUTPUT.PUT_LINE(RPAD('Number of Entries ',25,' ') || ': '
|| TO_CHAR(retval));

DBMS_OUTPUT.PUT_LINE('---------------------------------------------------');


-- get the first entry
my_entry := DBMS_LDAP.first_entry(my_session, my_message);
entry_index := 1;

-- Loop through each of the entries one by one
while my_entry IS NOT NULL loop
-- print the current entry
my_dn := DBMS_LDAP.get_dn(my_session, my_entry);
-- DBMS_OUTPUT.PUT_LINE (' entry #' || TO_CHAR(entry_index) ||
-- ' entry ptr: ' || RAWTOHEX(SUBSTR(my_entry,1,Cool));
DBMS_OUTPUT.PUT_LINE (' dn: ' || my_dn);
my_attr_name := DBMS_LDAP.first_attribute(my_session,my_entry,
my_ber_elmt);
attr_index := 1;
while my_attr_name IS NOT NULL loop
my_vals := DBMS_LDAP.get_values (my_session, my_entry,
my_attr_name);
if my_vals.COUNT > 0 then
FOR i in my_vals.FIRST..my_vals.LAST loop
DBMS_OUTPUT.PUT_LINE(' ' || my_attr_name || ' : ' ||
SUBSTR(my_vals(i),1,200));
end loop;
end if;
my_attr_name := DBMS_LDAP.next_attribute(my_session,my_entry,
my_ber_elmt);
attr_index := attr_index+1;
end loop;
-- Free ber_element
DBMS_LDAP.ber_free(my_ber_elmt, 0);
my_entry := DBMS_LDAP.next_entry(my_session, my_entry);

DBMS_OUTPUT.PUT_LINE('===================================================');
entry_index := entry_index+1;
end loop;

-- free LDAP Message
retval := DBMS_LDAP.msgfree(my_message);

-- unbind from the directory
retval := DBMS_LDAP.unbind_s(my_session);
DBMS_OUTPUT.PUT_LINE(RPAD('unbind_res Returns ',25,' ') || ': ' ||
TO_CHAR(retval));

DBMS_OUTPUT.PUT_LINE('Directory operation Successful .. exiting');

-- Handle Exceptions
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(' Error code : ' || TO_CHAR(SQLCODE));
DBMS_OUTPUT.PUT_LINE(' Error Message : ' || SQLERRM);
DBMS_OUTPUT.PUT_LINE(' Exception encountered .. exiting');
retval := DBMS_LDAP.unbind_s(my_session);
DBMS_OUTPUT.PUT_LINE(RPAD('unbind_res Returns ',25,' ') || ': ' ||
TO_CHAR(retval));
END;
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 2:55 am | All times are GMT
navigation Forum index » Databases » Oracle
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Postfix, VDA, Dovecote, LDAP, Phamm... Ville Walveranta Postfix 0 Sun Jul 20, 2008 4:23 am
No new posts Transfer qmail email account to postfix server tallman Postfix 0 Thu Jun 05, 2008 12:43 pm
No new posts Postfix ldap and Rewriting sender email address endfx Postfix 2 Thu Apr 17, 2008 9:34 pm
No new posts NFS server on Solaris 10 gurgle Solaris 0 Tue Sep 04, 2007 7:05 pm
No new posts Help required for configuring the VPN Server in Linux SHERDIL security 0 Sun Nov 19, 2006 2:22 pm

Personal Car Finance | Credit Card | Magazine Subscriptions | Hacker | Budapest hotels
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3240s ][ Queries: 20 (0.1546s) ][ GZIP on - Debug on ]