source: auth.c @ 5545c81

Last change on this file since 5545c81 was 50bb490, checked in by Dennis Kaarsemaker <dennis@…>, at 2016-03-25T18:07:53Z

ldap authentication backend

We only support the openldap scheme for now, with users that are
posixAccounts. Moreover, as the plugin cannot be configured directly,
you must configure libldap correctly in /etc/openldap/ldap.conf

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#define BITLBEE_CORE
2#include "bitlbee.h"
3
4#ifdef WITH_PAM
5extern auth_backend_t auth_pam;
6#endif
7#ifdef WITH_LDAP
8extern auth_backend_t auth_ldap;
9#endif
10
11GList *auth_init(const char *backend)
12{
13        GList *gl = NULL;
14        int ok = backend ? 0 : 1;
15#ifdef WITH_PAM
16        gl = g_list_append(gl, &auth_pam);
17        if (backend && !strcmp(backend, "pam")) {
18                ok = 1;
19        }
20#endif
21#ifdef WITH_LDAP
22        gl = g_list_append(gl, &auth_ldap);
23        if (backend && !strcmp(backend, "ldap")) {
24                ok = 1;
25        }
26#endif
27
28        return ok ? gl : NULL;
29}
30
31storage_status_t auth_check_pass(irc_t *irc, const char *nick, const char *password)
32{
33        GList *gl;
34        storage_status_t status = storage_check_pass(irc, nick, password);
35
36        if (status == STORAGE_CHECK_BACKEND) {
37                for (gl = global.auth; gl; gl = gl->next) {
38                        auth_backend_t *be = gl->data;
39                        if (!strcmp(be->name, irc->auth_backend)) {
40                                status = be->check_pass(nick, password);
41                                break;
42                        }
43                }
44        } else if (status == STORAGE_NO_SUCH_USER && global.conf->auth_backend) {
45                for (gl = global.auth; gl; gl = gl->next) {
46                        auth_backend_t *be = gl->data;
47                        if (!strcmp(be->name, global.conf->auth_backend)) {
48                                status = be->check_pass(nick, password);
49                                /* Save the user so storage_load will pick them up, similar to
50                                 * what the register command would do */
51                                if (status == STORAGE_OK) {
52                                        irc->auth_backend = g_strdup(global.conf->auth_backend);
53                                        storage_save(irc, (char *)password, 0);
54                                }
55                                break;
56                        }
57                }
58        }
59
60        if (status == STORAGE_OK) {
61                irc_setpass(irc, password);
62        }
63
64        return status;
65}
Note: See TracBrowser for help on using the repository browser.