libimcv: Pass TNC_SESSION_ID as argument instead as a environment variable
Doing so works on Windows as well.
This commit is contained in:
@@ -20,18 +20,20 @@
|
|||||||
# that, and use the "libimcv.policy_script = " option in strongswan.conf
|
# that, and use the "libimcv.policy_script = " option in strongswan.conf
|
||||||
# to make strongSwan use yours instead of this default one.
|
# to make strongSwan use yours instead of this default one.
|
||||||
|
|
||||||
# Environment variables that this script gets
|
# Passed arguments
|
||||||
#
|
#
|
||||||
# TNC_SESSION_ID
|
# $1
|
||||||
# unique session ID used as a reference by the policy
|
# action
|
||||||
# manager.
|
# $2
|
||||||
|
# unique session ID used as a reference by the policy
|
||||||
|
# manager.
|
||||||
#
|
#
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
echo "start session $TNC_SESSION_ID"
|
echo "start session $2"
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
echo "stop session $TNC_SESSION_ID"
|
echo "stop session $2"
|
||||||
;;
|
;;
|
||||||
*) echo "$0: unknown command '$1'"
|
*) echo "$0: unknown command '$1'"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -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");
|
DBG1(DBG_IMV, "imv_db: registering product info failed");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get device ID string */
|
/* get device ID string */
|
||||||
if (!session->get_device_id(session, &device_id))
|
if (!session->get_device_id(session, &device_id))
|
||||||
{
|
{
|
||||||
@@ -261,9 +261,9 @@ METHOD(imv_database_t, policy_script, bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* call the policy script */
|
/* call the policy script */
|
||||||
snprintf(command, sizeof(command), "2>&1 TNC_SESSION_ID='%d' %s %s",
|
snprintf(command, sizeof(command), "2>&1 %s %s %d",
|
||||||
session->get_session_id(session, NULL, NULL), this->script,
|
this->script, start ? "start" : "stop",
|
||||||
start ? "start" : "stop");
|
session->get_session_id(session, NULL, NULL));
|
||||||
DBG3(DBG_IMV, "running policy script: %s", command);
|
DBG3(DBG_IMV, "running policy script: %s", command);
|
||||||
|
|
||||||
shell = popen(command, "r");
|
shell = popen(command, "r");
|
||||||
@@ -363,4 +363,3 @@ imv_database_t *imv_database_create(char *uri, char *script)
|
|||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ static bool policy_stop(database_t *db, int session_id)
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
database_t *db;
|
database_t *db;
|
||||||
char *uri, *tnc_session_id;
|
char *uri;
|
||||||
int session_id;
|
int session_id;
|
||||||
bool start, success;
|
bool start, success;
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ int main(int argc, char *argv[])
|
|||||||
exit(SS_RC_INITIALIZATION_FAILED);
|
exit(SS_RC_INITIALIZATION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 3)
|
||||||
{
|
{
|
||||||
usage();
|
usage();
|
||||||
exit(SS_RC_INITIALIZATION_FAILED);
|
exit(SS_RC_INITIALIZATION_FAILED);
|
||||||
@@ -318,14 +318,7 @@ int main(int argc, char *argv[])
|
|||||||
exit(SS_RC_INITIALIZATION_FAILED);
|
exit(SS_RC_INITIALIZATION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get session ID */
|
session_id = atoi(argv[2]);
|
||||||
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);
|
|
||||||
|
|
||||||
/* attach IMV database */
|
/* attach IMV database */
|
||||||
uri = lib->settings->get_str(lib->settings,
|
uri = lib->settings->get_str(lib->settings,
|
||||||
|
|||||||
@@ -24,6 +24,5 @@ void usage(void)
|
|||||||
{
|
{
|
||||||
printf("\
|
printf("\
|
||||||
Usage:\n\
|
Usage:\n\
|
||||||
imv_policy_manager start|stop\n");
|
imv_policy_manager start|stop <tnc-session-id>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user