mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
Fix up indentation in gnc-keyring.c.
It was partly gnu-style.
This commit is contained in:
parent
2c45e0ecba
commit
08fd3e9797
@ -46,18 +46,18 @@ G_GNUC_UNUSED static QofLogModule log_module = GNC_MOD_GUI;
|
||||
const SecretSchema* gnucash_get_secret_schema(void) G_GNUC_CONST;
|
||||
const SecretSchema* gnucash_get_secret_schema(void)
|
||||
{
|
||||
static const SecretSchema secret_schema = {
|
||||
"org.gnucash.password", SECRET_SCHEMA_NONE,
|
||||
{
|
||||
{ "protocol", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
||||
{ "server", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
||||
{ "port", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
|
||||
{ "user", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
||||
{ "NULL", 0 },
|
||||
}
|
||||
};
|
||||
static const SecretSchema secret_schema = {
|
||||
"org.gnucash.password", SECRET_SCHEMA_NONE,
|
||||
{
|
||||
{ "protocol", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
||||
{ "server", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
||||
{ "port", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
|
||||
{ "user", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
||||
{ "NULL", 0 },
|
||||
}
|
||||
};
|
||||
|
||||
return &secret_schema;
|
||||
return &secret_schema;
|
||||
}
|
||||
|
||||
#define SECRET_SCHEMA_GNUCASH gnucash_get_secret_schema()
|
||||
@ -71,42 +71,42 @@ void gnc_keyring_set_password (const gchar *access_method,
|
||||
const gchar* password)
|
||||
{
|
||||
#ifdef HAVE_LIBSECRET
|
||||
GError* error = NULL;
|
||||
gchar* label = NULL;
|
||||
GError* error = NULL;
|
||||
gchar* label = NULL;
|
||||
|
||||
label = g_strdup_printf("GnuCash password for %s://%s@%s", access_method, user, server);
|
||||
label = g_strdup_printf("GnuCash password for %s://%s@%s", access_method, user, server);
|
||||
|
||||
if (port == 0)
|
||||
secret_password_store_sync (SECRET_SCHEMA_GNUCASH, SECRET_COLLECTION_DEFAULT,
|
||||
label, password, NULL, &error,
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"user", user,
|
||||
NULL);
|
||||
else
|
||||
secret_password_store_sync (SECRET_SCHEMA_GNUCASH, SECRET_COLLECTION_DEFAULT,
|
||||
label, password, NULL, &error,
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"port", port,
|
||||
"user", user,
|
||||
NULL);
|
||||
if (port == 0)
|
||||
secret_password_store_sync (SECRET_SCHEMA_GNUCASH, SECRET_COLLECTION_DEFAULT,
|
||||
label, password, NULL, &error,
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"user", user,
|
||||
NULL);
|
||||
else
|
||||
secret_password_store_sync (SECRET_SCHEMA_GNUCASH, SECRET_COLLECTION_DEFAULT,
|
||||
label, password, NULL, &error,
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"port", port,
|
||||
"user", user,
|
||||
NULL);
|
||||
|
||||
g_free(label);
|
||||
g_free(label);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
PWARN ("libsecret error: %s", error->message);
|
||||
PWARN ("The user will be prompted for a password again next time.");
|
||||
g_error_free(error);
|
||||
}
|
||||
if (error != NULL)
|
||||
{
|
||||
PWARN ("libsecret error: %s", error->message);
|
||||
PWARN ("The user will be prompted for a password again next time.");
|
||||
g_error_free(error);
|
||||
}
|
||||
#elif HAVE_GNOME_KEYRING
|
||||
GnomeKeyringResult gkr_result;
|
||||
guint32 item_id = 0;
|
||||
|
||||
gkr_result = gnome_keyring_set_network_password_sync
|
||||
(NULL, user, NULL, server, service,
|
||||
access_method, NULL, port, password, &item_id);
|
||||
(NULL, user, NULL, server, service,
|
||||
access_method, NULL, port, password, &item_id);
|
||||
|
||||
if (gkr_result != GNOME_KEYRING_RESULT_OK)
|
||||
{
|
||||
@ -126,22 +126,26 @@ void gnc_keyring_set_password (const gchar *access_method,
|
||||
// FIXME I'm not sure this works if a password was already in the keychain
|
||||
// I may have to do a lookup first and if it exists, run some
|
||||
// update function instead
|
||||
status = SecKeychainAddInternetPassword ( NULL, /* keychain */
|
||||
strlen(server), server, /* servername */
|
||||
strlen(access_method), access_method, /* securitydomain */
|
||||
strlen(user), user, /* acountname */
|
||||
strlen(service), service, /* path */
|
||||
port, /* port */
|
||||
kSecProtocolTypeAny, /* protocol */
|
||||
kSecAuthenticationTypeDefault, /* auth type */
|
||||
strlen(password), password, /* passworddata */
|
||||
itemRef );
|
||||
status =
|
||||
SecKeychainAddInternetPassword (NULL, /* keychain */
|
||||
strlen(server), server, /* servername */
|
||||
strlen(access_method),
|
||||
access_method, /* securitydomain */
|
||||
strlen(user), user, /* acountname */
|
||||
strlen(service), service, /* path */
|
||||
port, /* port */
|
||||
kSecProtocolTypeAny, /* protocol */
|
||||
kSecAuthenticationTypeDefault, /* auth type */
|
||||
strlen(password),
|
||||
password, /* passworddata */
|
||||
itemRef );
|
||||
|
||||
if ( status != noErr )
|
||||
{
|
||||
CFStringRef osx_resultstring = SecCopyErrorMessageString( status, NULL );
|
||||
const gchar *resultstring = CFStringGetCStringPtr(osx_resultstring,
|
||||
GetApplicationTextEncoding());
|
||||
const gchar *resultstring =
|
||||
CFStringGetCStringPtr(osx_resultstring,
|
||||
GetApplicationTextEncoding());
|
||||
PWARN ( "OS X keychain error: %s", resultstring );
|
||||
PWARN ( "The user will be prompted for a password again next time." );
|
||||
CFRelease ( osx_resultstring );
|
||||
@ -201,17 +205,17 @@ gboolean gnc_keyring_get_password ( GtkWidget *parent,
|
||||
/* Note: only use the port attribute if it was set by the user. */
|
||||
if (port == 0)
|
||||
libsecret_password = secret_password_lookup_sync (SECRET_SCHEMA_GNUCASH, NULL, &error,
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"user", *user,
|
||||
NULL);
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"user", *user,
|
||||
NULL);
|
||||
else
|
||||
libsecret_password = secret_password_lookup_sync (SECRET_SCHEMA_GNUCASH, NULL, &error,
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"port", port,
|
||||
"user", *user,
|
||||
NULL);
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"port", port,
|
||||
"user", *user,
|
||||
NULL);
|
||||
|
||||
if (libsecret_password != NULL) {
|
||||
*password = g_strdup (libsecret_password);
|
||||
@ -222,11 +226,11 @@ gboolean gnc_keyring_get_password ( GtkWidget *parent,
|
||||
/* No password found yet. Perhaps it was written with a port equal to 0.
|
||||
* Gnucash versions prior to 2.6.7 did this unfortunately... */
|
||||
libsecret_password = secret_password_lookup_sync (SECRET_SCHEMA_GNUCASH, NULL, &error,
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"port", 0,
|
||||
"user", *user,
|
||||
NULL);
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"port", 0,
|
||||
"user", *user,
|
||||
NULL);
|
||||
|
||||
if (libsecret_password != NULL) {
|
||||
*password = g_strdup (libsecret_password);
|
||||
@ -242,19 +246,19 @@ gboolean gnc_keyring_get_password ( GtkWidget *parent,
|
||||
Look for a password stored via gnome-keyring instead */
|
||||
if (port == 0)
|
||||
libsecret_password = secret_password_lookup_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL, &error,
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"object", service,
|
||||
"user", *user,
|
||||
NULL);
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"object", service,
|
||||
"user", *user,
|
||||
NULL);
|
||||
else
|
||||
libsecret_password = secret_password_lookup_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL, &error,
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"port", port,
|
||||
"object", service,
|
||||
"user", *user,
|
||||
NULL);
|
||||
"protocol", access_method,
|
||||
"server", server,
|
||||
"port", port,
|
||||
"object", service,
|
||||
"user", *user,
|
||||
NULL);
|
||||
|
||||
if (libsecret_password != NULL) {
|
||||
*password = g_strdup (libsecret_password);
|
||||
@ -275,8 +279,8 @@ gboolean gnc_keyring_get_password ( GtkWidget *parent,
|
||||
|
||||
#elif HAVE_GNOME_KEYRING
|
||||
gkr_result = gnome_keyring_find_network_password_sync
|
||||
( *user, NULL, server, service,
|
||||
access_method, NULL, port, &found_list );
|
||||
( *user, NULL, server, service,
|
||||
access_method, NULL, port, &found_list );
|
||||
|
||||
if (gkr_result == GNOME_KEYRING_RESULT_OK)
|
||||
{
|
||||
@ -290,7 +294,7 @@ gboolean gnc_keyring_get_password ( GtkWidget *parent,
|
||||
/* Something went wrong while attempting to access libsecret
|
||||
* Log the error message and carry on... */
|
||||
PWARN ("Gnome-keyring access failed: %s.",
|
||||
gnome_keyring_result_to_message(gkr_result));
|
||||
gnome_keyring_result_to_message(gkr_result));
|
||||
gnome_keyring_network_password_list_free(found_list);
|
||||
#endif /* HAVE_LIBSECRET or HAVE_GNOME_KEYRING */
|
||||
|
||||
@ -302,15 +306,15 @@ gboolean gnc_keyring_get_password ( GtkWidget *parent,
|
||||
if (*user != NULL)
|
||||
{
|
||||
status = SecKeychainFindInternetPassword( NULL,
|
||||
strlen(server), server,
|
||||
strlen(access_method), access_method,
|
||||
strlen(*user), *user,
|
||||
strlen(service), service,
|
||||
port,
|
||||
kSecProtocolTypeAny,
|
||||
kSecAuthenticationTypeDefault,
|
||||
&password_length, &password_data,
|
||||
NULL);
|
||||
strlen(server), server,
|
||||
strlen(access_method), access_method,
|
||||
strlen(*user), *user,
|
||||
strlen(service), service,
|
||||
port,
|
||||
kSecProtocolTypeAny,
|
||||
kSecAuthenticationTypeDefault,
|
||||
&password_length, &password_data,
|
||||
NULL);
|
||||
|
||||
if ( status == noErr )
|
||||
{
|
||||
@ -322,7 +326,7 @@ gboolean gnc_keyring_get_password ( GtkWidget *parent,
|
||||
{
|
||||
CFStringRef osx_resultstring = SecCopyErrorMessageString( status, NULL );
|
||||
const gchar *resultstring = CFStringGetCStringPtr(osx_resultstring,
|
||||
GetApplicationTextEncoding());
|
||||
GetApplicationTextEncoding());
|
||||
PWARN ( "OS X keychain error: %s", resultstring );
|
||||
CFRelease ( osx_resultstring );
|
||||
}
|
||||
@ -330,39 +334,39 @@ gboolean gnc_keyring_get_password ( GtkWidget *parent,
|
||||
#endif /* HAVE_OSX_KEYCHAIN */
|
||||
|
||||
/* If we got here, either no proper password store is
|
||||
* available on this system, or we couldn't retrieve
|
||||
* a password from it. In both cases, just ask the user
|
||||
* to enter one
|
||||
*/
|
||||
* available on this system, or we couldn't retrieve
|
||||
* a password from it. In both cases, just ask the user
|
||||
* to enter one
|
||||
*/
|
||||
|
||||
if ( port == 0 )
|
||||
db_path = g_strdup_printf ( "%s://%s/%s", access_method, server, service );
|
||||
else
|
||||
db_path = g_strdup_printf ( "%s://%s:%d/%s", access_method, server, port, service );
|
||||
heading = g_strdup_printf ( /* Translators: %s is a path to a database or any other url,
|
||||
like mysql://user@server.somewhere/somedb, https://www.somequotes.com/thequotes */
|
||||
_("Enter a user name and password to connect to: %s"),
|
||||
db_path );
|
||||
like mysql://user@server.somewhere/somedb, https://www.somequotes.com/thequotes */
|
||||
_("Enter a user name and password to connect to: %s"),
|
||||
db_path );
|
||||
|
||||
password_found = gnc_get_username_password ( parent, heading,
|
||||
*user, NULL,
|
||||
user, password );
|
||||
*user, NULL,
|
||||
user, password );
|
||||
g_free ( db_path );
|
||||
g_free ( heading );
|
||||
|
||||
if ( password_found )
|
||||
{
|
||||
/* User entered new user/password information
|
||||
* Let's try to add it to a password store.
|
||||
*/
|
||||
* Let's try to add it to a password store.
|
||||
*/
|
||||
gchar *newuser = g_strdup( *user );
|
||||
gchar *newpassword = g_strdup( *password );
|
||||
gnc_keyring_set_password ( access_method,
|
||||
server,
|
||||
port,
|
||||
service,
|
||||
newuser,
|
||||
newpassword );
|
||||
server,
|
||||
port,
|
||||
service,
|
||||
newuser,
|
||||
newpassword );
|
||||
g_free ( newuser );
|
||||
g_free ( newpassword );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user