diff options
author | June McEnroe <june@causal.agency> | 2020-12-15 18:44:29 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-15 18:45:00 -0500 |
commit | b112e868841dfbbd0d305daadade1cd695152256 (patch) | |
tree | 194f0cca834702216557b53b8bc8f5b09fe2ec06 /notemap.c | |
parent | Add -lresolv on macOS, Linux (diff) | |
download | notemap-b112e868841dfbbd0d305daadade1cd695152256.tar.gz notemap-b112e868841dfbbd0d305daadade1cd695152256.zip |
Remove dependency on dig/drill
Diffstat (limited to 'notemap.c')
-rw-r--r-- | notemap.c | 76 |
1 files changed, 3 insertions, 73 deletions
diff --git a/notemap.c b/notemap.c index 1849c44..e2b41dc 100644 --- a/notemap.c +++ b/notemap.c @@ -51,78 +51,8 @@ char * readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags); #include "imap.h" -#ifndef DIG_PATH -#define DIG_PATH "dig" -#endif - typedef unsigned char byte; -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"; - } -} - static const char *uuidGen(void) { byte uuid[16]; int error = getentropy(uuid, sizeof(uuid)); @@ -256,9 +186,9 @@ int main(int argc, char *argv[]) { argc -= optind; 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]; |