2 * One Time Password support plugin for libpurple
4 * Copyright (C) 2009, Daniel Atallah <datallah@pidgin.im>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "accountopt.h"
28 #define PLUGIN_ID "core-one_time_password"
29 #define PREF_NAME PLUGIN_ID "_enabled"
32 signed_on_cb(PurpleConnection
*conn
, void *data
)
34 PurpleAccount
*account
= purple_connection_get_account(conn
);
36 if (purple_account_get_bool(account
, PREF_NAME
, FALSE
)) {
37 if(purple_account_get_remember_password(account
))
38 purple_debug_error("One Time Password",
39 "Unable to enforce one time password for account %s (%s).\n"
40 "Account is set to remember the password.\n",
41 purple_account_get_username(account
),
42 purple_account_get_protocol_name(account
));
45 purple_debug_info("One Time Password", "Clearing password for account %s (%s).\n",
46 purple_account_get_username(account
),
47 purple_account_get_protocol_name(account
));
49 purple_account_set_password(account
, NULL
, NULL
, NULL
);
50 /* TODO: Do we need to somehow clear conn->password ? */
55 static PurplePluginInfo
*
56 plugin_query(GError
**error
)
58 const gchar
* const authors
[] = {
59 "Daniel Atallah <datallah@pidgin.im>",
63 return purple_plugin_info_new(
65 "name", N_("One Time Password Support"),
66 "version", DISPLAY_VERSION
,
67 "category", N_("Security"),
68 "summary", N_("Enforce that passwords are used only once."),
69 "description", N_("Allows you to enforce on a per-account basis that "
70 "passwords not being saved are only used in a "
71 "single successful connection.\n"
72 "Note: The account password must not be saved for "
75 "website", PURPLE_WEBSITE
,
76 "abi-version", PURPLE_ABI_VERSION
,
82 plugin_load(PurplePlugin
*plugin
, GError
**error
)
84 PurpleProtocol
*protocol
;
85 PurpleAccountOption
*option
;
88 list
= purple_protocols_get_all();
90 /* Register protocol preference. */
91 for (l
= list
; l
!= NULL
; l
= l
->next
) {
92 protocol
= PURPLE_PROTOCOL(l
->data
);
93 if (protocol
!= NULL
&& !(purple_protocol_get_options(protocol
) & OPT_PROTO_NO_PASSWORD
)) {
94 option
= purple_account_option_bool_new(_("One Time Password"),
96 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
101 /* Register callback. */
102 purple_signal_connect(purple_connections_get_handle(), "signed-on",
103 plugin
, PURPLE_CALLBACK(signed_on_cb
), NULL
);
109 plugin_unload(PurplePlugin
*plugin
, GError
**error
)
111 PurpleProtocol
*protocol
;
112 PurpleAccountOption
*option
;
113 GList
*list
, *l
, *options
;
115 list
= purple_protocols_get_all();
117 /* Remove protocol preference. */
118 for (l
= list
; l
!= NULL
; l
= l
->next
) {
119 protocol
= PURPLE_PROTOCOL(l
->data
);
120 if (protocol
!= NULL
&& !(purple_protocol_get_options(protocol
) & OPT_PROTO_NO_PASSWORD
)) {
121 options
= purple_protocol_get_account_options(protocol
);
122 while (options
!= NULL
) {
123 option
= (PurpleAccountOption
*) options
->data
;
124 if (strcmp(PREF_NAME
, purple_account_option_get_setting(option
)) == 0) {
125 protocol
->account_options
= g_list_delete_link(protocol
->account_options
, options
);
126 purple_account_option_destroy(option
);
129 options
= options
->next
;
135 /* Callback will be automagically unregistered */
140 PURPLE_PLUGIN_INIT(one_time_password
, plugin_query
, plugin_load
, plugin_unload
);