Necdet Deniz Halıcıoğlu's Blog

Just another WordPress.com weblog

  • Categories

    • No categories

MY OPEN WORLD 2010 SESSION

Posted by Necdet Deniz Halıcıoğlu on September 30, 2010

Oracle Open World 2010 was my first Open World experience. It was fun to stay in a beautiful city like San Francisco and to attend Open World. You can find my prepaid churn model with oracle data mining presentation.

Posted in Uncategorized | Leave a Comment »

LDAP SEARCH

Posted by Necdet Deniz Halıcıoğlu on September 9, 2009

If we want to do LDAP query, we either need a LDAP tool or a LDAP module within our database. Oracle has already supplied the package DBMS_LDAP to communicate with Corporate Directory Server. I will give an example of how we can use DBMS_LDAP package to query Corporate Directory Server.

This package has a procedure which handles search operation within LDAP;

CREATE OR REPLACE PACKAGE PKG_LDAP_CHECK IS

PROCEDURE PRC_LDAP_CHECK;

END PKG_LDAP_CHECK;
/

CREATE OR REPLACE PACKAGE BODY PKG_LDAP_CHECK IS

PROCEDURE PRC_LDAP_CHECK AS
retval                       PLS_INTEGER;                                       — used for return values
my_session           dbms_ldap.session;                             — used for storing our ldap session
my_attrs                dbms_ldap.string_collection;         — String collection that returns
— from our ldap search
my_message         dbms_ldap.message;                          — used to store the message of the search
my_entry               dbms_ldap.message;                          — used to store the entries retrieved
— from ldap search
entry_index          PLS_INTEGER;                                      — controls the while loop for examining each entry
my_dn                     VARCHAR2(256);                                — will be used to get the dn for each entry
my_attr_name     VARCHAR2(256);                                — Each entry has attributes and this variable
— will be used to store the name of an attribute
my_ber_elmt        dbms_ldap.ber_element;
attr_index              PLS_INTEGER;                                      — controls the loop for examining each attribute.
my_vals                  dbms_ldap.string_collection;        — used to store the values of each attribute.
ldap_host               VARCHAR2(256);                                — The LDAP directory host
ldap_port               VARCHAR2(256);                                — The LDAP directory port
ldap_user               VARCHAR2(256);                                — The LDAP directory user
ldap_passwd         VARCHAR2(256);                                — The LDAP directory password
ldap_base               VARCHAR2(256);                                — The base DN
search_filter         VARCHAR2(256) := ‘status=1’;       — specify the criteria for our search
— ‘status = 1’ returns the entries
— which status attribute equals 1.
— ‘uid=*’ returns all entries for all users
— ‘objectclass=*’ returns all entries
my_timeout           DBMS_LDAP.TIMEVAL;                   — specifies the time out value that
— will be used in our search
BEGIN
retval := -1;
my_timeout.seconds  := 10000;      — time out values
my_timeout.useconds := 0;

— customize the following variables as needed
ldap_host   := ‘****’;
ldap_port   := ‘****’;
ldap_user   := ‘****’;
ldap_passwd := ‘****’;
ldap_base   := ‘****’;
— end of customizable settings

dbms_output.put_line(‘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;

— dbms_ldap.init() initializes a session with a server
my_session := dbms_ldap.init(ldap_host,
ldap_port);

dbms_output.put_line(rpad(‘LDAP session ‘,
25,
‘ ‘) || ‘: ‘ || rawtohex(substr(my_session,
1,
8)) ||
‘(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
— I want to retrieve these 4 attributes for each entry
my_attrs(1) := ‘uid’;
my_attrs(2) := ‘cn’;
my_attrs(3) := ‘ou’;
my_attrs(4) := ’employeenumber’;

— retrieve attributes
— The function search_st() performs a synchronous search in the ldap server
— with a client side time out.
— If you don’t want to specify a local time out, just use search().
retval := dbms_ldap.search_st(my_session,
ldap_base,
dbms_ldap.scope_subtree,
search_filter,
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,
8)) ||
‘(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

my_dn := dbms_ldap.get_dn(my_session,
my_entry);

my_attr_name := dbms_ldap.first_attribute(my_session,
my_entry,
my_ber_elmt);
attr_index   := 1;

— Loop through each of the attributes one by one
WHILE my_attr_name IS NOT NULL LOOP

— get all the values for this attribute
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(RPAD(‘   ‘ || my_attr_name, 19, ‘ ‘) ||
‘: ‘ || SUBSTR(my_vals(i), 1, 200)
);
END LOOP;

END IF;

— get next attribute
my_attr_name := dbms_ldap.next_attribute(my_session,
my_entry,
my_ber_elmt);

— increase the attribute index
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(‘=============================================’);

— increase the entry index
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’);
RAISE;

END PRC_LDAP_CHECK;

END PKG_LDAP_CHECK;
/

Posted in Uncategorized | 1 Comment »

Hello Blog World!

Posted by Necdet Deniz Halıcıoğlu on March 24, 2009

        It has been always so hard for me to start something new (As you can see, this is the only starting sentence I could find). People need to share things even if they don’t know why they want to share. Maybe because of  feeling good or believing that doing good things leads to good things in their lives. So, it’s my turn to share now.

        It sounds good but what am I going to share? I believe that everybody has enough experience about a specific topic in their life to share. This topic can vary person to person. Now, the question is “what is my profession” or “what is the thing that I can share”. The question has  an answer for me to write (maybe for years to decide what it is) and for you to find out, but please don’t say “Dude, you do not have any profession about anything” in 30 years.

        Generally, I am going to write about daily issues and technical issues as a  computer scientist.  I hope you guys are going to enjoy to read my blog. So, here we go…

Posted in Uncategorized | Leave a Comment »