Mercurial > masqmail
annotate src/local.c @ 434:f2a7271746d1 default tip
Removes Freshmeat.net from the docs
The site, which was later renamed to freecode.com, is no longer
maintained (contains only a static copy).
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Sat, 07 Feb 2015 11:45:07 +0100 |
parents | f609a05ddff8 |
children |
rev | line source |
---|---|
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
1 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
2 ** MasqMail |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
3 ** Copyright (C) 1999-2001 Oliver Kurth |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
4 ** Copyright (C) 2010 markus schnalke <meillo@marmaro.de> |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
5 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
6 ** This program is free software; you can redistribute it and/or modify |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
7 ** it under the terms of the GNU General Public License as published by |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
8 ** the Free Software Foundation; either version 2 of the License, or |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
9 ** (at your option) any later version. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
10 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
11 ** This program is distributed in the hope that it will be useful, |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
14 ** GNU General Public License for more details. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
15 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
16 ** You should have received a copy of the GNU General Public License |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
17 ** along with this program; if not, write to the Free Software |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
18 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
0 | 19 */ |
20 | |
15 | 21 #include <sys/wait.h> |
169 | 22 #include <sys/stat.h> |
15 | 23 |
0 | 24 #include "masqmail.h" |
25 #include "peopen.h" | |
26 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
27 static void |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
332
diff
changeset
|
28 message_stream(FILE *out, message *msg, GList *hdr_list, guint flags) |
0 | 29 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
30 time_t now = time(NULL); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
31 GList *node; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
32 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
33 if (flags & MSGSTR_FROMLINE) { |
408 | 34 fprintf(out, "From <%s@%s> %s", msg->return_path->local_part, |
35 msg->return_path->domain, ctime(&now)); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
36 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
37 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
38 foreach(hdr_list, node) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
39 header *hdr = (header *) (node->data); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
40 fputs(hdr->header, out); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
41 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
42 putc('\n', out); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
43 foreach(msg->data_list, node) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
44 /* From hack: */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
45 if (flags & MSGSTR_FROMHACK) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 if (strncmp(node->data, "From ", 5) == 0) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
47 putc('>', out); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
48 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
49 fputs(node->data, out); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
50 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
51 putc('\n', out); |
0 | 52 } |
53 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
54 gboolean |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
332
diff
changeset
|
55 append_file(message *msg, GList *hdr_list, gchar *user) |
0 | 56 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
57 struct passwd *pw; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
58 gboolean ok = FALSE; |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
59 uid_t saved_uid = geteuid(); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
60 gid_t saved_gid = getegid(); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
61 gboolean uid_ok = TRUE, gid_ok = TRUE; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
62 gchar *filename; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
63 FILE *out; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
64 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
65 /* headers may be special for a local delivery */ |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
66 if (!hdr_list) |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
67 hdr_list = msg->hdr_list; |
0 | 68 |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
69 if (!(pw = getpwnam(user))) { |
408 | 70 logwrite(LOG_ALERT, "could not find password entry for " |
71 "user %s\n", user); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
72 errno = ENOENT; /* getpwnam does not set errno correctly */ |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
73 return FALSE; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
74 } |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
75 |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
76 if (!conf.run_as_user) { |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
77 uid_ok = (seteuid(0) == 0); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
78 if (uid_ok) { |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
79 gid_ok = (setegid(conf.mail_gid) == 0); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
80 uid_ok = (seteuid(pw->pw_uid) == 0); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
81 } |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
82 if (!uid_ok || !gid_ok) { |
408 | 83 logwrite(LOG_ALERT, "could not set uid or gid for " |
84 "local delivery, uid = %d: %s\n", | |
85 pw->pw_uid, strerror(errno)); | |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
86 return FALSE; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
87 } |
0 | 88 } |
89 | |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
90 DEBUG(5) debugf("running as euid %d, egid %d\n", geteuid(), getegid()); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
91 |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
92 filename = g_strdup_printf("%s/%s", conf.mail_dir, user); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
93 if (!(out = fopen(filename, "a"))) { |
408 | 94 logwrite(LOG_ALERT, "could not open file %s: %s\n", |
95 filename, strerror(errno)); | |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
96 } else { |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
97 #ifdef USE_LIBLOCKFILE |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
98 gint err; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
99 /* lock file using liblockfile */ |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
100 err = maillock(user, 3); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
101 if (err == 0) { |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
102 #else |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
103 /* lock file: */ |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
104 struct flock lock; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
105 lock.l_type = F_WRLCK; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
106 lock.l_whence = SEEK_END; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
107 lock.l_start = lock.l_len = 0; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
108 if (fcntl(fileno(out), F_SETLK, &lock) != -1) { |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
109 #endif |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
110 fchmod(fileno(out), 0600); |
408 | 111 message_stream(out, msg, hdr_list, |
112 MSGSTR_FROMLINE | MSGSTR_FROMHACK); | |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
113 ok = TRUE; |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
114 |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
115 /* close when still user */ |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
116 fclose(out); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
117 #ifdef USE_LIBLOCKFILE |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
118 mailunlock(); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
119 #endif |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
120 } else { |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
121 fclose(out); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
122 #ifdef USE_LIBLOCKFILE |
408 | 123 DEBUG(3) debugf("could not lock file %s: error %d\n", |
124 filename, err); | |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
125 } /* XEmacs indenting convenience... */ |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
126 #else |
408 | 127 DEBUG(3) debugf("could not lock file %s: %s\n", |
128 filename, strerror(errno)); | |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
129 } |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
130 #endif |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
131 } |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
132 g_free(filename); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
133 |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
134 if (!conf.run_as_user) { |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
135 uid_ok = (seteuid(0) == 0); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
136 if (uid_ok) { |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
137 gid_ok = (setegid(saved_gid) == 0); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
138 uid_ok = (seteuid(saved_uid) == 0); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
139 } |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
140 } |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
141 |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
142 if (!uid_ok || !gid_ok) { |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
143 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
144 ** FIXME: if this fails we HAVE to exit, because we shall |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
145 ** not run with some users id. But we do not return, and so |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
146 ** this message will not be finished, so the user will get |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
147 ** the message again next time a delivery is attempted... |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
148 */ |
408 | 149 logwrite(LOG_ALERT, "could not set back uid or gid after " |
150 "local delivery: %s\n", strerror(errno)); | |
151 logwrite(LOG_ALERT, "uid=%d, gid=%d, euid=%d, egid=%d, " | |
152 "want = %d, %d\n", getuid(), getgid(), | |
153 geteuid(), getegid(), saved_uid, saved_gid); | |
154 logwrite(LOG_ALERT, "In case of trouble, see " | |
155 "local.c:append_file() for details.\n", | |
156 strerror(errno)); | |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
157 exit(1); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
158 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
159 return ok; |
0 | 160 } |
161 | |
162 gboolean | |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
332
diff
changeset
|
163 pipe_out(message *msg, GList *hdr_list, address *rcpt, gchar *cmd, guint flags) |
0 | 164 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
165 gchar *envp[40]; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
166 FILE *out; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
167 uid_t saved_uid = geteuid(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
168 gid_t saved_gid = getegid(); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
169 gboolean ok = FALSE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
170 gint i, n; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
171 pid_t pid; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
172 void (*old_signal) (int); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
173 int status; |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
174 address *ancestor = addr_find_ancestor(rcpt); |
0 | 175 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
176 /* set uid and gid to the mail ids */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
177 if (!conf.run_as_user) { |
408 | 178 set_euidgid(conf.mail_uid, conf.mail_gid, |
179 &saved_uid, &saved_gid); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
180 } |
0 | 181 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
182 /* set environment */ |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
183 n = 0; |
408 | 184 envp[n++] = g_strdup_printf("SENDER=%s@%s", |
185 msg->return_path->local_part, | |
186 msg->return_path->domain); | |
187 envp[n++] = g_strdup_printf("SENDER_DOMAIN=%s", | |
188 msg->return_path->domain); | |
189 envp[n++] = g_strdup_printf("SENDER_LOCAL=%s", | |
190 msg->return_path->local_part); | |
191 envp[n++] = g_strdup_printf("RECEIVED_HOST=%s", | |
192 msg->received_host ? msg->received_host : ""); | |
0 | 193 |
408 | 194 envp[n++] = g_strdup_printf("RETURN_PATH=%s@%s", |
195 msg->return_path->local_part, | |
196 msg->return_path->domain); | |
197 envp[n++] = g_strdup_printf("DOMAIN=%s", | |
198 ancestor->domain); | |
0 | 199 |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
200 envp[n++] = g_strdup_printf("LOCAL_PART=%s", ancestor->local_part); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
201 envp[n++] = g_strdup_printf("USER=%s", ancestor->local_part); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
202 envp[n++] = g_strdup_printf("LOGNAME=%s", ancestor->local_part); |
0 | 203 |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
204 envp[n++] = g_strdup_printf("MESSAGE_ID=%s", msg->uid); |
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
205 envp[n++] = g_strdup_printf("QUALIFY_DOMAIN=%s", conf.host_name); |
0 | 206 |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
207 envp[n] = NULL; |
0 | 208 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
209 old_signal = signal(SIGCHLD, SIG_DFL); |
0 | 210 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
211 out = peidopen(cmd, "w", envp, &pid, conf.mail_uid, conf.mail_gid); |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
212 if (!out) { |
408 | 213 logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", |
214 cmd, strerror(errno)); | |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
215 } else { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
216 message_stream(out, msg, hdr_list, flags); |
0 | 217 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
218 fclose(out); |
0 | 219 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
220 waitpid(pid, &status, 0); |
0 | 221 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
222 if (WEXITSTATUS(status) != 0) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
223 int exstat = WEXITSTATUS(status); |
408 | 224 logwrite(LOG_ALERT, "process returned %d (%s)\n", |
225 exstat, ext_strerror(1024 + exstat)); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
226 errno = 1024 + exstat; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
227 } else if (WIFSIGNALED(status)) { |
408 | 228 logwrite(LOG_ALERT, "process got signal %d\n", |
229 WTERMSIG(status)); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
230 } else |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
231 ok = TRUE; |
0 | 232 |
332
63efd381e27b
refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents:
262
diff
changeset
|
233 } |
0 | 234 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
235 signal(SIGCHLD, old_signal); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
236 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
237 /* free environment */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
238 for (i = 0; i < n; i++) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
239 g_free(envp[i]); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
240 } |
0 | 241 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
242 /* set uid and gid back */ |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
243 if (!conf.run_as_user) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
244 set_euidgid(saved_uid, saved_gid, NULL, NULL); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
245 } |
0 | 246 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
247 return ok; |
0 | 248 } |