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
|
/* This file is part of NSsync
Copyright (C) 2011 Sergey Poznyakoff
NSsync is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
NSsync is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NSsync. If not, see <http://www.gnu.org/licenses/>. */
#include "nssync.h"
char *named_conf_file;
struct grecs_list *bind_include_path;
static struct grecs_node *bind_tree;
void
source_named_conf()
{
grecs_include_path_clear();
if (bind_include_path) {
struct grecs_list_entry *ep;
for (ep = bind_include_path->head; ep; ep = ep->next)
grecs_preproc_add_include_dir(grecs_strdup(ep->data));
}
grecs_parser_fun = grecs_bind_parser;
if (!named_conf_file)
named_conf_file = "/etc/named.conf";
bind_tree = grecs_parse(named_conf_file);
if (!bind_tree)
exit(EX_UNAVAILABLE);
}
const char *
bindcf_lookup(struct nssync *sp)
{
const char *name;
struct grecs_node *node = grecs_find_node(bind_tree, sp->kwpath);
if (!node) {
error("%s: keyword %s not found in %s",
sp->tag, sp->kwpath, named_conf_file);
return NULL;
}
if (!node->v.value) {
error("%s: no value for %s",
sp->tag, sp->kwpath);
return NULL;
}
if (node->v.value->type != GRECS_TYPE_STRING) {
error("%s: %s is not a string",
sp->tag, sp->kwpath);
return NULL;
}
debug(2, ("%s: found %s at %s:%d",
sp->tag, sp->kwpath, node->locus.file, node->locus.line));
name = node->v.value->v.string;
if (name[0] != '/') {
char *p = grecs_find_include_file(name, 1);
if (!p) {
if (errno == ENOENT) {
if (bind_include_path) {
size_t s = 0;
grecs_asprintf(&p, &s,
"%s/%s",
bind_include_path->head->data,
name);
}
}
if (!p) {
error("%s: cannot find absolute name for %s: %s",
sp->tag, name, strerror(errno));
return NULL;
}
}
name = p;
}
return name;
}
|