| 619 | |
| 620 | |
| 621 | int wmain(int argc, wchar_t * const argv[]) |
| 622 | { |
| 623 | if (argc < 2) |
| 624 | return 0; |
| 625 | |
| 626 | // Set output mode of stdout and stderr to UTF-16 |
| 627 | _setmode(_fileno(stdout), _O_U16TEXT); |
| 628 | _setmode(_fileno(stderr), _O_U16TEXT); |
| 629 | |
| 630 | vector<wstring> self_args; |
| 631 | |
| 632 | self_args.push_back(L"-h"); |
| 633 | self_args.push_back(L"--help"); |
| 634 | self_args.push_back(L"-I"); |
| 635 | self_args.push_back(L"--init"); |
| 636 | self_args.push_back(L"-0"); |
| 637 | self_args.push_back(L"--changepassword"); |
| 638 | self_args.push_back(L"-1"); |
| 639 | self_args.push_back(L"--printmasterkey"); |
| 640 | self_args.push_back(L"-2"); |
| 641 | self_args.push_back(L"--recover"); |
| 642 | |
| 643 | vector<wstring> mounting_args; |
| 644 | |
| 645 | mounting_args.push_back(L"-m"); |
| 646 | mounting_args.push_back(L"--mount"); |
| 647 | |
| 648 | vector<wstring> password_args; |
| 649 | |
| 650 | password_args.push_back(L"-p"); |
| 651 | password_args.push_back(L"--password"); |
| 652 | |
| 653 | // if we are doing certain things like initializing a filesystem then we handle |
| 654 | // it in cppcryptfsctl instead of passing the command line to cppcryptfs |
| 655 | |
| 656 | bool have_mounting_arg = false; |
| 657 | |
| 658 | bool have_password_arg = false; |
| 659 | |
| 660 | for (int i = 1; i < argc; ++i) { |
| 661 | for (const auto& self_arg : self_args) { |
| 662 | if (wcsncmp(argv[i], self_arg.c_str(), self_arg.length()) == 0) { |
| 663 | return do_self_args(argc, argv); |
| 664 | } |
| 665 | } |
| 666 | if (!have_mounting_arg) { |
| 667 | for (const auto& arg : mounting_args) { |
| 668 | if (wcsncmp(argv[i], arg.c_str(), arg.length()) == 0) { |
| 669 | have_mounting_arg = true; |
| 670 | break; |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | if (!have_password_arg) { |
| 675 | for (const auto& arg : password_args) { |
| 676 | if (wcsncmp(argv[i], arg.c_str(), arg.length()) == 0) { |
| 677 | have_password_arg = true; |
| 678 | break; |
nothing calls this directly
no test coverage detected