
LDAP 오류: ldap_read: Operations error는 일반적으로 LDAP 서버와의 연결이 실패하거나, 인증 정보가 잘못된 경우에 발생합니다.
ldap_read 함수를 사용할 때는 다음 조건을 만족해야 합니다.
1. LDAP 서버와의 연결이 성공적으로 이루어져야 합니다.
2. 인증 정보(사용자 ID 및 암호)가 정확해야 합니다.
3. LDAP 서버에 접근 권한이 있어야 합니다.
ldap_read 함수를 사용하여 사용자 정보를 읽어오기 위해 필요한 기본 옵션은 다음과 같습니다.
- LDAP 서버의 주소와 포트 번호
- 인증 정보(사용자 ID 및 암호)
- LDAP 서버의 DN(Distinguished Name)
추가 옵션으로는 다음과 같은 것을 사용할 수 있습니다.
- LDAP 서버에 접근할 때 사용하는 프로토콜(예: LDAP, LDAPS)
- LDAP 서버의 검색 범위
- 사용자 정보를 읽어오기 위해 필요한 필드
예를 들어, 다음 코드는 LDAP 서버에 접속하여 사용자 정보를 읽어오는 예제입니다.
#hostingforum.kr
c
#include
int main() {
LDAP* ld;
BerValue* attr;
int rc;
// LDAP 서버의 주소와 포트 번호
const char* ldap_url = "ldap://localhost:389";
// 인증 정보(사용자 ID 및 암호)
const char* user_id = "cn=admin,dc=example,dc=com";
const char* password = "password";
// LDAP 서버의 DN(Distinguished Name)
const char* base_dn = "dc=example,dc=com";
// LDAP 서버에 접속
rc = ldap_initialize(&ld, ldap_url);
if (rc != LDAP_SUCCESS) {
fprintf(stderr, "LDAP 오류: ldap_initialize: %sn", ldap_err2string(rc));
return 1;
}
// 인증 정보를 설정
rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, LDAP_VERSION3);
if (rc != LDAP_SUCCESS) {
fprintf(stderr, "LDAP 오류: ldap_set_option: %sn", ldap_err2string(rc));
return 1;
}
rc = ldap_bind_s(ld, user_id, password, LDAP_AUTH_SIMPLE);
if (rc != LDAP_SUCCESS) {
fprintf(stderr, "LDAP 오류: ldap_bind_s: %sn", ldap_err2string(rc));
return 1;
}
// 사용자 정보를 읽어오기
rc = ldap_search_s(ld, base_dn, LDAP_SCOPE_SUBTREE, "(objectClass=*)", NULL, 0, &attr);
if (rc != LDAP_SUCCESS) {
fprintf(stderr, "LDAP 오류: ldap_search_s: %sn", ldap_err2string(rc));
return 1;
}
// 사용자 정보를 출력
for (int i = 0; attr[i].bv_val != NULL; i++) {
printf("%s: %sn", attr[i].bv_val, ldap_get_values_len(ld, attr[i].bv_val, NULL));
}
// LDAP 서버와의 연결을 종료
ldap_unbind_s(ld);
return 0;
}
2025-06-14 22:29