Convert NextProto message construction to WPACKET
[openssl.git] / apps / openssl.c
1 /*
2  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <openssl/bio.h>
14 #include <openssl/crypto.h>
15 #include <openssl/lhash.h>
16 #include <openssl/conf.h>
17 #include <openssl/x509.h>
18 #include <openssl/pem.h>
19 #include <openssl/ssl.h>
20 #ifndef OPENSSL_NO_ENGINE
21 # include <openssl/engine.h>
22 #endif
23 #include <openssl/err.h>
24 #ifdef OPENSSL_FIPS
25 # include <openssl/fips.h>
26 #endif
27 #define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */
28 #include "s_apps.h"
29 /* Needed to get the other O_xxx flags. */
30 #ifdef OPENSSL_SYS_VMS
31 # include <unixio.h>
32 #endif
33 #define INCLUDE_FUNCTION_TABLE
34 #include "apps.h"
35
36
37 #ifdef OPENSSL_NO_CAMELLIA
38 # define FORMAT "%-15s"
39 # define COLUMNS 5
40 #else
41 # define FORMAT "%-18s"
42 # define COLUMNS 4
43 #endif
44
45 /* Special sentinel to exit the program. */
46 #define EXIT_THE_PROGRAM (-1)
47
48 /*
49  * The LHASH callbacks ("hash" & "cmp") have been replaced by functions with
50  * the base prototypes (we cast each variable inside the function to the
51  * required type of "FUNCTION*"). This removes the necessity for
52  * macro-generated wrapper functions.
53  */
54 static LHASH_OF(FUNCTION) *prog_init(void);
55 static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]);
56 static void list_pkey(void);
57 static void list_type(FUNC_TYPE ft);
58 static void list_disabled(void);
59 char *default_config_file = NULL;
60
61 static CONF *config = NULL;
62 BIO *bio_in = NULL;
63 BIO *bio_out = NULL;
64 BIO *bio_err = NULL;
65
66 static int apps_startup()
67 {
68 #ifdef SIGPIPE
69     signal(SIGPIPE, SIG_IGN);
70 #endif
71
72     /* Set non-default library initialisation settings */
73     if (!OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN
74                              | OPENSSL_INIT_LOAD_CONFIG, NULL))
75         return 0;
76
77 #ifndef OPENSSL_NO_UI
78     setup_ui_method();
79 #endif
80
81     return 1;
82 }
83
84 static void apps_shutdown()
85 {
86 #ifndef OPENSSL_NO_UI
87     destroy_ui_method();
88 #endif
89 }
90
91 static char *make_config_name()
92 {
93     const char *t;
94     size_t len;
95     char *p;
96
97     if ((t = getenv("OPENSSL_CONF")) != NULL)
98         return OPENSSL_strdup(t);
99
100     t = X509_get_default_cert_area();
101     len = strlen(t) + 1 + strlen(OPENSSL_CONF) + 1;
102     p = app_malloc(len, "config filename buffer");
103     strcpy(p, t);
104 #ifndef OPENSSL_SYS_VMS
105     strcat(p, "/");
106 #endif
107     strcat(p, OPENSSL_CONF);
108
109     return p;
110 }
111
112 int main(int argc, char *argv[])
113 {
114     FUNCTION f, *fp;
115     LHASH_OF(FUNCTION) *prog = NULL;
116     char **copied_argv = NULL;
117     char *p, *pname;
118     char buf[1024];
119     const char *prompt;
120     ARGS arg;
121     int first, n, i, ret = 0;
122
123     arg.argv = NULL;
124     arg.size = 0;
125
126     /* Set up some of the environment. */
127     default_config_file = make_config_name();
128     bio_in = dup_bio_in(FORMAT_TEXT);
129     bio_out = dup_bio_out(FORMAT_TEXT);
130     bio_err = dup_bio_err(FORMAT_TEXT);
131
132 #if defined(OPENSSL_SYS_VMS) && defined(__DECC)
133     copied_argv = argv = copy_argv(&argc, argv);
134 #elif defined(_WIN32)
135     /*
136      * Replace argv[] with UTF-8 encoded strings.
137      */
138     win32_utf8argv(&argc, &argv);
139 #endif
140
141     p = getenv("OPENSSL_DEBUG_MEMORY");
142     if (p != NULL && strcmp(p, "on") == 0)
143         CRYPTO_set_mem_debug(1);
144     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
145
146     if (getenv("OPENSSL_FIPS")) {
147 #ifdef OPENSSL_FIPS
148         if (!FIPS_mode_set(1)) {
149             ERR_print_errors(bio_err);
150             return 1;
151         }
152 #else
153         BIO_printf(bio_err, "FIPS mode not supported.\n");
154         return 1;
155 #endif
156     }
157
158     if (!apps_startup())
159         goto end;
160
161     prog = prog_init();
162     pname = opt_progname(argv[0]);
163
164     /* first check the program name */
165     f.name = pname;
166     fp = lh_FUNCTION_retrieve(prog, &f);
167     if (fp != NULL) {
168         argv[0] = pname;
169         ret = fp->func(argc, argv);
170         goto end;
171     }
172
173     /* If there is stuff on the command line, run with that. */
174     if (argc != 1) {
175         argc--;
176         argv++;
177         ret = do_cmd(prog, argc, argv);
178         if (ret < 0)
179             ret = 0;
180         goto end;
181     }
182
183     /* ok, lets enter interactive mode */
184     for (;;) {
185         ret = 0;
186         /* Read a line, continue reading if line ends with \ */
187         for (p = buf, n = sizeof buf, i = 0, first = 1; n > 0; first = 0) {
188             prompt = first ? "OpenSSL> " : "> ";
189             p[0] = '\0';
190 #ifndef READLINE
191             fputs(prompt, stdout);
192             fflush(stdout);
193             if (!fgets(p, n, stdin))
194                 goto end;
195             if (p[0] == '\0')
196                 goto end;
197             i = strlen(p);
198             if (i <= 1)
199                 break;
200             if (p[i - 2] != '\\')
201                 break;
202             i -= 2;
203             p += i;
204             n -= i;
205 #else
206             {
207                 extern char *readline(const char *);
208                 extern void add_history(const char *cp);
209                 char *text;
210
211                 text = readline(prompt);
212                 if (text == NULL)
213                     goto end;
214                 i = strlen(text);
215                 if (i == 0 || i > n)
216                     break;
217                 if (text[i - 1] != '\\') {
218                     p += strlen(strcpy(p, text));
219                     free(text);
220                     add_history(buf);
221                     break;
222                 }
223
224                 text[i - 1] = '\0';
225                 p += strlen(strcpy(p, text));
226                 free(text);
227                 n -= i;
228             }
229 #endif
230         }
231
232         if (!chopup_args(&arg, buf)) {
233             BIO_printf(bio_err, "Can't parse (no memory?)\n");
234             break;
235         }
236
237         ret = do_cmd(prog, arg.argc, arg.argv);
238         if (ret == EXIT_THE_PROGRAM) {
239             ret = 0;
240             goto end;
241         }
242         if (ret != 0)
243             BIO_printf(bio_err, "error in %s\n", arg.argv[0]);
244         (void)BIO_flush(bio_out);
245         (void)BIO_flush(bio_err);
246     }
247     ret = 1;
248  end:
249     OPENSSL_free(copied_argv);
250     OPENSSL_free(default_config_file);
251     NCONF_free(config);
252     config = NULL;
253     lh_FUNCTION_free(prog);
254     OPENSSL_free(arg.argv);
255
256     BIO_free(bio_in);
257     BIO_free_all(bio_out);
258     apps_shutdown();
259 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
260     if (CRYPTO_mem_leaks(bio_err) <= 0)
261         ret = 1;
262 #endif
263     BIO_free(bio_err);
264     EXIT(ret);
265 }
266
267 OPTIONS exit_options[] = {
268     {NULL}
269 };
270
271 static void list_cipher_fn(const EVP_CIPHER *c,
272                            const char *from, const char *to, void *arg)
273 {
274     if (c)
275         BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
276     else {
277         if (!from)
278             from = "<undefined>";
279         if (!to)
280             to = "<undefined>";
281         BIO_printf(arg, "%s => %s\n", from, to);
282     }
283 }
284
285 static void list_md_fn(const EVP_MD *m,
286                        const char *from, const char *to, void *arg)
287 {
288     if (m)
289         BIO_printf(arg, "%s\n", EVP_MD_name(m));
290     else {
291         if (!from)
292             from = "<undefined>";
293         if (!to)
294             to = "<undefined>";
295         BIO_printf((BIO *)arg, "%s => %s\n", from, to);
296     }
297 }
298
299 static void list_missing_help(void)
300 {
301     const FUNCTION *fp;
302     const OPTIONS *o;
303
304     for (fp = functions; fp->name != NULL; fp++) {
305         if ((o = fp->help) == NULL) {
306             BIO_printf(bio_out, "%s *\n", fp->name);
307             continue;
308         }
309         for ( ; o->name != NULL; o++) {
310             if (o->helpstr == NULL)
311                 BIO_printf(bio_out, "%s %s\n", fp->name, o->name);
312         }
313     }
314 }
315
316
317 /* Unified enum for help and list commands. */
318 typedef enum HELPLIST_CHOICE {
319     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
320     OPT_COMMANDS, OPT_DIGEST_COMMANDS,
321     OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
322     OPT_PK_ALGORITHMS, OPT_DISABLED, OPT_MISSING_HELP
323 } HELPLIST_CHOICE;
324
325 OPTIONS list_options[] = {
326     {"help", OPT_HELP, '-', "Display this summary"},
327     {"commands", OPT_COMMANDS, '-', "List of standard commands"},
328     {"digest-commands", OPT_DIGEST_COMMANDS, '-',
329      "List of message digest commands"},
330     {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
331      "List of message digest algorithms"},
332     {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
333     {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
334      "List of cipher algorithms"},
335     {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
336      "List of public key algorithms"},
337     {"disabled", OPT_DISABLED, '-',
338      "List of disabled features"},
339     {"missing-help", OPT_MISSING_HELP, '-',
340      "List missing detailed help strings"},
341     {NULL}
342 };
343
344 int list_main(int argc, char **argv)
345 {
346     char *prog;
347     HELPLIST_CHOICE o;
348     int done = 0;
349
350     prog = opt_init(argc, argv, list_options);
351     while ((o = opt_next()) != OPT_EOF) {
352         switch (o) {
353         case OPT_EOF:  /* Never hit, but suppresses warning */
354         case OPT_ERR:
355             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
356             return 1;
357         case OPT_HELP:
358             opt_help(list_options);
359             break;
360         case OPT_COMMANDS:
361             list_type(FT_general);
362             break;
363         case OPT_DIGEST_COMMANDS:
364             list_type(FT_md);
365             break;
366         case OPT_DIGEST_ALGORITHMS:
367             EVP_MD_do_all_sorted(list_md_fn, bio_out);
368             break;
369         case OPT_CIPHER_COMMANDS:
370             list_type(FT_cipher);
371             break;
372         case OPT_CIPHER_ALGORITHMS:
373             EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out);
374             break;
375         case OPT_PK_ALGORITHMS:
376             list_pkey();
377             break;
378         case OPT_DISABLED:
379             list_disabled();
380             break;
381         case OPT_MISSING_HELP:
382             list_missing_help();
383             break;
384         }
385         done = 1;
386     }
387
388     if (!done) {
389         BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
390         return 1;
391     }
392
393     return 0;
394 }
395
396 OPTIONS help_options[] = {
397     {"help", OPT_HELP, '-', "Display this summary"},
398     {NULL}
399 };
400
401 int help_main(int argc, char **argv)
402 {
403     FUNCTION *fp;
404     int i, nl;
405     FUNC_TYPE tp;
406     char *prog;
407     HELPLIST_CHOICE o;
408
409     prog = opt_init(argc, argv, help_options);
410     while ((o = opt_next()) != OPT_EOF) {
411         switch (o) {
412         default:
413             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
414             return 1;
415         case OPT_HELP:
416             opt_help(help_options);
417             return 0;
418         }
419     }
420
421     if (opt_num_rest() != 0) {
422         BIO_printf(bio_err, "Usage: %s\n", prog);
423         return 1;
424     }
425
426     BIO_printf(bio_err, "\nStandard commands");
427     i = 0;
428     tp = FT_none;
429     for (fp = functions; fp->name != NULL; fp++) {
430         nl = 0;
431         if (((i++) % COLUMNS) == 0) {
432             BIO_printf(bio_err, "\n");
433             nl = 1;
434         }
435         if (fp->type != tp) {
436             tp = fp->type;
437             if (!nl)
438                 BIO_printf(bio_err, "\n");
439             if (tp == FT_md) {
440                 i = 1;
441                 BIO_printf(bio_err,
442                            "\nMessage Digest commands (see the `dgst' command for more details)\n");
443             } else if (tp == FT_cipher) {
444                 i = 1;
445                 BIO_printf(bio_err,
446                            "\nCipher commands (see the `enc' command for more details)\n");
447             }
448         }
449         BIO_printf(bio_err, FORMAT, fp->name);
450     }
451     BIO_printf(bio_err, "\n\n");
452     return 0;
453 }
454
455 int exit_main(int argc, char **argv)
456 {
457     return EXIT_THE_PROGRAM;
458 }
459
460 static void list_type(FUNC_TYPE ft)
461 {
462     FUNCTION *fp;
463     int i = 0;
464
465     for (fp = functions; fp->name != NULL; fp++)
466         if (fp->type == ft) {
467             if ((i++ % COLUMNS) == 0)
468                 BIO_printf(bio_out, "\n");
469             BIO_printf(bio_out, FORMAT, fp->name);
470         }
471     BIO_printf(bio_out, "\n");
472 }
473
474 static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
475 {
476     FUNCTION f, *fp;
477
478     if (argc <= 0 || argv[0] == NULL)
479         return (0);
480     f.name = argv[0];
481     fp = lh_FUNCTION_retrieve(prog, &f);
482     if (fp == NULL) {
483         if (EVP_get_digestbyname(argv[0])) {
484             f.type = FT_md;
485             f.func = dgst_main;
486             fp = &f;
487         } else if (EVP_get_cipherbyname(argv[0])) {
488             f.type = FT_cipher;
489             f.func = enc_main;
490             fp = &f;
491         }
492     }
493     if (fp != NULL) {
494         return (fp->func(argc, argv));
495     }
496     if ((strncmp(argv[0], "no-", 3)) == 0) {
497         /*
498          * User is asking if foo is unsupported, by trying to "run" the
499          * no-foo command.  Strange.
500          */
501         f.name = argv[0] + 3;
502         if (lh_FUNCTION_retrieve(prog, &f) == NULL) {
503             BIO_printf(bio_out, "%s\n", argv[0]);
504             return (0);
505         }
506         BIO_printf(bio_out, "%s\n", argv[0] + 3);
507         return 1;
508     }
509     if (strcmp(argv[0], "quit") == 0 || strcmp(argv[0], "q") == 0 ||
510         strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0)
511         /* Special value to mean "exit the program. */
512         return EXIT_THE_PROGRAM;
513
514     BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
515                argv[0]);
516     return (1);
517 }
518
519 static void list_pkey(void)
520 {
521     int i;
522
523     for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
524         const EVP_PKEY_ASN1_METHOD *ameth;
525         int pkey_id, pkey_base_id, pkey_flags;
526         const char *pinfo, *pem_str;
527         ameth = EVP_PKEY_asn1_get0(i);
528         EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
529                                 &pinfo, &pem_str, ameth);
530         if (pkey_flags & ASN1_PKEY_ALIAS) {
531             BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
532             BIO_printf(bio_out, "\tAlias for: %s\n",
533                        OBJ_nid2ln(pkey_base_id));
534         } else {
535             BIO_printf(bio_out, "Name: %s\n", pinfo);
536             BIO_printf(bio_out, "\tType: %s Algorithm\n",
537                        pkey_flags & ASN1_PKEY_DYNAMIC ?
538                        "External" : "Builtin");
539             BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
540             if (pem_str == NULL)
541                 pem_str = "(none)";
542             BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
543         }
544
545     }
546 }
547
548 static int function_cmp(const FUNCTION * a, const FUNCTION * b)
549 {
550     return strncmp(a->name, b->name, 8);
551 }
552
553 static unsigned long function_hash(const FUNCTION * a)
554 {
555     return OPENSSL_LH_strhash(a->name);
556 }
557
558 static int SortFnByName(const void *_f1, const void *_f2)
559 {
560     const FUNCTION *f1 = _f1;
561     const FUNCTION *f2 = _f2;
562
563     if (f1->type != f2->type)
564         return f1->type - f2->type;
565     return strcmp(f1->name, f2->name);
566 }
567
568 static void list_disabled(void)
569 {
570     BIO_puts(bio_out, "Disabled algorithms:\n");
571 #ifdef OPENSSL_NO_BF
572     BIO_puts(bio_out, "BF\n");
573 #endif
574 #ifndef OPENSSL_NO_BLAKE2
575     BIO_puts(bio_out, "BLAKE2\n");
576 #endif
577 #ifdef OPENSSL_NO_CAMELLIA
578     BIO_puts(bio_out, "CAMELLIA\n");
579 #endif
580 #ifdef OPENSSL_NO_CAST
581     BIO_puts(bio_out, "CAST\n");
582 #endif
583 #ifdef OPENSSL_NO_CMAC
584     BIO_puts(bio_out, "CMAC\n");
585 #endif
586 #ifdef OPENSSL_NO_CMS
587     BIO_puts(bio_out, "CMS\n");
588 #endif
589 #ifdef OPENSSL_NO_COMP
590     BIO_puts(bio_out, "COMP\n");
591 #endif
592 #ifdef OPENSSL_NO_DES
593     BIO_puts(bio_out, "DES\n");
594 #endif
595 #ifdef OPENSSL_NO_DGRAM
596     BIO_puts(bio_out, "DGRAM\n");
597 #endif
598 #ifdef OPENSSL_NO_DH
599     BIO_puts(bio_out, "DH\n");
600 #endif
601 #ifdef OPENSSL_NO_DSA
602     BIO_puts(bio_out, "DSA\n");
603 #endif
604 #if defined(OPENSSL_NO_DTLS)
605     BIO_puts(bio_out, "DTLS\n");
606 #endif
607 #if defined(OPENSSL_NO_DTLS1)
608     BIO_puts(bio_out, "DTLS1\n");
609 #endif
610 #if defined(OPENSSL_NO_DTLS1_2)
611     BIO_puts(bio_out, "DTLS1_2\n");
612 #endif
613 #ifdef OPENSSL_NO_EC
614     BIO_puts(bio_out, "EC\n");
615 #endif
616 #ifdef OPENSSL_NO_EC2M
617     BIO_puts(bio_out, "EC2M\n");
618 #endif
619 #ifdef OPENSSL_NO_ENGINE
620     BIO_puts(bio_out, "ENGINE\n");
621 #endif
622 #ifdef OPENSSL_NO_GOST
623     BIO_puts(bio_out, "GOST\n");
624 #endif
625 #ifdef OPENSSL_NO_HEARTBEATS
626     BIO_puts(bio_out, "HEARTBEATS\n");
627 #endif
628 #ifdef OPENSSL_NO_IDEA
629     BIO_puts(bio_out, "IDEA\n");
630 #endif
631 #ifdef OPENSSL_NO_MD2
632     BIO_puts(bio_out, "MD2\n");
633 #endif
634 #ifdef OPENSSL_NO_MD4
635     BIO_puts(bio_out, "MD4\n");
636 #endif
637 #ifdef OPENSSL_NO_MD5
638     BIO_puts(bio_out, "MD5\n");
639 #endif
640 #ifdef OPENSSL_NO_MDC2
641     BIO_puts(bio_out, "MDC2\n");
642 #endif
643 #ifdef OPENSSL_NO_OCB
644     BIO_puts(bio_out, "OCB\n");
645 #endif
646 #ifdef OPENSSL_NO_OCSP
647     BIO_puts(bio_out, "OCSP\n");
648 #endif
649 #ifdef OPENSSL_NO_PSK
650     BIO_puts(bio_out, "PSK\n");
651 #endif
652 #ifdef OPENSSL_NO_RC2
653     BIO_puts(bio_out, "RC2\n");
654 #endif
655 #ifdef OPENSSL_NO_RC4
656     BIO_puts(bio_out, "RC4\n");
657 #endif
658 #ifdef OPENSSL_NO_RC5
659     BIO_puts(bio_out, "RC5\n");
660 #endif
661 #ifdef OPENSSL_NO_RMD160
662     BIO_puts(bio_out, "RMD160\n");
663 #endif
664 #ifdef OPENSSL_NO_RSA
665     BIO_puts(bio_out, "RSA\n");
666 #endif
667 #ifdef OPENSSL_NO_SCRYPT
668     BIO_puts(bio_out, "SCRYPT\n");
669 #endif
670 #ifdef OPENSSL_NO_SCTP
671     BIO_puts(bio_out, "SCTP\n");
672 #endif
673 #ifdef OPENSSL_NO_SEED
674     BIO_puts(bio_out, "SEED\n");
675 #endif
676 #ifdef OPENSSL_NO_SOCK
677     BIO_puts(bio_out, "SOCK\n");
678 #endif
679 #ifdef OPENSSL_NO_SRP
680     BIO_puts(bio_out, "SRP\n");
681 #endif
682 #ifdef OPENSSL_NO_SRTP
683     BIO_puts(bio_out, "SRTP\n");
684 #endif
685 #ifdef OPENSSL_NO_SSL3
686     BIO_puts(bio_out, "SSL3\n");
687 #endif
688 #ifdef OPENSSL_NO_TLS1
689     BIO_puts(bio_out, "TLS1\n");
690 #endif
691 #ifdef OPENSSL_NO_TLS1_1
692     BIO_puts(bio_out, "TLS1_1\n");
693 #endif
694 #ifdef OPENSSL_NO_TLS1_2
695     BIO_puts(bio_out, "TLS1_2\n");
696 #endif
697 #ifdef OPENSSL_NO_WHIRLPOOL
698     BIO_puts(bio_out, "WHIRLPOOL\n");
699 #endif
700 #ifndef ZLIB
701     BIO_puts(bio_out, "ZLIB\n");
702 #endif
703 }
704
705 static LHASH_OF(FUNCTION) *prog_init(void)
706 {
707     LHASH_OF(FUNCTION) *ret;
708     FUNCTION *f;
709     size_t i;
710
711     /* Sort alphabetically within category. For nicer help displays. */
712     for (i = 0, f = functions; f->name != NULL; ++f, ++i) ;
713     qsort(functions, i, sizeof(*functions), SortFnByName);
714
715     if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL)
716         return (NULL);
717
718     for (f = functions; f->name != NULL; f++)
719         (void)lh_FUNCTION_insert(ret, f);
720     return (ret);
721 }