3 * LDAP functionality for x3, by Rubin
6 * * get queries working in static existance, so i understand how it works
7 * * get ldap enabled in ./configure
8 * * x3.conf settings to enable/configure its use
9 * * generic functions to enable ldap
10 * * nickserv.c work to use said functions.
16 //#include <sys/select.h>
26 #ifdef HAVE_SYS_SELECT_H
27 #include <sys/select.h>
29 #ifdef HAVE_SYS_SOCKET_H
30 #include <sys/socket.h>
35 /* char dn[] = "uid=%s,ou=Users,dc=afternet,dc=org";
36 char password[] = "xxxxxxx";
37 char base[] = "ou=Users,dc=afternet,dc=org";
40 extern struct nickserv_config nickserv_conf
;
43 /* TODO: change all these printfs to proper debug statements */
49 /* TODO: check here for all required config options and exit() out if not present */
50 ld
= ldap_init(nickserv_conf
.ldap_host
, nickserv_conf
.ldap_port
);
55 ldap_set_option(ld
, LDAP_OPT_PROTOCOL_VERSION
, &nickserv_conf
.ldap_version
);
56 printf("Success! ldap_init() was successfull in connecting to %s port %d\n", nickserv_conf
.ldap_host
, nickserv_conf
.ldap_port
);
60 /* Try to auth someone. If theres problems, try reconnecting
61 * once every 10 seconds for 1 minute.
62 * TODO: move this stuff to config file
64 unsigned int ldap_check_auth( char *account
, char *pass
)
69 memset(buff
, 0, MAXLEN
);
70 snprintf(buff
, sizeof(buff
)-1, nickserv_conf
.ldap_dn_fmt
/*"uid=%s,ou=Users,dc=afternet,dc=org"*/, account
);
73 q
= ldap_simple_bind_s(ld
, buff
, pass
);
74 if(q
== LDAP_SUCCESS
) {
77 else if(q
== LDAP_INVALID_CREDENTIALS
) {
81 printf("Bind failed: %s/****** (%d)\n", buff
, q
);
82 ldap_perror(ld
, "ldap");
83 /* Re-init to re-connect to ldap server if thats the problem */
85 ldap_do_init(nickserv_conf
);
88 printf("Failing to reconnect to ldap server. Dieing.");
92 printf("bind() successfull! You are bound as %s\n", buff
);
97 #ifdef notdef /* not used yet - will be used to pull email etc out of ldap */
98 LDAPMessage
ldap_search_user(char uid
)
101 char filter
[] = "cn=admin";
103 struct timeval timeout
;
109 if( ldap_search_st(ld
, base
, LDAP_SCOPE_ONELEVEL
, filter
, NULL
, 0, &timeout
, &res
) != LDAP_SUCCESS
) {
110 printf("search failed: %s %s\n", base
, filter
);
113 printf("Search successfull! %s %s\n", base
, filter
);
114 printf("Got %d entries\n", ldap_count_entries(ld
, res
));
118 entry
= ldap_first_entry(ld
, res
);
119 value
= ldap_get_values(ld
, entry
, "cn");
120 printf("cn: %s\n", value
[0]);
121 value
= ldap_get_values(ld
, entry
, "description");
122 printf("Description: %s\n", value
[0]);
123 value
= ldap_get_values(ld
, entry
, "userPassword");
124 printf("pass: %s\n", value
? value
[0] : "error");
129 ldap_first_attribute();
132 ldap_next_attribute();
140 /* get errors with ldap_err2string(); */