* please see the file GPL in the top level source directory.
*/
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include <lib-lib/macros.h>
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
+#include <lib-lib/lib-lib.h>
#include "unix.h"
#include "mutt_signal.h"
#include <imap/imap.h> /* 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.
if (!pw->pw_gecos)
return 0;
- if (rx) {
+ if (rx->rx) {
regmatch_t pat_match[1];
if (regexec(rx->rx, pw->pw_gecos, 1, pat_match, 0)) {
}
p = pw->pw_gecos + pat_match[0].rm_so;
- end = pw->pw_gecos + pat_match[0].rm_so;
+ end = pw->pw_gecos + pat_match[0].rm_eo;
} else {
p = pw->pw_gecos;
end = m_strchrnul(pw->pw_gecos, ',');
}
for (;;) {
- const char *q = MIN(end, m_strchrnul(p, '&'));
+ const char *q = m_strchrnul(p, '&');
- len += m_strncpy(dst + len, n - len, p, q - p);
+ len += m_strncpy(dst + len, n - len, p, MIN(end, q) - p);
p = q + 1;
if (!p[-1] || p >= end)
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);
+ m_fclose(&f);
+ return 0;
+ }
+
+ p = q;
+ }
+ }
+
+ m_fclose(&f);
+ return -1;
+}