annotate src/mlmmj-sub.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 c7d0a386aef5
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: 218
diff changeset
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
6 * of this software and associated documentation files (the "Software"), to
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
7 * deal in the Software without restriction, including without limitation the
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
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: 218
diff changeset
10 * furnished to do so, subject to the following conditions:
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
11 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
12 * The above copyright notice and this permission notice shall be included in
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
13 * all copies or substantial portions of the Software.
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
14 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
diff changeset
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 218
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: 218
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 <errno.h>
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
28 #include <syslog.h>
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
29 #include <sys/types.h>
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 <sys/stat.h>
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
32 #include <fcntl.h>
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 34
diff changeset
33 #include <libgen.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"
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
38 #include "mlmmj-sub.h"
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 "getlistaddr.h"
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
42 #include "getlistdelim.h"
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
43 #include "strgen.h"
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 "log_error.h"
178
78d31a5a2d39 mlmmj-sub is now FILE* clean
mmj
parents: 117
diff changeset
46 #include "mygetline.h"
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
47 #include "statctrl.h"
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
48 #include "prepstdreply.h"
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
49 #include "memory.h"
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
50 #include "ctrlvalues.h"
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
51 #include "chomp.h"
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
52
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
53 void moderate_sub(const char *listdir, const char *listaddr,
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
54 const char *listdelim, const char *subaddr,
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
55 const char *mlmmjsend, enum subtype typesub)
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
56 {
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
57 int i, fd, status, nosubmodmails = 0;
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
58 char *a = NULL, *queuefilename, *from, *listname, *listfqdn, *str;
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
59 char *modfilename, *randomstr, *mods, *to, *replyto, *moderators = NULL;
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
60 char *modfilebase;
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
61 struct strlist *submods;
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
62 pid_t childpid, pid;
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
63 char *maildata[6] = { "subaddr", NULL, "moderateaddr", NULL,
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
64 "moderators", NULL };
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
65
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
66 /* generate the file in moderation/ */
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
67 switch(typesub) {
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
68 default:
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
69 case SUB_NORMAL:
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
70 str = concatstr(4, subaddr, "\n", "SUB_NORMAL", "\n");
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
71 break;
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
72 case SUB_DIGEST:
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
73 str = concatstr(4, subaddr, "\n", "SUB_DIGEST", "\n");
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
74 break;
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
75 case SUB_NOMAIL:
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
76 str = concatstr(4, subaddr, "\n", "SUB_NOMAIL", "\n");
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
77 break;
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
78 }
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
79
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
80 randomstr = random_str();
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
81 modfilename = concatstr(3, listdir, "/moderation/subscribe",
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
82 randomstr);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
83 myfree(randomstr);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
84
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
85 fd = open(modfilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
86 while(fd < 0 && errno == EEXIST) {
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
87 myfree(modfilename);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
88 randomstr = random_str();
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
89 modfilename = concatstr(3, listdir, "/moderation/subscribe",
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
90 randomstr);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
91 myfree(randomstr);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
92 fd = open(modfilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
93 }
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
94 if(fd < 0) {
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
95 log_error(LOG_ARGS, "could not create %s"
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
96 "ignoring request: %s", str);
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
97 exit(EXIT_FAILURE);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
98 }
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
99 if(writen(fd, str, strlen(str)) < 0) {
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
100 log_error(LOG_ARGS, "could not write to %s"
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
101 "ignoring request: %s", str);
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
102 exit(EXIT_FAILURE);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
103 }
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
104
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
105 close(fd);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
106
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
107 myfree(str);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
108
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
109 submods = ctrlvalues(listdir, "submod");
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
110 mods = concatstr(2, listdir, "/control/submod");
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
111 /* check to see if there's adresses in the submod control file */
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
112 for(i = 0; i < submods->count; i++)
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
113 a = strchr(submods->strs[i], '@');
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
114
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
115 /* no addresses in submod control file, use owner */
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
116 if(a == NULL) {
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
117 /* free the submods struct from above */
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
118 for(i = 0; i < submods->count; i++)
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
119 myfree(submods->strs[i]);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
120 myfree(submods->strs);
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
121 myfree(submods);
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
122 submods = ctrlvalues(listdir, "owner");
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
123 myfree(mods);
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
124 mods = concatstr(2, listdir, "/control/owner");
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
125 }
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
126
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
127 /* send mail to moderators about request pending */
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
128 listdelim = getlistdelim(listdir);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
129 listfqdn = genlistfqdn(listaddr);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
130 listname = genlistname(listaddr);
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
131 modfilebase = mybasename(modfilename);
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
132
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
133 from = concatstr(4, listname, listdelim, "owner@", listfqdn);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
134 to = concatstr(3, listname, "-moderators@", listfqdn);
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
135 replyto = concatstr(6, listname, listdelim, "moderate-", modfilebase,
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
136 "@", listfqdn);
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
137 myfree(modfilebase);
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
138 for(i = 0; i < submods->count; i++) {
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
139 printf("%s", submods->strs[i]);
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
140 str = moderators;
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
141 moderators = concatstr(3, moderators, submods->strs[i], "\n");
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
142 myfree(str);
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
143 }
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
144
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
145 maildata[1] = mystrdup(subaddr);
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
146 maildata[3] = replyto;
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
147 maildata[5] = moderators;
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
148
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
149 queuefilename = prepstdreply(listdir, "submod-moderator",
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 728
diff changeset
150 "$listowner$", to, replyto, 3, maildata, NULL);
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
151
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
152 myfree(maildata[1]);
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
153
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
154 /* we might need to exec more than one mlmmj-send */
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
155
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
156 nosubmodmails = statctrl(listdir,"nosubmodmails");
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
157
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
158 if (nosubmodmails)
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
159 childpid = -1;
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
160 else {
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
161 childpid = fork();
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
162 if(childpid < 0)
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
163 log_error(LOG_ARGS, "Could not fork; requester not notified");
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
164 }
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
165
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
166 if(childpid != 0) {
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
167 if(childpid > 0) {
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
168 do /* Parent waits for the child */
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
169 pid = waitpid(childpid, &status, 0);
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
170 while(pid == -1 && errno == EINTR);
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
171 }
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
172 execl(mlmmjsend, mlmmjsend,
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
173 "-a",
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
174 "-l", "4",
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
175 "-L", listdir,
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
176 "-s", mods,
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
177 "-F", from,
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
178 "-R", replyto,
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
179 "-m", queuefilename, (char *)NULL);
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
180 log_error(LOG_ARGS, "execl() of '%s' failed", mlmmjsend);
642
a5e0c3976086 Fixed missing exit()s in case of failed execl() calls (Ansgar Burchardt)
mortenp
parents: 562
diff changeset
181 exit(EXIT_FAILURE);
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
182 }
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
183
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
184 myfree(to);
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
185 myfree(replyto);
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
186 myfree(moderators);
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
187
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
188 /* send mail to requester that the list is submod'ed */
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
189
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
190 from = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
191 queuefilename = prepstdreply(listdir, "submod-requester", "$listowner$",
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 728
diff changeset
192 subaddr, NULL, 0, NULL, NULL);
539
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
193
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
194 myfree(listname);
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
195 myfree(listfqdn);
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
196 execl(mlmmjsend, mlmmjsend,
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
197 "-l", "1",
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
198 "-L", listdir,
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
199 "-T", subaddr,
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
200 "-F", from,
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
201 "-m", queuefilename, (char *)NULL);
fd132b4e283a CVS now compiles, 2nd iteration of submod
mmj
parents: 538
diff changeset
202 log_error(LOG_ARGS, "execl() of '%s' failed", mlmmjsend);
642
a5e0c3976086 Fixed missing exit()s in case of failed execl() calls (Ansgar Burchardt)
mortenp
parents: 562
diff changeset
203 exit(EXIT_FAILURE);
538
c3d11ce2455e First iteration of subscription moderation. CVS is hereby broken until further notice
mmj
parents: 532
diff changeset
204 }
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
205
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
206 void getaddrandtype(const char *listdir, const char *modstr,
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
207 char **addrptr, enum subtype *subtypeptr)
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
208 {
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
209 int fd;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
210 char *readaddr, *readtype, *modfilename;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
211
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
212 modfilename = concatstr(3, listdir, "/moderation/", modstr);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
213
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
214 fd = open(modfilename, O_RDONLY);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
215 if(fd < 0) {
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
216 log_error(LOG_ARGS, "Could not open %s", modfilename);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
217 exit(EXIT_FAILURE);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
218 }
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
219
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
220 readaddr = mygetline(fd);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
221 readtype = mygetline(fd);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
222
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
223 close(fd);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
224
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
225 if(readaddr == NULL || readtype == NULL) {
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
226 log_error(LOG_ARGS, "Could not parse %s", modfilename);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
227 exit(EXIT_FAILURE);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
228 }
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
229
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
230 chomp(readaddr);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
231 *addrptr = readaddr;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
232
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
233 if(strncmp(readtype, "SUB_NORMAL", 10) == 0) {
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
234 *subtypeptr = SUB_NORMAL;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
235 goto freedone;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
236 }
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
237
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
238 if(strncmp(readtype, "SUB_DIGEST", 10) == 0) {
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
239 *subtypeptr = SUB_DIGEST;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
240 goto freedone;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
241 }
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
242
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
243 if(strncmp(readtype, "SUB_NOMAIL", 10) == 0) {
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
244 *subtypeptr = SUB_NOMAIL;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
245 goto freedone;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
246 }
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
247
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
248 log_error(LOG_ARGS, "Type %s not valid in %s", readtype,
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
249 modfilename);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
250
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
251 freedone:
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
252 myfree(readtype);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
253 unlink(modfilename);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
254 myfree(modfilename);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
255 }
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
256
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 34
diff changeset
257 void confirm_sub(const char *listdir, const char *listaddr,
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
258 const char *listdelim, const char *subaddr,
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
259 const char *mlmmjsend, enum subtype typesub)
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
260 {
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
261 char *queuefilename, *fromaddr, *listname, *listfqdn, *listtext;
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
262
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
263 listname = genlistname(listaddr);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
264 listfqdn = genlistfqdn(listaddr);
276
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
265
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
266 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
267
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
268 myfree(listname);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
269 myfree(listfqdn);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
270
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
271 switch(typesub) {
366
7d6c9bb6168f Warning fixes and release prep
mmj
parents: 364
diff changeset
272 default:
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
273 case SUB_NORMAL:
364
fe02eed54635 fix typo
mmj
parents: 363
diff changeset
274 listtext = mystrdup("sub-ok");
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
275 break;
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
276 case SUB_DIGEST:
364
fe02eed54635 fix typo
mmj
parents: 363
diff changeset
277 listtext = mystrdup("sub-ok-digest");
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
278 break;
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
279 case SUB_NOMAIL:
364
fe02eed54635 fix typo
mmj
parents: 363
diff changeset
280 listtext = mystrdup("sub-ok-nomail");
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
281 break;
338
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
282 }
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
283
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
284 queuefilename = prepstdreply(listdir, listtext, "$helpaddr$",
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 728
diff changeset
285 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
286 MY_ASSERT(queuefilename);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
287 myfree(listtext);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
288
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 34
diff changeset
289 execlp(mlmmjsend, mlmmjsend,
71
489a2ecafb36 Assorted fixes
mmj
parents: 69
diff changeset
290 "-l", "1",
529
d65b467b647d Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents: 520
diff changeset
291 "-L", listdir,
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
292 "-T", subaddr,
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
293 "-F", fromaddr,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 432
diff changeset
294 "-m", queuefilename, (char *)NULL);
39
3509e8837988 changed log_error() to be a function (no C99 here)
mortenp
parents: 38
diff changeset
295 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
296 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
297 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
298
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
299 void notify_sub(const char *listdir, const char *listaddr,
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
300 const char *listdelim, const char *subaddr,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
301 const char *mlmmjsend, enum subtype typesub)
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
302 {
363
000cf869301c Further fixups to new prepstdreply. Seems to work now, needs more testing though
mmj
parents: 359
diff changeset
303 char *maildata[2] = { "newsub", NULL };
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
304 char *listfqdn, *listname, *fromaddr, *tostr;
432
2a3886ef3c75 Lets init the strlist before starting to use it
mmj
parents: 412
diff changeset
305 char *queuefilename = NULL, *listtext = NULL;
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
306
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
307 listname = genlistname(listaddr);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
308 listfqdn = genlistfqdn(listaddr);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
309
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
310 maildata[1] = mystrdup(subaddr);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
311
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
312 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
313 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
314
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
315 myfree(listname);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
316 myfree(listfqdn);
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
317
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
318 switch(typesub) {
366
7d6c9bb6168f Warning fixes and release prep
mmj
parents: 364
diff changeset
319 default:
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
320 case SUB_NORMAL:
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
321 listtext = mystrdup("notifysub");
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
322 break;
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
323 case SUB_DIGEST:
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
324 listtext = mystrdup("notifysub-digest");
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
325 break;
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
326 case SUB_NOMAIL:
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
327 listtext = mystrdup("notifysub-nomail");
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
328 break;
338
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
329 }
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
330
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
331 queuefilename = prepstdreply(listdir, listtext, "$listowner$",
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 728
diff changeset
332 "$listowner$", NULL, 1, maildata, NULL);
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
333 MY_ASSERT(queuefilename)
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
334 myfree(listtext);
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
335 myfree(maildata[1]);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
336 execlp(mlmmjsend, mlmmjsend,
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
337 "-l", "1",
529
d65b467b647d Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents: 520
diff changeset
338 "-L", listdir,
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
339 "-T", tostr,
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
340 "-F", fromaddr,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 432
diff changeset
341 "-m", queuefilename, (char *)NULL);
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
342
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
343 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
344 exit(EXIT_FAILURE);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
345 }
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
346
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
347 void generate_subconfirm(const char *listdir, const char *listaddr,
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
348 const char *listdelim, const char *subaddr,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
349 const char *mlmmjsend, enum subtype typesub)
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
350 {
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
351 int subconffd;
276
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
352 char *confirmaddr, *listname, *listfqdn, *confirmfilename = NULL;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
353 char *listtext, *queuefilename = NULL, *fromaddr;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
354 char *randomstr = NULL, *tmpstr;
363
000cf869301c Further fixups to new prepstdreply. Seems to work now, needs more testing though
mmj
parents: 359
diff changeset
355 char *maildata[4] = { "subaddr", NULL, "confaddr", NULL };
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
356
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
357 listname = genlistname(listaddr);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
358 listfqdn = genlistfqdn(listaddr);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
359
276
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
360 do {
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
361 myfree(confirmfilename);
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
362 myfree(randomstr);
277
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 276
diff changeset
363 randomstr = random_plus_addr(subaddr);
276
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
364 confirmfilename = concatstr(3, listdir, "/subconf/",
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
365 randomstr);
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
366
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
367 subconffd = open(confirmfilename, O_RDWR|O_CREAT|O_EXCL,
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
368 S_IRUSR|S_IWUSR);
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
369
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
370 } while ((subconffd < 0) && (errno == EEXIST));
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
371
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
372 if(subconffd < 0) {
39
3509e8837988 changed log_error() to be a function (no C99 here)
mortenp
parents: 38
diff changeset
373 log_error(LOG_ARGS, "Could not open '%s'", confirmfilename);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
374 myfree(confirmfilename);
277
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 276
diff changeset
375 myfree(randomstr);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
376 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
377 }
178
78d31a5a2d39 mlmmj-sub is now FILE* clean
mmj
parents: 117
diff changeset
378
276
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
379 myfree(confirmfilename);
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
380
178
78d31a5a2d39 mlmmj-sub is now FILE* clean
mmj
parents: 117
diff changeset
381 if(writen(subconffd, subaddr, strlen(subaddr)) < 0) {
78d31a5a2d39 mlmmj-sub is now FILE* clean
mmj
parents: 117
diff changeset
382 log_error(LOG_ARGS, "Could not write to subconffd");
277
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 276
diff changeset
383 myfree(confirmfilename);
a18debdfdcc1 More bugfixes and EEXIST checking
mmj
parents: 276
diff changeset
384 myfree(randomstr);
178
78d31a5a2d39 mlmmj-sub is now FILE* clean
mmj
parents: 117
diff changeset
385 exit(EXIT_FAILURE);
78d31a5a2d39 mlmmj-sub is now FILE* clean
mmj
parents: 117
diff changeset
386 }
276
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
387
178
78d31a5a2d39 mlmmj-sub is now FILE* clean
mmj
parents: 117
diff changeset
388 close(subconffd);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
389
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
390 fromaddr = concatstr(6, listname, listdelim, "bounces-confsub-",
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
391 randomstr, "@", listfqdn);
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
392
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
393 switch(typesub) {
366
7d6c9bb6168f Warning fixes and release prep
mmj
parents: 364
diff changeset
394 default:
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
395 case SUB_NORMAL:
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
396 listtext = mystrdup("sub-confirm");
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
397 tmpstr = mystrdup("confsub-");
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
398 break;
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
399 case SUB_DIGEST:
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
400 listtext = mystrdup("sub-confirm-digest");
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
401 tmpstr = mystrdup("confsub-digest-");
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
402 break;
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
403 case SUB_NOMAIL:
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
404 listtext = mystrdup("sub-confirm-nomail");
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
405 tmpstr = mystrdup("confsub-nomail-");
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
406 break;
338
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
407 }
276
f670b8a4e457 Some more reassuring that open will retry if EEXIST
mmj
parents: 245
diff changeset
408
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
409 confirmaddr = concatstr(6, listname, listdelim, tmpstr, randomstr, "@",
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
410 listfqdn);
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
411
338
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
412 myfree(randomstr);
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
413 myfree(tmpstr);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
414
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
415 maildata[1] = mystrdup(subaddr);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
416 maildata[3] = mystrdup(confirmaddr);
338
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
417
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
418 queuefilename = prepstdreply(listdir, listtext, "$helpaddr$", subaddr,
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 728
diff changeset
419 confirmaddr, 2, maildata, NULL);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
420
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
421 myfree(maildata[1]);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 355
diff changeset
422 myfree(maildata[3]);
44
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
423
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
424 myfree(listname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
425 myfree(listfqdn);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
426
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 34
diff changeset
427 execlp(mlmmjsend, mlmmjsend,
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 44
diff changeset
428 "-l", "1",
529
d65b467b647d Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents: 520
diff changeset
429 "-L", listdir,
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
430 "-T", subaddr,
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
431 "-F", fromaddr,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 432
diff changeset
432 "-m", queuefilename, (char *)NULL);
39
3509e8837988 changed log_error() to be a function (no C99 here)
mortenp
parents: 38
diff changeset
433 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
434 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
435 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
436
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
437 static void print_help(const char *prg)
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
438 {
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
439 printf("Usage: %s -L /path/to/list [-a john@doe.org | -m str]\n"
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
440 " [-c] [-C] [-f] [-h] [-L] [-d | -n] [-s] [-U] [-V]\n"
102
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 81
diff changeset
441 " -a: Email address to subscribe \n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 81
diff changeset
442 " -c: Send welcome mail\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 81
diff changeset
443 " -C: Request mail confirmation\n"
338
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
444 " -d: Subscribe to digest of list\n"
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
445 " -f: Force subscription (do not moderate)\n"
102
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 81
diff changeset
446 " -h: This help\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 81
diff changeset
447 " -L: Full path to list directory\n"
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
448 " -m: moderation string\n"
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
449 " -n: Subscribe to no mail version of list\n", prg);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
450 printf(" -s: Don't send a mail to subscriber if already subscribed\n"
218
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
451 " -U: Don't switch to the user id of the listdir owner\n"
102
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 81
diff changeset
452 " -V: Print version\n"
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
453 "When no options are specified, subscription may be "
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
454 "moderated;\nto ensure a silent subscription, use -f\n");
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
455 exit(EXIT_SUCCESS);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
456 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
457
499
d4634f323460 fix stuff for 1.2.6.1
mmj
parents: 495
diff changeset
458 void generate_subscribed(const char *listdir, const char *subaddr,
d4634f323460 fix stuff for 1.2.6.1
mmj
parents: 495
diff changeset
459 const char *mlmmjsend)
495
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
460 {
499
d4634f323460 fix stuff for 1.2.6.1
mmj
parents: 495
diff changeset
461 char *queuefilename, *fromaddr, *listname, *listfqdn, *listaddr;
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
462 char *listdelim = getlistdelim(listdir);
495
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
463
499
d4634f323460 fix stuff for 1.2.6.1
mmj
parents: 495
diff changeset
464 listaddr = getlistaddr(listdir);
495
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
465 listname = genlistname(listaddr);
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
466 listfqdn = genlistfqdn(listaddr);
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
467
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
468 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
469 myfree(listdelim);
495
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
470
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
471 queuefilename = prepstdreply(listdir, "sub-subscribed", "$helpaddr$",
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 728
diff changeset
472 subaddr, NULL, 0, NULL, NULL);
495
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
473 MY_ASSERT(queuefilename);
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
474
499
d4634f323460 fix stuff for 1.2.6.1
mmj
parents: 495
diff changeset
475 myfree(listaddr);
d4634f323460 fix stuff for 1.2.6.1
mmj
parents: 495
diff changeset
476 myfree(listname);
d4634f323460 fix stuff for 1.2.6.1
mmj
parents: 495
diff changeset
477 myfree(listfqdn);
d4634f323460 fix stuff for 1.2.6.1
mmj
parents: 495
diff changeset
478
495
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
479 execlp(mlmmjsend, mlmmjsend,
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
480 "-l", "1",
529
d65b467b647d Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents: 520
diff changeset
481 "-L", listdir,
495
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
482 "-T", subaddr,
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
483 "-F", fromaddr,
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
484 "-m", queuefilename, (char *)NULL);
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
485 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
486
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
487 exit(EXIT_FAILURE);
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
488 }
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
489
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
490 int main(int argc, char **argv)
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
491 {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
492 char *listaddr, *listdelim, *listdir = NULL, *address = NULL;
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
493 char *subfilename = NULL, *mlmmjsend, *bindir, chstr[2], *subdir;
532
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
494 char *subddirname = NULL, *sublockname, *lowcaseaddr;
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
495 char *modstr = NULL;
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
496 int subconfirm = 0, confirmsub = 0, opt, subfilefd, lock, notifysub;
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
497 int changeuid = 1, status, digest = 0, nomail = 0, i = 0, submod = 0;
517
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
498 int groupwritable = 0, sublock, sublockfd, nogensubscribed = 0, subbed;
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
499 int force = 0;
44
74cf6cb8362f Change for new sub/unsub internal
mmj
parents: 39
diff changeset
500 size_t len;
218
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
501 struct stat st;
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
502 pid_t pid, childpid;
342
6b3e1584a0fd Only setuid in mlmmj-sub when we're root
mmj
parents: 338
diff changeset
503 uid_t uid;
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
504 enum subtype typesub = SUB_NORMAL;
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
505
208
688011dbc4b7 Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents: 181
diff changeset
506 CHECKFULLPATH(argv[0]);
688011dbc4b7 Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents: 181
diff changeset
507
688011dbc4b7 Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents: 181
diff changeset
508 log_set_name(argv[0]);
688011dbc4b7 Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents: 181
diff changeset
509
117
9a39dff171fa added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents: 102
diff changeset
510 bindir = mydirname(argv[0]);
9a39dff171fa added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents: 102
diff changeset
511 mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
512 myfree(bindir);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
513
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
514 while ((opt = getopt(argc, argv, "hcCdfm:nsVUL:a:")) != -1) {
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
515 switch(opt) {
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
516 case 'a':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
517 address = optarg;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
518 break;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
519 case 'c':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
520 confirmsub = 1;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
521 break;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
522 case 'C':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
523 subconfirm = 1;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
524 break;
338
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
525 case 'd':
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
526 digest = 1;
60da8d3ef63e added digest support
mortenp
parents: 312
diff changeset
527 break;
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
528 case 'f':
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
529 force = 1;
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
530 break;
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
531 case 'h':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
532 print_help(argv[0]);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
533 break;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
534 case 'L':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
535 listdir = optarg;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
536 break;
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
537 case 'm':
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
538 modstr = optarg;
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
539 break;
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
540 case 'n':
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
541 nomail = 1;
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
542 break;
509
c89f55896ba5 Make resend_queue more robust
mmj
parents: 507
diff changeset
543 case 's':
c89f55896ba5 Make resend_queue more robust
mmj
parents: 507
diff changeset
544 nogensubscribed = 1;
c89f55896ba5 Make resend_queue more robust
mmj
parents: 507
diff changeset
545 break;
218
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
546 case 'U':
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
547 changeuid = 0;
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
548 break;
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
549 case 'V':
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
550 print_version(argv[0]);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
551 exit(0);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
552 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
553 }
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
554
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
555 if(listdir == NULL) {
562
0e6215f03447 Bugfix for submod -- now it works
mmj
parents: 560
diff changeset
556 fprintf(stderr, "You have to specify -L\n");
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
557 fprintf(stderr, "%s -h for help\n", argv[0]);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
558 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
559 }
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
560
562
0e6215f03447 Bugfix for submod -- now it works
mmj
parents: 560
diff changeset
561 if(address == NULL && modstr == NULL) {
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
562 fprintf(stderr, "You have to specify -a or -m\n");
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
563 fprintf(stderr, "%s -h for help\n", argv[0]);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
564 exit(EXIT_FAILURE);
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
565 }
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
566
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
567 if(modstr)
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
568 getaddrandtype(listdir, modstr, &address, &typesub);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
569
456
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
570 if(strchr(address, '@') == NULL) {
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
571 log_error(LOG_ARGS, "No '@' sign in '%s', not subscribing",
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
572 address);
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
573 exit(EXIT_SUCCESS);
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
574 }
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
575
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
576 if(digest && nomail) {
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
577 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: 342
diff changeset
578 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: 342
diff changeset
579 exit(EXIT_FAILURE);
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
580 }
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
581
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
582 if(digest)
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
583 typesub = SUB_DIGEST;
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
584 if(nomail)
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
585 typesub = SUB_NOMAIL;
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
586
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
587 if(confirmsub && subconfirm) {
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
588 fprintf(stderr, "Cannot specify both -C and -c\n");
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
589 fprintf(stderr, "%s -h for help\n", argv[0]);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
590 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
591 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
592
532
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
593 /* Make the address lowercase */
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
594 lowcaseaddr = mystrdup(address);
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
595 i = 0;
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
596 while(lowcaseaddr[i]) {
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
597 lowcaseaddr[i] = tolower(lowcaseaddr[i]);
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
598 i++;
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
599 }
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
600 address = lowcaseaddr;
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
601
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
602 /* get the list address */
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 44
diff changeset
603 listaddr = getlistaddr(listdir);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
604 if(strncasecmp(listaddr, address, strlen(listaddr)) == 0) {
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
605 printf("Cannot subscribe the list address to the list\n");
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
606 exit(EXIT_SUCCESS); /* XXX is this success? */
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
607 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
608
517
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
609 switch(typesub) {
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
610 default:
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
611 case SUB_NORMAL:
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
612 subdir = "/subscribers.d/";
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
613 break;
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
614 case SUB_DIGEST:
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
615 subdir = "/digesters.d/";
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
616 break;
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
617 case SUB_NOMAIL:
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
618 subdir = "/nomailsubs.d/";
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
619 break;
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
620 }
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
621
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
622 subddirname = concatstr(2, listdir, subdir);
355
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
623 if (stat(subddirname, &st) == 0) {
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
624 if(st.st_mode & S_IWGRP) {
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
625 groupwritable = S_IRGRP|S_IWGRP;
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
626 umask(S_IWOTH);
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
627 setgid(st.st_gid);
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
628 }
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
629 }
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
630
218
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
631 if(changeuid) {
342
6b3e1584a0fd Only setuid in mlmmj-sub when we're root
mmj
parents: 338
diff changeset
632 uid = getuid();
6b3e1584a0fd Only setuid in mlmmj-sub when we're root
mmj
parents: 338
diff changeset
633 if(!uid && stat(listdir, &st) == 0) {
218
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
634 printf("Changing to uid %d, owner of %s.\n",
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
635 (int)st.st_uid, listdir);
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
636 if(setuid(st.st_uid) < 0) {
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
637 perror("setuid");
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
638 fprintf(stderr, "Continuing as uid %d\n",
342
6b3e1584a0fd Only setuid in mlmmj-sub when we're root
mmj
parents: 338
diff changeset
639 (int)uid);
218
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
640 }
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
641 }
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
642 }
729f4a49aa01 Make mlmmj-sub change uid to the listdir owner
mmj
parents: 216
diff changeset
643
81
f435923b65e4 mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents: 71
diff changeset
644 chstr[0] = address[0];
f435923b65e4 mlmmj-{,un}sub have been brought up to speed in a coordinated effort
mortenp
parents: 71
diff changeset
645 chstr[1] = '\0';
343
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
646
6d1f589dee87 This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents: 342
diff changeset
647 subfilename = concatstr(3, listdir, subdir, chstr);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
648
456
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
649 sublockname = concatstr(5, listdir, subdir, ".", chstr, ".lock");
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
650 sublockfd = open(sublockname, O_RDWR | O_CREAT, 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
651 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
652 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
653 sublockname);
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
654 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
655 exit(EXIT_FAILURE);
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
656 }
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
657
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
658 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
659 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
660 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
661 sublockname);
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
662 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
663 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
664 exit(EXIT_FAILURE);
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
665 }
160dab909572 Add .filename.lock file to lock against. Only allow addresses with a @ in them. 1.2.3
mmj
parents: 435
diff changeset
666
355
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
667 subfilefd = open(subfilename, O_RDWR|O_CREAT,
1398baaa7034 Stak patches fra PIL:
mmj
parents: 345
diff changeset
668 S_IRUSR|S_IWUSR|groupwritable);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
669 if(subfilefd == -1) {
39
3509e8837988 changed log_error() to be a function (no C99 here)
mortenp
parents: 38
diff changeset
670 log_error(LOG_ARGS, "Could not open '%s'", subfilename);
465
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
671 myfree(sublockname);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
672 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
673 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
674
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
675 lock = myexcllock(subfilefd);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
676 if(lock) {
39
3509e8837988 changed log_error() to be a function (no C99 here)
mortenp
parents: 38
diff changeset
677 log_error(LOG_ARGS, "Error locking subscriber file");
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
678 close(subfilefd);
465
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
679 close(sublockfd);
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
680 myfree(sublockname);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
681 exit(EXIT_FAILURE);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
682 }
517
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
683 subbed = is_subbed_in(subddirname, address);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
684 listdelim = getlistdelim(listdir);
560
3258e74426b3 Subscriber moderation finished. Will test it all later tonight, but
mmj
parents: 553
diff changeset
685 if(modstr == NULL)
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
686 submod = !force && statctrl(listdir, "submod");
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
687
517
ad761c84a780 Fix mlmmj-sub to not be able to subscribe twice
mmj
parents: 509
diff changeset
688 if(subbed) {
462
439a151b29d6 Clean up a bit
mmj
parents: 456
diff changeset
689 if(subconfirm) {
439a151b29d6 Clean up a bit
mmj
parents: 456
diff changeset
690 close(subfilefd);
465
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
691 close(sublockfd);
462
439a151b29d6 Clean up a bit
mmj
parents: 456
diff changeset
692 unlink(sublockname);
465
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
693 myfree(sublockname);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
694 generate_subconfirm(listdir, listaddr, listdelim,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
695 address, mlmmjsend, typesub);
462
439a151b29d6 Clean up a bit
mmj
parents: 456
diff changeset
696 } else {
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
697 if(submod) {
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
698 close(subfilefd);
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
699 close(sublockfd);
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
700 unlink(sublockname);
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
701 myfree(sublockname);
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
702 moderate_sub(listdir, listaddr, listdelim,
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
703 address, mlmmjsend, typesub);
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
704 }
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
705 lseek(subfilefd, 0L, SEEK_END);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
706 len = strlen(address);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
707 address[len] = '\n';
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
708 writen(subfilefd, address, len + 1);
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
709 address[len] = 0;
462
439a151b29d6 Clean up a bit
mmj
parents: 456
diff changeset
710 close(subfilefd);
465
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
711 close(sublockfd);
462
439a151b29d6 Clean up a bit
mmj
parents: 456
diff changeset
712 unlink(sublockname);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
713 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
714 } else {
412
66991b1776df Remove call to myunlock, since it's closed right after
mmj
parents: 366
diff changeset
715 close(subfilefd);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
716 myfree(subfilename);
465
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
717 close(sublockfd);
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
718 unlink(sublockname);
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
719 myfree(sublockname);
495
c5e975579329 patch for warning people already subbed they are and same with unsub
mmj
parents: 465
diff changeset
720
509
c89f55896ba5 Make resend_queue more robust
mmj
parents: 507
diff changeset
721 if(!nogensubscribed)
c89f55896ba5 Make resend_queue more robust
mmj
parents: 507
diff changeset
722 generate_subscribed(listdir, address, mlmmjsend);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
723
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
724 return EXIT_SUCCESS;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
725 }
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
726
465
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
727 close(sublockfd);
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
728 unlink(sublockname);
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
729 myfree(sublockname);
7d527f44b368 Make valgrind happy
mmj
parents: 464
diff changeset
730
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
731 if(confirmsub) {
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
732 childpid = fork();
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
733
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
734 if(childpid < 0) {
728
e5286b45f9ca Fixed documentation regarding silent subscription, and added
Ben Schmidt
parents: 660
diff changeset
735 log_error(LOG_ARGS, "Could not fork; owner not notified");
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
736 confirm_sub(listdir, listaddr, listdelim, address,
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
737 mlmmjsend, typesub);
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
738 }
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
739
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
740 if(childpid > 0) {
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
741 do /* Parent waits for the child */
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
742 pid = waitpid(childpid, &status, 0);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
743 while(pid == -1 && errno == EINTR);
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
744 }
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
745
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
746 /* child confirms subscription */
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
747 if(childpid == 0)
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
748 confirm_sub(listdir, listaddr, listdelim, address,
541
370b9af33cc6 Small submod fix
mmj
parents: 539
diff changeset
749 mlmmjsend, typesub);
291
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
750 }
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
751
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
752 notifysub = statctrl(listdir, "notifysub");
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
753
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
754 /* Notify list owner about subscription */
7da5c55b9330 0.8.3 commit
mmj
parents: 277
diff changeset
755 if (notifysub)
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
756 notify_sub(listdir, listaddr, listdelim, address, mlmmjsend,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
757 typesub);
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
758
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
759 myfree(listaddr);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 517
diff changeset
760 myfree(listdelim);
216
cec96ecd796c More memory debugging, and small bugfixes
mmj
parents: 208
diff changeset
761
34
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
762 return EXIT_SUCCESS;
1344f636cff3 Rename mlmmj-{un,}subscribe to mlmmj-{un,}sub
mmj
parents:
diff changeset
763 }