about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--README.76
-rwxr-xr-xconfigure5
-rw-r--r--imbox.14
-rw-r--r--imbox.c77
4 files changed, 5 insertions, 87 deletions
diff --git a/README.7 b/README.7
index c309347..ab209db 100644
--- a/README.7
+++ b/README.7
@@ -1,4 +1,4 @@
-.Dd October 29, 2020
+.Dd December  4, 2020
 .Dt README 7
 .Os "Causal Agency"
 .
@@ -23,10 +23,6 @@ provided by either
 .Lk https://git.causal.agency/libretls/about LibreTLS
 (for OpenSSL)
 or by LibreSSL.
-On systems other than FreeBSD,
-.Xr dig 1
-is required for
-automatic IMAP server configuration.
 .
 .Bd -literal -offset indent
 \&./configure
diff --git a/configure b/configure
index 3b57019..3309d82 100755
--- a/configure
+++ b/configure
@@ -31,13 +31,8 @@ for opt; do
 done
 
 case "$(uname)" in
-	(FreeBSD)
-		config libtls
-		defstr DRILL_PATH /usr/bin/drill
-		;;
 	(OpenBSD)
 		ldlibs -ltls
-		defstr DIG_PATH /usr/bin/dig
 		;;
 	(Linux)
 		cflags -D_GNU_SOURCE -DDECLARE_RPP
diff --git a/imbox.1 b/imbox.1
index 92872ba..743c9fb 100644
--- a/imbox.1
+++ b/imbox.1
@@ -1,4 +1,4 @@
-.Dd May  2, 2020
+.Dd December  4, 2020
 .Dt IMBOX 1
 .Os
 .
@@ -70,8 +70,6 @@ on the domain name of
 .Ar user ,
 or simply the domain name
 if no SRV record exists.
-Lookup requires
-.Xr dig 1 .
 .
 .It Fl m Ar mailbox
 Export messages from
diff --git a/imbox.c b/imbox.c
index 99b4de8..8c4d351 100644
--- a/imbox.c
+++ b/imbox.c
@@ -30,7 +30,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/wait.h>
 #include <sysexits.h>
 #include <unistd.h>
 
@@ -43,10 +42,6 @@ char * readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags);
 
 #include "imap.h"
 
-#ifndef DIG_PATH
-#define DIG_PATH "dig"
-#endif
-
 #define FETCH_HEADERS \
 	"Date Subject From Sender Reply-To To Cc Bcc " \
 	"Message-Id In-Reply-To References " \
@@ -71,72 +66,6 @@ static void mboxrd(char *header, char *body) {
 	printf("\n");
 }
 
-static void lookup(const char **host, const char **port, const char *domain) {
-	static char buf[1024];
-	snprintf(buf, sizeof(buf), "_imaps._tcp.%s", domain);
-
-	int rw[2];
-	int error = pipe(rw);
-	if (error) err(EX_OSERR, "pipe");
-
-	pid_t pid = fork();
-	if (pid < 0) err(EX_OSERR, "fork");
-
-	if (!pid) {
-		close(rw[0]);
-		dup2(rw[1], STDOUT_FILENO);
-		dup2(rw[1], STDERR_FILENO);
-		close(rw[1]);
-#ifdef DRILL_PATH
-		execlp(DRILL_PATH, "drill", buf, "SRV", NULL);
-		err(EX_CONFIG, "%s", DRILL_PATH);
-#else
-		execlp(DIG_PATH, "dig", "-t", "SRV", "-q", buf, "+short", NULL);
-		err(EX_CONFIG, "%s", DIG_PATH);
-#endif
-	}
-
-	int status;
-	pid = wait(&status);
-	if (pid < 0) err(EX_OSERR, "wait");
-
-	close(rw[1]);
-	FILE *pipe = fdopen(rw[0], "r");
-	if (!pipe) err(EX_IOERR, "fdopen");
-
-	fgets(buf, sizeof(buf), pipe);
-	if (ferror(pipe)) err(EX_IOERR, "fgets");
-
-	if (!WIFEXITED(status) || WEXITSTATUS(status)) {
-		fprintf(stderr, "%s", buf);
-		exit(WEXITSTATUS(status));
-	}
-
-	char *ptr = buf;
-#ifdef DRILL_PATH
-	for (;;) {
-		char *line = fgets(buf, sizeof(buf), pipe);
-		if (!line || !strcmp(line, ";; ANSWER SECTION:\n")) break;
-	}
-	fgets(buf, sizeof(buf), pipe);
-	if (ferror(pipe)) err(EX_IOERR, "fgets");
-	ptr = strrchr(buf, '\t');
-	ptr = (ptr ? ptr + 1 : buf);
-#endif
-	fclose(pipe);
-
-	char *dot = strrchr(ptr, '.');
-	if (dot) *dot = '\0';
-	strsep(&ptr, " \n"); // priority
-	strsep(&ptr, " \n"); // weight
-	*port = strsep(&ptr, " \n");
-	*host = strsep(&ptr, " \n");
-	if (!*host) {
-		*host = domain;
-		*port = "imaps";
-	}
-}
-
 int main(int argc, char *argv[]) {
 	const char *host = NULL;
 	const char *port = "imaps";
@@ -167,9 +96,9 @@ int main(int argc, char *argv[]) {
 	if (!user) errx(EX_USAGE, "username required");
 
 	if (!host) {
-		const char *domain = strchr(user, '@');
-		if (!domain) errx(EX_USAGE, "no domain in username");
-		lookup(&host, &port, &domain[1]);
+		host = strchr(user, '@');
+		if (!host) errx(EX_USAGE, "no domain in username");
+		host++;
 	}
 
 	char buf[1024];