File: 10myorigin.dpatch

package info (click to toggle)
postfix 2.3.8-2%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 15,744 kB
  • ctags: 11,426
  • sloc: ansic: 81,810; makefile: 10,743; sh: 7,874; perl: 2,468; awk: 41
file content (73 lines) | stat: -rw-r--r-- 2,088 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /bin/sh /usr/share/dpatch/dpatch-run
## 10myorigin.dpatch by LaMont Jones <lamont@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Allow myorigin to be /path/to/file

@DPATCH@
diff -urNad postfix~/src/global/mail_params.c postfix/src/global/mail_params.c
--- postfix~/src/global/mail_params.c	2006-07-24 10:24:45.000000000 -0600
+++ postfix/src/global/mail_params.c	2006-10-18 10:39:22.000000000 -0600
@@ -157,6 +157,8 @@
 #include <valid_hostname.h>
 #include <stringops.h>
 #include <safe.h>
+#include <safe_open.h>
+#include <mymalloc.h>
 #ifdef HAS_DB
 #include <dict_db.h>
 #endif
@@ -433,6 +435,40 @@
 		  (long) var_sgid_gid);
 }
 
+static char *read_file(const char *name)
+{
+    char *ret;
+    VSTRING *why=vstring_alloc(1);
+    VSTRING *new_name=vstring_alloc(1);
+    VSTREAM *vp=safe_open(name, O_RDONLY, 0, NULL, -1, -1, why);
+
+    /*
+     * Ugly macros to make complex expressions less unreadable.
+     */
+#define SKIP(start, var, cond) \
+	for (var = start; *var && (cond); var++);
+
+#define TRIM(s) { \
+	char *p; \
+	for (p = (s) + strlen(s); p > (s) && ISSPACE(p[-1]); p--); \
+	*p = 0; \
+    }
+
+    if (!vp) {
+	msg_fatal("%s: unable to open: %s",name,vstring_str(why));
+    }
+    vstring_get_nonl(new_name,vp);
+    vstream_fclose(vp);
+    SKIP(vstring_str(new_name),ret,ISSPACE(*ret));
+    ret=mystrdup(ret);
+    if (*ret) {	/* empty strings are shared */
+	TRIM(ret);
+    }
+    vstring_free(why);
+    vstring_free(new_name);
+    return ret;
+}
+
 /* mail_params_init - configure built-in parameters */
 
 void    mail_params_init()
@@ -584,6 +620,12 @@
      * Variables that are needed by almost every program.
      */
     get_mail_conf_str_table(other_str_defaults);
+    if (*var_myorigin=='/') {
+	char *origin=read_file(var_myorigin);
+	if (!origin || !*origin)
+	    msg_fatal("myorigin file %s is empty",var_myorigin);
+	var_myorigin=origin;
+    }
     get_mail_conf_int_table(other_int_defaults);
     get_mail_conf_bool_table(bool_defaults);
     get_mail_conf_time_table(time_defaults);