xref: /netbsd-src/external/bsd/ntp/dist/util/ntp-keygen-opts.c (revision 7788a0781fe6ff2cce37368b4578a7ade0850cb1)
1 /*	$NetBSD: ntp-keygen-opts.c,v 1.4 2012/02/01 20:48:02 kardel Exp $	*/
2 
3 /*
4  *  EDIT THIS FILE WITH CAUTION  (ntp-keygen-opts.c)
5  *
6  *  It has been AutoGen-ed  December 24, 2011 at 06:34:40 PM by AutoGen 5.12
7  *  From the definitions    ntp-keygen-opts.def
8  *  and the template file   options
9  *
10  * Generated from AutoOpts 35:0:10 templates.
11  *
12  *  AutoOpts is a copyrighted work.  This source file is not encumbered
13  *  by AutoOpts licensing, but is provided under the licensing terms chosen
14  *  by the ntp-keygen author or copyright holder.  AutoOpts is
15  *  licensed under the terms of the LGPL.  The redistributable library
16  *  (``libopts'') is licensed under the terms of either the LGPL or, at the
17  *  users discretion, the BSD license.  See the AutoOpts and/or libopts sources
18  *  for details.
19  *
20  * This source file is copyrighted and licensed under the following terms:
21  *
22  *  see html/copyright.html
23  *
24  */
25 
26 #include <sys/types.h>
27 
28 #include <limits.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <errno.h>
32 #define OPTION_CODE_COMPILE 1
33 #include "ntp-keygen-opts.h"
34 
35 #ifdef  __cplusplus
36 extern "C" {
37 #endif
38 extern FILE * option_usage_fp;
39 
40 /* TRANSLATORS: choose the translation for option names wisely because you
41                 cannot ever change your mind. */
42 static char const zCopyright[50] =
43 "ntp-keygen (ntp) 4.2.6p5\n\
44 see html/copyright.html\n";
45 static char const zLicenseDescrip[25] =
46 "see html/copyright.html\n";
47 
48 extern tUsageProc optionUsage;
49 
50 /*
51  *  global included definitions
52  */
53 #include <stdlib.h>
54 #ifdef __windows
55   extern int atoi(const char*);
56 #else
57 # include <stdlib.h>
58 #endif
59 
60 #ifndef NULL
61 #  define NULL 0
62 #endif
63 
64 /*
65  *  Certificate option description:
66  */
67 #ifdef OPENSSL
68 static char const zCertificateText[] =
69         "certificate scheme";
70 static char const zCertificate_NAME[]        = "CERTIFICATE";
71 static char const zCertificate_Name[]        = "certificate";
72 #define CERTIFICATE_FLAGS       (OPTST_DISABLED \
73         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
74 
75 #else   /* disable Certificate */
76 #define CERTIFICATE_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
77 #define zCertificate_NAME      NULL
78 #define zCertificateText       NULL
79 #define zCertificate_Name      NULL
80 #endif  /* OPENSSL */
81 
82 /*
83  *  Debug_Level option description:
84  */
85 static char const zDebug_LevelText[] =
86         "Increase output debug message level";
87 static char const zDebug_Level_NAME[]        = "DEBUG_LEVEL";
88 static char const zDebug_Level_Name[]        = "debug-level";
89 #define DEBUG_LEVEL_FLAGS       (OPTST_DISABLED)
90 
91 /*
92  *  Set_Debug_Level option description:
93  */
94 static char const zSet_Debug_LevelText[] =
95         "Set the output debug message level";
96 static char const zSet_Debug_Level_NAME[]    = "SET_DEBUG_LEVEL";
97 static char const zSet_Debug_Level_Name[]    = "set-debug-level";
98 #define SET_DEBUG_LEVEL_FLAGS       (OPTST_DISABLED \
99         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
100 
101 /*
102  *  Id_Key option description:
103  */
104 #ifdef OPENSSL
105 static char const zId_KeyText[] =
106         "Write IFF or GQ identity keys";
107 static char const zId_Key_NAME[]             = "ID_KEY";
108 static char const zId_Key_Name[]             = "id-key";
109 #define ID_KEY_FLAGS       (OPTST_DISABLED)
110 
111 #else   /* disable Id_Key */
112 #define ID_KEY_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
113 #define zId_Key_NAME      NULL
114 #define zId_KeyText       NULL
115 #define zId_Key_Name      NULL
116 #endif  /* OPENSSL */
117 
118 /*
119  *  Gq_Params option description:
120  */
121 #ifdef OPENSSL
122 static char const zGq_ParamsText[] =
123         "Generate GQ parameters and keys";
124 static char const zGq_Params_NAME[]          = "GQ_PARAMS";
125 static char const zGq_Params_Name[]          = "gq-params";
126 #define GQ_PARAMS_FLAGS       (OPTST_DISABLED)
127 
128 #else   /* disable Gq_Params */
129 #define GQ_PARAMS_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
130 #define zGq_Params_NAME      NULL
131 #define zGq_ParamsText       NULL
132 #define zGq_Params_Name      NULL
133 #endif  /* OPENSSL */
134 
135 /*
136  *  Host_Key option description:
137  */
138 #ifdef OPENSSL
139 static char const zHost_KeyText[] =
140         "generate RSA host key";
141 static char const zHost_Key_NAME[]           = "HOST_KEY";
142 static char const zHost_Key_Name[]           = "host-key";
143 #define HOST_KEY_FLAGS       (OPTST_DISABLED)
144 
145 #else   /* disable Host_Key */
146 #define HOST_KEY_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
147 #define zHost_Key_NAME      NULL
148 #define zHost_KeyText       NULL
149 #define zHost_Key_Name      NULL
150 #endif  /* OPENSSL */
151 
152 /*
153  *  Iffkey option description:
154  */
155 #ifdef OPENSSL
156 static char const zIffkeyText[] =
157         "generate IFF parameters";
158 static char const zIffkey_NAME[]             = "IFFKEY";
159 static char const zIffkey_Name[]             = "iffkey";
160 #define IFFKEY_FLAGS       (OPTST_DISABLED)
161 
162 #else   /* disable Iffkey */
163 #define IFFKEY_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
164 #define zIffkey_NAME      NULL
165 #define zIffkeyText       NULL
166 #define zIffkey_Name      NULL
167 #endif  /* OPENSSL */
168 
169 /*
170  *  Issuer_Name option description:
171  */
172 #ifdef OPENSSL
173 static char const zIssuer_NameText[] =
174         "set issuer name";
175 static char const zIssuer_Name_NAME[]        = "ISSUER_NAME";
176 static char const zIssuer_Name_Name[]        = "issuer-name";
177 #define ISSUER_NAME_FLAGS       (OPTST_DISABLED \
178         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
179 
180 #else   /* disable Issuer_Name */
181 #define ISSUER_NAME_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
182 #define zIssuer_Name_NAME      NULL
183 #define zIssuer_NameText       NULL
184 #define zIssuer_Name_Name      NULL
185 #endif  /* OPENSSL */
186 
187 /*
188  *  Md5key option description:
189  */
190 static char const zMd5keyText[] =
191         "generate MD5 keys";
192 static char const zMd5key_NAME[]             = "MD5KEY";
193 static char const zMd5key_Name[]             = "md5key";
194 #define MD5KEY_FLAGS       (OPTST_DISABLED)
195 
196 /*
197  *  Modulus option description:
198  */
199 #ifdef OPENSSL
200 static char const zModulusText[] =
201         "modulus";
202 static char const zModulus_NAME[]            = "MODULUS";
203 static char const zModulus_Name[]            = "modulus";
204 #define MODULUS_FLAGS       (OPTST_DISABLED \
205         | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
206 
207 #else   /* disable Modulus */
208 #define MODULUS_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
209 #define zModulus_NAME      NULL
210 #define zModulusText       NULL
211 #define zModulus_Name      NULL
212 #endif  /* OPENSSL */
213 
214 /*
215  *  Pvt_Cert option description:
216  */
217 #ifdef OPENSSL
218 static char const zPvt_CertText[] =
219         "generate PC private certificate";
220 static char const zPvt_Cert_NAME[]           = "PVT_CERT";
221 static char const zPvt_Cert_Name[]           = "pvt-cert";
222 #define PVT_CERT_FLAGS       (OPTST_DISABLED)
223 
224 #else   /* disable Pvt_Cert */
225 #define PVT_CERT_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
226 #define zPvt_Cert_NAME      NULL
227 #define zPvt_CertText       NULL
228 #define zPvt_Cert_Name      NULL
229 #endif  /* OPENSSL */
230 
231 /*
232  *  Pvt_Passwd option description:
233  */
234 #ifdef OPENSSL
235 static char const zPvt_PasswdText[] =
236         "output private password";
237 static char const zPvt_Passwd_NAME[]         = "PVT_PASSWD";
238 static char const zPvt_Passwd_Name[]         = "pvt-passwd";
239 #define PVT_PASSWD_FLAGS       (OPTST_DISABLED \
240         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
241 
242 #else   /* disable Pvt_Passwd */
243 #define PVT_PASSWD_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
244 #define zPvt_Passwd_NAME      NULL
245 #define zPvt_PasswdText       NULL
246 #define zPvt_Passwd_Name      NULL
247 #endif  /* OPENSSL */
248 
249 /*
250  *  Get_Pvt_Passwd option description:
251  */
252 #ifdef OPENSSL
253 static char const zGet_Pvt_PasswdText[] =
254         "input private password";
255 static char const zGet_Pvt_Passwd_NAME[]     = "GET_PVT_PASSWD";
256 static char const zGet_Pvt_Passwd_Name[]     = "get-pvt-passwd";
257 #define GET_PVT_PASSWD_FLAGS       (OPTST_DISABLED \
258         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
259 
260 #else   /* disable Get_Pvt_Passwd */
261 #define GET_PVT_PASSWD_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
262 #define zGet_Pvt_Passwd_NAME      NULL
263 #define zGet_Pvt_PasswdText       NULL
264 #define zGet_Pvt_Passwd_Name      NULL
265 #endif  /* OPENSSL */
266 
267 /*
268  *  Sign_Key option description:
269  */
270 #ifdef OPENSSL
271 static char const zSign_KeyText[] =
272         "generate sign key (RSA or DSA)";
273 static char const zSign_Key_NAME[]           = "SIGN_KEY";
274 static char const zSign_Key_Name[]           = "sign-key";
275 #define SIGN_KEY_FLAGS       (OPTST_DISABLED \
276         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
277 
278 #else   /* disable Sign_Key */
279 #define SIGN_KEY_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
280 #define zSign_Key_NAME      NULL
281 #define zSign_KeyText       NULL
282 #define zSign_Key_Name      NULL
283 #endif  /* OPENSSL */
284 
285 /*
286  *  Subject_Name option description:
287  */
288 #ifdef OPENSSL
289 static char const zSubject_NameText[] =
290         "set subject name";
291 static char const zSubject_Name_NAME[]       = "SUBJECT_NAME";
292 static char const zSubject_Name_Name[]       = "subject-name";
293 #define SUBJECT_NAME_FLAGS       (OPTST_DISABLED \
294         | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
295 
296 #else   /* disable Subject_Name */
297 #define SUBJECT_NAME_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
298 #define zSubject_Name_NAME      NULL
299 #define zSubject_NameText       NULL
300 #define zSubject_Name_Name      NULL
301 #endif  /* OPENSSL */
302 
303 /*
304  *  Trusted_Cert option description:
305  */
306 #ifdef OPENSSL
307 static char const zTrusted_CertText[] =
308         "trusted certificate (TC scheme)";
309 static char const zTrusted_Cert_NAME[]       = "TRUSTED_CERT";
310 static char const zTrusted_Cert_Name[]       = "trusted-cert";
311 #define TRUSTED_CERT_FLAGS       (OPTST_DISABLED)
312 
313 #else   /* disable Trusted_Cert */
314 #define TRUSTED_CERT_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
315 #define zTrusted_Cert_NAME      NULL
316 #define zTrusted_CertText       NULL
317 #define zTrusted_Cert_Name      NULL
318 #endif  /* OPENSSL */
319 
320 /*
321  *  Mv_Params option description:
322  */
323 #ifdef OPENSSL
324 static char const zMv_ParamsText[] =
325         "generate <num> MV parameters";
326 static char const zMv_Params_NAME[]          = "MV_PARAMS";
327 static char const zMv_Params_Name[]          = "mv-params";
328 #define MV_PARAMS_FLAGS       (OPTST_DISABLED \
329         | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
330 
331 #else   /* disable Mv_Params */
332 #define MV_PARAMS_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
333 #define zMv_Params_NAME      NULL
334 #define zMv_ParamsText       NULL
335 #define zMv_Params_Name      NULL
336 #endif  /* OPENSSL */
337 
338 /*
339  *  Mv_Keys option description:
340  */
341 #ifdef OPENSSL
342 static char const zMv_KeysText[] =
343         "update <num> MV keys";
344 static char const zMv_Keys_NAME[]            = "MV_KEYS";
345 static char const zMv_Keys_Name[]            = "mv-keys";
346 #define MV_KEYS_FLAGS       (OPTST_DISABLED \
347         | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
348 
349 #else   /* disable Mv_Keys */
350 #define MV_KEYS_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
351 #define zMv_Keys_NAME      NULL
352 #define zMv_KeysText       NULL
353 #define zMv_Keys_Name      NULL
354 #endif  /* OPENSSL */
355 
356 /*
357  *  Help/More_Help/Version option descriptions:
358  */
359 static char const zHelpText[]          = "Display extended usage information and exit";
360 static char const zHelp_Name[]         = "help";
361 #ifdef HAVE_WORKING_FORK
362 #define OPTST_MORE_HELP_FLAGS   (OPTST_IMM | OPTST_NO_INIT)
363 static char const zMore_Help_Name[]    = "more-help";
364 static char const zMore_HelpText[]     = "Extended usage information passed thru pager";
365 #else
366 #define OPTST_MORE_HELP_FLAGS   (OPTST_OMITTED | OPTST_NO_INIT)
367 #define zMore_Help_Name   NULL
368 #define zMore_HelpText    NULL
369 #endif
370 #ifdef NO_OPTIONAL_OPT_ARGS
371 #  define OPTST_VERSION_FLAGS   OPTST_IMM | OPTST_NO_INIT
372 #else
373 #  define OPTST_VERSION_FLAGS   OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
374                                 OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
375 #endif
376 
377 static char const zVersionText[]       = "Output version information and exit";
378 static char const zVersion_Name[]      = "version";
379 static char const zSave_OptsText[]     = "Save the option state to a config file";
380 static char const zSave_Opts_Name[]    = "save-opts";
381 static char const zLoad_OptsText[]     = "Load options from a config file";
382 static char const zLoad_Opts_NAME[]    = "LOAD_OPTS";
383 static char const zNotLoad_Opts_Name[] = "no-load-opts";
384 static char const zNotLoad_Opts_Pfx[]  = "no";
385 #define zLoad_Opts_Name   (zNotLoad_Opts_Name + 3)
386 /*
387  *  Declare option callback procedures
388  */
389 #ifdef OPENSSL
390   static tOptProc doOptModulus;
391 #else /* not OPENSSL */
392 # define doOptModulus NULL
393 #endif /* def/not OPENSSL */
394 #if defined(TEST_NTP_KEYGEN_OPTS)
395 /*
396  *  Under test, omit argument processing, or call optionStackArg,
397  *  if multiple copies are allowed.
398  */
399 static tOptProc
400     doUsageOpt;
401 
402 /*
403  *  #define map the "normal" callout procs to the test ones...
404  */
405 #define SET_DEBUG_LEVEL_OPT_PROC optionStackArg
406 
407 
408 #else /* NOT defined TEST_NTP_KEYGEN_OPTS */
409 /*
410  *  When not under test, there are different procs to use
411  */
412 extern tOptProc
413     optionBooleanVal,    optionNestedVal,     optionNumericVal,
414     optionPagedUsage,    optionPrintVersion,  optionResetOpt,
415     optionStackArg,      optionTimeDate,      optionTimeVal,
416     optionUnstackArg,    optionVersionStderr;
417 static tOptProc
418     doOptSet_Debug_Level, doUsageOpt;
419 
420 /*
421  *  #define map the "normal" callout procs
422  */
423 #define SET_DEBUG_LEVEL_OPT_PROC doOptSet_Debug_Level
424 
425 #define SET_DEBUG_LEVEL_OPT_PROC doOptSet_Debug_Level
426 #endif /* defined(TEST_NTP_KEYGEN_OPTS) */
427 #ifdef TEST_NTP_KEYGEN_OPTS
428 # define DOVERPROC optionVersionStderr
429 #else
430 # define DOVERPROC optionPrintVersion
431 #endif /* TEST_NTP_KEYGEN_OPTS */
432 
433 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
434  *
435  *  Define the Ntp_Keygen Option Descriptions.
436  */
437 static tOptDesc optDesc[OPTION_CT] = {
438   {  /* entry idx, value */ 0, VALUE_OPT_CERTIFICATE,
439      /* equiv idx, value */ 0, VALUE_OPT_CERTIFICATE,
440      /* equivalenced to  */ NO_EQUIVALENT,
441      /* min, max, act ct */ 0, 1, 0,
442      /* opt state flags  */ CERTIFICATE_FLAGS, 0,
443      /* last opt argumnt */ { NULL },
444      /* arg list/cookie  */ NULL,
445      /* must/cannot opts */ NULL, NULL,
446      /* option proc      */ NULL,
447      /* desc, NAME, name */ zCertificateText, zCertificate_NAME, zCertificate_Name,
448      /* disablement strs */ NULL, NULL },
449 
450   {  /* entry idx, value */ 1, VALUE_OPT_DEBUG_LEVEL,
451      /* equiv idx, value */ 1, VALUE_OPT_DEBUG_LEVEL,
452      /* equivalenced to  */ NO_EQUIVALENT,
453      /* min, max, act ct */ 0, NOLIMIT, 0,
454      /* opt state flags  */ DEBUG_LEVEL_FLAGS, 0,
455      /* last opt argumnt */ { NULL },
456      /* arg list/cookie  */ NULL,
457      /* must/cannot opts */ NULL, NULL,
458      /* option proc      */ NULL,
459      /* desc, NAME, name */ zDebug_LevelText, zDebug_Level_NAME, zDebug_Level_Name,
460      /* disablement strs */ NULL, NULL },
461 
462   {  /* entry idx, value */ 2, VALUE_OPT_SET_DEBUG_LEVEL,
463      /* equiv idx, value */ 2, VALUE_OPT_SET_DEBUG_LEVEL,
464      /* equivalenced to  */ NO_EQUIVALENT,
465      /* min, max, act ct */ 0, NOLIMIT, 0,
466      /* opt state flags  */ SET_DEBUG_LEVEL_FLAGS, 0,
467      /* last opt argumnt */ { NULL },
468      /* arg list/cookie  */ NULL,
469      /* must/cannot opts */ NULL, NULL,
470      /* option proc      */ SET_DEBUG_LEVEL_OPT_PROC,
471      /* desc, NAME, name */ zSet_Debug_LevelText, zSet_Debug_Level_NAME, zSet_Debug_Level_Name,
472      /* disablement strs */ NULL, NULL },
473 
474   {  /* entry idx, value */ 3, VALUE_OPT_ID_KEY,
475      /* equiv idx, value */ 3, VALUE_OPT_ID_KEY,
476      /* equivalenced to  */ NO_EQUIVALENT,
477      /* min, max, act ct */ 0, 1, 0,
478      /* opt state flags  */ ID_KEY_FLAGS, 0,
479      /* last opt argumnt */ { NULL },
480      /* arg list/cookie  */ NULL,
481      /* must/cannot opts */ NULL, NULL,
482      /* option proc      */ NULL,
483      /* desc, NAME, name */ zId_KeyText, zId_Key_NAME, zId_Key_Name,
484      /* disablement strs */ NULL, NULL },
485 
486   {  /* entry idx, value */ 4, VALUE_OPT_GQ_PARAMS,
487      /* equiv idx, value */ 4, VALUE_OPT_GQ_PARAMS,
488      /* equivalenced to  */ NO_EQUIVALENT,
489      /* min, max, act ct */ 0, 1, 0,
490      /* opt state flags  */ GQ_PARAMS_FLAGS, 0,
491      /* last opt argumnt */ { NULL },
492      /* arg list/cookie  */ NULL,
493      /* must/cannot opts */ NULL, NULL,
494      /* option proc      */ NULL,
495      /* desc, NAME, name */ zGq_ParamsText, zGq_Params_NAME, zGq_Params_Name,
496      /* disablement strs */ NULL, NULL },
497 
498   {  /* entry idx, value */ 5, VALUE_OPT_HOST_KEY,
499      /* equiv idx, value */ 5, VALUE_OPT_HOST_KEY,
500      /* equivalenced to  */ NO_EQUIVALENT,
501      /* min, max, act ct */ 0, 1, 0,
502      /* opt state flags  */ HOST_KEY_FLAGS, 0,
503      /* last opt argumnt */ { NULL },
504      /* arg list/cookie  */ NULL,
505      /* must/cannot opts */ NULL, NULL,
506      /* option proc      */ NULL,
507      /* desc, NAME, name */ zHost_KeyText, zHost_Key_NAME, zHost_Key_Name,
508      /* disablement strs */ NULL, NULL },
509 
510   {  /* entry idx, value */ 6, VALUE_OPT_IFFKEY,
511      /* equiv idx, value */ 6, VALUE_OPT_IFFKEY,
512      /* equivalenced to  */ NO_EQUIVALENT,
513      /* min, max, act ct */ 0, 1, 0,
514      /* opt state flags  */ IFFKEY_FLAGS, 0,
515      /* last opt argumnt */ { NULL },
516      /* arg list/cookie  */ NULL,
517      /* must/cannot opts */ NULL, NULL,
518      /* option proc      */ NULL,
519      /* desc, NAME, name */ zIffkeyText, zIffkey_NAME, zIffkey_Name,
520      /* disablement strs */ NULL, NULL },
521 
522   {  /* entry idx, value */ 7, VALUE_OPT_ISSUER_NAME,
523      /* equiv idx, value */ 7, VALUE_OPT_ISSUER_NAME,
524      /* equivalenced to  */ NO_EQUIVALENT,
525      /* min, max, act ct */ 0, 1, 0,
526      /* opt state flags  */ ISSUER_NAME_FLAGS, 0,
527      /* last opt argumnt */ { NULL },
528      /* arg list/cookie  */ NULL,
529      /* must/cannot opts */ NULL, NULL,
530      /* option proc      */ NULL,
531      /* desc, NAME, name */ zIssuer_NameText, zIssuer_Name_NAME, zIssuer_Name_Name,
532      /* disablement strs */ NULL, NULL },
533 
534   {  /* entry idx, value */ 8, VALUE_OPT_MD5KEY,
535      /* equiv idx, value */ 8, VALUE_OPT_MD5KEY,
536      /* equivalenced to  */ NO_EQUIVALENT,
537      /* min, max, act ct */ 0, 1, 0,
538      /* opt state flags  */ MD5KEY_FLAGS, 0,
539      /* last opt argumnt */ { NULL },
540      /* arg list/cookie  */ NULL,
541      /* must/cannot opts */ NULL, NULL,
542      /* option proc      */ NULL,
543      /* desc, NAME, name */ zMd5keyText, zMd5key_NAME, zMd5key_Name,
544      /* disablement strs */ NULL, NULL },
545 
546   {  /* entry idx, value */ 9, VALUE_OPT_MODULUS,
547      /* equiv idx, value */ 9, VALUE_OPT_MODULUS,
548      /* equivalenced to  */ NO_EQUIVALENT,
549      /* min, max, act ct */ 0, 1, 0,
550      /* opt state flags  */ MODULUS_FLAGS, 0,
551      /* last opt argumnt */ { NULL },
552      /* arg list/cookie  */ NULL,
553      /* must/cannot opts */ NULL, NULL,
554      /* option proc      */ doOptModulus,
555      /* desc, NAME, name */ zModulusText, zModulus_NAME, zModulus_Name,
556      /* disablement strs */ NULL, NULL },
557 
558   {  /* entry idx, value */ 10, VALUE_OPT_PVT_CERT,
559      /* equiv idx, value */ 10, VALUE_OPT_PVT_CERT,
560      /* equivalenced to  */ NO_EQUIVALENT,
561      /* min, max, act ct */ 0, 1, 0,
562      /* opt state flags  */ PVT_CERT_FLAGS, 0,
563      /* last opt argumnt */ { NULL },
564      /* arg list/cookie  */ NULL,
565      /* must/cannot opts */ NULL, NULL,
566      /* option proc      */ NULL,
567      /* desc, NAME, name */ zPvt_CertText, zPvt_Cert_NAME, zPvt_Cert_Name,
568      /* disablement strs */ NULL, NULL },
569 
570   {  /* entry idx, value */ 11, VALUE_OPT_PVT_PASSWD,
571      /* equiv idx, value */ 11, VALUE_OPT_PVT_PASSWD,
572      /* equivalenced to  */ NO_EQUIVALENT,
573      /* min, max, act ct */ 0, 1, 0,
574      /* opt state flags  */ PVT_PASSWD_FLAGS, 0,
575      /* last opt argumnt */ { NULL },
576      /* arg list/cookie  */ NULL,
577      /* must/cannot opts */ NULL, NULL,
578      /* option proc      */ NULL,
579      /* desc, NAME, name */ zPvt_PasswdText, zPvt_Passwd_NAME, zPvt_Passwd_Name,
580      /* disablement strs */ NULL, NULL },
581 
582   {  /* entry idx, value */ 12, VALUE_OPT_GET_PVT_PASSWD,
583      /* equiv idx, value */ 12, VALUE_OPT_GET_PVT_PASSWD,
584      /* equivalenced to  */ NO_EQUIVALENT,
585      /* min, max, act ct */ 0, 1, 0,
586      /* opt state flags  */ GET_PVT_PASSWD_FLAGS, 0,
587      /* last opt argumnt */ { NULL },
588      /* arg list/cookie  */ NULL,
589      /* must/cannot opts */ NULL, NULL,
590      /* option proc      */ NULL,
591      /* desc, NAME, name */ zGet_Pvt_PasswdText, zGet_Pvt_Passwd_NAME, zGet_Pvt_Passwd_Name,
592      /* disablement strs */ NULL, NULL },
593 
594   {  /* entry idx, value */ 13, VALUE_OPT_SIGN_KEY,
595      /* equiv idx, value */ 13, VALUE_OPT_SIGN_KEY,
596      /* equivalenced to  */ NO_EQUIVALENT,
597      /* min, max, act ct */ 0, 1, 0,
598      /* opt state flags  */ SIGN_KEY_FLAGS, 0,
599      /* last opt argumnt */ { NULL },
600      /* arg list/cookie  */ NULL,
601      /* must/cannot opts */ NULL, NULL,
602      /* option proc      */ NULL,
603      /* desc, NAME, name */ zSign_KeyText, zSign_Key_NAME, zSign_Key_Name,
604      /* disablement strs */ NULL, NULL },
605 
606   {  /* entry idx, value */ 14, VALUE_OPT_SUBJECT_NAME,
607      /* equiv idx, value */ 14, VALUE_OPT_SUBJECT_NAME,
608      /* equivalenced to  */ NO_EQUIVALENT,
609      /* min, max, act ct */ 0, 1, 0,
610      /* opt state flags  */ SUBJECT_NAME_FLAGS, 0,
611      /* last opt argumnt */ { NULL },
612      /* arg list/cookie  */ NULL,
613      /* must/cannot opts */ NULL, NULL,
614      /* option proc      */ NULL,
615      /* desc, NAME, name */ zSubject_NameText, zSubject_Name_NAME, zSubject_Name_Name,
616      /* disablement strs */ NULL, NULL },
617 
618   {  /* entry idx, value */ 15, VALUE_OPT_TRUSTED_CERT,
619      /* equiv idx, value */ 15, VALUE_OPT_TRUSTED_CERT,
620      /* equivalenced to  */ NO_EQUIVALENT,
621      /* min, max, act ct */ 0, 1, 0,
622      /* opt state flags  */ TRUSTED_CERT_FLAGS, 0,
623      /* last opt argumnt */ { NULL },
624      /* arg list/cookie  */ NULL,
625      /* must/cannot opts */ NULL, NULL,
626      /* option proc      */ NULL,
627      /* desc, NAME, name */ zTrusted_CertText, zTrusted_Cert_NAME, zTrusted_Cert_Name,
628      /* disablement strs */ NULL, NULL },
629 
630   {  /* entry idx, value */ 16, VALUE_OPT_MV_PARAMS,
631      /* equiv idx, value */ 16, VALUE_OPT_MV_PARAMS,
632      /* equivalenced to  */ NO_EQUIVALENT,
633      /* min, max, act ct */ 0, 1, 0,
634      /* opt state flags  */ MV_PARAMS_FLAGS, 0,
635      /* last opt argumnt */ { NULL },
636      /* arg list/cookie  */ NULL,
637      /* must/cannot opts */ NULL, NULL,
638      /* option proc      */ optionNumericVal,
639      /* desc, NAME, name */ zMv_ParamsText, zMv_Params_NAME, zMv_Params_Name,
640      /* disablement strs */ NULL, NULL },
641 
642   {  /* entry idx, value */ 17, VALUE_OPT_MV_KEYS,
643      /* equiv idx, value */ 17, VALUE_OPT_MV_KEYS,
644      /* equivalenced to  */ NO_EQUIVALENT,
645      /* min, max, act ct */ 0, 1, 0,
646      /* opt state flags  */ MV_KEYS_FLAGS, 0,
647      /* last opt argumnt */ { NULL },
648      /* arg list/cookie  */ NULL,
649      /* must/cannot opts */ NULL, NULL,
650      /* option proc      */ optionNumericVal,
651      /* desc, NAME, name */ zMv_KeysText, zMv_Keys_NAME, zMv_Keys_Name,
652      /* disablement strs */ NULL, NULL },
653 
654   {  /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
655      /* equiv idx value  */ NO_EQUIVALENT, 0,
656      /* equivalenced to  */ NO_EQUIVALENT,
657      /* min, max, act ct */ 0, 1, 0,
658      /* opt state flags  */ OPTST_VERSION_FLAGS, 0,
659      /* last opt argumnt */ { NULL },
660      /* arg list/cookie  */ NULL,
661      /* must/cannot opts */ NULL, NULL,
662      /* option proc      */ DOVERPROC,
663      /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
664      /* disablement strs */ NULL, NULL },
665 
666 
667 
668   {  /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
669      /* equiv idx value  */ NO_EQUIVALENT, 0,
670      /* equivalenced to  */ NO_EQUIVALENT,
671      /* min, max, act ct */ 0, 1, 0,
672      /* opt state flags  */ OPTST_IMM | OPTST_NO_INIT, 0,
673      /* last opt argumnt */ { NULL },
674      /* arg list/cookie  */ NULL,
675      /* must/cannot opts */ NULL, NULL,
676      /* option proc      */ doUsageOpt,
677      /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
678      /* disablement strs */ NULL, NULL },
679 
680   {  /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
681      /* equiv idx value  */ NO_EQUIVALENT, 0,
682      /* equivalenced to  */ NO_EQUIVALENT,
683      /* min, max, act ct */ 0, 1, 0,
684      /* opt state flags  */ OPTST_MORE_HELP_FLAGS, 0,
685      /* last opt argumnt */ { NULL },
686      /* arg list/cookie  */ NULL,
687      /* must/cannot opts */ NULL,  NULL,
688      /* option proc      */ optionPagedUsage,
689      /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
690      /* disablement strs */ NULL, NULL },
691 
692   {  /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
693      /* equiv idx value  */ NO_EQUIVALENT, 0,
694      /* equivalenced to  */ NO_EQUIVALENT,
695      /* min, max, act ct */ 0, 1, 0,
696      /* opt state flags  */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
697                           | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0,
698      /* last opt argumnt */ { NULL },
699      /* arg list/cookie  */ NULL,
700      /* must/cannot opts */ NULL,  NULL,
701      /* option proc      */ NULL,
702      /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
703      /* disablement strs */ NULL, NULL },
704 
705   {  /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
706      /* equiv idx value  */ NO_EQUIVALENT, 0,
707      /* equivalenced to  */ NO_EQUIVALENT,
708      /* min, max, act ct */ 0, NOLIMIT, 0,
709      /* opt state flags  */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
710 			  | OPTST_DISABLE_IMM, 0,
711      /* last opt argumnt */ { NULL },
712      /* arg list/cookie  */ NULL,
713      /* must/cannot opts */ NULL, NULL,
714      /* option proc      */ optionLoadOpt,
715      /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
716      /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
717 };
718 
719 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
720  *
721  *  Define the Ntp_Keygen Option Environment
722  */
723 static char const zPROGNAME[11] = "NTP_KEYGEN";
724 static char const zUsageTitle[114] =
725 "ntp-keygen (ntp) - Create a NTP host key - Ver. 4.2.6p5\n\
726 USAGE:  %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
727 static char const zRcName[7] = ".ntprc";
728 static char const * const apzHomeList[3] = {
729     "$HOME",
730     ".",
731     NULL };
732 
733 static char const zBugsAddr[34]    = "http://bugs.ntp.org, bugs@ntp.org";
734 #define zExplain NULL
735 static char const zDetail[99] = "\n\
736 If there is no new host key, look for an existing one.  If one is not\n\
737 found, create it.\n";
738 static char const zFullVersion[] = NTP_KEYGEN_FULL_VERSION;
739 /* extracted from optcode.tlib near line 515 */
740 
741 #if defined(ENABLE_NLS)
742 # define OPTPROC_BASE OPTPROC_TRANSLATE
743   static tOptionXlateProc translate_option_strings;
744 #else
745 # define OPTPROC_BASE OPTPROC_NONE
746 # define translate_option_strings NULL
747 #endif /* ENABLE_NLS */
748 
749 
750 #define ntp_keygen_full_usage NULL
751 #define ntp_keygen_short_usage NULL
752 #ifndef  PKGDATADIR
753 # define PKGDATADIR ""
754 #endif
755 
756 #ifndef  WITH_PACKAGER
757 # define ntp_keygen_packager_info NULL
758 #else
759 static char const ntp_keygen_packager_info[] =
760     "Packaged by " WITH_PACKAGER
761 
762 # ifdef WITH_PACKAGER_VERSION
763         " ("WITH_PACKAGER_VERSION")"
764 # endif
765 
766 # ifdef WITH_PACKAGER_BUG_REPORTS
767     "\nReport ntp_keygen bugs to " WITH_PACKAGER_BUG_REPORTS
768 # endif
769     "\n";
770 #endif
771 
772 tOptions ntp_keygenOptions = {
773     OPTIONS_STRUCT_VERSION,
774     0, NULL,                    /* original argc + argv    */
775     ( OPTPROC_BASE
776     + OPTPROC_ERRSTOP
777     + OPTPROC_SHORTOPT
778     + OPTPROC_LONGOPT
779     + OPTPROC_NO_REQ_OPT
780     + OPTPROC_ENVIRON
781     + OPTPROC_NO_ARGS
782     + OPTPROC_MISUSE ),
783     0, NULL,                    /* current option index, current option */
784     NULL,         NULL,         zPROGNAME,
785     zRcName,      zCopyright,   zLicenseDescrip,
786     zFullVersion, apzHomeList,  zUsageTitle,
787     zExplain,     zDetail,      optDesc,
788     zBugsAddr,                  /* address to send bugs to */
789     NULL, NULL,                 /* extensions/saved state  */
790     optionUsage, /* usage procedure */
791     translate_option_strings,   /* translation procedure */
792     /*
793      *  Indexes to special options
794      */
795     { INDEX_OPT_MORE_HELP, /* more-help option index */
796       INDEX_OPT_SAVE_OPTS, /* save option index */
797       NO_EQUIVALENT, /* '-#' option index */
798       NO_EQUIVALENT /* index of default opt */
799     },
800     23 /* full option count */, 18 /* user option count */,
801     ntp_keygen_full_usage, ntp_keygen_short_usage,
802     NULL, NULL,
803     PKGDATADIR, ntp_keygen_packager_info
804 };
805 
806 /*
807  *  Create the static procedure(s) declared above.
808  */
809 static void
810 doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
811 {
812     (void)pOptions;
813     USAGE(NTP_KEYGEN_EXIT_SUCCESS);
814 }
815 
816 #if ! defined(TEST_NTP_KEYGEN_OPTS)
817 
818 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
819  *
820  *   For the set-debug-level option.
821  */
822 static void
823 doOptSet_Debug_Level(tOptions* pOptions, tOptDesc* pOptDesc)
824 {
825     /* extracted from debug-opt.def, line 27 */
826 DESC(DEBUG_LEVEL).optOccCt = atoi( pOptDesc->pzLastArg );
827 }
828 #endif /* defined(TEST_NTP_KEYGEN_OPTS) */
829 
830 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
831  *
832  *   For the modulus option, when OPENSSL is #define-d.
833  */
834 #ifdef OPENSSL
835 static void
836 doOptModulus(tOptions* pOptions, tOptDesc* pOptDesc)
837 {
838     static const struct {long const rmin, rmax;} rng[1] = {
839         { 256, 2048 } };
840     int  ix;
841 
842     if (pOptions <= OPTPROC_EMIT_LIMIT)
843         goto emit_ranges;
844     optionNumericVal(pOptions, pOptDesc);
845 
846     for (ix = 0; ix < 1; ix++) {
847         if (pOptDesc->optArg.argInt < rng[ix].rmin)
848             continue;  /* ranges need not be ordered. */
849         if (pOptDesc->optArg.argInt == rng[ix].rmin)
850             return;
851         if (rng[ix].rmax == LONG_MIN)
852             continue;
853         if (pOptDesc->optArg.argInt <= rng[ix].rmax)
854             return;
855     }
856 
857     option_usage_fp = stderr;
858 
859 emit_ranges:
860 
861     optionShowRange(pOptions, pOptDesc, (const void *)rng, 1);
862 }
863 #endif /* defined OPENSSL */
864 /* extracted from optmain.tlib near line 128 */
865 
866 #if defined(TEST_NTP_KEYGEN_OPTS) /* TEST MAIN PROCEDURE: */
867 
868 extern void optionPutShell(tOptions*);
869 
870 int
871 main(int argc, char ** argv)
872 {
873     int res = NTP_KEYGEN_EXIT_SUCCESS;
874     (void)optionProcess(&ntp_keygenOptions, argc, argv);
875     optionPutShell(&ntp_keygenOptions);
876     res = ferror(stdout);
877     if (res != 0)
878         fputs("output error writing to stdout\n", stderr);
879     return res;
880 }
881 #endif  /* defined TEST_NTP_KEYGEN_OPTS */
882 /* extracted from optcode.tlib near line 666 */
883 
884 #if ENABLE_NLS
885 #include <stdio.h>
886 #include <stdlib.h>
887 #include <string.h>
888 #include <unistd.h>
889 #include <autoopts/usage-txt.h>
890 
891 static char* AO_gettext(char const* pz);
892 static void  coerce_it(void** s);
893 
894 static char*
895 AO_gettext(char const* pz)
896 {
897     char* pzRes;
898     if (pz == NULL)
899         return NULL;
900     pzRes = _(pz);
901     if (pzRes == pz)
902         return pzRes;
903     pzRes = strdup(pzRes);
904     if (pzRes == NULL) {
905         fputs(_("No memory for duping translated strings\n"), stderr);
906         exit(NTP_KEYGEN_EXIT_FAILURE);
907     }
908     return pzRes;
909 }
910 
911 static void coerce_it(void** s) { *s = AO_gettext(*s);
912 }
913 
914 /*
915  *  This invokes the translation code (e.g. gettext(3)).
916  */
917 static void
918 translate_option_strings(void)
919 {
920     tOptions * const pOpt = &ntp_keygenOptions;
921 
922     /*
923      *  Guard against re-translation.  It won't work.  The strings will have
924      *  been changed by the first pass through this code.  One shot only.
925      */
926     if (option_usage_text.field_ct != 0) {
927         /*
928          *  Do the translations.  The first pointer follows the field count
929          *  field.  The field count field is the size of a pointer.
930          */
931         tOptDesc * pOD = pOpt->pOptDesc;
932         char **    ppz = (char**)(void*)&(option_usage_text);
933         int        ix  = option_usage_text.field_ct;
934 
935         do {
936             ppz++;
937             *ppz = AO_gettext(*ppz);
938         } while (--ix > 0);
939 
940         coerce_it((void*)&(pOpt->pzCopyright));
941         coerce_it((void*)&(pOpt->pzCopyNotice));
942         coerce_it((void*)&(pOpt->pzFullVersion));
943         coerce_it((void*)&(pOpt->pzUsageTitle));
944         coerce_it((void*)&(pOpt->pzExplain));
945         coerce_it((void*)&(pOpt->pzDetail));
946         coerce_it((void*)&(pOpt->pzPackager));
947         option_usage_text.field_ct = 0;
948 
949         for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
950             coerce_it((void*)&(pOD->pzText));
951     }
952 
953     if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
954         tOptDesc * pOD = pOpt->pOptDesc;
955         int        ix;
956 
957         for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
958             coerce_it((void*)&(pOD->pz_Name));
959             coerce_it((void*)&(pOD->pz_DisableName));
960             coerce_it((void*)&(pOD->pz_DisablePfx));
961         }
962         /* prevent re-translation */
963         ntp_keygenOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
964     }
965 }
966 
967 #endif /* ENABLE_NLS */
968 
969 #ifdef  __cplusplus
970 }
971 #endif
972 /* ntp-keygen-opts.c ends here */
973