Commit 3de75141 authored by Brian Wellington's avatar Brian Wellington
Browse files

Modified commandline parameters

parent f6afa4ac
......@@ -34,6 +34,8 @@
#include <dns/result.h>
#include <dns/time.h>
#define PROGRAM "keysettool"
#define BUFSIZE 2048
typedef struct keynode keynode_t;
......@@ -53,14 +55,14 @@ static keylist_t keylist;
static inline void
fatal(char *message) {
fprintf(stderr, "%s\n", message);
fprintf(stderr, "%s: %s\n", PROGRAM, message);
exit(1);
}
static inline void
check_result(isc_result_t result, char *message) {
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "%s: %s\n", message,
fprintf(stderr, "%s: %s: %s\n", PROGRAM, message,
isc_result_totext(result));
exit(1);
}
......@@ -93,7 +95,7 @@ strtotime(char *str, isc_int64_t now, isc_int64_t base) {
static void
usage() {
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\tkeysettool [options] domain keyfiles\n");
fprintf(stderr, "\tkeysettool [options] keys\n");
fprintf(stderr, "\n");
......@@ -109,11 +111,8 @@ usage() {
fprintf(stderr, "\n");
fprintf(stderr, "domain:\n");
fprintf(stderr, "\tdomain name associated with the keys\n");
fprintf(stderr, "Keyfiles:\n");
fprintf(stderr, "\tid/alg:\t\t");
fprintf(stderr, "key matching keyid, algorithm, and domain\n");
fprintf(stderr, "keys:\n");
fprintf(stderr, "\tkeyfile (Kname+alg+id)\n");
exit(0);
}
......@@ -121,9 +120,8 @@ int
main(int argc, char *argv[]) {
int i, ch;
char *startstr = NULL, *endstr = NULL;
char tdomain[1025];
dns_fixedname_t fdomain;
dns_name_t *domain;
dns_name_t *domain = NULL;
char *output = NULL;
char *endp;
unsigned char *data;
......@@ -188,7 +186,7 @@ main(int argc, char *argv[]) {
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc < 2)
if (argc < 1)
usage();
isc_stdtime_get(&now);
......@@ -209,7 +207,8 @@ main(int argc, char *argv[]) {
if (ttl == -1) {
ttl = 3600;
fprintf(stderr, "TTL not specified, assuming 3600\n");
fprintf(stderr, "%s: TTL not specified, assuming 3600\n",
PROGRAM);
}
if (verbose > 0) {
......@@ -222,28 +221,6 @@ main(int argc, char *argv[]) {
NULL, NULL) == ISC_R_SUCCESS);
}
dns_fixedname_init(&fdomain);
domain = dns_fixedname_name(&fdomain);
isc_buffer_init(&b, argv[0], strlen(argv[0]));
isc_buffer_add(&b, strlen(argv[0]));
result = dns_name_fromtext(domain, &b, dns_rootname, ISC_FALSE, NULL);
check_result(result, "dns_name_fromtext()");
isc_buffer_init(&b, tdomain, sizeof(tdomain) - 1);
result = dns_name_totext(domain, ISC_FALSE, &b);
check_result(result, "dns_name_totext()");
isc_buffer_usedregion(&b, &r);
tdomain[r.length] = 0;
output = isc_mem_allocate(mctx,
strlen(tdomain) + strlen("keyset") + 1);
if (output == NULL)
check_result(ISC_R_FAILURE, "isc_mem_allocate()");
strcpy(output, tdomain);
strcat(output, "keyset");
argc -= 1;
argv += 1;
dns_rdatalist_init(&rdatalist);
rdatalist.rdclass = dns_rdataclass_in;
rdatalist.type = dns_rdatatype_key;
......@@ -253,32 +230,43 @@ main(int argc, char *argv[]) {
ISC_LIST_INIT(keylist);
for (i = 0; i < argc; i++) {
int id, alg;
char *idstr = NULL, *algstr = NULL;
idstr = argv[i];
algstr = strchr(idstr, '/');
if (algstr == NULL)
isc_uint16_t id;
int alg;
char *namestr = NULL;
isc_buffer_init(&b, argv[i], strlen(argv[i]));
isc_buffer_add(&b, strlen(argv[i]));
result = dst_key_parsefilename(&b, mctx, &namestr, &id, &alg,
NULL);
if (result != ISC_R_SUCCESS)
usage();
*algstr++ = 0;
endp = NULL;
id = strtol(idstr, &endp, 10);
if (*endp != '\0')
check_result(ISC_R_FAILURE, "strtol");
endp = NULL;
alg = strtol(algstr, &endp, 10);
if (*endp != '\0')
check_result(ISC_R_FAILURE, "strtol");
if (output == NULL) {
output = isc_mem_allocate(mctx,
strlen(namestr) +
strlen("keyset") + 1);
if (output == NULL)
check_result(ISC_R_NOMEMORY,
"isc_mem_allocate()");
strcpy(output, namestr);
strcat(output, "keyset");
}
if (domain == NULL) {
dns_fixedname_init(&fdomain);
domain = dns_fixedname_name(&fdomain);
isc_buffer_init(&b, namestr, strlen(namestr));
isc_buffer_add(&b, strlen(namestr));
result = dns_name_fromtext(domain, &b, dns_rootname,
ISC_FALSE, NULL);
check_result(result, "dns_name_fromtext()");
}
key = NULL;
result = dst_key_fromfile(tdomain, id, alg, DST_TYPE_PUBLIC,
result = dst_key_fromfile(namestr, id, alg, DST_TYPE_PUBLIC,
mctx, &key);
check_result(result, "dst_key_fromfile");
if (dst_key_iszonekey(key)) {
dst_key_t *zonekey = NULL;
result = dst_key_fromfile(tdomain, id, alg,
result = dst_key_fromfile(namestr, id, alg,
DST_TYPE_PRIVATE, mctx,
&zonekey);
check_result(result, "dst_key_fromfile()");
......@@ -302,6 +290,7 @@ main(int argc, char *argv[]) {
dns_rdata_fromregion(rdata, dns_rdataclass_in,
dns_rdatatype_key, &r);
ISC_LIST_APPEND(rdatalist.rdata, rdata, link);
isc_mem_put(mctx, namestr, strlen(namestr) + 1);
dst_key_free(key);
}
......@@ -317,7 +306,8 @@ main(int argc, char *argv[]) {
if (ISC_LIST_EMPTY(keylist))
fprintf(stderr,
"no private zone key found; not self-signing\n");
"%s: no private zone key found; not self-signing\n",
PROGRAM);
for (keynode = ISC_LIST_HEAD(keylist);
keynode != NULL;
keynode = ISC_LIST_NEXT(keynode, link))
......
......@@ -33,6 +33,8 @@
#include <dns/rdatastruct.h>
#include <dns/result.h>
#define PROGRAM "keysigner"
#define BUFSIZE 2048
typedef struct keynode keynode_t;
......@@ -51,14 +53,14 @@ static keylist_t keylist;
static inline void
fatal(char *message) {
fprintf(stderr, "%s\n", message);
fprintf(stderr, "%s: %s\n", PROGRAM, message);
exit(1);
}
static inline void
check_result(isc_result_t result, char *message) {
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "%s: %s\n", message,
fprintf(stderr, "%s: %s: %s\n", PROGRAM, message,
isc_result_totext(result));
exit(1);
}
......@@ -80,8 +82,7 @@ usage() {
fprintf(stderr, "keyset:\n");
fprintf(stderr, "\tfile name of key set to be signed\n");
fprintf(stderr, "keys:\n");
fprintf(stderr, "\tname/id/alg:\t\t");
fprintf(stderr, "key matching name, keyid, algorithm\n");
fprintf(stderr, "\tkeyfile (Kname+alg+id)\n");
exit(0);
}
......@@ -280,33 +281,22 @@ main(int argc, char *argv[]) {
sigrdatalist.ttl = rdataset.ttl;
for (i = 0; i < argc; i++) {
int id, alg;
char *namestr, *idstr = NULL, *algstr = NULL;
namestr = argv[i];
idstr = strchr(namestr, '/');
if (idstr == NULL)
usage();
*idstr++ = 0;
algstr = strchr(idstr, '/');
if (algstr == NULL)
isc_uint16_t id;
int alg;
char *namestr = NULL;
isc_buffer_init(&b, argv[i], strlen(argv[i]));
isc_buffer_add(&b, strlen(argv[i]));
result = dst_key_parsefilename(&b, mctx, &namestr, &id, &alg,
NULL);
if (result != ISC_R_SUCCESS)
usage();
*algstr++ = 0;
endp = NULL;
id = strtol(idstr, &endp, 10);
if (*endp != '\0')
check_result(ISC_R_FAILURE, "strtol");
endp = NULL;
alg = strtol(algstr, &endp, 10);
if (*endp != '\0')
check_result(ISC_R_FAILURE, "strtol");
key = NULL;
result = dst_key_fromfile(namestr, id, alg, DST_TYPE_PRIVATE,
mctx, &key);
check_result (result, "dst_key_fromfile()");
isc_mem_put(mctx, namestr, strlen(namestr) + 1);
rdata = isc_mem_get(mctx, sizeof(dns_rdata_t));
if (rdata == NULL)
......
......@@ -43,6 +43,8 @@
#include <dst/result.h>
#define PROGRAM "signer"
/*#define USE_ZONESTATUS*/
#define BUFSIZE 2048
......@@ -71,14 +73,14 @@ static isc_mem_t *mctx = NULL;
static inline void
fatal(char *message) {
fprintf(stderr, "%s\n", message);
fprintf(stderr, "%s: %s\n", PROGRAM, message);
exit(1);
}
static inline void
check_result(isc_result_t result, char *message) {
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "%s: %s\n", message,
fprintf(stderr, "%s: %s: %s\n", PROGRAM, message,
isc_result_totext(result));
exit(1);
}
......@@ -90,6 +92,7 @@ vbprintf(int level, const char *fmt, ...) {
if (level > verbose)
return;
va_start(ap, fmt);
fprintf(stderr, "%s: ", PROGRAM);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
......@@ -736,11 +739,12 @@ signname(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node,
static int warnwild = 0;
if (dns_name_iswildcard(name)) {
fprintf(stderr, "Warning: wildcard name seen: %s\n",
nametostr(name));
if (warnwild++ == 0)
fprintf(stderr, "\tBIND 9 doesn't completely handle "
"wildcards in secure zones\n");
fprintf(stderr, "%s: warning: BIND 9 doesn't "
"handle wildcards in secure zones\n", PROGRAM);
else
fprintf(stderr, "%s: warning: wildcard name seen: %s\n",
PROGRAM, nametostr(name));
}
if (!atorigin) {
dns_rdataset_t nsset;
......@@ -1201,7 +1205,7 @@ dumpzone(dns_zone_t *zone, char *filename) {
fp = fopen(filename, "w");
if (fp == NULL) {
fprintf(stderr, "failure opening %s\n", filename);
fprintf(stderr, "%s: failure opening %s\n", PROGRAM, filename);
exit(-1);
}
result = dns_zone_dumptostream(zone, fp);
......@@ -1263,12 +1267,7 @@ usage() {
fprintf(stderr, "Signing Keys: ");
fprintf(stderr, "(default: all zone keys that have private keys)\n");
fprintf(stderr, "\tid:\t\t");
fprintf(stderr, "zone key with matching keyid\n");
fprintf(stderr, "\tid/alg:\t\t");
fprintf(stderr, "zone key with matching keyid and algorithm\n");
fprintf(stderr, "\tname/id/alg:\t");
fprintf(stderr, "key with matching name, keyid and algorithm\n");
fprintf(stderr, "\tkeyfile (Kname+alg+id)\n");
exit(0);
}
......@@ -1475,59 +1474,38 @@ main(int argc, char *argv[]) {
}
else {
for (i = 0; i < argc; i++) {
int id, alg;
char *idstr = NULL, *name = NULL, *algstr = NULL, *s;
idstr = argv[i];
algstr = strchr(idstr, '/');
if (algstr != NULL) {
*algstr++ = 0;
s = strchr(algstr, '/');
if (s != NULL) {
*s++ = 0;
name = idstr;
idstr = algstr;
algstr = s;
}
}
endp = NULL;
id = strtol(idstr, &endp, 0);
if (*endp != '\0')
check_result(ISC_R_FAILURE, "strtol");
isc_uint16_t id;
int alg;
char *namestr = NULL;
isc_buffer_t b;
if (algstr != NULL) {
endp = NULL;
alg = strtol(algstr, &endp, 0);
if (*endp != '\0')
check_result(ISC_R_FAILURE, "strtol");
}
else
alg = 0;
isc_buffer_init(&b, argv[i], strlen(argv[i]));
isc_buffer_add(&b, strlen(argv[i]));
result = dst_key_parsefilename(&b, mctx, &namestr,
&id, &alg, NULL);
if (result != ISC_R_SUCCESS)
usage();
if (name == NULL)
name = origin;
key = ISC_LIST_HEAD(keylist);
while (key != NULL) {
dst_key_t *dkey = key->key;
if (dst_key_id(dkey) == id &&
(alg == 0 || dst_key_alg(dkey) == alg) &&
strcasecmp(name, dst_key_name(dkey)) == 0)
dst_key_alg(dkey) == alg &&
strcasecmp(namestr,
dst_key_name(dkey)) == 0)
{
key->isdefault = ISC_TRUE;
if (!dst_key_isprivate(dkey))
check_result
(DST_R_NOTPRIVATEKEY,
"key specify");
if (alg == 0)
alg = dst_key_alg(dkey);
break;
}
key = ISC_LIST_NEXT(key, link);
}
if (key == NULL && alg != 0) {
if (key == NULL) {
dst_key_t *dkey = NULL;
result = dst_key_fromfile(name, id, alg,
result = dst_key_fromfile(namestr, id, alg,
DST_TYPE_PRIVATE,
mctx, &dkey);
check_result (result, "dst_key_fromfile");
......@@ -1539,8 +1517,7 @@ main(int argc, char *argv[]) {
key->isdefault = ISC_TRUE;
ISC_LIST_APPEND(keylist, key, link);
}
else
printf("Ignoring key with algorithm 0\n");
isc_mem_put(mctx, namestr, strlen(namestr) + 1);
}
}
......
......@@ -34,6 +34,8 @@
#include <dns/result.h>
#include <dns/time.h>
#define PROGRAM "keysettool"
#define BUFSIZE 2048
typedef struct keynode keynode_t;
......@@ -53,14 +55,14 @@ static keylist_t keylist;
static inline void
fatal(char *message) {
fprintf(stderr, "%s\n", message);
fprintf(stderr, "%s: %s\n", PROGRAM, message);
exit(1);
}
static inline void
check_result(isc_result_t result, char *message) {
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "%s: %s\n", message,
fprintf(stderr, "%s: %s: %s\n", PROGRAM, message,
isc_result_totext(result));
exit(1);
}
......@@ -93,7 +95,7 @@ strtotime(char *str, isc_int64_t now, isc_int64_t base) {
static void
usage() {
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\tkeysettool [options] domain keyfiles\n");
fprintf(stderr, "\tkeysettool [options] keys\n");
fprintf(stderr, "\n");
......@@ -109,11 +111,8 @@ usage() {
fprintf(stderr, "\n");
fprintf(stderr, "domain:\n");
fprintf(stderr, "\tdomain name associated with the keys\n");
fprintf(stderr, "Keyfiles:\n");
fprintf(stderr, "\tid/alg:\t\t");
fprintf(stderr, "key matching keyid, algorithm, and domain\n");
fprintf(stderr, "keys:\n");
fprintf(stderr, "\tkeyfile (Kname+alg+id)\n");
exit(0);
}
......@@ -121,9 +120,8 @@ int
main(int argc, char *argv[]) {
int i, ch;
char *startstr = NULL, *endstr = NULL;
char tdomain[1025];
dns_fixedname_t fdomain;
dns_name_t *domain;
dns_name_t *domain = NULL;
char *output = NULL;
char *endp;
unsigned char *data;
......@@ -188,7 +186,7 @@ main(int argc, char *argv[]) {
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc < 2)
if (argc < 1)
usage();
isc_stdtime_get(&now);
......@@ -209,7 +207,8 @@ main(int argc, char *argv[]) {
if (ttl == -1) {
ttl = 3600;
fprintf(stderr, "TTL not specified, assuming 3600\n");
fprintf(stderr, "%s: TTL not specified, assuming 3600\n",
PROGRAM);
}
if (verbose > 0) {
......@@ -222,28 +221,6 @@ main(int argc, char *argv[]) {
NULL, NULL) == ISC_R_SUCCESS);
}
dns_fixedname_init(&fdomain);
domain = dns_fixedname_name(&fdomain);
isc_buffer_init(&b, argv[0], strlen(argv[0]));
isc_buffer_add(&b, strlen(argv[0]));
result = dns_name_fromtext(domain, &b, dns_rootname, ISC_FALSE, NULL);
check_result(result, "dns_name_fromtext()");
isc_buffer_init(&b, tdomain, sizeof(tdomain) - 1);
result = dns_name_totext(domain, ISC_FALSE, &b);
check_result(result, "dns_name_totext()");
isc_buffer_usedregion(&b, &r);
tdomain[r.length] = 0;
output = isc_mem_allocate(mctx,
strlen(tdomain) + strlen("keyset") + 1);
if (output == NULL)
check_result(ISC_R_FAILURE, "isc_mem_allocate()");
strcpy(output, tdomain);
strcat(output, "keyset");
argc -= 1;
argv += 1;
dns_rdatalist_init(&rdatalist);
rdatalist.rdclass = dns_rdataclass_in;
rdatalist.type = dns_rdatatype_key;
......@@ -253,32 +230,43 @@ main(int argc, char *argv[]) {
ISC_LIST_INIT(keylist);
for (i = 0; i < argc; i++) {
int id, alg;
char *idstr = NULL, *algstr = NULL;
idstr = argv[i];
algstr = strchr(idstr, '/');
if (algstr == NULL)
isc_uint16_t id;
int alg;
char *namestr = NULL;
isc_buffer_init(&b, argv[i], strlen(argv[i]));
isc_buffer_add(&b, strlen(argv[i]));
result = dst_key_parsefilename(&b, mctx, &namestr, &id, &alg,
NULL);
if (result != ISC_R_SUCCESS)
usage();
*algstr++ = 0;
endp = NULL;
id = strtol(idstr, &endp, 10);
if (*endp != '\0')
check_result(ISC_R_FAILURE, "strtol");
endp = NULL;
alg = strtol(algstr, &endp, 10);
if (*endp != '\0')
check_result(ISC_R_FAILURE, "strtol");
if (output == NULL) {
output = isc_mem_allocate(mctx,
strlen(namestr) +
strlen("keyset") + 1);
if (output == NULL)
check_result(ISC_R_NOMEMORY,
"isc_mem_allocate()");
strcpy(output, namestr);
strcat(output, "keyset");
}
if (domain == NULL) {
dns_fixedname_init(&fdomain);
domain = dns_fixedname_name(&fdomain);
isc_buffer_init(&b, namestr, strlen(namestr));
isc_buffer_add(&b, strlen(namestr));
result = dns_name_fromtext(domain, &b, dns_rootname,
ISC_FALSE, NULL);
check_result(result, "dns_name_fromtext()");
}
key = NULL;
result = dst_key_fromfile(tdomain, id, alg, DST_TYPE_PUBLIC,
result = dst_key_fromfile(namestr, id, alg, DST_TYPE_PUBLIC,
mctx, &key);
check_result(result, "dst_key_fromfile");
if (dst_key_iszonekey(key)) {
dst_key_t *zonekey = NULL;
result = dst_key_fromfile(tdomain, id, alg,
result = dst_key_fromfile(namestr, id, alg,
DST_TYPE_PRIVATE, mctx,
&zonekey);
check_result(result, "dst_key_fromfile()");
......@@ -302,6 +290,7 @@ main(int argc, char *argv[]) {
dns_rdata_fromregion(rdata, dns_rdataclass_in,
dns_rdatatype_key, &r);
ISC_LIST_APPEND(rdatalist.rdata, rdata, link);
isc_mem_put(mctx, namestr, strlen(namestr) + 1);
dst_key_free(key);
}
......@@ -317,7 +306,8 @@ main(int argc, char *argv[]) {
if (ISC_LIST_EMPTY(keylist))
fprintf(stderr,
"no private zone key found; not self-signing\n");
"%s: no private zone key found; not self-signing\n",
PROGRAM);
for (keynode = ISC_LIST_HEAD(keylist);
keynode != NULL;
keynode = ISC_LIST_NEXT(keynode, link))
......
......@@ -33,6 +33,8 @@
#include <dns/rdatastruct.h>
#include <dns/result.h>
#define PROGRAM "keysigner"
#define BUFSIZE 2048
typedef struct keynode keynode_t;
......@@ -51,14 +53,14 @@ static keylist_t keylist;
static inline void
fatal(char *message) {
fprintf