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