View | Details | Raw Unified | Return to bug 2562
Collapse All | Expand All

(-)a/misc.c (+38 lines)
Lines 1080-1082 unix_listener(const char *path, int backlog, int unlink_first) Link Here
1080
	}
1080
	}
1081
	return sock;
1081
	return sock;
1082
}
1082
}
1083
1084
/*
1085
 * Compares two strings that maybe be NULL. Returns non-zero if strings
1086
 * are both NULL or are identical, returns zero otherwise.
1087
 */
1088
static int
1089
strcmp_maybe_null(const char *a, const char *b)
1090
{
1091
	if ((a == NULL && b != NULL) || (a != NULL && b == NULL))
1092
		return 0;
1093
	if (a != NULL && strcmp(a, b) != 0)
1094
		return 0;
1095
	return 1;
1096
}
1097
1098
/*
1099
 * Compare two forwards, returning non-zero if they are identical or
1100
 * zero otherwise.
1101
 */
1102
int
1103
forward_equals(const struct Forward *a, const struct Forward *b)
1104
{
1105
	if (strcmp_maybe_null(a->listen_host, b->listen_host) == 0)
1106
		return 0;
1107
	if (a->listen_port != b->listen_port)
1108
		return 0;
1109
	if (strcmp_maybe_null(a->listen_path, b->listen_path) == 0)
1110
		return 0;
1111
	if (strcmp_maybe_null(a->connect_host, b->connect_host) == 0)
1112
		return 0;
1113
	if (a->connect_port != b->connect_port)
1114
		return 0;
1115
	if (strcmp_maybe_null(a->connect_path, b->connect_path) == 0)
1116
		return 0;
1117
	/* allocated_port and handle are not checked */
1118
	return 1;
1119
}
1120
(-)a/misc.h (+2 lines)
Lines 27-32 struct Forward { Link Here
27
	int	  handle;		/* Handle for dynamic listen ports */
27
	int	  handle;		/* Handle for dynamic listen ports */
28
};
28
};
29
29
30
int forward_equals(const struct Forward *, const struct Forward *);
31
30
/* Common server and client forwarding options. */
32
/* Common server and client forwarding options. */
31
struct ForwardOptions {
33
struct ForwardOptions {
32
	int	 gateway_ports; /* Allow remote connects to forwarded ports. */
34
	int	 gateway_ports; /* Allow remote connects to forwarded ports. */
(-)a/readconf.c (+12 lines)
Lines 284-293 add_local_forward(Options *options, const struct Forward *newfwd) Link Here
284
{
286
{
285
	struct Forward *fwd;
287
	struct Forward *fwd;
286
	extern uid_t original_real_uid;
288
	extern uid_t original_real_uid;
289
	int i;
287
290
288
	if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0 &&
291
	if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0 &&
289
	    newfwd->listen_path == NULL)
292
	    newfwd->listen_path == NULL)
290
		fatal("Privileged ports can only be forwarded by root.");
293
		fatal("Privileged ports can only be forwarded by root.");
294
	/* Don't add duplicates */
295
	for (i = 0; i < options->num_local_forwards; i++) {
296
		if (forward_equals(newfwd, options->local_forwards + i))
297
			return;
298
	}
291
	options->local_forwards = xreallocarray(options->local_forwards,
299
	options->local_forwards = xreallocarray(options->local_forwards,
292
	    options->num_local_forwards + 1,
300
	    options->num_local_forwards + 1,
293
	    sizeof(*options->local_forwards));
301
	    sizeof(*options->local_forwards));
Lines 310-316 void Link Here
310
add_remote_forward(Options *options, const struct Forward *newfwd)
318
add_remote_forward(Options *options, const struct Forward *newfwd)
311
{
319
{
312
	struct Forward *fwd;
320
	struct Forward *fwd;
321
	int i;
313
322
323
	/* Don't add duplicates */
324
	for (i = 0; i < options->num_remote_forwards; i++) {
325
		if (forward_equals(newfwd, options->remote_forwards + i))
326
			return;
327
	}
314
	options->remote_forwards = xreallocarray(options->remote_forwards,
328
	options->remote_forwards = xreallocarray(options->remote_forwards,
315
	    options->num_remote_forwards + 1,
329
	    options->num_remote_forwards + 1,
316
	    sizeof(*options->remote_forwards));
330
	    sizeof(*options->remote_forwards));

Return to bug 2562