+++ /dev/null
-/* Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk>
- *
- * $Id$
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#ifndef _MEMORY_H
-#define _MEMORY_H 1
-
-void *__mymalloc(const char *file, int line, size_t size);
-void *__myrealloc(const char *file, int line, void *ptr, size_t size);
-void __myfree(const char *file, int line, void *ptr);
-char *__mystrdup(const char *file, int line, const char *str);
-char *__mystrndup(const char *file, int line, const char *str, size_t len);
-int __myasprintf(const char *file, int line, char **ret, const char *fmt, ...) __attribute__((format(printf, 4, 5)));
-
-#define mymalloc(s) __mymalloc(__FILE__, __LINE__, s)
-#define myrealloc(p,s) __myrealloc(__FILE__, __LINE__, p, s)
-#define myfree(p) __myfree(__FILE__, __LINE__, p)
-#define mystrdup(p) __mystrdup(__FILE__, __LINE__, p)
-#define mystrndup(p, s) __mystrdup(__FILE__, __LINE__, p, s)
-#define myasprintf(p, s, ...) __myasprintf(__FILE__, __LINE__, p, s, __VA_ARGS__)
-
-#endif /* _MEMORY_H */
};
/* make sure we use the wrappers */
-#ifndef _MEMORY_C
+#ifndef XMALLOC_H
#define malloc Bad_programmer__no_biscuit
#define realloc Bad_programmer__no_biscuit
-#define free Bad_programmer__no_biscuit
-#ifdef strdup
-#undef strdup
-#define strdup Bad_programmer__no_biscuit
-#endif /* strdup */
+#ifdef xstrdup
+#undef xstrdup
+#define xstrdup Bad_programmer__no_biscuit
+#endif /* xstrdup */
#endif /* _MEMORY_C */
#endif /* MLMMJ_GENERIC_INCLUDES */
--- /dev/null
+#ifndef XMALLOC_H
+#define XMALLOC_H
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static inline void *xmalloc(size_t size)
+{
+ void *ptr = malloc(size);
+ if (ptr == NULL)
+ abort();
+ return (ptr);
+}
+
+static inline void *xcalloc(size_t n, size_t size)
+{
+ void *ptr = calloc(n, size);
+ if (ptr == NULL)
+ abort();
+ return (ptr);
+}
+
+static inline void *xrealloc(void *ptr, size_t size)
+{
+ ptr = realloc(ptr, size);
+ if (ptr == NULL)
+ abort();
+ return (ptr);
+}
+
+static inline char *xstrdup(const char *str)
+{
+ char *s = strdup(str);
+ if (s == NULL)
+ abort();
+ return (s);
+}
+
+static inline char *xstrndup(const char *str, size_t n)
+{
+ char *s = strndup(str, n);
+ if (s == NULL)
+ abort();
+ return (s);
+}
+
+static inline int xasprintf(char **ret, const char *fmt, ...)
+{
+ va_list ap;
+ int i;
+
+ va_start(ap, fmt);
+ i = vasprintf(ret, fmt, ap);
+ va_end(ap);
+
+ if (i < 0 || *ret == NULL)
+ abort();
+
+ return (i);
+}
+#endif
mlmmj_send_SOURCES = mlmmj.c mlmmj-send.c mail-functions.c chomp.c \
incindexfile.c checkwait_smtpreply.c utils.c \
init_sockfd.c strgen.c random-int.c \
- print-version.c log_error.c mygetline.c memory.c \
+ print-version.c log_error.c mygetline.c \
controls.c getaddrsfromfd.c readn.c send_mails.c
mlmmj_receive_SOURCES = mlmmj-receive.c random-int.c strgen.c \
- print-version.c log_error.c dumpfd2fd.c memory.c \
+ print-version.c log_error.c dumpfd2fd.c \
log_oper.c readn.c
mlmmj_process_SOURCES = mlmmj.c mlmmj-process.c find_email_adr.c \
print-version.c send_help.c prepstdreply.c \
do_all_the_voodoo_here.c mygetline.c gethdrline.c \
log_error.c controls.c dumpfd2fd.c \
- subscriberfuncs.c memory.c log_oper.c \
+ subscriberfuncs.c log_oper.c \
send_list.c readn.c unistr.c \
send_mails.c checkwait_smtpreply.c \
mail-functions.c init_sockfd.c
mlmmj_sub_SOURCES = mlmmj.c mlmmj-sub.c \
chomp.c random-int.c strgen.c \
subscriberfuncs.c print-version.c \
- log_error.c mygetline.c prepstdreply.c memory.c \
+ log_error.c mygetline.c prepstdreply.c \
controls.c readn.c utils.c unistr.c send_mails.c checkwait_smtpreply.c \
mail-functions.c init_sockfd.c
mlmmj_unsub_SOURCES = mlmmj.c mlmmj-unsub.c \
chomp.c subscriberfuncs.c random-int.c \
strgen.c print-version.c log_error.c mygetline.c \
- prepstdreply.c memory.c controls.c readn.c utils.c \
+ prepstdreply.c controls.c readn.c utils.c \
unistr.c send_mails.c checkwait_smtpreply.c \
mail-functions.c init_sockfd.c
mlmmj_bounce_SOURCES = mlmmj.c mlmmj-bounce.c print-version.c log_error.c \
subscriberfuncs.c strgen.c random-int.c \
prepstdreply.c mygetline.c chomp.c \
- memory.c find_email_adr.c gethdrline.c readn.c \
+ find_email_adr.c gethdrline.c readn.c \
unistr.c controls.c utils.c
mlmmj_maintd_SOURCES = mlmmj.c mlmmj-maintd.c print-version.c log_error.c mygetline.c \
- strgen.c random-int.c chomp.c memory.c \
+ strgen.c random-int.c chomp.c \
send_digest.c dumpfd2fd.c utils.c \
log_oper.c readn.c \
prepstdreply.c gethdrline.c unistr.c controls.c \
send_mails.c checkwait_smtpreply.c \
mail-functions.c init_sockfd.c subscriberfuncs.c
-mlmmj_list_SOURCES = mlmmj-list.c strgen.c print-version.c memory.c \
+mlmmj_list_SOURCES = mlmmj-list.c strgen.c print-version.c \
log_error.c random-int.c readn.c subscriberfuncs.c
install-exec-hook:
#include <unistd.h>
#include <string.h>
+#include "xmalloc.h"
#include "checkwait_smtpreply.h"
#include "config.h"
-#include "memory.h"
#include "mygetline.h"
if(replytype == MLMMJ_EHLO) {
/* Consume all 8BITMIME 250- reply */
do {
- myfree(smtpreply);
+ free(smtpreply);
smtpreply = mygetline(sockfd);
} while (strncmp(smtpreply, "250-", 4) == 0);
} else {
if(smtpreply == NULL) {
/* This will never be a valid SMTP response so will always be returned,
* but is more descriptive than an empty string. */
- smtpreply = mystrdup("none / error / closed connection");
+ smtpreply = xstrdup("none / error / closed connection");
}
#if 0
break;
}
- myfree(smtpreply);
+ free(smtpreply);
return NULL;
}
#include <fcntl.h>
#include <stdbool.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "controls.h"
-#include "memory.h"
#include "log_error.h"
#include "chomp.h"
#include "utils.h"
return (NULL);
}
- ret = mymalloc(sizeof(struct strlist));
+ ret = xmalloc(sizeof(struct strlist));
ret->count = 0;
while ((buflen = getline(&buf, &bufcap, fp)) > 0) {
if (*buf == '\0')
continue;
ret->count++;
- ret->strs = (char **) myrealloc(ret->strs, sizeof(char *) *
+ ret->strs = (char **) xrealloc(ret->strs, sizeof(char *) *
(ret->count + 1));
- ret->strs[ret->count-1] = mystrdup(buf);
+ ret->strs[ret->count-1] = xstrdup(buf);
ret->strs[ret->count] = NULL;
}
fclose(fp);
if (errstr != NULL) {
log_error(LOG_ARGS, "Invalid value for '%s': %s", ctrlstr, errstr);
}
- myfree(val);
+ free(val);
return (ret);
}
if (errstr != NULL) {
log_error(LOG_ARGS, "Invalid value for '%s': %s", ctrlstr, errstr);
}
- myfree(val);
+ free(val);
return (ret);
}
if (errstr != NULL) {
log_error(LOG_ARGS, "Invalid value for '%s': %s", ctrlstr, errstr);
}
- myfree(val);
+ free(val);
return (ret);
}
if (errstr != NULL) {
log_error(LOG_ARGS, "Invalid value for '%s': %s", ctrlstr, errstr);
}
- myfree(val);
+ free(val);
return (ret);
}
#include <string.h>
#include <unistd.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "mygetline.h"
#include "gethdrline.h"
#include "do_all_the_voodoo_here.h"
#include "log_error.h"
#include "wrappers.h"
-#include "memory.h"
int findit(const char *line, const struct strlist *headers)
{
readhdrs[i].valuecount++;
valuelen = strlen(line) - tokenlen;
readhdrs[i].values =
- (char **)myrealloc(readhdrs[i].values,
+ (char **)xrealloc(readhdrs[i].values,
readhdrs[i].valuecount * sizeof(char *));
readhdrs[i].values[readhdrs[i].valuecount - 1] =
- (char *)mymalloc(valuelen + 1);
+ (char *)xmalloc(valuelen + 1);
strcpy(readhdrs[i].values[readhdrs[i].valuecount - 1],
line+tokenlen);
}
if(dumpfd2fd(hdrfd, outfd) < 0) {
log_error(LOG_ARGS, "Could not "
"add extra headers");
- myfree(hdrline);
- myfree(unfolded);
+ free(hdrline);
+ free(unfolded);
return -1;
}
fsync(outfd);
}
/* write LF */
if(dprintf(outfd, "\n") < 0) {
- myfree(hdrline);
- myfree(unfolded);
+ free(hdrline);
+ free(unfolded);
log_error(LOG_ARGS, "Error writing hdrs.");
return -1;
}
- myfree(hdrline);
- myfree(unfolded);
+ free(hdrline);
+ free(unfolded);
break;
}
/* Snatch a copy of the header */
allhdrs->count++;
- allhdrs->strs = myrealloc(allhdrs->strs,
+ allhdrs->strs = xrealloc(allhdrs->strs,
sizeof(char *) * (allhdrs->count));
- allhdrs->strs[allhdrs->count-1] = mystrdup(hdrline);
+ allhdrs->strs[allhdrs->count-1] = xstrdup(hdrline);
/* Add Subject: prefix if wanted */
if(prefix) {
strstr(unqp, prefix) == NULL) {
dprintf(outfd, "Subject: %s%s\n",
prefix, hdrline + 8);
- myfree(hdrline);
- myfree(unqp);
+ free(hdrline);
+ free(unqp);
continue;
}
- myfree(unqp);
+ free(unqp);
}
}
if(!delhdrs || !findit(hdrline, delhdrs))
dprintf(outfd, "%s", unfolded);
- myfree(hdrline);
- myfree(unfolded);
+ free(hdrline);
+ free(unfolded);
}
/* Just print the rest of the mail */
#include <stdlib.h>
#include "find_email_adr.h"
-#include "memory.h"
+#include "xmalloc.h"
/*
* Start of a "comment".
return (NULL);
/* We assume that length(input) <= length(output) */
- nbuf = mymalloc(strlen(name) + 1);
+ nbuf = xmalloc(strlen(name) + 1);
if (strchr(name, '(') == NULL && strchr(name, '<') == NULL
&& strchr(name, ' ') == NULL) {
}
*cp2 = '\0';
- nbuf = (char *)myrealloc(nbuf, strlen(nbuf) + 1);
+ nbuf = (char *)xrealloc(nbuf, strlen(nbuf) + 1);
return (nbuf);
}
char *p;
char *s;
- s = (char *)mymalloc(strlen(str) + 1);
+ s = (char *)xmalloc(strlen(str) + 1);
strcpy(s, str);
p = s;
adr = skin(cur);
if (adr) {
retstruct->emailcount++;
- retstruct->emaillist = (char **)myrealloc(retstruct->emaillist,
+ retstruct->emaillist = (char **)xrealloc(retstruct->emaillist,
sizeof(char *) * retstruct->emailcount);
retstruct->emaillist[retstruct->emailcount-1] = adr;
}
}
- myfree(s);
+ free(s);
return retstruct;
}
#include <unistd.h>
#include <string.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "log_error.h"
-#include "memory.h"
#include "strgen.h"
#include "getaddrsfromfd.h"
len = next - cur;
if(next == start + st.st_size - 1 && *next != '\n')
len++;
- slist->strs = (char **)myrealloc(slist->strs,
+ slist->strs = (char **)xrealloc(slist->strs,
sizeof(char *) * slist->count);
- slist->strs[slist->count - 1] = mymalloc(len + 1);
+ slist->strs[slist->count - 1] = xmalloc(len + 1);
strncpy(slist->strs[slist->count - 1], cur, len);
slist->strs[slist->count - 1][len] = '\0';
cur = next + 1;
#include <stdlib.h>
#include <unistd.h>
+#include "xmalloc.h"
#include "mygetline.h"
#include "gethdrline.h"
#include "strgen.h"
-#include "memory.h"
+
#include "wrappers.h"
#include "log_error.h"
#include "chomp.h"
}
if (unfolded != NULL)
- *unfolded = mystrdup(retstr);
+ *unfolded = xstrdup(retstr);
chomp(retstr);
/* end-of-headers */
if (*retstr == '\0') {
if (unfolded != NULL) {
- myfree(*unfolded);
+ free(*unfolded);
*unfolded = NULL;
}
- myfree(retstr);
+ free(retstr);
return NULL;
}
} else if (n == -1) { /* error */
log_error(LOG_ARGS, "readn() failed in gethdrline()");
if (unfolded != NULL) {
- myfree(*unfolded);
+ free(*unfolded);
*unfolded = NULL;
}
- myfree(retstr);
+ free(retstr);
return NULL;
}
if (lseek(fd, -1, SEEK_CUR) == (off_t)-1) {
log_error(LOG_ARGS, "lseek() failed in gethdrline()");
if (unfolded != NULL) {
- myfree(*unfolded);
+ free(*unfolded);
*unfolded = NULL;
}
- myfree(retstr);
+ free(retstr);
return NULL;
}
if (unfolded != NULL) {
oldunfolded = *unfolded;
*unfolded = concatstr(2, oldunfolded, line);
- myfree(oldunfolded);
+ free(oldunfolded);
}
chomp(line);
oldretstr = retstr;
retstr = concatstr(2, oldretstr, line);
- myfree(oldretstr);
+ free(oldretstr);
- myfree(line);
+ free(line);
}
}
#include <unistd.h>
#include <string.h>
+#include "xmalloc.h"
#include "wrappers.h"
#include "incindexfile.h"
#include "log_error.h"
#include "strgen.h"
-#include "memory.h"
#include "utils.h"
int incindexfile(struct mlmmj_list *list)
/* eliminate everything which is not a number */
line[strspn(line, "0123456789")] = '\0';
index = strtoim(line, 0, INT_MAX, &errstr);
- myfree(line);
+ free(line);
if (errstr != NULL)
log_error(LOG_ARGS, "Error reading index file: invalid line: %s", line);
}
#include "controls.h"
#include "mygetline.h"
#include "chomp.h"
-#include "memory.h"
+#include "xmalloc.h"
#include "log_oper.h"
#include "subscriberfuncs.h"
ctrl_commands[ctrl].command);
return -1;
}
- param = mystrdup(controlstr + cmdlen + 1);
+ param = xstrdup(controlstr + cmdlen + 1);
MY_ASSERT(param);
if (strchr(param, '/')) {
errno = 0;
/* listname+subconf-digest-COOKIE@domain.tld */
case CTRL_CONFSUB_DIGEST:
conffilename = concatstr(3, list->dir, "/subconf/", param);
- myfree(param);
+ free(param);
if((tmpfd = open(conffilename, O_RDONLY)) < 0) {
/* invalid COOKIE */
errno = 0;
/* listname+subconf-nomail-COOKIE@domain.tld */
case CTRL_CONFSUB_NOMAIL:
conffilename = concatstr(3, list->dir, "/subconf/", param);
- myfree(param);
+ free(param);
if((tmpfd = open(conffilename, O_RDONLY)) < 0) {
/* invalid COOKIE */
errno = 0;
/* listname+subconf-both-COOKIE@domain.tld */
case CTRL_CONFSUB_BOTH:
conffilename = concatstr(3, list->dir, "/subconf/", param);
- myfree(param);
+ free(param);
if((tmpfd = open(conffilename, O_RDONLY)) < 0) {
/* invalid COOKIE */
errno = 0;
/* listname+subconf-COOKIE@domain.tld */
case CTRL_CONFSUB:
conffilename = concatstr(3, list->dir, "/subconf/", param);
- myfree(param);
+ free(param);
if((tmpfd = open(conffilename, O_RDONLY)) < 0) {
/* invalid COOKIE */
errno = 0;
return -1;
}
conffilename = concatstr(3, list->dir, "/unsubconf/", param);
- myfree(param);
+ free(param);
if((tmpfd = open(conffilename, O_RDONLY)) < 0) {
/* invalid COOKIE */
errno = 0;
return -1;
}
conffilename = concatstr(3, list->dir, "/unsubconf/", param);
- myfree(param);
+ free(param);
if((tmpfd = open(conffilename, O_RDONLY)) < 0) {
/* invalid COOKIE */
errno = 0;
return -1;
}
conffilename = concatstr(3, list->dir, "/unsubconf/", param);
- myfree(param);
+ free(param);
if((tmpfd = open(conffilename, O_RDONLY)) < 0) {
/* invalid COOKIE */
errno = 0;
case CTRL_MODERATE:
/* Subscriber moderation; DEPRECATED */
if(strncmp(param, "subscribe", 9) == 0) {
- tmpstr = mystrdup(param + 9);
- myfree(param);
+ tmpstr = xstrdup(param + 9);
+ free(param);
param = tmpstr;
goto permit;
}
moderatefilename = concatstr(3, list->dir, "/moderation/", param);
if(stat(moderatefilename, &stbuf) < 0) {
- myfree(moderatefilename);
+ free(moderatefilename);
/* no mail to moderate */
errno = 0;
log_error(LOG_ARGS, "A release request was"
chomp(omit);
}
unlink(omitfilename);
- myfree(omitfilename);
+ free(omitfilename);
}
- myfree(moderatefilename);
+ free(moderatefilename);
log_oper(list->dir, OPLOGFNAME, "%s released %s",
fromemails->emaillist[0], param);
case CTRL_REJECT:
moderatefilename = concatstr(3, list->dir, "/moderation/", param);
if(stat(moderatefilename, &stbuf) < 0) {
- myfree(moderatefilename);
+ free(moderatefilename);
/* no mail to moderate */
errno = 0;
log_error(LOG_ARGS, "A reject request was"
}
log_oper(list->dir, OPLOGFNAME, "%s rejected %s",
fromemails->emaillist[0], param);
- myfree(param);
+ free(param);
if (unlink(moderatefilename) != 0) {
log_error(LOG_ARGS, "Could not unlink %s",
moderatefilename);
- myfree(moderatefilename);
+ free(moderatefilename);
exit(EXIT_FAILURE);
}
- myfree(moderatefilename);
+ free(moderatefilename);
break;
/* listname+permit-COOKIE@domain.tld */
gatekeepfilename = concatstr(3, list->dir,
"/moderation/subscribe", param);
if(stat(gatekeepfilename, &stbuf) < 0) {
- myfree(gatekeepfilename);
+ free(gatekeepfilename);
/* no mail to moderate */
errno = 0;
log_error(LOG_ARGS, "A permit request was"
gatekeepfilename = concatstr(3, list->dir,
"/moderation/subscribe", param);
if(stat(gatekeepfilename, &stbuf) < 0) {
- myfree(gatekeepfilename);
+ free(gatekeepfilename);
/* no mail to moderate */
errno = 0;
log_error(LOG_ARGS, "An obstruct request was"
}
log_oper(list->dir, OPLOGFNAME, "%s obstructed %s",
fromemails->emaillist[0], param);
- myfree(param);
+ free(param);
if (unlink(gatekeepfilename) != 0) {
log_error(LOG_ARGS, "Could not unlink %s",
gatekeepfilename);
- myfree(gatekeepfilename);
+ free(gatekeepfilename);
exit(EXIT_FAILURE);
}
- myfree(gatekeepfilename);
+ free(gatekeepfilename);
break;
/* listname+help@domain.tld */
#include "log_error.h"
#include "config.h"
-#include "memory.h"
+#include "xmalloc.h"
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
void log_set_name(const char* name)
{
- if (log_name) myfree(log_name);
- log_name = mystrdup(name);
+ if (log_name) free(log_name);
+ log_name = xstrdup(name);
}
void log_free_name()
{
- myfree(log_name);
+ free(log_name);
}
void log_error(const char *file, int line, const char *errstr,
#include "log_oper.h"
#include "strgen.h"
#include "wrappers.h"
-#include "memory.h"
+#include "xmalloc.h"
int log_oper(const char *prefix, const char *basename, const char *fmt, ...)
{
statres = lstat(logfilename, &st);
if(statres < 0 && errno != ENOENT) {
log_error(LOG_ARGS, "Could not stat logfile %s", logfilename);
- myfree(logfilename);
+ free(logfilename);
return -1;
}
log_error(LOG_ARGS, "Could not rename %s,%s",
logfilename, tmp);
}
- myfree(tmp);
+ free(tmp);
}
fd = open(logfilename, O_RDWR|O_CREAT|O_APPEND|O_EXLOCK, S_IRUSR|S_IWUSR);
if(fd < 0) {
log_error(LOG_ARGS, "Could not open %s", logfilename);
- myfree(logfilename);
+ free(logfilename);
return -1;
}
log_error(LOG_ARGS, "Could not write to %s", logfilename);
close(fd);
- myfree(logfilename);
- myfree(logstr);
+ free(logfilename);
+ free(logstr);
return 0;
}
#include "mail-functions.h"
#include "wrappers.h"
#include "log_error.h"
-#include "memory.h"
+#include "xmalloc.h"
static int
write_sock(int sockfd, const char *errstr, const char *fmt, ...) {
+++ /dev/null
-/* Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk>
- * Copyright (C) 2021 Baptiste Daroussin <bapt@FreeBSD.org>
- *
- * $Id$
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-/* define _MEMORY_C so we can use the libc memory functions -- see mlmmj.h */
-#define _MEMORY_C 1
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mlmmj.h"
-#include "memory.h"
-#include "log_error.h"
-
-
-/* TODO add a debug mode with canaries and other goodies */
-
-
-void *__mymalloc(const char *file, int line, size_t size)
-{
- void *ret;
-
- ret = malloc(size);
- if (ret == NULL) {
- log_error(file, line, strerror(errno),
- "malloc(%d) failed! Bailing out!", size);
- exit(EXIT_FAILURE);
- }
-
- return ret;
-}
-
-
-void *__myrealloc(const char *file, int line, void *ptr, size_t size)
-{
- void *ret;
-
- ret = realloc(ptr, size);
- if (ret == NULL) {
- log_error(file, line, strerror(errno),
- "realloc(%p, %d) failed! Bailing out!",
- ptr, size);
- exit(EXIT_FAILURE);
- }
-
- return ret;
-}
-
-
-void __myfree(const char *file, int line, void *ptr)
-{
- free(ptr);
-}
-
-
-char *__mystrdup(const char *file, int line, const char *str)
-{
- void *ret;
-
- ret = strdup(str);
- if (ret == NULL) {
- log_error(file, line, strerror(errno),
- "strdup() failed! Bailing out!");
- exit(EXIT_FAILURE);
- }
-
- return ret;
-}
-
-char *
-__mystrndup(const char *file, int line, const char *str, size_t len)
-{
- char *s = strndup(str, len);
- if (s == NULL) {
- log_error(file, line, strerror(errno),
- "strndup() failed! Bailing out!");
- exit(EXIT_FAILURE);
- }
- return (s);
-}
-
-int
-__myasprintf(const char *file, int line, char **ret, const char *format, ...)
-{
- va_list ap;
- int i;
-
- va_start(ap, format);
- i = vasprintf(ret, format, ap);
- va_end(ap);
-
- if (i < 0 || *ret == NULL) {
- log_error(file, line, strerror(errno),
- "aspritnf() failed! Bailing out!");
- exit(EXIT_FAILURE);
- }
- return (i);
-}
#include <string.h>
#include <ctype.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "strgen.h"
#include "wrappers.h"
#include "subscriberfuncs.h"
#include "mygetline.h"
#include "prepstdreply.h"
-#include "memory.h"
#include "find_email_adr.h"
#include "gethdrline.h"
int fd;
time_t t;
- myaddr = mystrdup(addr);
+ myaddr = xstrdup(addr);
from = concatstr(6, list->name, list->delim, "bounces-probe-", myaddr, "@",
list->fqdn);
a = strrchr(myaddr, '=');
if (!a) {
- myfree(myaddr);
- myfree(from);
+ free(myaddr);
+ free(from);
log_error(LOG_ARGS, "do_probe(): malformed address");
exit(EXIT_FAILURE);
probefile = concatstr(4, list->dir, "/bounce/", addr, "-probe");
MY_ASSERT(probefile);
t = time(NULL);
- a = mymalloc(32);
+ a = xmalloc(32);
snprintf(a, 31, "%ld", (long int)t);
a[31] = '\0';
unlink(probefile);
if(dprintf(fd, "%s", a) < 0)
log_error(LOG_ARGS, "Could not write time in probe");
- myfree(probefile);
+ free(probefile);
execlp(mlmmjsend, mlmmjsend,
"-l", "5",
}
while((line = gethdrline(fd, NULL))) {
- linedup = mystrdup(line);
+ linedup = xstrdup(line);
for(i = 0; line[i]; i++)
linedup[i] = tolower(line[i]);
search = strstr(linedup, "message/delivery-status");
- myfree(linedup);
+ free(linedup);
if(search) {
indsn = 1;
- myfree(line);
+ free(line);
continue;
}
if(indsn) {
if (search) {
find_email_adr(search+1, &emails);
if(emails.emailcount > 0) {
- addr = mystrdup(emails.emaillist[0]);
+ addr = xstrdup(emails.emaillist[0]);
for(i = 0; i < emails.emailcount; i++)
- myfree(emails.emaillist[i]);
- myfree(emails.emaillist);
+ free(emails.emaillist[i]);
+ free(emails.emaillist);
}
}
- myfree(line);
+ free(line);
break;
}
}
- myfree(line);
+ free(line);
}
return addr;
bindir = mydirname(argv[0]);
mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
- myfree(bindir);
+ free(bindir);
while ((opt = getopt(argc, argv, "hdVL:a:n:m:p")) != -1) {
switch(opt) {
if(strcmp(number, "confsub") == 0) {
a = concatstr(3, list.dir, "/subconf/", address);
unlink(a);
- myfree(a);
+ free(a);
if(mailname)
unlink(mailname);
exit(EXIT_SUCCESS);
if(strcmp(number, "confunsub") == 0) {
a = concatstr(3, list.dir, "/unsubconf/", address);
unlink(a);
- myfree(a);
+ free(a);
if(mailname)
unlink(mailname);
exit(EXIT_SUCCESS);
a = concatstr(4, list.dir, "/bounce/", address, "-probe");
unlink(a);
unlink(mailname);
- myfree(a);
+ free(a);
exit(EXIT_SUCCESS);
}
address);
if(mailname)
unlink(mailname);
- myfree(bfilename);
+ free(bfilename);
exit(EXIT_SUCCESS); /* Not subbed, so exit silently */
}
if ((fd = open(bfilename, O_WRONLY|O_APPEND|O_CREAT,
S_IRUSR|S_IWUSR)) < 0) {
log_error(LOG_ARGS, "Could not open '%s'", bfilename);
- myfree(bfilename);
+ free(bfilename);
exit(EXIT_FAILURE);
}
/* int + ":" + int + " # Wed Jun 30 21:49:08 1993\n" + NUL */
len = 20 + 1 + 20 + 28 + 1;
- buf = mymalloc(len);
+ buf = xmalloc(len);
if (!buf) exit(EXIT_FAILURE);
t = time(NULL);
if(mailname) {
savename = concatstr(2, bfilename, ".lastmsg");
rename(mailname, savename);
- myfree(savename);
+ free(savename);
}
- myfree(bfilename);
+ free(bfilename);
if(dsnbounce && address)
- myfree(address);
+ free(address);
return EXIT_SUCCESS;
}
#include "log_error.h"
#include "mygetline.h"
#include "wrappers.h"
-#include "memory.h"
+#include "xmalloc.h"
#include "controls.h"
#include "send_digest.h"
#include "log_oper.h"
continue;
if(strchr(dp->d_name, '.')) {
- char *tmpname = mystrdup(dp->d_name);
+ char *tmpname = xstrdup(dp->d_name);
ch = strrchr(tmpname, '.');
MY_ASSERT(ch);
*ch = '\0';
if(errno == ENOENT)
unlinkat(list->queuefd, mailname, 0);
}
- myfree(tmpname);
+ free(tmpname);
continue;
}
- myasprintf(&fromname, "%s.mailfrom", mailname);
- myasprintf(&toname, "%s.reciptto", mailname);
- myasprintf(&reptoname, "%s.reply-to", mailname);
+ xasprintf(&fromname, "%s.mailfrom", mailname);
+ xasprintf(&toname, "%s.reciptto", mailname);
+ xasprintf(&reptoname, "%s.reply-to", mailname);
fromfd = openat(list->queuefd, fromname, O_RDONLY);
if(fromfd < 0)
unlinkat(list->queuefd, toname, 0);
unlinkat(list->queuefd, reptoname, 0);
}
- myfree(fromname);
- myfree(toname);
- myfree(reptoname);
+ free(fromname);
+ free(toname);
+ free(reptoname);
if(fromfd >= 0)
close(fromfd);
if(tofd >= 0)
from = mygetline(fromfd);
chomp(from);
close(fromfd);
- myfree(fromname);
+ free(fromname);
to = mygetline(tofd);
chomp(to);
close(tofd);
- myfree(toname);
+ free(toname);
fd = openat(list->queuefd, reptoname, O_RDONLY);
if(fd < 0) {
- myfree(reptoname);
+ free(reptoname);
repto = NULL;
} else {
repto = mygetline(fd);
chomp(repto);
close(fd);
- myfree(reptoname);
+ free(reptoname);
}
/* before we try again, check and see if it's old */
t = time(NULL);
if(t - st.st_mtime > bouncelife) {
unlinkat(list->queuefd, mailname, 0);
- myfree(from);
- myfree(to);
- myfree(repto);
+ free(from);
+ free(to);
+ free(repto);
continue;
}
if(chdir(dirname) < 0) {
log_error(LOG_ARGS, "Could not chdir(%s)", dirname);
- myfree(dirname);
+ free(dirname);
return 1;
}
if((queuedir = opendir(dirname)) == NULL) {
log_error(LOG_ARGS, "Could not opendir(%s)", dirname);
- myfree(dirname);
+ free(dirname);
return 1;
}
* yet because it's still getting sent, so just
* continue
*/
- myfree(archivefilename);
+ free(archivefilename);
/* If the list is set not to archive we want to look
* in /requeue/ for a mailfile
archivefilename = concatstr(4, list->dir, "/requeue/",
dp->d_name, "/mailfile");
if(stat(archivefilename, &st) < 0) {
- myfree(archivefilename);
+ free(archivefilename);
continue;
}
fromrequeuedir = 1;
if(stat(subfilename, &st) < 0) {
if (fromrequeuedir)
unlink(archivefilename);
- myfree(archivefilename);
- myfree(subfilename);
+ free(archivefilename);
+ free(subfilename);
continue;
}
if(rename(subfilename, subnewname) < 0) {
log_error(LOG_ARGS, "Could not rename(%s, %s)",
subfilename, subnewname);
- myfree(archivefilename);
- myfree(subfilename);
- myfree(subnewname);
+ free(archivefilename);
+ free(subfilename);
+ free(subnewname);
continue;
}
- myfree(subfilename);
+ free(subfilename);
childpid = fork();
if(childpid < 0) {
- myfree(archivefilename);
- myfree(subnewname);
+ free(archivefilename);
+ free(subnewname);
log_error(LOG_ARGS, "Could not fork");
continue;
}
if(childpid > 0) {
- myfree(archivefilename);
- myfree(subnewname);
+ free(archivefilename);
+ free(subnewname);
do /* Parent waits for the child */
pid = waitpid(childpid, &status, 0);
while(pid == -1 && errno == EINTR);
closedir(queuedir);
- myfree(dirname);
+ free(dirname);
return 0;
}
if(chdir(dirname) < 0) {
log_error(LOG_ARGS, "Could not chdir(%s)", dirname);
- myfree(dirname);
+ free(dirname);
return 1;
}
if((bouncedir = opendir(dirname)) == NULL) {
log_error(LOG_ARGS, "Could not opendir(%s)", dirname);
- myfree(dirname);
+ free(dirname);
return 1;
}
- myfree(dirname);
+ free(dirname);
while((dp = readdir(bouncedir)) != NULL) {
if((strcmp(dp->d_name, "..") == 0) ||
(strcmp(dp->d_name, ".") == 0))
continue;
- filename = mystrdup(dp->d_name);
+ filename = xstrdup(dp->d_name);
s = strrchr(filename, '-');
if(s && (strcmp(s, "-probe") == 0)) {
if(stat(filename, &st) < 0) {
log_error(LOG_ARGS, "Could not stat(%s)",
filename);
- myfree(filename);
+ free(filename);
continue;
}
probefd = open(filename, O_RDONLY);
if(probefd < 0) {
- myfree(filename);
+ free(filename);
continue;
}
probetimestr = mygetline(probefd);
if(probetimestr == NULL) {
- myfree(filename);
+ free(filename);
continue;
}
close(probefd);
chomp(probetimestr);
probetime = strtotimet(probetimestr, &errstr);
- myfree(probetimestr);
+ free(probetimestr);
t = time(NULL);
if(t - probetime > WAITPROBE) {
unlink(filename);
unlink(filename);
s = concatstr(2, filename, ".lastmsg");
unlink(s);
- myfree(s);
+ free(s);
}
}
- myfree(filename);
+ free(filename);
}
closedir(bouncedir);
if(chdir(dirname) < 0) {
log_error(LOG_ARGS, "Could not chdir(%s)", dirname);
- myfree(dirname);
+ free(dirname);
return 1;
}
if((bouncedir = opendir(dirname)) == NULL) {
log_error(LOG_ARGS, "Could not opendir(%s)", dirname);
- myfree(dirname);
+ free(dirname);
return 1;
}
- myfree(dirname);
+ free(dirname);
while((dp = readdir(bouncedir)) != NULL) {
if((strcmp(dp->d_name, "..") == 0) ||
/* Skip files which already have a probe out */
if(stat(probefile, &st) == 0) {
- myfree(probefile);
+ free(probefile);
continue;
}
- myfree(probefile);
+ free(probefile);
childpid = fork();
pid = waitpid(childpid, &status, 0);
while(pid == -1 && errno == EINTR);
} else {
- probefile = mystrdup(dp->d_name);
+ probefile = xstrdup(dp->d_name);
execlp(mlmmjbounce, mlmmjbounce,
"-L", list->dir,
"-a", probefile,
if(chdir(dirname) < 0) {
log_error(LOG_ARGS, "Could not chdir(%s)", dirname);
- myfree(dirname);
+ free(dirname);
return 1;
}
if((bouncedir = opendir(dirname)) == NULL) {
log_error(LOG_ARGS, "Could not opendir(%s)", dirname);
- myfree(dirname);
+ free(dirname);
return 1;
}
- myfree(dirname);
+ free(dirname);
bouncelife = ctrltimet(list, "bouncelife");
if (bouncelife == 0)
/* Skip files which already have a probe out */
if(stat(probefile, &st) == 0) {
- myfree(probefile);
+ free(probefile);
continue;
}
- myfree(probefile);
+ free(probefile);
/* Get the first line of the bounce file to check if it's
* been bouncing for long enough
/* End the string at the comment */
a = strchr(firstbounce, '#');
if(a == NULL) {
- myfree(firstbounce);
+ free(firstbounce);
continue;
}
*a = '\0';
- bouncedata = mystrdup(a+1); /* Save for the log */
+ bouncedata = xstrdup(a+1); /* Save for the log */
chomp(bouncedata);
a = strchr(firstbounce, ':');
if(a == NULL) {
- myfree(firstbounce);
- myfree(bouncedata);
+ free(firstbounce);
+ free(bouncedata);
continue;
}
a++; /* Increase to first digit */
bouncetime = strtotimet(a, &errstr);
- myfree(firstbounce);
+ free(firstbounce);
t = time(NULL);
if(t - bouncetime < bouncelife + WAITPROBE) {
- myfree(bouncedata);
+ free(bouncedata);
continue; /* ok, don't unsub this one */
}
/* Ok, go ahead and unsubscribe the address */
- address = mystrdup(dp->d_name);
+ address = xstrdup(dp->d_name);
a = strchr(address, '=');
if(a == NULL) { /* skip malformed */
- myfree(address);
- myfree(bouncedata);
+ free(address);
+ free(bouncedata);
continue;
}
*a = '@';
log_oper(list->dir, OPLOGFNAME, "mlmmj-maintd: %s"
" unsubscribed due to bouncing since"
" %s", address, bouncedata);
- myfree(address);
- myfree(bouncedata);
+ free(address);
+ free(bouncedata);
unlink(dp->d_name);
a = concatstr(2, dp->d_name, ".lastmsg");
unlink(a);
- myfree(a);
+ free(a);
}
closedir(bouncedir);
if (s1 && (strlen(s1) > 0)) {
log_error(LOG_ARGS, "'%s/latestdigest' contains malformed data",
list->dir);
- myfree(s1);
+ free(s1);
close(fd);
return 1;
}
indexfd = openat(list->fd, "index", O_RDONLY);
if (indexfd < 0) {
log_error(LOG_ARGS, "Could not open '%s/index'", list->dir);
- myfree(s1);
+ free(s1);
close(fd);
return 1;
}
if (!s2) {
/* If we don't have an index, no mails have been sent to the
* list, and therefore we don't need to send a digest */
- myfree(s1);
+ free(s1);
close(fd);
return 1;
}
}
}
- myfree(s1);
- myfree(s2);
+ free(s1);
+ free(s2);
close(fd);
return 0;
random = random_str();
- myasprintf(&logname, "maintdlog-%s", random);
- myfree(random);
+ xasprintf(&logname, "maintdlog-%s", random);
+ free(random);
maintdlogfd = openat(list.fd, logname, O_WRONLY|O_EXCL|O_CREAT, S_IRUSR|S_IWUSR);
if(maintdlogfd < 0) {
log_error(LOG_ARGS, "Could not open %s", logname);
- myfree(logname);
+ free(logname);
return;
}
log_error(LOG_ARGS, "Could not rename(%s/%s,%s/"MAINTD_LOGFILE")",
list.dir, logname, list.dir);
- myfree(logname);
+ free(logname);
mlmmj_list_close(&list);
}
}
bindir = mydirname(argv[0]);
- myasprintf(&mlmmjsend, "%s/mlmmj-send", bindir);
- myasprintf(&mlmmjbounce, "%s/mlmmj-bounce", bindir);
- myfree(bindir);
+ xasprintf(&mlmmjsend, "%s/mlmmj-send", bindir);
+ xasprintf(&mlmmjbounce, "%s/mlmmj-bounce", bindir);
+ free(bindir);
if(daemonize) {
if(dirlists)
if(chdir(dirlists) < 0) {
log_error(LOG_ARGS, "Could not chdir(%s).",
dirlists);
- myfree(mlmmjbounce);
- myfree(mlmmjsend);
+ free(mlmmjbounce);
+ free(mlmmjsend);
exit(EXIT_FAILURE);
}
if((dirp = opendir(dirlists)) == NULL) {
log_error(LOG_ARGS, "Could not opendir(%s).",
dirlists);
- myfree(mlmmjbounce);
- myfree(mlmmjsend);
+ free(mlmmjbounce);
+ free(mlmmjsend);
exit(EXIT_FAILURE);
}
if((strcmp(dp->d_name, "..") == 0) ||
(strcmp(dp->d_name, ".") == 0))
continue;
- myasprintf(&listiter, "%s/%s", dirlists, dp->d_name);
+ xasprintf(&listiter, "%s/%s", dirlists, dp->d_name);
do_maintenance(listiter, mlmmjsend, mlmmjbounce);
- myfree(listiter);
+ free(listiter);
}
closedir(dirp);
sleep(MAINTD_SLEEP);
}
- myfree(mlmmjbounce);
- myfree(mlmmjsend);
+ free(mlmmjbounce);
+ free(mlmmjsend);
log_free_name();
exit(EXIT_SUCCESS);
#include <libgen.h>
#include <regex.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "wrappers.h"
#include "find_email_adr.h"
#include "controls.h"
#include "prepstdreply.h"
#include "subscriberfuncs.h"
-#include "memory.h"
#include "log_oper.h"
#include "unistr.h"
#include "chomp.h"
moderatorsfilename = concatstr(2, listdir, "/control/moderators");
if((moderatorsfd = open(moderatorsfilename, O_RDONLY)) < 0) {
log_error(LOG_ARGS, "Could not open '%s'", moderatorsfilename);
- myfree(moderatorsfilename);
+ free(moderatorsfilename);
exit(EXIT_FAILURE);
}
- myfree(moderatorsfilename);
+ free(moderatorsfilename);
while((buf = mygetline(moderatorsfd))) {
chomp(buf);
foundaddr = 1;
if (!moderators) {
close(moderatorsfd);
- myfree(buf);
+ free(buf);
return foundaddr;
}
}
if (moderators) {
tmp = *moderators;
*moderators = concatstr(3, *moderators, buf, "\n");
- myfree(tmp);
+ free(tmp);
}
- myfree(buf);
+ free(buf);
}
close(moderatorsfd);
if(efromismod) mls = init_memory_lines(efromismod);
else mls = init_memory_lines(moderators);
- myfree(moderators);
+ free(moderators);
replyto = concatstr(6, list->name, list->delim, "release-", mailbasename,
"@", list->fqdn);
exit(EXIT_FAILURE);
}
- myfree(queuefilename);
+ free(queuefilename);
/* send mail to poster that the list is moderated */
if (match != not) {
if (match) {
- hdr = mystrdup(hdrs->strs[j]);
+ hdr = xstrdup(hdrs->strs[j]);
log_oper(listdir, OPLOGFNAME, "mlmmj-process: access -"
" A mail from \"%s\" with header \"%s\" was %s by"
" rule #%d \"%s\"", from, hdr, action_strs[act],
i, rule_strs->strs[i]);
- myfree(hdr);
+ free(hdr);
} else {
log_oper(listdir, OPLOGFNAME, "mlmmj-process: access -"
" A mail from \"%s\" was %s by rule #%d \"%s\""
if (recipextra) {
len = atsign - delim;
- *recipextra = (char *)mymalloc(len + 1);
+ *recipextra = (char *)xmalloc(len + 1);
strncpy(*recipextra, delim, len);
(*recipextra)[len] = '\0';
}
close_text(txt);
unlink(donemailname);
unlink(mailfile);
- myfree(donemailname);
- myfree(causestr);
+ free(donemailname);
+ free(causestr);
memset(&mh, 0, sizeof(mh));
mh.to = posteraddr;
mh.from = fromaddr;
mlmmjsub = concatstr(2, bindir, "/mlmmj-sub");
mlmmjunsub = concatstr(2, bindir, "/mlmmj-unsub");
mlmmjbounce = concatstr(2, bindir, "/mlmmj-bounce");
- myfree(bindir);
+ free(bindir);
while ((opt = getopt(argc, argv, "hVPm:L:")) != -1) {
switch(opt) {
}
do {
- myfree(donemailname);
- myfree(randomstr);
+ free(donemailname);
+ free(randomstr);
randomstr = random_str();
donemailname = concatstr(3, list.dir, "/queue/", randomstr);
if(donemailfd < 0) {
log_error(LOG_ARGS, "could not create %s", donemailname);
- myfree(donemailname);
+ free(donemailname);
exit(EXIT_FAILURE);
}
#if 0
#endif
if((rawmailfd = open(mailfile, O_RDONLY)) < 0) {
unlink(donemailname);
- myfree(donemailname);
+ free(donemailname);
log_error(LOG_ARGS, "could not open() input mail file");
exit(EXIT_FAILURE);
}
* customheaders file might not exist */
headerfilename = concatstr(2, list.dir, "/control/customheaders");
hdrfd = open(headerfilename, O_RDONLY);
- myfree(headerfilename);
+ free(headerfilename);
/* footfd is checked in do_all_the_voodoo_here(), see above */
footerfilename = concatstr(2, list.dir, "/control/footer");
footfd = open(footerfilename, O_RDONLY);
- myfree(footerfilename);
+ free(footerfilename);
delheaders = ctrlvalues(&list, "delheaders");
if(delheaders == NULL) {
- delheaders = mymalloc(sizeof(struct strlist));
+ delheaders = xmalloc(sizeof(struct strlist));
delheaders->count = 0;
delheaders->strs = NULL;
}
- delheaders->strs = myrealloc(delheaders->strs,
+ delheaders->strs = xrealloc(delheaders->strs,
(delheaders->count+2) * sizeof(char *));
- delheaders->strs[delheaders->count++] = mystrdup("From ");
- delheaders->strs[delheaders->count++] = mystrdup("Return-Path:");
+ delheaders->strs[delheaders->count++] = xstrdup("From ");
+ delheaders->strs[delheaders->count++] = xstrdup("Return-Path:");
subjectprefix = ctrlvalue(&list, "prefix");
}
for(i = 0; i < delheaders->count; i++)
- myfree(delheaders->strs[i]);
- myfree(delheaders->strs);
+ free(delheaders->strs[i]);
+ free(delheaders->strs);
close(rawmailfd);
close(donemailfd);
/* address extension (the "foo" part of "user+foo@domain.tld") */
if((envstr = getenv("DEFAULT")) != NULL) {
/* qmail */
- recipextra = mystrdup(envstr);
+ recipextra = xstrdup(envstr);
} else if((envstr = getenv("EXTENSION")) != NULL) {
/* postfix */
- recipextra = mystrdup(envstr);
+ recipextra = xstrdup(envstr);
} else if((envstr = getenv("LOCAL_PART_SUFFIX")) != NULL) {
/* exim */
if (strncmp(envstr, list.delim, strlen(list.delim)) == 0) {
- recipextra = mystrdup(envstr + strlen(list.delim));
+ recipextra = xstrdup(envstr + strlen(list.delim));
} else {
- recipextra = mystrdup(envstr);
+ recipextra = xstrdup(envstr);
}
} else {
findaddress = 1;
}
}
if (listaddrs) for(i = 0; i < listaddrs->count; i++)
- myfree(listaddrs->strs[i]);
+ free(listaddrs->strs[i]);
if(recipextra && (strlen(recipextra) == 0)) {
- myfree(recipextra);
+ free(recipextra);
recipextra = NULL;
}
i, fromemails.emaillist[i]);
rename(mailfile, discardname);
unlink(donemailname);
- myfree(donemailname);
- myfree(discardname);
- myfree(randomstr);
+ free(donemailname);
+ free(discardname);
+ free(randomstr);
/* TODO: free emailstructs */
exit(EXIT_SUCCESS);
}
/* envelope from */
if((envstr = getenv("SENDER")) != NULL) {
/* qmail, postfix, exim */
- efrom = mystrdup(envstr);
+ efrom = xstrdup(envstr);
} else if(rpemails.emailcount >= 1) {
/* the (first) Return-Path: header */
- efrom = mystrdup(rpemails.emaillist[0]);
+ efrom = xstrdup(rpemails.emaillist[0]);
} else {
- efrom = mystrdup("");
+ efrom = xstrdup("");
}
/* Subject: */
if (readhdrs[5].valuecount)
subject = unistr_header_to_utf8(readhdrs[5].values[0]);
- if (!subject) subject = mystrdup("");
+ if (!subject) subject = xstrdup("");
if(recipextra) {
owner = concatstr(2, list.dir, "/control/owner");
/* strip envelope from before resending */
delheaders->count = 0;
delheaders->strs = NULL;
- delheaders->strs = myrealloc(delheaders->strs,
+ delheaders->strs = xrealloc(delheaders->strs,
2 * sizeof(char *));
delheaders->strs[delheaders->count++] =
- mystrdup("From ");
+ xstrdup("From ");
delheaders->strs[delheaders->count++] =
- mystrdup("Return-Path:");
+ xstrdup("Return-Path:");
if((rawmailfd = open(mailfile, O_RDONLY)) < 0) {
log_error(LOG_ARGS, "could not open() "
"input mail file");
exit(EXIT_FAILURE);
}
for(i = 0; i < delheaders->count; i++)
- myfree(delheaders->strs[i]);
- myfree(delheaders->strs);
+ free(delheaders->strs[i]);
+ free(delheaders->strs);
close(rawmailfd);
close(donemailfd);
unlink(mailfile);
donemailname, (st.st_size - maxmailsize));
unlink(donemailname);
unlink(mailfile);
- myfree(donemailname);
- myfree(maxmailsizestr);
+ free(donemailname);
+ free(maxmailsizestr);
exit(EXIT_SUCCESS);
}
send_denymail(&list, "maxmailsize", "maxmailsize",
}
}
- myfree(delheaders);
+ free(delheaders);
if(strcmp(efrom, "") == 0) { /* don't send mails with <> in From
to the list */
" from address", mailfile);
rename(mailfile, discardname);
unlink(donemailname);
- myfree(donemailname);
- myfree(discardname);
- myfree(randomstr);
+ free(donemailname);
+ free(discardname);
+ free(randomstr);
/* TODO: free emailstructs */
exit(EXIT_SUCCESS);
}
" notoccdenymails was set",
mailfile);
unlink(donemailname);
- myfree(donemailname);
+ free(donemailname);
exit(EXIT_SUCCESS);
}
send_denymail(&list, "tocc", "notintocc", NULL,
" was set",
mailfile);
unlink(donemailname);
- myfree(donemailname);
+ free(donemailname);
exit(EXIT_SUCCESS);
}
send_denymail(&list, "access", "access",
} else if (accret == DISCARD) {
discardname = concatstr(3, list.dir,
"/queue/discarded/", randomstr);
- myfree(randomstr);
+ free(randomstr);
if(rename(donemailname, discardname) < 0) {
log_error(LOG_ARGS, "could not rename(%s,%s)",
donemailname, discardname);
- myfree(donemailname);
- myfree(discardname);
+ free(donemailname);
+ free(discardname);
exit(EXIT_FAILURE);
}
- myfree(donemailname);
- myfree(discardname);
+ free(donemailname);
+ free(discardname);
exit(EXIT_SUCCESS);
} else if (accret == SEND) {
send = 1;
" From: was the list address",
mailfile);
unlink(donemailname);
- myfree(donemailname);
+ free(donemailname);
exit(EXIT_SUCCESS);
}
if(subonlypost) {
" no{sub|mod}onlydenymails was set",
mailfile);
unlink(donemailname);
- myfree(donemailname);
+ free(donemailname);
exit(EXIT_SUCCESS);
}
if (subonlypost) {
if(moderated) {
mqueuename = concatstr(3, list.dir, "/moderation/",
randomstr);
- myfree(randomstr);
+ free(randomstr);
if(rename(donemailname, mqueuename) < 0) {
log_error(LOG_ARGS, "could not rename(%s,%s)",
donemailname, mqueuename);
- myfree(donemailname);
- myfree(mqueuename);
+ free(donemailname);
+ free(mqueuename);
exit(EXIT_FAILURE);
}
- myfree(donemailname);
+ free(donemailname);
if (notmetoo) {
omitfilename = concatstr(2, mqueuename, ".omit");
omitfd = open(omitfilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
if (omitfd < 0) {
log_error(LOG_ARGS, "could not open %s",
omitfilename);
- myfree(mqueuename);
- myfree(omitfilename);
+ free(mqueuename);
+ free(omitfilename);
exit(EXIT_FAILURE);
}
- myfree(omitfilename);
+ free(omitfilename);
if(dprintf(omitfd, "%s", posteraddr) < 0) {
log_error(LOG_ARGS,
"could not write omit file");
- myfree(mqueuename);
+ free(mqueuename);
exit(EXIT_FAILURE);
}
fsync(omitfd);
return EXIT_SUCCESS;
}
- myfree(randomstr);
+ free(randomstr);
if(noprocess) {
- myfree(donemailname);
- /* XXX: toemails and ccemails etc. have to be myfree() */
+ free(donemailname);
+ /* XXX: toemails and ccemails etc. have to be free() */
exit(EXIT_SUCCESS);
}
#include "mygetline.h"
#include "strgen.h"
#include "log_error.h"
-#include "memory.h"
+#include "xmalloc.h"
extern char *optarg;
bindir = mydirname(argv[0]);
mlmmjprocess = concatstr(2, bindir, "/mlmmj-process");
- myfree(bindir);
+ free(bindir);
while ((opt = getopt(argc, argv, "hPVL:s:e:F")) != -1) {
switch(opt) {
}
infilename = concatstr(3, listdir, "/incoming/", randomstr);
- myfree(randomstr);
+ free(randomstr);
fd = open(infilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
while(fd < 0 && errno == EEXIST) {
- myfree(infilename);
+ free(infilename);
randomstr = random_str();
infilename = concatstr(3, listdir, "/incoming/", randomstr);
- myfree(randomstr);
+ free(randomstr);
fd = open(infilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
}
if(fd < 0) {
log_error(LOG_ARGS, "could not create mail file in "
"%s/incoming directory", listdir);
- myfree(infilename);
+ free(infilename);
exit(EXIT_FAILURE);
}
close(fd);
if(noprocess) {
- myfree(infilename);
+ free(infilename);
exit(EXIT_SUCCESS);
}
#include <arpa/inet.h>
#include <signal.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "mlmmj-send.h"
#include "mail-functions.h"
#include "log_error.h"
#include "mygetline.h"
#include "wrappers.h"
-#include "memory.h"
#include "controls.h"
#include "getaddrsfromfd.h"
#include "utils.h"
char *myfilename, *indexstr, *ret;
size_t len;
- myfilename = mystrdup(filename);
+ myfilename = xstrdup(filename);
if (!myfilename) {
return NULL;
}
indexstr = myfilename;
}
- ret = mystrdup(indexstr);
- myfree(myfilename);
+ ret = xstrdup(indexstr);
+ free(myfilename);
return ret;
}
const char *staticbounceaddr_domain;
size_t len;
- mymailfilename = mystrdup(mailfilename);
+ mymailfilename = xstrdup(mailfilename);
if (!mymailfilename) {
return NULL;
}
indexstr = get_index_from_filename(mymailfilename);
if (!indexstr) {
- myfree(mymailfilename);
+ free(mymailfilename);
return NULL;
}
- myrecipient = mystrdup(recipient);
+ myrecipient = xstrdup(recipient);
if (!myrecipient) {
- myfree(mymailfilename);
+ free(mymailfilename);
return NULL;
}
a = strchr(myrecipient, '@');
if (a)
*a = '=';
- mylistadr = mystrdup(list->addr);
+ mylistadr = xstrdup(list->addr);
if (!mylistadr) {
- myfree(mymailfilename);
- myfree(myrecipient);
+ free(mymailfilename);
+ free(myrecipient);
return NULL;
}
listdomain = strchr(mylistadr, '@');
if (!listdomain) {
- myfree(mymailfilename);
- myfree(myrecipient);
- myfree(mylistadr);
+ free(mymailfilename);
+ free(myrecipient);
+ free(mylistadr);
return NULL;
}
*listdomain++ = '\0';
staticbounceaddr_domain = NULL;
}
- bounceaddr = mymalloc(len);
+ bounceaddr = xmalloc(len);
if (!bounceaddr) {
- myfree(staticbounceaddr);
- myfree(staticbounceaddr_localpart);
- myfree(myrecipient);
- myfree(mylistadr);
+ free(staticbounceaddr);
+ free(staticbounceaddr_localpart);
+ free(myrecipient);
+ free(mylistadr);
return NULL;
}
staticbounceaddr_localpart, list->delim, mylistadr,
indexstr, myrecipient, staticbounceaddr_domain);
- myfree(staticbounceaddr);
- myfree(staticbounceaddr_localpart);
+ free(staticbounceaddr);
+ free(staticbounceaddr_localpart);
} else {
snprintf(bounceaddr, len, "%s%sbounces-%s-%s@%s", mylistadr, list->delim,
indexstr, myrecipient, listdomain);
}
- myfree(myrecipient);
- myfree(mylistadr);
- myfree(indexstr);
- myfree(mymailfilename);
+ free(myrecipient);
+ free(mylistadr);
+ free(indexstr);
+ free(mymailfilename);
return bounceaddr;
}
if(reply) {
log_error(LOG_ARGS, "Error in MAIL FROM. Reply = [%s]",
reply);
- myfree(reply);
+ free(reply);
write_rset(sockfd);
reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET);
- if (reply2 != NULL) myfree(reply2);
+ if (reply2 != NULL) free(reply2);
return MLMMJ_FROM;
}
for(i = 0; i < addrs->count; i++) {
if(reply) {
log_error(LOG_ARGS, "Error in RCPT TO. Reply = [%s]",
reply);
- myfree(reply);
+ free(reply);
return MLMMJ_RCPTTO;
}
}
reply = checkwait_smtpreply(sockfd, MLMMJ_DATA);
if(reply) {
log_error(LOG_ARGS, "Error with DATA. Reply = [%s]", reply);
- myfree(reply);
+ free(reply);
write_rset(sockfd);
reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET);
- if (reply2 != NULL) myfree(reply2);
+ if (reply2 != NULL) free(reply2);
return MLMMJ_DATA;
}
log_error(LOG_ARGS, "Mailserver did not ack end of mail.\n"
"<CR><LF>.<CR><LF> was written, to no"
"avail. Reply = [%s]", reply);
- myfree(reply);
+ free(reply);
write_rset(sockfd);
reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET);
- if (reply2 != NULL) myfree(reply2);
+ if (reply2 != NULL) free(reply2);
return MLMMJ_DOT;
}
mlmmjbounce, hdrs, hdrslen,
body, bodylen);
for(i = 0; i < stl.count; i++)
- myfree(stl.strs[i]);
+ free(stl.strs[i]);
if(ret < 0)
return ret;
stl.count = 0;
mailsize, &stl, archivefilename, list,
mlmmjbounce, hdrs, hdrslen, body, bodylen);
for(i = 0; i < stl.count; i++)
- myfree(stl.strs[i]);
+ free(stl.strs[i]);
stl.count = 0;
return ret;
}
log_error(LOG_ARGS, "Could not mkdir(%s) for "
"requeueing. Mail cannot "
"be requeued.", dirname);
- myfree(dirname);
+ free(dirname);
return -1;
}
addrfilename = concatstr(2, dirname, "/subscribers");
- myfree(dirname);
+ free(dirname);
addrfd = open(addrfilename, O_WRONLY|O_CREAT|O_APPEND,
S_IRUSR|S_IWUSR);
if(addrfd < 0) {
log_error(LOG_ARGS, "Could not open %s",
addrfilename);
- myfree(addrfilename);
+ free(addrfilename);
return -1;
} else {
/* Dump the remaining addresses. We dump the remaining before
return -1;
}
}
- myfree(addrfilename);
+ free(addrfilename);
close(addrfd);
return 0;
"shutting down.");
index = get_index_from_filename(archivefilename);
status = requeuemail(list->dir, index, addrs, i);
- myfree(index);
+ free(index);
return status;
}
if(from) {
res = send_mail(sockfd, bounceaddr, addr, replyto,
mailmap, mailsize, list, mlmmjbounce,
hdrs, hdrslen, body, bodylen, addtohdr, prepmailinmem);
- myfree(bounceaddr);
+ free(bounceaddr);
}
if(res && list->addr && archivefilename) {
/* we failed, so save the addresses and bail */
index = get_index_from_filename(archivefilename);
status = requeuemail(list->dir, index, addrs, i);
- myfree(index);
+ free(index);
return status;
}
}
bindir = mydirname(argv[0]);
mlmmjbounce = concatstr(2, bindir, "/mlmmj-bounce");
- myfree(bindir);
+ free(bindir);
/* install signal handler for SIGTERM */
sigact.sa_handler = catch_sig_term;
}
if(!listctrl)
- listctrl = mystrdup("0");
+ listctrl = xstrdup("0");
/* get the list address */
verp = ctrlvalue(&list, "verp");
if(verp == NULL)
if(statctrl(&list, "verp") == 1)
- verp = mystrdup("");
+ verp = xstrdup("");
maxverprecips = ctrlint(&list, "maxverprecips");
if(maxverprecips <= 0)
&bodylen);
if(body == NULL) {
log_error(LOG_ARGS, "Could not prepare mailbody");
- myfree(hdrs);
+ free(hdrs);
exit(EXIT_FAILURE);
}
}
if((subfd = open(subfilename, O_RDONLY)) < 0) {
log_error(LOG_ARGS, "Could not open '%s':",
subfilename);
- myfree(hdrs);
- myfree(body);
- myfree(subfilename);
+ free(hdrs);
+ free(body);
+ free(subfilename);
/* No moderators is no error. Could be the sysadmin
* likes to do it manually.
*/
if((subfd = open(subfilename, O_RDONLY)) < 0) {
log_error(LOG_ARGS, "Could not open '%s':",
subfilename);
- myfree(hdrs);
- myfree(body);
+ free(hdrs);
+ free(body);
exit(EXIT_FAILURE);
}
break;
case '6':
archive = 0;
deletewhensent = 0;
- archivefilename = mystrdup(mailfilename);
+ archivefilename = xstrdup(mailfilename);
bounceaddr = bounce_from_adr(to_addr, archivefilename, &list);
break;
default: /* normal list mail -- now handled when forking */
if(archive) {
mindex = incindexfile(&list);
len = strlen(list.dir) + 9 + 20;
- archivefilename = mymalloc(len);
+ archivefilename = xmalloc(len);
snprintf(archivefilename, len, "%s/archive/%d", list.dir,
mindex);
}
* if it already exists. In that case continue */
tmpstr = concatstr(2, mailfilename, ".mailfrom");
if(stat(tmpstr, &st) == 0) {
- myfree(tmpstr);
+ free(tmpstr);
break;
}
tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR);
- myfree(tmpstr);
+ free(tmpstr);
if(tmpfd >= 0) {
dprintf(tmpfd, "%s", bounceaddr);
fsync(tmpfd);
close(tmpfd);
tmpstr = concatstr(2, mailfilename, ".reciptto");
if(stat(tmpstr, &st) == 0) {
- myfree(tmpstr);
+ free(tmpstr);
break;
}
tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR);
- myfree(tmpstr);
+ free(tmpstr);
if(tmpfd >= 0) {
dprintf(tmpfd, "%s", to_addr);
fsync(tmpfd);
tmpstr = concatstr(2, mailfilename,
".reply-to");
if(stat(tmpstr, &st) == 0) {
- myfree(tmpstr);
+ free(tmpstr);
break;
}
tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR);
- myfree(tmpstr);
+ free(tmpstr);
if(tmpfd >= 0) {
dprintf(tmpfd, "%s", replyto);
fsync(tmpfd);
close(sockfd);
sockfd = -1;
/* error, so remove the probefile */
- tmpstr = mystrdup(to_addr);
+ tmpstr = xstrdup(to_addr);
a = strchr(tmpstr, '@');
MY_ASSERT(a);
*a = '=';
probefile = concatstr(4, list.dir, "/bounce/", tmpstr,
"-probe");
unlink(probefile);
- myfree(probefile);
- myfree(tmpstr);
+ free(probefile);
+ free(tmpstr);
} else {
endsmtp(&sockfd);
}
if((subddir = opendir(subddirname)) == NULL) {
log_error(LOG_ARGS, "Could not opendir(%s)",
subddirname);
- myfree(subddirname);
- myfree(hdrs);
- myfree(body);
+ free(subddirname);
+ free(hdrs);
+ free(body);
exit(EXIT_FAILURE);
}
verp = NULL;
if(verp && (strcmp(verp, "postfix") == 0)) {
- myfree(verp);
- verp = mystrdup("XVERP=-=");
+ free(verp);
+ verp = xstrdup("XVERP=-=");
}
if(addtohdr && verp) {
"Mailserver did not "
"accept VERP MAIL FROM. "
"Not sending with VERP.");
- myfree(reply);
+ free(reply);
verp = NULL;
}
}
if((subfd = open(subfilename, O_RDONLY)) < 0) {
log_error(LOG_ARGS, "Could not open '%s'",
subfilename);
- myfree(subfilename);
+ free(subfilename);
continue;
}
do {
while(i < stl.count) {
if(strcmp(stl.strs[i], omit)
== 0) {
- myfree(stl.strs[i]);
+ free(stl.strs[i]);
stl.count--;
while (i < stl.count) {
stl.strs[i] =
endsmtp(&sockfd);
}
for(i = 0; i < stl.count; i++)
- myfree(stl.strs[i]);
+ free(stl.strs[i]);
stl.count = 0;
}
} while(res > 0);
- myfree(subfilename);
+ free(subfilename);
close(subfd);
}
endsmtp(&sockfd);
}
for(i = 0; i < stl.count; i++)
- myfree(stl.strs[i]);
+ free(stl.strs[i]);
stl.count = 0;
}
- myfree(stl.strs);
- myfree(verpfrom);
+ free(stl.strs);
+ free(verpfrom);
closedir(subddir);
- myfree(subddirname);
+ free(subddirname);
break;
}
- myfree(hdrs);
- myfree(body);
- myfree(mlmmjbounce);
+ free(hdrs);
+ free(body);
+ free(mlmmjbounce);
munmap(mailmap, st.st_size);
close(mailfd);
- myfree(verp);
- myfree(smtphelo);
+ free(verp);
+ free(smtphelo);
if(archive) {
if(!ctrlarchive) {
}
} else {
len = strlen(list.dir) + 9 + 20 + 9;
- requeuefilename = mymalloc(len);
+ requeuefilename = xmalloc(len);
snprintf(requeuefilename, len, "%s/requeue/%d",
list.dir, mindex);
if(stat(requeuefilename, &st) < 0) {
requeuefilename);
}
}
- myfree(requeuefilename);
+ free(requeuefilename);
}
- myfree(archivefilename);
+ free(archivefilename);
} else if(deletewhensent)
unlink(mailfilename);
#include "mygetline.h"
#include "controls.h"
#include "prepstdreply.h"
-#include "memory.h"
+#include "xmalloc.h"
#include "chomp.h"
#include "send_mails.h"
modetype = "SUB_BOTH";
break;
}
- myasprintf(&str, "%s\n%s\n", subaddr, modetype);
+ xasprintf(&str, "%s\n%s\n", subaddr, modetype);
for (;;) {
cookie = random_str();
- myasprintf(&modfilename, "%s/moderation/subscribe/%s",
+ xasprintf(&modfilename, "%s/moderation/subscribe/%s",
list->dir, cookie);
fd = open(modfilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
if (fd < 0) {
if (errno == EEXIST) {
- myfree(cookie);
- myfree(modfilename);
+ free(cookie);
+ free(modfilename);
continue;
}
log_error(LOG_ARGS, "could not create %s"
close(fd);
- myfree(str);
+ free(str);
submods = ctrlvalues(list, "submod");
- myasprintf(&mods, "%s/control/submod", list->dir);
+ xasprintf(&mods, "%s/control/submod", list->dir);
/* check to see if there's adresses in the submod control file */
for(i = 0; i < submods->count; i++)
if(a == NULL) {
/* free the submods struct from above */
for(i = 0; i < submods->count; i++)
- myfree(submods->strs[i]);
- myfree(submods->strs);
- myfree(submods);
+ free(submods->strs[i]);
+ free(submods->strs);
+ free(submods);
submods = ctrlvalues(list, "owner");
- myfree(mods);
- myasprintf(&mods, "%s/control/owner", list->dir);
+ free(mods);
+ xasprintf(&mods, "%s/control/owner", list->dir);
}
- myasprintf(&from, "%s%sowner@%s", list->name, list->delim, list->fqdn);
- myasprintf(&to, "%s-moderators@%s", list->name, list->fqdn);
- myasprintf(&replyto, "%s%spermit-%s@%s", list->name, list->delim,
+ xasprintf(&from, "%s%sowner@%s", list->name, list->delim, list->fqdn);
+ xasprintf(&to, "%s-moderators@%s", list->name, list->fqdn);
+ xasprintf(&replyto, "%s%spermit-%s@%s", list->name, list->delim,
cookie, list->fqdn);
- myasprintf(&obstruct, "%s%sobstruct-%s@%s", list->name, list->delim,
+ xasprintf(&obstruct, "%s%sobstruct-%s@%s", list->name, list->delim,
cookie, list->fqdn);
- myfree(cookie);
+ free(cookie);
for(i = 0; i < submods->count; i++) {
printf("%s", submods->strs[i]);
str = moderators;
moderators = concatstr(3, moderators, submods->strs[i], "\n");
- myfree(str);
+ free(str);
}
mls = init_memory_lines(moderators);
- myfree(moderators);
+ free(moderators);
txt = open_text(list,
"gatekeep", "sub",
exit(EXIT_FAILURE);
}
- myfree(to);
- myfree(replyto);
+ free(to);
+ free(replyto);
/* send mail to requester that the list is submod'ed */
- myasprintf(&from, "%s%sbounces-help@%s", list->name, list->delim,
+ xasprintf(&from, "%s%sbounces-help@%s", list->name, list->delim,
list->fqdn);
txt = open_text(list,
if (strncmp(modstr, "subscribe", 9) == 0)
modstr += 9;
- myasprintf(&modfilename, "%s/moderation/subscribe/%s", listdir, modstr);
+ xasprintf(&modfilename, "%s/moderation/subscribe/%s", listdir, modstr);
fd = open(modfilename, O_RDONLY);
if(fd < 0) {
modfilename);
freedone:
- myfree(readtype);
+ free(readtype);
unlink(modfilename);
- myfree(modfilename);
+ free(modfilename);
}
static void confirm_sub(struct mlmmj_list *list, const char *subaddr,
text *txt;
char *queuefilename, *fromaddr, *listtext;
- myasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
+ xasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
list->fqdn);
switch(typesub) {
default:
case SUB_NORMAL:
- listtext = mystrdup("sub-ok");
+ listtext = xstrdup("sub-ok");
break;
case SUB_DIGEST:
- listtext = mystrdup("sub-ok-digest");
+ listtext = xstrdup("sub-ok-digest");
break;
case SUB_NOMAIL:
- listtext = mystrdup("sub-ok-nomail");
+ listtext = xstrdup("sub-ok-nomail");
break;
case SUB_BOTH:
/* No legacy list text as feature didn't exist. */
- listtext = mystrdup("sub-ok");
+ listtext = xstrdup("sub-ok");
break;
}
txt = open_text(list, "finish", "sub",
subreason_strs[reasonsub], subtype_strs[typesub],
listtext);
- myfree(listtext);
+ free(listtext);
MY_ASSERT(txt);
register_unformatted(txt, "subaddr", subaddr);
queuefilename = prepstdreply(txt, list, "$helpaddr$", subaddr, NULL, true);
text *txt;
char *queuefilename = NULL, *listtext = NULL;
- myasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
+ xasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
list->fqdn);
- myasprintf(&tostr, "%s%sowner@%s", list->name, list->delim,
+ xasprintf(&tostr, "%s%sowner@%s", list->name, list->delim,
list->fqdn);
switch(typesub) {
default:
case SUB_NORMAL:
- listtext = mystrdup("notifysub");
+ listtext = xstrdup("notifysub");
break;
case SUB_DIGEST:
- listtext = mystrdup("notifysub-digest");
+ listtext = xstrdup("notifysub-digest");
break;
case SUB_NOMAIL:
- listtext = mystrdup("notifysub-nomail");
+ listtext = xstrdup("notifysub-nomail");
break;
case SUB_BOTH:
/* No legacy list text as feature didn't exist. */
- listtext = mystrdup("notifysub");
+ listtext = xstrdup("notifysub");
break;
}
txt = open_text(list, "notify", "sub",
subreason_strs[reasonsub], subtype_strs[typesub],
listtext);
- myfree(listtext);
+ free(listtext);
MY_ASSERT(txt);
register_unformatted(txt, "subaddr", subaddr);
register_unformatted(txt, "newsub", subaddr); /* DEPRECATED */
char *randomstr = NULL, *tmpstr;
do {
- myfree(confirmfilename);
- myfree(randomstr);
+ free(confirmfilename);
+ free(randomstr);
randomstr = random_plus_addr(subaddr);
- myasprintf(&confirmfilename, "%s/subconf/%s", list->dir,
+ xasprintf(&confirmfilename, "%s/subconf/%s", list->dir,
randomstr);
subconffd = open(confirmfilename, O_RDWR|O_CREAT|O_EXCL,
if(subconffd < 0) {
log_error(LOG_ARGS, "Could not open '%s'", confirmfilename);
- myfree(confirmfilename);
- myfree(randomstr);
+ free(confirmfilename);
+ free(randomstr);
exit(EXIT_FAILURE);
}
- myfree(confirmfilename);
+ free(confirmfilename);
if(dprintf(subconffd, "%s", subaddr) < 0) {
log_error(LOG_ARGS, "Could not write to subconffd");
- myfree(confirmfilename);
- myfree(randomstr);
+ free(confirmfilename);
+ free(randomstr);
exit(EXIT_FAILURE);
}
close(subconffd);
- myasprintf(&fromaddr, "%s%sbounces-confsub-%s@%s", list->name,
+ xasprintf(&fromaddr, "%s%sbounces-confsub-%s@%s", list->name,
list->delim, randomstr, list->fqdn);
switch(typesub) {
default:
case SUB_NORMAL:
- listtext = mystrdup("sub-confirm");
- tmpstr = mystrdup("confsub-");
+ listtext = xstrdup("sub-confirm");
+ tmpstr = xstrdup("confsub-");
break;
case SUB_DIGEST:
- listtext = mystrdup("sub-confirm-digest");
- tmpstr = mystrdup("confsub-digest-");
+ listtext = xstrdup("sub-confirm-digest");
+ tmpstr = xstrdup("confsub-digest-");
break;
case SUB_NOMAIL:
- listtext = mystrdup("sub-confirm-nomail");
- tmpstr = mystrdup("confsub-nomail-");
+ listtext = xstrdup("sub-confirm-nomail");
+ tmpstr = xstrdup("confsub-nomail-");
break;
case SUB_BOTH:
/* No legacy list text as feature didn't exist. */
- listtext = mystrdup("sub-confirm");
- tmpstr = mystrdup("confsub-both-");
+ listtext = xstrdup("sub-confirm");
+ tmpstr = xstrdup("confsub-both-");
break;
}
- myasprintf(&confirmaddr, "%s%s%s%s@%s", list->name, list->delim, tmpstr,
+ xasprintf(&confirmaddr, "%s%s%s%s@%s", list->name, list->delim, tmpstr,
randomstr, list->fqdn);
- myfree(randomstr);
- myfree(tmpstr);
+ free(randomstr);
+ free(tmpstr);
txt = open_text(list, "confirm", "sub",
subreason_strs[reasonsub], subtype_strs[typesub],
listtext);
- myfree(listtext);
+ free(listtext);
MY_ASSERT(txt);
register_unformatted(txt, "subaddr", subaddr);
register_unformatted(txt, "confaddr", confirmaddr); /* DEPRECATED */
text *txt;
char *queuefilename, *fromaddr;
- myasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
+ xasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
list->fqdn);
txt = open_text(list,
err(EXIT_FAILURE, "Error opening %s/%s/%s", list->dir, subdir, chstr);
}
- myasprintf(&sublockname, ".%s.lock", chstr);
+ xasprintf(&sublockname, ".%s.lock", chstr);
sublockfd = openat(subdirfd, sublockname, O_RDWR | O_CREAT | O_EXLOCK, S_IRUSR | S_IWUSR);
if(sublockfd < 0) {
log_error(LOG_ARGS, "Error opening lock file %s%s%s", list->dir,
subdir, sublockname);
- myfree(sublockname);
+ free(sublockname);
exit(EXIT_FAILURE);
}
S_IRUSR|S_IWUSR|groupwritable);
if(subfilefd == -1) {
log_error(LOG_ARGS, "Could not open '%s/%s/%s'", list->dir, chstr);
- myfree(sublockname);
+ free(sublockname);
exit(EXIT_FAILURE);
}
close(subfilefd);
close(sublockfd);
unlinkat(subdirfd, sublockname, 0);
- myfree(sublockname);
+ free(sublockname);
}
int main(int argc, char **argv)
log_set_name(argv[0]);
bindir = mydirname(argv[0]);
- myasprintf(&mlmmjsend, "%s/mlmmj-send", bindir);
- myfree(bindir);
+ xasprintf(&mlmmjsend, "%s/mlmmj-send", bindir);
+ free(bindir);
while ((opt = getopt(argc, argv, "hbcCdfm:nsVUL:a:qrR")) != -1) {
switch(opt) {
if (notifysub)
notify_sub(&list, address, typesub, reasonsub);
- myfree(address);
+ free(address);
mlmmj_list_close(&list);
return EXIT_SUCCESS;
#include "subscriberfuncs.h"
#include "strgen.h"
#include "log_error.h"
-#include "memory.h"
+#include "xmalloc.h"
#include "controls.h"
#include "prepstdreply.h"
#include "send_mails.h"
text *txt;
char *queuefilename, *fromaddr, *listtext;
- myasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim, list->fqdn);
+ xasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim, list->fqdn);
switch(typesub) {
default:
case SUB_NORMAL:
- listtext = mystrdup("unsub-ok");
+ listtext = xstrdup("unsub-ok");
break;
case SUB_DIGEST:
- listtext = mystrdup("unsub-ok-digest");
+ listtext = xstrdup("unsub-ok-digest");
break;
case SUB_NOMAIL:
- listtext = mystrdup("unsub-ok-nomail");
+ listtext = xstrdup("unsub-ok-nomail");
break;
}
txt = open_text(list, "finish", "unsub",
subreason_strs[reasonsub], subtype_strs[typesub],
listtext);
- myfree(listtext);
+ free(listtext);
MY_ASSERT(txt);
register_unformatted(txt, "subaddr", subaddr);
queuefilename = prepstdreply(txt, list, "$helpaddr$", subaddr, NULL, false);
char *queuefilename = NULL;
const char *listtext;
- myasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
+ xasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
list->fqdn);
- myasprintf(&tostr, "%s%sowner@%s", list->name, list->delim, list->fqdn);
+ xasprintf(&tostr, "%s%sowner@%s", list->name, list->delim, list->fqdn);
switch(typesub) {
default:
int subconffd;
do {
- myfree(confirmfilename);
- myfree(randomstr);
+ free(confirmfilename);
+ free(randomstr);
randomstr = random_plus_addr(subaddr);
- myasprintf(&confirmfilename, "%s/ubsubconf/%s", list->dir, randomstr);
+ xasprintf(&confirmfilename, "%s/ubsubconf/%s", list->dir, randomstr);
subconffd = open(confirmfilename, O_RDWR|O_CREAT|O_EXLOCK,
S_IRUSR|S_IWUSR);
if(subconffd < 0) {
log_error(LOG_ARGS, "Could not open '%s'", confirmfilename);
- myfree(randomstr);
- myfree(confirmfilename);
+ free(randomstr);
+ free(confirmfilename);
exit(EXIT_FAILURE);
}
- myfree(confirmfilename);
+ free(confirmfilename);
if (dprintf(subconffd, "%s", subaddr) < 0) {
log_error(LOG_ARGS, "Could not write unsubconffile");
- myfree(randomstr);
- myfree(confirmfilename);
+ free(randomstr);
+ free(confirmfilename);
exit(EXIT_FAILURE);
}
close(subconffd);
- myasprintf(&fromaddr, "%s%sbounces-confunsub-%s@%s", list->name,
+ xasprintf(&fromaddr, "%s%sbounces-confunsub-%s@%s", list->name,
list->delim, randomstr, list->fqdn);
switch(typesub) {
break;
}
- myasprintf(&confirmaddr, "%s%s%s%s@%s", list->name, list->delim, tmpstr,
+ xasprintf(&confirmaddr, "%s%s%s%s@%s", list->name, list->delim, tmpstr,
randomstr, list->fqdn);
- myfree(randomstr);
+ free(randomstr);
txt = open_text(list, "confirm", "unsub",
subreason_strs[reasonsub], subtype_strs[typesub],
text *txt;
char *queuefilename, *fromaddr;
- myasprintf(&fromaddr, "%s%sbounes-help@%s", list->name, list->delim, list->fqdn);
+ xasprintf(&fromaddr, "%s%sbounes-help@%s", list->name, list->delim, list->fqdn);
txt = open_text(list,
"deny", "unsub", "unsubbed", subtype_strs[typesub],
#include <stdlib.h>
#include <string.h>
-#include "memory.h"
+#include "xmalloc.h"
#include "strgen.h"
#include "mlmmj.h"
#include "controls.h"
void
mlmmj_list_close(struct mlmmj_list *list)
{
- myfree(list->delim);
- myfree(list->addr);
- myfree(list->name);
+ free(list->delim);
+ free(list->addr);
+ free(list->name);
if (list->fd != -1)
close(list->fd);
if (list->controlfd != -1)
}
list->delim = ctrlvalue(list, "delimiter");
if (list->delim == NULL)
- list->delim = mystrdup(DEFAULT_RECIPDELIM);
+ list->delim = xstrdup(DEFAULT_RECIPDELIM);
if (!splitlistaddr(list->addr, &list->name, &list->fqdn)) {
warnx("%s: is not a valid mailing list address, "
#include <stdio.h>
#include "mygetline.h"
-#include "memory.h"
+#include "xmalloc.h"
char *mygetline(int fd)
{
size_t i = 0, res, buf_size = BUFSIZE; /* initial buffer size */
char *buf, ch;
- buf = mymalloc(buf_size);
+ buf = xmalloc(buf_size);
buf[0] = '\0';
while(1) {
res = read(fd, &ch, 1);
if(errno == EINTR)
continue;
else {
- myfree(buf);
+ free(buf);
return NULL;
}
}
buf[i] = '\0';
return buf;
} else {
- myfree(buf);
+ free(buf);
return NULL;
}
}
if(i == buf_size - 1) {
buf_size *= 2;
- buf = myrealloc(buf, buf_size);
+ buf = xrealloc(buf, buf_size);
}
buf[i++] = ch;
if(ch == '\n') {
#include <errno.h>
#include <err.h>
+#include "xmalloc.h"
#include "prepstdreply.h"
#include "controls.h"
#include "strgen.h"
#include "log_error.h"
#include "mygetline.h"
#include "wrappers.h"
-#include "memory.h"
#include "mlmmj.h"
#include "unistr.h"
memory_lines_state *init_memory_lines(const char *lines)
{
- memory_lines_state *s = mymalloc(sizeof(memory_lines_state));
+ memory_lines_state *s = xmalloc(sizeof(memory_lines_state));
size_t len;
/* Ensure there *is* a trailing newline */
s->pos = NULL;
len = strlen(lines);
if (lines[len-1] == '\n') {
- s->lines = mystrdup(lines);
+ s->lines = xstrdup(lines);
return s;
}
- s->lines = mymalloc((len + 2) * sizeof(char));
+ s->lines = xmalloc((len + 2) * sizeof(char));
strcpy(s->lines, lines);
s->lines[len] = '\n';
s->lines[len+1] = '\0';
void finish_memory_lines(memory_lines_state *s)
{
if (s == NULL) return;
- myfree(s->lines);
- myfree(s);
+ free(s->lines);
+ free(s);
}
file_lines_state *init_file_lines(const char *filename, int open_now)
{
- file_lines_state *s = mymalloc(sizeof(file_lines_state));
+ file_lines_state *s = xmalloc(sizeof(file_lines_state));
if (open_now) {
s->fd = open(filename, O_RDONLY);
s->filename = NULL;
if (s->fd < 0) {
- myfree(s);
+ free(s);
return NULL;
}
} else {
- s->filename = mystrdup(filename);
+ s->filename = xstrdup(filename);
s->fd = -1;
}
if (s == NULL) return;
if (s->filename != NULL) {
s->fd = open(s->filename, O_RDONLY);
- myfree(s->filename);
+ free(s->filename);
s->filename = NULL;
}
if (s->fd >= 0) {
char *end;
if (s == NULL) return NULL;
if (s->line != NULL) {
- myfree(s->line);
+ free(s->line);
s->line = NULL;
}
if (s->fd >= 0) {
void finish_file_lines(file_lines_state *s)
{
if (s == NULL) return;
- if (s->line != NULL) myfree(s->line);
+ if (s->line != NULL) free(s->line);
if (s->fd >= 0) close(s->fd);
- if (s->filename != NULL) myfree(s->filename);
- myfree(s);
+ if (s->filename != NULL) free(s->filename);
+ free(s);
}
return token;
}
-#define cmd_mail(val, str, list) myasprintf(val, "%s%s"str"%s", list->name, list->delim, list->fqdn)
+#define cmd_mail(val, str, list) xasprintf(val, "%s%s"str"%s", list->name, list->delim, list->fqdn)
static void substitute_one(char **line_p, char **pos_p, int *width_p,
struct mlmmj_list *list, text *txt)
if(strcmp(token, "") == 0) {
- value = mystrdup("$");
+ value = xstrdup("$");
} else if(strcmp(token, "listaddr") == 0) {
/* DEPRECATED: use $list$@$domain$ instead */
- value = mystrdup(list->addr);
+ value = xstrdup(list->addr);
} else if(strcmp(token, "list+") == 0) {
- myasprintf(&value, "%s%s", list->name, list->delim);
+ xasprintf(&value, "%s%s", list->name, list->delim);
} else if(strcmp(token, "list") == 0) {
- value = mystrdup(list->name);
+ value = xstrdup(list->name);
} else if(strcmp(token, "domain") == 0) {
- value = mystrdup(list->fqdn);
+ value = xstrdup(list->fqdn);
} else if(strcmp(token, "listowner") == 0) {
/* DEPRECATED: use $list+$owner@$domain$ instead */
cmd_mail(&value, "owner@", list);
if (token != NULL) value = textcontent(list, token);
} else if(strcmp(token, "originalmail") == 0) {
/* DEPRECATED: use %originalmail% instead */
- value = mystrdup(" %originalmail 100%");
+ value = xstrdup(" %originalmail 100%");
} else {
subst = txt->substs;
while (subst != NULL) {
if(strcmp(token, subst->token) == 0) {
- value = mystrdup(subst->subst);
+ value = xstrdup(subst->subst);
break;
}
subst = subst->next;
(*pos_p)++;
(*width_p)++;
}
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
- myfree(value);
+ free(value);
} else {
*pos = '$';
*endpos = '$';
char *pos;
int width = 0; /* Just a dummy here */
- new = mystrdup(line);
+ new = xstrdup(line);
pos = new;
while (*pos != '\0') {
{
text *txt;
- txt = mymalloc(sizeof(text));
- txt->src = mymalloc(sizeof(source));
+ txt = xmalloc(sizeof(text));
+ txt->src = xmalloc(sizeof(source));
txt->src->prev = NULL;
txt->src->upcoming = NULL;
txt->src->processedlen = 0;
filename[filenamelen-len-1] = '-';
filenamelen -= len + 1;
if ((txt = open_text_file(list, compat)) != NULL) {
- myfree(filename);
- filename = mystrdup(compat);
+ free(filename);
+ filename = xstrdup(compat);
break;
}
log_error(LOG_ARGS, "Could not open listtext '%s'", filename);
- myfree(filename);
+ free(filename);
return NULL;
} while (0);
- txt->action = action != NULL ? mystrdup(action) : NULL;
- txt->reason = reason != NULL ? mystrdup(reason) : NULL;
- txt->type = type != NULL ? mystrdup(type) : NULL;
+ txt->action = action != NULL ? xstrdup(action) : NULL;
+ txt->reason = reason != NULL ? xstrdup(reason) : NULL;
+ txt->type = type != NULL ? xstrdup(type) : NULL;
return txt;
}
{
source *tmp;
if (txt->src->fd != -1) close(txt->src->fd);
- if (txt->src->prefix != NULL) myfree(txt->src->prefix);
- if (txt->src->suffix != NULL) myfree(txt->src->suffix);
+ if (txt->src->prefix != NULL) free(txt->src->prefix);
+ if (txt->src->suffix != NULL) free(txt->src->suffix);
tmp = txt->src;
txt->src = txt->src->prev;
- myfree(tmp);
+ free(tmp);
}
void register_unformatted(text *txt, const char *token, const char *replacement)
{
- substitution * subst = mymalloc(sizeof(substitution));
- subst->token = mystrdup(token);
- subst->subst = mystrdup(replacement);
+ substitution * subst = xmalloc(sizeof(substitution));
+ subst->token = xstrdup(token);
+ subst->subst = xstrdup(replacement);
subst->next = txt->substs;
txt->substs = subst;
}
void register_originalmail(text *txt, const char *mailname)
{
- txt->mailname = mystrdup(mailname);
+ txt->mailname = xstrdup(mailname);
}
void register_formatted(text *txt, const char *token,
rewind_function rew, get_function get, void *state)
{
- formatted * fmt = mymalloc(sizeof(formatted));
- fmt->token = mystrdup(token);
+ formatted * fmt = xmalloc(sizeof(formatted));
+ fmt->token = xstrdup(token);
fmt->rew = rew;
fmt->get = get;
fmt->state = state;
if (*pos == '\r') pos++;
if (*pos == '\n') pos++;
if (*pos != '\0') {
- txt->src->upcoming = mystrdup(pos);
+ txt->src->upcoming = xstrdup(pos);
txt->src->processedlen = 0;
txt->src->processedwidth = 0;
}
return;
}
- src = mymalloc(sizeof(source));
+ src = xmalloc(sizeof(source));
src->prev = txt->src;
src->upcoming = NULL;
src->prefixlen = strlen(line);
src->prefixwidth = *width_p;
- src->prefix = mymalloc((*width_p + 1) * sizeof(char));
+ src->prefix = xmalloc((*width_p + 1) * sizeof(char));
for (tmp = src->prefix, i = 0; i < *width_p; tmp++, i++) *tmp = ' ';
*tmp = '\0';
src->suffix = NULL;
}
if (!transparent) {
esc = unistr_escaped_to_utf8(tmp);
- myfree(tmp);
+ free(tmp);
tmp = esc;
}
line = concatstr(2, line, tmp);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
- myfree(tmp);
+ free(tmp);
}
if (*pos == '\r') pos++;
if (*pos == '\n') pos++;
if (*pos != '\0') {
- txt->src->upcoming = mystrdup(pos);
+ txt->src->upcoming = xstrdup(pos);
txt->src->processedlen = 0;
txt->src->processedwidth = 0;
}
(*fmt->rew)(fmt->state);
- src = mymalloc(sizeof(source));
+ src = xmalloc(sizeof(source));
src->prev = txt->src;
src->upcoming = NULL;
if (*line == '\0') {
src->prefix = NULL;
} else {
- src->prefix = mystrdup(line);
+ src->prefix = xstrdup(line);
}
src->prefixlen = strlen(line);
src->prefixwidth = *width_p;
if (*suffix == '\0' || *suffix == '\r' || *suffix == '\n') {
src->suffix = NULL;
} else {
- src->suffix = mystrdup(suffix);
+ src->suffix = xstrdup(suffix);
}
src->fd = -1;
src->fmt = fmt;
line = concatstr(2, line, str);
/* The suffix will be added back in get_processed_text_line() */
*pos_p = line + strlen(*line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
}
multi = 0;
}
- cond = mymalloc(sizeof(conditional));
+ cond = xmalloc(sizeof(conditional));
cond->satisfied = satisfied;
cond->elsepart = 0;
cond->outer = txt->cond;
}
line = concatstr(2, line, pos);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
}
line = concatstr(2, line, endpos);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
}
cond = txt->cond;
swallow = (!cond->satisfied && !cond->elsepart)?1:0;
txt->cond = cond->outer;
- myfree(cond);
+ free(cond);
endpos++;
if (*skipwhite_p) {
while (*endpos == ' ' || *endpos == '\t')
}
line = concatstr(2, line, endpos);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return swallow;
}
line = concatstr(3, line, "%", endpos + 1);
*pos_p = line + (*pos_p - *line_p) + 1;
(*width_p)++;
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
} else if(strcmp(token, "^") == 0) {
line = concatstr(2, line, endpos + 1);
*width_p = txt->src->prefixwidth;
} else {
- line = mystrdup(endpos + 1);
+ line = xstrdup(endpos + 1);
*width_p = 0;
}
*pos_p = line;
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
} else if(strcmp(token, "comment") == 0 || strcmp(token, "$") == 0 ) {
while (*pos != '\0' && *pos != '\r' && *pos != '\n') pos++;
line = concatstr(2, line, pos);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
} else if(strncmp(token, "wrap", 4) == 0) {
txt->wrapwidth = limit;
line = concatstr(2, line, endpos + 1);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
}
txt->wrapwidth = 0;
line = concatstr(2, line, endpos + 1);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
} else if(strcmp(token, "ww") == 0 ||
if (*token == 'u') txt->wrapmode = WRAP_USER;
line = concatstr(2, line, endpos + 1);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
} else if(strcmp(token, "thin") == 0) {
txt->widthreckoning = WIDTH_THIN;
line = concatstr(2, line, endpos + 1);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
} else if(strcmp(token, "wide") == 0) {
txt->widthreckoning = WIDTH_WIDE;
line = concatstr(2, line, endpos + 1);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
} else if(strncmp(token, "zero ", 5) == 0) {
token += 5;
- if (txt->zerowidth != NULL) myfree(txt->zerowidth);
- txt->zerowidth = mystrdup(token);
+ if (txt->zerowidth != NULL) free(txt->zerowidth);
+ txt->zerowidth = xstrdup(token);
line = concatstr(2, line, endpos + 1);
*pos_p = line + (*pos_p - *line_p);
- myfree(*line_p);
+ free(*line_p);
*line_p = line;
return 0;
} else if(strncmp(token, "control ", 8) == 0) {
processedwidth += txt->wrapindent -
txt->src->prefixwidth;
}
- line = mymalloc((len + 1) * sizeof(char));
+ line = xmalloc((len + 1) * sizeof(char));
if (txt->src->prefixwidth != 0) {
strcpy(line, txt->src->prefix);
pos = line + txt->src->prefixlen;
wrapindentlen = pos - line;
}
strcpy(pos, txt->src->upcoming);
- myfree(txt->src->upcoming);
+ free(txt->src->upcoming);
txt->src->upcoming = NULL;
break;
}
item = (*txt->src->fmt->get)(
txt->src->fmt->state);
if (item==NULL) tmp = NULL;
- else tmp = mystrdup(item);
+ else tmp = xstrdup(item);
} else {
tmp = NULL;
}
unistr_escaped_to_utf8(tmp);
txt->src->processedlen = 0;
txt->src->processedwidth = 0;
- myfree(tmp);
+ free(tmp);
}
} else {
txt->src->upcoming = NULL;
close_source(txt);
}
if (line == NULL) {
- if (peeking) return mystrdup("");
+ if (peeking) return xstrdup("");
if (prev != NULL) return prev;
return NULL;
}
skipwhite = 0;
} else {
if (*prev == '\0') {
- tmp = mystrdup(pos);
+ tmp = xstrdup(pos);
} else {
if (txt->wrapmode == WRAP_WORD &&
len > wrapindentlen) {
tmp = concatstr(2, prev, pos);
}
}
- myfree(line);
+ free(line);
line = tmp;
- myfree(prev);
+ free(prev);
pos = line + len;
skipwhite = 1;
}
pos++;
if (*pos == '\n') pos++;
if (*pos == '\0') break;
- txt->src->upcoming = mystrdup(pos);
+ txt->src->upcoming = xstrdup(pos);
txt->src->processedlen = 0;
txt->src->processedwidth = 0;
break;
*pos = '\0';
pos++;
if (*pos == '\0') break;
- txt->src->upcoming = mystrdup(pos);
+ txt->src->upcoming = xstrdup(pos);
txt->src->processedlen = 0;
txt->src->processedwidth = 0;
break;
*pos = '\0';
tmp = concatstr(2, line, tmp);
pos = tmp + len;
- myfree(line);
+ free(line);
line = tmp;
skipwhite = 0;
continue;
line[incision] = '\0';
tmp = concatstr(2, line, pos);
pos = tmp + incision;
- myfree(line);
+ free(line);
line = tmp;
}
incision = -1;
/* The whole line was skipped; nothing to return yet;
* keep reading */
incision = -1;
- myfree(line);
+ free(line);
continue;
}
/* Time to cut */
if (pos - line != incision) {
line[incision] = '\0';
- tmp = mystrdup(line);
+ tmp = xstrdup(line);
pos = tmp + incision;
- myfree(line);
+ free(line);
line = tmp;
}
incision = -1;
}
if (linebreak != 0) {
if (txt->src->upcoming == NULL) {
- tmp = mystrdup(line + linebreak);
+ tmp = xstrdup(line + linebreak);
} else {
/* If something's coming up, it's because
* it was a new line. */
if (*(line + linebreak) != '\0') {
tmp = concatstr(3, line + linebreak,
"\n", txt->src->upcoming);
- myfree(txt->src->upcoming);
+ free(txt->src->upcoming);
} else {
tmp = txt->src->upcoming;
}
width - linebreakwidth;
}
line[linebreak] = '\0';
- tmp = mystrdup(line);
- myfree(line);
+ tmp = xstrdup(line);
+ free(line);
line = tmp;
} else {
if (directive) {
if (*pos == '\0') {
/* Omit whitespace-only line with
* directives */
- myfree(line);
+ free(line);
continue;
}
}
* not followed by an unsatisfied conditional
* without an else */
peeking = 1;
- myfree(line);
+ free(line);
continue;
} else if (peeking) {
/* We found something; return preceding blank
txt->src->upcoming);
txt->src->processedlen = len;
txt->src->processedwidth = width;
- myfree(line);
- myfree(tmp);
+ free(line);
+ free(tmp);
}
- line = mystrdup("");
+ line = xstrdup("");
}
}
if (txt->src->suffix != NULL) {
tmp = concatstr(2, line, txt->src->suffix);
- myfree(line);
+ free(line);
return tmp;
} else {
return line;
}
while (txt->substs != NULL) {
subst = txt->substs;
- myfree(subst->token);
- myfree(subst->subst);
+ free(subst->token);
+ free(subst->subst);
txt->substs = txt->substs->next;
- myfree(subst);
+ free(subst);
}
- if (txt->mailname != NULL) myfree(txt->mailname);
+ if (txt->mailname != NULL) free(txt->mailname);
while (txt->fmts != NULL) {
fmt = txt->fmts;
- myfree(fmt->token);
+ free(fmt->token);
txt->fmts = txt->fmts->next;
- myfree(fmt);
+ free(fmt);
}
while (txt->cond != NULL) {
cond = txt->cond;
txt->cond = txt->cond->outer;
- myfree(cond);
+ free(cond);
}
- myfree(txt);
+ free(txt);
}
if (infd) {
if (list->queuefd == -1)
list->queuefd = openat(list->fd, "queue", O_DIRECTORY);
- myfree(retstr);
+ free(retstr);
retstr = random_str();
outfd = openat(list->queuefd, retstr, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
} else {
tmp = random_str();
- myfree(retstr);
+ free(retstr);
retstr = concatstr(3, list->dir, "/queue/", tmp);
- myfree(tmp);
+ free(tmp);
outfd = open(retstr, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
}
} while ((outfd < 0) && (errno == EEXIST));
if(outfd < 0) {
log_error(LOG_ARGS, "Could not open std mail %s", retstr);
- myfree(retstr);
- myfree(txt);
+ free(retstr);
+ free(txt);
return NULL;
}
for (i=0; i<6; i++) {
- tmp = mystrdup("randomN");
+ tmp = xstrdup("randomN");
tmp[6] = '0' + i;
str = random_str();
register_unformatted(txt, tmp, str);
- myfree(tmp);
- myfree(str);
+ free(tmp);
+ free(str);
}
tmp = substitute(from, list, txt);
headers[0] = concatstr(2, "From: ", tmp);
- myfree(tmp);
+ free(tmp);
tmp = substitute(to, list, txt);
headers[1] = concatstr(2, "To: ", tmp);
- myfree(tmp);
+ free(tmp);
headers[2] = genmsgid(list->fqdn);
chomp(headers[2]);
headers[3] = gendatestr();
chomp(headers[3]);
- headers[4] = mystrdup("Subject: mlmmj administrivia");
- headers[5] = mystrdup("MIME-Version: 1.0");
- headers[6] = mystrdup("Content-Type: text/plain; charset=utf-8");
- headers[7] = mystrdup("Content-Transfer-Encoding: 8bit");
+ headers[4] = xstrdup("Subject: mlmmj administrivia");
+ headers[5] = xstrdup("MIME-Version: 1.0");
+ headers[6] = xstrdup("Content-Type: text/plain; charset=utf-8");
+ headers[7] = xstrdup("Content-Transfer-Encoding: 8bit");
if(replyto) {
tmp = substitute(replyto, list, txt);
headers[8] = concatstr(2, "Reply-To: ", tmp);
- myfree(tmp);
+ free(tmp);
}
for(;;) {
}
if (*line == '\0') {
/* end of headers */
- myfree(line);
+ free(line);
line = NULL;
break;
}
continuation of previous header line */
if(dprintf(outfd, "%s\n", line) < 0) {
log_error(LOG_ARGS, "Could not write std mail");
- myfree(line);
- myfree(retstr);
+ free(line);
+ free(retstr);
retstr = NULL;
goto freeandreturn;
}
/* remove the standard header if one matches */
for (i=0; headers[i] != NULL; i++) {
if (strncasecmp(line, headers[i], len) == 0) {
- myfree(headers[i]);
+ free(headers[i]);
while (headers[i] != NULL) {
headers[i] = headers[i+1];
i++;
}
if (strncasecmp(line, "Subject:", len) == 0) {
tmp = unistr_utf8_to_header(tmp);
- myfree(line);
+ free(line);
line = concatstr(2, "Subject: ", tmp);
- myfree(tmp);
+ free(tmp);
}
if(dprintf(outfd, "%s\n", line) < 0) {
log_error(LOG_ARGS, "Could not write std mail");
- myfree(line);
- myfree(retstr);
+ free(line);
+ free(retstr);
retstr = NULL;
goto freeandreturn;
}
}
- myfree(line);
+ free(line);
line = NULL;
}
if(dprintf(outfd, "%s\n", headers[i]) < 0) {
log_error(LOG_ARGS, "Could not write std mail");
if (line)
- myfree(line);
- myfree(retstr);
+ free(line);
+ free(retstr);
retstr = NULL;
goto freeandreturn;
}
if(dprintf(outfd, "\n") < 0) {
log_error(LOG_ARGS, "Could not write std mail");
if (line)
- myfree(line);
- myfree(retstr);
+ free(line);
+ free(retstr);
retstr = NULL;
goto freeandreturn;
}
}
while(line) {
if(dprintf(outfd, "%s\n", line) < 0) {
- myfree(str);
+ free(str);
log_error(LOG_ARGS, "Could not write std mail");
- myfree(retstr);
+ free(retstr);
retstr = NULL;
goto freeandreturn;
}
- myfree(line);
+ free(line);
line = get_processed_text_line(txt, 0, list);
}
#include <sys/wait.h>
#include <ctype.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "send_digest.h"
#include "log_error.h"
#include "strgen.h"
-#include "memory.h"
#include "wrappers.h"
#include "prepstdreply.h"
#include "mygetline.h"
}
for (i=s->firstindex; i<=s->lastindex; i++) {
- myasprintf(&archivename, "archive/%d", i);
+ xasprintf(&archivename, "archive/%d", i);
archivefd = openat(s->list->fd, archivename, O_RDONLY|O_CLOEXEC);
- myfree(archivename);
+ free(archivename);
if (archivefd < 0)
continue;
while ((line = gethdrline(archivefd, NULL))) {
if (strncasecmp(line, "Subject:", 8) == 0) {
- myfree(subj);
+ free(subj);
subj = unistr_header_to_utf8(line + 8);
}
if (strncasecmp(line, "From:", 5) == 0) {
- myfree(from);
+ free(from);
from = unistr_header_to_utf8(line + 5);
}
- myfree(line);
+ free(line);
}
if (!subj) {
- subj = mystrdup("no subject");
+ subj = xstrdup("no subject");
}
if (!from) {
- from = mystrdup("anonymous");
+ from = xstrdup("anonymous");
}
tmp = subj;
}
if (thread_idx == -1) {
num_threads++;
- threads = myrealloc(threads,
+ threads = xrealloc(threads,
num_threads*sizeof(struct thread));
- myasprintf(&(threads[num_threads-1].subject), "%s\n", tmp);
+ xasprintf(&(threads[num_threads-1].subject), "%s\n", tmp);
threads[num_threads-1].num_mails = 0;
threads[num_threads-1].mails = NULL;
thread_idx = num_threads-1;
/* tmp is now left-trimmed from */
threads[thread_idx].num_mails++;
- threads[thread_idx].mails = myrealloc(threads[thread_idx].mails,
+ threads[thread_idx].mails = xrealloc(threads[thread_idx].mails,
threads[thread_idx].num_mails*sizeof(struct mail));
threads[thread_idx].mails[threads[thread_idx].num_mails-1].idx = i;
- myasprintf(&(threads[thread_idx].mails[threads[thread_idx].num_mails-1].from),
+ xasprintf(&(threads[thread_idx].mails[threads[thread_idx].num_mails-1].from),
" %d - %s\n", i, tmp);
- myfree(subj);
- myfree(from);
+ free(subj);
+ free(from);
close(archivefd);
}
int i, j;
if (s->threads == NULL) return;
for (i=0; i<s->num_threads; i++) {
- myfree(s->threads[i].subject);
+ free(s->threads[i].subject);
for (j=0; j<s->threads[i].num_mails; j++) {
- myfree(s->threads[i].mails[j].from);
+ free(s->threads[i].mails[j].from);
}
- myfree(s->threads[i].mails);
+ free(s->threads[i].mails);
}
- myfree(s->threads);
+ free(s->threads);
s->threads = NULL;
}
do {
tmp = random_str();
- myfree(queuename);
- myasprintf(&queuename, "queue/%s", tmp);
- myfree(tmp);
+ free(queuename);
+ xasprintf(&queuename, "queue/%s", tmp);
+ free(tmp);
fd = openat(list->fd, queuename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
} while ((fd < 0) && (errno == EEXIST));
if (fd < 0) {
log_error(LOG_ARGS, "Could not open digest queue file '%s'",
queuename);
- myfree(queuename);
+ free(queuename);
return -1;
}
len++;
if (strncasecmp(line, "Subject:", len) == 0) {
tmp = unistr_utf8_to_header(tmp);
- myasprintf(&subject, "Subject: %s", tmp);
- myfree(tmp);
- myfree(line);
+ xasprintf(&subject, "Subject: %s", tmp);
+ free(tmp);
+ free(line);
/* Skip the empty line after the subject */
line = get_processed_text_line(txt, 1, list);
goto fallback_subject;
}
- if (line != NULL) myfree(line);
+ if (line != NULL) free(line);
line = NULL;
} else {
log_error(LOG_ARGS, "No subject or invalid "
} else {
snprintf(buf, sizeof(buf), "%d-%d", firstindex, lastindex);
}
- tmp = mystrdup(buf);
+ tmp = xstrdup(buf);
snprintf(buf, sizeof(buf), "Digest of %s issue %d (%s)",
list->addr, issue, tmp);
subject = unistr_utf8_to_header(buf);
- myfree(tmp);
+ free(tmp);
}
r = dprintf(fd, "From: %s%shelp@%s"
"boundary=%s"
"\nSubject: %s\n",
list->name, list->delim, list->fqdn, boundary, subject);
- myfree(subject);
+ free(subject);
if (r < 0)
goto errdighdrs;
queuename);
close(fd);
unlink(queuename);
- myfree(boundary);
- myfree(queuename);
+ free(boundary);
+ free(queuename);
if (txt != NULL) {
close_text(txt);
- myfree(line);
+ free(line);
}
if (hdrfd > 0) {
close(hdrfd);
" part headers to '%s'", queuename);
close(fd);
unlink(queuename);
- myfree(boundary);
- myfree(queuename);
+ free(boundary);
+ free(queuename);
if (txt != NULL) {
close_text(txt);
- myfree(line);
+ free(line);
}
return -1;
}
len = strlen(line);
line[len] = '\n';
if(dprintf(fd, "%s", line) < 0) {
- myfree(line);
+ free(line);
log_error(LOG_ARGS, "Could not write"
" std mail");
break;
}
- myfree(line);
+ free(line);
}
finish_thread_list(tls);
close_text(txt);
}
- if (line != NULL) myfree(line);
+ if (line != NULL) free(line);
for (i=firstindex; i<=lastindex; i++) {
- myasprintf(&archivename, "archive/%d", i);
+ xasprintf(&archivename, "archive/%d", i);
archivefd = openat(list->fd, archivename, O_RDONLY|O_CLOEXEC);
- myfree(archivename);
+ free(archivename);
if (archivefd < 0)
continue;
close(fd);
close(archivefd);
unlink(queuename);
- myfree(boundary);
- myfree(queuename);
+ free(boundary);
+ free(queuename);
return -1;
}
close(fd);
close(archivefd);
unlink(queuename);
- myfree(boundary);
- myfree(queuename);
+ free(boundary);
+ free(queuename);
return -1;
}
queuename);
close(fd);
unlink(queuename);
- myfree(boundary);
- myfree(queuename);
+ free(boundary);
+ free(queuename);
return -1;
}
close(fd);
- myfree(boundary);
+ free(boundary);
childpid = fork();
if(childpid < 0) {
log_error(LOG_ARGS, "Could not fork");
- myfree(queuename);
+ free(queuename);
return -1;
}
exit(EXIT_FAILURE); /* It is OK to exit, as this is a child */
}
- myfree(queuename);
+ free(queuename);
return 0;
}
#include "mlmmj.h"
#include "send_help.h"
-#include "memory.h"
+#include "xmalloc.h"
#include "send_mails.h"
void send_help(struct mlmmj_list *list, const char *queuefilename,
char *fromaddr;
int queuefd;
- myasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
+ xasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim,
list->fqdn);
memset(&mh, 0, sizeof(mh));
mh.to = emailaddr;
#include <sys/stat.h>
#include <dirent.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "send_list.h"
#include "strgen.h"
#include "chomp.h"
#include "mygetline.h"
#include "prepstdreply.h"
-#include "memory.h"
#include "send_mails.h"
static subs_list_state *init_subs_list(struct mlmmj_list *list, const char *dirname)
{
- subs_list_state *s = mymalloc(sizeof(subs_list_state));
+ subs_list_state *s = xmalloc(sizeof(subs_list_state));
s->dirname = dirname;
s->list = list;
s->dirp = NULL;
if (s->dirp == NULL) return NULL;
if (s->line != NULL) {
- myfree(s->line);
+ free(s->line);
s->line = NULL;
}
log_error(LOG_ARGS,
"Could not open %s for reading",
filename);
- myfree(filename);
+ free(filename);
continue;
}
- myfree(filename);
+ free(filename);
}
s->line = mygetline(s->fd);
if (s->line == NULL) {
static void finish_subs_list(subs_list_state *s)
{
if (s == NULL) return;
- if (s->line != NULL) myfree(s->line);
+ if (s->line != NULL) free(s->line);
if (s->fd != -1) close(s->fd);
if (s->dirp != NULL) closedir(s->dirp);
- myfree(s);
+ free(s);
}
char *fromaddr;
int fd, queuefd;;
- myasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim, list->fqdn);
+ xasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim, list->fqdn);
normalsls = init_subs_list(list, "subscribers.d");
digestsls = init_subs_list(list, "digesters.d");
#include <unistd.h>
#include <netdb.h>
+#include "xmalloc.h"
#include "controls.h"
#include "strgen.h"
#include "mlmmj.h"
#include "log_error.h"
#include "init_sockfd.h"
#include "checkwait_smtpreply.h"
-#include "memory.h"
#include "mail-functions.h"
int
if((reply = checkwait_smtpreply(*sockfd, MLMMJ_CONNECT)) != NULL) {
log_error(LOG_ARGS, "No proper greeting to our connect"
"Reply: [%s]", reply);
- myfree(reply);
+ free(reply);
retval = MLMMJ_CONNECT;
/* FIXME: Queue etc. */
break;
* unacceptable, it will return code 501.
*/
if (strncmp(reply, "501", 3) == 0) {
- myfree(reply);
+ free(reply);
/* Commmand unacceptable; we choose to QUIT but
* ignore any QUIT errors; return that EHLO was
* the error.
*/
if (reply[0] != '5') {
- myfree(reply);
+ free(reply);
/* Server doesn't understand EHLO, but gives a
* broken response. Try with new connection.
*/
continue;
}
- myfree(reply);
+ free(reply);
/* RFC 1869 - 4.7. - Other improperly-implemented
* servers will not accept a HELO command after EHLO has
* code (e.g., 503 Bad sequence of commands) in response
* to the RSET. This code can be safely ignored.
*/
- myfree(reply);
+ free(reply);
/* Try HELO on the same connection
*/
break;
}
if (try_ehlo) {
- myfree(reply);
+ free(reply);
/* We reused a connection we tried EHLO on. Maybe
* that's why it failed. Try with new connection.
*/
log_error(LOG_ARGS, "Error with HELO. Reply: "
"[%s]", reply);
- myfree(reply);
+ free(reply);
/* FIXME: quit and tell admin to configure
* correctly */
retval = MLMMJ_HELO;
log_error(LOG_ARGS, "Mailserver would not let us QUIT. "
"We close the socket anyway though. "
"Mailserver reply = [%s]", reply);
- myfree(reply);
+ free(reply);
retval = MLMMJ_QUIT;
}
if(reply) {
log_error(LOG_ARGS, "Error in MAIL FROM. Reply = [%s]",
reply);
- myfree(reply);
+ free(reply);
write_rset(sockfd);
reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET);
- if (reply2 != NULL) myfree(reply2);
+ if (reply2 != NULL) free(reply2);
return MLMMJ_FROM;
}
retval = write_rcpt_to(sockfd, to);
if(reply) {
write_rset(sockfd);
reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET);
- if (reply2 != NULL) myfree(reply2);
+ if (reply2 != NULL) free(reply2);
if(mlmmjbounce && ((reply[0] == '4') || (reply[0] == '5'))
&& (reply[1] == '5')) {
- myfree(reply);
+ free(reply);
return bouncemail(list, mlmmjbounce, from);
} else {
log_error(LOG_ARGS, "Error in RCPT TO. Reply = [%s]",
reply);
- myfree(reply);
+ free(reply);
return MLMMJ_RCPTTO;
}
}
reply = checkwait_smtpreply(sockfd, MLMMJ_DATA);
if(reply) {
log_error(LOG_ARGS, "Error with DATA. Reply = [%s]", reply);
- myfree(reply);
+ free(reply);
write_rset(sockfd);
reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET);
- if (reply2 != NULL) myfree(reply2);
+ if (reply2 != NULL) free(reply2);
return MLMMJ_DATA;
}
}
if(addtohdr)
- myasprintf(&tohdr, "To: %s\r\n", to);
+ xasprintf(&tohdr, "To: %s\r\n", to);
else
tohdr = NULL;
log_error(LOG_ARGS, "Could not write To:.\n");
return retval;
}
- myfree(tohdr);
+ free(tohdr);
}
retval = dprintf(sockfd, "%.*s", (int)bodylen, body);
if(retval < 0) {
log_error(LOG_ARGS, "Mailserver did not ack end of mail.\n"
"<CR><LF>.<CR><LF> was written, to no"
"avail. Reply = [%s]", reply);
- myfree(reply);
+ free(reply);
write_rset(sockfd);
reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET);
- if (reply2 != NULL) myfree(reply2);
+ if (reply2 != NULL) free(reply2);
return MLMMJ_DOT;
}
int
bouncemail(struct mlmmj_list *list, const char *mlmmjbounce, const char *from)
{
- char *myfrom = mystrdup(from);
+ char *myfrom = xstrdup(from);
char *addr, *num, *c;
size_t len;
pid_t pid = 0;
if((c = strchr(myfrom, '@')) == NULL) {
- myfree(myfrom);
+ free(myfrom);
return 0; /* Success when malformed 'from' */
}
*c = '\0';
myfrom = strchr(c, '-');
myfrom++;
len = num - myfrom - 1;
- addr = mymalloc(len + 1);
+ addr = xmalloc(len + 1);
addr[len] = '\0';
strncpy(addr, myfrom, len);
&bodylen);
if(body == NULL) {
log_error(LOG_ARGS, "Could not prepare mailbody");
- myfree(hdrs);
+ free(hdrs);
munmap(mailmap, st.st_size);
return (false);
}
sockfd = -1;
/* dump data we want when resending first check
* if it already exists. In that case continue */
- myasprintf(&tmpstr, "%s.mailfrom", mailfilename);
+ xasprintf(&tmpstr, "%s.mailfrom", mailfilename);
if(stat(tmpstr, &st) == 0) {
- myfree(tmpstr);
+ free(tmpstr);
goto out;
}
tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR);
- myfree(tmpstr);
+ free(tmpstr);
if(tmpfd >= 0) {
dprintf(tmpfd, "%s", mh->bounceaddr);
fsync(tmpfd);
}
close(tmpfd);
- myasprintf(&tmpstr, "%s.reciptto", mailfilename);
+ xasprintf(&tmpstr, "%s.reciptto", mailfilename);
if(stat(tmpstr, &st) == 0) {
- myfree(tmpstr);
+ free(tmpstr);
goto out;
}
tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR);
- myfree(tmpstr);
+ free(tmpstr);
if(tmpfd >= 0) {
dprintf(tmpfd, "%s", mh->to);
fsync(tmpfd);
}
close(tmpfd);
if(mh->replyto) {
- myasprintf(&tmpstr, "%s.reply-to", mailfilename);
+ xasprintf(&tmpstr, "%s.reply-to", mailfilename);
if(stat(tmpstr, &st) == 0) {
- myfree(tmpstr);
+ free(tmpstr);
goto out;
}
tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR);
- myfree(tmpstr);
+ free(tmpstr);
if(tmpfd >= 0) {
dprintf(tmpfd, "%s", mh->replyto);
fsync(tmpfd);
}
out:
- myfree(hdrs);
- myfree(body);
+ free(hdrs);
+ free(body);
munmap(mailmap, st.st_size);
close(mailfd);
- myfree(smtphelo);
+ free(smtphelo);
/* TODO Archive goes here */
return (true);
#include <ctype.h>
#include <errno.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "strgen.h"
#include "wrappers.h"
-#include "memory.h"
#include "log_error.h"
char *random_str()
{
char *dest;
- myasprintf(&dest, "%08x%08x", random_int(), random_int());
+ xasprintf(&dest, "%08x%08x", random_int(), random_int());
return dest;
}
char *atsign;
char *tmpstr;
- tmpstr = mystrdup(addr);
+ tmpstr = xstrdup(addr);
atsign = strchr(tmpstr, '@');
MY_ASSERT(atsign);
*atsign = '=';
- myasprintf(&dest, "%08x%08x-%s", random_int(), random_int(), tmpstr);
+ xasprintf(&dest, "%08x%08x-%s", random_int(), random_int(), tmpstr);
- myfree(tmpstr);
+ free(tmpstr);
return dest;
}
splitlistaddr(const char *listaddr, char **listname, const char **listfqdn)
{
char *allocated, *walk;
- allocated = mystrdup(listaddr);
+ allocated = xstrdup(listaddr);
walk = strchr(allocated, '@');
if (walk == NULL) {
- myfree(allocated);
+ free(allocated);
return (false);
}
*walk = '\0';
len += strlen(str);
}
- retstr = mymalloc(len + 1);
+ retstr = xmalloc(len + 1);
retstr[0] = retstr[len] = 0;
va_start(arg, count);
for (;;) {
len *= 2;
- myfree(hostname);
+ free(hostname);
- hostname = mymalloc(len);
+ hostname = xmalloc(len);
hostname[len-1] = '\0';
/* gethostname() is allowed to:
if (errno == ENAMETOOLONG) {
continue;
}
- myfree(hostname);
- return mystrdup("localhost");
+ free(hostname);
+ return xstrdup("localhost");
}
if (hostname[len-1] == '\0') {
}
if ((hostlookup = gethostbyname(hostname))) {
- myfree(hostname);
- return mystrdup(hostlookup->h_name);
+ free(hostname);
+ return xstrdup(hostlookup->h_name);
}
return hostname;
{
char *mypath, *dname, *ret;
- mypath = mystrdup(path);
+ mypath = xstrdup(path);
dname = dirname(mypath);
- ret = mystrdup(dname);
+ ret = xstrdup(dname);
- /* We don't free mypath until we have strdup()'ed dname, because
+ /* We don't free mypath until we have xstrdup()'ed dname, because
* dirname() returns a pointer into mypath -- mortenp 20040527 */
- myfree(mypath);
+ free(mypath);
return ret;
}
* complete nor correct */
len = strlen(qpstr);
- retstr = mymalloc(len + 1);
+ retstr = xmalloc(len + 1);
retstr[len] = '\0';
qc[2] = '\0';
while(c < qpstr+len) {
{
char *buf;
- myasprintf(&buf, "Message-ID: <%ld-%d-mlmmj-%08x@%s>\n",
+ xasprintf(&buf, "Message-ID: <%ld-%d-mlmmj-%08x@%s>\n",
(long int)time(NULL), (int)getpid(), random_int(), fqdn);
return (buf);
char *timestr;
/* 6 + 26 + ' ' + timezone which is 5 + '\n\0' == 40 */
- timestr = (char *)mymalloc(40);
+ timestr = (char *)xmalloc(40);
t = time(NULL);
localtime_r(&t, <tm);
#include "log_error.h"
#include "wrappers.h"
#include "strgen.h"
-#include "memory.h"
+#include "xmalloc.h"
char *subtype_strs[] = {
"normal",
char *loweraddress;
int i = 0;
- loweraddress = mystrdup(address);
+ loweraddress = xstrdup(address);
while (loweraddress[i] != '\0') {
loweraddress[i] = tolower(loweraddress[i]);
i++;
}
/* create a .name.lock file and aquire the lock */
- myasprintf(&sublockname, ".%s.lock", dp->d_name);
+ xasprintf(&sublockname, ".%s.lock", dp->d_name);
sublockfd = openat(subdirfd, sublockname, O_RDWR | O_CREAT | O_EXLOCK,
S_IRUSR | S_IWUSR);
if (sublockfd < 0) {
log_error(LOG_ARGS, "Error opening lock file %s/%s/%s",
list->dir, subdir, sublockname);
- myfree(sublockname);
+ free(sublockname);
continue;
}
- myasprintf(&subwritename, "%s.new", dp->d_name);
+ xasprintf(&subwritename, "%s.new", dp->d_name);
subwrite = openat(subdirfd, subwritename, O_RDWR | O_CREAT | O_TRUNC | O_EXLOCK,
S_IRUSR | S_IWUSR | groupwritable);
if(subwrite == -1){
list->dir, subdir, subwritename);
close(subread);
close(sublockfd);
- myfree(subwritename);
- myfree(sublockname);
+ free(subwritename);
+ free(sublockname);
continue;
}
close(subwrite);
close(sublockfd);
unlinkat(subdirfd, subwritename, 0);
- myfree(subwritename);
- myfree(sublockname);
+ free(subwritename);
+ free(sublockname);
continue;
}
subwritename, dp->d_name);
close(subread);
close(subwrite);
- myfree(subwritename);
+ free(subwritename);
continue;
}
} else { /* unsubres == 0, no subscribers left */
close(subread);
close(subwrite);
close(sublockfd);
- myfree(subwritename);
+ free(subwritename);
unlinkat(subdirfd, sublockname, 0);
- myfree(sublockname);
+ free(sublockname);
}
closedir(subddir);
#include <ctype.h>
#include <iconv.h>
+#include "xmalloc.h"
#include "mlmmj.h"
#include "unistr.h"
#include "log_error.h"
-#include "memory.h"
/* This is allocated on the stack, so it can't be too big. */
#define ICONV_BUFFER_SIZE 160
{
unistr *ret;
- ret = mymalloc(sizeof(unistr));
+ ret = xmalloc(sizeof(unistr));
ret->len = 0;
ret->alloc_len = 64;
- ret->chars = mymalloc(ret->alloc_len * sizeof(unistr_char));
+ ret->chars = xmalloc(ret->alloc_len * sizeof(unistr_char));
return ret;
}
{
if (!str)
return;
- myfree(str->chars);
- myfree(str);
+ free(str->chars);
+ free(str);
}
{
if (str->len >= str->alloc_len) {
str->alloc_len *= 2;
- str->chars = myrealloc(str->chars, str->alloc_len * sizeof(unistr_char));
+ str->chars = xrealloc(str->chars, str->alloc_len * sizeof(unistr_char));
}
str->chars[str->len++] = uc;
}
errno = 0;
log_error(LOG_ARGS, "unistr_to_utf8(): can not utf-8 encode"
"U+%04X", str->chars[i]);
- return mystrdup("");
+ return xstrdup("");
}
}
len++; /* NUL */
- ret = mymalloc(len);
+ ret = xmalloc(len);
p = ret;
for (i=0; i<str->len; i++) {
int i;
/* decoded string will never be longer, and we don't include a NUL */
- *binary = mymalloc(strlen(str));
+ *binary = xmalloc(strlen(str));
*bin_len = 0;
for (i=0; str[i]; i++) {
/* decoded string will never be longer, and we don't include a NUL */
len = strlen(str);
- *binary = mymalloc(len);
+ *binary = xmalloc(len);
*bin_len = 0;
out = 0;
return 0;
}
- my_word = mystrdup(word);
+ my_word = xstrdup(word);
charset = my_word + 2;
/* missing encoding */
unistr_append_usascii(ret, wsp, word-wsp);
unistr_append_usascii(ret, "???", 3);
- myfree(my_word);
+ free(my_word);
return 0;
}
*(encoding++) = '\0';
/* missing string */
unistr_append_usascii(ret, wsp, word-wsp);
unistr_append_usascii(ret, "???", 3);
- myfree(my_word);
+ free(my_word);
return 0;
}
*(string++) = '\0';
/* missing end */
unistr_append_usascii(ret, wsp, word-wsp);
unistr_append_usascii(ret, "???", 3);
- myfree(my_word);
+ free(my_word);
return 0;
}
*(end++) = '\0';
/* broken end */
unistr_append_usascii(ret, wsp, word-wsp);
unistr_append_usascii(ret, "???", 3);
- myfree(my_word);
+ free(my_word);
return 0;
}
/* unknown encoding */
unistr_append_usascii(ret, wsp, word-wsp);
unistr_append_usascii(ret, "???", 3);
- myfree(my_word);
+ free(my_word);
return 0;
}
unistr_append_iconv(ret, binary, bin_len, charset);
}
- myfree(my_word);
- myfree(binary);
+ free(my_word);
+ free(binary);
return 1;
}
unistr *us;
char *ret;
- my_str = mystrdup(str);
+ my_str = xstrdup(str);
us = unistr_new();
p = my_str + strspn(my_str, " \t\n");
p += strspn(p, " \t\n");
}
- myfree(my_str);
+ free(my_str);
ret = unistr_to_utf8(us);
unistr_free(us);
int clean;
char buf[4];
- my_str = mystrdup(str);
+ my_str = xstrdup(str);
/* trim whitespace and see if the header is clean */
*wsp = '\0';
if (clean) {
- ret = mystrdup(ret);
- myfree(my_str);
+ ret = xstrdup(ret);
+ free(my_str);
return ret;
}
ret = unistr_to_utf8(us);
unistr_free(us);
- myfree(my_str);
+ free(my_str);
return ret;
}
check_PROGRAMS = mlmmj
mlmmj_SOURCES = mlmmj.c $(top_srcdir)/src/prepstdreply.c $(top_srcdir)/include/prepstdreply.h \
- $(top_srcdir)/src/memory.c $(top_srcdir)/src/controls.c $(top_srcdir)/src/utils.c \
+ $(top_srcdir)/src/controls.c $(top_srcdir)/src/utils.c \
$(top_srcdir)/src/strgen.c $(top_srcdir)/src/random-int.c $(top_srcdir)/src/readn.c \
$(top_srcdir)/src/log_error.c $(top_srcdir)/src/chomp.c $(top_srcdir)/src/mygetline.c $(top_srcdir)/src/unistr.c \
$(top_srcdir)/src/mlmmj.c $(top_srcdir)/src/mail-functions.c
ATF_CHECK(errp == NULL);
asprintf(&str, "1%"PRIdMAX, INTMAX_MAX);
ATF_REQUIRE_EQ(strtotimet(str, &errp), 0);
- myfree(str);
+ free(str);
ATF_REQUIRE(errp != NULL);
ATF_REQUIRE_STREQ(errp, "too large");
}