annotate src/local.c @ 379:193013200396

Updated ChangeLog and NEWS.
author markus schnalke <meillo@marmaro.de>
date Wed, 18 Jan 2012 09:31:35 +0100
parents b27f66555ba8
children f609a05ddff8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
20
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
21 #include <sys/wait.h>
169
d1c53e76096f added a missing #include <sys/stat.h>
meillo@marmaro.de
parents: 114
diff changeset
22 #include <sys/stat.h>
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
23
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
24 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
25 #include "peopen.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
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) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
34 fprintf(out, "From <%s@%s> %s", msg->return_path->local_part, msg->return_path->domain, ctime(&now));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
35 }
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 foreach(hdr_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
38 header *hdr = (header *) (node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
39 fputs(hdr->header, out);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
40 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
41 putc('\n', out);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
42 foreach(msg->data_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
43 /* From hack: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
44 if (flags & MSGSTR_FROMHACK) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
45 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
46 putc('>', out);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
47 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
48 fputs(node->data, out);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
49 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
50 putc('\n', out);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
51 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
52
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
53 gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 332
diff changeset
54 append_file(message *msg, GList *hdr_list, gchar *user)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
55 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
56 struct passwd *pw;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
57 gboolean ok = FALSE;
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
58 uid_t saved_uid = geteuid();
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
59 gid_t saved_gid = getegid();
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
60 gboolean uid_ok = TRUE, gid_ok = TRUE;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
61 gchar *filename;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
62 FILE *out;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
63
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
64 /* 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
65 if (!hdr_list)
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
66 hdr_list = msg->hdr_list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
67
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
68 if (!(pw = getpwnam(user))) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
69 logwrite(LOG_ALERT, "could not find password entry for user %s\n", user);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
70 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
71 return FALSE;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
72 }
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
73
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
74 if (!conf.run_as_user) {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
75 uid_ok = (seteuid(0) == 0);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
76 if (uid_ok) {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
77 gid_ok = (setegid(conf.mail_gid) == 0);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
78 uid_ok = (seteuid(pw->pw_uid) == 0);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
79 }
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
80 if (!uid_ok || !gid_ok) {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
81 logwrite(LOG_ALERT, "could not set uid or gid for local delivery, uid = %d: %s\n", pw->pw_uid, strerror(errno));
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
82 return FALSE;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
83 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
84 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
85
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
86 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
87
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
88 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
89 if (!(out = fopen(filename, "a"))) {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
90 logwrite(LOG_ALERT, "could not open file %s: %s\n", filename, strerror(errno));
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
91 } else {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
92 #ifdef USE_LIBLOCKFILE
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
93 gint err;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
94 /* lock file using liblockfile */
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
95 err = maillock(user, 3);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
96 if (err == 0) {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
97 #else
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
98 /* lock file: */
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
99 struct flock lock;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
100 lock.l_type = F_WRLCK;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
101 lock.l_whence = SEEK_END;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
102 lock.l_start = lock.l_len = 0;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
103 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
104 #endif
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
105 fchmod(fileno(out), 0600);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
106 message_stream(out, msg, hdr_list, MSGSTR_FROMLINE | MSGSTR_FROMHACK);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
107 ok = TRUE;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
108
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
109 /* close when still user */
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
110 fclose(out);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
111 #ifdef USE_LIBLOCKFILE
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
112 mailunlock();
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
113 #endif
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
114 } else {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
115 fclose(out);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
116 #ifdef USE_LIBLOCKFILE
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
117 DEBUG(3) debugf("could not lock file %s: error %d\n", filename, err);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
118 } /* XEmacs indenting convenience... */
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
119 #else
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
120 DEBUG(3) debugf("could not lock file %s: %s\n", filename, strerror(errno));
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
121 }
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
122 #endif
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
123 }
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
124 g_free(filename);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
125
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
126 if (!conf.run_as_user) {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
127 uid_ok = (seteuid(0) == 0);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
128 if (uid_ok) {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
129 gid_ok = (setegid(saved_gid) == 0);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
130 uid_ok = (seteuid(saved_uid) == 0);
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 }
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 (!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
135 /*
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
136 ** 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
137 ** 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
138 ** 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
139 ** 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
140 */
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
141 logwrite(LOG_ALERT, "could not set back uid or gid after local delivery: %s\n", strerror(errno));
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
142 logwrite(LOG_ALERT, "uid=%d, gid=%d, euid=%d, egid=%d, want = %d, %d\n",
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
143 getuid(), getgid(), geteuid(), getegid(), saved_uid, saved_gid);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
144 logwrite(LOG_ALERT, "In case of trouble, see local.c:append_file() for details.\n", strerror(errno));
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
145 exit(1);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
146 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
147 return ok;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
148 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
149
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
150 gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 332
diff changeset
151 pipe_out(message *msg, GList *hdr_list, address *rcpt, gchar *cmd, guint flags)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
152 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
153 gchar *envp[40];
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
154 FILE *out;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
155 uid_t saved_uid = geteuid();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
156 gid_t saved_gid = getegid();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
157 gboolean ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
158 gint i, n;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
159 pid_t pid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
160 void (*old_signal) (int);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
161 int status;
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
162 address *ancestor = addr_find_ancestor(rcpt);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
163
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
164 /* 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
165 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
166 set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
167 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
168
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
169 /* set environment */
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
170 n = 0;
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
171 envp[n++] = g_strdup_printf("SENDER=%s@%s", msg->return_path->local_part, msg->return_path->domain);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
172 envp[n++] = g_strdup_printf("SENDER_DOMAIN=%s", msg->return_path->domain);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
173 envp[n++] = g_strdup_printf("SENDER_LOCAL=%s", msg->return_path->local_part);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
174 envp[n++] = g_strdup_printf("RECEIVED_HOST=%s", msg->received_host ? msg->received_host : "");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
175
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
176 envp[n++] = g_strdup_printf("RETURN_PATH=%s@%s", msg->return_path->local_part, msg->return_path->domain);
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
177 envp[n++] = g_strdup_printf("DOMAIN=%s", ancestor->domain);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
178
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
179 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
180 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
181 envp[n++] = g_strdup_printf("LOGNAME=%s", ancestor->local_part);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
182
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
183 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
184 envp[n++] = g_strdup_printf("QUALIFY_DOMAIN=%s", conf.host_name);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
185
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
186 envp[n] = NULL;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
187
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
188 old_signal = signal(SIGCHLD, SIG_DFL);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
189
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
190 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
191 if (!out) {
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
192 logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", cmd, strerror(errno));
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
193 } else {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
194 message_stream(out, msg, hdr_list, flags);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
195
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
196 fclose(out);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
197
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
198 waitpid(pid, &status, 0);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
199
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
200 if (WEXITSTATUS(status) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
201 int exstat = WEXITSTATUS(status);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
202 logwrite(LOG_ALERT, "process returned %d (%s)\n", exstat, ext_strerror(1024 + exstat));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
203 errno = 1024 + exstat;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
204 } else if (WIFSIGNALED(status)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
205 logwrite(LOG_ALERT, "process got signal %d\n", WTERMSIG(status));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
206 } else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
207 ok = TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
208
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
209 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
210
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
211 signal(SIGCHLD, old_signal);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
212
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
213 /* free environment */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
214 for (i = 0; i < n; i++) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
215 g_free(envp[i]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
216 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
217
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
218 /* set uid and gid back */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
219 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
220 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
221 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
222
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
223 return ok;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
224 }