annotate libpurple/protocols/jabber/auth_cyrus.c @ 28753:8a5252630857

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