From: Baptiste Daroussin Date: Tue, 2 Nov 2021 10:57:52 +0000 (+0100) Subject: cleanup: replace most writen with dprintf X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f2848ac073a80dc237fbe234fedb23454b63b24;p=thirdparty%2Fmlmmj.git cleanup: replace most writen with dprintf --- diff --git a/include/mlmmj-maintd.h b/include/mlmmj-maintd.h index 5ec79bd4..562222b1 100644 --- a/include/mlmmj-maintd.h +++ b/include/mlmmj-maintd.h @@ -42,16 +42,6 @@ int run_digests(struct mlmmj_list *list, const char *mlmmjsend); * C99 -- Jun 09 2004, mmj */ -#define WRITEMAINTLOG4( s1, s2, s3, s4 ) do { \ - logstr = concatstr( s1, s2, s3, s4 ) ;\ - writen(maintdlogfd, logstr, strlen(logstr)); \ - myfree(logstr); \ - } while (0); - -#define WRITEMAINTLOG6( s1, s2, s3, s4, s5, s6 ) do { \ - logstr = concatstr( s1, s2, s3, s4, s5, s6 ) ;\ - writen(maintdlogfd, logstr, strlen(logstr)); \ - myfree(logstr); \ - } while (0); +#define WRITEMAINTLOG(fmt, ...) dprintf(maintdlogfd, fmt, __VA_ARGS__) #endif /* MLMMJ_MAINTD_H */ diff --git a/src/do_all_the_voodoo_here.c b/src/do_all_the_voodoo_here.c index ff6520e9..d7ea1842 100644 --- a/src/do_all_the_voodoo_here.c +++ b/src/do_all_the_voodoo_here.c @@ -21,6 +21,7 @@ * IN THE SOFTWARE. */ +#include #include #include #include @@ -74,7 +75,7 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd, const struct strlist *delhdrs, struct mailhdr *readhdrs, struct strlist *allhdrs, const char *prefix) { - char *hdrline, *unfolded, *subject, *unqp; + char *hdrline, *unfolded, *unqp; int hdrsadded = 0; int subject_present = 0; @@ -107,13 +108,11 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd, /* add Subject if none is present and a prefix is defined */ if (prefix && !subject_present) { - subject = concatstr(3,"Subject: ",prefix,"\n"); - writen(outfd, subject, strlen(subject)); - myfree(subject); + dprintf(outfd, "Subject: %s\n", prefix); subject_present = 1; } /* write LF */ - if(writen(outfd, "\n", 1) < 0) { + if(dprintf(outfd, "\n") < 0) { myfree(hdrline); myfree(unfolded); log_error(LOG_ARGS, "Error writing hdrs."); @@ -141,12 +140,8 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd, unqp = cleanquotedp(hdrline + 8); if(strstr(hdrline + 8, prefix) == NULL && strstr(unqp, prefix) == NULL) { - subject = concatstr(4, - "Subject: ", prefix, - hdrline + 8, "\n"); - writen(outfd, subject, - strlen(subject)); - myfree(subject); + dprintf(outfd, "Subject: %s%s\n", + prefix, hdrline + 8); myfree(hdrline); myfree(unqp); continue; @@ -157,7 +152,7 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd, /* Should it be stripped? */ if(!delhdrs || !findit(hdrline, delhdrs)) - writen(outfd, unfolded, strlen(unfolded)); + dprintf(outfd, "%s", unfolded); myfree(hdrline); myfree(unfolded); diff --git a/src/incindexfile.c b/src/incindexfile.c index 40a76da9..b439460c 100644 --- a/src/incindexfile.c +++ b/src/incindexfile.c @@ -77,7 +77,7 @@ int incindexfile(const char *listdir) index++; itoa(index, intbuf); lseek(fd, 0, SEEK_SET); - writen(fd, intbuf, strlen(intbuf)); + dprintf(fd, "%s", intbuf); close(fd); /* Lock is also released */ myfree(indexfilename); diff --git a/src/log_oper.c b/src/log_oper.c index ca3d3241..359d969d 100644 --- a/src/log_oper.c +++ b/src/log_oper.c @@ -97,7 +97,7 @@ int log_oper(const char *prefix, const char *basename, const char *fmt, ...) va_end(ap); logstr = concatstr(4, ct, " ", log_msg, "\n"); - if(writen(fd, logstr, strlen(logstr)) < 0) + if(dprintf(fd, "%s", logstr) < 0) log_error(LOG_ARGS, "Could not write to %s", logfilename); close(fd); diff --git a/src/mail-functions.c b/src/mail-functions.c index 9ff128c7..2facc1de 100644 --- a/src/mail-functions.c +++ b/src/mail-functions.c @@ -37,114 +37,60 @@ #include "log_error.h" #include "memory.h" -/* "EHLO \r\n" has length 7 */ -#define EXTRA_EHLO_LEN 7 int write_ehlo(int sockfd, const char *hostname) { - size_t len = (size_t)(strlen(hostname) + EXTRA_EHLO_LEN + 1); - char *ehlo; size_t bytes_written; - - if((ehlo = mymalloc(len)) == 0) - return errno; - snprintf(ehlo, len, "EHLO %s\r\n", hostname); - len = strlen(ehlo); -#if 0 - fprintf(stderr, "\nwrite_ehlo, ehlo = [%s]\n", ehlo); -#endif - bytes_written = writen(sockfd, ehlo, len); + + bytes_written = dprintf(sockfd, "EHLO %s\r\n", hostname); if(bytes_written < 0) { log_error(LOG_ARGS, "Could not write EHLO"); - myfree(ehlo); return errno; } - myfree(ehlo); return 0; } -/* "HELO \r\n" has length 7 */ -#define EXTRA_HELO_LEN 7 + int write_helo(int sockfd, const char *hostname) { - size_t len = (size_t)(strlen(hostname) + EXTRA_HELO_LEN + 1); - char *helo; size_t bytes_written; - - if((helo = mymalloc(len)) == 0) - return errno; - snprintf(helo, len, "HELO %s\r\n", hostname); - len = strlen(helo); -#if 0 - fprintf(stderr, "\nwrite_helo, helo = [%s]\n", helo); -#endif - bytes_written = writen(sockfd, helo, len); + + bytes_written = dprintf(sockfd, "HELO %s\r\n", hostname); if(bytes_written < 0) { log_error(LOG_ARGS, "Could not write HELO"); - myfree(helo); return errno; } - myfree(helo); return 0; } -/* "MAIL FROM:<> \r\n" has length 15 */ -#define EXTRA_FROM_LEN 15 + int write_mail_from(int sockfd, const char *from_addr, const char *extra) { - size_t len = (size_t)(strlen(from_addr) + EXTRA_FROM_LEN + - strlen(extra) + 1); - char *mail_from; size_t bytes_written; - mail_from = mymalloc(len); - if(extra && extra[0] != '\0') { if(extra[0] == ' ') extra++; - snprintf(mail_from, len, "MAIL FROM:<%s> %s\r\n", from_addr, - extra); + bytes_written = dprintf(sockfd, "MAIL FROM:<%s> %s\r\n", + from_addr, extra); } else - snprintf(mail_from, len, "MAIL FROM:<%s>\r\n", from_addr); - - len = strlen(mail_from); + bytes_written = dprintf(sockfd, "MAIL FROM:<%s>\r\n", from_addr); -#if 0 - fprintf(stderr, "%s", mail_from); -#endif - bytes_written = writen(sockfd, mail_from, len); if(bytes_written < 0) { log_error(LOG_ARGS, "Could not write FROM"); - myfree(mail_from); return errno; } - myfree(mail_from); return 0; } -/* "RCPT TO:<>\r\n" has length 12 */ -#define EXTRA_RCPT_LEN 12 int write_rcpt_to(int sockfd, const char *rcpt_addr) { - size_t len = (size_t)(strlen(rcpt_addr) + EXTRA_RCPT_LEN + 1); - char *rcpt_to; size_t bytes_written; - - if((rcpt_to = mymalloc(len)) == 0) - return errno; - snprintf(rcpt_to, len, "RCPT TO:<%s>\r\n", rcpt_addr); - len = strlen(rcpt_to); -#if 0 - log_error(LOG_ARGS, "%s", rcpt_to); -#endif - bytes_written = writen(sockfd, rcpt_to, len); + bytes_written = dprintf(sockfd, "RCPT TO:<%s>\r\n", rcpt_addr); if(bytes_written < 0) { log_error(LOG_ARGS, "Could not write TO"); - myfree(rcpt_to); return errno; } - myfree(rcpt_to); return 0; } - int write_mailbody_from_map(int sockfd, char *mapstart, size_t size, const char *tohdr) { @@ -155,7 +101,7 @@ int write_mailbody_from_map(int sockfd, char *mapstart, size_t size, for(next = cur = mapstart; next < mapstart + size; next++) { if(*next == '\n') { - if(writen(sockfd, cur, next - cur) < 0) { + if(dprintf(sockfd, "%.*s", (int)(next - cur), cur) < 0) { log_error(LOG_ARGS, "Could not write mail"); return -1; } @@ -166,12 +112,12 @@ int write_mailbody_from_map(int sockfd, char *mapstart, size_t size, newlinebuf[2] = '.'; len = 3; } - if(writen(sockfd, newlinebuf, len) < 0) { + if(dprintf(sockfd, "%.*s", (int)len, newlinebuf) < 0) { log_error(LOG_ARGS, "Could not write mail"); return -1; } if(i && tohdr && *(next+1) == '\n') { /* add To: header */ - if(writen(sockfd, tohdr, strlen(tohdr)) < 0) { + if(dprintf(sockfd, "%s", tohdr) < 0) { log_error(LOG_ARGS, "Could not write" " To: header"); return -1; @@ -268,64 +214,34 @@ int write_dot(int sockfd) { size_t bytes_written; - bytes_written = writen(sockfd, "\r\n.\r\n", 5); + bytes_written = dprintf(sockfd, "\r\n.\r\n"); if(bytes_written < 0) return errno; return 0; } -/* "\r\n" has length 2 */ -#define EXTRA_CUSTOM_LEN 2 int write_custom_line(int sockfd, const char *line) { - size_t len = strlen(line) + EXTRA_CUSTOM_LEN + 1; size_t bytes_written; - char *customline; - - if((customline = mymalloc(len)) == 0) - return errno; - - snprintf(customline, len, "%s\r\n", line); - len = strlen(customline); -#if 0 - fprintf(stderr, "write_custom_line = [%s]\n", customline); - fprintf(stderr, "strlen(customline) = [%d]\n", strlen(customline)); -#endif - bytes_written = writen(sockfd, customline, len); + + bytes_written = dprintf(sockfd, "%s\r\n", line); if(bytes_written < 0) { log_error(LOG_ARGS, "Could not write customline"); - myfree(customline); return errno; } - myfree(customline); return 0; } -/* "Reply-To: \r\n" has length 12 */ -#define EXTRA_REPLYTO_LEN 12 int write_replyto(int sockfd, const char *replyaddr) { - size_t len = (size_t)(strlen(replyaddr) + EXTRA_REPLYTO_LEN + 1); - char *replyto; size_t bytes_written; - if((replyto = mymalloc(len)) == 0) - return errno; - - snprintf(replyto, len, "Reply-To: %s\r\n", replyaddr); - len = strlen(replyto); - -#if 0 - fprintf(stderr, "\nwrite_replyto, replyto = [%s]\n", replyto); -#endif - bytes_written = writen(sockfd, replyto, len); + bytes_written = dprintf(sockfd, "Reply-To: %s\r\n", replyaddr); if(bytes_written < 0) { log_error(LOG_ARGS, "Could not write Reply-To header"); - myfree(replyto); return errno; } - myfree(replyto); return 0; } diff --git a/src/mlmmj-bounce.c b/src/mlmmj-bounce.c index 7c1e6f28..f33cbd9c 100644 --- a/src/mlmmj-bounce.c +++ b/src/mlmmj-bounce.c @@ -93,7 +93,7 @@ static void do_probe(struct mlmmj_list *list, const char *mlmmjsend, const char if(fd < 0) log_error(LOG_ARGS, "Could not open %s", probefile); else - if(writen(fd, a, strlen(a)) < 0) + if(dprintf(fd, "%s", a) < 0) log_error(LOG_ARGS, "Could not write time in probe"); myfree(probefile); @@ -239,9 +239,9 @@ int main(int argc, char **argv) log_error(LOG_ARGS, "Have to invoke either as root " "or as the user owning listdir"); - writen(STDERR_FILENO, + dprintf(STDERR_FILENO, "Have to invoke either as root " - "or as the user owning listdir\n", 60); + "or as the user owning listdir\n"); exit(EXIT_FAILURE); } } else { @@ -375,7 +375,7 @@ int main(int argc, char **argv) t = time(NULL); snprintf(buf, len-26, "%s:%ld # ", number, (long int)t); ctime_r(&t, buf+strlen(buf)); - writen(fd, buf, strlen(buf)); + dprintf(fd, "%s", buf); close(fd); if(mailname) { diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index 5180c9cf..44767e75 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -821,11 +821,10 @@ int run_digests(struct mlmmj_list *list, const char *mlmmjsend) char *lasttimestr, *lastindexstr, *lastissuestr; char *digestname, *indexname; char *digestintervalstr, *digestmaxmailsstr; - char *s1, *s2, *s3; + char *s1, *s2; time_t digestinterval, t, lasttime; long digestmaxmails, lastindex, index, lastissue; int fd, indexfd, lock; - size_t lenbuf, lenstr; if (statctrl(list, "noarchive")) { return 0; @@ -932,16 +931,10 @@ int run_digests(struct mlmmj_list *list, const char *mlmmjsend) log_error(LOG_ARGS, "Could not seek '%s'", digestname); } else { /* index + ':' + time + ':' + issue + '\n' + '\0' */ - lenbuf = 20 + 1 + 20 + 1 + 20 + 2; - s3 = mymalloc(lenbuf); - lenstr = snprintf(s3, lenbuf, "%ld:%ld:%ld\n", index, (long)t, lastissue); - if (lenstr >= lenbuf) - lenstr = lenbuf - 1; - if (writen(fd, s3, lenstr) == -1) { + if (dprintf(fd, "%ld:%ld:%ld\n", index, (long)t, lastissue) == -1) { log_error(LOG_ARGS, "Could not write new '%s'", digestname); } - myfree(s3); } } @@ -1009,43 +1002,37 @@ void do_maintenance(const char *listdir, const char *mlmmjsend, t = time(NULL); if(ctime_r(&t, timenow)) - WRITEMAINTLOG4(3, "Starting maintenance run at ", - timenow, "\n"); + WRITEMAINTLOG("Starting maintenance run at %s\n", timenow); - WRITEMAINTLOG4(3, "clean_moderation(", listdir, ");\n"); + WRITEMAINTLOG("clean_moderation(%s);\n", listdir); clean_moderation(&list); - WRITEMAINTLOG4(3, "clean_discarded(", listdir, ");\n"); + WRITEMAINTLOG("clean_discarded(%s);\n", listdir); clean_discarded(&list); - WRITEMAINTLOG4(3, "clean_subconf(", listdir, ");\n"); + WRITEMAINTLOG("clean_subconf(%s);\n", listdir); clean_subconf(&list); - WRITEMAINTLOG4(3, "clean_unsubconf(", listdir, ");\n"); + WRITEMAINTLOG("clean_unsubconf(%s);\n", listdir); clean_unsubconf(&list); - WRITEMAINTLOG6(5, "resend_queue(", listdir, ", ", mlmmjsend, - ");\n"); + WRITEMAINTLOG("resend_queue(%s, %s);\n)", listdir, mlmmjsend); resend_queue(&list, mlmmjsend); - WRITEMAINTLOG6(5, "resend_requeue(", listdir, ", ", mlmmjsend, - ");\n"); + WRITEMAINTLOG("resend_requeue(%s, %s);\n", listdir, mlmmjsend); resend_requeue(&list, mlmmjsend); - WRITEMAINTLOG4(3, "clean_nolongerbouncing(", listdir, ");\n"); + WRITEMAINTLOG("clean_nolongerbouncing(%s);\n", listdir); clean_nolongerbouncing(&list); - WRITEMAINTLOG6(5, "unsub_bouncers(", listdir, ", ", - mlmmjunsub, ");\n"); + WRITEMAINTLOG("unsub_bouncers(%s, %s);\n", listdir, mlmmjunsub); unsub_bouncers(&list, mlmmjunsub); - WRITEMAINTLOG6(5, "probe_bouncers(", listdir, ", ", - mlmmjbounce, ");\n"); + WRITEMAINTLOG("probe_bouncers(%s, %s);\n", listdir, mlmmjbounce); probe_bouncers(&list, mlmmjbounce); - WRITEMAINTLOG6(5, "run_digests(", listdir, ", ", mlmmjsend, - ");\n"); + WRITEMAINTLOG("run_digests(%s, %s);\n", listdir, mlmmjsend); run_digests(&list, mlmmjsend); close(maintdlogfd); diff --git a/src/mlmmj-process.c b/src/mlmmj-process.c index 613a25f2..2946cebf 100644 --- a/src/mlmmj-process.c +++ b/src/mlmmj-process.c @@ -556,9 +556,9 @@ int main(int argc, char **argv) log_error(LOG_ARGS, "Have to invoke either as root " "or as the user owning listdir"); - writen(STDERR_FILENO, + dprintf(STDERR_FILENO, "Have to invoke either as root " - "or as the user owning listdir\n", 60); + "or as the user owning listdir\n"); exit(EXIT_FAILURE); } } else { @@ -1028,7 +1028,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } myfree(omitfilename); - if(writen(omitfd, posteraddr, strlen(posteraddr)) < 0) { + if(dprintf(omitfd, "%s", posteraddr) < 0) { log_error(LOG_ARGS, "could not write omit file"); myfree(mqueuename); diff --git a/src/mlmmj-receive.c b/src/mlmmj-receive.c index b67de9a2..1e275425 100644 --- a/src/mlmmj-receive.c +++ b/src/mlmmj-receive.c @@ -113,9 +113,9 @@ int main(int argc, char **argv) "Have to invoke either as root " "or as the user owning listdir " "Invoked with uid = [%d]", (int)uid); - writen(STDERR_FILENO, + dprintf(STDERR_FILENO, "Have to invoke either as root " - "or as the user owning listdir\n", 60); + "or as the user owning listdir\n"); exit(EXIT_FAILURE); } } else { diff --git a/src/mlmmj-send.c b/src/mlmmj-send.c index 15cecd69..f43a9184 100644 --- a/src/mlmmj-send.c +++ b/src/mlmmj-send.c @@ -318,20 +318,20 @@ int send_mail(int sockfd, const char *from, const char *to, tohdr = NULL; if(prepmailinmem) { - retval = writen(sockfd, hdrs, hdrslen); + retval = dprintf(sockfd, "%.*s", (int) hdrslen, hdrs); if(retval < 0) { log_error(LOG_ARGS, "Could not write mailheaders.\n"); return retval; } if(tohdr) { - retval = writen(sockfd, tohdr, strlen(tohdr)); + retval = dprintf(sockfd, "%s", tohdr); if(retval < 0) { log_error(LOG_ARGS, "Could not write To:.\n"); return retval; } myfree(tohdr); } - retval = writen(sockfd, body, bodylen); + retval = dprintf(sockfd, "%.*s", (int)bodylen, body); if(retval < 0) { log_error(LOG_ARGS, "Could not write mailbody.\n"); return retval; @@ -581,12 +581,12 @@ int send_mail_verp(int sockfd, struct strlist *addrs, char *mailmap, } if(prepmailinmem) { - retval = writen(sockfd, hdrs, hdrslen); + retval = dprintf(sockfd, "%.*s", (int)hdrslen, hdrs); if(retval < 0) { log_error(LOG_ARGS, "Could not write mailheaders.\n"); return retval; } - retval = writen(sockfd, body, bodylen); + retval = dprintf(sockfd, "%.*s", (int)bodylen, body); if(retval < 0) { log_error(LOG_ARGS, "Could not write mailbody.\n"); return retval; @@ -666,7 +666,8 @@ int requeuemail(const char *listdir, const char *index, struct strlist *addrs, int addrcount) { int addrfd, i; - char *dirname, *addrfilename, *addr; + const char *addr; + char *dirname, *addrfilename; dirname = concatstr(3, listdir, "/requeue/", index); if(mkdir(dirname, 0750) < 0 && errno != EEXIST) { @@ -691,21 +692,19 @@ int requeuemail(const char *listdir, const char *index, struct strlist *addrs, * ones will be tried first when mlmmj-maintd sends out mails * that have been requeued. addrcount was so far we were */ for(i = addrcount + 1; i < addrs->count; i++) { - addr = concatstr(2, addrs->strs[i], "\n"); - if(writen(addrfd, addr, strlen(addr)) < 0) { + addr = addrs->strs[i]; + if(dprintf(addrfd, "%s\n", addr) < 0) { log_error(LOG_ARGS, "Could not add [%s] " "to requeue file", addr); return -1; } - myfree(addr); } - addr = concatstr(2, addrs->strs[addrcount], "\n"); - if(writen(addrfd, addr, strlen(addr)) < 0) { + addr = addrs->strs[addrcount]; + if(dprintf(addrfd, "%s\n", addr) < 0) { log_error(LOG_ARGS, "Could not add [%s] to requeue " "file", addr); return -1; } - myfree(addr); } myfree(addrfilename); close(addrfd); @@ -889,9 +888,9 @@ int main(int argc, char **argv) log_error(LOG_ARGS, "Have to invoke either as root " "or as the user owning listdir"); - writen(STDERR_FILENO, + dprintf(STDERR_FILENO, "Have to invoke either as root " - "or as the user owning listdir\n", 60); + "or as the user owning listdir\n"); exit(EXIT_FAILURE); } } else { @@ -1104,7 +1103,7 @@ int main(int argc, char **argv) S_IRUSR|S_IWUSR); myfree(tmpstr); if(tmpfd >= 0) { - writen(tmpfd, bounceaddr, strlen(bounceaddr)); + dprintf(tmpfd, "%s", bounceaddr); fsync(tmpfd); } close(tmpfd); @@ -1117,7 +1116,7 @@ int main(int argc, char **argv) S_IRUSR|S_IWUSR); myfree(tmpstr); if(tmpfd >= 0) { - writen(tmpfd, to_addr, strlen(to_addr)); + dprintf(tmpfd, "%s", to_addr); fsync(tmpfd); } close(tmpfd); @@ -1132,8 +1131,7 @@ int main(int argc, char **argv) S_IRUSR|S_IWUSR); myfree(tmpstr); if(tmpfd >= 0) { - writen(tmpfd, replyto, - strlen(replyto)); + dprintf(tmpfd, "%s", replyto); fsync(tmpfd); } close(tmpfd); diff --git a/src/mlmmj-sub.c b/src/mlmmj-sub.c index 066e505e..d23e690e 100644 --- a/src/mlmmj-sub.c +++ b/src/mlmmj-sub.c @@ -98,7 +98,7 @@ static void moderate_sub(struct mlmmj_list *list, const char *subaddr, break; } - if(writen(fd, str, strlen(str)) < 0) { + if(dprintf(fd, "%s", str) < 0) { log_error(LOG_ARGS, "could not write to %s" "ignoring request: %s", str); exit(EXIT_FAILURE); @@ -408,7 +408,7 @@ static void generate_subconfirm(struct mlmmj_list *list, const char *subaddr, myfree(confirmfilename); - if(writen(subconffd, subaddr, strlen(subaddr)) < 0) { + if(dprintf(subconffd, "%s", subaddr) < 0) { log_error(LOG_ARGS, "Could not write to subconffd"); myfree(confirmfilename); myfree(randomstr); diff --git a/src/mlmmj-unsub.c b/src/mlmmj-unsub.c index 6eec81ca..3fee1737 100644 --- a/src/mlmmj-unsub.c +++ b/src/mlmmj-unsub.c @@ -167,7 +167,7 @@ static void generate_unsubconfirm(struct mlmmj_list *list, const char *subaddr, myfree(confirmfilename); - if(writen(subconffd, subaddr, strlen(subaddr)) < 0) { + if (dprintf(subconffd, "%s", subaddr) < 0) { log_error(LOG_ARGS, "Could not write unsubconffile"); myfree(randomstr); myfree(confirmfilename); @@ -246,14 +246,14 @@ static ssize_t unsubscribe(int subreadfd, int subwritefd, const char *address) } if(suboff > 0) { - writeres = writen(subwritefd, inmap, suboff); + writeres = dprintf(subwritefd, "%.*s", (int)suboff, inmap); if(writeres < 0) return -1; } written += writeres; - writeres = writen(subwritefd, inmap + len + suboff, - st.st_size - len - suboff); + writeres = dprintf(subwritefd, "%.*s", (int)(st.st_size - len - suboff), + inmap + len + suboff); if(writeres < 0) return -1; diff --git a/src/prepstdreply.c b/src/prepstdreply.c index 0c874048..ab5ea5a0 100644 --- a/src/prepstdreply.c +++ b/src/prepstdreply.c @@ -1642,9 +1642,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list, if (*line == ' ' || *line == '\t') { /* line beginning with linear whitespace is a continuation of previous header line */ - len = strlen(line); - line[len] = '\n'; - if(writen(outfd, line, len+1) < 0) { + if(dprintf(outfd, "%s\n", line) < 0) { log_error(LOG_ARGS, "Could not write std mail"); myfree(line); myfree(retstr); @@ -1682,9 +1680,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list, line = concatstr(2, "Subject: ", tmp); myfree(tmp); } - len = strlen(line); - line[len] = '\n'; - if(writen(outfd, line, len+1) < 0) { + if(dprintf(outfd, "%s\n", line) < 0) { log_error(LOG_ARGS, "Could not write std mail"); myfree(line); myfree(retstr); @@ -1697,9 +1693,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list, } for (i=0; headers[i] != NULL; i++) { - len = strlen(headers[i]); - headers[i][len] = '\n'; - if(writen(outfd, headers[i], len+1) < 0) { + if(dprintf(outfd, "%s\n", headers[i]) < 0) { log_error(LOG_ARGS, "Could not write std mail"); if (line) myfree(line); @@ -1710,7 +1704,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list, } /* end the headers */ - if(writen(outfd, "\n", 1) < 0) { + if(dprintf(outfd, "\n") < 0) { log_error(LOG_ARGS, "Could not write std mail"); if (line) myfree(line); @@ -1723,9 +1717,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list, line = get_processed_text_line(txt, 0, list); } while(line) { - len = strlen(line); - line[len] = '\n'; - if(writen(outfd, line, len+1) < 0) { + if(dprintf(outfd, "%s\n", line) < 0) { myfree(str); log_error(LOG_ARGS, "Could not write std mail"); myfree(retstr); diff --git a/src/send_digest.c b/src/send_digest.c index 6f055847..abdf8956 100644 --- a/src/send_digest.c +++ b/src/send_digest.c @@ -370,7 +370,7 @@ fallback_subject: myfree(subject); - if (writen(fd, tmp, strlen(tmp)) < 0) { + if (dprintf(fd, "%s", tmp) < 0) { myfree(tmp); goto errdighdrs; } @@ -383,7 +383,7 @@ fallback_subject: close(hdrfd); hdrfd = -1; - if (writen(fd, "\n", 1) < 0) { + if (dprintf(fd, "\n") < 0) { errdighdrs: log_error(LOG_ARGS, "Could not write digest headers to '%s'", queuename); @@ -407,7 +407,7 @@ errdighdrs: "\nContent-Type: text/plain; charset=UTF-8" "\nContent-Transfer-Encoding: 8bit" "\n\n"); - if (writen(fd, tmp, strlen(tmp)) == -1) { + if (dprintf(fd, "%s", tmp) == -1) { log_error(LOG_ARGS, "Could not write digest text/plain" " part headers to '%s'", queuename); close(fd); @@ -428,7 +428,7 @@ errdighdrs: if (line == NULL) break; len = strlen(line); line[len] = '\n'; - if(writen(fd, line, len+1) < 0) { + if(dprintf(fd, "%s", line) < 0) { myfree(line); log_error(LOG_ARGS, "Could not write" " std mail"); @@ -461,7 +461,7 @@ errdighdrs: "\nContent-Disposition: inline; filename=\"", list->name, "_", buf, ".eml\"" "\n\n"); - if (writen(fd, tmp, strlen(tmp)) == -1) { + if (dprintf(fd, "%s", tmp) == -1) { log_error(LOG_ARGS, "Could not write digest part " "headers for archive index %d to " "'%s'", i, queuename); @@ -491,7 +491,7 @@ errdighdrs: } tmp = concatstr(3, "\n--", boundary, "--\n"); - if (writen(fd, tmp, strlen(tmp)) == -1) { + if (dprintf(fd, "%s", tmp) == -1) { log_error(LOG_ARGS, "Could not write digest end to '%s'", queuename); close(fd); diff --git a/src/send_list.c b/src/send_list.c index a3a9f6fe..75bf1836 100644 --- a/src/send_list.c +++ b/src/send_list.c @@ -141,10 +141,9 @@ static void print_subs(int fd, subs_list_state *s) const char *sub; rewind_subs_list(s); while ((sub = get_sub(s)) != NULL) { - if (writen(fd, sub, strlen(sub)) < 0) { + if (dprintf(fd, "%s\n", sub) < 0) { log_error(LOG_ARGS, "error writing subs list"); } - writen(fd, "\n", 1); } } @@ -199,11 +198,11 @@ void send_list(struct mlmmj_list *list, const char *emailaddr, exit(EXIT_FAILURE); } print_subs(fd, normalsls); - writen(fd, "\n-- \n", 5); + dprintf(fd, "\n-- \n"); print_subs(fd, nomailsls); - writen(fd, "\n-- \n", 5); + dprintf(fd, "\n-- \n"); print_subs(fd, digestsls); - writen(fd, "\n-- \nend of output\n", 19); + dprintf(fd, "\n-- \nend of output\n"); close(fd); }