static void
on_get_connection_unix_process_id (DBusPendingCall *pending, gpointer user_data)
{
	on_get_connection_unix_process_id_args *args = user_data;
	DBusMessage *reply = NULL;
	DBusError error = DBUS_ERROR_INIT;
	dbus_uint32_t caller_pid = 0;
	GkdSecretService *self;
	ServiceClient *client;
	const gchar *caller;

	g_return_if_fail (GKD_SECRET_IS_SERVICE (args->self));
	self = args->self;

	/* Get the resulting process ID */
	reply = dbus_pending_call_steal_reply (pending);
	g_return_if_fail (reply);

	caller = dbus_message_get_sender (args->message);
	g_return_if_fail (caller);

	client = g_hash_table_lookup (self->clients, caller);
	if (client == NULL) {

		/* An error returned from GetConnectionUnixProcessID */
		if (dbus_set_error_from_message (&error, reply)) {
			g_message ("couldn't get the caller's unix process id: %s", error.message);
			caller_pid = 0;
			dbus_error_free (&error);

		/* A PID was returned from GetConnectionUnixProcessID */
		} else {
			if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &caller_pid, DBUS_TYPE_INVALID))
				g_return_if_reached ();
		}

		/* Initialize the client object */
		client = g_new0 (ServiceClient, 1);
		client->caller_peer = g_strdup (caller);
		client->caller_pid = caller_pid;
		if (caller_pid != 0)
			client->caller_exec = egg_unix_credentials_executable (caller_pid);
		client->app.applicationData = client;
		client->sessions = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, dispose_and_unref);
		client->prompts = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, dispose_and_unref);

		g_hash_table_replace (self->clients, client->caller_peer, client);

		/* Update default collection each time someone connects */
		update_default (self, TRUE);
	}

	dbus_message_unref (reply);

	/* Dispatch the original message again */
	service_dispatch_message (self, args->message);
}
Ejemplo n.º 2
0
static void
gkd_secret_service_init_aliases (GkdSecretService *self)
{
	self->aliases = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
	g_hash_table_insert (self->aliases, g_strdup ("session"), g_strdup ("session"));
	/* TODO: We should be using CKA_G_LOGIN_COLLECTION */
	g_hash_table_insert (self->aliases, g_strdup ("login"), g_strdup ("login"));

	update_default (self);
}
Ejemplo n.º 3
0
const gchar*
gkd_secret_service_get_alias (GkdSecretService *self, const gchar *alias)
{
	const gchar *identifier;

	g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL);
	g_return_val_if_fail (alias, NULL);

	identifier =  g_hash_table_lookup (self->aliases, alias);
	if (!identifier && g_str_equal (alias, "default")) {
		update_default (self, TRUE);
		identifier = g_hash_table_lookup (self->aliases, alias);
	}
	return identifier;
}
Ejemplo n.º 4
0
static void
initialize_service_client (GkdSecretService *self,
			   const gchar *caller)
{
	ServiceClient *client;

	g_assert (GKD_SECRET_IS_SERVICE (self));
	g_assert (caller);

	/* Initialize the client object */
	client = g_new0 (ServiceClient, 1);
	client->caller_peer = g_strdup (caller);
	client->app.applicationData = client;
	client->dispatch = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, dispose_and_unref);

	g_hash_table_replace (self->clients, client->caller_peer, client);

	/* Update default collection each time someone connects */
	update_default (self, TRUE);
}
static DBusMessage*
service_method_read_alias (GkdSecretService *self, DBusMessage *message)
{
	DBusMessage *reply;
	const char *alias;
	gchar *path = NULL;
	const gchar *identifier;
	GP11Object  *collection = NULL;

	if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &alias, DBUS_TYPE_INVALID))
		return NULL;

	update_default (self, FALSE);

	identifier = gkd_secret_objects_get_alias (self->objects, alias);
	if (identifier)
		path = gkd_secret_util_build_path (SECRET_COLLECTION_PREFIX, identifier, -1);

	/* Make sure it actually exists */
	if (path)
		collection = gkd_secret_objects_lookup_collection (self->objects,
		                                                   dbus_message_get_sender (message), path);
	if (collection == NULL) {
		g_free (path);
		path = NULL;
	} else {
		g_object_unref (collection);
	}

	reply = dbus_message_new_method_return (message);
	if (path == NULL)
		path = g_strdup ("/");
	dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
	g_free (path);

	return reply;
}
Ejemplo n.º 6
0
const gchar*
gkd_secret_service_get_alias (GkdSecretService *self, const gchar *alias)
{
	const gchar *identifier;

	g_return_val_if_fail (GKD_SECRET_IS_SERVICE (self), NULL);
	g_return_val_if_fail (alias != NULL, NULL);

	identifier =  g_hash_table_lookup (self->aliases, alias);
	if (!identifier) {
		if (g_str_equal (alias, "default")) {
			update_default (self, TRUE);
			identifier = g_hash_table_lookup (self->aliases, alias);

			/* Default to to 'login' if no default keyring */
			if (identifier == NULL) {
				identifier = "login";
				g_hash_table_replace (self->aliases, g_strdup (alias),
						      g_strdup (identifier));
			}

		} else if (g_str_equal (alias, "session")) {
			identifier = "session";
			g_hash_table_replace (self->aliases, g_strdup (alias),
					      g_strdup (identifier));

		/* TODO: We should be using CKA_G_LOGIN_COLLECTION */
		} else if (g_str_equal (alias, "login")) {
			identifier = "login";
			g_hash_table_replace (self->aliases, g_strdup (alias),
					      g_strdup (identifier));
		}
	}

	return identifier;
}