Mercurial > pidgin.yaz
annotate libpurple/protocols/jabber/auth_plain.c @ 30906:34f586bffe4e
Added new files in sub directory google
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Thu, 25 Mar 2010 20:18:54 +0000 |
parents | b94fd073187c |
children | a54e59c1c520 |
rev | line source |
---|---|
29078
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 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
25 #include "account.h" |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
26 #include "debug.h" |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
27 #include "request.h" |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
28 #include "util.h" |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
29 #include "xmlnode.h" |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
30 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
31 #include "jabber.h" |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
32 #include "auth.h" |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
33 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
34 static xmlnode *finish_plaintext_authentication(JabberStream *js) |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
35 { |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
36 xmlnode *auth; |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
37 GString *response; |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
38 gchar *enc_out; |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
39 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
40 auth = xmlnode_new("auth"); |
29097
cea22db36ffc
jabber: Use NS_XMPP_SASL
Paul Aurich <paul@darkrain42.org>
parents:
29078
diff
changeset
|
41 xmlnode_set_namespace(auth, NS_XMPP_SASL); |
29078
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
42 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
43 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
|
44 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
|
45 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
46 response = g_string_new(""); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
47 response = g_string_append_len(response, "\0", 1); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
48 response = g_string_append(response, js->user->node); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
49 response = g_string_append_len(response, "\0", 1); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
50 response = g_string_append(response, |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
51 purple_connection_get_password(js->gc)); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
52 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
53 enc_out = purple_base64_encode((guchar *)response->str, response->len); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
54 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
55 xmlnode_set_attrib(auth, "mechanism", "PLAIN"); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
56 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
|
57 g_free(enc_out); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
58 g_string_free(response, TRUE); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
59 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
60 return auth; |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
61 } |
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 static void allow_plaintext_auth(PurpleAccount *account) |
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 PurpleConnection *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
|
66 JabberStream *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
|
67 xmlnode *response; |
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 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
|
70 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
71 response = finish_plaintext_authentication(js); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
72 jabber_send(js, response); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
73 xmlnode_free(response); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
74 } |
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 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
|
77 { |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
78 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
|
79 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
80 _("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
|
81 } |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
82 |
29107
4f45aae3ace1
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <paul@darkrain42.org>
parents:
29097
diff
changeset
|
83 static JabberSaslState |
29136
b94fd073187c
jabber: Fix that leak I mentioned (and fix a mistake where error/response weren't NULL-initialized)
Paul Aurich <paul@darkrain42.org>
parents:
29107
diff
changeset
|
84 jabber_plain_start(JabberStream *js, xmlnode *packet, xmlnode **response, char **error) |
29078
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 PurpleAccount *account = purple_connection_get_account(js->gc); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
87 char *msg; |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
88 |
29107
4f45aae3ace1
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <paul@darkrain42.org>
parents:
29097
diff
changeset
|
89 if (jabber_stream_is_ssl(js) || purple_account_get_bool(account, "auth_plain_in_clear", FALSE)) { |
4f45aae3ace1
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <paul@darkrain42.org>
parents:
29097
diff
changeset
|
90 *response = finish_plaintext_authentication(js); |
4f45aae3ace1
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <paul@darkrain42.org>
parents:
29097
diff
changeset
|
91 return JABBER_SASL_STATE_OK; |
4f45aae3ace1
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <paul@darkrain42.org>
parents:
29097
diff
changeset
|
92 } |
29078
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
93 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
94 msg = g_strdup_printf(_("%s requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
95 purple_account_get_username(account)); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
96 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
|
97 _("Plaintext Authentication"), |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
98 msg, |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
99 1, |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
100 account, NULL, NULL, |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
101 account, allow_plaintext_auth, disallow_plaintext_auth); |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
102 g_free(msg); |
29107
4f45aae3ace1
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <paul@darkrain42.org>
parents:
29097
diff
changeset
|
103 return JABBER_SASL_STATE_CONTINUE; |
29078
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
104 } |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
105 |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
106 static JabberSaslMech plain_mech = { |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
107 0, /* priority */ |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
108 "PLAIN", /* name */ |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
109 jabber_plain_start, |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
110 NULL, /* handle_challenge */ |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
111 NULL, /* handle_success */ |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
112 NULL, /* handle_failure */ |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
113 NULL /* dispose */ |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
114 }; |
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 JabberSaslMech *jabber_auth_get_plain_mech(void) |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
117 { |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
118 return &plain_mech; |
8ada06fb65ed
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
119 } |