Пример #1
0
static void
gkm_secret_item_real_set_attribute (GkmObject *base, GkmSession *session,
                                    GkmTransaction *transaction, CK_ATTRIBUTE_PTR attr)
{
	GkmSecretItem *self = GKM_SECRET_ITEM (base);
	const gchar *identifier;
	GkmSecretData *sdata;
	GHashTable *fields;
	gchar *schema_name;
	GkmSecret *secret;
	gchar *schema;
	CK_RV rv;

	if (!self->collection) {
		gkm_transaction_fail (transaction, CKR_GENERAL_ERROR);
		g_return_if_reached ();
	}

	/* Check that the object is not locked */
	if (!gkm_secret_collection_unlocked_have (self->collection, session)) {
		gkm_transaction_fail (transaction, CKR_USER_NOT_LOGGED_IN);
		return;
	}

	switch (attr->type) {
	case CKA_VALUE:
		sdata = gkm_secret_collection_unlocked_use (self->collection, session);
		g_return_if_fail (sdata);
		identifier = gkm_secret_object_get_identifier (GKM_SECRET_OBJECT (self));
		secret = gkm_secret_new (attr->pValue, attr->ulValueLen);
		gkm_secret_data_set_transacted (sdata, transaction, identifier, secret);
		g_object_unref (secret);
		g_object_unref (sdata);
		gkm_secret_object_begin_modified (GKM_SECRET_OBJECT (self), transaction);
		if (!gkm_transaction_get_failed (transaction))
			gkm_transaction_add (transaction, self, complete_set_secret, NULL);
		return;

	case CKA_G_FIELDS:
		rv = gkm_secret_fields_parse (attr, &fields, &schema_name);
		if (rv != CKR_OK) {
			gkm_transaction_fail (transaction, rv);
		} else {
			begin_set_fields (self, transaction, fields);
			if (schema_name)
				begin_set_schema (self, transaction, schema_name);
		}
		return;

	case CKA_G_SCHEMA:
		rv = gkm_attribute_get_string (attr, &schema);
		if (rv != CKR_OK)
			gkm_transaction_fail (transaction, rv);
		else
			begin_set_schema (self, transaction, schema);
		return;
	}

	GKM_OBJECT_CLASS (gkm_secret_item_parent_class)->set_attribute (base, session, transaction, attr);
}
Пример #2
0
static void
setup_item_from_info (GkmSecretItem *item, GkmSecretData *data, ItemInfo *info)
{
	GkmSecretObject *obj = GKM_SECRET_OBJECT (item);
	const gchar *schema_name;
	GkmSecret *secret;

	gkm_secret_object_set_label (obj, info->display_name);
	gkm_secret_object_set_created (obj, info->ctime);
	gkm_secret_object_set_modified (obj, info->mtime);

	schema_name = g_hash_table_lookup (info->attributes, GKM_SECRET_FIELD_SCHEMA);
	if (schema_name == NULL)
		schema_name = gkm_secret_compat_format_item_type (info->type);
	gkm_secret_item_set_schema (item, schema_name);

	gkm_secret_item_set_fields (item, info->attributes);

	/* Collection is locked */
	if (!data) {
		g_object_set_data (G_OBJECT (item), "compat-acl", NULL);

	} else {
		secret = gkm_secret_new (info->ptr_secret, info->n_secret);
		gkm_secret_data_set_secret (data, gkm_secret_object_get_identifier (obj), secret);
		g_object_unref (secret);
		g_object_set_data_full (G_OBJECT (item), "compat-acl", info->acl, gkm_secret_compat_acl_free);
		info->acl = NULL;
	}
}
Пример #3
0
int
main(int argc, char* argv[])
{
	const gchar *password;
	GkmDataResult res;
	GkmMate2File *file;
	GkmSecret *login;
	int fd;

	g_type_init ();
	gkm_crypto_initialize ();

	if (argc != 2)
		failure ("usage: dump-data-file filename");

	fd = open (argv[1], O_RDONLY, 0);
	if (fd == -1)
		failure ("dump-data-file: couldn't open file: %s: %s", argv[1], g_strerror (errno));

	password = getpass ("Password: "******"dump-data-file: failed to read file: %s", argv[1]);
	case GKM_DATA_LOCKED:
		failure ("dump-data-file: invalid password for file: %s", argv[1]);
	case GKM_DATA_UNRECOGNIZED:
		failure ("dump-data-file: unparseable file format: %s", argv[1]);
	case GKM_DATA_SUCCESS:
		break;
	default:
		g_assert_not_reached ();
	}

	gkm_mate2_file_dump (file);
	g_object_unref (file);

	return 0;
}