--- /dev/null
+*.o
+dma
+dma-mbox-create
+aliases_parse.c
+aliases_parse.h
+aliases_scan.c
SSL_library_init();
SSL_load_error_strings();
- meth = TLSv1_client_method();
+ // Allow any possible version
+#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
+ meth = TLS_client_method();
+#else
+ meth = SSLv23_client_method();
+#endif
ctx = SSL_CTX_new(meth);
if (ctx == NULL) {
struct group *gr;
uid_t user_uid;
gid_t mail_gid;
- int error;
- char fn[PATH_MAX+1];
- int f;
+ int f, maildirfd;
openlog("dma-mbox-create", 0, LOG_MAIL);
if (!pw)
logfail(EX_NOUSER, "cannot find user `%s'", user);
- user_uid = pw->pw_uid;
+ maildirfd = open(_PATH_MAILDIR, O_RDONLY);
+ if (maildirfd < 0)
+ logfail(EX_NOINPUT, "cannot open maildir %s", _PATH_MAILDIR);
- error = snprintf(fn, sizeof(fn), "%s/%s", _PATH_MAILDIR, user);
- if (error < 0 || (size_t)error >= sizeof(fn)) {
- if (error >= 0) {
- errno = 0;
- logfail(EX_USAGE, "mbox path too long");
- }
- logfail(EX_CANTCREAT, "cannot build mbox path for `%s/%s'", _PATH_MAILDIR, user);
- }
+ user_uid = pw->pw_uid;
- f = open(fn, O_RDONLY|O_CREAT, 0600);
+ f = openat(maildirfd, user, O_RDONLY|O_CREAT|O_NOFOLLOW, 0600);
if (f < 0)
- logfail(EX_NOINPUT, "cannt open mbox `%s'", fn);
+ logfail(EX_NOINPUT, "cannot open mbox `%s'", user);
if (fchown(f, user_uid, mail_gid))
- logfail(EX_OSERR, "cannot change owner of mbox `%s'", fn);
+ logfail(EX_OSERR, "cannot change owner of mbox `%s'", user);
if (fchmod(f, 0620))
- logfail(EX_OSERR, "cannot change permissions of mbox `%s'", fn);
+ logfail(EX_OSERR, "cannot change permissions of mbox `%s'",
+ user);
/* file should be present with the right owner and permissions */
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <libgen.h>
#include <paths.h>
#include <pwd.h>
#include <signal.h>
snprintf(errmsg, sizeof(errmsg), "unknown bounce reason");
retry:
- syslog(LOG_INFO, "trying delivery");
+ syslog(LOG_INFO, "<%s> trying delivery", it->addr);
if (it->remote)
error = deliver_remote(it);
switch (error) {
case 0:
delqueue(it);
- syslog(LOG_INFO, "delivery successful");
+ syslog(LOG_INFO, "<%s> delivery successful", it->addr);
exit(EX_OK);
case 1:
bzero(&queue, sizeof(queue));
LIST_INIT(&queue.queue);
- if (strcmp(argv[0], "mailq") == 0) {
+ if (strcmp(basename(argv[0]), "mailq") == 0) {
argv++; argc--;
showq = 1;
if (argc != 0)
#define VERSION "DragonFly Mail Agent " DMA_VERSION
#define BUF_SIZE 2048
-#define ERRMSG_SIZE 200
+#define ERRMSG_SIZE 1024
#define USERNAME_SIZE 50
#define EHLO_RESPONSE_SIZE BUF_SIZE
#define MIN_RETRY 300 /* 5 minutes */
*/
#include <sys/types.h>
+#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
goto out;
}
- error = snprintf(line, sizeof(line), "%sFrom %s\t%s", newline, sender, ctime(&now));
+ error = snprintf(line, sizeof(line), "%sFrom %s %s", newline, sender, ctime(&now));
if (error < 0 || (size_t)error >= sizeof(line)) {
syslog(LOG_NOTICE, "local delivery deferred: can not write header: %m");
goto out;
/*
* mboxro processing:
* - escape lines that start with "From " with a > sign.
- * - be reversable by escaping lines that contain an arbitrary
+ * - be reversible by escaping lines that contain an arbitrary
* number of > signs, followed by "From ", i.e. />*From / in regexp.
* - strict mbox processing only requires escaping after empty lines,
* yet most MUAs seem to relax this requirement and will treat any
host->host, host->addr, c, neterr); \
snprintf(errmsg, sizeof(errmsg), "%s [%s] did not like our %s:\n%s", \
host->host, host->addr, c, neterr); \
- return (-1); \
+ error = -1; \
+ goto out; \
} else if (res != exp) { \
syslog(LOG_NOTICE, "remote delivery deferred: %s [%s] failed after %s: %s", \
host->host, host->addr, c, neterr); \
- return (1); \
+ error = 1; \
+ goto out; \
}
/* Check first reply from remote host */
syslog(LOG_ERR, "remote delivery failed:"
" SMTP login failed: %m");
snprintf(errmsg, sizeof(errmsg), "SMTP login to %s failed", host->host);
- return (-1);
+ error = -1;
+ goto out;
}
/* SMTP login is not available, so try without */
else if (error > 0) {