s4:dsdb: Add userAccountControl helper function
[Samba.git] / libcli / dns / resolvconftest.c
blob639526443f0c98c9bce0ce147c634fe2bd6b5675
1 /*
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/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <talloc.h>
23 #include <errno.h>
24 #include "libcli/dns/resolvconf.h"
25 #include "lib/util/memory.h"
27 static int resolvconftest1(void)
29 const char *content =
30 "#foo\nbar\nnameserver 1.2.3.4\nnameserver 2.3.4.5";
31 char *file;
32 FILE *fp;
33 int ret;
34 char **nameservers;
35 size_t num_nameservers;
37 file = strdup(content);
38 if (file == NULL) {
39 perror("strdup failed");
40 return ENOMEM;
42 fp = fmemopen(file, strlen(file), "r");
43 if (fp == NULL) {
44 perror("fmemopen failed");
45 return errno;
48 ret = parse_resolvconf_fp(fp, NULL, &nameservers, &num_nameservers);
49 if (ret != 0) {
50 fprintf(stderr, "parse_resolvconf_fp failed: %s\n",
51 strerror(ret));
52 return ret;
55 if (num_nameservers != 2) {
56 fprintf(stderr, "expected 2 nameservers, got %zu\n",
57 num_nameservers);
58 return EIO;
60 if ((strcmp(nameservers[0], "1.2.3.4") != 0) ||
61 (strcmp(nameservers[1], "2.3.4.5") != 0)) {
62 fprintf(stderr, "got wrong nameservers\n");
63 return EIO;
66 TALLOC_FREE(nameservers);
67 fclose(fp);
68 SAFE_FREE(file);
70 return 0;
73 int main(void) {
74 int ret;
76 ret = resolvconftest1();
77 if (ret != 0) {
78 return 1;
81 return 0;