annotate src/local.c @ 114:a80ebfa16cd5

better debugging output (thanks to Paolo)
author meillo@marmaro.de
date Wed, 30 Jun 2010 15:00:59 +0200
parents f671821d8222
children d1c53e76096f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
1 /* MasqMail
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
2 Copyright (C) 1999-2001 Oliver Kurth
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
3
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
7 (at your option) any later version.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
8
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
12 GNU General Public License for more details.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
13
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
15 along with this program; if not, write to the Free Software
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
17 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
18
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
19 #include <sys/wait.h>
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
20
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
21 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
22 #include "peopen.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
23
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
24 static void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
25 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
26 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
27 time_t now = time(NULL);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
28 GList *node;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
29
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
30 if (flags & MSGSTR_FROMLINE) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
31 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
32 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
33
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
34 foreach(hdr_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
35 header *hdr = (header *) (node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
36 fputs(hdr->header, out);
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 putc('\n', out);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
39 foreach(msg->data_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
40 /* From hack: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
41 if (flags & MSGSTR_FROMHACK) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
42 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
43 putc('>', out);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
44 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
45 fputs(node->data, out);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
46 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
47 putc('\n', out);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
48 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
49
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
50 gboolean
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
51 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
52 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
53 struct passwd *pw;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
54 gboolean ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
55
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
56 /* headers may be special for a local delivery */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
57 if (hdr_list == NULL)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
58 hdr_list = msg->hdr_list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
59
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
60 if ((pw = getpwnam(user))) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
61 uid_t saved_uid = geteuid();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
62 gid_t saved_gid = getegid();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
63 gboolean uid_ok = TRUE, gid_ok = TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
64
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
65 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
66 uid_ok = (seteuid(0) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
67 if (uid_ok) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
68 gid_ok = (setegid(conf.mail_gid) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
69 uid_ok = (seteuid(pw->pw_uid) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
70 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
71 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
72
114
a80ebfa16cd5 better debugging output (thanks to Paolo)
meillo@marmaro.de
parents: 15
diff changeset
73 DEBUG(5) debugf("running as euid %d, egid %d\n", geteuid(), getegid());
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
74
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
75 if (uid_ok && gid_ok) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
76 gchar *filename;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
77 FILE *out;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
78
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
79 filename = g_strdup_printf("%s/%s", conf.mail_dir, user);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
80 if ((out = fopen(filename, "a"))) {
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
81 #ifdef USE_LIBLOCKFILE
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
82 gint err;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
83 /* lock file using liblockfile */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
84 err = maillock(user, 3);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
85 if (err == 0) {
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
86 #else
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
87 /* lock file: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
88 struct flock lock;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
89 lock.l_type = F_WRLCK;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
90 lock.l_whence = SEEK_END;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
91 lock.l_start = lock.l_len = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
92 if (fcntl(fileno(out), F_SETLK, &lock) != -1) {
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
93 #endif
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
94 fchmod(fileno(out), 0600);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
95 message_stream(out, msg, hdr_list, MSGSTR_FROMLINE | MSGSTR_FROMHACK);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
96 ok = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
97
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
98 /* close when still user */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
99 fclose(out);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
100 #ifdef USE_LIBLOCKFILE
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
101 mailunlock();
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
102 #endif
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
103 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
104 fclose(out);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
105 #ifdef USE_LIBLOCKFILE
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
106 DEBUG(3) debugf("could not lock file %s: error %d\n", filename, err);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
107 } /* XEmacs indenting convenience... */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
108 #else
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
109 DEBUG(3) debugf("could not lock file %s: %s\n", filename, strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
110 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
111 #endif
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
112 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
113 logwrite(LOG_ALERT, "could not open file %s: %s\n", filename, strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
114 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
115 g_free(filename);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
116
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
117 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
118 uid_ok = (seteuid(0) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
119 if (uid_ok) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
120 gid_ok = (setegid(saved_gid) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
121 uid_ok = (seteuid(saved_uid) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
122 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
123 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
124
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
125 if (!uid_ok || !gid_ok) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
126 /* FIXME: if this fails we HAVE to exit, because we shall not run
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
127 with some users id. But we do not return, and so this message
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
128 will not be finished, so the user will get the message again
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
129 next time a delivery is attempted... */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
130 logwrite(LOG_ALERT, "could not set back uid or gid after local delivery: %s\n", strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
131 logwrite(LOG_ALERT, "uid=%d, gid=%d, euid=%d, egid=%d, want = %d, %d\n",
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
132 getuid(), getgid(), geteuid(), getegid(), saved_uid, saved_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
133 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
134 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
135 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
136 logwrite(LOG_ALERT, "could not set uid or gid for local delivery, uid = %d: %s\n", pw->pw_uid, strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
137 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
138 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
139 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
140 errno = ENOENT; /* getpwnam does not set errno correctly */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
141 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
142
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
143 return ok;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
144 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
145
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
146 #ifdef ENABLE_MAILDIR
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
147 gboolean
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
148 maildir_out(message * msg, GList * hdr_list, gchar * user, guint flags)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
149 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
150 struct passwd *pw;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
151 gboolean ok = FALSE;
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 /* headers may be special for a local delivery */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
154 if (hdr_list == NULL)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
155 hdr_list = msg->hdr_list;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
156
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
157 if ((pw = getpwnam(user))) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
158 uid_t saved_uid = geteuid();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
159 gid_t saved_gid = getegid();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
160 gboolean uid_ok = TRUE, gid_ok = TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
161
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
162 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
163 uid_ok = (seteuid(0) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
164 if (uid_ok) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
165 gid_ok = (setegid(conf.mail_gid) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
166 uid_ok = (seteuid(pw->pw_uid) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
167 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
168 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
169
114
a80ebfa16cd5 better debugging output (thanks to Paolo)
meillo@marmaro.de
parents: 15
diff changeset
170 DEBUG(5) debugf("running as euid %d, egid %d\n", geteuid(), getegid());
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
171
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
172 if (uid_ok && gid_ok) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
173 char *path = g_strdup_printf("%s/Maildir", pw->pw_dir);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
174 struct stat statbuf;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
175 int ret;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
176
114
a80ebfa16cd5 better debugging output (thanks to Paolo)
meillo@marmaro.de
parents: 15
diff changeset
177 DEBUG(5) debugf(" path = %s\n", path);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
178
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
179 ok = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
180 ret = stat(path, &statbuf);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
181 if (ret != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
182 ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
183 if (errno == ENOENT) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
184 logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
185 if (mkdir(path, 0700) == 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
186 ok = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
187 } else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
188 logwrite(LOG_ALERT, "stat of %s failed: %s\n", path, strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
189 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
190 if (ok) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
191 ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
192 ret = stat(path, &statbuf);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
193 if (S_ISDIR(statbuf.st_mode)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
194 gchar *subdirs[] = { "tmp", "new", "cur" };
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
195 int i;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
196 for (i = 0; i < 3; i++) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
197 char *path1 = g_strdup_printf("%s/%s", path, subdirs[i]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
198 ret = stat(path1, &statbuf);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
199 if (ret != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
200 if (errno == ENOENT) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
201 logwrite(LOG_NOTICE, "directory %s does not exist, creating\n", path1);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
202 if (mkdir(path1, 0700) != 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
203 break;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
204 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
205 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
206 g_free(path1);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
207 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
208 if (i == 3) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
209 FILE *out;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
210 mode_t saved_mode = umask(066);
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
211 /* the qmail style unique works only if delivering with different process.
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
212 We do not fork for each delivery, so our uid is more unique.
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
213 Hope it is compatible with all MUAs.
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
214 */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
215 gchar *filename = g_strdup_printf("%s/tmp/%s.%s", path, msg->uid, conf.host_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
216
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
217 DEBUG(5) debugf("filename = %s\n", filename);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
218
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
219 if ((out = fopen(filename, "w"))) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
220 gchar *newname = g_strdup_printf("%s/new/%s.%s", path, msg->uid, conf.host_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
221 message_stream(out, msg, hdr_list, flags);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
222 ok = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
223 if (fflush(out) == EOF)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
224 ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
225 else if (fdatasync(fileno(out)) != 0) {
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
226 if (errno != EINVAL)
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
227 /* some fs do not support this.. I hope this also means that it is not necessary */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
228 ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
229 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
230 fclose(out);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
231 if (rename(filename, newname) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
232 ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
233 logwrite(LOG_ALERT, "moving %s to %s failed: %s", filename, newname, strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
234 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
235 g_free(newname);
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 umask(saved_mode);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
238 g_free(filename);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
239 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
240 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
241 logwrite(LOG_ALERT, "%s is not a directory\n", path);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
242 errno = ENOTDIR;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
243 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
244 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
245 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
246 uid_ok = (seteuid(0) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
247 if (uid_ok) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
248 gid_ok = (setegid(saved_gid) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
249 uid_ok = (seteuid(saved_uid) == 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
250 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
251 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
252 if (!uid_ok || !gid_ok) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
253 /* FIXME: if this fails we HAVE to exit, because we shall not run
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
254 with some users id. But we do not return, and so this message
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
255 will not be finished, so the user will get the message again
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
256 next time a delivery is attempted... */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
257 logwrite(LOG_ALERT, "could not set back uid or gid after local delivery: %s\n", strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
258 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
259 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
260 g_free(path);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
261 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
262 logwrite(LOG_ALERT, "could not set uid or gid for local delivery, uid = %d: %s\n", pw->pw_uid, strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
263 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
264 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
265 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
266 errno = ENOENT; /* getpwnam does not set errno correctly */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
267 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
268 return ok;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
269 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
270 #endif
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
271
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
272 gboolean
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
273 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
274 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
275 gchar *envp[40];
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
276 FILE *out;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
277 uid_t saved_uid = geteuid();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
278 gid_t saved_gid = getegid();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
279 gboolean ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
280 gint i, n;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
281 pid_t pid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
282 void (*old_signal) (int);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
283 int status;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
284
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
285 /* 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
286 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
287 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
288 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
289
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
290 /* set environment */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
291 {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
292 gint i = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
293 address *ancestor = addr_find_ancestor(rcpt);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
294
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
295 envp[i++] = g_strdup_printf("SENDER=%s@%s", msg->return_path->local_part, msg->return_path->domain);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
296 envp[i++] = g_strdup_printf("SENDER_DOMAIN=%s", msg->return_path->domain);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
297 envp[i++] = g_strdup_printf("SENDER_LOCAL=%s", msg->return_path->local_part);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
298 envp[i++] = 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
299
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
300 envp[i++] = g_strdup_printf("RETURN_PATH=%s@%s", msg->return_path->local_part, msg->return_path->domain);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
301 envp[i++] = g_strdup_printf("DOMAIN=%s", ancestor->domain);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
302
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
303 envp[i++] = g_strdup_printf("LOCAL_PART=%s", ancestor->local_part);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
304 envp[i++] = g_strdup_printf("USER=%s", ancestor->local_part);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
305 envp[i++] = 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
306
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
307 envp[i++] = g_strdup_printf("MESSAGE_ID=%s", msg->uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
308 envp[i++] = 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
309
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
310 envp[i] = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
311 n = i;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
312 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
313
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
314 old_signal = signal(SIGCHLD, SIG_DFL);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
315
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
316 out = peidopen(cmd, "w", envp, &pid, conf.mail_uid, conf.mail_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
317 if (out != NULL) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
318 message_stream(out, msg, hdr_list, flags);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
319
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
320 fclose(out);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
321
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
322 waitpid(pid, &status, 0);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
323
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
324 if (WEXITSTATUS(status) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
325 int exstat = WEXITSTATUS(status);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
326 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
327 errno = 1024 + exstat;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
328 } else if (WIFSIGNALED(status)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
329 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
330 } else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
331 ok = TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
332
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
333 } else
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
334 logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", cmd, strerror(errno));
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
335
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
336 signal(SIGCHLD, old_signal);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
337
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
338 /* free environment */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
339 for (i = 0; i < n; i++) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
340 g_free(envp[i]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
341 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
342
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
343 /* set uid and gid back */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
344 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
345 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
346 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
347
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
348 return ok;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
349 }