30
32
#endif /* HAVE_LIBREADLINE || HAVE_LIBEDIT */
33
/* vxWorks needs mode flag -casey*/
34
#define open(name, flags) open(name, flags, 0777)
35
#define SERVER_PORT_NUM 123
35
/* vxWorks needs mode flag -casey*/
36
# define open(name, flags) open(name, flags, 0777)
37
# define SERVER_PORT_NUM 123
40
/* We use COMMAND as an autogen keyword */
105
118
{ "help", help, { OPT|NTP_STR, NO, NO, NO },
106
119
{ "command", "", "", "" },
107
120
"tell the use and syntax of commands" },
108
{ "timeout", timeout, { OPT|UINT, NO, NO, NO },
121
{ "timeout", timeout, { OPT|NTP_UINT, NO, NO, NO },
109
122
{ "msec", "", "", "" },
110
123
"set the primary receive time out" },
111
{ "delay", my_delay, { OPT|INT, NO, NO, NO },
124
{ "delay", my_delay, { OPT|NTP_INT, NO, NO, NO },
112
125
{ "msec", "", "", "" },
113
126
"set the delay added to encryption time stamps" },
114
127
{ "host", host, { OPT|NTP_STR, OPT|NTP_STR, NO, NO },
129
142
{ "exit", quit, { NO, NO, NO, NO },
130
143
{ "", "", "", "" },
132
{ "keyid", keyid, { OPT|UINT, NO, NO, NO },
145
{ "keyid", keyid, { OPT|NTP_UINT, NO, NO, NO },
133
146
{ "key#", "", "", "" },
134
147
"set/show keyid to use for authenticated requests" },
135
148
{ "keytype", keytype, { OPT|NTP_STR, NO, NO, NO },
154
167
#define MAXCMDS 100 /* maximum commands on cmd line */
155
168
#define MAXHOSTS 200 /* maximum hosts on cmd line */
156
169
#define MAXLINE 512 /* maximum line length */
157
#define MAXTOKENS (1+1+MAXARGS+2) /* maximum number of usable tokens */
158
/* command + -4|-6 + MAXARGS + */
170
#define MAXTOKENS (1+1+MAXARGS+MOREARGS+2) /* maximum number of usable tokens */
171
#define SCREENWIDTH 78 /* nominal screen width in columns */
162
174
* Some variables used and manipulated locally
317
322
progname = argv[0];
325
int optct = optionProcess(&ntpdcOptions, argc, argv);
330
switch (WHICH_IDX_IPV4) {
332
ai_fam_templ = AF_INET;
335
ai_fam_templ = AF_INET6;
338
ai_fam_templ = ai_fam_default;
342
if (HAVE_OPT(COMMAND)) {
343
int cmdct = STACKCT_OPT( COMMAND );
344
const char** cmds = STACKLST_OPT( COMMAND );
346
while (cmdct-- > 0) {
351
debug = DESC(DEBUG_LEVEL).optOccCt;
353
if (HAVE_OPT(INTERACTIVE)) {
357
if (HAVE_OPT(NUMERIC)) {
361
if (HAVE_OPT(LISTPEERS)) {
365
if (HAVE_OPT(PEERS)) {
369
if (HAVE_OPT(SHOWPEERS)) {
373
if (ntp_optind == argc) {
376
for (; ntp_optind < argc; ntp_optind++)
377
ADDHOST(argv[ntp_optind]);
380
if (numcmds == 0 && interactive == 0
381
&& isatty(fileno(stdin)) && isatty(fileno(stderr))) {
318
386
ai_fam_templ = ai_fam_default;
319
387
while ((c = ntp_getopt(argc, argv, "46c:dilnps")) != EOF)
854
931
qpkt.mbz_itemsize = MBZ_ITEMSIZE(qsize);
856
933
qpkt.err_nitems = ERR_NITEMS(0, 0);
857
qpkt.mbz_itemsize = MBZ_ITEMSIZE(0);
934
qpkt.mbz_itemsize = MBZ_ITEMSIZE(qsize); /* allow for optional first item */
937
if (!auth || (keyid_entered && info_auth_keyid == 0)) {
861
938
qpkt.auth_seq = AUTH_SEQ(0, 0);
862
939
return sendpkt((char *)&qpkt, req_pkt_size);
870
947
+ MAX_MAC_LEN - sizeof(struct req_pkt_tail));
872
949
if (info_auth_keyid == 0) {
873
maclen = getkeyid("Keyid: ");
875
(void) fprintf(stderr,
876
"Invalid key identifier\n");
950
if (((struct conf_peer *)qpkt.data)->keyid > 0)
951
info_auth_keyid = ((struct conf_peer *)qpkt.data)->keyid;
953
maclen = getkeyid("Keyid: ");
955
(void) fprintf(stderr,
956
"Invalid key identifier\n");
959
info_auth_keyid = maclen;
879
info_auth_keyid = maclen;
881
962
if (!authistrusted(info_auth_keyid)) {
882
963
pass = getpass("MD5 Password: ");
1452
1553
struct xcmd *xcp;
1454
const char *cmdsort[100];
1458
static const char *spaces = " "; /* 20 spaces */
1555
const char *list[100];
1460
1560
if (pcmd->nargs == 0) {
1462
1562
for (xcp = builtins; xcp->keyword != 0; xcp++) {
1463
1563
if (*(xcp->keyword) != '?')
1464
cmdsort[n++] = xcp->keyword;
1564
list[words++] = xcp->keyword;
1466
for (xcp = opcmds; xcp->keyword != 0; xcp++)
1467
cmdsort[n++] = xcp->keyword;
1566
for (xcp = opcmds; xcp->keyword != 0; xcp++)
1567
list[words++] = xcp->keyword;
1469
1570
#ifdef QSORT_USES_VOID_P
1470
qsort(cmdsort, (size_t)n, sizeof(char *), helpsort);
1472
qsort((char *)cmdsort, (size_t)n, sizeof(char *), helpsort);
1476
for (i = 0; i < n; i++) {
1477
length[i] = strlen(cmdsort[i]);
1478
if (length[i] > maxlength)
1479
maxlength = length[i];
1575
(list), (size_t)(words), sizeof(char *), helpsort);
1577
for (word = 0; word < words; word++) {
1578
int length = strlen(list[word]);
1482
numperline = 76 / maxlength;
1484
(void) fprintf(fp, "Commands available:\n");
1485
for (i = 0; i < n; i++) {
1486
if ((i % numperline) == (numperline-1)
1488
(void) fprintf(fp, "%s\n", cmdsort[i]);
1490
(void) fprintf(fp, "%s%s", cmdsort[i],
1491
spaces+20-maxlength+length[i]);
1584
cols = SCREENWIDTH / ++col;
1585
rows = (words + cols - 1) / cols;
1587
(void) fprintf(fp, "ntpdc commands:\n");
1589
for (row = 0; row < rows; row++) {
1590
for (word = row; word < words; word += rows) {
1591
(void) fprintf(fp, "%-*.*s", col, col-1, list[word]);
1593
(void) fprintf(fp, "\n");
1494
1596
cmd = pcmd->argval[0].string;
1495
n = findcmd(cmd, builtins, opcmds, &xcp);
1597
words = findcmd(cmd, builtins, opcmds, &xcp);
1497
1599
(void) fprintf(stderr,
1498
1600
"Command `%s' is unknown\n", cmd);
1500
} else if (n >= 2) {
1602
} else if (words >= 2) {
1501
1603
(void) fprintf(stderr,
1502
1604
"Command `%s' is ambiguous\n", cmd);
1550
1652
(void) fprintf(fp, "usage: %s", xcp->keyword);
1551
1653
for (i = 0; i < MAXARGS && xcp->arg[i] != NO; i++) {
1552
if (opt46 == 0 && (xcp->arg[i] & ~OPT) == ADD) {
1654
if (opt46 == 0 && (xcp->arg[i] & ~OPT) == NTP_ADD) {
1553
1655
(void) fprintf(fp, " [ -4|-6 ]");
1677
1779
if (pcmd->nargs == 0) {
1678
if (info_auth_keyid == 0)
1780
if (info_auth_keyid == 0 && !keyid_entered)
1679
1781
(void) fprintf(fp, "no keyid defined\n");
1782
else if (info_auth_keyid == 0 && keyid_entered)
1783
(void) fprintf(fp, "no keyid will be sent\n");
1681
1785
(void) fprintf(fp, "keyid is %lu\n", (u_long)info_auth_keyid);
1683
1787
info_auth_keyid = pcmd->argval[0].uval;