From ee6b1642b1813d57bfbab47dae7d88cd5dbc18ca Mon Sep 17 00:00:00 2001 From: Paul Crowley Date: Thu, 10 Dec 2015 16:51:53 +0000 Subject: [PATCH] Use Jeff's C++ style for finding the subcommand consistently. Change-Id: I2c7333de680cf5d350894f5064e955969e804781 --- CryptCommandListener.cpp | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/CryptCommandListener.cpp b/CryptCommandListener.cpp index fc27277..93f953f 100644 --- a/CryptCommandListener.cpp +++ b/CryptCommandListener.cpp @@ -144,20 +144,20 @@ int CryptCommandListener::CryptfsCmd::runCommand(SocketClient *cli, int rc = 0; - std::string cmd(argv[1]); - if (!strcmp(argv[1], "checkpw")) { + std::string subcommand(argv[1]); + if (subcommand == "checkpw") { CHECK_ARGC(3, "checkpw "); dumpArgs(argc, argv, 2); rc = cryptfs_check_passwd(argv[2]); - } else if (!strcmp(argv[1], "restart")) { + } else if (subcommand == "restart") { CHECK_ARGC(2, "restart"); dumpArgs(argc, argv, -1); rc = cryptfs_restart(); - } else if (!strcmp(argv[1], "cryptocomplete")) { + } else if (subcommand == "cryptocomplete") { CHECK_ARGC(2, "cryptocomplete"); dumpArgs(argc, argv, -1); rc = cryptfs_crypto_complete(); - } else if (!strcmp(argv[1], "enablecrypto")) { + } else if (subcommand == "enablecrypto") { const char* syntax = "Usage: cryptfs enablecrypto " "default|password|pin|pattern [passwd] [noui]"; @@ -227,11 +227,11 @@ int CryptCommandListener::CryptfsCmd::runCommand(SocketClient *cli, Process::killProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL); } } - } else if (!strcmp(argv[1], "enablefilecrypto")) { + } else if (subcommand == "enablefilecrypto") { CHECK_ARGC(2, "enablefilecrypto"); dumpArgs(argc, argv, -1); rc = cryptfs_enable_file(); - } else if (!strcmp(argv[1], "changepw")) { + } else if (subcommand == "changepw") { const char* syntax = "Usage: cryptfs changepw " "default|password|pin|pattern [newpasswd]"; const char* password; @@ -250,11 +250,11 @@ int CryptCommandListener::CryptfsCmd::runCommand(SocketClient *cli, } SLOGD("cryptfs changepw %s {}", argv[2]); rc = cryptfs_changepw(type, password); - } else if (!strcmp(argv[1], "verifypw")) { + } else if (subcommand == "verifypw") { CHECK_ARGC(3, "verifypw "); SLOGD("cryptfs verifypw {}"); rc = cryptfs_verify_passwd(argv[2]); - } else if (!strcmp(argv[1], "getfield")) { + } else if (subcommand == "getfield") { CHECK_ARGC(3, "getfield "); char *valbuf; int valbuf_len = PROPERTY_VALUE_MAX; @@ -279,16 +279,16 @@ int CryptCommandListener::CryptfsCmd::runCommand(SocketClient *cli, cli->sendMsg(ResponseCode::CryptfsGetfieldResult, valbuf, false); } free(valbuf); - } else if (!strcmp(argv[1], "setfield")) { + } else if (subcommand == "setfield") { CHECK_ARGC(4, "setfield "); dumpArgs(argc, argv, -1); rc = cryptfs_setfield(argv[2], argv[3]); - } else if (!strcmp(argv[1], "mountdefaultencrypted")) { + } else if (subcommand == "mountdefaultencrypted") { CHECK_ARGC(2, "mountdefaultencrypted"); SLOGD("cryptfs mountdefaultencrypted"); dumpArgs(argc, argv, -1); rc = cryptfs_mount_default_encrypted(); - } else if (!strcmp(argv[1], "getpwtype")) { + } else if (subcommand == "getpwtype") { CHECK_ARGC(2, "getpwtype"); SLOGD("cryptfs getpwtype"); dumpArgs(argc, argv, -1); @@ -310,7 +310,7 @@ int CryptCommandListener::CryptfsCmd::runCommand(SocketClient *cli, cli->sendMsg(ResponseCode::OpFailedStorageNotFound, "Error", false); return 0; } - } else if (!strcmp(argv[1], "getpw")) { + } else if (subcommand == "getpw") { CHECK_ARGC(2, "getpw"); SLOGD("cryptfs getpw"); dumpArgs(argc, argv, -1); @@ -326,52 +326,52 @@ int CryptCommandListener::CryptfsCmd::runCommand(SocketClient *cli, } } rc = -1; - } else if (!strcmp(argv[1], "clearpw")) { + } else if (subcommand == "clearpw") { CHECK_ARGC(2, "clearpw"); SLOGD("cryptfs clearpw"); dumpArgs(argc, argv, -1); cryptfs_clear_password(); rc = 0; - } else if (!strcmp(argv[1], "setusercryptopolicies")) { + } else if (subcommand == "setusercryptopolicies") { CHECK_ARGC(3, "setusercryptopolicies "); SLOGD("cryptfs setusercryptopolicies"); dumpArgs(argc, argv, -1); rc = e4crypt_vold_set_user_crypto_policies(argv[2]); - } else if (!strcmp(argv[1], "isConvertibleToFBE")) { + } else if (subcommand == "isConvertibleToFBE") { CHECK_ARGC(2, "isConvertibleToFBE"); // ext4enc:TODO: send a CommandSyntaxError if argv[2] not an integer SLOGD("cryptfs isConvertibleToFBE"); dumpArgs(argc, argv, -1); rc = cryptfs_isConvertibleToFBE(); - } else if (cmd == "create_user_key") { + } else if (subcommand == "create_user_key") { CHECK_ARGC(5, "create_user_key "); return sendGenericOkFail(cli, e4crypt_vold_create_user_key(atoi(argv[2]), atoi(argv[3]), atoi(argv[4]) != 0)); - } else if (cmd == "destroy_user_key") { + } else if (subcommand == "destroy_user_key") { CHECK_ARGC(3, "destroy_user_key "); return sendGenericOkFail(cli, e4crypt_destroy_user_key(atoi(argv[2]))); - } else if (cmd == "unlock_user_key") { + } else if (subcommand == "unlock_user_key") { CHECK_ARGC(5, "unlock_user_key "); return sendGenericOkFail(cli, e4crypt_unlock_user_key(atoi(argv[2]), parseNull(argv[4]))); - } else if (cmd == "lock_user_key") { + } else if (subcommand == "lock_user_key") { CHECK_ARGC(3, "lock_user_key "); return sendGenericOkFail(cli, e4crypt_lock_user_key(atoi(argv[2]))); - } else if (cmd == "prepare_user_storage") { + } else if (subcommand == "prepare_user_storage") { CHECK_ARGC(6, "prepare_user_storage "); return sendGenericOkFail(cli, e4crypt_prepare_user_storage( parseNull(argv[2]), atoi(argv[3]), atoi(argv[4]) != 0)); } else { dumpArgs(argc, argv, -1); - cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown cryptfs cmd", false); + cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown cryptfs subcommand", false); return 0; }