source: auth.c @ a6005da

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

Linux pam authentication backend

This backend authenticates users against pam.

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