besser82 / rpms / pidgin

Forked from rpms/pidgin 6 years ago
Clone
83c545f
/*
83c545f
 * One Time Password support plugin for libpurple
83c545f
 *
83c545f
 * Copyright (C) 2009, Daniel Atallah <datallah@pidgin.im>
83c545f
 *
83c545f
 * This program is free software; you can redistribute it and/or
83c545f
 * modify it under the terms of the GNU General Public License as
83c545f
 * published by the Free Software Foundation; either version 2 of the
83c545f
 * License, or (at your option) any later version.
83c545f
 *
83c545f
 * This program is distributed in the hope that it will be useful, but
83c545f
 * WITHOUT ANY WARRANTY; without even the implied warranty of
83c545f
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
83c545f
 * General Public License for more details.
83c545f
 *
83c545f
 * You should have received a copy of the GNU General Public License
83c545f
 * along with this program; if not, write to the Free Software
83c545f
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
83c545f
 * 02111-1301, USA.
83c545f
 */
83c545f
#include "internal.h"
83c545f
#include "debug.h"
83c545f
#include "plugin.h"
83c545f
#include "version.h"
83c545f
#include "account.h"
83c545f
#include "accountopt.h"
83c545f
83c545f
#define PLUGIN_ID "core-one_time_password"
83c545f
#define PREF_NAME PLUGIN_ID "_enabled"
83c545f
83c545f
static void
83c545f
signed_on_cb(PurpleConnection *conn, void *data)
83c545f
{
83c545f
	PurpleAccount *account = purple_connection_get_account(conn);
83c545f
83c545f
	if (purple_account_get_bool(account, PREF_NAME, FALSE)) {
83c545f
		if(purple_account_get_remember_password(account))
83c545f
			purple_debug_error("One Time Password",
83c545f
					   "Unable to enforce one time password for account %s (%s).\n"
83c545f
					   "Account is set to remember the password.\n",
83c545f
					   purple_account_get_username(account),
83c545f
					   purple_account_get_protocol_name(account));
83c545f
		else {
83c545f
83c545f
			purple_debug_info("One Time Password", "Clearing password for account %s (%s).\n",
83c545f
					  purple_account_get_username(account),
83c545f
					  purple_account_get_protocol_name(account));
83c545f
83c545f
			purple_account_set_password(account, NULL);
83c545f
			/* TODO: Do we need to somehow clear conn->password ? */
83c545f
		}
83c545f
	}
83c545f
}
83c545f
83c545f
static gboolean
83c545f
plugin_load(PurplePlugin *plugin)
83c545f
{
83c545f
	PurplePlugin *prpl;
83c545f
	PurplePluginProtocolInfo *prpl_info;
83c545f
	PurpleAccountOption *option;
83c545f
	GList *l;
83c545f
83c545f
	/* Register protocol preference. */
83c545f
	for (l = purple_plugins_get_protocols(); l != NULL; l = l->next) {
83c545f
		prpl = (PurplePlugin *)l->data;
83c545f
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
83c545f
		if (prpl_info != NULL && !(prpl_info->options & OPT_PROTO_NO_PASSWORD)) {
83c545f
			option = purple_account_option_bool_new(_("One Time Password"),
83c545f
								PREF_NAME, FALSE);
83c545f
			prpl_info->protocol_options = g_list_append(prpl_info->protocol_options, option);
83c545f
		}
83c545f
	}
83c545f
83c545f
	/* Register callback. */
83c545f
	purple_signal_connect(purple_connections_get_handle(), "signed-on",
83c545f
			      plugin, PURPLE_CALLBACK(signed_on_cb), NULL);
83c545f
83c545f
	return TRUE;
83c545f
}
83c545f
83c545f
static gboolean
83c545f
plugin_unload(PurplePlugin *plugin)
83c545f
{
83c545f
	PurplePlugin *prpl;
83c545f
	PurplePluginProtocolInfo *prpl_info;
83c545f
	PurpleAccountOption *option;
83c545f
	GList *l, *options;
83c545f
83c545f
	/* Remove protocol preference. */
83c545f
	for (l = purple_plugins_get_protocols(); l != NULL; l = l->next) {
83c545f
		prpl = (PurplePlugin *)l->data;
83c545f
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
83c545f
		if (prpl_info != NULL && !(prpl_info->options & OPT_PROTO_NO_PASSWORD)) {
83c545f
			options = prpl_info->protocol_options;
83c545f
			while (options != NULL) {
83c545f
				option = (PurpleAccountOption *) options->data;
83c545f
				if (strcmp(PREF_NAME, purple_account_option_get_setting(option)) == 0) {
83c545f
					prpl_info->protocol_options = g_list_delete_link(prpl_info->protocol_options, options);
83c545f
					purple_account_option_destroy(option);
83c545f
					break;
83c545f
				}
83c545f
				options = options->next;
83c545f
			}
83c545f
		}
83c545f
	}
83c545f
83c545f
	/* Callback will be automagically unregistered */
83c545f
83c545f
	return TRUE;
83c545f
}
83c545f
83c545f
static PurplePluginInfo info =
83c545f
{
83c545f
	PURPLE_PLUGIN_MAGIC,
83c545f
	PURPLE_MAJOR_VERSION,
83c545f
	PURPLE_MINOR_VERSION,
83c545f
	PURPLE_PLUGIN_STANDARD,				/**< type           */
83c545f
	NULL,						/**< ui_requirement */
83c545f
	0,						/**< flags          */
83c545f
	NULL,						/**< dependencies   */
83c545f
	PURPLE_PRIORITY_DEFAULT,			/**< priority       */
83c545f
	PLUGIN_ID,					/**< id             */
83c545f
	N_("One Time Password Support"),		/**< name           */
83c545f
	DISPLAY_VERSION,				/**< version        */
83c545f
							/**  summary        */
83c545f
	N_("Enforce that passwords are used only once."),
83c545f
							/**  description    */
83c545f
	N_("Allows you to enforce on a per-account basis that passwords not "
83c545f
	   "being saved are only used in a single successful connection.\n"
83c545f
	   "Note: The account password must not be saved for this to work."),
83c545f
	"Daniel Atallah <datallah@pidgin.im>",		/**< author         */
83c545f
	PURPLE_WEBSITE,					/**< homepage       */
83c545f
	plugin_load,					/**< load           */
83c545f
	plugin_unload,					/**< unload         */
83c545f
	NULL,						/**< destroy        */
83c545f
	NULL,						/**< ui_info        */
83c545f
	NULL,						/**< extra_info     */
83c545f
	NULL,						/**< prefs_info     */
83c545f
	NULL,						/**< actions        */
83c545f
	NULL,						/**< reserved 1     */
83c545f
	NULL,						/**< reserved 2     */
83c545f
	NULL,						/**< reserved 3     */
83c545f
	NULL						/**< reserved 4     */
83c545f
};
83c545f
83c545f
static void
83c545f
init_plugin(PurplePlugin *plugin)
83c545f
{
83c545f
}
83c545f
83c545f
PURPLE_INIT_PLUGIN(one_time_password, init_plugin, info)