aboutsummaryrefslogtreecommitdiffstats
path: root/src/libimcv/os_info
diff options
context:
space:
mode:
Diffstat (limited to 'src/libimcv/os_info')
-rw-r--r--src/libimcv/os_info/os_info.c45
-rw-r--r--src/libimcv/os_info/os_info.h11
2 files changed, 39 insertions, 17 deletions
diff --git a/src/libimcv/os_info/os_info.c b/src/libimcv/os_info/os_info.c
index 110c60ea1..9716e2c9e 100644
--- a/src/libimcv/os_info/os_info.c
+++ b/src/libimcv/os_info/os_info.c
@@ -177,13 +177,13 @@ METHOD(os_info_t, get_setting, chunk_t,
chunk_t value;
if (!strneq(name, "/etc/", 5) && !strneq(name, "/proc/", 6) &&
- !strneq(name, "/sys/", 5))
+ !strneq(name, "/sys/", 5) && !strneq(name, "/var/", 5))
{
/**
* In order to guarantee privacy, only settings from the
* /etc/, /proc/ and /sys/ directories can be retrieved
*/
- DBG1(DBG_IMC, "not allowed to access \"%s\"", name);
+ DBG1(DBG_IMC, "not allowed to access '%s'", name);
return chunk_empty;
}
@@ -191,7 +191,7 @@ METHOD(os_info_t, get_setting, chunk_t,
file = fopen(name, "r");
if (!file)
{
- DBG1(DBG_IMC, "failed to open \"%s\"", name);
+ DBG1(DBG_IMC, "failed to open '%s'", name);
return chunk_empty;
}
@@ -337,7 +337,7 @@ static bool extract_platform_info(os_type_t *type, chunk_t *name,
chunk_t os_version = chunk_empty;
char *os_str;
struct utsname uninfo;
- int i, t;
+ int i;
/* Linux/Unix distribution release info (from http://linuxmafia.com) */
const char* releases[] = {
@@ -492,21 +492,14 @@ static bool extract_platform_info(os_type_t *type, chunk_t *name,
return FALSE;
}
- /* Try to find a matching OS type */
+ /* Try to find a matching OS type based on the OS name */
if (os_type == OS_TYPE_UNKNOWN)
{
- for (t = OS_TYPE_DEBIAN; t <= OS_TYPE_GENTOO; t++)
- {
- os_str = enum_to_name(os_type_names, t);
- if (memeq(os_name.ptr, os_str, min(os_name.len, strlen(os_str))))
- {
- os_type = t;
- os_name = chunk_create(os_str, strlen(os_str));
- break;
- }
- }
+ os_type = os_type_from_name(os_name);
}
- else
+
+ /* If known use the official OS name */
+ if (os_type != OS_TYPE_UNKNOWN)
{
os_str = enum_to_name(os_type_names, os_type);
os_name = chunk_create(os_str, strlen(os_str));
@@ -532,6 +525,26 @@ static bool extract_platform_info(os_type_t *type, chunk_t *name,
/**
* See header
*/
+os_type_t os_type_from_name(chunk_t name)
+{
+ os_type_t type;
+ char *name_str;
+
+ for (type = OS_TYPE_DEBIAN; type < OS_TYPE_ROOF; type++)
+ {
+ /* name_str is a substring of name.ptr */
+ name_str = enum_to_name(os_type_names, type);
+ if (memeq(name.ptr, name_str, min(name.len, strlen(name_str))))
+ {
+ return type;
+ }
+ }
+ return OS_TYPE_UNKNOWN;
+}
+
+/**
+ * See header
+ */
os_info_t *os_info_create(void)
{
private_os_info_t *this;
diff --git a/src/libimcv/os_info/os_info.h b/src/libimcv/os_info/os_info.h
index d8b53f8fc..6946b1ed7 100644
--- a/src/libimcv/os_info/os_info.h
+++ b/src/libimcv/os_info/os_info.h
@@ -38,7 +38,8 @@ enum os_type_t {
OS_TYPE_CENTOS,
OS_TYPE_SUSE,
OS_TYPE_GENTOO,
- OS_TYPE_ANDROID
+ OS_TYPE_ANDROID,
+ OS_TYPE_ROOF
};
extern enum_name_t *os_type_names;
@@ -125,6 +126,14 @@ struct os_info_t {
};
/**
+ * Convert an OS name into an OS enumeration type
+ *
+ * @param name OS name
+ * @return OS enumeration type
+ */
+os_type_t os_type_from_name(chunk_t name);
+
+/**
* Create an os_info_t object
*/
os_info_t* os_info_create(void);