Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
ISC Open Source Projects
BIND
Commits
0094faa6
Commit
0094faa6
authored
Aug 03, 2001
by
Andreas Gustafsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduced code duplication. Code duplication is evil.
parent
644772cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
67 deletions
+52
-67
bin/rndc/rndc-confgen.c
bin/rndc/rndc-confgen.c
+52
-67
No files found.
bin/rndc/rndc-confgen.c
View file @
0094faa6
...
...
@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rndc-confgen.c,v 1.
4
2001/08/03 22:
12:4
2 gson Exp $ */
/* $Id: rndc-confgen.c,v 1.
5
2001/08/03 22:
33:0
2 gson Exp $ */
#include <config.h>
...
...
@@ -76,6 +76,45 @@ Usage:\n\
exit
(
status
);
}
/*
* Write an rndc.key file to 'keyfile'. If 'user' is non-NULL,
* make that user the owner of the file. The key will have
* the name 'keyname' and the secret in the buffer 'secret'.
*/
static
void
write_key_file
(
const
char
*
keyfile
,
const
char
*
user
,
const
char
*
keyname
,
isc_buffer_t
*
secret
)
{
FILE
*
fd
;
fd
=
safe_create
(
keyfile
);
if
(
fd
==
NULL
)
{
fprintf
(
stderr
,
"unable to create
\"
%s
\"\n
"
,
keyfile
);
return
;
}
if
(
user
!=
NULL
)
{
if
(
set_user
(
fd
,
user
)
==
-
1
)
{
fprintf
(
stderr
,
"unable to set file owner
\n
"
);
fclose
(
fd
);
return
;
}
}
fprintf
(
fd
,
"key
\"
%s
\"
{
\n\t
algorithm hmac-md5;
\n
"
"
\t
secret
\"
%.*s
\"
;
\n
};
\n
"
,
keyname
,
(
int
)
isc_buffer_usedlength
(
secret
),
(
char
*
)
isc_buffer_base
(
secret
));
fflush
(
fd
);
if
(
ferror
(
fd
))
{
fprintf
(
stderr
,
"write to %s failed
\n
"
,
keyfile
);
fclose
(
fd
);
return
;
}
if
(
fclose
(
fd
))
{
fprintf
(
stderr
,
"fclose(%s) failed
\n
"
,
keyfile
);
return
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
isc_boolean_t
show_final_mem
=
ISC_FALSE
;
...
...
@@ -104,8 +143,6 @@ main(int argc, char **argv) {
char
*
user
=
NULL
;
isc_boolean_t
keyonly
=
ISC_FALSE
;
int
len
;
FILE
*
fd
;
char
*
buf
;
keydef
=
keyfile
=
RNDC_KEYFILE
;
...
...
@@ -241,74 +278,22 @@ main(int argc, char **argv) {
printf
(
"
\n\n
"
);
if
(
keyonly
)
{
fd
=
safe_create
(
keyfile
);
if
(
fd
==
NULL
)
{
fprintf
(
stderr
,
"unable to create
\"
%s
\"\n
"
,
keyfile
);
goto
cleanup
;
}
if
(
user
!=
NULL
&&
chrootdir
==
NULL
)
{
if
(
set_user
(
fd
,
user
)
==
-
1
)
{
fprintf
(
stderr
,
"unable to set file owner
\n
"
);
fclose
(
fd
);
goto
cleanup
;
}
}
fprintf
(
fd
,
"key
\"
%s
\"
{
\n\t
algorithm hmac-md5;
\n
"
"
\t
secret
\"
%.*s
\"
;
\n
};
\n
"
,
keyname
,
(
int
)
isc_buffer_usedlength
(
&
key_txtbuffer
),
(
char
*
)
isc_buffer_base
(
&
key_txtbuffer
));
fflush
(
fd
);
if
(
ferror
(
fd
))
{
fprintf
(
stderr
,
"write to %s failed
\n
"
,
keyfile
);
fclose
(
fd
);
goto
cleanup
;
}
if
(
fclose
(
fd
))
{
fprintf
(
stderr
,
"fclose(%s) failed
\n
"
,
keyfile
);
goto
cleanup
;
}
if
(
chrootdir
==
NULL
)
goto
cleanup
;
len
=
strlen
(
chrootdir
)
+
strlen
(
keyfile
)
+
2
;
buf
=
isc_mem_get
(
mctx
,
len
);
if
(
buf
!=
NULL
)
{
fprintf
(
stderr
,
"isc_mem_get(%d) failed
\n
"
,
len
);
goto
cleanup
;
}
snprintf
(
buf
,
len
,
"%s/%s"
,
chrootdir
,
keyfile
);
fd
=
safe_create
(
buf
);
if
(
fd
==
NULL
)
{
fprintf
(
stderr
,
"unable to create
\"
%s
\"\n
"
,
buf
);
isc_mem_put
(
mctx
,
buf
,
len
);
goto
cleanup
;
}
if
(
user
!=
NULL
)
{
if
(
set_user
(
fd
,
user
)
==
-
1
)
{
fprintf
(
stderr
,
"unable to set file owner
\n
"
);
fclose
(
fd
);
isc_mem_put
(
mctx
,
buf
,
len
);
write_key_file
(
keyfile
,
chrootdir
==
NULL
?
user
:
NULL
,
keyname
,
&
key_txtbuffer
);
if
(
chrootdir
!=
NULL
)
{
char
*
buf
;
len
=
strlen
(
chrootdir
)
+
strlen
(
keyfile
)
+
2
;
buf
=
isc_mem_get
(
mctx
,
len
);
if
(
buf
!=
NULL
)
{
fprintf
(
stderr
,
"isc_mem_get(%d) failed
\n
"
,
len
);
goto
cleanup
;
}
}
fprintf
(
fd
,
"key
\"
%s
\"
{
\n\t
algorithm hmac-md5;
\n
"
"
\t
secret
\"
%.*s
\"
;
\n
};
\n
"
,
keyname
,
(
int
)
isc_buffer_usedlength
(
&
key_txtbuffer
),
(
char
*
)
isc_buffer_base
(
&
key_txtbuffer
));
fflush
(
fd
);
if
(
ferror
(
fd
))
{
fprintf
(
stderr
,
"write to %s failed
\n
"
,
buf
);
fclose
(
fd
);
isc_mem_put
(
mctx
,
buf
,
len
);
goto
cleanup
;
}
if
(
fclose
(
fd
))
{
fprintf
(
stderr
,
"fclose(%s) failed
\n
"
,
buf
);
snprintf
(
buf
,
len
,
"%s/%s"
,
chrootdir
,
keyfile
);
write_key_file
(
buf
,
user
,
keyname
,
&
key_txtbuffer
);
isc_mem_put
(
mctx
,
buf
,
len
);
goto
cleanup
;
}
isc_mem_put
(
mctx
,
buf
,
len
);
}
else
{
printf
(
"\
# Start of rndc.conf
\n
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment