Ejemplo n.º 1
0
void
password_cache_save (const char *keygrip, const char *password)
{
#ifdef HAVE_LIBSECRET
  char *label;
  GError *error = NULL;

  if (! *keygrip)
    return;

  label = keygrip_to_label (keygrip);
  if (! label)
    return;

  if (! secret_password_store_sync (gpg_schema (),
				    SECRET_COLLECTION_DEFAULT,
				    label, password, NULL, &error,
				    "stored-by", "GnuPG Pinentry",
				    "keygrip", keygrip, NULL))
    {
      fprintf (stderr, "Failed to cache password for key %s with secret service: %s\n",
	     keygrip, error->message);

      g_error_free (error);
    }

  free (label);
#else
  return;
#endif
}
Ejemplo n.º 2
0
gboolean
vino_keyring_set_password (const char *password)
{
  return secret_password_store_sync (SECRET_SCHEMA_COMPAT_NETWORK,
                                     SECRET_COLLECTION_DEFAULT,
                                     _("Remote desktop sharing password"),
                                     password, NULL, NULL,
                                     "server", "vino.local",
                                     "protocol", "rfb",
                                     "authtype", "vnc-password",
                                     "port", 5900,
                                     NULL);
}
Ejemplo n.º 3
0
bool pfUnixPasswordStore::SetPassword(const ST::string& username,
                                      const ST::string& password)
{
    GError *error = nullptr;
    ST::string server = GetServerDisplayName();
    secret_password_store_sync(&pfPasswordStore_Schema, SECRET_COLLECTION_DEFAULT,
                               ST::format("Myst Online Password for {}", server).c_str(),
                               password.c_str(), nullptr, &error,
                               "username", username.c_str(),
                               "server", server.c_str(),
                               nullptr);
    if (error) {
        g_error_free(error);
        return false;
    } else {
        return true;
    }
}
Ejemplo n.º 4
0
void remmina_plugin_glibsecret_store_password(RemminaFile *remminafile, const gchar *key, const gchar *password)
{
	TRACE_CALL(__func__);
	GError *r = NULL;
	const gchar *path;
	gchar *s;

	path = remmina_plugin_service->file_get_path(remminafile);
	s = g_strdup_printf("Remmina: %s - %s", remmina_plugin_service->file_get_string(remminafile, "name"), key);
	secret_password_store_sync(&remmina_file_secret_schema, SECRET_COLLECTION_DEFAULT, s, password,
		NULL, &r, "filename", path, "key", key, NULL);
	g_free(s);
	if (r == NULL) {
		remmina_plugin_service->log_printf("[glibsecret] password \"%s\" saved for file %s\n", key, path);
	}else  {
		remmina_plugin_service->log_printf("[glibsecret] password \"%s\" cannot be saved for file %s\n", key, path);
		g_error_free(r);
	}
}
Ejemplo n.º 5
0
static int _set_integer_value( const SecretSchema * s,const char * name,const char * key,int value )
{
	return secret_password_store_sync( s,"default",name,key,NULL,NULL,"integer",value,NULL ) ;
}
Ejemplo n.º 6
0
static int _set_string_value( const SecretSchema * s,const char * name,const char * key,const char * value )
{
	return secret_password_store_sync( s,"default",name,key,NULL,NULL,"string",value,NULL ) ;
}
Ejemplo n.º 7
0
gboolean
goa_utils_store_credentials_for_id_sync (GoaProvider   *provider,
                                         const gchar   *id,
                                         GVariant      *credentials,
                                         GCancellable  *cancellable,
                                         GError       **error)
{
  gboolean ret;
  gchar *credentials_str;
  gchar *password_description;
  gchar *password_key;
  GError *sec_error = NULL;

  g_return_val_if_fail (GOA_IS_PROVIDER (provider), FALSE);
  g_return_val_if_fail (id != NULL && id[0] != '\0', FALSE);
  g_return_val_if_fail (credentials != NULL, FALSE);
  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  ret = FALSE;

  credentials_str = g_variant_print (credentials, TRUE);
  g_variant_ref_sink (credentials);
  g_variant_unref (credentials);

  password_key = g_strdup_printf ("%s:gen%d:%s",
                                  goa_provider_get_provider_type (GOA_PROVIDER (provider)),
                                  goa_provider_get_credentials_generation (GOA_PROVIDER (provider)),
                                  id);
  /* Translators: The %s is the type of the provider, e.g. 'google' or 'yahoo' */
  password_description = g_strdup_printf (_("GOA %s credentials for identity %s"),
                                          goa_provider_get_provider_type (GOA_PROVIDER (provider)),
                                          id);

  if (!secret_password_store_sync (&secret_password_schema,
                                   SECRET_COLLECTION_DEFAULT, /* default keyring */
                                   password_description,
                                   credentials_str,
                                   cancellable,
                                   &sec_error,
                                   "goa-identity", password_key,
                                   NULL))
    {
      g_warning ("secret_password_store_sync() failed: %s", sec_error->message);
      g_set_error_literal (error,
                           GOA_ERROR,
                           GOA_ERROR_FAILED, /* TODO: more specific */
                           _("Failed to store credentials in the keyring"));
      g_error_free (sec_error);
      goto out;
    }

  g_debug ("Stored keyring credentials for identity: %s", id);
  ret = TRUE;

 out:
  g_free (credentials_str);
  g_free (password_key);
  g_free (password_description);
  return ret;
}
Ejemplo n.º 8
0
LibBalsaImapServer*
libbalsa_imap_server_new_from_config(void)
{
    LibBalsaServer tmp_server;
    LibBalsaImapServer *imap_server;
    LibBalsaServer *server;
    gboolean d, d1;
    gint tls_mode, conn_limit;

    tmp_server.host = libbalsa_conf_get_string("Server");
    if(strrchr(tmp_server.host, ':') == NULL) {
        gint port;
        port = libbalsa_conf_get_int_with_default("Port", &d);
        if (!d) {
            gchar *newhost = g_strdup_printf("%s:%d", tmp_server.host, port);
            g_free(tmp_server.host);
            tmp_server.host = newhost;
        }
    }       
    tmp_server.user = libbalsa_conf_private_get_string("Username");
    if (!tmp_server.user)
        tmp_server.user = g_strdup(getenv("USER"));

    imap_server = get_or_create(tmp_server.user, tmp_server.host);
    server = LIBBALSA_SERVER(imap_server);
    if (server->user) {
        g_free(tmp_server.user);
        g_free(tmp_server.host);
    } else {
        server->user = tmp_server.user;
        server->host = tmp_server.host;
    }
    d1 = libbalsa_conf_get_bool_with_default("Anonymous", &d);
    if(!d) server->try_anonymous = !!d1;
    server->use_ssl |= libbalsa_conf_get_bool("SSL=false");
    tls_mode = libbalsa_conf_get_int_with_default("TLSMode", &d);
    if(!d) server->tls_mode = tls_mode;
    conn_limit = libbalsa_conf_get_int_with_default("ConnectionLimit", &d);
    if(!d) imap_server->max_connections = conn_limit;
    d1 = libbalsa_conf_get_bool_with_default("PersistentCache", &d);
    if(!d) imap_server->persistent_cache = !!d1;
    d1 = libbalsa_conf_get_bool_with_default("HasFetchBug", &d);
    if(!d) imap_server->has_fetch_bug = !!d1;
    d1 = libbalsa_conf_get_bool_with_default("UseStatus", &d);
    if(!d) imap_server->use_status = !!d1;
    d1 = libbalsa_conf_get_bool_with_default("UseIdle", &d);
    if(!d) imap_server->use_idle = !!d1;
    if (!server->passwd) {
        server->remember_passwd = libbalsa_conf_get_bool("RememberPasswd=false");
        if(server->remember_passwd) {
#if defined(HAVE_LIBSECRET)
            GError *err = NULL;

            server->passwd =
                secret_password_lookup_sync(LIBBALSA_SERVER_SECRET_SCHEMA,
                                            NULL, &err,
                                            "protocol", server->protocol,
                                            "server",   server->host,
                                            "user",     server->user,
                                            NULL);
            if (err) {
                libbalsa_free_password(server->passwd);
                server->passwd = NULL;
                printf(_("Error looking up password for %s@%s: %s\n"),
                       server->user, server->host, err->message);
                printf(_("Falling back\n"));
                g_clear_error(&err);
                server->passwd =
                    libbalsa_conf_private_get_string("Password");
                if (server->passwd != NULL) {
                    gchar *buff = libbalsa_rot(server->passwd);
                    libbalsa_free_password(server->passwd);
                    server->passwd = buff;
                    secret_password_store_sync
                        (LIBBALSA_SERVER_SECRET_SCHEMA, NULL,
                         _("Balsa passwords"), server->passwd, NULL, &err,
                         "protocol", server->protocol,
                         "server",   server->host,
                         "user",     server->user,
                         NULL);
                    /* We could in principle clear the password in the
                     * config file here but we do not for the backward
                     * compatibility. */
                    if (err) {
                        printf(_("Error storing password for %s@%s: %s\n"),
                               server->user, server->host, err->message);
                        g_error_free(err);
                    }
                }
            }
#elif defined (HAVE_GNOME_KEYRING)
	    GnomeKeyringResult r;
	    server->passwd = NULL;
	    r = gnome_keyring_find_password_sync(LIBBALSA_SERVER_KEYRING_SCHEMA,
						 &server->passwd,
						 "protocol", server->protocol,
						 "server", server->host,
						 "user", server->user,
						 NULL);
	    if(r != GNOME_KEYRING_RESULT_OK) {
		gnome_keyring_free_password(server->passwd);
		server->passwd = NULL;
		printf("Keyring has no password for %s@%s\n",
		       server->user, server->host);
		server->passwd = libbalsa_conf_private_get_string("Password");
		if (server->passwd != NULL) {
		    gchar *buff = libbalsa_rot(server->passwd);
		    libbalsa_free_password(server->passwd);
		    server->passwd = buff;
	            gnome_keyring_store_password_sync
                        (LIBBALSA_SERVER_KEYRING_SCHEMA, NULL,
                         _("Balsa passwords"), server->passwd,
                         "protocol", server->protocol,
                         "server", server->host,
                         "user", server->user,
                         NULL);
		    /* We could in principle clear the password in the
		       config file here but we do not for the backward
		       compatibility. */
		}
	    }
#else
            server->passwd = libbalsa_conf_private_get_string("Password");
	    if (server->passwd != NULL) {
		gchar *buff = libbalsa_rot(server->passwd);
		libbalsa_free_password(server->passwd);
		server->passwd = buff;
	    }
#endif                          /* defined(HAVE_LIBSECRET) */
	}
        if(server->passwd && server->passwd[0] == '\0') {
            libbalsa_free_password(server->passwd);
            server->passwd = NULL;
        }
    }
    return imap_server;
}