summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activitypub.c42
-rw-r--r--data.c16
2 files changed, 42 insertions, 16 deletions
diff --git a/activitypub.c b/activitypub.c
index a73b107..97fdc7b 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -13,6 +13,8 @@
13 13
14#include "snac.h" 14#include "snac.h"
15 15
16#include <sys/wait.h>
17
16const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public"; 18const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public";
17 19
18int activitypub_request(snac *snac, char *url, d_char **data) 20int activitypub_request(snac *snac, char *url, d_char **data)
@@ -999,6 +1001,35 @@ int process_message(snac *snac, char *msg, char *req)
999} 1001}
1000 1002
1001 1003
1004int send_email(char *msg)
1005/* invoke sendmail with email headers and body in msg */
1006{
1007 FILE *f;
1008 int status;
1009 int fds[2];
1010 pid_t pid;
1011 if (pipe(fds) == -1) return -1;
1012 pid = vfork();
1013 if (pid == -1) return -1;
1014 else if (pid == 0) {
1015 dup2(fds[0], 0);
1016 close(fds[0]);
1017 close(fds[1]);
1018 execl("/usr/sbin/sendmail", "sendmail", "-t", (char *) NULL);
1019 _exit(1);
1020 }
1021 close(fds[0]);
1022 if ((f = fdopen(fds[1], "w")) == NULL) {
1023 close(fds[1]);
1024 return -1;
1025 }
1026 fprintf(f, "%s\n", msg);
1027 fclose(f);
1028 if (waitpid(pid, &status, 0) == -1) return -1;
1029 return status;
1030}
1031
1032
1002void process_queue(snac *snac) 1033void process_queue(snac *snac)
1003/* processes the queue */ 1034/* processes the queue */
1004{ 1035{
@@ -1085,17 +1116,8 @@ void process_queue(snac *snac)
1085 /* send this email */ 1116 /* send this email */
1086 char *msg = xs_dict_get(q_item, "message"); 1117 char *msg = xs_dict_get(q_item, "message");
1087 int retries = xs_number_get(xs_dict_get(q_item, "retries")); 1118 int retries = xs_number_get(xs_dict_get(q_item, "retries"));
1088 FILE *f;
1089 int ok = 0;
1090
1091 if ((f = popen("/usr/sbin/sendmail -t", "w")) != NULL) {
1092 fprintf(f, "%s\n", msg);
1093
1094 if (pclose(f) != -1)
1095 ok = 1;
1096 }
1097 1119
1098 if (ok) 1120 if (!send_email(msg))
1099 snac_debug(snac, 1, xs_fmt("email message sent")); 1121 snac_debug(snac, 1, xs_fmt("email message sent"));
1100 else { 1122 else {
1101 if (retries > queue_retry_max) 1123 if (retries > queue_retry_max)
diff --git a/data.c b/data.c
index 18efd92..5e6ce63 100644
--- a/data.c
+++ b/data.c
@@ -86,15 +86,19 @@ int srv_open(char *basedir, int auto_upgrade)
86 if (error != NULL) 86 if (error != NULL)
87 srv_log(error); 87 srv_log(error);
88 88
89/* disabled temporarily; messages can't be sent (libcurl issue?) */
90#if 0
91#ifdef __OpenBSD__ 89#ifdef __OpenBSD__
92 srv_debug(2, xs_fmt("Calling unveil()")); 90 srv_debug(2, xs_fmt("Calling unveil()"));
93 unveil(basedir, "rwc"); 91 unveil(basedir, "rwc");
94 unveil("/usr/sbin", "x"); 92 unveil("/usr/sbin/sendmail", "x");
95 unveil(NULL, NULL); 93 unveil("/etc/resolv.conf", "r");
94 unveil("/etc/hosts", "r");
95 unveil("/etc/ssl/openssl.cnf", "r");
96 unveil("/etc/ssl/cert.pem", "r");
97 unveil("/usr/share/zoneinfo", "r");
98 unveil(NULL, NULL);
99 srv_debug(2, xs_fmt("Calling pledge()"));
100 pledge("stdio rpath wpath cpath flock inet proc exec dns", NULL);
96#endif /* __OpenBSD__ */ 101#endif /* __OpenBSD__ */
97#endif
98 102
99 return ret; 103 return ret;
100} 104}