Hi,
I looked at Billy's code, at https://kr.forums.oracle.com/forums/thread.jspa?threadID=2246994 and i wanted to try that code.
I have a problem in establishing a connection with the LDAP server. Here is the code used:
declare
LDAP_SERVER constant varchar2(200) := 'ldap://romtelecom.ro';
LDAP_PORT constant number := 6658;
LDAP_USER constant varchar2(200) := 'an_ad_user';
LDAP_PASSW constant varchar2(200) := 'ad_users_password';
LDAP_BASE constant varchar2(200) := 'dc=romtelecom,dc=ro';
rc integer;
ldapSession DBMS_LDAP.session;
ntUser varchar2(30);
attrName varchar2(255);
attrList DBMS_LDAP.string_collection;
valList DBMS_LDAP.string_collection;
ldapMessage DBMS_LDAP.message;
ldapEntry DBMS_LDAP.message;
berElem DBMS_LDAP.ber_element;
--// very primitive assertion interface - should be catering
--// for unique error code and messages in a prod environment
procedure assert( condition boolean ) is
begin
if not condition then
raise_application_error(
-20001,
'LDAP call unsuccessful.'
);
end if;
end;
procedure W( line varchar2 ) is
begin
DBMS_OUTPUT.put_line( line );
end;
begin
--// logon to the Microsoft Active Directory Server
DBMS_LDAP.USE_EXCEPTION := false;
W( 'Logging on to AD server;' );
ldapSession := DBMS_LDAP.init( LDAP_SERVER, LDAP_PORT );
rc := DBMS_LDAP.simple_bind_s(
ld => ldapSession,
dn => LDAP_USER,
passwd => LDAP_PASSW
);
assert( rc = DBMS_LDAP_UTL.SUCCESS );
/*
--// set the NTLM user and attributes that we want
ntUser := 'an_ad_user;
attrList(1) := 'givenName';
attrList(2) := 'mail';
attrList(3) := 'mobile';
attrList(4) := 'telephoneNumber';
attrList(5) := 'manager';
--// so a search on the username (NTLM username typically)
W( 'Doing a basic search on NT username' );
rc := DBMS_LDAP.search_s(
ld => ldapSession,
base => LDAP_BASE,
scope => DBMS_LDAP.SCOPE_SUBTREE,
filter => '(&(objectclass=USER)(SAMAccountName='||ntUser||'))',
attrs => attrList,
attronly => 0,
res => ldapMessage
);
assert( rc = DBMS_LDAP_UTL.SUCCESS );
if DBMS_LDAP.count_entries(ldapSession,ldapMessage) > 0 then
W( '1st entry - only 1 expected as we did a unique account lookup' );
ldapEntry := DBMS_LDAP.first_entry( ldapSession, ldapMessage );
while (ldapEntry is not null) loop
--// get the attribute
attrName := DBMS_LDAP.first_attribute(
ld => ldapSession,
ldapEntry => ldapEntry,
ber_elem => berElem
);
while (attrName is not null) loop
--// get the list of values for the attribute
valList := DBMS_LDAP.get_values(
ld => ldapSession,
ldapEntry => ldapEntry,
attr => attrName
);
--// for simplicity sake, we expect a scalar name-value and
--// thus a single value only
W( attrName||'='||valList(0) );
--// proceed to process the next attribute
attrName := DBMS_LDAP.next_attribute(
ld => ldapSession,
ldapEntry => ldapEntry,
ber_elem => berElem
);
end loop;
--// not really needed in this case as we're processing a single SAMaccount entry
ldapEntry := DBMS_LDAP.next_entry( ldapSession, ldapEntry );
end loop;
end if;
W( 'Disconnecting from AD server' );
rc := DBMS_LDAP.unbind_s( ld => ldapSession );*/
end;
(i've commented the rest of the code, i'm just looking first for a successful connection).
The error thrown is
ORA-20001: LDAP call unsuccessful.
ORA-06512: at line 24
ORA-06512: at line 46 ,
at this line: assert( rc = DBMS_LDAP_UTL.SUCCESS );
What could be the problem? The ldap server and port is ldap://romtelecom.ro:6658, ldap domain is romtelecom.ro, and search base is dc=romtelecom, dc=ro.
Please help.
Thanks in advance
Edited by: Roger25 on 25.02.2013 14:28