2 * Unix SMB/CIFS implementation.
3 * Internal DNS query structures
4 * Copyright (C) Volker Lendecke 2018
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/dns/resolvconf.h"
24 #include "lib/util/memory.h"
26 int parse_resolvconf_fp(
30 size_t *pnum_nameservers
)
34 char **nameservers
= NULL
;
35 size_t num_nameservers
= 0;
39 char *saveptr
= NULL
, *option
= NULL
, *ns
= NULL
;
43 n
= getline(&line
, &len
, fp
);
51 if ((n
> 0) && (line
[n
-1] == '\n')) {
55 if ((line
[0] == '#') || (line
[0] == ';')) {
59 option
= strtok_r(line
, " \t", &saveptr
);
64 if (strcmp(option
, "nameserver") != 0) {
68 ns
= strtok_r(NULL
, " \t", &saveptr
);
84 nameservers
[num_nameservers
] = talloc_strdup(nameservers
, ns
);
85 if (nameservers
[num_nameservers
] == NULL
) {
95 *pnameservers
= nameservers
;
96 *pnum_nameservers
= num_nameservers
;
98 TALLOC_FREE(nameservers
);
104 int parse_resolvconf(
105 const char *resolvconf
,
107 char ***pnameservers
,
108 size_t *pnum_nameservers
)
113 fp
= fopen(resolvconf
? resolvconf
: "/etc/resolv.conf", "r");
118 ret
= parse_resolvconf_fp(fp
, mem_ctx
, pnameservers
, pnum_nameservers
);