typedef struct private_os_info_t private_os_info_t;
+ENUM(os_type_names, OS_TYPE_UNKNOWN, OS_TYPE_ANDROID,
+ "Unknown",
+ "Debian",
+ "Ubuntu",
+ "Fedora",
+ "Red Hat",
+ "CentOS",
+ "SUSE",
+ "Gentoo",
+ "Android"
+);
+
ENUM(os_fwd_status_names, OS_FWD_DISABLED, OS_FWD_UNKNOWN,
"disabled",
"enabled",
*/
os_info_t public;
+ /**
+ * OS type
+ */
+ os_type_t type;
+
/**
* OS name
*/
};
+METHOD(os_info_t, get_type, os_type_t,
+ private_os_info_t *this)
+{
+ return this->type;
+}
+
METHOD(os_info_t, get_name, chunk_t,
private_os_info_t *this)
{
enumerator_t public;
/**
- * streamed pipe
+ * package info pipe stream
*/
FILE* file;
{
FILE *file;
package_enumerator_t *enumerator;
- chunk_t debian = { "Debian", 6 };
- chunk_t ubuntu = { "Ubuntu", 6 };
/* Only Debian and Ubuntu package enumeration is currently supported */
- if (!chunk_equals(this->name, debian) && !chunk_equals(this->name, ubuntu))
+ if (this->type != OS_TYPE_DEBIAN && this->type != OS_TYPE_UBUNTU)
{
return NULL;
}
/**
* Determine Linux distribution version and hardware platform
*/
-static bool extract_platform_info(chunk_t *name, chunk_t *version)
+static bool extract_platform_info(os_type_t *type, chunk_t *name,
+ chunk_t *version)
{
FILE *file;
u_char buf[BUF_LEN], *pos = buf;
int len = BUF_LEN - 1;
+ os_type_t os_type = OS_TYPE_UNKNOWN;
chunk_t os_name = chunk_empty;
chunk_t os_version = chunk_empty;
+ char *os_str;
struct utsname uninfo;
- int i;
+ int i, t;
/* Linux/Unix distribution release info (from http://linuxmafia.com) */
const char* releases[] = {
DBG1(DBG_IMC, "failed to find end of DISTRIB_ID field");
return FALSE;
}
-
os_name.len = pos - os_name.ptr;
/* Determine Distribution Release */
DBG1(DBG_IMC, "failed to find end of DISTRIB_RELEASE field");
return FALSE;
}
-
os_version.len = pos - os_version.ptr;
break;
}
case RELEASE_DEBIAN:
{
- char str_debian[] = "Debian";
+ os_type = OS_TYPE_DEBIAN;
- os_name = chunk_create(str_debian, strlen(str_debian));
os_version.ptr = buf;
-
pos = strchr(buf, '\n');
if (!pos)
{
}
os_name.len = pos - os_name.ptr;
+
pos += strlen(str_release);
os_version.ptr = pos;
return FALSE;
}
+ /* Try to find a matching OS type */
+ 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;
+ }
+ }
+ }
+ else
+ {
+ os_str = enum_to_name(os_type_names, os_type);
+ os_name = chunk_create(os_str, strlen(os_str));
+ }
+
+ /* copy OS type */
+ *type = os_type;
+
/* copy OS name */
*name = chunk_clone(os_name);
{
private_os_info_t *this;
chunk_t name, version;
+ os_type_t type;
- /* As an opton OS name and OS version can be configured manually */
+ /* As an option OS name and OS version can be configured manually */
name.ptr = lib->settings->get_str(lib->settings,
"libimcv.os_info.name", NULL);
version.ptr = lib->settings->get_str(lib->settings,
}
else
{
- if (!extract_platform_info(&name, &version))
+ if (!extract_platform_info(&type, &name, &version))
{
return NULL;
}
INIT(this,
.public = {
+ .get_type = _get_type,
.get_name = _get_name,
.get_numeric_version = _get_numeric_version,
.get_version = _get_version,
.create_package_enumerator = _create_package_enumerator,
.destroy = _destroy,
},
+ .type = type,
.name = name,
.version = version,
);
static void add_product_info(imc_msg_t *msg)
{
pa_tnc_attr_t *attr;
- chunk_t os_name;
+ os_type_t os_type;
pen_t vendor_id = PEN_IETF;
- char *vendor;
int i;
typedef struct vendor_pen_t {
- char *vendor;
+ os_type_t os_type;
pen_t pen;
} vendor_pen_t;
vendor_pen_t vendor_pens[] = {
- { "Debian", PEN_DEBIAN },
- { "Ubuntu", PEN_CANONICAL }
+ { OS_TYPE_DEBIAN, PEN_DEBIAN },
+ { OS_TYPE_UBUNTU, PEN_CANONICAL },
+ { OS_TYPE_FEDORA, PEN_FEDORA },
+ { OS_TYPE_REDHAT, PEN_REDHAT },
+ { OS_TYPE_ANDROID, PEN_GOOGLE }
};
- os_name = os->get_name(os);
+ os_type = os->get_type(os);
for (i = 0; i < countof(vendor_pens); i++)
{
- vendor = vendor_pens[i].vendor;
- if (chunk_equals(os_name, chunk_create(vendor, strlen(vendor))))
+ if (os_type == vendor_pens[i].os_type)
{
vendor_id = vendor_pens[i].pen;
break;
}
}
- attr = ietf_attr_product_info_create(vendor_id, 0, os_name);
+ attr = ietf_attr_product_info_create(vendor_id, 0, os->get_name(os));
msg->add_attribute(msg, attr);
}