Browse Source

Make hash length and hash minimum length configurable

master
Gedalya 8 years ago
parent
commit
54e5923379

+ 6
- 0
init/postsrsd.default.in View File

@@ -23,6 +23,12 @@ SRS_SEPARATOR==
23 23
 #
24 24
 SRS_SECRET=@SYSCONF_DIR@/@PROJECT_NAME@.secret
25 25
 
26
+# Length of hash to be used in rewritten addresses
27
+SRS_HASHLENGTH=4
28
+
29
+# Minimum length of hash to accept when validating return addresses
30
+SRS_HASHMIN=4
31
+
26 32
 # Local ports for TCP list.
27 33
 # These ports are used to bind the TCP list for postfix. If you change
28 34
 # these, you have to modify the postfix settings accordingly. The ports

+ 1
- 1
init/postsrsd.systemd.in View File

@@ -17,7 +17,7 @@ EnvironmentFile=-/run/@PROJECT_NAME@/default
17 17
 # Load the real configuration.
18 18
 EnvironmentFile=@CONFIG_DIR@/@PROJECT_NAME@
19 19
 
20
-ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ -f "${SRS_FORWARD_PORT}" -r "${SRS_REVERSE_PORT}" -d "${SRS_DOMAIN}" -s "${SRS_SECRET}" -a "${SRS_SEPARATOR}" -u "${RUN_AS}" -c "${CHROOT}" -X"${SRS_EXCLUDE_DOMAINS}"
20
+ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ -f "${SRS_FORWARD_PORT}" -r "${SRS_REVERSE_PORT}" -d "${SRS_DOMAIN}" -s "${SRS_SECRET}" -a "${SRS_SEPARATOR}" -n "${SRS_HASHLENGTH}" -N "${SRS_HASHMIN}" -u "${RUN_AS}" -c "${CHROOT}" -X"${SRS_EXCLUDE_DOMAINS}"
21 21
 
22 22
 [Install]
23 23
 WantedBy=multi-user.target

+ 1
- 1
init/postsrsd.sysv-lsb.in View File

@@ -44,7 +44,7 @@ case "$1" in
44 44
 		--pidfile $PIDFILE \
45 45
 		--name $NAME \
46 46
 		--startas $DAEMON \
47
-		-- -f "$SRS_FORWARD_PORT" -r "$SRS_REVERSE_PORT" -d "$SRS_DOMAIN" -s "$SRS_SECRET" -a "$SRS_SEPARATOR" -u "$RUN_AS" -p "$PIDFILE" -c "$CHROOT" -D -X"$SRS_EXCLUDE_DOMAINS"
47
+		-- -f "$SRS_FORWARD_PORT" -r "$SRS_REVERSE_PORT" -d "$SRS_DOMAIN" -s "$SRS_SECRET" -a "$SRS_SEPARATOR" -n "$SRS_HASHLENGTH" -N "$SRS_HASHMIN" -u "$RUN_AS" -p "$PIDFILE" -c "$CHROOT" -D -X"$SRS_EXCLUDE_DOMAINS"
48 48
 	then
49 49
 	    log_end_msg 0
50 50
 	else

+ 2
- 1
init/postsrsd.sysv-redhat.in View File

@@ -35,7 +35,8 @@ test -r "$SRS_SECRET" -a -n "$SRS_DOMAIN" || exit 0
35 35
 do_start()
