line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Bind8 key directive handling |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright Karthik Krishnamurthy |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Unix::Conf::Bind8::Conf::Key - Class for handling Bind8 configuration |
8
|
|
|
|
|
|
|
directive `key' |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Unix::Conf::Bind8; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my ($conf, $key, $ret); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$conf = Unix::Conf::Bind8->new_conf ( |
17
|
|
|
|
|
|
|
FILE => '/etc/named.conf', |
18
|
|
|
|
|
|
|
SECURE_OPEN => 1, |
19
|
|
|
|
|
|
|
) or $conf->die ("couldn't open `named.conf'"); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Ways to get a key object |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$key = $conf->new_key ( |
26
|
|
|
|
|
|
|
NAME => 'sample_key', |
27
|
|
|
|
|
|
|
ALGORITHM => 'hmac-md5', |
28
|
|
|
|
|
|
|
SECRET => '"abcdefgh"', |
29
|
|
|
|
|
|
|
) or $key->die ("couldn't create key"); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# OR |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$key = $conf->get_key ('extremix-slaves.key') |
34
|
|
|
|
|
|
|
or $key->die ("couldn't get key"); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# Operations that can be performed on a Key object |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$ret = $key->name ('some_other_key') |
41
|
|
|
|
|
|
|
or $ret->die ("couldn't set name"); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$ret = $key->secret ('"secret"') |
44
|
|
|
|
|
|
|
or $ret->die ("couldn't set secret"); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# get attributes |
47
|
|
|
|
|
|
|
printf ("KEY ID => %s, ALGORITHM => %s, SECRET => %s", |
48
|
|
|
|
|
|
|
$key->name (), $key->algorithm (), $key->secret ()); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# delete key |
51
|
|
|
|
|
|
|
$ret = $key->delete () or $ret->die ("couldn't delete"); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$ret = $conf->delete_key ('sample_key') |
54
|
|
|
|
|
|
|
or $ret->die ("couldn't delete"); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
package Unix::Conf::Bind8::Conf::Key; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
10
|
|
|
10
|
|
54
|
use strict; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
403
|
|
64
|
10
|
|
|
10
|
|
52
|
use warnings; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
280
|
|
65
|
10
|
|
|
10
|
|
53
|
use Unix::Conf; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
248
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
10
|
|
|
10
|
|
47
|
use Unix::Conf::Bind8::Conf::Directive; |
|
10
|
|
|
|
|
37
|
|
|
10
|
|
|
|
|
666
|
|
69
|
|
|
|
|
|
|
our (@ISA) = qw (Unix::Conf::Bind8::Conf::Directive); |
70
|
|
|
|
|
|
|
|
71
|
10
|
|
|
10
|
|
87
|
use Unix::Conf::Bind8::Conf; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
7789
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=over 4 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item new () |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Arguments |
78
|
|
|
|
|
|
|
NAME => scalar, |
79
|
|
|
|
|
|
|
ALGORITHM => scalar, # number |
80
|
|
|
|
|
|
|
SECRET => scalar, # quoted string |
81
|
|
|
|
|
|
|
WHERE => 'FIRST'|'LAST'|'BEFORE'|'AFTER' |
82
|
|
|
|
|
|
|
WARG => Unix::Conf::Bind8::Conf::Directive subclass object |
83
|
|
|
|
|
|
|
# WARG is to be provided only in case WHERE eq 'BEFORE |
84
|
|
|
|
|
|
|
# or WHERE eq 'AFTER' |
85
|
|
|
|
|
|
|
PARENT => reference, |
86
|
|
|
|
|
|
|
# to the Conf object datastructure. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Class constructor |
89
|
|
|
|
|
|
|
Creates a new Unix::Conf::Bind8::Conf::Key object and returns it, on success, |
90
|
|
|
|
|
|
|
an Err object otherwise. Do not use this constructor directly. Use the |
91
|
|
|
|
|
|
|
Unix::Conf::Bind8::Conf::new_key () method instead. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub new |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
0
|
1
|
|
my $self = shift (); |
98
|
0
|
|
|
|
|
|
my $new = bless ({}); |
99
|
0
|
|
|
|
|
|
my %args = @_; |
100
|
0
|
|
|
|
|
|
my $ret; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
$args{NAME} || return (Unix::Conf->_err ('new', "NAME not defined")); |
103
|
0
|
0
|
|
|
|
|
$args{ALGORITHM}|| return (Unix::Conf->_err ('new', "ALGORITHM not defined")); |
104
|
0
|
0
|
|
|
|
|
$args{SECRET} || return (Unix::Conf->_err ('new', "SECRET not defined")); |
105
|
0
|
0
|
|
|
|
|
$args{PARENT} || return (Unix::Conf->_err ('new', "PARENT not defined")); |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
$ret = $new->_parent ($args{PARENT}) or return ($ret); |
108
|
0
|
0
|
|
|
|
|
$ret = $new->name ($args{NAME}) or return ($ret); |
109
|
0
|
0
|
|
|
|
|
$ret = $new->algorithm ($args{ALGORITHM}) |
110
|
|
|
|
|
|
|
or return ($ret); |
111
|
0
|
0
|
|
|
|
|
$ret = $new->secret ($args{SECRET}) or return ($ret); |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
$args{WHERE} = 'LAST' unless ($args{WHERE}); |
114
|
0
|
0
|
|
|
|
|
$ret = Unix::Conf::Bind8::Conf::_insert_in_list ($new, $args{WHERE}, $args{WARG}) |
115
|
|
|
|
|
|
|
or return ($ret); |
116
|
0
|
|
|
|
|
|
return ($new); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item name |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Arguments |
123
|
|
|
|
|
|
|
value |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Object method. |
126
|
|
|
|
|
|
|
Get/set the corresponding attribute. Returns the attribute value or true |
127
|
|
|
|
|
|
|
on success, an Err object otherwise. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub name |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if ($name) { |
136
|
0
|
|
|
|
|
|
my $ret; |
137
|
0
|
0
|
0
|
|
|
|
$ret = Unix::Conf::Bind8::Conf::_del_key ($self) or return ($ret) |
138
|
|
|
|
|
|
|
if ($self->{name}); |
139
|
0
|
|
|
|
|
|
$self->{name} = $name; |
140
|
0
|
0
|
|
|
|
|
$ret = Unix::Conf::Bind8::Conf::_add_key ($self) or return ($ret); |
141
|
0
|
|
|
|
|
|
$self->dirty (1); |
142
|
0
|
|
|
|
|
|
return (1); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
return ( |
145
|
0
|
0
|
|
|
|
|
defined ($self->{name}) ? $self->{name} : |
146
|
|
|
|
|
|
|
Unix::Conf->_err ('name', "name not defined for key") |
147
|
|
|
|
|
|
|
); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item algorithm |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Arguments |
153
|
|
|
|
|
|
|
value |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Object method. |
156
|
|
|
|
|
|
|
Get/set the corresponding attribute. Returns the attribute value or true |
157
|
|
|
|
|
|
|
on success, an Err object otherwise. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub algorithm |
162
|
|
|
|
|
|
|
{ |
163
|
0
|
|
|
0
|
1
|
|
my ($self, $algo) = @_; |
164
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
|
if ($algo) { |
166
|
|
|
|
|
|
|
# validate later |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
$self->{algo} = $algo; |
169
|
0
|
|
|
|
|
|
$self->dirty (1); |
170
|
0
|
|
|
|
|
|
return (1); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
return ( |
173
|
0
|
0
|
|
|
|
|
defined ($self->{algo}) ? $self->{algo} : |
174
|
|
|
|
|
|
|
Unix::Conf->_err ('algorithm', "algorithm not defined for key") |
175
|
|
|
|
|
|
|
); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item secret |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Arguments |
181
|
|
|
|
|
|
|
value |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Object method. |
184
|
|
|
|
|
|
|
Get/set the corresponding attribute. Returns the attribute value or true |
185
|
|
|
|
|
|
|
on success, an Err object otherwise. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub secret |
190
|
|
|
|
|
|
|
{ |
191
|
0
|
|
|
0
|
1
|
|
my ($self, $secret) = @_; |
192
|
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
|
if ($secret) { |
194
|
|
|
|
|
|
|
# strip quotes |
195
|
0
|
|
|
|
|
|
$secret =~ s/^"(.+)"$/$1/; |
196
|
0
|
|
|
|
|
|
$self->{secret} = $secret; |
197
|
0
|
|
|
|
|
|
$self->dirty (1); |
198
|
0
|
|
|
|
|
|
return (1); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
return ( |
201
|
0
|
0
|
|
|
|
|
defined ($self->{secret}) ? $self->{secret} : |
202
|
|
|
|
|
|
|
Unix::Conf->_err ('secret', "secret not defined for key") |
203
|
|
|
|
|
|
|
); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub __render |
207
|
|
|
|
|
|
|
{ |
208
|
0
|
|
|
0
|
|
|
my $self = $_[0]; |
209
|
0
|
|
|
|
|
|
my $rendered; |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
$rendered = sprintf ( |
212
|
|
|
|
|
|
|
qq /key %s {\n\talgorithm %s;\n\tsecret "%s";\n};/, |
213
|
|
|
|
|
|
|
$self->name (), $self->algorithm (), $self->secret (), |
214
|
|
|
|
|
|
|
); |
215
|
0
|
|
|
|
|
|
return ($self->_rstring (\$rendered)); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
1; |