#include "check-tool.h"
-static const char *program = "named-checkconf";
-
#define CHECK(r) \
do { \
result = (r); \
fprintf(stderr,
"usage: %s [-achijlvz] [-p [-x]] [-t directory] "
"[named.conf]\n",
- program);
+ isc_commandline_progname);
exit(EXIT_SUCCESS);
}
unsigned int flags = 0;
unsigned int checkflags = BIND_CHECK_PLUGINS | BIND_CHECK_ALGORITHMS;
+ isc_commandline_init(argc, argv);
+
isc_commandline_errprint = false;
/*
}
isc_commandline_reset = true;
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != EOF) {
switch (c) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'h':
usage();
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
CHECK(ISC_R_FAILURE);
}
}
if (((flags & CFG_PRINTER_XKEY) != 0) && !print) {
- fprintf(stderr, "%s: -x cannot be used without -p\n", program);
+ fprintf(stderr, "%s: -x cannot be used without -p\n",
+ isc_commandline_progname);
CHECK(ISC_R_FAILURE);
}
if (print && list_zones) {
- fprintf(stderr, "%s: -l cannot be used with -p\n", program);
+ fprintf(stderr, "%s: -l cannot be used with -p\n",
+ isc_commandline_progname);
CHECK(ISC_R_FAILURE);
}
#include <isc/attributes.h>
#include <isc/commandline.h>
#include <isc/dir.h>
-#include <isc/file.h>
#include <isc/hash.h>
#include <isc/lib.h>
#include <isc/log.h>
dns_zonetype_t zonetype = dns_zone_primary;
static int dumpzone = 0;
static const char *output_filename;
-static const char *prog_name = NULL;
static const dns_master_style_t *outputstyle = NULL;
static enum { progmode_check, progmode_compile } progmode;
"[-M (ignore|warn|fail)] [-S (ignore|warn|fail)] "
"[-W (ignore|warn)] "
"%s zonename [ (filename|-) ]\n",
- prog_name,
+ isc_commandline_progname,
progmode == progmode_check ? "[-o filename]" : "-o filename");
exit(EXIT_FAILURE);
}
outputstyle = &dns_master_style_full;
- prog_name = strrchr(argv[0], '/');
- if (prog_name == NULL) {
- prog_name = strrchr(argv[0], '\\');
- }
- if (prog_name != NULL) {
- prog_name++;
- } else {
- prog_name = argv[0];
- }
- /*
- * Libtool doesn't preserve the program name prior to final
- * installation. Remove the libtool prefix ("lt-").
- */
- if (strncmp(prog_name, "lt-", 3) == 0) {
- prog_name += 3;
- }
+ isc_commandline_init(argc, argv);
-#define PROGCMP(X) \
- (strcasecmp(prog_name, X) == 0 || strcasecmp(prog_name, X ".exe") == 0)
-
- if (PROGCMP("named-checkzone")) {
+ if (strcasecmp(isc_commandline_progname, "named-checkzone") == 0) {
progmode = progmode_check;
- } else if (PROGCMP("named-compilezone")) {
+ } else if (strcasecmp(isc_commandline_progname, "named-compilezone") ==
+ 0)
+ {
progmode = progmode_compile;
} else {
UNREACHABLE();
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- prog_name, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'h':
usage();
default:
- fprintf(stderr, "%s: unhandled option -%c\n", prog_name,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
usage();
}
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
if (!quiet) {
RUNTIME_CHECK(setup_logging(errout) == ISC_R_SUCCESS);
}
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
-#include <isc/file.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/net.h>
#define DEFAULT_SERVER "127.0.0.1"
#define DEFAULT_PORT 953
-static char program[256];
-const char *progname;
-
bool verbose = false;
const char *keyfile, *keydef;
-s addr: the address to which rndc should connect\n\
-t chrootdir: write a keyfile in chrootdir as well (requires -a)\n\
-u user: set the keyfile owner to \"user\" (requires -a)\n",
- progname, keydef);
+ isc_commandline_progname, keydef);
exit(status);
}
isc_buffer_t key_txtbuffer;
char key_txtsecret[256];
isc_mem_t *mctx = NULL;
- isc_result_t result = ISC_R_SUCCESS;
const char *keyname = NULL;
const char *serveraddr = NULL;
dns_secalg_t alg;
bool keyonly = false;
bool quiet = false;
int len;
- const char *name = argv[0];
keydef = keyfile = RNDC_KEYFILE;
- result = isc_file_progname(*argv, program, sizeof(program));
- if (result != ISC_R_SUCCESS) {
- memmove(program, "rndc-confgen", 13);
- }
- progname = program;
+ isc_commandline_init(argc, argv);
keyname = DEFAULT_KEYNAME;
alg = DST_ALG_HMACSHA256;
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
usage(EXIT_FAILURE);
} else {
usage(EXIT_SUCCESS);
}
break;
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
}
algname = dst_hmac_algorithm_totext(alg);
- isc_mem_create(name, &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret));
generate_key(mctx, alg, keysize, &key_txtbuffer);
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
-#include <isc/file.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/net.h>
#define KEYGEN_DEFAULT "tsig-key"
#define CONFGEN_DEFAULT "ddns-key"
-static char program[256];
-const char *progname;
static enum { progmode_keygen, progmode_confgen } progmode;
bool verbose = false; /* needed by util.c but not used here */
-s name: domain name to be updated using the created key\n\
-z zone: name of the zone as it will be used in named.conf\n\
-q: quiet mode: print the key, with no explanatory text\n",
- progname);
+ isc_commandline_progname);
} else {
fprintf(stderr, "\
Usage:\n\
%s [-a alg] [keyname]\n\
-a alg: algorithm (default hmac-sha256)\n\n",
- progname);
+ isc_commandline_progname);
}
exit(status);
int
main(int argc, char **argv) {
- isc_result_t result = ISC_R_SUCCESS;
bool show_final_mem = false;
bool quiet = false;
isc_buffer_t key_txtbuffer;
int len = 0;
int ch;
- result = isc_file_progname(*argv, program, sizeof(program));
- if (result != ISC_R_SUCCESS) {
- memmove(program, "tsig-keygen", 11);
- }
- progname = program;
-
- /*
- * Libtool doesn't preserve the program name prior to final
- * installation. Remove the libtool prefix ("lt-").
- */
- if (strncmp(progname, "lt-", 3) == 0) {
- progname += 3;
- }
-
-#define PROGCMP(X) \
- (strcasecmp(progname, X) == 0 || strcasecmp(progname, X ".exe") == 0)
+ isc_commandline_init(argc, argv);
- if (PROGCMP("tsig-keygen")) {
+ if (strcasecmp(isc_commandline_progname, "tsig-keygen") == 0) {
progmode = progmode_keygen;
quiet = true;
- } else if (PROGCMP("ddns-confgen")) {
+ } else if (strcasecmp(isc_commandline_progname, "ddns-confgen") == 0) {
progmode = progmode_confgen;
} else {
UNREACHABLE();
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
usage(EXIT_FAILURE);
} else {
usage(EXIT_SUCCESS);
}
break;
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
/* Use canonical algorithm name */
algname = dst_hmac_algorithm_totext(alg);
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
if (keyname == NULL) {
const char *suffix = NULL;
#include <isc/tls.h>
+#include "isc/commandline.h"
#include "util.h"
extern bool verbose;
-extern const char *progname;
void
notify(const char *fmt, ...) {
fatal(const char *format, ...) {
va_list args;
- fprintf(stderr, "%s: ", progname);
+ fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
#include <isc/attributes.h>
#include <isc/base64.h>
#include <isc/buffer.h>
+#include <isc/commandline.h>
#include <isc/crypto.h>
#include <isc/hex.h>
#include <isc/lib.h>
#define MAX_RESTARTS 11
/* Variables used internally by delv. */
-char *progname = NULL;
static isc_mem_t *mctx = NULL;
static dns_view_t *view = NULL;
static ns_server_t *sctx = NULL;
va_list args;
fflush(stdout);
- fprintf(stderr, "%s: ", progname);
+ fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
va_list args;
fflush(stdout);
- fprintf(stderr, "%s: warning: ", progname);
+ fprintf(stderr, "%s: warning: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
isc_result_t result;
isc_loop_t *loop = NULL;
- progname = argv[0];
+ isc_commandline_init(argc, argv);
+
logfp = stderr;
preparse_args(argc, argv);
dighost_warning = dig_warning;
dighost_comments = dig_comments;
- progname = argv[0];
preparse_args(argc, argv);
- setup_libs();
+ setup_libs(argc, argv);
setup_system(ipv4only, ipv6only);
}
#endif /* HAVE_LIBIDN2 */
#include <isc/base64.h>
+#include <isc/commandline.h>
#include <isc/crypto.h>
#include <isc/file.h>
#include <isc/getaddresses.h>
bool debugging = false;
bool debugtiming = false;
bool memdebugging = false;
-char *progname = NULL;
dig_lookup_t *current_lookup = NULL;
#define DIG_MAX_ADDRESSES 20
va_list args;
fflush(stdout);
- fprintf(stderr, "%s: ", progname);
+ fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
va_list args;
fflush(stdout);
- fprintf(stderr, "%s: ", progname);
+ fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
* Setup the ISC and DNS libraries for use by the system.
*/
void
-setup_libs(void) {
+setup_libs(int argc, char **argv) {
isc_result_t result;
isc_logconfig_t *logconfig = NULL;
debug("setup_libs()");
+ isc_commandline_init(argc, argv);
+
result = isc_net_probeipv4();
if (result == ISC_R_SUCCESS) {
have_ipv4 = true;
extern bool debugging, debugtiming, memdebugging;
extern bool keep_open;
-extern char *progname;
extern int tries;
extern int fatalexit;
extern bool verbose;
void
run_loop(void *arg);
-int
-dhmain(int argc, char **argv);
-
void
-setup_libs(void);
+setup_libs(int argc, char **argv);
void
setup_system(bool ipv4only, bool ipv6only);
dighost_shutdown = host_shutdown;
debug("main()");
- progname = argv[0];
pre_parse_args(argc, argv);
- setup_libs();
+ setup_libs(argc, argv);
setup_system(ipv4only, ipv6only);
parse_args(false, argc, argv);
if (keyfile[0] != 0) {
dighost_trying = trying;
dighost_shutdown = start_next_command;
- setup_libs();
- progname = argv[0];
+ setup_libs(argc, argv);
setup_system(false, false);
parse_args(argc, argv);
#include "dnssectool.h"
-const char *program = "dnssec-cds";
-
/*
* Infrastructure
*/
fprintf(stderr, "Usage:\n");
fprintf(stderr,
" %s options [options] -f <file> -d <path> <domain>\n",
- program);
+ isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "Options:\n"
" -a <algorithm> digest algorithm (SHA-1 / "
setfatalcallback(cleanup);
- isc_mem_create(argv[0], &mctx);
+ isc_commandline_init(argc, argv);
+
+ isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
break;
case 'V':
/* Does not return. */
- version(program);
+ version(isc_commandline_progname);
break;
case 'v':
verbose = strtoul(isc_commandline_argument, &endp, 0);
#include "dnssectool.h"
-const char *program = "dnssec-dsfromkey";
-
static dns_rdataclass_t rdclass;
static dns_fixedname_t fixed;
static dns_name_t *name = NULL;
char keystr[DST_KEY_FORMATSIZE];
dst_key_format(key, keystr, sizeof(keystr));
- fprintf(stderr, "%s: %s\n", program, keystr);
+ fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
}
result = dst_key_todns(key, &keyb);
}
dst_key_format(key, keystr, sizeof(keystr));
- fprintf(stderr, "%s: %s\n", program, keystr);
+ fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
dst_key_free(&key);
}
static void
usage(void) {
fprintf(stderr, "Usage:\n");
- fprintf(stderr, " %s [options] keyfile\n\n", program);
- fprintf(stderr, " %s [options] -f zonefile [zonename]\n\n", program);
- fprintf(stderr, " %s [options] -s dnsname\n\n", program);
- fprintf(stderr, " %s [-h|-V]\n\n", program);
+ fprintf(stderr, " %s [options] keyfile\n\n",
+ isc_commandline_progname);
+ fprintf(stderr, " %s [options] -f zonefile [zonename]\n\n",
+ isc_commandline_progname);
+ fprintf(stderr, " %s [options] -s dnsname\n\n",
+ isc_commandline_progname);
+ fprintf(stderr, " %s [-h|-V]\n\n", isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "Options:\n"
" -1: digest algorithm SHA-1\n"
usage();
}
- isc_mem_create(argv[0], &mctx);
+ isc_commandline_init(argc, argv);
+
+ isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
fprintf(stderr,
"%s: the -d option is deprecated; "
"use -K\n",
- program);
+ isc_commandline_progname);
/* fall through */
case 'K':
dir = isc_commandline_argument;
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'h':
case 'V':
/* Does not return. */
- version(program);
+ version(isc_commandline_progname);
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
#include "dnssectool.h"
-const char *program = "dnssec-importkey";
-
static dns_rdataclass_t rdclass;
static dns_fixedname_t fixed;
static dns_name_t *name = NULL;
char keystr[DST_KEY_FORMATSIZE];
dst_key_format(key, keystr, sizeof(keystr));
- fprintf(stderr, "%s: %s\n", program, keystr);
+ fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
}
result = dst_key_todns(key, &keyb);
static void
usage(void) {
fprintf(stderr, "Usage:\n");
- fprintf(stderr, " %s options [-K dir] keyfile\n\n", program);
- fprintf(stderr, " %s options -f file [keyname]\n\n", program);
+ fprintf(stderr, " %s options [-K dir] keyfile\n\n",
+ isc_commandline_progname);
+ fprintf(stderr, " %s options -f file [keyname]\n\n",
+ isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -f file: read key from zone file\n");
usage();
}
- isc_mem_create(argv[0], &mctx);
+ isc_commandline_init(argc, argv);
+
+ isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'h':
case 'V':
/* Does not return. */
- version(program);
+ version(isc_commandline_progname);
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
#define MAX_RSA 4096 /* should be long enough... */
-const char *program = "dnssec-keyfromlabel";
-
static uint16_t tag_min = 0, tag_max = 0xffff;
ISC_NORETURN static void
static void
usage(void) {
fprintf(stderr, "Usage:\n");
- fprintf(stderr, " %s -l label [options] name\n\n", program);
+ fprintf(stderr, " %s -l label [options] name\n\n",
+ isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "Required options:\n");
fprintf(stderr, " -l label: label of the key pair\n");
usage();
}
- isc_mem_create(argv[0], &mctx);
+ isc_commandline_init(argc, argv);
+
+ isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'h':
case 'V':
/* Does not return. */
- version(program);
+ version(isc_commandline_progname);
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
"indefinitely after rollover.\n\t "
"You can use dnssec-settime -D to "
"change this.\n",
- program, keystr);
+ isc_commandline_progname, keystr);
}
setpub = setact = true;
"not flagged as a KSK, but -R "
"was used. Revoking a ZSK is "
"legal, but undefined.\n",
- program);
+ isc_commandline_progname);
}
dst_key_settime(key, DST_TIME_REVOKE, revoke);
}
isc_result_totext(ret));
}
if (exact) {
- fatal("%s: %s already exists\n", program, filename);
+ fatal("%s: %s already exists\n",
+ isc_commandline_progname, filename);
}
if (avoid_collisions) {
fatal("%s: %s could collide with another key upon "
"revokation\n",
- program, filename);
+ isc_commandline_progname, filename);
}
fprintf(stderr,
"another key upon revokation. If you plan "
"to revoke keys, destroy this key and "
"generate a different one.\n",
- program, filename);
+ isc_commandline_progname, filename);
}
ret = dst_key_tofile(key, options, directory);
#include "dnssectool.h"
-const char *program = "dnssec-keygen";
-
/*
* These are are set here for backwards compatibility. They are
* raised to 2048 in FIPS mode.
static void
usage(void) {
fprintf(stderr, "Usage:\n");
- fprintf(stderr, " %s [options] name\n\n", program);
+ fprintf(stderr, " %s [options] name\n\n", isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, " name: owner of the key\n");
fprintf(stderr, "Options:\n");
"indefinitely after rollover.\n\t "
"You can use dnssec-settime -D to "
"change this.\n",
- program, keystr);
+ isc_commandline_progname, keystr);
}
ctx->setpub = ctx->setact = true;
"not flagged as a KSK, but -R "
"was used. Revoking a ZSK is "
"legal, but undefined.\n",
- program);
+ isc_commandline_progname);
}
dst_key_settime(key, DST_TIME_REVOKE,
ctx->revokekey);
"scheduled to be deleted "
"before it is scheduled to be "
"made inactive.\n",
- program);
+ isc_commandline_progname);
}
dst_key_settime(key, DST_TIME_DELETE,
ctx->deltime);
"might collide with another "
"key upon revokation. "
"Generating a new key\n",
- program, filename);
+ isc_commandline_progname,
+ filename);
}
}
usage();
}
+ isc_commandline_init(argc, argv);
+
isc_commandline_errprint = false;
/*
}
isc_commandline_reset = true;
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
switch (ch) {
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'h':
case 'V':
/* Does not return. */
- version(program);
+ version(isc_commandline_progname);
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
#include "dnssectool.h"
-const char *program = "dnssec-ksr";
-
/*
* Infrastructure
*/
static void
usage(int ret) {
fprintf(stderr, "Usage:\n");
- fprintf(stderr, " %s options [options] <command> <zone>\n", program);
+ fprintf(stderr, " %s options [options] <command> <zone>\n",
+ isc_commandline_progname);
fprintf(stderr, "\n");
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "\n");
"might collide with another "
"key upon revokation. "
"Generating a new key\n",
- program, filename);
+ isc_commandline_progname,
+ filename);
}
}
dst_key_free(&key);
.now = isc_stdtime_now(),
};
- isc_mem_create(argv[0], &mctx);
+ isc_commandline_init(argc, argv);
+
+ isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
ksr.ksk = true;
break;
case 'V':
- version(program);
+ version(isc_commandline_progname);
break;
case 'v':
verbose = strtoul(isc_commandline_argument, &endp, 0);
#include "dnssectool.h"
-const char *program = "dnssec-revoke";
-
static isc_mem_t *mctx = NULL;
ISC_NORETURN static void
static void
usage(void) {
fprintf(stderr, "Usage:\n");
- fprintf(stderr, " %s [options] keyfile\n\n", program);
+ fprintf(stderr, " %s [options] keyfile\n\n",
+ isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, " -f: force overwrite\n");
fprintf(stderr, " -h: help\n");
bool removefile = false;
bool id = false;
+ isc_commandline_init(argc, argv);
+
if (argc == 1) {
usage();
}
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'h':
case 'V':
/* Does not return. */
- version(program);
+ version(isc_commandline_progname);
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
dst_key_format(key, keystr, sizeof(keystr));
if (verbose > 2) {
- fprintf(stderr, "%s: %s\n", program, keystr);
+ fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
}
if (force) {
"%s: warning: Key is not flagged "
"as a KSK. Revoking a ZSK is "
"legal, but undefined.\n",
- program);
+ isc_commandline_progname);
}
dst_key_settime(key, DST_TIME_REVOKE, now);
#include "dnssectool.h"
-const char *program = "dnssec-settime";
-
static isc_mem_t *mctx = NULL;
ISC_NORETURN static void
static void
usage(void) {
fprintf(stderr, "Usage:\n");
- fprintf(stderr, " %s [options] keyfile\n\n", program);
+ fprintf(stderr, " %s [options] keyfile\n\n",
+ isc_commandline_progname);
fprintf(stderr, "Version: %s\n", PACKAGE_VERSION);
fprintf(stderr, "General options:\n");
fprintf(stderr, " -f: force update of old-style "
bool printdsadd = false, printdsdel = false;
isc_stdtime_t now = isc_stdtime_now();
+ isc_commandline_init(argc, argv);
+
options = DST_TYPE_PUBLIC | DST_TYPE_PRIVATE | DST_TYPE_STATE;
if (argc == 1) {
usage();
}
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
setup_logging();
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'h':
break;
case 'V':
/* Does not return. */
- version(program);
+ version(isc_commandline_progname);
case 'v':
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0') {
break;
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
"removal date;\n\t"
"it will remain in the zone "
"indefinitely after rollover.\n",
- program);
+ isc_commandline_progname);
} else if (prevdel < previnact) {
fprintf(stderr,
"%s: warning: Predecessor is "
"scheduled to be deleted\n\t"
"before it is scheduled to be "
"inactive.\n",
- program);
+ isc_commandline_progname);
}
changed = setpub = setact = true;
"%s: warning: Key is scheduled to "
"be deleted before it is\n\t"
"scheduled to be inactive.\n",
- program);
+ isc_commandline_progname);
}
if (force) {
}
if (verbose > 2) {
- fprintf(stderr, "%s: %s\n", program, keystr);
+ fprintf(stderr, "%s: %s\n", isc_commandline_progname, keystr);
}
/*
"%s: warning: Key %s is already "
"revoked; changing the revocation date "
"will not affect this.\n",
- program, keystr);
+ isc_commandline_progname, keystr);
}
if ((dst_key_flags(key) & DNS_KEYFLAG_KSK) == 0) {
fprintf(stderr,
"%s: warning: Key %s is not flagged as "
"a KSK, but -R was used. Revoking a "
"ZSK is legal, but undefined.\n",
- program, keystr);
+ isc_commandline_progname, keystr);
}
dst_key_settime(key, DST_TIME_REVOKE, rev);
} else if (unsetrev) {
"%s: warning: Key %s is already "
"revoked; removing the revocation date "
"will not affect this.\n",
- program, keystr);
+ isc_commandline_progname, keystr);
}
dst_key_unsettime(key, DST_TIME_REVOKE);
}
#include "dnssectool.h"
-const char *program = "dnssec-signzone";
-
typedef struct hashlist hashlist_t;
static int nsec_datatype = dns_rdatatype_nsec;
fprintf(stderr,
"%s: warning: Serial number would not advance, "
"using increment method instead\n",
- program);
+ isc_commandline_progname);
}
/* If the new serial is not likely to cause a zone transfer
fprintf(stderr,
"%s: warning: Serial number not advanced, "
"zone may not transfer\n",
- program);
+ isc_commandline_progname);
}
dns_soa_setserial(new_serial, &rdata);
fprintf(stderr,
"%s: warning: No non-KSK DNSKEY found; "
"supply a ZSK or use '-z'.\n",
- program);
+ isc_commandline_progname);
} else {
fatal("No non-KSK DNSKEY found; "
"supply a ZSK or use '-z'.");
return;
}
- fprintf(fp, "; %s version %s\n", program, PACKAGE_VERSION);
+ fprintf(fp, "; %s version %s\n", isc_commandline_progname,
+ PACKAGE_VERSION);
}
ISC_NORETURN static void
static void
usage(void) {
fprintf(stderr, "Usage:\n");
- fprintf(stderr, "\t%s [options] zonefile [keys]\n", program);
+ fprintf(stderr, "\t%s [options] zonefile [keys]\n",
+ isc_commandline_progname);
fprintf(stderr, "\n");
atomic_init(&shuttingdown, false);
atomic_init(&finished, false);
+ isc_commandline_init(argc, argv);
+
/*
* Unused letters: Bb G J l q Yy (and F is reserved).
* l was previously used for DLV lookaside.
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'h':
case 'V':
/* Does not return. */
- version(program);
+ version(isc_commandline_progname);
case 'Z': /* Undocumented test options */
if (!strcmp(isc_commandline_argument, "nonsecify")) {
break;
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
fprintf(stderr,
"%s: warning: Specified key TTL %u "
"exceeds maximum zone TTL; reducing to %u\n",
- program, keyttl, maxttl);
+ isc_commandline_progname, keyttl, maxttl);
keyttl = maxttl;
}
fprintf(stderr,
"%s: warning: No keys specified "
"or found\n",
- program);
+ isc_commandline_progname);
} else {
fatal("No signing keys specified or found.");
}
fprintf(stderr,
"%s: warning: NSEC3 generation "
"requested with no DNSKEY; ignoring\n",
- program);
+ isc_commandline_progname);
} else if (result != ISC_R_SUCCESS) {
check_result(result, "dns_nsec_nseconly");
} else if (answer) {
#include <isc/attributes.h>
#include <isc/base32.h>
#include <isc/commandline.h>
-#include <isc/file.h>
#include <isc/hash.h>
#include <isc/hex.h>
#include <isc/lib.h>
#include "dnssectool.h"
-const char *program = "dnssec-verify";
-
static isc_stdtime_t now;
static isc_mem_t *mctx = NULL;
static dns_masterformat_t inputformat = dns_masterformat_text;
static void
usage(void) {
fprintf(stderr, "Usage:\n");
- fprintf(stderr, "\t%s [options] zonefile [keys]\n", program);
+ fprintf(stderr, "\t%s [options] zonefile [keys]\n",
+ isc_commandline_progname);
fprintf(stderr, "\n");
char *endp;
int ch;
+ isc_commandline_init(argc, argv);
+
#define CMDLINE_FLAGS "c:E:hJ:m:o:I:qv:Vxz"
/*
}
isc_commandline_reset = true;
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
isc_commandline_errprint = false;
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
}
FALLTHROUGH;
case 'V':
/* Does not return. */
- version(program);
+ version(isc_commandline_progname);
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/dir.h>
-#include <isc/file.h>
#include <isc/heap.h>
#include <isc/list.h>
#include <isc/log.h>
fatal(const char *format, ...) {
va_list args;
- fprintf(stderr, "%s: fatal: ", program);
+ fprintf(stderr, "%s: fatal: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
return;
}
va_start(ap, fmt);
- fprintf(stderr, "%s: ", program);
+ fprintf(stderr, "%s: ", isc_commandline_progname);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
logconfig = isc_logconfig_get();
- isc_log_settag(logconfig, program);
+ isc_log_settag(logconfig, isc_commandline_progname);
/*
* Set up a channel similar to default_stderr except:
if (!strcasecmp(isc_commandline_argument, arg)) {
if (argv[isc_commandline_index] == NULL) {
fprintf(stderr, "%s: missing argument -%c %s\n",
- program, isc_commandline_option,
+ isc_commandline_progname,
+ isc_commandline_option,
isc_commandline_argument);
usage();
}
result = dns_journal_open(mctx, file, DNS_JOURNAL_READ, &jnl);
if (result == ISC_R_NOTFOUND) {
- fprintf(stderr, "%s: journal file %s not found\n", program,
- file);
+ fprintf(stderr, "%s: journal file %s not found\n",
+ isc_commandline_progname, file);
goto cleanup;
} else if (result != ISC_R_SUCCESS) {
fatal("unable to open journal %s: %s\n", file,
extern int verbose;
extern bool quiet;
-/*! program name, statically initialized in each program */
-extern const char *program;
-
/*! journal file */
extern const char *journal;
extern unsigned int dns_zone_mkey_month;
static bool want_stats = false;
-static char program_name[NAME_MAX] = "named";
static char absolute_conffile[PATH_MAX];
static char saved_command_line[4096] = { 0 };
static char ellipsis[5] = { 0 };
ISC_LOG_NOTICE, "built with %s", PACKAGE_CONFIGARGS);
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_MAIN,
- ISC_LOG_NOTICE, "running as: %s%s%s", program_name,
- saved_command_line, ellipsis);
+ ISC_LOG_NOTICE, "running as: %s%s%s",
+ isc_commandline_progname, saved_command_line, ellipsis);
#ifdef __clang__
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "compiled by CLANG %s", __VERSION__);
"> (" __DATE__ ")",
#endif
sizeof(version));
- result = isc_file_progname(*argv, program_name, sizeof(program_name));
- if (result != ISC_R_SUCCESS) {
- named_main_earlyfatal("program name too long");
- }
+
+ isc_commandline_init(argc, argv);
isc_assertion_setcallback(assertion_failed);
isc_error_setfatal(library_fatal_error);
isc_error_setunexpected(library_unexpected_error);
- named_os_init(program_name);
+ named_os_init(isc_commandline_progname);
parse_command_line(argc, argv);
#include <stdbool.h>
#include <isc/buffer.h>
-#include <isc/file.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/result.h>
#define SERVERADDRS 10
#define RNDC_TIMEOUT 60 * 1000
-const char *progname = NULL;
bool verbose;
static isc_nm_t *netmgr = NULL;
static isc_mem_t *rndc_mctx = NULL;
static char *command = NULL;
static char *args = NULL;
-static char program[256];
static uint32_t serial;
static bool quiet = false;
static bool showresult = false;
Display the current status of a zone.\n\
\n\
Version: %s\n",
- progname, version);
+ isc_commandline_progname, version);
exit(status);
}
result = isccc_cc_lookupstring(data, "err", &errormsg);
if (result == ISC_R_SUCCESS) {
failed = true;
- fprintf(stderr, "%s: '%s' failed: %s\n", progname, command,
- errormsg);
+ fprintf(stderr, "%s: '%s' failed: %s\n",
+ isc_commandline_progname, command, errormsg);
} else if (result != ISC_R_NOTFOUND) {
- fprintf(stderr, "%s: parsing response failed: %s\n", progname,
- isc_result_totext(result));
+ fprintf(stderr, "%s: parsing response failed: %s\n",
+ isc_commandline_progname, isc_result_totext(result));
}
result = isccc_cc_lookupstring(data, "text", &textmsg);
fprintf(failed ? stderr : stdout, "%s\n", textmsg);
}
} else if (result != ISC_R_NOTFOUND) {
- fprintf(stderr, "%s: parsing response failed: %s\n", progname,
- isc_result_totext(result));
+ fprintf(stderr, "%s: parsing response failed: %s\n",
+ isc_commandline_progname, isc_result_totext(result));
}
if (showresult) {
int
main(int argc, char **argv) {
- isc_result_t result = ISC_R_SUCCESS;
bool show_final_mem = false;
isc_logconfig_t *logconfig = NULL;
cfg_parser_t *pctx = NULL;
int ch;
int i;
- result = isc_file_progname(*argv, program, sizeof(program));
- if (result != ISC_R_SUCCESS) {
- memmove(program, "rndc", 5);
- }
- progname = program;
+ isc_commandline_init(argc, argv);
admin_conffile = RNDC_CONFFILE;
admin_keyfile = RNDC_KEYFILE;
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
- program, isc_commandline_option);
+ isc_commandline_progname,
+ isc_commandline_option);
usage(1);
}
FALLTHROUGH;
usage(0);
break;
default:
- fprintf(stderr, "%s: unhandled option -%c\n", program,
+ fprintf(stderr, "%s: unhandled option -%c\n",
+ isc_commandline_progname,
isc_commandline_option);
exit(EXIT_FAILURE);
}
isc_nm_setkeepalivetimeout(netmgr, timeout);
logconfig = isc_logconfig_get();
- isc_log_settag(logconfig, progname);
+ isc_log_settag(logconfig, isc_commandline_progname);
isc_log_createandusechannel(
logconfig, "default_stderr", ISC_LOG_TOFILEDESC, ISC_LOG_INFO,
ISC_LOGDESTINATION_STDERR,
#include <stdlib.h>
#include <unistd.h>
+#include <isc/commandline.h>
#include <isc/tls.h>
extern bool verbose;
-extern const char *progname;
void
notify(const char *fmt, ...) {
fatal(const char *format, ...) {
va_list args;
- fprintf(stderr, "%s: ", progname);
+ fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
#include <stdbool.h>
#include <stdlib.h>
+#include <isc/commandline.h>
#include <isc/hash.h>
#include <isc/lib.h>
#include <isc/log.h>
dns_db_t *olddb = NULL, *newdb = NULL;
isc_logconfig_t *logconfig = NULL;
+ isc_commandline_init(argc, argv);
+
if (argc != 5) {
printf("usage: %s origin file1 file2 journal\n", argv[0]);
return 1;
journal = argv[4];
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
logconfig = isc_logconfig_get();
isc_log_createandusechannel(
#include <isc/buffer.h>
#include <isc/commandline.h>
-#include <isc/file.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/result.h>
bool yaml = false;
bool timestampmillis = false;
-const char *program = "dnstap-read";
-
-#define CHECKM(op, msg) \
- do { \
- result = (op); \
- if (result != ISC_R_SUCCESS) { \
- fprintf(stderr, "%s: %s: %s\n", program, msg, \
- isc_result_totext(result)); \
- goto cleanup; \
- } \
+#define CHECKM(op, msg) \
+ do { \
+ result = (op); \
+ if (result != ISC_R_SUCCESS) { \
+ fprintf(stderr, "%s: %s: %s\n", \
+ isc_commandline_progname, msg, \
+ isc_result_totext(result)); \
+ goto cleanup; \
+ } \
} while (0)
ISC_NORETURN static void
fatal(const char *format, ...) {
va_list args;
- fprintf(stderr, "%s: fatal: ", program);
+ fprintf(stderr, "%s: fatal: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
dns_dthandle_t *handle = NULL;
int rv = 0, ch;
+ isc_commandline_init(argc, argv);
+
while ((ch = isc_commandline_parse(argc, argv, "mptxy")) != -1) {
switch (ch) {
case 'm':
fatal("no file specified");
}
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
CHECKM(dns_dt_open(argv[0], dns_dtmode_file, mctx, &handle),
"dns_dt_openfile");
#include <dns/lib.h>
#include <dns/types.h>
-const char *progname = NULL;
-
static void
usage(void) {
- fprintf(stderr, "Usage: %s [-dux] journal\n", progname);
+ fprintf(stderr, "Usage: %s [-dux] journal\n", isc_commandline_progname);
exit(EXIT_FAILURE);
}
unsigned int serial = 0;
char *endp = NULL;
- progname = argv[0];
+ isc_commandline_init(argc, argv);
+
while ((ch = isc_commandline_parse(argc, argv, "c:dux")) != -1) {
switch (ch) {
case 'c':
}
file = argv[0];
- isc_mem_create(argv[0], &mctx);
+ isc_mem_create(isc_commandline_progname, &mctx);
setup_logging(stderr);
if (upgrade) {
#include <isc/base32.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
-#include <isc/file.h>
#include <isc/hex.h>
#include <isc/iterated_hash.h>
#include <isc/lib.h>
#include <dns/nsec3.h>
#include <dns/types.h>
-const char *program = "nsec3hash";
-
ISC_NORETURN static void
fatal(const char *format, ...);
fatal(const char *format, ...) {
va_list args;
- fprintf(stderr, "%s: ", program);
+ fprintf(stderr, "%s: ", isc_commandline_progname);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
static void
usage(void) {
fprintf(stderr, "Usage: %s salt algorithm iterations domain\n",
- program);
+ isc_commandline_progname);
fprintf(stderr, " %s -r algorithm flags iterations salt domain\n",
- program);
+ isc_commandline_progname);
exit(EXIT_FAILURE);
}
bool rdata_format = false;
int ch;
+ isc_commandline_init(argc, argv);
+
while ((ch = isc_commandline_parse(argc, argv, "-r")) != -1) {
switch (ch) {
case 'r':
#include <stdbool.h>
#include <stdio.h>
+#include <zconf.h>
#include <isc/commandline.h>
+#include <isc/file.h>
#include <isc/mem.h>
#include <isc/string.h>
#include <isc/util.h>
/*% Argument associated with option. */
char *isc_commandline_argument;
/*% For printing error messages. */
-char *isc_commandline_progname;
+char isc_commandline_progname[NAME_MAX];
/*% Print error messages. */
bool isc_commandline_errprint = true;
/*% Reset processing. */
bool isc_commandline_reset = true;
+void
+isc_commandline_init(int argc ISC_ATTR_UNUSED, char *const *argv) {
+ isc_file_progname(argv[0], isc_commandline_progname,
+ sizeof(isc_commandline_progname));
+}
+
static char endopt = '\0';
#define BADOPT '?'
isc_commandline_reset = false;
}
- if (isc_commandline_progname == NULL) {
- isc_commandline_progname = argv[0];
- }
-
if (isc_commandline_index >= argc ||
*(place = argv[isc_commandline_index]) != '-')
{
return s + 1;
}
-isc_result_t
+void
isc_file_progname(const char *filename, char *buf, size_t buflen) {
const char *base;
size_t len;
REQUIRE(buf != NULL);
base = isc_file_basename(filename);
- len = strlen(base) + 1;
- if (len > buflen) {
- return ISC_R_NOSPACE;
+ /*
+ * Libtool doesn't preserve the program name prior to final
+ * installation. Remove the libtool prefix ("lt-").
+ */
+ if (strncmp(base, "lt-", 3) == 0) {
+ base += 3;
}
- memmove(buf, base, len);
- return ISC_R_SUCCESS;
+ len = strlen(base) + 1;
+
+ RUNTIME_CHECK(len <= buflen);
+
+ memmove(buf, base, len);
}
/*
/*! \file isc/commandline.h */
#include <stdbool.h>
+#include <zconf.h>
#include <isc/result.h>
#include <isc/types.h>
/*% Argument associated with option. */
extern char *isc_commandline_argument;
/*% For printing error messages. */
-extern char *isc_commandline_progname;
+extern char isc_commandline_progname[NAME_MAX];
/*% Print error message. */
extern bool isc_commandline_errprint;
/*% Reset getopt. */
extern bool isc_commandline_reset;
+void
+isc_commandline_init(int argc, char *const *argv);
+/*%<
+ * Initialize isc_commandline unit internal and external variables.
+ * Currently, this only initializes isc_commandline_progname.
+ */
+
int
isc_commandline_parse(int argc, char *const *argv, const char *options);
/*%<
* Return the final component of the path in the file name.
*/
-isc_result_t
+void
isc_file_progname(const char *filename, char *buf, size_t buflen);
/*!<
* \brief Given an operating system specific file name "filename"
* names are case insensitive, the name is canonicalized to all
* lower case. The name is written to 'buf', an array of 'buflen'
* chars, and null terminated.
- *
- * Returns:
- *\li #ISC_R_SUCCESS
- *\li #ISC_R_NOSPACE The name did not fit in 'buf'.
*/
isc_result_t