[PATCH/RFC 4/6] remove closed forwardings from options

Bert Wesarg bert.wesarg at googlemail.com
Thu May 3 21:33:50 EST 2012


---
 mux.c      |    8 +-------
 readconf.c |   32 ++++++++++++++++++++++++++++++++
 readconf.h |    1 +
 3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/mux.c b/mux.c
index 337ef54..c59bb97 100644
--- a/mux.c
+++ b/mux.c
@@ -835,13 +835,7 @@ process_mux_close_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
 		buffer_put_int(r, MUX_S_OK);
 		buffer_put_int(r, rid);
 
-		found_fwd->type = 0;
-		if (found_fwd->listen_host != NULL)
-			xfree(found_fwd->listen_host);
-		if (found_fwd->connect_host != NULL)
-			xfree(found_fwd->connect_host);
-		found_fwd->listen_host = found_fwd->connect_host = NULL;
-		found_fwd->listen_port = found_fwd->connect_port = 0;
+		remove_forward(&options, found_fwd);
 	} else {
 		buffer_put_int(r, MUX_S_FAILURE);
 		buffer_put_int(r, rid);
diff --git a/readconf.c b/readconf.c
index a89b07a..371570d 100644
--- a/readconf.c
+++ b/readconf.c
@@ -286,6 +286,38 @@ add_forward(Options *options, const Forward *newfwd)
 	return fwd->id;
 }
 
+/*
+ * Remove a TCP/IP port forward from the options.
+ */
+
+void
+remove_forward(Options *options, Forward *remfwd)
+{
+	if (remfwd < options->forwards ||
+	    options->forwards + options->num_forwards <= remfwd)
+		fatal("Invalid forwarding to remove.");
+
+	if (remfwd->listen_host != NULL)
+		xfree(remfwd->listen_host);
+	if (remfwd->connect_host != NULL)
+		xfree(remfwd->connect_host);
+	remfwd->listen_host = remfwd->connect_host = NULL;
+	remfwd->listen_port = remfwd->connect_port = 0;
+
+	options->num_forwards--;
+	while (remfwd < options->forwards + options->num_forwards) {
+		*remfwd = *(remfwd + 1);
+		remfwd++;
+	}
+	if (options->num_forwards > 0)
+		options->forwards = xrealloc(options->forwards,
+		    options->num_forwards, sizeof(*remfwd));
+	else {
+		xfree(options->forwards);
+		options->forwards = NULL;
+	}
+}
+
 static void
 clear_forwardings(Options *options)
 {
diff --git a/readconf.h b/readconf.h
index d44946b..6877888 100644
--- a/readconf.h
+++ b/readconf.h
@@ -160,5 +160,6 @@ process_config_line(Options *, const char *, char *, const char *, int, int *);
 
 int	 parse_forward(Forward *, const char *, u_int);
 u_int	 add_forward(Options *, const Forward *);
+void	 remove_forward(Options *, Forward *);
 
 #endif				/* READCONF_H */
-- 
1.7.9.rc0.542.g07ca1



More information about the openssh-unix-dev mailing list