1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-22 14:39:24 -05:00

winpgnt: more rigorous command-line processing.

This makes Windows Pageant's slightly ad-hoc command-line handling a
bit more like a standard option loop: we start by deciding whether we
think any given argument _is_ an option or not, and if we think it is,
we give an error message if it's one we don't recognise.
This commit is contained in:
Simon Tatham 2021-04-02 11:02:36 +01:00
parent efc31ee30d
commit 04390ff4a7

View File

@ -1407,30 +1407,42 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
* Process the command line and add keys as listed on it. * Process the command line and add keys as listed on it.
*/ */
split_into_argv(cmdline, &argc, &argv, &argstart); split_into_argv(cmdline, &argc, &argv, &argstart);
bool doing_opts = true;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-pgpfp")) { char *p = argv[i];
pgp_fingerprints_msgbox(NULL); if (*p == '-' && doing_opts) {
return 1; if (!strcmp(p, "-pgpfp")) {
} else if (!strcmp(argv[i], "-restrict-acl") || pgp_fingerprints_msgbox(NULL);
!strcmp(argv[i], "-restrict_acl") || return 1;
!strcmp(argv[i], "-restrictacl")) { } else if (!strcmp(p, "-restrict-acl") ||
restrict_process_acl(); !strcmp(p, "-restrict_acl") ||
} else if (!strcmp(argv[i], "-restrict-putty-acl") || !strcmp(p, "-restrictacl")) {
!strcmp(argv[i], "-restrict_putty_acl")) { restrict_process_acl();
restrict_putty_acl = true; } else if (!strcmp(p, "-restrict-putty-acl") ||
} else if (!strcmp(argv[i], "-c")) { !strcmp(p, "-restrict_putty_acl")) {
/* restrict_putty_acl = true;
* If we see `-c', then the rest of the } else if (!strcmp(p, "-c")) {
* command line should be treated as a /*
* command to be spawned. * If we see `-c', then the rest of the
*/ * command line should be treated as a
if (i < argc-1) * command to be spawned.
command = argstart[i+1]; */
else if (i < argc-1)
command = ""; command = argstart[i+1];
break; else
command = "";
break;
} else if (!strcmp(p, "--")) {
doing_opts = false;
} else {
char *msg = dupprintf("unrecognised command-line option\n"
"'%s'", p);
MessageBox(NULL, msg, "Pageant command-line syntax error",
MB_ICONERROR | MB_OK);
exit(1);
}
} else { } else {
Filename *fn = filename_from_str(argv[i]); Filename *fn = filename_from_str(p);
win_add_keyfile(fn); win_add_keyfile(fn);
filename_free(fn); filename_free(fn);
added_keys = true; added_keys = true;