summaryrefslogtreecommitdiff
path: root/src/libimcv/plugins/imv_os
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2013-04-26 14:57:47 +0200
committerYves-Alexis Perez <corsac@debian.org>2013-04-26 14:57:47 +0200
commit10e5fb2b9b2f27c83b3e5a1d048b158d5cf42a43 (patch)
treebf1d05a2e37dbd1911b86fcc026fbe49b0239c71 /src/libimcv/plugins/imv_os
parent7585facf05d927eb6df3929ce09ed5e60d905437 (diff)
downloadvyos-strongswan-10e5fb2b9b2f27c83b3e5a1d048b158d5cf42a43.tar.gz
vyos-strongswan-10e5fb2b9b2f27c83b3e5a1d048b158d5cf42a43.zip
Imported Upstream version 5.0.3
Diffstat (limited to 'src/libimcv/plugins/imv_os')
-rw-r--r--src/libimcv/plugins/imv_os/Makefile.in38
-rw-r--r--src/libimcv/plugins/imv_os/imv_os.c29
-rw-r--r--src/libimcv/plugins/imv_os/imv_os_database.c46
-rw-r--r--src/libimcv/plugins/imv_os/imv_os_database.h12
-rw-r--r--src/libimcv/plugins/imv_os/imv_os_state.c51
-rw-r--r--src/libimcv/plugins/imv_os/imv_os_state.h21
-rw-r--r--src/libimcv/plugins/imv_os/pacman.c3
7 files changed, 169 insertions, 31 deletions
diff --git a/src/libimcv/plugins/imv_os/Makefile.in b/src/libimcv/plugins/imv_os/Makefile.in
index 53a547a4d..b4e2a3a4f 100644
--- a/src/libimcv/plugins/imv_os/Makefile.in
+++ b/src/libimcv/plugins/imv_os/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.11.3 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -17,6 +17,23 @@
VPATH = @srcdir@
+am__make_dryrun = \
+ { \
+ am__dry=no; \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
+ | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+ *) \
+ for am__flg in $$MAKEFLAGS; do \
+ case $$am__flg in \
+ *=*|--*) ;; \
+ *n*) am__dry=yes; break;; \
+ esac; \
+ done;; \
+ esac; \
+ test $$am__dry = yes; \
+ }
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -110,6 +127,11 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(imv_os_la_SOURCES) $(pacman_SOURCES)
DIST_SOURCES = $(imv_os_la_SOURCES) $(pacman_SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -126,6 +148,8 @@ BTLIB = @BTLIB@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
+CHECK_CFLAGS = @CHECK_CFLAGS@
+CHECK_LIBS = @CHECK_LIBS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
@@ -142,6 +166,7 @@ EGREP = @EGREP@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
GPERF = @GPERF@
+GPRBUILD = @GPRBUILD@
GREP = @GREP@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
@@ -210,8 +235,6 @@ am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
attest_plugins = @attest_plugins@
-axis2c_CFLAGS = @axis2c_CFLAGS@
-axis2c_LIBS = @axis2c_LIBS@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
@@ -267,7 +290,6 @@ nm_ca_dir = @nm_ca_dir@
nm_plugins = @nm_plugins@
oldincludedir = @oldincludedir@
openac_plugins = @openac_plugins@
-p_plugins = @p_plugins@
pcsclite_CFLAGS = @pcsclite_CFLAGS@
pcsclite_LIBS = @pcsclite_LIBS@
pdfdir = @pdfdir@
@@ -353,7 +375,6 @@ $(ACLOCAL_M4): $(am__aclocal_m4_deps)
$(am__aclocal_m4_deps):
install-imcvLTLIBRARIES: $(imcv_LTLIBRARIES)
@$(NORMAL_INSTALL)
- test -z "$(imcvdir)" || $(MKDIR_P) "$(DESTDIR)$(imcvdir)"
@list='$(imcv_LTLIBRARIES)'; test -n "$(imcvdir)" || list=; \
list2=; for p in $$list; do \
if test -f $$p; then \
@@ -361,6 +382,8 @@ install-imcvLTLIBRARIES: $(imcv_LTLIBRARIES)
else :; fi; \
done; \
test -z "$$list2" || { \
+ echo " $(MKDIR_P) '$(DESTDIR)$(imcvdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(imcvdir)" || exit 1; \
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(imcvdir)'"; \
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(imcvdir)"; \
}
@@ -386,8 +409,11 @@ imv-os.la: $(imv_os_la_OBJECTS) $(imv_os_la_DEPENDENCIES) $(EXTRA_imv_os_la_DEPE
$(imv_os_la_LINK) -rpath $(imcvdir) $(imv_os_la_OBJECTS) $(imv_os_la_LIBADD) $(LIBS)
install-ipsecPROGRAMS: $(ipsec_PROGRAMS)
@$(NORMAL_INSTALL)
- test -z "$(ipsecdir)" || $(MKDIR_P) "$(DESTDIR)$(ipsecdir)"
@list='$(ipsec_PROGRAMS)'; test -n "$(ipsecdir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(ipsecdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(ipsecdir)" || exit 1; \
+ fi; \
for p in $$list; do echo "$$p $$p"; done | \
sed 's/$(EXEEXT)$$//' | \
while read p p1; do if test -f $$p || test -f $$p1; \
diff --git a/src/libimcv/plugins/imv_os/imv_os.c b/src/libimcv/plugins/imv_os/imv_os.c
index 65538df07..f1cb74e50 100644
--- a/src/libimcv/plugins/imv_os/imv_os.c
+++ b/src/libimcv/plugins/imv_os/imv_os.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Andreas Steffen
+ * Copyright (C) 2012-2013 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -360,7 +360,9 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
out_msg->add_attribute(out_msg, attr);
}
- if (fatal_error)
+ if (fatal_error ||
+ (os_state->get_attribute_request(os_state) &&
+ os_state->get_info(os_state, NULL, NULL, NULL) == NULL))
{
state->set_recommendation(state,
TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
@@ -371,10 +373,13 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
/* If all Installed Packages attributes were received, go to assessment */
if (!assessment &&
!os_state->get_package_request(os_state) &&
- !os_state->get_angel_count(os_state))
+ !os_state->get_angel_count(os_state) &&
+ os_state->get_info(os_state, NULL, NULL, NULL))
{
int device_id, count, count_update, count_blacklist, count_ok;
u_int os_settings;
+ u_int32_t id_type;
+ chunk_t id_value;
os_settings = os_state->get_os_settings(os_state);
os_state->get_count(os_state, &count, &count_update, &count_blacklist,
@@ -385,9 +390,10 @@ static TNC_Result receive_message(imv_state_t *state, imv_msg_t *in_msg)
/* Store device information in database */
device_id = os_state->get_device_id(os_state);
+ id_value = state->get_ar_id(state, &id_type);
if (os_db && device_id)
{
- os_db->set_device_info(os_db, device_id,
+ os_db->set_device_info(os_db, device_id, id_type, id_value,
os_state->get_info(os_state, NULL, NULL, NULL),
count, count_update, count_blacklist, os_settings);
}
@@ -518,6 +524,8 @@ TNC_Result TNC_IMV_BatchEnding(TNC_IMVID imv_id,
{
imv_state_t *state;
imv_os_state_t *os_state;
+ TNC_IMV_Action_Recommendation rec;
+ TNC_IMV_Evaluation_Result eval;
TNC_Result result = TNC_RESULT_SUCCESS;
if (!imv_os)
@@ -531,6 +539,18 @@ TNC_Result TNC_IMV_BatchEnding(TNC_IMVID imv_id,
}
os_state = (imv_os_state_t*)state;
+ state->get_recommendation(state, &rec, &eval);
+
+ /*
+ * Don't send an attribute request if an evaluation is available
+ * or if an attribute request has already been sent
+ */
+ if (eval != TNC_IMV_EVALUATION_RESULT_DONT_KNOW ||
+ os_state->get_attribute_request(os_state))
+ {
+ return TNC_RESULT_SUCCESS;
+ }
+
if (os_state->get_info(os_state, NULL, NULL, NULL) == NULL)
{
imv_msg_t *out_msg;
@@ -548,6 +568,7 @@ TNC_Result TNC_IMV_BatchEnding(TNC_IMVID imv_id,
attr_cast->add(attr_cast, PEN_IETF, IETF_ATTR_FORWARDING_ENABLED);
attr_cast->add(attr_cast, PEN_IETF, IETF_ATTR_FACTORY_DEFAULT_PWD_ENABLED);
out_msg->add_attribute(out_msg, attr);
+ os_state->set_attribute_request(os_state, TRUE);
/* send PA-TNC message with excl flag not set */
result = out_msg->send(out_msg, FALSE);
diff --git a/src/libimcv/plugins/imv_os/imv_os_database.c b/src/libimcv/plugins/imv_os/imv_os_database.c
index c6db9953f..dff414497 100644
--- a/src/libimcv/plugins/imv_os/imv_os_database.c
+++ b/src/libimcv/plugins/imv_os/imv_os_database.c
@@ -214,12 +214,14 @@ METHOD(imv_os_database_t, get_device_id, int,
}
METHOD(imv_os_database_t, set_device_info, void,
- private_imv_os_database_t *this, int device_id, char *os_info,
- int count, int count_update, int count_blacklist, u_int flags)
+ private_imv_os_database_t *this, int device_id, u_int32_t ar_id_type,
+ chunk_t ar_id_value, char *os_info, int count, int count_update,
+ int count_blacklist, u_int flags)
{
enumerator_t *e;
time_t last_time;
- int pid = 0, last_pid = 0, last_count_update = 0, last_count_blacklist = 0;
+ int pid = 0, last_pid = 0, iid = 0, last_iid;
+ int last_count_update = 0, last_count_blacklist = 0;
u_int last_flags;
bool found = FALSE;
@@ -233,26 +235,45 @@ METHOD(imv_os_database_t, set_device_info, void,
e->destroy(e);
}
- /* if OS ifo string has not been found - register it */
+ /* if OS info string has not been found - register it */
if (!pid)
{
this->db->execute(this->db, &pid,
"INSERT INTO products (name) VALUES (?)", DB_TEXT, os_info);
}
+ /* get primary key of AR identity if it exists */
+ e = this->db->query(this->db,
+ "SELECT id FROM identities WHERE type = ? AND data = ?",
+ DB_INT, ar_id_type, DB_BLOB, ar_id_value, DB_INT);
+ if (e)
+ {
+ e->enumerate(e, &iid);
+ e->destroy(e);
+ }
+
+ /* if AR identity has not been found - register it */
+ if (!iid)
+ {
+ this->db->execute(this->db, &iid,
+ "INSERT INTO identities (type, data) VALUES (?, ?)",
+ DB_INT, ar_id_type, DB_BLOB, ar_id_value);
+ }
+
/* get latest device info record if it exists */
e = this->db->query(this->db,
- "SELECT time, product, count_update, count_blacklist, flags "
+ "SELECT time, ar_id, product, count_update, count_blacklist, flags "
"FROM device_infos WHERE device = ? ORDER BY time DESC",
- DB_INT, device_id, DB_UINT, DB_INT, DB_INT, DB_INT, DB_UINT);
+ DB_INT, device_id, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_UINT);
if (e)
{
- found = e->enumerate(e, &last_time, &last_pid, &last_count_update,
- &last_count_blacklist, &last_flags);
+ found = e->enumerate(e, &last_time, &last_iid, &last_pid,
+ &last_count_update, &last_count_blacklist,
+ &last_flags);
e->destroy(e);
}
if (found && !last_count_update && !last_count_blacklist && !last_flags &&
- pid == last_pid)
+ iid == last_iid && pid == last_pid)
{
/* update device info */
this->db->execute(this->db, NULL,
@@ -266,9 +287,10 @@ METHOD(imv_os_database_t, set_device_info, void,
{
/* insert device info */
this->db->execute(this->db, NULL,
- "INSERT INTO device_infos (device, time, product, count, "
- "count_update, count_blacklist, flags) VALUES (?, ?, ?, ?, ?, ?, ?)",
- DB_INT, device_id, DB_UINT, time(NULL), DB_INT, pid,
+ "INSERT INTO device_infos (device, time, ar_id, product, count, "
+ "count_update, count_blacklist, flags) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
+ DB_INT, device_id, DB_UINT, time(NULL), DB_INT, iid, DB_INT, pid,
DB_INT, count, DB_INT, count_update, DB_INT, count_blacklist,
DB_UINT, flags);
}
diff --git a/src/libimcv/plugins/imv_os/imv_os_database.h b/src/libimcv/plugins/imv_os/imv_os_database.h
index 9ce748f9b..01d7e84a2 100644
--- a/src/libimcv/plugins/imv_os/imv_os_database.h
+++ b/src/libimcv/plugins/imv_os/imv_os_database.h
@@ -14,9 +14,8 @@
*/
/**
- *
* @defgroup imv_os_database_t imv_os_database
- * @{ @ingroup imv_os_database
+ * @{ @ingroup imv_os
*/
#ifndef IMV_OS_DATABASE_H_
@@ -53,15 +52,18 @@ struct imv_os_database_t {
* Set health infos for a given device
*
* @param device_id Device ID primary key
+ * @param ar_id_type Access Requestor ID Type
+ * @param ar_id_value Access Requestor ID Value
* @param os_info OS info string
* @param count Number of installed packages
* @param count_update Number of packages to be updated
* @param count_blacklist Number of blacklisted packages
* @param flags Various flags, e.g. illegal OS settings
*/
- void (*set_device_info)(imv_os_database_t *this, int device_id, char *os_info,
- int count, int count_update, int count_blacklist,
- u_int flags);
+ void (*set_device_info)(imv_os_database_t *this, int device_id,
+ u_int32_t ar_id_type, chunk_t ar_id_value,
+ char *os_info, int count, int count_update,
+ int count_blacklist, u_int flags);
/**
* Destroys an imv_os_database_t object.
diff --git a/src/libimcv/plugins/imv_os/imv_os_state.c b/src/libimcv/plugins/imv_os/imv_os_state.c
index ca6e050f7..073d7133a 100644
--- a/src/libimcv/plugins/imv_os/imv_os_state.c
+++ b/src/libimcv/plugins/imv_os/imv_os_state.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Andreas Steffen
+ * Copyright (C) 2012-2013 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -62,6 +62,16 @@ struct private_imv_os_state_t {
u_int32_t max_msg_len;
/**
+ * Access Requestor ID Type
+ */
+ u_int32_t ar_id_type;
+
+ /**
+ * Access Requestor ID Value
+ */
+ chunk_t ar_id_value;
+
+ /**
* IMV action recommendation
*/
TNC_IMV_Action_Recommendation rec;
@@ -137,6 +147,11 @@ struct private_imv_os_state_t {
int count_ok;
/**
+ * Attribute request sent - mandatory response expected
+ */
+ bool attribute_request;
+
+ /**
* OS Installed Package request sent - mandatory response expected
*/
bool package_request;
@@ -314,6 +329,23 @@ METHOD(imv_state_t, get_max_msg_len, u_int32_t,
return this->max_msg_len;
}
+METHOD(imv_state_t, set_ar_id, void,
+ private_imv_os_state_t *this, u_int32_t id_type, chunk_t id_value)
+{
+ this->ar_id_type = id_type;
+ this->ar_id_value = chunk_clone(id_value);
+}
+
+METHOD(imv_state_t, get_ar_id, chunk_t,
+ private_imv_os_state_t *this, u_int32_t *id_type)
+{
+ if (id_type)
+ {
+ *id_type = this->ar_id_type;
+ }
+ return this->ar_id_value;
+}
+
METHOD(imv_state_t, change_state, void,
private_imv_os_state_t *this, TNC_ConnectionState new_state)
{
@@ -437,6 +469,7 @@ METHOD(imv_state_t, destroy, void,
free(this->info);
free(this->name.ptr);
free(this->version.ptr);
+ free(this->ar_id_value.ptr);
free(this);
}
@@ -506,6 +539,18 @@ METHOD(imv_os_state_t, get_count, void,
}
}
+METHOD(imv_os_state_t, set_attribute_request, void,
+ private_imv_os_state_t *this, bool set)
+{
+ this->attribute_request = set;
+}
+
+METHOD(imv_os_state_t, get_attribute_request, bool,
+ private_imv_os_state_t *this)
+{
+ return this->attribute_request;
+}
+
METHOD(imv_os_state_t, set_package_request, void,
private_imv_os_state_t *this, bool set)
{
@@ -586,6 +631,8 @@ imv_state_t *imv_os_state_create(TNC_ConnectionID connection_id)
.set_flags = _set_flags,
.set_max_msg_len = _set_max_msg_len,
.get_max_msg_len = _get_max_msg_len,
+ .set_ar_id = _set_ar_id,
+ .get_ar_id = _get_ar_id,
.change_state = _change_state,
.get_recommendation = _get_recommendation,
.set_recommendation = _set_recommendation,
@@ -597,6 +644,8 @@ imv_state_t *imv_os_state_create(TNC_ConnectionID connection_id)
.get_info = _get_info,
.set_count = _set_count,
.get_count = _get_count,
+ .set_attribute_request = _set_attribute_request,
+ .get_attribute_request = _get_attribute_request,
.set_package_request = _set_package_request,
.get_package_request = _get_package_request,
.set_device_id = _set_device_id,
diff --git a/src/libimcv/plugins/imv_os/imv_os_state.h b/src/libimcv/plugins/imv_os/imv_os_state.h
index 05abdbb6c..1c2adeaf9 100644
--- a/src/libimcv/plugins/imv_os/imv_os_state.h
+++ b/src/libimcv/plugins/imv_os/imv_os_state.h
@@ -14,9 +14,11 @@
*/
/**
+ * @defgroup imv_os imv_os
+ * @ingroup libimcv_plugins
*
* @defgroup imv_os_state_t imv_os_state
- * @{ @ingroup imv_os_state
+ * @{ @ingroup imv_os
*/
#ifndef IMV_OS_STATE_H_
@@ -61,7 +63,7 @@ struct imv_os_state_t {
* @param type OS type (enumerated)
* @param name OS name (string)
* @param version OS version
- * @return OS name & version as a concatenated string
+ * @return OS name & version as a concatenated string
*/
char* (*get_info)(imv_os_state_t *this, os_type_t *os_type,
chunk_t *name, chunk_t *version);
@@ -87,6 +89,21 @@ struct imv_os_state_t {
*/
void (*get_count)(imv_os_state_t *this, int *count, int *count_update,
int *count_blacklist, int *count_ok);
+
+ /**
+ * Set/reset attribute request status
+ *
+ * @param set TRUE to set, FALSE to clear
+ */
+ void (*set_attribute_request)(imv_os_state_t *this, bool set);
+
+ /**
+ * Get attribute request status
+ *
+ * @return TRUE if set, FALSE if unset
+ */
+ bool (*get_attribute_request)(imv_os_state_t *this);
+
/**
* Set/reset OS Installed Packages request status
*
diff --git a/src/libimcv/plugins/imv_os/pacman.c b/src/libimcv/plugins/imv_os/pacman.c
index f5f52885d..25e63760b 100644
--- a/src/libimcv/plugins/imv_os/pacman.c
+++ b/src/libimcv/plugins/imv_os/pacman.c
@@ -131,6 +131,7 @@ static void process_packages(char *filename, char *product, bool update)
char *uri, line[12288], *pos;
int count = 0, errored = 0, vulnerable = 0, new_packages = 0;
int new_versions = 0, updated_versions = 0, deleted_versions = 0;
+ time_t gen_time;
u_int32_t pid = 0;
enumerator_t *e;
database_t *db;
@@ -192,7 +193,7 @@ static void process_packages(char *filename, char *product, bool update)
bool security, add_version = TRUE;
int cur_security, security_update = 0, security_delete = 0;
u_int32_t gid = 0, vid = 0, vid_update = 0, vid_delete = 0;
- time_t gen_time, cur_time;
+ time_t cur_time;
count++;
if (count == 1)