-/* $OpenBSD: spamd.c,v 1.116 2014/11/23 21:19:47 guenther Exp $ */
+/* $OpenBSD: spamd.c,v 1.117 2014/12/29 20:39:27 millert Exp $ */
/*
* Copyright (c) 2002-2007 Bob Beck. All rights reserved.
void parse_configs(void);
void do_config(void);
int append_error_string (struct con *, size_t, char *, int, void *);
-void build_reply(struct con *);
void doreply(struct con *);
void setlog(char *, size_t, char *);
void initcon(struct con *, int, struct sockaddr *);
}
void
-build_reply(struct con *cp)
+doreply(struct con *cp)
{
struct sdlist **matches;
int off = 0;
goto nomatch;
for (; *matches; matches++) {
int used = 0;
- char *c = cp->obuf + off;
int left = cp->osize - off;
used = append_error_string(cp, off, matches[0]->string,
left -= used;
if (cp->obuf[off - 1] != '\n') {
if (left < 1) {
- c = grow_obuf(cp, off);
- if (c == NULL)
+ if (grow_obuf(cp, off) == NULL)
goto bad;
}
cp->obuf[off++] = '\n';
/* No match. give generic reply */
free(cp->obuf);
cp->obuf = NULL;
- cp->osize = 0;
if (cp->blacklists != NULL)
- asprintf(&cp->obuf,
+ cp->osize = asprintf(&cp->obuf,
"%s-Sorry %s\n"
"%s-You are trying to send mail from an address "
"listed by one\n"
"%s or more IP-based registries as being a SPAM source.\n",
nreply, cp->addr, nreply, nreply);
else
- asprintf(&cp->obuf,
+ cp->osize = asprintf(&cp->obuf,
"451 Temporary failure, please try again later.\r\n");
- if (cp->obuf != NULL)
- cp->osize = strlen(cp->obuf) + 1;
- else
- cp->osize = 0;
+ cp->osize++; /* size includes the NUL (also changes -1 to 0) */
return;
bad:
if (cp->obuf != NULL) {
}
}
-void
-doreply(struct con *cp)
-{
- build_reply(cp);
-}
-
void
setlog(char *p, size_t len, char *f)
{
{
socklen_t len = sa->sa_len;
time_t tt;
- char *tmp;
+ char ctimebuf[26];
int error;
time(&tt);
if (error)
errx(1, "%s", gai_strerror(error));
#endif
- tmp = strdup(ctime(&t));
- if (tmp == NULL)
- err(1, "malloc");
- tmp[strlen(tmp) - 1] = '\0'; /* nuke newline */
+ ctime_r(&t, ctimebuf);
+ ctimebuf[sizeof(ctimebuf) - 2] = '\0'; /* nuke newline */
snprintf(cp->obuf, cp->osize, "220 %s ESMTP %s; %s\r\n",
- hostname, spamd, tmp);
- free(tmp);
+ hostname, spamd, ctimebuf);
cp->op = cp->obuf;
cp->ol = strlen(cp->op);
cp->w = tt + cp->stutter;