Browse Source

Make SRS separator configurable

tags/1.3
Timo Röhling 9 years ago
parent
commit
90718d708b
2 changed files with 19 additions and 2 deletions
  1. 4
    0
      init/postsrsd.default.in
  2. 15
    2
      postsrsd.c

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

13
 #
13
 #
14
 #SRS_EXCLUDE_DOMAINS=.example.com,example.org
14
 #SRS_EXCLUDE_DOMAINS=.example.com,example.org
15
 
15
 
16
+# First separator character after SRS0 or SRS1.
17
+# Can be one of: -+=
18
+#SRS_SEPARATOR==
19
+
16
 # Secret key to sign rewritten addresses.
20
 # Secret key to sign rewritten addresses.
17
 # When postsrsd is installed for the first time, a random secret is generated
21
 # When postsrsd is installed for the first time, a random secret is generated
18
 # and stored in /etc/postsrsd.secret. For most installations, that's just fine.
22
 # and stored in /etc/postsrsd.secret. For most installations, that's just fine.

+ 15
- 2
postsrsd.c View File

214
     "Options:\n"
214
     "Options:\n"
215
     "   -s<file>       read secrets from file (required)\n"
215
     "   -s<file>       read secrets from file (required)\n"
216
     "   -d<domain>     set domain name for rewrite (required)\n"
216
     "   -d<domain>     set domain name for rewrite (required)\n"
217
+    "   -a<char>       set first separator character which can be one of: -=+ (default: =)\n"
217
     "   -f<port>       set port for the forward SRS lookup (default: 10001)\n"
218
     "   -f<port>       set port for the forward SRS lookup (default: 10001)\n"
218
     "   -r<port>       set port for the reverse SRS lookup (default: 10002)\n"
219
     "   -r<port>       set port for the reverse SRS lookup (default: 10002)\n"
219
     "   -p<pidfile>    write process ID to pidfile (default: none)\n"
220
     "   -p<pidfile>    write process ID to pidfile (default: none)\n"
240
   int daemonize = FALSE;
241
   int daemonize = FALSE;
241
   char *forward_service = NULL, *reverse_service = NULL,
242
   char *forward_service = NULL, *reverse_service = NULL,
242
        *user = NULL, *domain = NULL, *chroot_dir = NULL;
243
        *user = NULL, *domain = NULL, *chroot_dir = NULL;
244
+  char separator = '=';
243
   int forward_sock, reverse_sock;
245
   int forward_sock, reverse_sock;
244
   char *secret_file = NULL, *pid_file = NULL;
246
   char *secret_file = NULL, *pid_file = NULL;
245
   FILE *pf = NULL, *sf = NULL;
247
   FILE *pf = NULL, *sf = NULL;
257
   tmp = strrchr(argv[0], '/');
259
   tmp = strrchr(argv[0], '/');
258
   if (tmp) self = strdup(tmp + 1); else self = strdup(argv[0]);
260
   if (tmp) self = strdup(tmp + 1); else self = strdup(argv[0]);
259
 
261
 
260
-  while ((opt = getopt(argc, argv, "46d:f:r:s:u:t:p:c:X::Dhev")) != -1) {
262
+  while ((opt = getopt(argc, argv, "46d:a:f:r:s:u:t:p:c:X::Dhev")) != -1) {
261
     switch (opt) {
263
     switch (opt) {
262
       case '?':
264
       case '?':
263
         return EXIT_FAILURE;
265
         return EXIT_FAILURE;
270
       case 'd':
272
       case 'd':
271
         domain = strdup(optarg);
273
         domain = strdup(optarg);
272
         break;
274
         break;
275
+      case 'a':
276
+        separator = *optarg;
277
+        break;
273
       case 'f':
278
       case 'f':
274
         forward_service = strdup(optarg);
279
         forward_service = strdup(optarg);
275
         break;
280
         break;
318
       case 'e':
323
       case 'e':
319
         if ( getenv("SRS_DOMAIN") != NULL )
324
         if ( getenv("SRS_DOMAIN") != NULL )
320
           domain = strdup(getenv("SRS_DOMAIN"));
325
           domain = strdup(getenv("SRS_DOMAIN"));
326
+        if ( getenv("SRS_SEPARATOR") != NULL )
327
+          separator = *getenv("SRS_SEPARATOR");
321
         if ( getenv("SRS_FORWARD_PORT") != NULL )
328
         if ( getenv("SRS_FORWARD_PORT") != NULL )
322
           forward_service = strdup(getenv("SRS_FORWARD_PORT"));
329
           forward_service = strdup(getenv("SRS_FORWARD_PORT"));
323
         if ( getenv("SRS_REVERSE_PORT") != NULL )
330
         if ( getenv("SRS_REVERSE_PORT") != NULL )
363
     return EXIT_FAILURE;
370
     return EXIT_FAILURE;
364
   }
371
   }
365
 
372
 
373
+  if (separator != '=' && separator != '+' && separator != '-') {
374
+    fprintf (stderr, "%s: SRS separator character must be one of '=+-'\n", self);
375
+    return EXIT_FAILURE;
376
+  }
377
+
366
   /* The stuff we do first may not be possible from within chroot or without privileges */
378
   /* The stuff we do first may not be possible from within chroot or without privileges */
367
 
379
 
368
   /* Open pid file for writing (the actual process ID is filled in later) */
380
   /* Open pid file for writing (the actual process ID is filled in later) */
455
       srs_add_secret (srs, secret);
467
       srs_add_secret (srs, secret);
456
   }
468
   }
457
   fclose (sf);
469
   fclose (sf);
458
-  srs_set_separator (srs, '+');
470
+
471
+  srs_set_separator (srs, separator);
459
 
472
 
460
   fds[0].fd = forward_sock;
473
   fds[0].fd = forward_sock;
461
   fds[0].events = POLLIN;
474
   fds[0].events = POLLIN;

Loading…
Cancel
Save