Open Ldap 에서 query 하기..
글쓴이: litdream / 작성시간: 금, 2004/09/17 - 2:49오전
안녕하세요.
LDAP 라이브러리는 처음 써보는데, 갑작스레 간단히 로그인 정보를 확인하는 프로그램을 짜게 되었습니다.
리눅스에서 OpenLdap 을 써서 하려는데, 지금 테스트 코드에서도 헤메고 있습니다.
retreive 부분에서 성공을 하지 못하고 있습니다.
서버는 LDAPS(636) 으로만 통신을 하고 있습니다. 389는 timeout..
일반적으로 ldapsearch -x -h hostname -b "dn=....." 으로 하면 결과가 돌아옵니다만,
이것과 똑같은 테스트 코드를 만들어서 쿼리를 날리는데 retreive 에서 실패를 합니다.
#include <stdio.h>
#include <sys/time.h>
#include <ldap.h>
int main()
{
LDAP *session;
//LDAPMessage **chain;
LDAPMessage *chain[1000];
int result, err;
int count;
const char *base = "dc=people,dc=ldap,dc=umd,dc=edu";
char filter[] = "uid=106364747";
struct timeval timeout = {10,0};
if ( (session = ldap_init("ldaptest.umd.edu", LDAPS_PORT)) == NULL ) {
//if ( (session = ldap_init("ldaptest.umd.edu", LDAP_PORT)) == NULL ) {
fprintf(stderr, "ldap open fail.\n");
exit(1);
}
printf ("ldap open success.\n");
// Bind
if ( (err=ldap_simple_bind(session, "", "")) == -1 ) {
fprintf(stderr, "ldap bind fail.\n");
exit(1);
}
printf ("ldap bind success. Rtncode = %d\n",err);
// first query
if ( (err = ldap_search(session, base, LDAP_SCOPE_SUBTREE, \
filter , NULL, 0)) < 0) {
fprintf(stderr, "ldap query fail. Errcode=%d\n",err);
exit(1);
}
// retreive -- 여기가 문제!
if ( (err=ldap_result(session, 0, 1, &timeout, chain)) < 0) {
fprintf(stderr, "ldap retreive fail. Errcode=%d\n",err);
exit(1);
}
// Success
printf ("ldap retreive success. \n");
// Count
result = ldap_count_messages(session, chain[0]);
printf ("Num result: %d\n", result);
ldap_unbind(session);
return 0;
}
쿼리 보낼때, ldap_search_ext 가 쓰여져야 할테지만, 테스트용으로 일단 간단하게
ldap_search (depricated 되었답니다만..) 를 썼는데, 이것이 문제인지..
아니면 아예 커넥션부분이 SSL 인데 아무생각없이 포트번호만 잡아줘서 그런지...
혹시 open ldap 에 대해 잘 아시는분 부탁드립니다.
그럼 이만.. 꾸뻑.
Forums:


거의 5개월만에 자답합니다.[code:1] // retreiv
거의 5개월만에 자답합니다.
// retreive -- 여기가 문제! if ( (err=ldap_result(session, 0, 1, &timeout, chain)) < 0) { fprintf(stderr, "ldap retreive fail. Errcode=%d\n",err); exit(1); }저기서 ldap_result() 구분을 다음과 같이 바꾸면, 일단 성공하더군요.
if ( (err=ldap_result(session, LDAP_RES_ANY, 1, &timeout, chain)) < 0) {물론, bind 할때 credential 을 정확히 잡아주어야 하고요.
저희 팀장이 이 프로젝을 끝내라는 압력이 지금 대단합니다.. 흑흑..
LDAP/SSL 을 사용한 secure service 를 만들어내라고 닥닥 볶임을 당합니다.
솔직히 저 두 분야는 모두 자신이 없는 부분이라 앞으로 한달간 엄청난 시련이
예상되는 바입니다. 잘되기를 바랄 뿐입죠.. 흐흐흐..
삽질의 대마왕...
어제 책 읽고 다시 만든 ldap query 입니다.[code:1
어제 책 읽고 다시 만든 ldap query 입니다.
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <lber.h> #include <ldap.h> int main (int argc, char **argv) { LDAP *ld; int auth_method = LDAP_AUTH_SIMPLE; int desired_version = LDAP_VERSION3; char *ldap_host = "[hostname]"; char *root_dn = "uid=[ldap-user-name],dc=[dc1],dc=[dc2]...."; char *root_pw = "secret" ; char *base = "dc=[dca],dc=[dcb]..."; char *filter = "[filter string]"; char *errstring; char *dn = NULL; char *attr; char **vals; int i; int result; BerElement *ber; LDAPMessage *msg; LDAPMessage *entry; if ((ld = ldap_init (ldap_host, LDAP_PORT)) == NULL) { perror ("ldap_init failed"); exit (EXIT_FAILURE); } if (ldap_set_option (ld, LDAP_OPT_PROTOCOL_VERSION, &desired_version) != LDAP_OPT_SUCCESS) { ldap_perror (ld, "ldap_set_option"); exit (EXIT_FAILURE); } if (ldap_bind_s (ld, root_dn, root_pw, auth_method) != LDAP_SUCCESS) { ldap_perror (ld, "ldap_bind"); exit (EXIT_FAILURE); } if (ldap_search_s (ld, base, LDAP_SCOPE_SUBTREE, filter, NULL, 0, &msg) != LDAP_SUCCESS) { ldap_perror (ld, "ldap_search_s"); exit (EXIT_FAILURE); } printf ("the number of entries returned was %d\n\n", ldap_count_entries (ld, msg)); for (entry = ldap_first_entry (ld, msg); entry != NULL; entry = ldap_next_entry (ld, entry)) { if ((dn = ldap_get_dn (ld, entry)) != NULL) { printf ("Returned dn: %s\n", dn); ldap_memfree (dn); } for (attr = ldap_first_attribute (ld, entry, &ber); attr != NULL; attr = ldap_next_attribute (ld, entry, ber)) { if ((vals = ldap_get_values (ld, entry, attr)) != NULL) { for (i = 0; vals[i] != NULL; i++) printf ("%s: %s\n", attr, vals[i]); ldap_value_free (vals); } ldap_memfree (attr); } if (ber != NULL) ber_free (ber, 0); printf ("\n"); } ldap_msgfree (msg); result = ldap_unbind_s (ld); if (result != 0) { fprintf (stderr, "ldap_unbind_s: %s\n", ldap_err2string (result)); exit (1); } return 0; }삽질의 대마왕...
..
위에 첫 example는 ldaps 인 서버에 평문으로 ldap 질의를 날려서... 안되는것
ldap_search에서 error가 나야 할 것 처럼 보이지만 특이하게 ldap_result에서 에러 떨어지는 상태??
아닌가 해요
댓글 달기