int main(int argc, char *argv[]) { char *subcmd; int cmdnum; int cmd_index = 0; int rc = SUCCESS; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ #endif (void) textdomain(TEXT_DOMAIN); cryptodebug_init(basename(argv[0])); if (argc < REQ_ARG_CNT) { usage(); return (ERROR_USAGE); } /* get the subcommand index */ cmd_index = 0; subcmd = argv[1]; cmdnum = sizeof (cmd_table)/sizeof (cmd_table[0]); while ((cmd_index < cmdnum) && (strcmp(subcmd, cmd_table[cmd_index]) != 0)) { cmd_index++; } if (cmd_index >= cmdnum) { usage(); return (ERROR_USAGE); } /* do the subcommand */ switch (cmd_index) { case CRYPTO_LIST: rc = do_list(argc, argv); break; case CRYPTO_DISABLE: rc = do_disable(argc, argv); break; case CRYPTO_ENABLE: rc = do_enable(argc, argv); break; case CRYPTO_INSTALL: rc = do_install(argc, argv); break; case CRYPTO_UNINSTALL: rc = do_uninstall(argc, argv); break; case CRYPTO_UNLOAD: rc = do_unload(argc, argv); break; case CRYPTO_REFRESH: rc = do_refresh(argc); break; case CRYPTO_START: rc = do_start(argc); break; case CRYPTO_STOP: rc = do_stop(argc); break; case CRYPTO_HELP: usage(); rc = SUCCESS; break; default: /* should not come here */ usage(); rc = ERROR_USAGE; break; } return (rc); }
/* * MAIN() -- where all the action is */ int main(int argc, char *argv[], char *envp[]) /* ARGSUSED2 */ { int i, found = -1; int rv; int pk_argc = 0; char **pk_argv = NULL; int save_errno = 0; /* Set up for i18n/l10n. */ (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D. */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't. */ #endif (void) textdomain(TEXT_DOMAIN); /* Get program base name and move pointer over 0th arg. */ prog = basename(argv[0]); argv++, argc--; /* Set up for debug and error output. */ cryptodebug_init(prog); if (argc == 0) { usage(); return (1); } /* Check for help options. For CLIP-compliance. */ if (argc == 1 && argv[0][0] == '-') { switch (argv[0][1]) { case '?': return (pk_help(argc, argv)); default: usage(); return (1); } } /* Always turns off Metaslot so that we can see softtoken. */ cryptodebug("disabling Metaslot"); if (setenv("METASLOT_ENABLED", "false", 1) < 0) { save_errno = errno; cryptoerror(LOG_STDERR, gettext("Disabling Metaslot failed (%s)."), strerror(save_errno)); return (1); } /* Begin parsing command line. */ cryptodebug("begin parsing command line"); pk_argc = argc; pk_argv = argv; /* Check for valid verb (or an abbreviation of it). */ found = -1; for (i = 0; i < num_cmds; i++) { if (strcmp(cmds[i].verb, pk_argv[0]) == 0) { if (found < 0) { cryptodebug("found cmd %s", cmds[i].verb); found = i; break; } else { cryptodebug("also found cmd %s, skipping", cmds[i].verb); } } } /* Stop here if no valid verb found. */ if (found < 0) { cryptoerror(LOG_STDERR, gettext("Invalid verb: %s"), pk_argv[0]); return (1); } /* Get to work! */ cryptodebug("begin executing cmd action"); rv = (*cmds[found].action)(pk_argc, pk_argv); cryptodebug("end executing cmd action"); switch (rv) { case PK_ERR_NONE: cryptodebug("subcommand succeeded"); break; /* Command succeeded, do nothing. */ case PK_ERR_USAGE: cryptodebug("usage error detected"); usage(); break; case PK_ERR_QUIT: cryptodebug("quit command received"); exit(0); /* NOTREACHED */ case PK_ERR_PK11: cryptoerror(LOG_STDERR, "%s", gettext("Command failed due to PKCS#11 error.")); break; case PK_ERR_SYSTEM: cryptoerror(LOG_STDERR, "%s", gettext("Command failed due to system error.")); break; case PK_ERR_OPENSSL: cryptoerror(LOG_STDERR, "%s", gettext("Command failed due to OpenSSL error.")); break; default: cryptoerror(LOG_STDERR, "%s (%d).", gettext("Unknown error value"), rv); break; } return (rv); }