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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
1 /* Copyright (C) 2002, 2003 Mads Martin Joergensen <mmj at mmj.dk>
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
2 *
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
3 * $Id$
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
4 *
225
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
6 * of this software and associated documentation files (the "Software"), to
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
7 * deal in the Software without restriction, including without limitation the
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
9 * sell copies of the Software, and to permit persons to whom the Software is
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
10 * furnished to do so, subject to the following conditions:
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
11 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
12 * The above copyright notice and this permission notice shall be included in
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
13 * all copies or substantial portions of the Software.
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
14 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
21 * IN THE SOFTWARE.
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
22 */
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
23
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
24 #include <stdlib.h>
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
25 #include <stdio.h>
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
26 #include <string.h>
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
27 #include <sys/types.h>
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
28 #include <sys/stat.h>
44
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
29 #include <sys/mman.h>
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
30 #include <unistd.h>
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
31 #include <fcntl.h>
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 34
diff changeset
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
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
34 #include <sys/wait.h>
532
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
35 #include <ctype.h>
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
36
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
37 #include "mlmmj.h"
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 34
diff changeset
38 #include "mlmmj-unsub.h"
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
39 #include "mylocking.h"
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
40 #include "wrappers.h"
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
41 #include "mygetline.h"
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
42 #include "getlistaddr.h"
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
43 #include "getlistdelim.h"
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
44 #include "subscriberfuncs.h"
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
45 #include "strgen.h"
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
46 #include "log_error.h"
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
47 #include "memory.h"
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
48 #include "statctrl.h"
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
49 #include "prepstdreply.h"
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
50
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 34
diff changeset
51 void confirm_unsub(const char *listdir, const char *listaddr,
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
52 const char *listdelim, const char *subaddr,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
53 const char *mlmmjsend, enum subtype typesub)
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
56
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
57 listname = genlistname(listaddr);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
58 listfqdn = genlistfqdn(listaddr);
277
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
59
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
60 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
7d6c9bb6168f Warning fixes and release prep
mmj
parents: 364
diff changeset
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
fe02eed54635 fix typo
mmj
parents: 363
diff changeset
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
fe02eed54635 fix typo
mmj
parents: 363
diff changeset
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
fe02eed54635 fix typo
mmj
parents: 363
diff changeset
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
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
76 }
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
82
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 34
diff changeset
83 execlp(mlmmjsend, mlmmjsend,
71
489a2ecafb36 Assorted fixes
mmj
parents: 69
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
86 "-T", subaddr,
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
87 "-F", fromaddr,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 412
diff changeset
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
3509e8837988 changed log_error() to be a function (no C99 here)
mortenp
parents: 38
diff changeset
90 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
91 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
92 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
93
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
94 void notify_unsub(const char *listdir, const char *listaddr,
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
95 const char *listdelim, const char *subaddr,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
96 const char *mlmmjsend, enum subtype typesub)
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
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
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
101
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
102 listname = genlistname(listaddr);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
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
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
107 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
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
7d6c9bb6168f Warning fixes and release prep
mmj
parents: 364
diff changeset
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
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
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
65781b43a7b9 - subswitch, NULL);
mmj
parents: 412
diff changeset
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
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
139 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
140 exit(EXIT_FAILURE);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
141 }
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
142
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
143
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
144 void generate_unsubconfirm(const char *listdir, const char *listaddr,
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
145 const char *listdelim, const char *subaddr,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
146 const char *mlmmjsend, enum subtype typesub)
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
153
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
154 listname = genlistname(listaddr);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
155 listfqdn = genlistfqdn(listaddr);
277
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
156
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
157 do {
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
158 myfree(confirmfilename);
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
159 myfree(randomstr);
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
160 randomstr = random_plus_addr(subaddr);
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
161 confirmfilename = concatstr(3, listdir, "/unsubconf/",
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
162 randomstr);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
163
277
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
164 subconffd = open(confirmfilename, O_RDWR|O_CREAT|O_EXCL,
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
165 S_IRUSR|S_IWUSR);
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
166
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
167 } while ((subconffd < 0) && (errno == EEXIST));
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
168
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
169 if(subconffd < 0) {
39
3509e8837988 changed log_error() to be a function (no C99 here)
mortenp
parents: 38
diff changeset
170 log_error(LOG_ARGS, "Could not open '%s'", confirmfilename);
277
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
171 myfree(randomstr);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
172 myfree(confirmfilename);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
173 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
174 }
179
6c179df5f4cd Last place to get rid of FILE* are now done.
mmj
parents: 176
diff changeset
175
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
176 myfree(confirmfilename);
179
6c179df5f4cd Last place to get rid of FILE* are now done.
mmj
parents: 176
diff changeset
177
6c179df5f4cd Last place to get rid of FILE* are now done.
mmj
parents: 176
diff changeset
178 if(writen(subconffd, subaddr, strlen(subaddr)) < 0) {
6c179df5f4cd Last place to get rid of FILE* are now done.
mmj
parents: 176
diff changeset
179 log_error(LOG_ARGS, "Could not write unsubconffile");
277
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
180 myfree(randomstr);
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
181 myfree(confirmfilename);
179
6c179df5f4cd Last place to get rid of FILE* are now done.
mmj
parents: 176
diff changeset
182 exit(EXIT_FAILURE);
6c179df5f4cd Last place to get rid of FILE* are now done.
mmj
parents: 176
diff changeset
183 }
6c179df5f4cd Last place to get rid of FILE* are now done.
mmj
parents: 176
diff changeset
184
6c179df5f4cd Last place to get rid of FILE* are now done.
mmj
parents: 176
diff changeset
185 close(subconffd);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
186
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
187 fromaddr = concatstr(6, listname, listdelim, "bounces-confunsub-",
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
188 randomstr, "@", listfqdn);
277
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 245
diff changeset
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
7d6c9bb6168f Warning fixes and release prep
mmj
parents: 364
diff changeset
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
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
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
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
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
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
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
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
204 }
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
205
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
206 confirmaddr = concatstr(6, listname, listdelim, tmpstr, randomstr, "@",
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
207 listfqdn);
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 338
diff changeset
208
338
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
220
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
221 myfree(listname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
222 myfree(listfqdn);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
223
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 34
diff changeset
224 execlp(mlmmjsend, mlmmjsend,
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 45
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
227 "-T", subaddr,
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
228 "-F", fromaddr,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 412
diff changeset
229 "-m", queuefilename, (char *)NULL);
39
3509e8837988 changed log_error() to be a function (no C99 here)
mortenp
parents: 38
diff changeset
230 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
231 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
232 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
235 {
44
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
236 off_t suboff = find_subscriber(subreadfd, address);
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
237 struct stat st;
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
238 char *inmap;
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
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
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
244
44
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
248 }
44
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
249
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
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
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
254 }
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
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
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
270 munmap(inmap, st.st_size);
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
273 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
274
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
275 static void print_help(const char *prg)
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 82
diff changeset
279 " -a: Email address to unsubscribe \n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 82
diff changeset
280 " -c: Send goodbye mail\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 82
diff changeset
281 " -C: Request mail confirmation\n"
554
6c4034f79857 Small textual correction
xi
parents: 553
diff changeset
282 " -d: Unsubscribe from digest of list\n"
102
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 82
diff changeset
283 " -h: This help\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 82
diff changeset
284 " -L: Full path to list directory\n"
554
6c4034f79857 Small textual correction
xi
parents: 553
diff changeset
285 " -n: Unsubscribe from no mail version of list\n"
509
c89f55896ba5 Make resend_queue more robust
mmj
parents: 502
diff changeset
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
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 82
diff changeset
288 " -V: Print version\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 82
diff changeset
289 "When no options are specified, unsubscription silently "
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 82
diff changeset
290 "happens\n", prg);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
291 exit(EXIT_SUCCESS);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
292 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
293
500
8eeb497b2715 Another bugfix
mmj
parents: 495
diff changeset
294 void generate_notsubscribed(const char *listdir, const char *subaddr,
8eeb497b2715 Another bugfix
mmj
parents: 495
diff changeset
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
8eeb497b2715 Another bugfix
mmj
parents: 495
diff changeset
297 char *queuefilename, *fromaddr, *listname, *listfqdn, *listaddr;
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
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
8eeb497b2715 Another bugfix
mmj
parents: 495
diff changeset
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
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
304 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
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
8eeb497b2715 Another bugfix
mmj
parents: 495
diff changeset
311 myfree(listaddr);
8eeb497b2715 Another bugfix
mmj
parents: 495
diff changeset
312 myfree(listname);
8eeb497b2715 Another bugfix
mmj
parents: 495
diff changeset
313 myfree(listfqdn);
8eeb497b2715 Another bugfix
mmj
parents: 495
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
327 int main(int argc, char **argv)
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
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
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
332 int nogennotsubscribed = 0, i = 0;
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
333 char *listaddr, *listdelim, *listdir = NULL, *address = NULL;
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
334 char *subreadname = NULL, *subwritename, *mlmmjsend, *bindir, *subdir;
532
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
335 char *subddirname, *sublockname, *lowcaseaddr;
44
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
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
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
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
86314c99da0a Declare variables to make compile again
mmj
parents: 345
diff changeset
341 uid_t uid;
86314c99da0a Declare variables to make compile again
mmj
parents: 345
diff changeset
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
7f4c75a4a346 dirname(argv[0]) -> dirname(argv0);
mmj
parents: 37
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
350 myfree(bindir);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
351
509
c89f55896ba5 Make resend_queue more robust
mmj
parents: 502
diff changeset
352 while ((opt = getopt(argc, argv, "hcCdnVUL:a:s")) != -1) {
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
353 switch(opt) {
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
354 case 'L':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
355 listdir = optarg;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
360 case 'a':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
361 address = optarg;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
362 break;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
363 case 'c':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
364 confirmunsub = 1;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
365 break;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
366 case 'C':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
367 unsubconfirm = 1;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
368 break;
338
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
369 case 'd':
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
370 digest = 1;
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
371 break;
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
372 case 'h':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
373 print_help(argv[0]);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
374 break;
509
c89f55896ba5 Make resend_queue more robust
mmj
parents: 502
diff changeset
375 case 's':
c89f55896ba5 Make resend_queue more robust
mmj
parents: 502
diff changeset
376 nogennotsubscribed = 1;
c89f55896ba5 Make resend_queue more robust
mmj
parents: 502
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
381 case 'V':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
382 print_version(argv[0]);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
383 exit(0);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
384 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
385 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
386 if(listdir == 0 || address == 0) {
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
387 fprintf(stderr, "You have to specify -L and -a\n");
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
388 fprintf(stderr, "%s -h for help\n", argv[0]);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
389 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
390 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
403 if(confirmunsub && unsubconfirm) {
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
404 fprintf(stderr, "Cannot specify both -C and -c\n");
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
405 fprintf(stderr, "%s -h for help\n", argv[0]);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
406 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
407 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
408
532
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
409 /* Make the address lowercase */
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
410 lowcaseaddr = mystrdup(address);
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
411 i = 0;
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
412 while(lowcaseaddr[i]) {
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
413 lowcaseaddr[i] = tolower(lowcaseaddr[i]);
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
414 i++;
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
415 }
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
416 address = lowcaseaddr;
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
417
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
418 /* get the list address */
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 45
diff changeset
419 listaddr = getlistaddr(listdir);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
7d6c9bb6168f Warning fixes and release prep
mmj
parents: 364
diff changeset
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
5177ad983444 don't mystrdup unless needed
mmj
parents: 456
diff changeset
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
5177ad983444 don't mystrdup unless needed
mmj
parents: 456
diff changeset
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
5177ad983444 don't mystrdup unless needed
mmj
parents: 456
diff changeset
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
1398baaa7034 Stak patches fra PIL:
mmj
parents: 346
diff changeset
448 if (stat(subddirname, &st) == 0) {
1398baaa7034 Stak patches fra PIL:
mmj
parents: 346
diff changeset
449 if(st.st_mode & S_IWGRP) {
1398baaa7034 Stak patches fra PIL:
mmj
parents: 346
diff changeset
450 groupwritable = S_IRGRP|S_IWGRP;
1398baaa7034 Stak patches fra PIL:
mmj
parents: 346
diff changeset
451 umask(S_IWOTH);
1398baaa7034 Stak patches fra PIL:
mmj
parents: 346
diff changeset
452 }
1398baaa7034 Stak patches fra PIL:
mmj
parents: 346
diff changeset
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
c89f55896ba5 Make resend_queue more robust
mmj
parents: 502
diff changeset
460 if(!nogennotsubscribed) {
c89f55896ba5 Make resend_queue more robust
mmj
parents: 502
diff changeset
461 generate_notsubscribed(listdir, address, mlmmjsend);
c89f55896ba5 Make resend_queue more robust
mmj
parents: 502
diff changeset
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
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
467 listdelim = getlistdelim(listdir);
71
489a2ecafb36 Assorted fixes
mmj
parents: 69
diff changeset
468 if(unsubconfirm)
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
469 generate_unsubconfirm(listdir, listaddr, listdelim, address,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
470 mlmmjsend, typesub);
71
489a2ecafb36 Assorted fixes
mmj
parents: 69
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
477 myfree(listdelim);
82
822f9a7bb8f4 bail out if we can not open subscribers.d/
mortenp
parents: 81
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
1398baaa7034 Stak patches fra PIL:
mmj
parents: 346
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
545 myfree(subreadname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
558 myfree(subreadname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
570 myfree(subreadname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
583 myfree(subreadname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
595 myfree(subreadname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 45
diff changeset
599
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
600 if(confirmunsub) {
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
601 childpid = fork();
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
602
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
603 if(childpid < 0) {
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
604 log_error(LOG_ARGS, "Could not fork");
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
605 confirm_unsub(listdir, listaddr, listdelim,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
606 address, mlmmjsend, digest);
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
607 }
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
608
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
609 if(childpid > 0) {
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
610 do /* Parent waits for the child */
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
611 pid = waitpid(childpid, &status, 0);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
612 while(pid == -1 && errno == EINTR);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
613 }
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
614
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
615 /* child confirms subscription */
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
616 if(childpid == 0)
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
617 confirm_unsub(listdir, listaddr, listdelim,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
618 address, mlmmjsend, digest);
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
619 }
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
620 }
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
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
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
623
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
624 notifysub = statctrl(listdir, "notifysub");
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
625
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
626 /* Notify list owner about subscription */
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
627 if (notifysub)
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
628 notify_unsub(listdir, listaddr, listdelim, address, mlmmjsend,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
629 typesub);
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
630
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
631 myfree(listaddr);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 509
diff changeset
632 myfree(listdelim);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
633
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
634 return EXIT_SUCCESS;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
635 }