[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: svn commit: r34977 - trunk/subversion/libsvn_auth_gnome_keyring

From: Bert Huijben <rhuijben_at_sharpsvn.net>
Date: Tue, 30 Dec 2008 13:44:32 +0100

> -----Original Message-----
> From: Senthil Kumaran S [mailto:senthil_at_collab.net]
> Sent: Tuesday, December 30, 2008 11:27 AM
> To: svn_at_subversion.tigris.org
> Subject: svn commit: r34977 -
> trunk/subversion/libsvn_auth_gnome_keyring
>
> Author: stylesen
> Date: Tue Dec 30 02:26:56 2008
> New Revision: 34977
>
> Log:
> Prompts for default keyring password if the keyring is locked
> and unlocks the keyring.
>
> * subversion/libsvn_auth_gnome_keyring/gnome_keyring.c
> (gnome_keyring_baton): New struct.
> (callback_destroy_data_keyring): New helper function to do cleanup.
> (callback_done): New helper function.
> (callback_get_info_keyring): New helper function to handle keyring
> details.
> (callback_default_keyring): New helper function for getting the
> default
> keyring name.
> (gnome_keyring_unlock_keyring): New function, which will prompt for
> the keyring password and unlocks the keyring if it is already
> locked.
> (gnome_keyring_password_get): Use gnome_keyring_unlock_keyring()
> to unlock a keyring and later do the cleanup.
> (gnome_keyring_password_set): Use gnome_keyring_unlock_keyring()
> to unlock a keyring and later do the cleanup.
>
> Patch by: Alexander Thomas <alexander_at_collab.net>
> (Tweaked by me)
>
> Modified:
> trunk/subversion/libsvn_auth_gnome_keyring/gnome_keyring.c
>
> Modified: trunk/subversion/libsvn_auth_gnome_keyring/gnome_keyring.c
> URL:
> http://svn.collab.net/viewvc/svn/trunk/subversion/libsvn_auth_gnome_key
> ring/gnome_keyring.c?pathrev=34977&r1=34976&r2=34977
> =======================================================================
> =======
> --- trunk/subversion/libsvn_auth_gnome_keyring/gnome_keyring.c Mon
> Dec 29 20:36:16 2008 (r34976)
> +++ trunk/subversion/libsvn_auth_gnome_keyring/gnome_keyring.c Tue
> Dec 30 02:26:56 2008 (r34977)
> @@ -26,6 +26,8 @@
> #include "svn_auth.h"
> #include "svn_config.h"
> #include "svn_error.h"
> +#include "svn_pools.h"
> +#include "svn_cmdline.h"
>
> #include "private/svn_auth_private.h"
>
> @@ -40,6 +42,167 @@
> /* GNOME Keyring simple provider, puts passwords in GNOME Keyring
> */
> /*--------------------------------------------------------------------
> ---*/
>
> +struct gnome_keyring_baton
> +{
> + const char *keyring_name;
> + GnomeKeyringInfo *info;
> + GMainLoop *loop;
> +};
> +
> +
> +/* Callback function to destroy gnome_keyring_baton. */
> +static void
> +callback_destroy_data_keyring(void *data)
> +{
> + struct gnome_keyring_baton *key_info =
> + (struct gnome_keyring_baton*) data;
> +
> + if (data == NULL)
> + return;
> +
> + if (key_info->keyring_name)
> + {
> + free((void*)key_info->keyring_name);
> + key_info->keyring_name = NULL;
> + }
> +
> + if (key_info->info)
> + {
> + gnome_keyring_info_free(key_info->info);
> + key_info->info = NULL;
> + }
> +
> + return;
> +}
> +
> +
> +/* Callback function to complete the keyring operation. */
> +static void
> +callback_done (GnomeKeyringResult result,
> + gpointer data)
> +{
> + struct gnome_keyring_baton *key_info =
> + (struct gnome_keyring_baton*) data;
> +
> + g_main_loop_quit(key_info->loop);
> + return;
> +}
> +
> +
> +/* Callback function to get the keyring info. */
> +static void
> +callback_get_info_keyring(GnomeKeyringResult result,
> + GnomeKeyringInfo *info,
> + void *data)
> +{
> + struct gnome_keyring_baton *key_info =
> + (struct gnome_keyring_baton*) data;
> +
> + if (result == GNOME_KEYRING_RESULT_OK && info != NULL)
> + {
> + key_info->info = gnome_keyring_info_copy(info);
> + }
> + else
> + {
> + if (key_info->info != NULL)
> + gnome_keyring_info_free(key_info->info);
> +
> + key_info->info = NULL;
> + }
> +
> + g_main_loop_quit(key_info->loop);
> +
> + return;
> +}
> +
> +
> +/* Callback function to get the default keyring string name. */
> +static void
> +callback_default_keyring(GnomeKeyringResult result,
> + const char *string,
> + void *data)
> +{
> + struct gnome_keyring_baton *key_info =
> + (struct gnome_keyring_baton*) data;
> +
> + if (result == GNOME_KEYRING_RESULT_OK && string != NULL)
> + {
> + key_info->keyring_name = strdup(string);
> + }
> + else
> + {
> + if (key_info->keyring_name != NULL)
> + free((void*)key_info->keyring_name);
> + key_info->keyring_name = NULL;
> + }
> +
> + g_main_loop_quit(key_info->loop);
> +
> + return;
> +}
> +
> +/* If the default keyring is locked, prompts for keyring password and
> + * unlocks the keyring. Returns default keyring name if successfully
> + * unlocked, else NULL. */
> +static char*
> +gnome_keyring_unlock_keyring(apr_pool_t *pool)
> +{
> + char *def = NULL;
> + struct gnome_keyring_baton key_info;
> +
> + key_info.info = NULL;
> + key_info.keyring_name = NULL;
> +
> + /* Finds default keyring. */
> + key_info.loop = g_main_loop_new(NULL, FALSE);
> + gnome_keyring_get_default_keyring(
> + (GnomeKeyringOperationGetStringCallback)callback_default_keyring,
> + (void*)&key_info, NULL);
> + g_main_loop_run(key_info.loop);
> +
> + if (key_info.keyring_name == NULL)
> + {
> + callback_destroy_data_keyring((void*)&key_info);
> + return NULL;
> + }
> +
> + /* Get details about the default keyring. */
> + key_info.loop = g_main_loop_new(NULL, FALSE);
> + gnome_keyring_get_info(key_info.keyring_name,
> +
> (GnomeKeyringOperationGetKeyringInfoCallback)callback_get_info_keyring,
> + (void*)&key_info, NULL);
> + g_main_loop_run(key_info.loop);
> +
> + if (key_info.info == NULL)
> + {
> + callback_destroy_data_keyring((void*)&key_info);
> + return NULL;
> + }
> +
> + /* Check if default keyring is locked. */
> + if (gnome_keyring_info_get_is_locked(key_info.info))
> + {
> + char *prompt;
> + svn_auth_cred_simple_t *cred;
> + apr_pool_t *subpool = svn_pool_create(pool);
> +
> + prompt = apr_psprintf(subpool, "[%s] keyring",
> key_info.keyring_name);
> + svn_cmdline_auth_simple_prompt(&cred, NULL, NULL, prompt, TRUE,
> subpool);

This will create a commandline prompt from a library function. It would make
non commandline programs (Eclipse? RapidSVN?) ask a password via a
commandline.

Please add a prompt handler for this kind of actions, like all other
interactive providers do. (Or use the default password prompt handler if
that would be possible). A library should never talk to the end user, unless
the application explicitly asks so.

        Bert

> + svn_pool_destroy(subpool);
> +
> + key_info.loop = g_main_loop_new(NULL, FALSE);
> + gnome_keyring_unlock(key_info.keyring_name, cred->password,
> + (GnomeKeyringOperationDoneCallback)callback_done,
> + (void*)&key_info, NULL);
> + g_main_loop_run(key_info.loop);
> + }
> +
> + def = strdup(key_info.keyring_name);
> + callback_destroy_data_keyring((void*)&key_info);
> +
> + return (def);
> +}
> +
> /* Implementation of password_get_t that retrieves the password
> from GNOME Keyring. */
> static svn_boolean_t
> @@ -51,6 +214,8 @@ gnome_keyring_password_get(const char **
> svn_boolean_t non_interactive,
> apr_pool_t *pool)
> {
> + char *default_keyring = NULL;
> +
> if (non_interactive)
> {
> return FALSE;
> @@ -66,6 +231,8 @@ gnome_keyring_password_get(const char **
> return FALSE;
> }
>
> + default_keyring = gnome_keyring_unlock_keyring(pool);
> +
> GnomeKeyringResult result;
> GList *items;
> svn_boolean_t ret = FALSE;
> @@ -109,6 +276,9 @@ gnome_keyring_password_get(const char **
> "");
> }
>
> + if (default_keyring)
> + free(default_keyring);
> +
> return ret;
> }
>
> @@ -123,6 +293,8 @@ gnome_keyring_password_set(apr_hash_t *c
> svn_boolean_t non_interactive,
> apr_pool_t *pool)
> {
> + char *default_keyring = NULL;
> +
> if (non_interactive)
> {
> return FALSE;
> @@ -138,6 +310,8 @@ gnome_keyring_password_set(apr_hash_t *c
> return FALSE;
> }
>
> + default_keyring = gnome_keyring_unlock_keyring(pool);
> +
> GnomeKeyringResult result;
> guint32 item_id;
>
> @@ -163,6 +337,9 @@ gnome_keyring_password_set(apr_hash_t *c
> "");
> }
>
> + if (default_keyring)
> + free(default_keyring);
> +
> return result == GNOME_KEYRING_RESULT_OK;
> }
>
> ------------------------------------------------------
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=495&dsMessageI
> d=995792

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=995904
Received on 2008-12-30 15:16:36 CET

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.