From 538c13fe5c4edeca1ffad64e94992806e0c41e98 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Wed, 7 Nov 2012 13:39:44 +0100 Subject: use OS type on IMV side --- src/libimcv/os_info/os_info.c | 45 ++++++++++++++++++++++++++++--------------- src/libimcv/os_info/os_info.h | 11 ++++++++++- 2 files changed, 39 insertions(+), 17 deletions(-) (limited to 'src/libimcv/os_info') 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)); @@ -529,6 +522,26 @@ static bool extract_platform_info(os_type_t *type, chunk_t *name, return TRUE; } +/** + * 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 */ 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; @@ -124,6 +125,14 @@ struct os_info_t { void (*destroy)(os_info_t *this); }; +/** + * 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 */ -- cgit v1.2.3