summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorAndrew Alderwick <andrew@alderwick.co.uk>2023-01-13 13:25:14 +0100
committerdefault <nobody@localhost>2023-01-13 13:25:14 +0100
commit3cb1725225567211c85226498bbc038cfe78d4fe (patch)
tree2a916a33a975e3c96a70c7cf005432bbd3222629 /activitypub.c
parenta99f742d739048f42c0a079f6c28a2ae2b4b9f2f (diff)
Added OpenBSD's unveil() and pledge() support.
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/activitypub.c b/activitypub.c
index a73b107..97fdc7b 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -13,6 +13,8 @@
#include "snac.h"
+#include <sys/wait.h>
+
const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public";
int activitypub_request(snac *snac, char *url, d_char **data)
@@ -999,6 +1001,35 @@ int process_message(snac *snac, char *msg, char *req)
}
+int send_email(char *msg)
+/* invoke sendmail with email headers and body in msg */
+{
+ FILE *f;
+ int status;
+ int fds[2];
+ pid_t pid;
+ if (pipe(fds) == -1) return -1;
+ pid = vfork();
+ if (pid == -1) return -1;
+ else if (pid == 0) {
+ dup2(fds[0], 0);
+ close(fds[0]);
+ close(fds[1]);
+ execl("/usr/sbin/sendmail", "sendmail", "-t", (char *) NULL);
+ _exit(1);
+ }
+ close(fds[0]);
+ if ((f = fdopen(fds[1], "w")) == NULL) {
+ close(fds[1]);
+ return -1;
+ }
+ fprintf(f, "%s\n", msg);
+ fclose(f);
+ if (waitpid(pid, &status, 0) == -1) return -1;
+ return status;
+}
+
+
void process_queue(snac *snac)
/* processes the queue */
{
@@ -1085,17 +1116,8 @@ void process_queue(snac *snac)
/* send this email */
char *msg = xs_dict_get(q_item, "message");
int retries = xs_number_get(xs_dict_get(q_item, "retries"));
- FILE *f;
- int ok = 0;
-
- if ((f = popen("/usr/sbin/sendmail -t", "w")) != NULL) {
- fprintf(f, "%s\n", msg);
-
- if (pclose(f) != -1)
- ok = 1;
- }
- if (ok)
+ if (!send_email(msg))
snac_debug(snac, 1, xs_fmt("email message sent"));
else {
if (retries > queue_retry_max)