2 * e4crypt.c - ext4 encryption management utility
4 * Copyright (c) 2014 Google, Inc.
5 * SHA512 implementation from libtomcrypt.
7 * Authors: Michael Halcrow <mhalcrow@google.com>,
8 * Ildar Muslukhov <ildarm@google.com>
11 #ifndef _LARGEFILE_SOURCE
12 #define _LARGEFILE_SOURCE
15 #ifndef _LARGEFILE64_SOURCE
16 #define _LARGEFILE64_SOURCE
35 #include <sys/ioctl.h>
37 #include <sys/types.h>
42 #if !defined(HAVE_ADD_KEY) || !defined(HAVE_KEYCTL)
43 #include <sys/syscall.h>
49 #include "ext2fs/ext2_fs.h"
50 #include "ext2fs/ext2fs.h"
51 #include "uuid/uuid.h"
53 /* special process keyring shortcut IDs */
54 #define KEY_SPEC_THREAD_KEYRING -1
55 #define KEY_SPEC_PROCESS_KEYRING -2
56 #define KEY_SPEC_SESSION_KEYRING -3
57 #define KEY_SPEC_USER_KEYRING -4
58 #define KEY_SPEC_USER_SESSION_KEYRING -5
59 #define KEY_SPEC_GROUP_KEYRING -6
61 #define KEYCTL_GET_KEYRING_ID 0
62 #define KEYCTL_JOIN_SESSION_KEYRING 1
63 #define KEYCTL_DESCRIBE 6
64 #define KEYCTL_SEARCH 10
65 #define KEYCTL_SESSION_TO_PARENT 18
67 typedef __s32 key_serial_t;
69 #define EXT4_KEY_REF_STR_BUF_SIZE ((EXT4_KEY_DESCRIPTOR_SIZE * 2) + 1)
71 #ifndef EXT4_IOC_GET_ENCRYPTION_PWSALT
72 #define EXT4_IOC_GET_ENCRYPTION_PWSALT _IOW('f', 20, __u8[16])
75 #define OPT_VERBOSE 0x0001
76 #define OPT_QUIET 0x0002
81 static long keyctl(int cmd, ...)
84 unsigned long arg2, arg3, arg4, arg5;
87 arg2 = va_arg(va, unsigned long);
88 arg3 = va_arg(va, unsigned long);
89 arg4 = va_arg(va, unsigned long);
90 arg5 = va_arg(va, unsigned long);
92 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
97 static key_serial_t add_key(const char *type, const char *description,
98 const void *payload, size_t plen,
101 return syscall(__NR_add_key, type, description, payload,
106 static const unsigned char *hexchars = (const unsigned char *) "0123456789abcdef";
107 static const size_t hexchars_size = 16;
109 #define SHA512_LENGTH 64
110 #define EXT2FS_KEY_TYPE_LOGON "logon"
111 #define EXT2FS_KEY_DESC_PREFIX "ext4:"
112 #define EXT2FS_KEY_DESC_PREFIX_SIZE 5
114 #define EXT4_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct ext4_encryption_policy)
115 #define EXT4_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct ext4_encryption_policy)
117 static int int_log2(int arg)
129 static void validate_paths(int argc, char *argv[], int path_start_index)
135 for (x = path_start_index; x < argc; x++) {
136 int ret = access(argv[x], W_OK);
143 ret = stat(argv[x], &st);
146 if (!S_ISDIR(st.st_mode)) {
147 fprintf(stderr, "%s is not a directory\n", argv[x]);
155 static int hex2byte(const char *hex, size_t hex_size, unsigned char *bytes,
159 unsigned char *h, *l;
163 for (x = 0; x < hex_size; x += 2) {
164 h = memchr(hexchars, hex[x], hexchars_size);
167 l = memchr(hexchars, hex[x + 1], hexchars_size);
170 if ((x >> 1) >= bytes_size)
172 bytes[x >> 1] = (((unsigned char)(h - hexchars) << 4) +
173 (unsigned char)(l - hexchars));
183 char key_ref_str[EXT4_KEY_REF_STR_BUF_SIZE];
184 unsigned char key_desc[EXT4_KEY_DESCRIPTOR_SIZE];
185 unsigned char key[EXT4_MAX_KEY_SIZE];
188 struct salt *salt_list;
191 char in_passphrase[EXT4_MAX_PASSPHRASE_SIZE];
193 static struct salt *find_by_salt(unsigned char *salt, size_t salt_len)
198 for (i = 0, p = salt_list; i < num_salt; i++, p++)
199 if ((p->salt_len == salt_len) &&
200 !memcmp(p->salt, salt, salt_len))
205 static void add_salt(unsigned char *salt, size_t salt_len)
207 if (find_by_salt(salt, salt_len))
209 if (num_salt >= max_salt) {
210 max_salt = num_salt + 10;
211 salt_list = realloc(salt_list, max_salt * sizeof(struct salt));
213 fprintf(stderr, "Couldn't allocate salt list\n");
217 salt_list[num_salt].salt = salt;
218 salt_list[num_salt].salt_len = salt_len;
222 static void clear_secrets(void)
225 memset(salt_list, 0, sizeof(struct salt) * max_salt);
229 memset(in_passphrase, 0, sizeof(in_passphrase));
232 static void die_signal_handler(int signum EXT2FS_ATTR((unused)),
233 siginfo_t *siginfo EXT2FS_ATTR((unused)),
234 void *context EXT2FS_ATTR((unused)))
240 static void sigcatcher_setup(void)
244 memset(&sa, 0, sizeof(struct sigaction));
245 sa.sa_sigaction = die_signal_handler;
246 sa.sa_flags = SA_SIGINFO;
248 sigaction(SIGHUP, &sa, 0);
249 sigaction(SIGINT, &sa, 0);
250 sigaction(SIGQUIT, &sa, 0);
251 sigaction(SIGFPE, &sa, 0);
252 sigaction(SIGILL, &sa, 0);
253 sigaction(SIGBUS, &sa, 0);
254 sigaction(SIGSEGV, &sa, 0);
255 sigaction(SIGABRT, &sa, 0);
256 sigaction(SIGPIPE, &sa, 0);
257 sigaction(SIGALRM, &sa, 0);
258 sigaction(SIGTERM, &sa, 0);
259 sigaction(SIGUSR1, &sa, 0);
260 sigaction(SIGUSR2, &sa, 0);
261 sigaction(SIGPOLL, &sa, 0);
262 sigaction(SIGPROF, &sa, 0);
263 sigaction(SIGSYS, &sa, 0);
264 sigaction(SIGTRAP, &sa, 0);
265 sigaction(SIGVTALRM, &sa, 0);
266 sigaction(SIGXCPU, &sa, 0);
267 sigaction(SIGXFSZ, &sa, 0);
271 #define PARSE_FLAGS_NOTSUPP_OK 0x0001
272 #define PARSE_FLAGS_FORCE_FN 0x0002
274 static void parse_salt(char *salt_str, int flags)
276 unsigned char buf[EXT4_MAX_SALT_SIZE];
278 unsigned char *salt_buf;
279 int fd, ret, salt_len = 0;
281 if (flags & PARSE_FLAGS_FORCE_FN)
282 goto salt_from_filename;
283 if (strncmp(cp, "s:", 2) == 0) {
285 salt_len = strlen(cp);
286 if (salt_len >= EXT4_MAX_SALT_SIZE)
288 strncpy((char *) buf, cp, sizeof(buf));
289 } else if (cp[0] == '/') {
291 fd = open(cp, O_RDONLY | O_DIRECTORY);
292 if (fd == -1 && errno == ENOTDIR)
293 fd = open(cp, O_RDONLY);
298 ret = ioctl(fd, EXT4_IOC_GET_ENCRYPTION_PWSALT, &buf);
301 if (flags & PARSE_FLAGS_NOTSUPP_OK)
303 perror("EXT4_IOC_GET_ENCRYPTION_PWSALT");
306 if (options & OPT_VERBOSE) {
308 uuid_unparse(buf, tmp);
309 printf("%s has pw salt %s\n", cp, tmp);
312 } else if (strncmp(cp, "f:", 2) == 0) {
314 goto salt_from_filename;
315 } else if (strncmp(cp, "0x", 2) == 0) {
316 unsigned char *h, *l;
322 if (salt_len >= EXT4_MAX_SALT_SIZE)
324 h = memchr(hexchars, *cp++, hexchars_size);
325 l = memchr(hexchars, *cp++, hexchars_size);
329 (((unsigned char)(h - hexchars) << 4) +
330 (unsigned char)(l - hexchars));
332 } else if (uuid_parse(cp, buf) == 0) {
336 fprintf(stderr, "Invalid salt: %s\n", salt_str);
339 salt_buf = malloc(salt_len);
341 fprintf(stderr, "Couldn't allocate salt\n");
344 memcpy(salt_buf, buf, salt_len);
345 add_salt(salt_buf, salt_len);
348 static void set_policy(struct salt *set_salt, int pad,
349 int argc, char *argv[], int path_start_index)
352 struct ext4_encryption_policy policy;
358 if ((pad != 4) && (pad != 8) &&
359 (pad != 16) && (pad != 32)) {
360 fprintf(stderr, "Invalid padding %d\n", pad);
364 for (x = path_start_index; x < argc; x++) {
365 fd = open(argv[x], O_DIRECTORY);
373 if (ioctl(fd, EXT4_IOC_GET_ENCRYPTION_PWSALT,
375 perror("EXT4_IOC_GET_ENCRYPTION_PWSALT");
378 salt = find_by_salt(uu, sizeof(uu));
380 fprintf(stderr, "Couldn't find salt!?!\n");
385 policy.contents_encryption_mode =
386 EXT4_ENCRYPTION_MODE_AES_256_XTS;
387 policy.filenames_encryption_mode =
388 EXT4_ENCRYPTION_MODE_AES_256_CTS;
389 policy.flags = int_log2(pad >> 2);
390 memcpy(policy.master_key_descriptor, salt->key_desc,
391 EXT4_KEY_DESCRIPTOR_SIZE);
392 rc = ioctl(fd, EXT4_IOC_SET_ENCRYPTION_POLICY, &policy);
395 printf("Error [%s] setting policy.\nThe key descriptor "
396 "[%s] may not match the existing encryption "
397 "context for directory [%s].\n",
398 strerror(errno), salt->key_ref_str, argv[x]);
401 printf("Key with descriptor [%s] applied to %s.\n",
402 salt->key_ref_str, argv[x]);
406 static void pbkdf2_sha512(const char *passphrase, struct salt *salt,
408 unsigned char derived_key[EXT4_MAX_KEY_SIZE])
410 size_t passphrase_size = strlen(passphrase);
411 unsigned char buf[SHA512_LENGTH + EXT4_MAX_PASSPHRASE_SIZE] = {0};
412 unsigned char tempbuf[SHA512_LENGTH] = {0};
413 char final[SHA512_LENGTH] = {0};
414 unsigned char saltbuf[EXT4_MAX_SALT_SIZE + EXT4_MAX_PASSPHRASE_SIZE] = {0};
415 int actual_buf_len = SHA512_LENGTH + passphrase_size;
416 int actual_saltbuf_len = EXT4_MAX_SALT_SIZE + passphrase_size;
418 __u32 *final_u32 = (__u32 *)final;
419 __u32 *temp_u32 = (__u32 *)tempbuf;
421 if (passphrase_size > EXT4_MAX_PASSPHRASE_SIZE) {
422 printf("Passphrase size is %zd; max is %d.\n", passphrase_size,
423 EXT4_MAX_PASSPHRASE_SIZE);
426 if (salt->salt_len > EXT4_MAX_SALT_SIZE) {
427 printf("Salt size is %zd; max is %d.\n", salt->salt_len,
431 assert(EXT4_MAX_KEY_SIZE <= SHA512_LENGTH);
433 memcpy(saltbuf, salt->salt, salt->salt_len);
434 memcpy(&saltbuf[EXT4_MAX_SALT_SIZE], passphrase, passphrase_size);
436 memcpy(&buf[SHA512_LENGTH], passphrase, passphrase_size);
438 for (x = 0; x < count; ++x) {
440 ext2fs_sha512(saltbuf, actual_saltbuf_len, tempbuf);
443 * buf: [previous hash || passphrase]
445 memcpy(buf, tempbuf, SHA512_LENGTH);
446 ext2fs_sha512(buf, actual_buf_len, tempbuf);
448 for (y = 0; y < (sizeof(final) / sizeof(*final_u32)); ++y)
449 final_u32[y] = final_u32[y] ^ temp_u32[y];
451 memcpy(derived_key, final, EXT4_MAX_KEY_SIZE);
454 static int disable_echo(struct termios *saved_settings)
456 struct termios current_settings;
459 rc = tcgetattr(0, ¤t_settings);
462 *saved_settings = current_settings;
463 current_settings.c_lflag &= ~ECHO;
464 rc = tcsetattr(0, TCSANOW, ¤t_settings);
469 static void get_passphrase(char *passphrase, int len)
472 struct termios current_settings;
475 disable_echo(¤t_settings);
476 p = fgets(passphrase, len, stdin);
477 tcsetattr(0, TCSANOW, ¤t_settings);
480 printf("Aborting.\n");
483 p = strrchr(passphrase, '\n');
485 p = passphrase + len - 1;
495 static const struct keyring_map keyrings[] = {
496 {"@us", 3, KEY_SPEC_USER_SESSION_KEYRING},
497 {"@u", 2, KEY_SPEC_USER_KEYRING},
498 {"@s", 2, KEY_SPEC_SESSION_KEYRING},
499 {"@g", 2, KEY_SPEC_GROUP_KEYRING},
500 {"@p", 2, KEY_SPEC_PROCESS_KEYRING},
501 {"@t", 2, KEY_SPEC_THREAD_KEYRING},
504 static int get_keyring_id(const char *keyring)
510 * If no keyring is specified, by default use either the user
511 * session keyring or the session keyring. Fetching the
512 * session keyring will return the user session keyring if no
513 * session keyring has been set.
516 return KEY_SPEC_SESSION_KEYRING;
517 for (x = 0; x < (sizeof(keyrings) / sizeof(keyrings[0])); ++x) {
518 if (strcmp(keyring, keyrings[x].name) == 0) {
519 return keyrings[x].code;
522 x = strtoul(keyring, &end, 10);
524 if (keyctl(KEYCTL_DESCRIBE, x, NULL, 0) < 0)
531 static void generate_key_ref_str(struct salt *salt)
533 unsigned char key_ref1[SHA512_LENGTH];
534 unsigned char key_ref2[SHA512_LENGTH];
537 ext2fs_sha512(salt->key, EXT4_MAX_KEY_SIZE, key_ref1);
538 ext2fs_sha512(key_ref1, SHA512_LENGTH, key_ref2);
539 memcpy(salt->key_desc, key_ref2, EXT4_KEY_DESCRIPTOR_SIZE);
540 for (x = 0; x < EXT4_KEY_DESCRIPTOR_SIZE; ++x) {
541 sprintf(&salt->key_ref_str[x * 2], "%02x",
544 salt->key_ref_str[EXT4_KEY_REF_STR_BUF_SIZE - 1] = '\0';
547 static void insert_key_into_keyring(const char *keyring, struct salt *salt)
549 int keyring_id = get_keyring_id(keyring);
550 struct ext4_encryption_key key;
551 char key_ref_full[EXT2FS_KEY_DESC_PREFIX_SIZE +
552 EXT4_KEY_REF_STR_BUF_SIZE];
555 if (keyring_id == 0) {
556 printf("Invalid keyring [%s].\n", keyring);
559 sprintf(key_ref_full, "%s%s", EXT2FS_KEY_DESC_PREFIX,
561 rc = keyctl(KEYCTL_SEARCH, keyring_id, EXT2FS_KEY_TYPE_LOGON,
564 if ((options & OPT_QUIET) == 0)
565 printf("Key with descriptor [%s] already exists\n",
568 } else if ((rc == -1) && (errno != ENOKEY)) {
569 printf("keyctl_search failed: %s\n", strerror(errno));
571 printf("Keyring [%s] is not available.\n", keyring);
574 key.mode = EXT4_ENCRYPTION_MODE_AES_256_XTS;
575 memcpy(key.raw, salt->key, EXT4_MAX_KEY_SIZE);
576 key.size = EXT4_MAX_KEY_SIZE;
579 * We need to do this instead of simply adding the key to
580 * KEY_SPEC_SESSION_KEYRING since trying to add a key to a
581 * session keyring that does not yet exist will cause the
582 * kernel to create a session keyring --- which will then get
583 * garbage collected as soon as e4crypt exits.
585 * The fact that the keyctl system call and the add_key system
586 * call treats KEY_SPEC_SESSION_KEYRING differently when a
587 * session keyring does not exist is very unfortunate and
588 * confusing, but so it goes...
590 if (keyring_id == KEY_SPEC_SESSION_KEYRING) {
591 keyring_id = keyctl(KEYCTL_GET_KEYRING_ID, keyring_id, 0);
592 if (keyring_id < 0) {
593 printf("Error getting session keyring ID: %s\n",
598 rc = add_key(EXT2FS_KEY_TYPE_LOGON, key_ref_full, (void *)&key,
599 sizeof(key), keyring_id);
601 if (errno == EDQUOT) {
602 printf("Error adding key to keyring; quota exceeded\n");
604 printf("Error adding key with key descriptor [%s]: "
605 "%s\n", salt->key_ref_str, strerror(errno));
609 if ((options & OPT_QUIET) == 0)
610 printf("Added key with descriptor [%s]\n",
615 static void get_default_salts(void)
617 FILE *f = setmntent("/etc/mtab", "r");
620 while (f && ((mnt = getmntent(f)) != NULL)) {
621 if (strcmp(mnt->mnt_type, "ext4") ||
622 access(mnt->mnt_dir, R_OK))
624 parse_salt(mnt->mnt_dir, PARSE_FLAGS_NOTSUPP_OK);
629 /* Functions which implement user commands */
632 const char *cmd_name;
633 void (*cmd_func)(int, char **, const struct cmd_desc *);
634 const char *cmd_desc;
635 const char *cmd_help;
639 #define CMD_HIDDEN 0x0001
641 static void do_help(int argc, char **argv, const struct cmd_desc *cmd);
643 #define add_key_desc "adds a key to the user's keyring"
644 #define add_key_help \
645 "e4crypt add_key -S salt [ -k keyring ] [-v] [-q] [ -p pad ] [ path ... ]\n\n" \
646 "Prompts the user for a passphrase and inserts it into the specified\n" \
647 "keyring. If no keyring is specified, e4crypt will use the session\n" \
648 "keyring if it exists or the user session keyring if it does not.\n\n" \
649 "If one or more directory paths are specified, e4crypt will try to\n" \
650 "set the policy of those directories to use the key just entered by\n" \
653 static void do_add_key(int argc, char **argv, const struct cmd_desc *cmd)
656 bool explicit_salt = false;
657 char *keyring = NULL;
661 while ((opt = getopt(argc, argv, "k:S:p:vq")) != -1) {
664 /* Specify a keyring. */
672 fputs("May only provide -S once\n", stderr);
675 /* Salt value for passphrase. */
676 parse_salt(optarg, 0);
677 explicit_salt = true;
680 options |= OPT_VERBOSE;
683 options |= OPT_QUIET;
688 fprintf(stderr, "Unrecognized option: %c\n",
690 fputs("USAGE:\n ", stderr);
691 fputs(cmd->cmd_help, stderr);
698 fprintf(stderr, "No salt values available\n");
701 validate_paths(argc, argv, optind);
703 for (i = optind; i < argc; i++)
704 parse_salt(argv[i], PARSE_FLAGS_FORCE_FN);
705 printf("Enter passphrase (echo disabled): ");
706 get_passphrase(in_passphrase, sizeof(in_passphrase));
707 for (j = 0, salt = salt_list; j < num_salt; j++, salt++) {
708 pbkdf2_sha512(in_passphrase, salt,
709 EXT4_PBKDF2_ITERATIONS, salt->key);
710 generate_key_ref_str(salt);
711 insert_key_into_keyring(keyring, salt);
713 if (optind != argc) {
714 salt = explicit_salt ? salt_list : NULL;
715 set_policy(salt, pad, argc, argv, optind);
721 #define set_policy_desc "sets a policy for directories"
722 #define set_policy_help \
723 "e4crypt set_policy [ -p pad ] policy path ... \n\n" \
724 "Sets the policy for the directories specified on the command line.\n" \
725 "All directories must be empty to set the policy; if the directory\n" \
726 "already has a policy established, e4crypt will validate that it the\n" \
727 "policy matches what was specified. A policy is an encryption key\n" \
728 "identifier consisting of 16 hexadecimal characters.\n"
730 static void do_set_policy(int argc, char **argv, const struct cmd_desc *cmd)
735 while ((c = getopt (argc, argv, "p:")) != EOF) {
743 if (argc < optind + 2) {
744 fprintf(stderr, "Missing required argument(s).\n\n");
745 fputs("USAGE:\n ", stderr);
746 fputs(cmd->cmd_help, stderr);
750 if ((strlen(argv[optind]) != (EXT4_KEY_DESCRIPTOR_SIZE * 2)) ||
751 hex2byte(argv[optind], (EXT4_KEY_DESCRIPTOR_SIZE * 2),
752 saltbuf.key_desc, EXT4_KEY_DESCRIPTOR_SIZE)) {
753 printf("Invalid key descriptor [%s]. Valid characters "
754 "are 0-9 and a-f, lower case. "
755 "Length must be %d.\n",
756 argv[optind], (EXT4_KEY_DESCRIPTOR_SIZE * 2));
759 validate_paths(argc, argv, optind+1);
760 strcpy(saltbuf.key_ref_str, argv[optind]);
761 set_policy(&saltbuf, pad, argc, argv, optind+1);
765 #define get_policy_desc "get the encryption for directories"
766 #define get_policy_help \
767 "e4crypt get_policy path ... \n\n" \
768 "Gets the policy for the directories specified on the command line.\n"
770 static void do_get_policy(int argc, char **argv, const struct cmd_desc *cmd)
772 struct ext4_encryption_policy policy;
776 fprintf(stderr, "Missing required argument(s).\n\n");
777 fputs("USAGE:\n ", stderr);
778 fputs(cmd->cmd_help, stderr);
782 for (i = 1; i < argc; i++) {
783 fd = open(argv[i], O_RDONLY);
788 rc = ioctl(fd, EXT4_IOC_GET_ENCRYPTION_POLICY, &policy);
791 printf("Error getting policy for %s: %s\n",
792 argv[i], strerror(errno));
795 printf("%s: ", argv[i]);
796 for (j = 0; j < EXT4_KEY_DESCRIPTOR_SIZE; j++) {
797 printf("%02x", (unsigned char) policy.master_key_descriptor[j]);
804 #define new_session_desc "give the invoking process a new session keyring"
805 #define new_session_help \
806 "e4crypt new_session\n\n" \
807 "Give the invoking process (typically a shell) a new session keyring,\n" \
808 "discarding its old session keyring.\n"
810 static void do_new_session(int argc, char **argv EXT2FS_ATTR((unused)),
811 const struct cmd_desc *cmd)
816 fputs("Excess arguments\n\n", stderr);
817 fputs(cmd->cmd_help, stderr);
820 keyid = keyctl(KEYCTL_JOIN_SESSION_KEYRING, NULL);
822 perror("KEYCTL_JOIN_SESSION_KEYRING");
825 ret = keyctl(KEYCTL_SESSION_TO_PARENT, NULL);
827 perror("KEYCTL_SESSION_TO_PARENT");
830 printf("Switched invoking process to new session keyring %ld\n", keyid);
834 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
835 #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
837 const struct cmd_desc cmd_list[] = {
843 { NULL, NULL, NULL, NULL, 0 }
846 static void do_help(int argc, char **argv,
847 const struct cmd_desc *cmd EXT2FS_ATTR((unused)))
849 const struct cmd_desc *p;
852 for (p = cmd_list; p->cmd_name; p++) {
853 if (p->cmd_flags & CMD_HIDDEN)
855 if (strcmp(p->cmd_name, argv[1]) == 0) {
857 fputs("USAGE:\n ", stdout);
858 fputs(p->cmd_help, stdout);
862 printf("Unknown command: %s\n\n", argv[1]);
865 fputs("Available commands:\n", stdout);
866 for (p = cmd_list; p->cmd_name; p++) {
867 if (p->cmd_flags & CMD_HIDDEN)
869 printf(" %-20s %s\n", p->cmd_name, p->cmd_desc);
871 printf("\nTo get more information on a command, "
872 "type 'e4crypt help cmd'\n");
876 int main(int argc, char *argv[])
878 const struct cmd_desc *cmd;
881 do_help(argc, argv, cmd_list);
884 for (cmd = cmd_list; cmd->cmd_name; cmd++) {
885 if (strcmp(cmd->cmd_name, argv[1]) == 0) {
886 cmd->cmd_func(argc-1, argv+1, cmd);
890 printf("Unknown command: %s\n\n", argv[1]);
891 do_help(1, argv, cmd_list);