summary refs log tree commit diff
path: root/imbox.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-23 00:06:05 -0500
committerJune McEnroe <june@causal.agency>2019-12-23 00:08:25 -0500
commit197d139430f0fd44492f81b71e005ab63bebab6b (patch)
treec1d75d5dbcc59037600eee801ba10a74a69f727e /imbox.c
parentDocument dig requirement in imbox(1) (diff)
downloadimbox-197d139430f0fd44492f81b71e005ab63bebab6b.tar.gz
imbox-197d139430f0fd44492f81b71e005ab63bebab6b.zip
Properly support using drill rather than dig
Silly drill doesn't have +short, so emulate it by waiting for the ANSWER
SECTION and skipping the leading fields.
Diffstat (limited to 'imbox.c')
-rw-r--r--imbox.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/imbox.c b/imbox.c
index eb611a2..fff867f 100644
--- a/imbox.c
+++ b/imbox.c
@@ -27,9 +27,9 @@
 #include <tls.h>
 #include <unistd.h>
 
-#ifndef DIG_PATH
+#if !defined(DIG_PATH) && !defined(DRILL_PATH)
 #	ifdef __FreeBSD__
-#		define DIG_PATH "/usr/bin/drill"
+#		define DRILL_PATH "/usr/bin/drill"
 #	else
 #		define DIG_PATH "dig"
 #	endif
@@ -108,8 +108,13 @@ static void lookup(const char **host, const char **port, const char *domain) {
 		dup2(rw[1], STDOUT_FILENO);
 		dup2(rw[1], STDERR_FILENO);
 		close(rw[1]);
+#ifdef DRILL_PATH
+		execlp(DRILL_PATH, DRILL_PATH, buf, "SRV", NULL);
+		err(EX_CONFIG, "%s", DRILL_PATH);
+#else
 		execlp(DIG_PATH, DIG_PATH, "-t", "SRV", "-q", buf, "+short", NULL);
 		err(EX_CONFIG, "%s", DIG_PATH);
+#endif
 	}
 
 	int status;
@@ -122,7 +127,6 @@ static void lookup(const char **host, const char **port, const char *domain) {
 
 	fgets(buf, sizeof(buf), pipe);
 	if (ferror(pipe)) err(EX_IOERR, "fgets");
-	fclose(pipe);
 
 	if (!WIFEXITED(status) || WEXITSTATUS(status)) {
 		fprintf(stderr, "%s", buf);
@@ -130,6 +134,18 @@ static void lookup(const char **host, const char **port, const char *domain) {
 	}
 
 	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