Implemented PTS attributes Request File Metadata, Unix-Style File Metadata

This commit is contained in:
Sansar Choinyambuu
2011-09-10 22:39:55 +02:00
committed by Andreas Steffen
parent 31ac5b0d6b
commit d883495418
10 changed files with 1132 additions and 5 deletions
+3 -1
View File
@@ -463,6 +463,7 @@ static bool has_tpm(private_pts_t *this)
TSS_HCONTEXT hContext;
TSS_HTPM hTPM;
TSS_RESULT result;
u_int32_t version_info_len;
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS)
@@ -480,8 +481,9 @@ static bool has_tpm(private_pts_t *this)
goto err;
}
result = Tspi_TPM_GetCapability(hTPM, TSS_TPMCAP_VERSION_VAL, 0, NULL,
&this->tpm_version_info.len,
&version_info_len,
&this->tpm_version_info.ptr);
this->tpm_version_info.len = version_info_len;
if (result != TSS_SUCCESS)
{
goto err;
+135
View File
@@ -0,0 +1,135 @@
/*
* Copyright (C) 2011 Sansar Choinyambuu
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "pts_file_meta.h"
#include <utils/linked_list.h>
#include <debug.h>
typedef struct private_pts_file_meta_t private_pts_file_meta_t;
/**
* Private data of a pts_file_meta_t object.
*
*/
struct private_pts_file_meta_t {
/**
* Public pts_file_meta_t interface.
*/
pts_file_meta_t public;
/**
* List of File Metadata
*/
linked_list_t *list;
};
/**
* Free an pts_file_metadata_t object
*/
static void free_entry(pts_file_metadata_t *entry)
{
if (entry)
{
free(entry->filename);
free(entry);
}
}
METHOD(pts_file_meta_t, get_file_count, int,
private_pts_file_meta_t *this)
{
return this->list->get_count(this->list);
}
METHOD(pts_file_meta_t, add, void,
private_pts_file_meta_t *this, char *filename, pts_file_type_t type,
u_int64_t filesize, time_t create_time, time_t last_modify_time, time_t last_access_time,
u_int64_t owner_id, u_int64_t group_id)
{
pts_file_metadata_t *entry;
entry = malloc_thing(pts_file_metadata_t);
entry->filename = strdup(filename);
entry->meta_length = PTS_FILE_METADATA_SIZE + strlen(entry->filename);
entry->type = type;
entry->filesize = filesize;
entry->create_time = create_time;
entry->last_modify_time = last_modify_time;
entry->last_access_time = last_access_time;
entry->owner_id = owner_id;
entry->group_id = group_id;
this->list->insert_last(this->list, entry);
}
/**
* Enumerate file metadata entries
*/
static bool entry_filter(void *null, pts_file_metadata_t **entry,
char **filename, void *i2, u_int16_t *meta_length, void *i3,
pts_file_type_t *type, void *i4, u_int64_t *filesize, void *i5,
time_t *create_time, void *i6, time_t *last_modify_time, void *i7,
time_t *last_access_time, void *i8, u_int64_t *owner_id, void *i9,
u_int64_t *group_id)
{
*filename = (*entry)->filename;
*meta_length = (*entry)->meta_length;
*type = (*entry)->type;
*filesize = (*entry)->filesize;
*create_time = (*entry)->create_time;
*last_modify_time = (*entry)->last_modify_time;
*last_access_time = (*entry)->last_access_time;
*owner_id = (*entry)->owner_id;
*group_id = (*entry)->group_id;
return TRUE;
}
METHOD(pts_file_meta_t, create_enumerator, enumerator_t*,
private_pts_file_meta_t *this)
{
return enumerator_create_filter(this->list->create_enumerator(this->list),
(void*)entry_filter, NULL, NULL);
}
METHOD(pts_file_meta_t, destroy, void,
private_pts_file_meta_t *this)
{
this->list->destroy_function(this->list, (void *)free_entry);
free(this);
}
/**
* See header
*/
pts_file_meta_t *pts_file_meta_create()
{
private_pts_file_meta_t *this;
INIT(this,
.public = {
.get_file_count = _get_file_count,
.add = _add,
.create_enumerator = _create_enumerator,
.destroy = _destroy,
},
.list = linked_list_create(),
);
return &this->public;
}
+91
View File
@@ -0,0 +1,91 @@
/*
* Copyright (C) 2011 Sansar Choinyambuu
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup pts_file_meta pts_file_meta
* @{ @ingroup pts
*/
#ifndef PTS_FILE_META_H_
#define PTS_FILE_META_H_
#include "pts_file_type.h"
#include <time.h>
#include <library.h>
typedef struct pts_file_meta_t pts_file_meta_t;
typedef struct pts_file_metadata_t pts_file_metadata_t;
/* Without filename field included */
#define PTS_FILE_METADATA_SIZE 52
/**
* Structure holding file metadata
*/
struct pts_file_metadata_t {
u_int16_t meta_length;
pts_file_type_t type;
u_int64_t filesize;
time_t create_time;
time_t last_modify_time;
time_t last_access_time;
u_int64_t owner_id;
u_int64_t group_id;
char *filename;
};
/**
* Class storing PTS File Metadata
*/
struct pts_file_meta_t {
/**
* Get the number of files
*
* @return Number of files
*/
int (*get_file_count)(pts_file_meta_t *this);
/**
* Add a PTS File Metadata
*
* @param filename Name of measured file or directory
* @param metadata File metadata
*/
void (*add)(pts_file_meta_t *this, char *filename, pts_file_type_t type,
u_int64_t filesize, time_t create_time, time_t last_modfy_time, time_t last_access_time,
u_int64_t owner_id, u_int64_t group_id);
/**
* Create a PTS File Metadata enumerator
*
* @return Enumerator returning file metadata
*/
enumerator_t* (*create_enumerator)(pts_file_meta_t *this);
/**
* Destroys a pts_file_meta_t object.
*/
void (*destroy)(pts_file_meta_t *this);
};
/**
* Creates a pts_file_meta_t object
*/
pts_file_meta_t* pts_file_meta_create();
#endif /** PTS_FILE_MEAS_H_ @}*/
+49
View File
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2011 Sansar Choinyambuu
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup pts_file_type pts_file_type
* @{ @ingroup pts
*/
#ifndef PTS_FILE_TYPE_H_
#define PTS_FILE_TYPE_H_
typedef enum pts_file_type_t pts_file_type_t;
/**
* PTS File Type
* see section 3.17.3 of PTS Protocol: Binding to TNC IF-M Specification
*/
enum pts_file_type_t {
/** Ignore */
PTS_FILE_OTHER = 0x0000,
/** CRTM */
PTS_FILE_FIFO = 0x0001,
/** BIOS */
PTS_FILE_CHAR_SPEC = 0x0002,
/** Platform Extensions */
PTS_FILE_DIRECTORY = 0x0004,
/** Motherboard firmware */
PTS_FILE_BLOCK_SPEC = 0x0006,
/** Initial Program Loader */
PTS_FILE_REGULAR = 0x0008,
/** Option ROMs */
PTS_FILE_SYM_LINK = 0x000A,
/** Option ROMs */
PTS_FILE_SOCKET = 0x000C,
};
#endif /** PTS_FILE_TYPE_H_ @}*/