From: Baptiste Daroussin Date: Wed, 12 Apr 2023 08:47:51 +0000 (+0200) Subject: listcontrol: stop forking when unsubscribing X-Git-Tag: RELEASE_1_4_0b1~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7baff23fd371ab24d5f244ca3c93bb00763ffc0d;p=thirdparty%2Fmlmmj.git listcontrol: stop forking when unsubscribing --- diff --git a/include/subscriberfuncs.h b/include/subscriberfuncs.h index 0c478715..577a21bf 100644 --- a/include/subscriberfuncs.h +++ b/include/subscriberfuncs.h @@ -35,3 +35,4 @@ void generate_subscription(struct ml *ml, const char *subaddr, enum subtype type void generate_subconfirm(struct ml *ml, const char *subaddr, enum subtype typesub, enum subreason reasonsub, bool sub); void send_confirmation_mail(struct ml *ml, const char *subaddr, enum subtype typesub, enum subreason reasonsub, bool sub); +bool do_unsubscribe(struct ml *ml, const char *addr, enum subtype typesub, enum subreason reasonsub, bool inform_not_subscribed, bool confirm_unsubscription, bool quiet, bool send_goodbye_mail); diff --git a/src/listcontrol.c b/src/listcontrol.c index f852ddd7..a284f06d 100644 --- a/src/listcontrol.c +++ b/src/listcontrol.c @@ -372,9 +372,9 @@ int listcontrol(strlist *fromemails, struct ml *ml, } log_oper(ml->fd, OPLOGFNAME, "mlmmj-unsub: %s requests" " unsubscribe", tll_front(*fromemails)); - exec_or_die(mlmmjunsub, "-L", ml->dir, "-a", - tll_front(*fromemails), "-r", - (nosubconfirm ? "-c" : "-C"), NULL); + do_unsubscribe(ml, tll_front(*fromemails), SUB_ALL, SUB_REQUEST, + false, !nosubconfirm, false, nosubconfirm); + exit(EXIT_SUCCESS); break; /* listname+unsubconf-digest-COOKIE@domain.tld */ diff --git a/src/mlmmj-unsub.c b/src/mlmmj-unsub.c index bfb353ca..20f8784e 100644 --- a/src/mlmmj-unsub.c +++ b/src/mlmmj-unsub.c @@ -70,13 +70,12 @@ static void print_help(const char *prg) int main(int argc, char **argv) { int opt; - bool normal = false, digest = false, nomail = false, subbed; - bool unsubconfirm = false, notifysub = false; + bool normal = false, digest = false, nomail = false; + bool unsubconfirm = false; bool changeuid = true, quiet = false; bool inform_not_subscribed = true; bool send_goodbye_mail = false; char *address = NULL; - const char *subdir; enum subtype typesub = SUB_ALL; enum subreason reasonsub = SUB_ADMIN; uid_t uid; @@ -135,7 +134,7 @@ int main(int argc, char **argv) exit(0); } } - if(ml.dir == 0 || address == 0) { + if(ml.dir == NULL || address == NULL) { errx(EXIT_FAILURE, "You have to specify -L and -a\n" "%s -h for help", argv[0]); } @@ -164,9 +163,6 @@ int main(int argc, char **argv) "%s -h for help", argv[0]); } - /* Make the address lowercase */ - address = lowercase(address); - if(changeuid) { uid = getuid(); if(!uid && fstat(ml.fd, &st) == 0 && uid != st.st_uid) { @@ -179,40 +175,8 @@ int main(int argc, char **argv) } } } - - if (typesub == SUB_ALL) { - subbed = is_subbed(ml.fd, address, false) != SUB_NONE; - } else { - int subdirfd = open_subscriber_directory(ml.fd, typesub, &subdir); - if (subdirfd == -1) { - log_error(LOG_ARGS, "Could not opendir(%s/%s)", ml.dir, subdir); - exit(EXIT_FAILURE); - } - subbed = is_subbed_in(subdirfd, subdir, address); - } - - if(!subbed) { - /* Address is not subscribed */ - if(inform_not_subscribed) - generate_subscription(&ml, address, typesub, false); - exit(EXIT_SUCCESS); - } - - if(unsubconfirm) - generate_subconfirm(&ml, address, typesub, reasonsub, false); - - unsubscribe(ml.fd, address, typesub); - - if(send_goodbye_mail) - send_confirmation_mail(&ml, address, typesub, reasonsub, false); - - notifysub = !quiet && statctrl(ml.ctrlfd, "notifysub"); - - /* Notify list owner about subscription */ - if (notifysub) - notify_sub(&ml, address, typesub, reasonsub, false); - - free(address); - - return EXIT_SUCCESS; + if (do_unsubscribe(&ml, address, typesub, reasonsub, inform_not_subscribed, + unsubconfirm, quiet, send_goodbye_mail)) + return(EXIT_SUCCESS); + return(EXIT_FAILURE); } diff --git a/src/subscriberfuncs.c b/src/subscriberfuncs.c index 50dd7b72..5708f35a 100644 --- a/src/subscriberfuncs.c +++ b/src/subscriberfuncs.c @@ -39,6 +39,7 @@ #include "send_mail.h" #include "strgen.h" #include "send_help.h" +#include "statctrl.h" char *subtype_strs[] = { "normal", @@ -351,3 +352,47 @@ send_confirmation_mail(struct ml *ml, const char *subaddr, enum subtype typesub, send_help_noexit(ml, queuefilename, subaddr); } + +bool +do_unsubscribe(struct ml *ml, const char *addr, enum subtype typesub, + enum subreason reasonsub, bool inform_not_subscribed, + bool confirm_unsubscription, bool quiet, bool send_goodbye_mail) +{ + char *address; + bool subscribed = false; + + address = lowercase(addr); + + if (typesub == SUB_ALL) { + subscribed = is_subbed(ml->fd, address, false) != SUB_NONE; + } else { + const char *subdir; + int fd = open_subscriber_directory(ml->fd, typesub, &subdir); + if (fd == -1) { + log_error(LOG_ARGS, "Could not opendir(%s/%s)", ml->dir, + subdir); + return (false); + } + subscribed = is_subbed_in(fd, subdir, address); + close(fd); + } + + if (!subscribed) { + if (inform_not_subscribed) + generate_subscription(ml, address, typesub, false); + return (true); + } + if (confirm_unsubscription) + generate_subconfirm(ml, address, typesub, reasonsub, false); + + unsubscribe(ml->fd, address, typesub); + if (send_goodbye_mail) + send_confirmation_mail(ml, address, typesub, reasonsub, false); + + /* Notify list owner about subscription */ + if (!quiet && statctrl(ml->ctrlfd, "notifysub")) + notify_sub(ml, address, typesub, reasonsub, false); + + free(address); + return (true); +}