Mercurial > hg > mlmmj
annotate src/mlmmj-unsub.c @ 741:b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
and document \uNNNN substitution
Also, the interface to prepstdreply() has changed; there is no longer a
customheaders argument, which was never used anyway, and is now essentially
redundant due to this patch.
author | Ben Schmidt |
---|---|
date | Mon, 20 Sep 2010 01:44:58 +1000 |
parents | e5286b45f9ca |
children | c3ee2bfaeb02 |
rev | line source |
---|---|
34 | 1 /* Copyright (C) 2002, 2003 Mads Martin Joergensen <mmj at mmj.dk> |
2 * | |
3 * $Id$ | |
4 * | |
225 | 5 * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 * of this software and associated documentation files (the "Software"), to | |
7 * deal in the Software without restriction, including without limitation the | |
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
9 * sell copies of the Software, and to permit persons to whom the Software is | |
10 * furnished to do so, subject to the following conditions: | |
11 * | |
12 * The above copyright notice and this permission notice shall be included in | |
13 * all copies or substantial portions of the Software. | |
14 * | |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 * IN THE SOFTWARE. | |
34 | 22 */ |
23 | |
24 #include <stdlib.h> | |
25 #include <stdio.h> | |
26 #include <string.h> | |
27 #include <sys/types.h> | |
28 #include <sys/stat.h> | |
44 | 29 #include <sys/mman.h> |
34 | 30 #include <unistd.h> |
31 #include <fcntl.h> | |
37 | 32 #include <libgen.h> |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
33 #include <dirent.h> |
291 | 34 #include <sys/wait.h> |
532 | 35 #include <ctype.h> |
34 | 36 |
37 #include "mlmmj.h" | |
37 | 38 #include "mlmmj-unsub.h" |
34 | 39 #include "mylocking.h" |
40 #include "wrappers.h" | |
41 #include "mygetline.h" | |
42 #include "getlistaddr.h" | |
520 | 43 #include "getlistdelim.h" |
34 | 44 #include "subscriberfuncs.h" |
45 #include "strgen.h" | |
46 #include "log_error.h" | |
245 | 47 #include "memory.h" |
291 | 48 #include "statctrl.h" |
49 #include "prepstdreply.h" | |
34 | 50 |
37 | 51 void confirm_unsub(const char *listdir, const char *listaddr, |
520 | 52 const char *listdelim, const char *subaddr, |
53 const char *mlmmjsend, enum subtype typesub) | |
34 | 54 { |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
55 char *queuefilename, *fromaddr, *listname, *listfqdn, *listtext; |
34 | 56 |
57 listname = genlistname(listaddr); | |
58 listfqdn = genlistfqdn(listaddr); | |
277 | 59 |
520 | 60 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn); |
34 | 61 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
62 myfree(listname); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
63 myfree(listfqdn); |
34 | 64 |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
65 switch(typesub) { |
366 | 66 default: |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
67 case SUB_NORMAL: |
364 | 68 listtext = mystrdup("unsub-ok"); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
69 break; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
70 case SUB_DIGEST: |
364 | 71 listtext = mystrdup("unsub-ok-digest"); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
72 break; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
73 case SUB_NOMAIL: |
364 | 74 listtext = mystrdup("unsub-ok-nomail"); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
75 break; |
338 | 76 } |
34 | 77 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
78 queuefilename = prepstdreply(listdir, listtext, "$helpaddr$", |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
728
diff
changeset
|
79 subaddr, NULL, 0, NULL, NULL); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
80 MY_ASSERT(queuefilename); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
81 myfree(listtext); |
34 | 82 |
37 | 83 execlp(mlmmjsend, mlmmjsend, |
71 | 84 "-l", "1", |
529
d65b467b647d
Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents:
520
diff
changeset
|
85 "-L", listdir, |
34 | 86 "-T", subaddr, |
87 "-F", fromaddr, | |
435 | 88 "-m", queuefilename, (char *)NULL); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
89 |
39 | 90 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend); |
34 | 91 exit(EXIT_FAILURE); |
92 } | |
93 | |
291 | 94 void notify_unsub(const char *listdir, const char *listaddr, |
520 | 95 const char *listdelim, const char *subaddr, |
96 const char *mlmmjsend, enum subtype typesub) | |
291 | 97 { |
363
000cf869301c
Further fixups to new prepstdreply. Seems to work now, needs more testing though
mmj
parents:
359
diff
changeset
|
98 char *maildata[4] = { "oldsub", NULL }; |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
99 char *listfqdn, *listname, *fromaddr, *tostr; |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
100 char *queuefilename = NULL, *listtext; |
291 | 101 |
102 listname = genlistname(listaddr); | |
103 listfqdn = genlistfqdn(listaddr); | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
104 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
105 maildata[1] = mystrdup(subaddr); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
106 |
520 | 107 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn); |
108 tostr = concatstr(4, listname, listdelim, "owner@", listfqdn); | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
109 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
110 myfree(listname); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
111 myfree(listfqdn); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
112 |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
113 switch(typesub) { |
366 | 114 default: |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
115 case SUB_NORMAL: |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
116 listtext = mystrdup("notifyunsub"); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
117 break; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
118 case SUB_DIGEST: |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
119 listtext = mystrdup("notifyunsub-digest"); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
120 break; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
121 case SUB_NOMAIL: |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
122 listtext = mystrdup("notifyunsub-nomail"); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
123 break; |
338 | 124 } |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
125 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
126 queuefilename = prepstdreply(listdir, listtext, "$listowner$", |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
728
diff
changeset
|
127 "$listowner$", NULL, 1, maildata, NULL); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
128 MY_ASSERT(queuefilename); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
129 myfree(listtext); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
130 myfree(maildata[1]); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
131 |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
132 execlp(mlmmjsend, mlmmjsend, |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
133 "-l", "1", |
529
d65b467b647d
Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents:
520
diff
changeset
|
134 "-L", listdir, |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
135 "-T", tostr, |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
136 "-F", fromaddr, |
435 | 137 "-m", queuefilename, (char *)NULL); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
138 |
291 | 139 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend); |
140 exit(EXIT_FAILURE); | |
141 } | |
142 | |
143 | |
34 | 144 void generate_unsubconfirm(const char *listdir, const char *listaddr, |
520 | 145 const char *listdelim, const char *subaddr, |
146 const char *mlmmjsend, enum subtype typesub) | |
34 | 147 { |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
148 char *confirmaddr, *listname, *listfqdn, *tmpstr; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
149 char *queuefilename, *fromaddr; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
150 char *randomstr = NULL, *confirmfilename = NULL, *listtext; |
363
000cf869301c
Further fixups to new prepstdreply. Seems to work now, needs more testing though
mmj
parents:
359
diff
changeset
|
151 char *maildata[4] = { "subaddr", NULL, "confaddr", NULL }; |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
152 int subconffd; |
34 | 153 |
154 listname = genlistname(listaddr); | |
155 listfqdn = genlistfqdn(listaddr); | |
277 | 156 |
157 do { | |
158 myfree(confirmfilename); | |
159 myfree(randomstr); | |
160 randomstr = random_plus_addr(subaddr); | |
161 confirmfilename = concatstr(3, listdir, "/unsubconf/", | |
162 randomstr); | |
34 | 163 |
277 | 164 subconffd = open(confirmfilename, O_RDWR|O_CREAT|O_EXCL, |
165 S_IRUSR|S_IWUSR); | |
166 | |
167 } while ((subconffd < 0) && (errno == EEXIST)); | |
168 | |
169 if(subconffd < 0) { | |
39 | 170 log_error(LOG_ARGS, "Could not open '%s'", confirmfilename); |
277 | 171 myfree(randomstr); |
245 | 172 myfree(confirmfilename); |
34 | 173 exit(EXIT_FAILURE); |
174 } | |
179 | 175 |
245 | 176 myfree(confirmfilename); |
179 | 177 |
178 if(writen(subconffd, subaddr, strlen(subaddr)) < 0) { | |
179 log_error(LOG_ARGS, "Could not write unsubconffile"); | |
277 | 180 myfree(randomstr); |
181 myfree(confirmfilename); | |
179 | 182 exit(EXIT_FAILURE); |
183 } | |
184 | |
185 close(subconffd); | |
34 | 186 |
520 | 187 fromaddr = concatstr(6, listname, listdelim, "bounces-confunsub-", |
188 randomstr, "@", listfqdn); | |
277 | 189 |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
190 switch(typesub) { |
366 | 191 default: |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
192 case SUB_NORMAL: |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
193 listtext = mystrdup("unsub-confirm"); |
520 | 194 tmpstr = mystrdup("confunsub-"); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
195 break; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
196 case SUB_DIGEST: |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
197 listtext = mystrdup("unsub-confirm-digest"); |
520 | 198 tmpstr = mystrdup("confunsub-digest-"); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
199 break; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
200 case SUB_NOMAIL: |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
201 listtext = mystrdup("unsub-confirm-nomail"); |
520 | 202 tmpstr = mystrdup("confunsub-nomail-"); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
203 break; |
338 | 204 } |
205 | |
520 | 206 confirmaddr = concatstr(6, listname, listdelim, tmpstr, randomstr, "@", |
207 listfqdn); | |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
208 |
338 | 209 myfree(randomstr); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
210 myfree(tmpstr); |
34 | 211 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
212 maildata[1] = mystrdup(subaddr); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
213 maildata[3] = mystrdup(confirmaddr); |
34 | 214 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
215 queuefilename = prepstdreply(listdir, listtext, "$helpaddr$", subaddr, |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
728
diff
changeset
|
216 confirmaddr, 2, maildata, NULL); |
34 | 217 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
218 myfree(maildata[1]); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
219 myfree(maildata[3]); |
44 | 220 |
245 | 221 myfree(listname); |
222 myfree(listfqdn); | |
34 | 223 |
37 | 224 execlp(mlmmjsend, mlmmjsend, |
69 | 225 "-l", "1", |
529
d65b467b647d
Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents:
520
diff
changeset
|
226 "-L", listdir, |
34 | 227 "-T", subaddr, |
228 "-F", fromaddr, | |
435 | 229 "-m", queuefilename, (char *)NULL); |
39 | 230 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend); |
34 | 231 exit(EXIT_FAILURE); |
232 } | |
233 | |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
234 ssize_t unsubscribe(int subreadfd, int subwritefd, const char *address) |
34 | 235 { |
44 | 236 off_t suboff = find_subscriber(subreadfd, address); |
237 struct stat st; | |
238 char *inmap; | |
239 size_t len = strlen(address) + 1; /* + 1 for the '\n' */ | |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
240 ssize_t writeres = 0, written = 0; |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
241 |
44 | 242 if(suboff == -1) |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
243 return -1; /* Did not find subscriber */ |
34 | 244 |
44 | 245 if(fstat(subreadfd, &st) < 0) { |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
246 log_error(LOG_ARGS, "Could not stat subreadfd"); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
247 return -1; |
34 | 248 } |
44 | 249 |
250 if((inmap = mmap(0, st.st_size, PROT_READ, MAP_SHARED, | |
176
186c65c5f81d
Use MAP_FAILED to indicate failed mmap rather than (void \*)-1
mmj
parents:
117
diff
changeset
|
251 subreadfd, 0)) == MAP_FAILED) { |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
252 log_error(LOG_ARGS, "Could not mmap subreadfd"); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
253 return -1; |
44 | 254 } |
255 | |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
256 if(suboff > 0) { |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
257 writeres = writen(subwritefd, inmap, suboff); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
258 if(writeres < 0) |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
259 return -1; |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
260 } |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
261 written += writeres; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
262 |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
263 writeres = writen(subwritefd, inmap + len + suboff, |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
264 st.st_size - len - suboff); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
265 if(writeres < 0) |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
266 return -1; |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
267 |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
268 written += writeres; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
269 |
44 | 270 munmap(inmap, st.st_size); |
271 | |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
272 return written; |
34 | 273 } |
274 | |
275 static void print_help(const char *prg) | |
276 { | |
728
e5286b45f9ca
Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents:
660
diff
changeset
|
277 printf("Usage: %s -L /path/to/list -a john@doe.org\n" |
e5286b45f9ca
Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents:
660
diff
changeset
|
278 " [-c] [-C] [-h] [-L] [-d | -n] [-s] [-V]\n" |
102 | 279 " -a: Email address to unsubscribe \n" |
280 " -c: Send goodbye mail\n" | |
281 " -C: Request mail confirmation\n" | |
554 | 282 " -d: Unsubscribe from digest of list\n" |
102 | 283 " -h: This help\n" |
284 " -L: Full path to list directory\n" | |
554 | 285 " -n: Unsubscribe from no mail version of list\n" |
509 | 286 " -s: Don't send a mail to the address if not subscribed\n" |
345
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
287 " -U: Don't switch to the user id of the listdir owner\n" |
102 | 288 " -V: Print version\n" |
289 "When no options are specified, unsubscription silently " | |
290 "happens\n", prg); | |
34 | 291 exit(EXIT_SUCCESS); |
292 } | |
293 | |
500 | 294 void generate_notsubscribed(const char *listdir, const char *subaddr, |
295 const char *mlmmjsend) | |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
296 { |
500 | 297 char *queuefilename, *fromaddr, *listname, *listfqdn, *listaddr; |
520 | 298 char *listdelim = getlistdelim(listdir); |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
299 |
500 | 300 listaddr = getlistaddr(listdir); |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
301 listname = genlistname(listaddr); |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
302 listfqdn = genlistfqdn(listaddr); |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
303 |
520 | 304 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn); |
305 myfree(listdelim); | |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
306 |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
307 queuefilename = prepstdreply(listdir, "unsub-notsubscribed", |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
728
diff
changeset
|
308 "$helpaddr$", subaddr, NULL, 0, NULL, NULL); |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
309 MY_ASSERT(queuefilename); |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
310 |
500 | 311 myfree(listaddr); |
312 myfree(listname); | |
313 myfree(listfqdn); | |
314 | |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
315 execlp(mlmmjsend, mlmmjsend, |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
316 "-l", "1", |
529
d65b467b647d
Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents:
520
diff
changeset
|
317 "-L", listdir, |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
318 "-T", subaddr, |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
319 "-F", fromaddr, |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
320 "-m", queuefilename, (char *)NULL); |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
321 |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
322 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend); |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
323 exit(EXIT_FAILURE); |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
324 } |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
325 |
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
326 |
34 | 327 int main(int argc, char **argv) |
328 { | |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
329 int subread, subwrite, rlock, wlock, opt, unsubres, status, nomail = 0; |
338 | 330 int confirmunsub = 0, unsubconfirm = 0, notifysub = 0, digest = 0; |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
331 int changeuid = 1, groupwritable = 0, sublock, sublockfd; |
532 | 332 int nogennotsubscribed = 0, i = 0; |
520 | 333 char *listaddr, *listdelim, *listdir = NULL, *address = NULL; |
334 char *subreadname = NULL, *subwritename, *mlmmjsend, *bindir, *subdir; | |
532 | 335 char *subddirname, *sublockname, *lowcaseaddr; |
44 | 336 off_t suboff; |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
337 DIR *subddir; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
338 struct dirent *dp; |
291 | 339 pid_t pid, childpid; |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
340 enum subtype typesub = SUB_NORMAL; |
346 | 341 uid_t uid; |
342 struct stat st; | |
208
688011dbc4b7
Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents:
179
diff
changeset
|
343 |
688011dbc4b7
Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents:
179
diff
changeset
|
344 CHECKFULLPATH(argv[0]); |
38 | 345 |
208
688011dbc4b7
Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents:
179
diff
changeset
|
346 log_set_name(argv[0]); |
688011dbc4b7
Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents:
179
diff
changeset
|
347 |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
102
diff
changeset
|
348 bindir = mydirname(argv[0]); |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
102
diff
changeset
|
349 mlmmjsend = concatstr(2, bindir, "/mlmmj-send"); |
245 | 350 myfree(bindir); |
34 | 351 |
509 | 352 while ((opt = getopt(argc, argv, "hcCdnVUL:a:s")) != -1) { |
34 | 353 switch(opt) { |
354 case 'L': | |
355 listdir = optarg; | |
356 break; | |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
357 case 'n': |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
358 nomail = 1; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
359 break; |
34 | 360 case 'a': |
361 address = optarg; | |
362 break; | |
363 case 'c': | |
364 confirmunsub = 1; | |
365 break; | |
366 case 'C': | |
367 unsubconfirm = 1; | |
368 break; | |
338 | 369 case 'd': |
370 digest = 1; | |
371 break; | |
34 | 372 case 'h': |
373 print_help(argv[0]); | |
374 break; | |
509 | 375 case 's': |
376 nogennotsubscribed = 1; | |
377 break; | |
345
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
378 case 'U': |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
379 changeuid = 0; |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
380 break; |
34 | 381 case 'V': |
382 print_version(argv[0]); | |
383 exit(0); | |
384 } | |
385 } | |
386 if(listdir == 0 || address == 0) { | |
387 fprintf(stderr, "You have to specify -L and -a\n"); | |
388 fprintf(stderr, "%s -h for help\n", argv[0]); | |
389 exit(EXIT_FAILURE); | |
390 } | |
391 | |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
392 if(digest && nomail) { |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
393 fprintf(stderr, "Specify either -d or -n, not both\n"); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
394 fprintf(stderr, "%s -h for help\n", argv[0]); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
395 exit(EXIT_FAILURE); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
396 } |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
397 |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
398 if(digest) |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
399 typesub = SUB_DIGEST; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
400 if(nomail) |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
401 typesub = SUB_NOMAIL; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
402 |
34 | 403 if(confirmunsub && unsubconfirm) { |
404 fprintf(stderr, "Cannot specify both -C and -c\n"); | |
405 fprintf(stderr, "%s -h for help\n", argv[0]); | |
406 exit(EXIT_FAILURE); | |
407 } | |
408 | |
532 | 409 /* Make the address lowercase */ |
410 lowcaseaddr = mystrdup(address); | |
411 i = 0; | |
412 while(lowcaseaddr[i]) { | |
413 lowcaseaddr[i] = tolower(lowcaseaddr[i]); | |
414 i++; | |
415 } | |
416 address = lowcaseaddr; | |
417 | |
34 | 418 /* get the list address */ |
69 | 419 listaddr = getlistaddr(listdir); |
34 | 420 |
345
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
421 if(changeuid) { |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
422 uid = getuid(); |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
423 if(!uid && stat(listdir, &st) == 0) { |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
424 printf("Changing to uid %d, owner of %s.\n", |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
425 (int)st.st_uid, listdir); |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
426 if(setuid(st.st_uid) < 0) { |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
427 perror("setuid"); |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
428 fprintf(stderr, "Continuing as uid %d\n", |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
429 (int)uid); |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
430 } |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
431 } |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
432 } |
8e5eaa8fc956
mlmmj-unsub should also setuid, and fix a bug in mlmmj-sub so -U is actually recognized as an option
mmj
parents:
343
diff
changeset
|
433 |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
434 switch(typesub) { |
366 | 435 default: |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
436 case SUB_NORMAL: |
464 | 437 subdir = "/subscribers.d/"; |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
438 break; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
439 case SUB_DIGEST: |
464 | 440 subdir = "/digesters.d/"; |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
441 break; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
442 case SUB_NOMAIL: |
464 | 443 subdir = "/nomailsubs.d/"; |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
444 break; |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
445 } |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
446 |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
447 subddirname = concatstr(2, listdir, subdir); |
355 | 448 if (stat(subddirname, &st) == 0) { |
449 if(st.st_mode & S_IWGRP) { | |
450 groupwritable = S_IRGRP|S_IWGRP; | |
451 umask(S_IWOTH); | |
452 } | |
453 } | |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
454 |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
455 if(is_subbed_in(subddirname, address)) { |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
456 /* Address is not subscribed */ |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
457 myfree(subddirname); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
458 myfree(listaddr); |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
459 |
509 | 460 if(!nogennotsubscribed) { |
461 generate_notsubscribed(listdir, address, mlmmjsend); | |
462 } | |
495
c5e975579329
patch for warning people already subbed they are and same with unsub
mmj
parents:
465
diff
changeset
|
463 |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
464 exit(EXIT_SUCCESS); |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
465 } |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
466 |
520 | 467 listdelim = getlistdelim(listdir); |
71 | 468 if(unsubconfirm) |
520 | 469 generate_unsubconfirm(listdir, listaddr, listdelim, address, |
470 mlmmjsend, typesub); | |
71 | 471 |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
472 if((subddir = opendir(subddirname)) == NULL) { |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
473 log_error(LOG_ARGS, "Could not opendir(%s)", |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
474 subddirname); |
245 | 475 myfree(subddirname); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
476 myfree(listaddr); |
520 | 477 myfree(listdelim); |
82 | 478 exit(EXIT_FAILURE); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
479 } |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
480 |
245 | 481 myfree(subddirname); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
482 |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
483 while((dp = readdir(subddir)) != NULL) { |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
484 if(!strcmp(dp->d_name, ".")) |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
485 continue; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
486 if(!strcmp(dp->d_name, "..")) |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
487 continue; |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
488 |
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
489 subreadname = concatstr(3, listdir, subdir, dp->d_name); |
34 | 490 |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
491 subread = open(subreadname, O_RDWR); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
492 if(subread == -1) { |
245 | 493 myfree(subreadname); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
494 continue; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
495 } |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
496 |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
497 suboff = find_subscriber(subread, address); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
498 if(suboff == -1) { |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
499 close(subread); |
245 | 500 myfree(subreadname); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
501 continue; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
502 } |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
503 |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
504 /* create a .name.lock file and aquire the lock */ |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
505 sublockname = concatstr(5, listdir, subdir, ".", dp->d_name, |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
506 ".lock"); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
507 sublockfd = open(sublockname, O_RDWR | O_CREAT, |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
508 S_IRUSR | S_IWUSR); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
509 if(sublockfd < 0) { |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
510 log_error(LOG_ARGS, "Error opening lock file %s", |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
511 sublockname); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
512 myfree(sublockname); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
513 continue; |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
514 } |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
515 |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
516 sublock = myexcllock(sublockfd); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
517 if(sublock < 0) { |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
518 log_error(LOG_ARGS, "Error locking '%s' file", |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
519 sublockname); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
520 myfree(sublockname); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
521 close(sublockfd); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
522 continue; |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
523 } |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
524 |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
525 rlock = myexcllock(subread); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
526 if(rlock < 0) { |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
527 log_error(LOG_ARGS, "Error locking '%s' file", |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
528 subreadname); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
529 close(subread); |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
530 close(sublockfd); |
245 | 531 myfree(subreadname); |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
532 myfree(sublockname); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
533 continue; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
534 } |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
535 |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
536 subwritename = concatstr(2, subreadname, ".new"); |
34 | 537 |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
538 subwrite = open(subwritename, O_RDWR | O_CREAT | O_TRUNC, |
355 | 539 S_IRUSR | S_IWUSR | groupwritable); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
540 if(subwrite == -1){ |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
541 log_error(LOG_ARGS, "Could not open '%s'", |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
542 subwritename); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
543 close(subread); |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
544 close(sublockfd); |
245 | 545 myfree(subreadname); |
546 myfree(subwritename); | |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
547 myfree(sublockname); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
548 continue; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
549 } |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
550 |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
551 wlock = myexcllock(subwrite); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
552 if(wlock < 0) { |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
553 log_error(LOG_ARGS, "Error locking '%s'", |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
554 subwritename); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
555 close(subread); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
556 close(subwrite); |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
557 close(sublockfd); |
245 | 558 myfree(subreadname); |
559 myfree(subwritename); | |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
560 myfree(sublockname); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
561 continue; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
562 } |
34 | 563 |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
564 unsubres = unsubscribe(subread, subwrite, address); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
565 if(unsubres < 0) { |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
566 close(subread); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
567 close(subwrite); |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
568 close(sublockfd); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
569 unlink(subwritename); |
245 | 570 myfree(subreadname); |
571 myfree(subwritename); | |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
572 myfree(sublockname); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
573 continue; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
574 } |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
575 |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
576 if(unsubres > 0) { |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
577 if(rename(subwritename, subreadname) < 0) { |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
578 log_error(LOG_ARGS, |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
579 "Could not rename '%s' to '%s'", |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
580 subwritename, subreadname); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
581 close(subread); |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
582 close(subwrite); |
245 | 583 myfree(subreadname); |
584 myfree(subwritename); | |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
585 continue; |
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
586 } |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
587 } else { /* unsubres == 0, no subscribers left */ |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
588 unlink(subwritename); |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
589 unlink(subreadname); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
590 } |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
591 |
44 | 592 close(subread); |
81
f435923b65e4
mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents:
71
diff
changeset
|
593 close(subwrite); |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
594 close(sublockfd); |
245 | 595 myfree(subreadname); |
596 myfree(subwritename); | |
456
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
597 unlink(sublockname); |
160dab909572
Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents:
435
diff
changeset
|
598 myfree(sublockname); |
69 | 599 |
291 | 600 if(confirmunsub) { |
601 childpid = fork(); | |
602 | |
603 if(childpid < 0) { | |
604 log_error(LOG_ARGS, "Could not fork"); | |
520 | 605 confirm_unsub(listdir, listaddr, listdelim, |
606 address, mlmmjsend, digest); | |
291 | 607 } |
608 | |
609 if(childpid > 0) { | |
610 do /* Parent waits for the child */ | |
611 pid = waitpid(childpid, &status, 0); | |
612 while(pid == -1 && errno == EINTR); | |
613 } | |
614 | |
615 /* child confirms subscription */ | |
616 if(childpid == 0) | |
520 | 617 confirm_unsub(listdir, listaddr, listdelim, |
618 address, mlmmjsend, digest); | |
291 | 619 } |
620 } | |
621 | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
355
diff
changeset
|
622 closedir(subddir); |
291 | 623 |
624 notifysub = statctrl(listdir, "notifysub"); | |
625 | |
626 /* Notify list owner about subscription */ | |
627 if (notifysub) | |
520 | 628 notify_unsub(listdir, listaddr, listdelim, address, mlmmjsend, |
629 typesub); | |
291 | 630 |
245 | 631 myfree(listaddr); |
520 | 632 myfree(listdelim); |
34 | 633 |
634 return EXIT_SUCCESS; | |
635 } |