/* $ gcc -o frob-cldap-initfd -Wall -lldap -llber frob-cldap-initfd.c */ #include #include #include #include #include #include #include /* From ldap_pvt.h */ #define LDAP_PROTO_TCP 1 /* ldap:// */ #define LDAP_PROTO_UDP 2 /* reserved */ #define LDAP_PROTO_IPC 3 /* ldapi:// */ #define LDAP_PROTO_EXT 4 /* user-defined socket/sockbuf */ LDAP_F (int) ldap_init_fd LDAP_P(( ber_socket_t fd, int proto, LDAP_CONST char *url, struct ldap **ldp )); int main (void) { struct sockaddr_in dest; LDAP *ldap; int sock; int rc; int id; /* Yes, this doesn't actually do anything useful, just demonstrates ldap_init_fd failure when dealing with UDP */ sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (sock < 0) err(1, "socket()"); memset (&dest, 0, sizeof (dest)); dest.sin_family = AF_INET; dest.sin_addr.s_addr = inet_addr ("127.0.0.1"); dest.sin_port = htons (389); if (connect (sock, (struct sockaddr *)&dest, sizeof (dest)) < 0) err(1, "connect()"); rc = ldap_init_fd (sock, LDAP_PROTO_UDP, "cldap://localhost", &ldap); if (rc != LDAP_SUCCESS) errx (1, "ldap_init_fd: %d", rc); rc = ldap_search_ext (ldap, "", LDAP_SCOPE_BASE, "(objectClass=*)", NULL, 0, NULL, NULL, NULL, -1, &id); /* Unpatched openldap fails here with a return value of -1 */ if (rc != LDAP_SUCCESS) errx (1, "ldap_search_ext: %d", rc); ldap_unbind_ext (ldap, NULL, NULL); return 0; }