X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-sys%2Funix.c;h=a83d4bcf96ee99b4122ddcdb2d25b1b9a0841f3f;hp=f2141c0c18849a0655a459ac80afdee7ec986d20;hb=723f7ae3f24f7881c9ce87abf933cd5bec4ac0bc;hpb=97677c08933e16e25ecb3c12473ef1efdab7962b diff --git a/lib-sys/unix.c b/lib-sys/unix.c index f2141c0..a83d4bc 100644 --- a/lib-sys/unix.c +++ b/lib-sys/unix.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -16,19 +17,19 @@ #include #include #include +#include #include "unix.h" #include "mutt_signal.h" #include /* for imap_wait_keepalive EEEEK */ - /* Extract the real name from /etc/passwd's GECOS field. * When set, honor the regular expression in rx, * otherwise assume that the GECOS field is a comma-separated list. * Replace "&" by a capitalized version of the user's login name. */ -ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, rx_t *rx) +ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, regex_t *rx) { const char *p, *end; ssize_t len; @@ -42,7 +43,7 @@ ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, rx_t *rx) if (rx) { regmatch_t pat_match[1]; - if (regexec(rx->rx, pw->pw_gecos, 1, pat_match, 0)) { + if (regexec(rx, pw->pw_gecos, 1, pat_match, 0)) { return 0; } @@ -156,3 +157,41 @@ int _mutt_system(const char *cmd, int flags) return (pid > 0 && WIFEXITED(rc)) ? WEXITSTATUS(rc) : -1; } + +int getdnsdomainname(char *s, ssize_t n) +{ + char tmp[1024]; + FILE *f; + + if ((f = fopen("/etc/resolv.conf", "r")) == NULL) + return -1; + + while (fgets(tmp, sizeof(tmp), f)) { + const char *p = skipspaces(tmp); + + if (m_strncmp("domain", p, 6) && m_strncmp("search", p, 6)) + continue; + + p += 6; + + while (*p) { + int trailing_dot; + const char *q; + + p = skipspaces(p); + q = m_strnextsp(p); + + trailing_dot = q[-1] == '.'; + if (!trailing_dot || q > p + 1) { + m_strncpy(s, n, p, q - trailing_dot - p); + safe_fclose(&f); + return 0; + } + + p = q; + } + } + + safe_fclose (&f); + return -1; +}