From b83200569ef6b72aafb9c3ab2ab18c15044d7805 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Mon, 29 May 2006 07:17:55 +0000 Subject: [PATCH] ipsec up|down|route|delete require a connection name --- src/ipsec/ipsec.in | 15 +++++++++ src/pluto/rcv_whack.c | 72 +++++++++++++++++++++++++++++++------------ 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/src/ipsec/ipsec.in b/src/ipsec/ipsec.in index 6fd57776c..7ed1286c2 100755 --- a/src/ipsec/ipsec.in +++ b/src/ipsec/ipsec.in @@ -96,6 +96,11 @@ case "$1" in ;; down) shift + if [ "$#" -ne 1 ] + then + echo "Usage: ipsec down " + exit 1 + fi if test -e $IPSEC_PLUTO_PID then $IPSEC_WHACK --name "$1" --terminate @@ -160,6 +165,11 @@ restart) route|unroute) op="$1" shift + if [ "$#" -ne 1 ] + then + echo "Usage: ipsec $op " + exit 1 + fi if test -e $IPSEC_PLUTO_PID then $IPSEC_WHACK --name "$1" "--$op" @@ -223,6 +233,11 @@ stop) ;; up) shift + if [ "$#" -ne 1 ] + then + echo "Usage: ipsec up " + exit 1 + fi if test -e $IPSEC_PLUTO_PID then $IPSEC_WHACK --name "$1" --initiate diff --git a/src/pluto/rcv_whack.c b/src/pluto/rcv_whack.c index 164a4f249..99c377765 100644 --- a/src/pluto/rcv_whack.c +++ b/src/pluto/rcv_whack.c @@ -12,7 +12,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: rcv_whack.c,v 1.17 2005/12/25 12:41:23 as Exp $ + * RCSID $Id: rcv_whack.c,v 1.18 2006/05/25 11:33:57 as Exp $ */ #include @@ -557,7 +557,14 @@ whack_handle(int whackctlfd) if (msg.whack_route) { if (!listening) + { whack_log(RC_DEAF, "need --listen before --route"); + } + if (msg.name == NULL) + { + whack_log(RC_UNKNOWN_NAME + , "whack --route requires a connection name"); + } else { struct connection *c = con_by_name(msg.name, TRUE); @@ -579,37 +586,54 @@ whack_handle(int whackctlfd) if (msg.whack_unroute) { - struct connection *c = con_by_name(msg.name, TRUE); - - if (c != NULL) + if (msg.name == NULL) { - struct spd_route *sr; - int fail = 0; + whack_log(RC_UNKNOWN_NAME + , "whack --unroute requires a connection name"); + } + else + { + struct connection *c = con_by_name(msg.name, TRUE); - set_cur_connection(c); - - for (sr = &c->spd; sr != NULL; sr = sr->next) + if (c != NULL) { - if (sr->routing >= RT_ROUTED_TUNNEL) - fail++; + struct spd_route *sr; + int fail = 0; + + set_cur_connection(c); + + for (sr = &c->spd; sr != NULL; sr = sr->next) + { + if (sr->routing >= RT_ROUTED_TUNNEL) + fail++; + } + if (fail > 0) + whack_log(RC_RTBUSY, "cannot unroute: route busy"); + else if (c->policy & POLICY_GROUP) + unroute_group(c); + else + unroute_connection(c); + reset_cur_connection(); } - if (fail > 0) - whack_log(RC_RTBUSY, "cannot unroute: route busy"); - else if (c->policy & POLICY_GROUP) - unroute_group(c); - else - unroute_connection(c); - reset_cur_connection(); } } if (msg.whack_initiate) { if (!listening) + { whack_log(RC_DEAF, "need --listen before --initiate"); + } + else if (msg.name == NULL) + { + whack_log(RC_UNKNOWN_NAME + , "whack --initiate requires a connection name"); + } else + { initiate_connection(msg.name , msg.whack_async? NULL_FD : dup_any(whackfd)); + } } if (msg.whack_oppo_initiate) @@ -623,7 +647,17 @@ whack_handle(int whackctlfd) } if (msg.whack_terminate) - terminate_connection(msg.name); + { + if (msg.name == NULL) + { + whack_log(RC_UNKNOWN_NAME + , "whack --terminate requires a connection name"); + } + else + { + terminate_connection(msg.name); + } + } if (msg.whack_status) show_status(msg.whack_statusall, msg.name);