Sun, 08 Nov 2009 03:34:48 +0000
jabber: Clear js->auth_mech for good measure.
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
1 | /* |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
2 | * purple - Jabber Protocol Plugin |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
3 | * |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too numerous |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
6 | * source distribution. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
7 | * |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
8 | * This program is free software; you can redistribute it and/or modify |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
9 | * it under the terms of the GNU General Public License as published by |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
10 | * the Free Software Foundation; either version 2 of the License, or |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
11 | * (at your option) any later version. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
12 | * |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
13 | * This program is distributed in the hope that it will be useful, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
16 | * GNU General Public License for more details. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
17 | * |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
19 | * along with this program; if not, write to the Free Software |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
21 | * |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
22 | */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
23 | #include "internal.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
24 | #include "core.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
25 | #include "debug.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
26 | #include "request.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
27 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
28 | #include "auth.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
29 | #include "jabber.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
30 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
31 | static xmlnode *jabber_auth_start_cyrus(JabberStream *); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
32 | static void jabber_sasl_build_callbacks(JabberStream *); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
33 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
34 | static void disallow_plaintext_auth(PurpleAccount *account) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
35 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
36 | purple_connection_error_reason(purple_account_get_connection(account), |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
37 | PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
38 | _("Server requires plaintext authentication over an unencrypted stream")); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
39 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
40 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
41 | /* Callbacks for Cyrus SASL */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
42 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
43 | static int jabber_sasl_cb_realm(void *ctx, int id, const char **avail, const char **result) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
44 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
45 | JabberStream *js = ctx; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
46 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
47 | if (id != SASL_CB_GETREALM || !result) return SASL_BADPARAM; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
48 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
49 | *result = js->user->domain; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
50 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
51 | return SASL_OK; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
52 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
53 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
54 | static int jabber_sasl_cb_simple(void *ctx, int id, const char **res, unsigned *len) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
55 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
56 | JabberStream *js = ctx; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
57 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
58 | switch(id) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
59 | case SASL_CB_AUTHNAME: |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
60 | *res = js->user->node; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
61 | break; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
62 | case SASL_CB_USER: |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
63 | *res = ""; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
64 | break; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
65 | default: |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
66 | return SASL_BADPARAM; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
67 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
68 | if (len) *len = strlen((char *)*res); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
69 | return SASL_OK; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
70 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
71 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
72 | static int jabber_sasl_cb_secret(sasl_conn_t *conn, void *ctx, int id, sasl_secret_t **secret) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
73 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
74 | JabberStream *js = ctx; |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
75 | PurpleAccount *account; |
|
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
76 | const char *pw; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
77 | size_t len; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
78 | static sasl_secret_t *x = NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
79 | |
| 28859 | 80 | account = purple_connection_get_account(js->gc); |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
81 | pw = purple_account_get_password(account); |
|
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
82 | |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
83 | if (!conn || !secret || id != SASL_CB_PASS) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
84 | return SASL_BADPARAM; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
85 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
86 | len = strlen(pw); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
87 | x = (sasl_secret_t *) realloc(x, sizeof(sasl_secret_t) + len); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
88 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
89 | if (!x) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
90 | return SASL_NOMEM; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
91 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
92 | x->len = len; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
93 | strcpy((char*)x->data, pw); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
94 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
95 | *secret = x; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
96 | return SASL_OK; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
97 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
98 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
99 | static void allow_cyrus_plaintext_auth(PurpleAccount *account) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
100 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
101 | PurpleConnection *gc; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
102 | JabberStream *js; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
103 | xmlnode *response; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
104 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
105 | gc = purple_account_get_connection(account); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
106 | js = purple_connection_get_protocol_data(gc); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
107 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
108 | purple_account_set_bool(account, "auth_plain_in_clear", TRUE); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
109 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
110 | response = jabber_auth_start_cyrus(js); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
111 | if (response) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
112 | jabber_send(js, response); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
113 | xmlnode_free(response); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
114 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
115 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
116 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
117 | static void auth_pass_cb(PurpleConnection *gc, PurpleRequestFields *fields) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
118 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
119 | PurpleAccount *account; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
120 | JabberStream *js; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
121 | xmlnode *response; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
122 | const char *entry; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
123 | gboolean remember; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
124 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
125 | /* The password prompt dialog doesn't get disposed if the account disconnects */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
126 | if (!PURPLE_CONNECTION_IS_VALID(gc)) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
127 | return; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
128 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
129 | account = purple_connection_get_account(gc); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
130 | js = purple_connection_get_protocol_data(gc); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
131 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
132 | entry = purple_request_fields_get_string(fields, "password"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
133 | remember = purple_request_fields_get_bool(fields, "remember"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
134 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
135 | if (!entry || !*entry) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
136 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
137 | purple_notify_error(account, NULL, _("Password is required to sign on."), NULL); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
138 | return; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
139 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
140 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
141 | if (remember) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
142 | purple_account_set_remember_password(account, TRUE); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
143 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
144 | purple_account_set_password(account, entry); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
145 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
146 | /* Rebuild our callbacks as we now have a password to offer */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
147 | jabber_sasl_build_callbacks(js); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
148 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
149 | /* Restart our connection */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
150 | response = jabber_auth_start_cyrus(js); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
151 | if (response) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
152 | jabber_send(js, response); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
153 | xmlnode_free(response); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
154 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
155 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
156 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
157 | static void |
|
28860
d2a057cdd7b6
jabber: A little more use of accessors.
Paul Aurich <darkrain42@pidgin.im>
parents:
28859
diff
changeset
|
158 | auth_no_pass_cb(PurpleConnection *gc, PurpleRequestFields *fields) |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
159 | { |
|
28860
d2a057cdd7b6
jabber: A little more use of accessors.
Paul Aurich <darkrain42@pidgin.im>
parents:
28859
diff
changeset
|
160 | PurpleAccount *account; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
161 | JabberStream *js; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
162 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
163 | /* The password prompt dialog doesn't get disposed if the account disconnects */ |
|
28860
d2a057cdd7b6
jabber: A little more use of accessors.
Paul Aurich <darkrain42@pidgin.im>
parents:
28859
diff
changeset
|
164 | if (!PURPLE_CONNECTION_IS_VALID(gc)) |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
165 | return; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
166 | |
|
28860
d2a057cdd7b6
jabber: A little more use of accessors.
Paul Aurich <darkrain42@pidgin.im>
parents:
28859
diff
changeset
|
167 | account = purple_connection_get_account(gc); |
|
d2a057cdd7b6
jabber: A little more use of accessors.
Paul Aurich <darkrain42@pidgin.im>
parents:
28859
diff
changeset
|
168 | js = purple_connection_get_protocol_data(gc); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
169 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
170 | /* Disable the account as the user has canceled connecting */ |
|
28860
d2a057cdd7b6
jabber: A little more use of accessors.
Paul Aurich <darkrain42@pidgin.im>
parents:
28859
diff
changeset
|
171 | purple_account_set_enabled(account, purple_core_get_ui(), FALSE); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
172 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
173 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
174 | static xmlnode *jabber_auth_start_cyrus(JabberStream *js) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
175 | { |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
176 | PurpleAccount *account; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
177 | const char *clientout = NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
178 | char *enc_out; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
179 | unsigned coutlen = 0; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
180 | xmlnode *auth; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
181 | sasl_security_properties_t secprops; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
182 | gboolean again; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
183 | gboolean plaintext = TRUE; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
184 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
185 | /* Set up security properties and options */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
186 | secprops.min_ssf = 0; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
187 | secprops.security_flags = SASL_SEC_NOANONYMOUS; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
188 | |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
189 | account = purple_connection_get_account(js->gc); |
|
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
190 | |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
191 | if (!jabber_stream_is_ssl(js)) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
192 | secprops.max_ssf = -1; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
193 | secprops.maxbufsize = 4096; |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
194 | plaintext = purple_account_get_bool(account, "auth_plain_in_clear", FALSE); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
195 | if (!plaintext) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
196 | secprops.security_flags |= SASL_SEC_NOPLAINTEXT; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
197 | } else { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
198 | secprops.max_ssf = 0; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
199 | secprops.maxbufsize = 0; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
200 | plaintext = TRUE; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
201 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
202 | secprops.property_names = 0; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
203 | secprops.property_values = 0; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
204 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
205 | do { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
206 | again = FALSE; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
207 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
208 | js->sasl_state = sasl_client_new("xmpp", js->serverFQDN, NULL, NULL, js->sasl_cb, 0, &js->sasl); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
209 | if (js->sasl_state==SASL_OK) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
210 | sasl_setprop(js->sasl, SASL_SEC_PROPS, &secprops); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
211 | purple_debug_info("sasl", "Mechs found: %s\n", js->sasl_mechs->str); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
212 | js->sasl_state = sasl_client_start(js->sasl, js->sasl_mechs->str, NULL, &clientout, &coutlen, &js->current_mech); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
213 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
214 | switch (js->sasl_state) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
215 | /* Success */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
216 | case SASL_OK: |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
217 | case SASL_CONTINUE: |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
218 | break; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
219 | case SASL_NOMECH: |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
220 | /* No mechanisms have offered to help */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
221 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
222 | /* Firstly, if we don't have a password try |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
223 | * to get one |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
224 | */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
225 | |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
226 | if (!purple_account_get_password(account)) { |
|
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
227 | purple_account_request_password(account, G_CALLBACK(auth_pass_cb), G_CALLBACK(auth_no_pass_cb), js->gc); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
228 | return NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
229 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
230 | /* If we've got a password, but aren't sending |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
231 | * it in plaintext, see if we can turn on |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
232 | * plaintext auth |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
233 | */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
234 | } else if (!plaintext) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
235 | char *msg = g_strdup_printf(_("%s requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
236 | purple_account_get_username(account)); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
237 | purple_request_yes_no(js->gc, _("Plaintext Authentication"), |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
238 | _("Plaintext Authentication"), |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
239 | msg, |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
240 | 1, account, NULL, NULL, account, |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
241 | allow_cyrus_plaintext_auth, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
242 | disallow_plaintext_auth); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
243 | g_free(msg); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
244 | return NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
245 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
246 | } else { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
247 | /* We have no mechs which can work. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
248 | * Try falling back on the old jabber:iq:auth method. We get here if the server supports |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
249 | * one or more sasl mechs, we are compiled with cyrus-sasl support, but we support or can connect with none of |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
250 | * the offerred mechs. jabberd 2.0 w/ SASL and Apple's iChat Server 10.5 both handle and expect |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
251 | * jabber:iq:auth in this situation. iChat Server in particular offers SASL GSSAPI by default, which is often |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
252 | * not configured on the client side, and expects a fallback to jabber:iq:auth when it (predictably) fails. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
253 | * |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
254 | * Note: xep-0078 points out that using jabber:iq:auth after a sasl failure is wrong. However, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
255 | * I believe this refers to actual authentication failure, not a simple lack of concordant mechanisms. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
256 | * Doing otherwise means that simply compiling with SASL support renders the client unable to connect to servers |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
257 | * which would connect without issue otherwise. -evands |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
258 | */ |
|
28861
b77599fa1e36
jabber: Clear js->auth_mech for good measure.
Paul Aurich <darkrain42@pidgin.im>
parents:
28860
diff
changeset
|
259 | js->auth_mech = NULL; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
260 | jabber_auth_start_old(js); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
261 | return NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
262 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
263 | /* not reached */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
264 | break; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
265 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
266 | /* Fatal errors. Give up and go home */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
267 | case SASL_BADPARAM: |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
268 | case SASL_NOMEM: |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
269 | break; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
270 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
271 | /* For everything else, fail the mechanism and try again */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
272 | default: |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
273 | purple_debug_info("sasl", "sasl_state is %d, failing the mech and trying again\n", js->sasl_state); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
274 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
275 | /* |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
276 | * DAA: is this right? |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
277 | * The manpage says that "mech" will contain the chosen mechanism on success. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
278 | * Presumably, if we get here that isn't the case and we shouldn't try again? |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
279 | * I suspect that this never happens. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
280 | */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
281 | /* |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
282 | * SXW: Yes, this is right. What this handles is the situation where a |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
283 | * mechanism, say GSSAPI, is tried. If that mechanism fails, it may be |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
284 | * due to mechanism specific issues, so we want to try one of the other |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
285 | * supported mechanisms. This code handles that case |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
286 | */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
287 | if (js->current_mech && *js->current_mech) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
288 | char *pos; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
289 | if ((pos = strstr(js->sasl_mechs->str, js->current_mech))) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
290 | g_string_erase(js->sasl_mechs, pos-js->sasl_mechs->str, strlen(js->current_mech)); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
291 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
292 | /* Remove space which separated this mech from the next */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
293 | if ((js->sasl_mechs->str)[0] == ' ') { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
294 | g_string_erase(js->sasl_mechs, 0, 1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
295 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
296 | again = TRUE; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
297 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
298 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
299 | sasl_dispose(&js->sasl); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
300 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
301 | } while (again); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
302 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
303 | if (js->sasl_state == SASL_CONTINUE || js->sasl_state == SASL_OK) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
304 | auth = xmlnode_new("auth"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
305 | xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
306 | xmlnode_set_attrib(auth, "mechanism", js->current_mech); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
307 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
308 | xmlnode_set_attrib(auth, "xmlns:ga", "http://www.google.com/talk/protocol/auth"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
309 | xmlnode_set_attrib(auth, "ga:client-uses-full-bind-result", "true"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
310 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
311 | if (clientout) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
312 | if (coutlen == 0) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
313 | xmlnode_insert_data(auth, "=", -1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
314 | } else { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
315 | enc_out = purple_base64_encode((unsigned char*)clientout, coutlen); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
316 | xmlnode_insert_data(auth, enc_out, -1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
317 | g_free(enc_out); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
318 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
319 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
320 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
321 | return auth; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
322 | } else { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
323 | purple_connection_error_reason(js->gc, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
324 | PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
325 | _("SASL authentication failed")); |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
326 | |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
327 | return NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
328 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
329 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
330 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
331 | static int |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
332 | jabber_sasl_cb_log(void *context, int level, const char *message) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
333 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
334 | if(level <= SASL_LOG_TRACE) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
335 | purple_debug_info("sasl", "%s\n", message); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
336 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
337 | return SASL_OK; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
338 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
339 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
340 | static void |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
341 | jabber_sasl_build_callbacks(JabberStream *js) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
342 | { |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
343 | PurpleAccount *account; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
344 | int id; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
345 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
346 | /* Set up our callbacks structure */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
347 | if (js->sasl_cb == NULL) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
348 | js->sasl_cb = g_new0(sasl_callback_t,6); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
349 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
350 | id = 0; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
351 | js->sasl_cb[id].id = SASL_CB_GETREALM; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
352 | js->sasl_cb[id].proc = jabber_sasl_cb_realm; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
353 | js->sasl_cb[id].context = (void *)js; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
354 | id++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
355 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
356 | js->sasl_cb[id].id = SASL_CB_AUTHNAME; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
357 | js->sasl_cb[id].proc = jabber_sasl_cb_simple; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
358 | js->sasl_cb[id].context = (void *)js; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
359 | id++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
360 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
361 | js->sasl_cb[id].id = SASL_CB_USER; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
362 | js->sasl_cb[id].proc = jabber_sasl_cb_simple; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
363 | js->sasl_cb[id].context = (void *)js; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
364 | id++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
365 | |
|
28856
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
366 | account = purple_connection_get_account(js->gc); |
|
992b7074357d
jabber: Use accessors instead of directly accessing gc->account (and similar)
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
367 | if (purple_account_get_password(account) != NULL ) { |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
368 | js->sasl_cb[id].id = SASL_CB_PASS; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
369 | js->sasl_cb[id].proc = jabber_sasl_cb_secret; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
370 | js->sasl_cb[id].context = (void *)js; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
371 | id++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
372 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
373 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
374 | js->sasl_cb[id].id = SASL_CB_LOG; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
375 | js->sasl_cb[id].proc = jabber_sasl_cb_log; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
376 | js->sasl_cb[id].context = (void*)js; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
377 | id++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
378 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
379 | js->sasl_cb[id].id = SASL_CB_LIST_END; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
380 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
381 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
382 | static xmlnode *jabber_cyrus_start(JabberStream *js, xmlnode *mechanisms) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
383 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
384 | xmlnode *mechnode; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
385 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
386 | js->sasl_mechs = g_string_new(""); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
387 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
388 | for(mechnode = xmlnode_get_child(mechanisms, "mechanism"); mechnode; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
389 | mechnode = xmlnode_get_next_twin(mechnode)) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
390 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
391 | char *mech_name = xmlnode_get_data(mechnode); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
392 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
393 | if (!mech_name || !*mech_name) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
394 | g_free(mech_name); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
395 | continue; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
396 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
397 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
398 | /* Don't include Google Talk's X-GOOGLE-TOKEN mechanism, as we will not |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
399 | * support it and including it gives a false fall-back to other mechs offerred, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
400 | * leading to incorrect error handling. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
401 | */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
402 | if (g_str_equal(mech_name, "X-GOOGLE-TOKEN")) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
403 | g_free(mech_name); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
404 | continue; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
405 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
406 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
407 | g_string_append(js->sasl_mechs, mech_name); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
408 | g_string_append_c(js->sasl_mechs, ' '); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
409 | g_free(mech_name); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
410 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
411 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
412 | jabber_sasl_build_callbacks(js); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
413 | return jabber_auth_start_cyrus(js); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
414 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
415 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
416 | static xmlnode *jabber_cyrus_handle_challenge(JabberStream *js, xmlnode *packet) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
417 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
418 | char *enc_in = xmlnode_get_data(packet); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
419 | unsigned char *dec_in; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
420 | char *enc_out; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
421 | const char *c_out; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
422 | unsigned int clen; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
423 | gsize declen; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
424 | xmlnode *response = NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
425 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
426 | dec_in = purple_base64_decode(enc_in, &declen); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
427 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
428 | js->sasl_state = sasl_client_step(js->sasl, (char*)dec_in, declen, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
429 | NULL, &c_out, &clen); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
430 | g_free(enc_in); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
431 | g_free(dec_in); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
432 | if (js->sasl_state != SASL_CONTINUE && js->sasl_state != SASL_OK) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
433 | gchar *tmp = g_strdup_printf(_("SASL error: %s"), |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
434 | sasl_errdetail(js->sasl)); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
435 | purple_debug_error("jabber", "Error is %d : %s\n", |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
436 | js->sasl_state, sasl_errdetail(js->sasl)); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
437 | purple_connection_error_reason(js->gc, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
438 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
439 | g_free(tmp); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
440 | } else { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
441 | response = xmlnode_new("response"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
442 | xmlnode_set_namespace(response, "urn:ietf:params:xml:ns:xmpp-sasl"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
443 | if (clen > 0) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
444 | /* Cyrus SASL 2.1.22 appears to contain code to add the charset |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
445 | * to the response for DIGEST-MD5 but there is no possibility |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
446 | * it will be executed. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
447 | * |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
448 | * My reading of the digestmd5 plugin indicates the username and |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
449 | * realm are always encoded in UTF-8 (they seem to be the values |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
450 | * we pass in), so we need to ensure charset=utf-8 is set. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
451 | */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
452 | if (!purple_strequal(js->current_mech, "DIGEST-MD5") || |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
453 | strstr(c_out, ",charset=")) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
454 | /* If we're not using DIGEST-MD5 or Cyrus SASL is fixed */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
455 | enc_out = purple_base64_encode((unsigned char*)c_out, clen); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
456 | else { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
457 | char *tmp = g_strdup_printf("%s,charset=utf-8", c_out); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
458 | enc_out = purple_base64_encode((unsigned char*)tmp, clen + 14); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
459 | g_free(tmp); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
460 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
461 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
462 | xmlnode_insert_data(response, enc_out, -1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
463 | g_free(enc_out); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
464 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
465 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
466 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
467 | return response; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
468 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
469 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
470 | static gboolean jabber_cyrus_handle_success(JabberStream *js, xmlnode *packet) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
471 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
472 | const void *x; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
473 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
474 | /* The SASL docs say that if the client hasn't returned OK yet, we |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
475 | * should try one more round against it |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
476 | */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
477 | if (js->sasl_state != SASL_OK) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
478 | char *enc_in = xmlnode_get_data(packet); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
479 | unsigned char *dec_in = NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
480 | const char *c_out; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
481 | unsigned int clen; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
482 | gsize declen = 0; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
483 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
484 | if(enc_in != NULL) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
485 | dec_in = purple_base64_decode(enc_in, &declen); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
486 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
487 | js->sasl_state = sasl_client_step(js->sasl, (char*)dec_in, declen, NULL, &c_out, &clen); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
488 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
489 | g_free(enc_in); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
490 | g_free(dec_in); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
491 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
492 | if (js->sasl_state != SASL_OK) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
493 | /* This should never happen! */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
494 | purple_connection_error_reason(js->gc, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
495 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
496 | _("Invalid response from server")); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
497 | g_return_val_if_reached(FALSE); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
498 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
499 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
500 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
501 | /* If we've negotiated a security layer, we need to enable it */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
502 | if (js->sasl) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
503 | sasl_getprop(js->sasl, SASL_SSF, &x); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
504 | if (*(int *)x > 0) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
505 | sasl_getprop(js->sasl, SASL_MAXOUTBUF, &x); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
506 | js->sasl_maxbuf = *(int *)x; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
507 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
508 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
509 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
510 | return TRUE; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
511 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
512 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
513 | static xmlnode *jabber_cyrus_handle_failure(JabberStream *js, xmlnode *packet) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
514 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
515 | if (js->auth_fail_count++ < 5) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
516 | if (js->current_mech && *js->current_mech) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
517 | char *pos; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
518 | if ((pos = strstr(js->sasl_mechs->str, js->current_mech))) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
519 | g_string_erase(js->sasl_mechs, pos-js->sasl_mechs->str, strlen(js->current_mech)); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
520 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
521 | /* Remove space which separated this mech from the next */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
522 | if ((js->sasl_mechs->str)[0] == ' ') { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
523 | g_string_erase(js->sasl_mechs, 0, 1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
524 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
525 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
526 | if (*js->sasl_mechs->str) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
527 | /* If we have remaining mechs to try, do so */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
528 | sasl_dispose(&js->sasl); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
529 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
530 | return jabber_auth_start_cyrus(js); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
531 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
532 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
533 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
534 | /* Nothing to send */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
535 | return NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
536 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
537 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
538 | static JabberSaslMech cyrus_mech = { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
539 | 100, /* priority */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
540 | "*", /* name; Cyrus provides a bunch of mechanisms, so use an invalid |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
541 | * mechanism name (per rfc4422 3.1). */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
542 | jabber_cyrus_start, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
543 | jabber_cyrus_handle_challenge, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
544 | jabber_cyrus_handle_success, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
545 | jabber_cyrus_handle_failure, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
546 | NULL, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
547 | }; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
548 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
549 | JabberSaslMech *jabber_auth_get_cyrus_mech(void) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
550 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
551 | return &cyrus_mech; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
552 | } |