mailing list of musl libc
 help / color / mirror / code / Atom feed
16ca395fd2acd91373bdddbb7cce0d4dce31daf1 blob 2351 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
 
#include "lookup.h"
#include "stdio_impl.h"
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <netinet/in.h>

void __parse_resolv_opts(struct resolvconf *conf, const char *opts)
{
	char *p, *z;

	p = strstr(opts, "ndots:");
	if (p && isdigit(p[6])) {
		p += 6;
		unsigned long x = strtoul(p, &z, 10);
		if (z != p) conf->ndots = x > 15 ? 15 : x;
	}
	p = strstr(opts, "attempts:");
	if (p && isdigit(p[9])) {
		p += 9;
		unsigned long x = strtoul(p, &z, 10);
		if (z != p) conf->attempts = x > 10 ? 10 : x;
	}
	p = strstr(opts, "timeout:");
	if (p && (isdigit(p[8]) || p[8]=='.')) {
		p += 8;
		unsigned long x = strtoul(p, &z, 10);
		if (z != p) conf->timeout = x > 60 ? 60 : x;
	}
}

int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
{
	char line[256];
	unsigned char _buf[256];
	FILE *f, _f;
	int nns = 0;

	conf->ndots = 1;
	conf->timeout = 5;
	conf->attempts = 2;
	if (search) *search = 0;

	f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf);
	if (!f) switch (errno) {
	case ENOENT:
	case ENOTDIR:
	case EACCES:
		goto no_resolv_conf;
	default:
		return -1;
	}

	while (fgets(line, sizeof line, f)) {
		char *p, *z;
		if (!strchr(line, '\n') && !feof(f)) {
			/* Ignore lines that get truncated rather than
			 * potentially misinterpreting them. */
			int c;
			do c = getc(f);
			while (c != '\n' && c != EOF);
			continue;
		}
		if (!strncmp(line, "options", 7) && isspace(line[7])) {
			__parse_resolv_opts(conf, line);
			continue;
		}
		if (!strncmp(line, "nameserver", 10) && isspace(line[10])) {
			if (nns >= MAXNS) continue;
			for (p=line+11; isspace(*p); p++);
			for (z=p; *z && !isspace(*z); z++);
			*z=0;
			if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0)
				nns++;
			continue;
		}

		if (!search) continue;
		if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6))
		    || !isspace(line[6]))
			continue;
		for (p=line+7; isspace(*p); p++);
		size_t l = strlen(p);
		/* This can never happen anyway with chosen buffer sizes. */
		if (l >= search_sz) continue;
		memcpy(search, p, l+1);
	}

	__fclose_ca(f);

no_resolv_conf:
	if (!nns) {
		__lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC);
		nns = 1;
	}

	conf->nns = nns;

	if (!libc.secure) {
		const char *opts = getenv("RES_OPTIONS");
		if (opts) __parse_resolv_opts(conf, opts);
	}

	return 0;
}
debug log:

solving 16ca395f ...
found 16ca395f in https://inbox.vuxu.org/musl/20170430205258.4806-1-stefan.sedich@gmail.com/
found 4c3e4c4b in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 4c3e4c4b1c03c9feaafe831e4b865626a9a4d60d	src/network/resolvconf.c

applying [1/1] https://inbox.vuxu.org/musl/20170430205258.4806-1-stefan.sedich@gmail.com/
diff --git a/src/network/resolvconf.c b/src/network/resolvconf.c
index 4c3e4c4b..16ca395f 100644

Checking patch src/network/resolvconf.c...
Applied patch src/network/resolvconf.c cleanly.

index at:
100644 16ca395fd2acd91373bdddbb7cce0d4dce31daf1	src/network/resolvconf.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).