Certificate trigger and directory operations
Implement trigger of certificate and permission expiries using the timed callbacks. Implement directory operations such that trusted CA can be read. This implements OS abstraction functions such as opendir and stat. Signed-off-by: Stefan Kimmer <skimmer@s2e-systems.com>
This commit is contained in:
parent
3b4facbd45
commit
aef4f0a126
25 changed files with 3039 additions and 169 deletions
|
@ -149,7 +149,7 @@ list(APPEND sources
|
|||
# network stack. In order to mix-and-match various compilers, architectures,
|
||||
# operating systems, etc input from the build system is required.
|
||||
foreach(feature atomics cdtors environ heap ifaddrs random rusage
|
||||
sockets string sync threads time md5 process netstat dynlib)
|
||||
sockets string sync threads time md5 process netstat dynlib filesystem)
|
||||
if(EXISTS "${include_path}/dds/ddsrt/${feature}.h")
|
||||
list(APPEND headers "${include_path}/dds/ddsrt/${feature}.h")
|
||||
file(GLOB_RECURSE
|
||||
|
|
123
src/ddsrt/include/dds/ddsrt/filesystem.h
Normal file
123
src/ddsrt/include/dds/ddsrt/filesystem.h
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FILESYSTEM_H
|
||||
#define FILESYSTEM_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "dds/export.h"
|
||||
#include "dds/ddsrt/retcode.h"
|
||||
#include "dds/ddsrt/time.h"
|
||||
|
||||
#if _WIN32
|
||||
#include "dds/ddsrt/filesystem/windows.h"
|
||||
#else
|
||||
#include "dds/ddsrt/filesystem/posix.h"
|
||||
#endif
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct ddsrt_stat {
|
||||
ddsrt_mode_t stat_mode;
|
||||
size_t stat_size;
|
||||
dds_time_t stat_mtime;
|
||||
};
|
||||
|
||||
|
||||
struct ddsrt_dirent {
|
||||
char d_name[DDSRT_PATH_MAX + 1];
|
||||
};
|
||||
|
||||
/** \brief opendir wrapper
|
||||
*
|
||||
* Open the directory conform opendir
|
||||
*
|
||||
* Precondition:
|
||||
* none
|
||||
*
|
||||
* Possible results:
|
||||
* - return DDS_RETCODE_OK if directory 'name' is opened
|
||||
* - DDS_RETCODE_ERROR if 'name' could not
|
||||
* be found or is not a directory.
|
||||
*/
|
||||
DDS_EXPORT dds_return_t ddsrt_opendir(const char *name, ddsrt_dir_handle_t *dir);
|
||||
|
||||
/** \brief closedir wrapper
|
||||
*
|
||||
* Close the directory conform closdir
|
||||
*
|
||||
* Precondition:
|
||||
* none
|
||||
*
|
||||
* Possible results:
|
||||
* - return DDS_RETCODE_OK if directory identified by the handle
|
||||
* is succesfully closed
|
||||
* - return DDS_RETCODE_ERROR if the handle is invalid.
|
||||
*/
|
||||
DDS_EXPORT dds_return_t ddsrt_closedir(ddsrt_dir_handle_t d);
|
||||
|
||||
/** \brief readdir wrapper
|
||||
*
|
||||
* Read the directory conform readdir.
|
||||
*
|
||||
* Precondition:
|
||||
* none
|
||||
*
|
||||
* Possible results:
|
||||
* - return DDS_RETCODE_OK if next directory is found
|
||||
* - return DDS_RETCODE_ERROR if no more directories are found.
|
||||
*/
|
||||
DDS_EXPORT dds_return_t ddsrt_readdir(ddsrt_dir_handle_t d, struct ddsrt_dirent *direntp);
|
||||
|
||||
/** \brief stat wrapper
|
||||
*
|
||||
* Gets directory status conform stat.
|
||||
*
|
||||
* Precondition:
|
||||
* none
|
||||
*
|
||||
* Possible results:
|
||||
* - return DDS_RETCODE_OK if stat is successful
|
||||
* - return DDS_RETCODE_ERROR if stat fails.
|
||||
*/
|
||||
DDS_EXPORT dds_return_t ddsrt_stat(const char *path, struct ddsrt_stat *buf);
|
||||
|
||||
/** \brief Transforms the given filepath into a platform specific filepath.
|
||||
*
|
||||
* This translation function will replace any platform file seperator into
|
||||
* the fileseperator of the current platform. Doulbe quotes are removed
|
||||
* as well.
|
||||
*
|
||||
* Precondition:
|
||||
* none
|
||||
*
|
||||
* Possible results:
|
||||
* - returns normalized filepath conform current platform
|
||||
* - return NULL if out of memory.
|
||||
*/
|
||||
DDS_EXPORT char* ddsrt_file_normalize(const char *filepath);
|
||||
|
||||
/** \brief Get file seperator
|
||||
*
|
||||
* Possible Results:
|
||||
* - "<file-seperator-string>"
|
||||
*/
|
||||
DDS_EXPORT const char* ddsrt_file_sep(void);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // FILESYSTEM_H
|
34
src/ddsrt/include/dds/ddsrt/filesystem/posix.h
Normal file
34
src/ddsrt/include/dds/ddsrt/filesystem/posix.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_FILESYSTEM_POSIX_H
|
||||
#define DDSRT_FILESYSTEM_POSIX_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
|
||||
typedef DIR *ddsrt_dir_handle_t;
|
||||
typedef mode_t ddsrt_mode_t;
|
||||
|
||||
#define DDSRT_PATH_MAX PATH_MAX
|
||||
#define DDSRT_FILESEPCHAR '/'
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DDSRT_FILESYSTEM_POSIX_H */
|
34
src/ddsrt/include/dds/ddsrt/filesystem/windows.h
Normal file
34
src/ddsrt/include/dds/ddsrt/filesystem/windows.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#ifndef DDSRT_FILESYSTEM_WINDOWS_H
|
||||
#define DDSRT_FILESYSTEM_WINDOWS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "dds/ddsrt/types.h"
|
||||
|
||||
typedef HANDLE ddsrt_dir_handle_t;
|
||||
typedef unsigned short ddsrt_mode_t;
|
||||
|
||||
#define DDSRT_PATH_MAX MAX_PATH
|
||||
#define DDSRT_FILESEPCHAR '\\'
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DDSRT_FILESYSTEM_WINDOWS_H */
|
116
src/ddsrt/src/filesystem/posix/filesystem.c
Normal file
116
src/ddsrt/src/filesystem/posix/filesystem.c
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "dds/ddsrt/filesystem.h"
|
||||
#include "dds/ddsrt/string.h"
|
||||
#include "dds/ddsrt/heap.h"
|
||||
|
||||
dds_return_t ddsrt_opendir(const char *name, ddsrt_dir_handle_t *dir)
|
||||
{
|
||||
dds_return_t result = DDS_RETCODE_ERROR;
|
||||
DIR *d;
|
||||
if (dir) {
|
||||
d = opendir(name);
|
||||
if (d) {
|
||||
*dir = d;
|
||||
result = DDS_RETCODE_OK;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
dds_return_t ddsrt_readdir(ddsrt_dir_handle_t d, struct ddsrt_dirent *direntp)
|
||||
{
|
||||
dds_return_t result;
|
||||
struct dirent *d_entry;
|
||||
|
||||
result = DDS_RETCODE_ERROR;
|
||||
if (d && direntp) {
|
||||
d_entry = readdir(d);
|
||||
if (d_entry) {
|
||||
ddsrt_strlcpy(direntp->d_name, d_entry->d_name, sizeof(direntp->d_name));
|
||||
result = DDS_RETCODE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
dds_return_t ddsrt_closedir(ddsrt_dir_handle_t d)
|
||||
{
|
||||
dds_return_t result;
|
||||
|
||||
result = DDS_RETCODE_ERROR;
|
||||
if (d) {
|
||||
if (closedir(d) == 0) {
|
||||
result = DDS_RETCODE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
dds_return_t ddsrt_stat(const char *path, struct ddsrt_stat *buf)
|
||||
{
|
||||
dds_return_t result;
|
||||
struct stat _buf;
|
||||
int r;
|
||||
|
||||
r = stat(path, &_buf);
|
||||
if (r == 0) {
|
||||
buf->stat_mode = _buf.st_mode;
|
||||
buf->stat_size = (size_t) _buf.st_size;
|
||||
buf->stat_mtime = DDS_SECS(_buf.st_mtime);
|
||||
result = DDS_RETCODE_OK;
|
||||
} else {
|
||||
result = DDS_RETCODE_ERROR;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char * ddsrt_file_normalize(const char *filepath)
|
||||
{
|
||||
char *norm;
|
||||
const char *fpPtr;
|
||||
char *normPtr;
|
||||
|
||||
norm = NULL;
|
||||
if ((filepath != NULL) && (*filepath != '\0')) {
|
||||
norm = ddsrt_malloc(strlen(filepath) + 1);
|
||||
/* replace any / or \ by DDSRT_FILESEPCHAR */
|
||||
fpPtr = (char *) filepath;
|
||||
normPtr = norm;
|
||||
while (*fpPtr != '\0') {
|
||||
*normPtr = *fpPtr;
|
||||
if ((*fpPtr == '/') || (*fpPtr == '\\')) {
|
||||
*normPtr = DDSRT_FILESEPCHAR;
|
||||
normPtr++;
|
||||
} else {
|
||||
if (*fpPtr != '\"') {
|
||||
normPtr++;
|
||||
}
|
||||
}
|
||||
fpPtr++;
|
||||
}
|
||||
*normPtr = '\0';
|
||||
}
|
||||
|
||||
return norm;
|
||||
}
|
||||
|
||||
const char *ddsrt_file_sep(void)
|
||||
{
|
||||
return "/";
|
||||
}
|
122
src/ddsrt/src/filesystem/windows/filesystem.c
Normal file
122
src/ddsrt/src/filesystem/windows/filesystem.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v. 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
|
||||
* v. 1.0 which is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "dds/ddsrt/filesystem.h"
|
||||
#include "dds/ddsrt/string.h"
|
||||
#include "dds/ddsrt/heap.h"
|
||||
#include "dds/ddsrt/io.h"
|
||||
|
||||
dds_return_t ddsrt_opendir(const char *name, ddsrt_dir_handle_t *dir)
|
||||
{
|
||||
dds_return_t result;
|
||||
|
||||
TCHAR szDir[DDSRT_PATH_MAX + 1];
|
||||
WIN32_FIND_DATA FileData;
|
||||
HANDLE hList;
|
||||
|
||||
result = DDS_RETCODE_ERROR;
|
||||
if (dir) {
|
||||
snprintf(szDir, DDSRT_PATH_MAX, "%s\\*", name);
|
||||
hList = FindFirstFile(szDir, &FileData);
|
||||
|
||||
if (hList != INVALID_HANDLE_VALUE) {
|
||||
*dir = hList;
|
||||
result = DDS_RETCODE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
dds_return_t ddsrt_readdir(ddsrt_dir_handle_t d, struct ddsrt_dirent *direntp)
|
||||
{
|
||||
dds_return_t result;
|
||||
WIN32_FIND_DATA FileData;
|
||||
BOOL r;
|
||||
|
||||
if (direntp) {
|
||||
r = FindNextFile(d, &FileData);
|
||||
if (r) {
|
||||
ddsrt_strlcpy(direntp->d_name, FileData.cFileName, sizeof(direntp->d_name));
|
||||
result = DDS_RETCODE_OK;
|
||||
} else {
|
||||
result = DDS_RETCODE_ERROR;
|
||||
}
|
||||
} else {
|
||||
result = DDS_RETCODE_ERROR;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
dds_return_t ddsrt_closedir(ddsrt_dir_handle_t d)
|
||||
{
|
||||
FindClose(d);
|
||||
|
||||
return DDS_RETCODE_OK;
|
||||
}
|
||||
|
||||
dds_return_t ddsrt_stat(const char *path, struct ddsrt_stat *buf)
|
||||
{
|
||||
dds_return_t result;
|
||||
struct _stat _buf;
|
||||
int r;
|
||||
|
||||
r = _stat(path, &_buf);
|
||||
if (r == 0) {
|
||||
buf->stat_mode = _buf.st_mode;
|
||||
buf->stat_size = _buf.st_size;
|
||||
buf->stat_mtime = DDS_SECS(_buf.st_mtime);;
|
||||
result = DDS_RETCODE_OK;
|
||||
} else {
|
||||
result = DDS_RETCODE_ERROR;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char * ddsrt_file_normalize(const char *filepath)
|
||||
{
|
||||
char *norm;
|
||||
const char *fpPtr;
|
||||
char *normPtr;
|
||||
|
||||
norm = NULL;
|
||||
if ((filepath != NULL) && (*filepath != '\0')) {
|
||||
norm = ddsrt_malloc(strlen(filepath) + 1);
|
||||
/* replace any / or \ by DDSRT_FILESEPCHAR */
|
||||
fpPtr = (char *) filepath;
|
||||
normPtr = norm;
|
||||
while (*fpPtr != '\0') {
|
||||
*normPtr = *fpPtr;
|
||||
if ((*fpPtr == '/') || (*fpPtr == '\\')) {
|
||||
*normPtr = DDSRT_FILESEPCHAR;
|
||||
normPtr++;
|
||||
} else {
|
||||
if (*fpPtr != '\"') {
|
||||
normPtr++;
|
||||
}
|
||||
}
|
||||
fpPtr++;
|
||||
}
|
||||
*normPtr = '\0';
|
||||
}
|
||||
|
||||
return norm;
|
||||
}
|
||||
|
||||
const char *ddsrt_file_sep(void)
|
||||
{
|
||||
return "\\";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue