swtpm: Remove all interface functions from swtpm_nvstore_dir.h

Remove all interface functions from swtpm_nvstore_dir.h and make them
static in swtpm_nvstore_dir.c. This way we avoid direct calls to these
functions from elsewhere.

Move the declaration of the interface structure into swtpm_nvstore.h
to get rid of swtpm_nvstore_dir.h entirely.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2021-09-24 20:24:32 -04:00 committed by Stefan Berger
parent 78137e819f
commit 3d8b87611c
5 changed files with 24 additions and 100 deletions

View File

@ -25,7 +25,6 @@ noinst_HEADERS = \
swtpm_debug.h \
swtpm_io.h \
swtpm_nvstore.h \
swtpm_nvstore_dir.h \
threadpool.h \
tlv.h \
tpmlib.h \

View File

@ -87,7 +87,6 @@
#include "swtpm_aes.h"
#include "swtpm_debug.h"
#include "swtpm_nvstore.h"
#include "swtpm_nvstore_dir.h"
#include "key.h"
#include "logging.h"
#include "tpmstate.h"

View File

@ -123,6 +123,11 @@ struct nvram_backend_ops {
const char *uri);
void (*cleanup)(void);
};
/* backend interfaces */
extern struct nvram_backend_ops nvram_dir_ops;
int SWTPM_NVRAM_PrintJson(void);
#endif /* _SWTPM_NVSTORE_H */

View File

@ -52,21 +52,14 @@
#include "swtpm.h"
#include "swtpm_debug.h"
#include "swtpm_nvstore.h"
#include "swtpm_nvstore_dir.h"
#include "key.h"
#include "logging.h"
#include "tpmstate.h"
#include "utils.h"
static int lock_fd = -1;
#define TPM_FILENAME_MAX 20
struct nvram_backend_ops nvram_dir_ops = {
.prepare = SWTPM_NVRAM_Prepare_Dir,
.load = SWTPM_NVRAM_LoadData_Dir,
.store = SWTPM_NVRAM_StoreData_Dir,
.delete = SWTPM_NVRAM_DeleteName_Dir,
.cleanup = SWTPM_NVRAM_Cleanup_Dir,
};
static int lock_fd = -1;
static const char *
SWTPM_NVRAM_Uri_to_Dir(const char *uri)
@ -180,7 +173,7 @@ SWTPM_NVRAM_GetFilepathForName(char *filepath, /* output: rooted file path
return rc;
}
TPM_RESULT
static TPM_RESULT
SWTPM_NVRAM_Prepare_Dir(const char *uri)
{
TPM_RESULT rc = 0;
@ -195,13 +188,13 @@ SWTPM_NVRAM_Prepare_Dir(const char *uri)
return rc;
}
void
static void
SWTPM_NVRAM_Cleanup_Dir(void)
{
SWTPM_NVRAM_Unlock_Dir();
}
TPM_RESULT
static TPM_RESULT
SWTPM_NVRAM_LoadData_Dir(unsigned char **data,
uint32_t *length,
uint32_t tpm_number,
@ -305,7 +298,7 @@ SWTPM_NVRAM_LoadData_Dir(unsigned char **data,
return rc;
}
TPM_RESULT
static TPM_RESULT
SWTPM_NVRAM_StoreData_Dir(unsigned char *filedata,
uint32_t filedata_length,
uint32_t tpm_number,
@ -446,10 +439,11 @@ SWTPM_NVRAM_StoreData_Dir(unsigned char *filedata,
return rc;
}
TPM_RESULT SWTPM_NVRAM_DeleteName_Dir(uint32_t tpm_number,
const char *name,
TPM_BOOL mustExist,
const char *uri)
static TPM_RESULT
SWTPM_NVRAM_DeleteName_Dir(uint32_t tpm_number,
const char *name,
TPM_BOOL mustExist,
const char *uri)
{
TPM_RESULT rc = 0;
int irc;
@ -476,3 +470,11 @@ TPM_RESULT SWTPM_NVRAM_DeleteName_Dir(uint32_t tpm_number,
}
return rc;
}
struct nvram_backend_ops nvram_dir_ops = {
.prepare = SWTPM_NVRAM_Prepare_Dir,
.load = SWTPM_NVRAM_LoadData_Dir,
.store = SWTPM_NVRAM_StoreData_Dir,
.delete = SWTPM_NVRAM_DeleteName_Dir,
.cleanup = SWTPM_NVRAM_Cleanup_Dir,
};

View File

@ -1,81 +0,0 @@
/********************************************************************************/
/* */
/* NVRAM Utilities */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* */
/* (c) Copyright IBM Corporation 2006, 2010. */
/* */
/* All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or without */
/* modification, are permitted provided that the following conditions are */
/* met: */
/* */
/* Redistributions of source code must retain the above copyright notice, */
/* this list of conditions and the following disclaimer. */
/* */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in the */
/* documentation and/or other materials provided with the distribution. */
/* */
/* Neither the names of the IBM Corporation nor the names of its */
/* contributors may be used to endorse or promote products derived from */
/* this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/********************************************************************************/
#ifndef _SWTPM_NVSTORE_DIR_H
#define _SWTPM_NVSTORE_DIR_H
#include <libtpms/tpm_types.h>
#include <libtpms/tpm_library.h>
/* characters in the TPM base file name, 14 for file name, slash, NUL terminator, etc.
This macro is used once during initialization to ensure that the TPM_PATH environment variable
length will not cause the rooted file name to overflow file name buffers.
*/
#define TPM_FILENAME_MAX 20
TPM_RESULT
SWTPM_NVRAM_Prepare_Dir(const char *uri);
TPM_RESULT
SWTPM_NVRAM_LoadData_Dir(unsigned char **data,
uint32_t *length,
uint32_t tpm_number,
const char *name,
const char *uri);
TPM_RESULT
SWTPM_NVRAM_StoreData_Dir(unsigned char *filedata,
uint32_t filedata_length,
uint32_t tpm_number,
const char *name,
const char *uri);
TPM_RESULT
SWTPM_NVRAM_DeleteName_Dir(uint32_t tpm_number,
const char *name,
TPM_BOOL mustExist,
const char *uri);
void
SWTPM_NVRAM_Cleanup_Dir(void);
extern struct nvram_backend_ops nvram_dir_ops;
#endif /* _SWTPM_NVSTORE_DIR_H */