티스토리 뷰


http://www.linuxjournal.com/article/6988
간단한 LDAP server 작성하는 법이 나와 있다.

http://www.grotan.com/ldap/python-ldap-samples.html
LDAP 와 관련된 작업을 수행하는 간단한 예제 코드


http://pypi.python.org/pypi/python-ldap/
여기서 python-ldap(
OpenLDAP C API 를 wrap 한 api 라고 한다.) 를 설치하자.

http://www.python-ldap.org/docs.shtml
python-ldap 와 관련돼서, 그리고 LDAP 와 관련된 문서들을 찾을 수 있다.



간단하게 Authentication(login) 을 하는 program을 만들어 보자.
기본적으로 아래 링크를 참조하자.
http://www.grotan.com/ldap/python-ldap-samples.html#bind

authentication 을 위해서는 id에 해당하는 unique name을 알아야 한다.
그러기 위해서는 The LDAP information model을 알아야 한다.

LDAP information model
The LDAP information model 에 대한 설명은 아래 링크에서 찾자.
http://www.ietf.org/rfc/rfc1823.txt

간략하게 설명하면,LDAP information model 은 entry 의 tree 로 구성되어 있다.
그리고 이 entry 는 attributes 들로 구성되어 있다.
이 entry 의 attributes 들의 구성으로 unique name 을 갖게 되는 것이다.
말하자면 '영자'는 여러명이지만, 한국, 제주도의 이도동의 영자는 하나인 것처럼 말이다.

DN format
LDAP 에서는 distinguished name(DN) 의 format 으로
http://www.faqs.org/rfcs/rfc1779.html 를 사용하고 있다.

 Key     Attribute (X.520 keys)
------------------------------
CN CommonName
L LocalityName
ST StateOrProvinceName
O OrganizationName
OU OrganizationalUnitName
C CountryName
STREET StreetAddress

Table 1: Standardised Keywords

 
LDAP 관련 명령을 수행하는 법을 알아보자.
 
l = ldap.open(address)
먼저 LDAP server와 connection 을 열어야 한다.
 
l.simple_bind(username, password)
그리고 directory 에 권한을 얻는다. 즉 login을 한다고 보면된다. 이 권한획득이 되어야만 다른 일들이 가능하다.
ldap_result_id = l.search(baseDN, searchScope, searchFilter, retrieveAttributes)
로그인을 하는 방법은 여러가지가 있지만, simple_bind()는 특정 entry 의 userPassword attribute 만 비교해서 binding 하게 된다. 그리고 이 bind function 의 return 값을 통해 message id 를 반환해 준다.

result_type, result_data = l.result(ldap_result_id, 0)
그리고 이 반환된 message id 를 가지고 search 의 결과값을 가져오면 된다. 자세한 내용은 소스를 참조하자.
 
ldap_result() 는 이전에 실행한 operation 에 대한 결과값을 반환해 준다.
결과값이 어떤 type인지는 return 값으로 판단할 수 있다.
return 값은 아래와 같은 값들을 갖는다.
LDAP_RES_BIND = ldap.RES_BIND
LDAP_RES_SEARCH_ENTRY
LDAP_RES_SEARCH_RESULT
LDAP_RES_MODIFY
LDAP_RES_ADD
LDAP_RES_DELETE
LDAP_RES_MODRDN
LDAP_RES_COMPARE
여기서 LDAP_RES_SEARCH_ENTRY 와 LDAP_RES_SEARCH_RESULT 의 차이가 궁금해 지는데,
LDAP_RES_SEARCH_ENTRY 는 message 가 LDAP SearchResultDone message 라는 얘기고,
LDAP_RES_SEARCH_RESULT 는 message 가 LDAP SearchResultDone message 얘기다.

자세한 사항은 source 와 http://www.ietf.org/rfc/rfc1823.txt 를 참조하자.





댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함