changeset 1816:e255ee1b2f90

Revert accidental keyring fix commit.
author Severin Gehwolf <sgehwolf@redhat.com>
date Tue, 29 Sep 2015 10:20:19 +0200
parents 9360b7767e42
children 1695efcce99d
files keyring/Makefile keyring/src/main/native/GnomeKeyringLibraryNative.c keyring/src/test/java/com/redhat/thermostat/utils/keyring/impl/KeyringImplTest.java
diffstat 3 files changed, 34 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/keyring/Makefile	Tue Sep 29 10:03:49 2015 +0200
+++ b/keyring/Makefile	Tue Sep 29 10:20:19 2015 +0200
@@ -14,8 +14,8 @@
 
 EXECUTABLE = libGnomeKeyringWrapper.so
 
-MYCFLAGS   += `pkg-config --cflags libsecret-1`
-MYLDFLAGS  += `pkg-config --libs libsecret-1`
+MYCFLAGS   += `pkg-config --cflags gnome-keyring-1`
+MYLDFLAGS  += `pkg-config --libs gnome-keyring-1`
 
 .PHONY:
 JNI_LIST = com.redhat.thermostat.utils.keyring.impl.KeyringImpl
--- a/keyring/src/main/native/GnomeKeyringLibraryNative.c	Tue Sep 29 10:03:49 2015 +0200
+++ b/keyring/src/main/native/GnomeKeyringLibraryNative.c	Tue Sep 29 10:20:19 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012-2015 Red Hat, Inc.
+ * Copyright 2012-2014 Red Hat, Inc.
  *
  * This file is part of Thermostat.
  *
@@ -38,18 +38,18 @@
 
 #include <jni.h>
 #include <glib.h>
-#include <libsecret/secret.h>
+#include <gnome-keyring.h>
 #include <stdlib.h>
 #include <string.h>
 
