static gboolean password_get_hook(gpointer source, gpointer hook_data) { PasswordRequest *req = source; GError* error = NULL; gchar *pass; // "full search" debug_print("LIBSECRET:: user: %s, server: %s, proto: %s \n", req->user, req->server, req->protocol); pass = secret_password_lookup_sync(GENERIC_SCHEMA, NULL, &error, "user", req->user, "server", req->server, "protocol", req->protocol, NULL); if (pass != NULL) { req->password = g_strdup(pass); secret_password_free(pass); return TRUE; } else if (error != NULL) { debug_print("libsecret access failed: %s.", error->message); g_error_free(error); return FALSE; } // fallback debug_print("LIBSECRET:: user: %s, server: %s \n", req->user, req->server); pass = secret_password_lookup_sync(GENERIC_SCHEMA, NULL, &error, "user", req->user, "server", req->server, NULL); if (pass != NULL) { req->password = g_strdup(pass); secret_password_free(pass); return TRUE; } else if (error != NULL) { debug_print("libsecret access failed: %s.", error->message); g_error_free(error); return FALSE; } return FALSE; }
static void dwb_pwd_free(dwb_pwd_t *pwd) { g_return_if_fail(pwd != NULL); g_free(pwd->collection); g_free(pwd->label); g_free(pwd->id); if (pwd->pwd != NULL) { secret_password_free(pwd->pwd); } g_free(pwd); }
static void on_lookup_pwd(GObject *o, GAsyncResult *result, dwb_secret_t *secret) { GError *e = NULL; char *pwd = secret_password_lookup_finish(result, &e); if (e == NULL) { invoke(secret, DWB_SECRET_OK, pwd); secret_password_free(pwd); } else { invoke(secret, DWB_SECRET_ERROR, NULL); g_error_free(e); } }
int main () { GError *error = NULL; gchar *password = secret_password_lookup_sync (FOO_SCHEMA, NULL, &error, NULL); if (error != NULL) { g_critical ("%s\n", error->message); g_error_free (error); return 1; } g_message ("Password %s\n", password); secret_password_free (password); return 0; }
std::string Ring::find_password(const std::map<std::string, std::string> & atts) { GHashTable *attributes = keyring_attributes(atts); GError *error = NULL; gchar *result = secret_password_lookupv_sync(&s_schema, attributes, NULL, &error); g_hash_table_unref(attributes); if(error) { KeyringException e(error->message); g_error_free(error); throw e; } std::string res; if(result) { res = result; secret_password_free(result); } return res; }
/***************************************************************************** ** pfUnixPasswordStore ** *****************************************************************************/ ST::string pfUnixPasswordStore::GetPassword(const ST::string& username) { GError *error = nullptr; gchar *password = secret_password_lookup_sync(&pfPasswordStore_Schema, nullptr, &error, "username", username.c_str(), "server", GetServerDisplayName().c_str(), nullptr); ST::string result; if (error) { // Throw away the error and treat it as if no password was found... g_error_free(error); } else if (password) { result = ST::string::from_utf8(password); secret_password_free(password); } return result; }
gchar* remmina_plugin_glibsecret_get_password(RemminaFile *remminafile, const gchar *key) { TRACE_CALL(__func__); GError *r = NULL; const gchar *path; gchar *password; gchar *p; path = remmina_plugin_service->file_get_path(remminafile); password = secret_password_lookup_sync(&remmina_file_secret_schema, NULL, &r, "filename", path, "key", key, NULL); if (r == NULL) { // remmina_plugin_service->log_printf("[glibsecret] found password for file %s\n", path); p = g_strdup(password); secret_password_free(password); return p; }else { remmina_plugin_service->log_printf("[glibsecret] password cannot be found for file %s\n", path); return NULL; } }
char * password_cache_lookup (const char *keygrip) { #ifdef HAVE_LIBSECRET GError *error = NULL; char *password; char *password2; if (! *keygrip) return NULL; password = secret_password_lookup_nonpageable_sync (gpg_schema (), NULL, &error, "keygrip", keygrip, NULL); if (error != NULL) { fprintf (stderr, "Failed to lookup password for key %s with secret service: %s\n", keygrip, error->message); g_error_free (error); return NULL; } if (! password) /* The password for this key is not cached. Just return NULL. */ return NULL; /* The password needs to be returned in secmem allocated memory. */ password2 = secmem_malloc (strlen (password) + 1); if (password2) strcpy(password2, password); else fprintf (stderr, "secmem_malloc failed: can't copy password!\n"); secret_password_free (password); return password2; #else return NULL; #endif }