36 36
 {
37 37
 	echo -n "Starting $DESC: "
38
-	daemon $DAEMON -f "$SRS_FORWARD_PORT" -r "$SRS_REVERSE_PORT" -d "$SRS_DOMAIN" -s "$SRS_SECRET" \
38
+	daemon $DAEMON -f "$SRS_FORWARD_PORT" -r "$SRS_REVERSE_PORT" -d "$SRS_DOMAIN" \
39
+	               -s "$SRS_SECRET" -n "$SRS_HASHLENGTH" -N "$SRS_HASHMIN" \
39 40
 	               -u "$RUN_AS" -p "$PIDFILE" -a "$SRS_SEPARATOR" -c "$CHROOT" -D -X"$SRS_EXCLUDE_DOMAINS"
40 41
 	RETVAL=$?
41 42
 	echo

+ 1
- 1
init/postsrsd.upstart.in View File

@@ -9,6 +9,6 @@ script
9 9
 	SRS_DOMAIN=`postconf -h mydomain || true`
10 10
 	SRS_EXCLUDE_DOMAINS=
11 11
 	. "@CONFIG_DIR@/@PROJECT_NAME@"
12
-	exec @CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ -f "$SRS_FORWARD_PORT" -r "$SRS_REVERSE_PORT" -d "$SRS_DOMAIN" -s "$SRS_SECRET" -a "$SRS_SEPARATOR" -u "$RUN_AS" -c "$CHROOT" -X"$SRS_EXCLUDE_DOMAINS"
12
+	exec @CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ -f "$SRS_FORWARD_PORT" -r "$SRS_REVERSE_PORT" -d "$SRS_DOMAIN" -s "$SRS_SECRET" -a "$SRS_SEPARATOR" -n "$SRS_HASHLENGTH" -N "$SRS_HASHMIN" -u "$RUN_AS" -c "$CHROOT" -X"$SRS_EXCLUDE_DOMAINS"
13 13
 end script
14 14
 

+ 18
- 2
postsrsd.c View File

@@ -219,6 +219,8 @@ static void show_help ()
219 219
     "   -s<file>       read secrets from file (required)\n"
220 220
     "   -d<domain>     set domain name for rewrite (required)\n"
221 221
     "   -a<char>       set first separator character which can be one of: -=+ (default: =)\n"
222
+    "   -n<num>        length of hash to be used in rewritten addresses (default: 4)\n"
223
+    "   -N<num>        minimum length of hash to accept for validation (default: 4)\n"
222 224
     "   -l<addr>       set socket listen address (default: 127.0.0.1)\n"
223 225
     "   -f<port>       set port for the forward SRS lookup (default: 10001)\n"
224 226
     "   -r<port>       set port for the reverse SRS lookup (default: 10002)\n"
@@ -242,7 +244,7 @@ typedef void(*handle_t)(srs_t*, FILE*, const char*, const char*, const char**);
242 244
 
243 245
 int main (int argc, char **argv)
244 246
 {
245
-  int opt, timeout = 1800, family = AF_UNSPEC;
247
+  int opt, timeout = 1800, family = AF_UNSPEC, hashlength = 0, hashmin = 0;
246 248
   int daemonize = FALSE;
247 249
   char *listen_addr = NULL, *forward_service = NULL, *reverse_service = NULL,
248 250
        *user = NULL, *domain = NULL, *chroot_dir = NULL;
@@ -265,7 +267,7 @@ int main (int argc, char **argv)
265 267
   tmp = strrchr(argv[0], '/');
266 268
   if (tmp) self = strdup(tmp + 1); else self = strdup(argv[0]);
267 269
 
268
-  while ((opt = getopt(argc, argv, "46d:a:l:f:r:s:u:t:p:c:X::Dhev")) != -1) {
270
+  while ((opt = getopt(argc, argv, "46d:a:l:f:r:s:n:N:u:t:p:c:X::Dhev")) != -1) {
269 271
     switch (opt) {
270 272
       case '?':
271 273
         return EXIT_FAILURE;
@@ -296,6 +298,12 @@ int main (int argc, char **argv)
296 298
       case 's':
297 299
         secret_file = strdup(optarg);
298 300
         break;
301
+      case 'n':
302
+        hashlength = atoi(optarg);
303
+        break;
304
+      case 'N':
305
+        hashmin = atoi(optarg);
306
+        break;
299 307
       case 'p':
300 308
         pid_file = strdup(optarg);
301 309
         break;
@@ -334,6 +342,10 @@ int main (int argc, char **argv)
334 342
           domain = strdup(getenv("SRS_DOMAIN"));
335 343
         if ( getenv("SRS_SEPARATOR") != NULL )
336 344
           separator = *getenv("SRS_SEPARATOR");
345
+        if ( getenv("SRS_HASHLENGTH") != NULL )
346
+          hashlength = atoi(getenv("SRS_HASHLENGTH"));
347
+        if ( getenv("SRS_HASHMIN") != NULL )
348
+          hashmin = atoi(getenv("SRS_HASHMIN"));
337 349
         if ( getenv("SRS_FORWARD_PORT") != NULL )
338 350
           forward_service = strdup(getenv("SRS_FORWARD_PORT"));
339 351
         if ( getenv("SRS_REVERSE_PORT") != NULL )
@@ -473,6 +485,10 @@ int main (int argc, char **argv)
473 485
   fclose (sf);
474 486
 
475 487
   srs_set_separator (srs, separator);
488
+  if (hashlength)
489
+    srs_set_hashlength (srs, hashlength);
490
+  if (hashmin)
491
+    srs_set_hashmin (srs, hashmin);
476 492
 
477 493
   for (sc = 0; sc < socket_count; ++sc) {
478 494
     fds[sc].fd = sockets[sc];

+ 1
- 1
srs2.c View File

@@ -371,7 +371,7 @@ srs_hash_check(srs_t *srs, char *hash, int nargs, ...)
371 371
 	len = strlen(hash);
372 372
 	if (len < srs->hashmin)
373 373
 		return SRS_EHASHTOOSHORT;
374
-	if (len < srs->hashlength) {
374
+	if (len > srs->hashlength) {
375 375
 		tmp = alloca(srs->hashlength + 1);
376 376
 		strncpy(tmp, hash, srs->hashlength);
377 377
 		tmp[srs->hashlength] = '\0';

Loading…
Cancel
Save