-SecretSchema thermostat_schema = {
-        "com.redhat.thermostat.password", SECRET_SCHEMA_NONE,
-        {
-            { "username", SECRET_SCHEMA_ATTRIBUTE_STRING },
-            { "url", SECRET_SCHEMA_ATTRIBUTE_STRING },
-            { "NULL", 0 }
-        }
-    };
+GnomeKeyringPasswordSchema thermostat_schema = {
+    GNOME_KEYRING_ITEM_GENERIC_SECRET,
+    {
+        { "username", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
+        { "url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
+        { NULL, 0 }
+    }
+};
 
 static void init(void) {
     if (g_get_application_name() == NULL) {
@@ -104,7 +104,7 @@
 
     const char *description = (*env)->GetStringUTFChars(env, jdescription, NULL);
     if (description == NULL) {
-        (*env)->ReleaseStringUTFChars(env, jurl, url);
+    	(*env)->ReleaseStringUTFChars(env, jurl, url);
         (*env)->ReleaseStringUTFChars(env, juserName, userName);
         for (passIndex = 0; passIndex < (int) passwordLength; passIndex++) {
             gpassword[passIndex] = (gchar) '\0';
@@ -114,21 +114,13 @@
     }
 
     init();
-    GError *error = NULL;
-    jboolean is_success = JNI_TRUE;
-    secret_password_store_sync(&thermostat_schema,
-                               SECRET_COLLECTION_DEFAULT,
-                               description,
-                               gpassword,
-                               NULL,
-                               &error,
-                               "username", userName,
-                               "url", url,
-                               NULL);
-    if (error != NULL) {
-        is_success = JNI_FALSE;
-        g_error_free (error);
-    }
+    GnomeKeyringResult res = gnome_keyring_store_password_sync(&thermostat_schema,
+                                                                GNOME_KEYRING_DEFAULT,
+                                                                description,
+                                                                gpassword,
+                                                                "username", userName,
+                                                                "url", url,
+                                                                NULL);
     (*env)->ReleaseStringUTFChars(env, jurl, url);
     (*env)->ReleaseStringUTFChars(env, juserName, userName);
     for (passIndex = 0; passIndex < (int) passwordLength; passIndex++) {
@@ -137,31 +129,31 @@
     free(gpassword);
     (*env)->ReleaseStringUTFChars(env, jdescription, description);
 
-    return is_success;
+    return (res == GNOME_KEYRING_RESULT_OK) ? JNI_TRUE : JNI_FALSE;
 }
 
 JNIEXPORT jbyteArray JNICALL
 Java_com_redhat_thermostat_utils_keyring_impl_KeyringImpl_gnomeKeyringWrapperGetPasswordNative
   (JNIEnv *env, jclass GnomeKeyringLibraryNative, jstring jurl, jstring juserName)
 {
-    const char *url = (*env)->GetStringUTFChars(env, jurl, NULL);
+	const char *url = (*env)->GetStringUTFChars(env, jurl, NULL);
     if (url == NULL) {
+
         return NULL;
     }
 
     const char *userName = (*env)->GetStringUTFChars(env, juserName, NULL);
     if (userName == NULL) {
-        (*env)->ReleaseStringUTFChars(env, jurl, url);
+    	(*env)->ReleaseStringUTFChars(env, jurl, url);
         return NULL;
     }
 
     gchar *password = NULL;
-    GError *error = NULL;
+    GnomeKeyringResult res;
 
     init();
-    password = secret_password_lookup_sync(&thermostat_schema,
-                                           NULL,
-                                           &error,
+    res = gnome_keyring_find_password_sync(&thermostat_schema,
+                                           &password,
                                            "username", userName,
                                            "url", url,
                                            NULL);
@@ -169,20 +161,15 @@
     (*env)->ReleaseStringUTFChars(env, jurl, url);
     (*env)->ReleaseStringUTFChars(env, juserName, userName);
 
-    if (error == NULL) {
-        // Password may be null if not found in secret store
-        if (password == NULL) {
-            return NULL;
-        }
+    if (res == GNOME_KEYRING_RESULT_OK) {
         const jbyte *jbytePassword = (const jbyte *) password;
 
         jsize passwordLength = strlen(password);
         jbyteArray jpassword = (*env)->NewByteArray(env, passwordLength);
         (*env)->SetByteArrayRegion(env, jpassword, 0, passwordLength, jbytePassword);
-        secret_password_free(password);
+        gnome_keyring_free_password(password);
         return jpassword;
     } else {
-        g_error_free(error);
         return NULL;
     }
 }
@@ -202,22 +189,14 @@
     }
 
     init();
-    GError *error = NULL;
-    jboolean is_success = JNI_TRUE;
-    secret_password_clear_sync(&thermostat_schema,
-                               NULL,
-                               &error,
-                               "username", userName,
-                               "url", url,
-                               NULL);
+    GnomeKeyringResult res = gnome_keyring_delete_password_sync(&thermostat_schema,
+                                                                "username", userName,
+                                                                "url", url,
+                                                                NULL);
 
-    if (error != NULL) {
-        is_success = JNI_FALSE;
-        g_error_free (error);
-    }
     (*env)->ReleaseStringUTFChars(env, jurl, url);
     (*env)->ReleaseStringUTFChars(env, juserName, userName);
 
-    return is_success;
+    return (res == GNOME_KEYRING_RESULT_OK) ? JNI_TRUE : JNI_FALSE;
 }
 
--- a/keyring/src/test/java/com/redhat/thermostat/utils/keyring/impl/KeyringImplTest.java	Tue Sep 29 10:03:49 2015 +0200
+++ b/keyring/src/test/java/com/redhat/thermostat/utils/keyring/impl/KeyringImplTest.java	Tue Sep 29 10:20:19 2015 +0200
@@ -43,12 +43,6 @@
 import org.junit.Ignore;
 import org.junit.Test;
 
-/**
- * This test needs property "com.redhat.thermostat.shared.loader.testNativesHome"
- * to be set when run from an IDE. The property value should be the location of
- * the native SO's.
- *
- */
 public class KeyringImplTest {
 
     @Ignore // FIXME Hangs waiting for user to unlock keyring.