+1.4.0-b2
+ o moderation cookie for subscription is now under the sub directory
+ moderation/subscribe
1.4.0-b1
o manpage converted from man(7) to mdoc(7)
o Fix a potential crash with mail without separator between headers and body
void
mod_get_addr_and_type(struct ml *ml, const char *modstr, char **addrptr, enum subtype *subtypeptr)
{
- int fd;
- char *readtype, *modfilename;
+ int fd, dfd;
+ char *readtype, *modfilename = NULL;
char *buf, *walk;
size_t i;
if (strncmp(modstr, "subscribe", 9) == 0)
modstr += 9;
- xasprintf(&modfilename, "moderation/subscribe%s", modstr);
-
- fd = openat(ml->fd, modfilename, O_RDONLY);
+ dfd = openat(ml->fd, "moderation/subscribe", O_DIRECTORY);
+ if (dfd != -1) {
+ fd = openat(dfd, modstr, O_RDONLY);
+ }
+ if (dfd == -1 || fd == -1) {
+ xasprintf(&modfilename, "moderation/subscribe%s", modstr);
+ fd = openat(ml->fd, modfilename, O_RDONLY);
+ }
if(fd < 0) {
- log_error(LOG_ARGS, "Could not open %s/%s", ml->dir, modfilename);
+ log_error(LOG_ARGS, "Could not open "
+ "%s/moderation/subscribe/%s nor %s/%s", ml->dir, modstr,
+ ml->dir, modfilename);
exit(EXIT_FAILURE);
}
walk = buf = readlf(fd, false);
if (buf == NULL) {
- log_error(LOG_ARGS, "Could not open %s/%s", ml->dir, modfilename);
+ if (modfilename == NULL)
+ log_error(LOG_ARGS, "Invalid %s/moderation/subscribe/%s",
+ ml->dir, modstr);
+ else
+ log_error(LOG_ARGS, "Invalid %s/%s", ml->dir,
+ modfilename);
exit(EXIT_FAILURE);
}
*addrptr = xstrdup(strsep(&walk, "\n"));
}
free(buf);
- unlinkat(ml->fd, modfilename, 0);
+ if (modfilename != NULL)
+ unlinkat(ml->fd, modfilename, 0);
+ else
+ unlinkat(dfd, modstr, 0);
+ if (dfd != -1)
+ close(dfd);
free(modfilename);
}
exit(EXIT_SUCCESS);
}
atf_utils_wait(p, 1, "", "");
+
+ mkdir("moderation/subscribe", 0755);
+ atf_utils_create_file("moderation/subscribe/valid2", "user1\nSUB_BOTH\n");
+ atf_utils_create_file("moderation/subscribevalid2", "user2\nSUB_BOTH\n");
+ p = atf_utils_fork();
+ if (p == 0) {
+ struct ml ml;
+ enum subtype subtype = 0;
+ char *addr;
+ ml.fd = open(".", O_DIRECTORY);
+ mod_get_addr_and_type(&ml, "valid2", &addr, &subtype);
+ ATF_REQUIRE_STREQ(addr, "user1");
+ ATF_REQUIRE_EQ(subtype, SUB_BOTH);
+ exit(EXIT_SUCCESS);
+ }
+ atf_utils_wait(p, 0, "", "");
+
+ atf_utils_create_file("moderation/subscribevalid3", "user2\nSUB_BOTH\n");
+ p = atf_utils_fork();
+ if (p == 0) {
+ struct ml ml;
+ enum subtype subtype = 0;
+ char *addr;
+ ml.fd = open(".", O_DIRECTORY);
+ mod_get_addr_and_type(&ml, "valid3", &addr, &subtype);
+ ATF_REQUIRE_STREQ(addr, "user2");
+ ATF_REQUIRE_EQ(subtype, SUB_BOTH);
+ exit(EXIT_SUCCESS);
+ }
+ atf_utils_wait(p, 0, "", "");
+
+ p = atf_utils_fork();
+ if (p == 0) {
+ struct ml ml;
+ enum subtype subtype = 0;
+ char *addr;
+ ml.fd = open(".", O_DIRECTORY);
+ mod_get_addr_and_type(&ml, "valid4", &addr, &subtype);
+ exit(EXIT_SUCCESS);
+ }
+ atf_utils_wait(p, 1, "", "");
+
+ atf_utils_create_file("moderation/subscribe/invalid5", "");
+ p = atf_utils_fork();
+ if (p == 0) {
+ struct ml ml;
+ enum subtype subtype = 0;
+ char *addr;
+ ml.fd = open(".", O_DIRECTORY);
+ mod_get_addr_and_type(&ml, "invalid5", &addr, &subtype);
+ exit(EXIT_SUCCESS);
+ }
+ atf_utils_wait(p, 1, "", "");
}
ATF_TP_ADD_TCS(tp)