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
 #
23
 #
24
 SRS_SECRET=@SYSCONF_DIR@/@PROJECT_NAME@.secret
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
 # Local ports for TCP list.
32
 # Local ports for TCP list.
27
 # These ports are used to bind the TCP list for postfix. If you change
33
 # These ports are used to bind the TCP list for postfix. If you change
28
 # these, you have to modify the postfix settings accordingly. The ports
34
 # these, you have to modify the postfix settings accordingly. The ports

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

17
 # Load the real configuration.
17
 # Load the real configuration.
18
 EnvironmentFile=@CONFIG_DIR@/@PROJECT_NAME@
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
 [Install]
22
 [Install]
23
 WantedBy=multi-user.target
23
 WantedBy=multi-user.target

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

44
 		--pidfile $PIDFILE \
44
 		--pidfile $PIDFILE \
45
 		--name $NAME \
45
 		--name $NAME \
46
 		--startas $DAEMON \
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
 	then
48
 	then
49
 	    log_end_msg 0
49
 	    log_end_msg 0
50
 	else
50
 	else

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

35
 do_start()
35
 do_start()
36
 {
36
 {
37
 	echo -n "Starting $DESC: "
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
 	               -u "$RUN_AS" -p "$PIDFILE" -a "$SRS_SEPARATOR" -c "$CHROOT" -D -X"$SRS_EXCLUDE_DOMAINS"
40
 	               -u "$RUN_AS" -p "$PIDFILE" -a "$SRS_SEPARATOR" -c "$CHROOT" -D -X"$SRS_EXCLUDE_DOMAINS"
40
 	RETVAL=$?
41
 	RETVAL=$?
41
 	echo
42
 	echo

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

9
 	SRS_DOMAIN=`postconf -h mydomain || true`
9
 	SRS_DOMAIN=`postconf -h mydomain || true`
10
 	SRS_EXCLUDE_DOMAINS=
10
 	SRS_EXCLUDE_DOMAINS=
11
 	. "@CONFIG_DIR@/@PROJECT_NAME@"
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
 end script
13
 end script
14
 
14
 

+ 18
- 2
postsrsd.c View File

219
     "   -s<file>       read secrets from file (required)\n"
219
     "   -s<file>       read secrets from file (required)\n"
220
     "   -d<domain>     set domain name for rewrite (required)\n"
220
     "   -d<domain>     set domain name for rewrite (required)\n"
221
     "   -a<char>       set first separator character which can be one of: -=+ (default: =)\n"
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
     "   -l<addr>       set socket listen address (default: 127.0.0.1)\n"
224
     "   -l<addr>       set socket listen address (default: 127.0.0.1)\n"
223
     "   -f<port>       set port for the forward SRS lookup (default: 10001)\n"
225
     "   -f<port>       set port for the forward SRS lookup (default: 10001)\n"
224
     "   -r<port>       set port for the reverse SRS lookup (default: 10002)\n"
226
     "   -r<port>       set port for the reverse SRS lookup (default: 10002)\n"
242
 
244
 
243
 int main (int argc, char **argv)
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
   int daemonize = FALSE;
248
   int daemonize = FALSE;
247
   char *listen_addr = NULL, *forward_service = NULL, *reverse_service = NULL,
249
   char *listen_addr = NULL, *forward_service = NULL, *reverse_service = NULL,
248
        *user = NULL, *domain = NULL, *chroot_dir = NULL;
250
        *user = NULL, *domain = NULL, *chroot_dir = NULL;
265
   tmp = strrchr(argv[0], '/');
267
   tmp = strrchr(argv[0], '/');
266
   if (tmp) self = strdup(tmp + 1); else self = strdup(argv[0]);
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
     switch (opt) {
271
     switch (opt) {
270
       case '?':
272
       case '?':
271
         return EXIT_FAILURE;
273
         return EXIT_FAILURE;
296
       case 's':
298
       case 's':
297
         secret_file = strdup(optarg);
299
         secret_file = strdup(optarg);
298
         break;
300
         break;
301
+      case 'n':
302
+        hashlength = atoi(optarg);
303
+        break;
304
+      case 'N':
305
+        hashmin = atoi(optarg);
306
+        break;
299
       case 'p':
307
       case 'p':
300
         pid_file = strdup(optarg);
308
         pid_file = strdup(optarg);
301
         break;
309
         break;
334
           domain = strdup(getenv("SRS_DOMAIN"));
342
           domain = strdup(getenv("SRS_DOMAIN"));
335
         if ( getenv("SRS_SEPARATOR") != NULL )
343
         if ( getenv("SRS_SEPARATOR") != NULL )
336
           separator = *getenv("SRS_SEPARATOR");
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
         if ( getenv("SRS_FORWARD_PORT") != NULL )
349
         if ( getenv("SRS_FORWARD_PORT") != NULL )
338
           forward_service = strdup(getenv("SRS_FORWARD_PORT"));
350
           forward_service = strdup(getenv("SRS_FORWARD_PORT"));
339
         if ( getenv("SRS_REVERSE_PORT") != NULL )
351
         if ( getenv("SRS_REVERSE_PORT") != NULL )
473
   fclose (sf);
485
   fclose (sf);
474
 
486
 
475
   srs_set_separator (srs, separator);
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
   for (sc = 0; sc < socket_count; ++sc) {
493
   for (sc = 0; sc < socket_count; ++sc) {
478
     fds[sc].fd = sockets[sc];
494
     fds[sc].fd = sockets[sc];

+ 1
- 1
srs2.c View File

371
 	len = strlen(hash);
371
 	len = strlen(hash);
372
 	if (len < srs->hashmin)
372
 	if (len < srs->hashmin)
373
 		return SRS_EHASHTOOSHORT;
373
 		return SRS_EHASHTOOSHORT;
374
-	if (len < srs->hashlength) {
374
+	if (len > srs->hashlength) {
375
 		tmp = alloca(srs->hashlength + 1);
375
 		tmp = alloca(srs->hashlength + 1);
376
 		strncpy(tmp, hash, srs->hashlength);
376
 		strncpy(tmp, hash, srs->hashlength);
377
 		tmp[srs->hashlength] = '\0';
377
 		tmp[srs->hashlength] = '\0';

Loading…
Cancel
Save