[8e6ecfe] | 1 | #define BITLBEE_CORE |
---|
| 2 | #include "bitlbee.h" |
---|
| 3 | |
---|
[a6005da] | 4 | #ifdef WITH_PAM |
---|
| 5 | extern auth_backend_t auth_pam; |
---|
| 6 | #endif |
---|
| 7 | |
---|
[8e6ecfe] | 8 | GList *auth_init(const char *backend) |
---|
| 9 | { |
---|
| 10 | GList *gl = NULL; |
---|
| 11 | int ok = backend ? 0 : 1; |
---|
[a6005da] | 12 | #ifdef WITH_PAM |
---|
| 13 | gl = g_list_append(gl, &auth_pam); |
---|
| 14 | if (backend && !strcmp(backend, "pam")) { |
---|
| 15 | ok = 1; |
---|
| 16 | } |
---|
| 17 | #endif |
---|
[8e6ecfe] | 18 | |
---|
| 19 | return ok ? gl : NULL; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | storage_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 | } |
---|