libimcv: Pass TNC_SESSION_ID as argument instead as a environment variable

Doing so works on Windows as well.
This commit is contained in:
Martin Willi
2014-06-04 15:53:10 +02:00
parent 9b7d1a3b33
commit ecc6c2e8a4
4 changed files with 16 additions and 23 deletions
+8 -6
View File
@@ -20,18 +20,20 @@
# that, and use the "libimcv.policy_script = " option in strongswan.conf
# to make strongSwan use yours instead of this default one.
# Environment variables that this script gets
# Passed arguments
#
# TNC_SESSION_ID
# unique session ID used as a reference by the policy
# manager.
# $1
# action
# $2
# unique session ID used as a reference by the policy
# manager.
#
case "$1" in
start)
echo "start session $TNC_SESSION_ID"
echo "start session $2"
;;
stop)
echo "stop session $TNC_SESSION_ID"
echo "stop session $2"
;;
*) echo "$0: unknown command '$1'"
exit 1
+4 -5
View File
@@ -126,7 +126,7 @@ static bool create_session(private_imv_database_t *this, imv_session_t *session)
DBG1(DBG_IMV, "imv_db: registering product info failed");
return FALSE;
}
/* get device ID string */
if (!session->get_device_id(session, &device_id))
{
@@ -261,9 +261,9 @@ METHOD(imv_database_t, policy_script, bool,
}
/* call the policy script */
snprintf(command, sizeof(command), "2>&1 TNC_SESSION_ID='%d' %s %s",
session->get_session_id(session, NULL, NULL), this->script,
start ? "start" : "stop");
snprintf(command, sizeof(command), "2>&1 %s %s %d",
this->script, start ? "start" : "stop",
session->get_session_id(session, NULL, NULL));
DBG3(DBG_IMV, "running policy script: %s", command);
shell = popen(command, "r");
@@ -363,4 +363,3 @@ imv_database_t *imv_database_create(char *uri, char *script)
return &this->public;
}
+3 -10
View File
@@ -278,7 +278,7 @@ static bool policy_stop(database_t *db, int session_id)
int main(int argc, char *argv[])
{
database_t *db;
char *uri, *tnc_session_id;
char *uri;
int session_id;
bool start, success;
@@ -299,7 +299,7 @@ int main(int argc, char *argv[])
exit(SS_RC_INITIALIZATION_FAILED);
}
if (argc < 2)
if (argc < 3)
{
usage();
exit(SS_RC_INITIALIZATION_FAILED);
@@ -318,14 +318,7 @@ int main(int argc, char *argv[])
exit(SS_RC_INITIALIZATION_FAILED);
}
/* get session ID */
tnc_session_id = getenv("TNC_SESSION_ID");
if (!tnc_session_id)
{
fprintf(stderr, "environment variable TNC_SESSION_ID is not defined\n");
exit(SS_RC_INITIALIZATION_FAILED);
}
session_id = atoi(tnc_session_id);
session_id = atoi(argv[2]);
/* attach IMV database */
uri = lib->settings->get_str(lib->settings,
+1 -2
View File
@@ -24,6 +24,5 @@ void usage(void)
{
printf("\
Usage:\n\
imv_policy_manager start|stop\n");
imv_policy_manager start|stop <tnc-session-id>\n");
}