Browse Source

Support for multiple secrets

The secrets file is now parsed line by line, and
each line (excluding CR and/or LF) is used as a secret.
Only the first secret is used for signing, but all
secrets are used for verification.
tags/1.0
Timo Röhling 12 years ago
parent
commit
ff33d043b9
2 changed files with 15 additions and 15 deletions
  1. 4
    2
      README.md
  2. 11
    13
      postsrsd.c

+ 4
- 2
README.md View File

33
 
33
 
34
 Configuration
34
 Configuration
35
 =============
35
 =============
36
-The configuration is located in `/etc/default/postsrsd`. You must store 
37
-a secret key in `/etc/postsrsd.secret`. The installer tries to generate 
36
+The configuration is located in `/etc/default/postsrsd`. You must store
37
+at least one secret key in `/etc/postsrsd.secret`. The installer tries to generate
38
 one from `/dev/urandom`. Be careful that no one can guess your secret,
38
 one from `/dev/urandom`. Be careful that no one can guess your secret,
39
 because anyone who knows it can use your mail server as open relay!
39
 because anyone who knows it can use your mail server as open relay!
40
+Each line of `/etc/postsrsd.secret` is used as secret. The first secret is
41
+used for signing and verification, the others for verification only.
40
 
42
 
41
 PostSRSd exposes its functionality via two TCP lookup tables. The
43
 PostSRSd exposes its functionality via two TCP lookup tables. The
42
 recommended Postfix configuration is to add the following fragment to
44
 recommended Postfix configuration is to add the following fragment to

+ 11
- 13
postsrsd.c View File

189
     "\n"
189
     "\n"
190
     "Usage: %s -s<file> -d<domain> [other options]\n"
190
     "Usage: %s -s<file> -d<domain> [other options]\n"
191
     "Options:\n"
191
     "Options:\n"
192
-    "   -s<file>       read secret from file (required)\n"
192
+    "   -s<file>       read secrets from file (required)\n"
193
     "   -d<domain>     set domain name for rewrite (required)\n"
193
     "   -d<domain>     set domain name for rewrite (required)\n"
194
     "   -f<port>       set port for the forward SRS lookup (default: 10001)\n"
194
     "   -f<port>       set port for the forward SRS lookup (default: 10001)\n"
195
     "   -r<port>       set port for the reverse SRS lookup (default: 10002)\n"
195
     "   -r<port>       set port for the reverse SRS lookup (default: 10002)\n"
217
        *user = NULL, *domain = NULL, *chroot_dir = NULL;
217
        *user = NULL, *domain = NULL, *chroot_dir = NULL;
218
   int forward_sock, reverse_sock;
218
   int forward_sock, reverse_sock;
219
   char *secret_file = NULL, *pid_file = NULL;
219
   char *secret_file = NULL, *pid_file = NULL;
220
-  FILE *pf = NULL;
220
+  FILE *pf = NULL, *sf = NULL;
221
   struct passwd *pwd = NULL;
221
   struct passwd *pwd = NULL;
222
-  char secret[1024];
222
+  char secretbuf[1024], *secret = NULL;
223
   char *tmp;
223
   char *tmp;
224
   srs_t *srs;
224
   srs_t *srs;
225
   struct pollfd fds[3];
225
   struct pollfd fds[3];
292
   /* Read secret. The default installation makes this root accessible only. */
292
   /* Read secret. The default installation makes this root accessible only. */
293
   if (secret_file != NULL) {
293
   if (secret_file != NULL) {
294
     size_t len;
294
     size_t len;
295
-    FILE *fp = fopen(secret_file, "rb");
296
-    if (fp == NULL) {
295
+    sf = fopen(secret_file, "rb");
296
+    if (sf == NULL) {
297
       fprintf (stderr, "%s: Cannot open file with secret: %s\n", self, secret_file);
297
       fprintf (stderr, "%s: Cannot open file with secret: %s\n", self, secret_file);
298
       return EXIT_FAILURE;
298
       return EXIT_FAILURE;
299
     }
299
     }
300
-    len = fread(secret, 1, sizeof(secret) - 1, fp);
301
-    if (len == 0 || len > sizeof(secret) - 1) {
302
-      fprintf (stderr, "%s: Cannot read secret from file: %s\n", self, secret_file);
303
-      return EXIT_FAILURE;
304
-    }
305
-    secret[len] = 0;
306
-    fclose (fp);
307
   } else {
300
   } else {
308
     fprintf (stderr, "%s: You must set a secret (-s)\n", self);
301
     fprintf (stderr, "%s: You must set a secret (-s)\n", self);
309
     show_help();
302
     show_help();
371
   }
364
   }
372
 
365
 
373
   srs = srs_new();
366
   srs = srs_new();
374
-  srs_add_secret (srs, secret);
367
+  while ((secret = fgets(secretbuf, sizeof(secretbuf), sf))) {
368
+    secret = strtok(secret, "\r\n");
369
+    if (secret)
370
+      srs_add_secret (srs, secret);
371
+  }
372
+  fclose (sf);
375
   srs_set_separator (srs, '+');
373
   srs_set_separator (srs, '+');
376
 
374
 
377
   fds[0].fd = forward_sock;
375
   fds[0].fd = forward_sock;

Loading…
Cancel
Save