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
+6 -4
View File
@@ -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
# action
# $2
# unique session ID used as a reference by the policy # unique session ID used as a reference by the policy
# manager. # 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
+3 -4
View File
@@ -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;
} }
+3 -10
View File
@@ -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,
+1 -2
View File
@@ -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");
} }