just fix bug for windows with aid of #ifdef approach and keep the old code intact

This commit is contained in:
lupo1977 2018-02-07 22:51:09 +01:00
parent 5c34676927
commit 521a370765

View File

@ -221,7 +221,8 @@ type_bits_valid(int type, const char *name, u_int32_t *bitsp)
*bitsp = sshkey_curve_nid_to_bits(nid);
if (*bitsp == 0)
*bitsp = DEFAULT_BITS_ECDSA;
} else
}
else
#endif
*bitsp = DEFAULT_BITS;
}
@ -488,9 +489,11 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
if (strstr(type, "dsa")) {
ktype = KEY_DSA;
} else if (strstr(type, "rsa")) {
}
else if (strstr(type, "rsa")) {
ktype = KEY_RSA;
} else {
}
else {
sshbuf_free(b);
free(type);
return NULL;
@ -736,7 +739,8 @@ do_convert_from(struct passwd *pw)
ok = 1;
if (ok)
fprintf(stdout, "\n");
} else {
}
else {
switch (k->type) {
case KEY_DSA:
ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL,
@ -814,7 +818,8 @@ do_download(struct passwd *pw)
printf("%s\n", ra);
free(ra);
free(fp);
} else {
}
else {
(void)sshkey_write(keys[i], stdout); /* XXX check */
fprintf(stdout, "\n");
}
@ -905,7 +910,8 @@ do_fingerprint(struct passwd *pw)
if (strcmp(identity_file, "-") == 0) {
f = stdin;
path = "(stdin)";
} else if ((f = fopen(path, "r")) == NULL)
}
else if ((f = fopen(path, "r")) == NULL)
fatal("%s: %s: %s", __progname, path, strerror(errno));
while (read_keyfile_line(f, path, line, sizeof(line), &lnum) == 0) {
@ -1017,7 +1023,8 @@ do_gen_all_hostkeys(struct passwd *pw)
if (stat(prv_file, &st) == 0) {
if (st.st_size != 0)
goto next;
} else if (errno != ENOENT) {
}
else if (errno != ENOENT) {
error("Could not stat %s: %s", key_types[i].path,
strerror(errno));
goto failnext;
@ -1202,7 +1209,8 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx)
if (l->marker != MRK_NONE) {
/* Don't remove CA and revocation lines */
fprintf(ctx->out, "%s\n", l->line);
} else {
}
else {
/*
* Hostname matches and has no CA/revoke
* marker, delete it by *not* writing the
@ -1214,7 +1222,8 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx)
ctx->host, l->linenum);
}
return 0;
} else if (find_host) {
}
else if (find_host) {
ctx->found_key = 1;
if (!quiet) {
printf("# Host %s found: line %lu %s\n",
@ -1229,11 +1238,13 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx)
mprintf("%s %s %s %s\n", ctx->host,
sshkey_type(l->key), fp, l->comment);
free(fp);
} else
}
else
fprintf(ctx->out, "%s\n", l->line);
return 0;
}
} else if (delete_host) {
}
else if (delete_host) {
/* Retain non-matching hosts when deleting */
if (l->status == HKF_STATUS_INVALID) {
ctx->invalid = 1;
@ -1312,11 +1323,13 @@ do_known_hosts(struct passwd *pw, const char *name)
unlink(tmp);
}
exit(1);
} else if (delete_host && !ctx.found_key) {
}
else if (delete_host && !ctx.found_key) {
logit("Host %s not found in %s", name, identity_file);
if (inplace)
unlink(tmp);
} else if (inplace) {
}
else if (inplace) {
/* Backup existing file */
if (unlink(old) == -1 && errno != ENOENT)
fatal("unlink %.100s: %s", old, strerror(errno));
@ -1377,7 +1390,8 @@ do_change_passphrase(struct passwd *pw)
free(old_passphrase);
if (r != 0)
goto badkey;
} else if (r != 0) {
}
else if (r != 0) {
badkey:
fatal("Failed to load key %s: %s", identity_file, ssh_err(r));
}
@ -1388,7 +1402,8 @@ do_change_passphrase(struct passwd *pw)
if (identity_new_passphrase) {
passphrase1 = xstrdup(identity_new_passphrase);
passphrase2 = NULL;
} else {
}
else {
passphrase1 =
read_passphrase("Enter new passphrase (empty for no "
"passphrase): ", RP_ALLOW_STDIN);
@ -1512,7 +1527,8 @@ do_change_comment(struct passwd *pw)
if (identity_comment) {
strlcpy(new_comment, identity_comment, sizeof(new_comment));
} else {
}
else {
printf("Enter new comment: ");
fflush(stdout);
if (!fgets(new_comment, sizeof(new_comment), stdin)) {
@ -1541,18 +1557,21 @@ do_change_comment(struct passwd *pw)
sshkey_free(private);
strlcat(identity_file, ".pub", sizeof(identity_file));
if ((fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1)
fatal("Could not save your public key in %s: %s",
identity_file, strerror(errno));
fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd == -1)
fatal("Could not save your public key in %s", identity_file);
#ifdef WINDOWS
/* Windows POSIX adpater does not support fdopen() on open(file)*/
close(fd);
if ((f = fopen(identity_file, "w")) == NULL)
fatal("fopen %s failed: %s", identity_file, strerror(errno));
#else /* !WINDOWS */
if ((f = fdopen(fd, "w")) == NULL)
f = fdopen(fd, "w");
if (f == NULL)
fatal("fdopen %s failed: %s", identity_file, strerror(errno));
#endif /* !WINDOWS */
if ((r = sshkey_write(public, f)) != 0)
fatal("write key failed: %s", ssh_err(r));
sshkey_free(public);
@ -1697,7 +1716,8 @@ do_ca_sign(struct passwd *pw, int argc, char **argv)
/* If a PKCS#11 token was specified then try to use it */
if ((ca = load_pkcs11_key(tmp)) == NULL)
fatal("No PKCS#11 key matching %s found", ca_key_path);
} else if (prefer_agent) {
}
else if (prefer_agent) {
/*
* Agent signature requested. Try to use agent after making
* sure the public key specified is actually present in the
@ -1722,7 +1742,8 @@ do_ca_sign(struct passwd *pw, int argc, char **argv)
fatal("CA key %s not found in agent", tmp);
ssh_free_identitylist(agent_ids);
ca->flags |= SSHKEY_FLAG_EXT;
} else {
}
else {
/* CA key is assumed to be a private key on the filesystem */
ca = load_identity(tmp);
}
@ -1780,7 +1801,8 @@ do_ca_sign(struct passwd *pw, int argc, char **argv)
key_type_name, agent_signer, &agent_fd)) != 0)
fatal("Couldn't certify key %s via agent: %s",
tmp, ssh_err(r));
} else {
}
else {
if ((sshkey_certify(public, ca, key_type_name)) != 0)
fatal("Couldn't certify key %s: %s",
tmp, ssh_err(r));
@ -1963,7 +1985,8 @@ add_cert_option(char *opt)
if (certflags_command != NULL)
fatal("force-command already specified");
certflags_command = xstrdup(val);
} else if (strncasecmp(opt, "source-address=", 15) == 0) {
}
else if (strncasecmp(opt, "source-address=", 15) == 0) {
val = opt + 15;
if (*val == '\0')
fatal("Empty source-address option");
@ -1972,7 +1995,8 @@ add_cert_option(char *opt)
if (addr_match_cidr_list(NULL, val) != 0)
fatal("Invalid source-address list");
certflags_src_addr = xstrdup(val);
} else if (strncasecmp(opt, "extension:", 10) == 0 ||
}
else if (strncasecmp(opt, "extension:", 10) == 0 ||
(iscrit = (strncasecmp(opt, "critical:", 9) == 0))) {
val = xstrdup(strchr(opt, ':') + 1);
if ((cp = strchr(val, '=')) != NULL)
@ -1984,7 +2008,8 @@ add_cert_option(char *opt)
NULL : xstrdup(cp);
cert_userext[ncert_userext].crit = iscrit;
ncert_userext++;
} else
}
else
fatal("Unsupported certificate option \"%s\"", opt);
}
@ -2019,7 +2044,8 @@ show_options(struct sshbuf *optbuf, int in_critical)
__func__, ssh_err(r));
printf(" %s\n", arg);
free(arg);
} else {
}
else {
printf(" UNKNOWN OPTION (len %zu)\n",
sshbuf_len(option));
sshbuf_reset(option);
@ -2099,7 +2125,8 @@ do_show_cert(struct passwd *pw)
f = stdin;
path = "(stdin)";
is_stdin = 1;
} else if ((f = fopen(identity_file, "r")) == NULL)
}
else if ((f = fopen(identity_file, "r")) == NULL)
fatal("fopen %s: %s", identity_file, strerror(errno));
while (read_keyfile_line(f, path, line, sizeof(line), &lnum) == 0) {
@ -2168,7 +2195,8 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca,
krl_spec = stdin;
free(path);
path = xstrdup("(standard input)");
} else if ((krl_spec = fopen(path, "r")) == NULL)
}
else if ((krl_spec = fopen(path, "r")) == NULL)
fatal("fopen %s: %s", path, strerror(errno));
if (!quiet)
@ -2187,7 +2215,8 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca,
/* Remember the start of a span of whitespace */
if (r == -1)
r = i;
} else
}
else
r = -1;
}
if (r != -1)
@ -2231,7 +2260,8 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca,
fatal("%s: revoke serial failed",
__func__);
}
} else if (strncasecmp(cp, "id:", 3) == 0) {
}
else if (strncasecmp(cp, "id:", 3) == 0) {
if (ca == NULL && !wild_ca) {
fatal("revoking certificates by key ID "
"requires specification of a CA key");
@ -2240,16 +2270,19 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca,
cp = cp + strspn(cp, " \t");
if (ssh_krl_revoke_cert_by_key_id(krl, ca, cp) != 0)
fatal("%s: revoke key ID failed", __func__);
} else {
}
else {
if (strncasecmp(cp, "key:", 4) == 0) {
cp += 4;
cp = cp + strspn(cp, " \t");
was_explicit_key = 1;
} else if (strncasecmp(cp, "sha1:", 5) == 0) {
}
else if (strncasecmp(cp, "sha1:", 5) == 0) {
cp += 5;
cp = cp + strspn(cp, " \t");
was_sha1 = 1;
} else {
}
else {
/*
* Just try to process the line as a key.
* Parsing will fail if it isn't.
@ -2674,7 +2707,8 @@ main(int argc, char **argv)
error("Too few arguments.");
usage();
}
} else if (argc > 0 && !gen_krl && !check_krl) {
}
else if (argc > 0 && !gen_krl && !check_krl) {
error("Too many arguments.");
usage();
}
@ -2728,7 +2762,8 @@ main(int argc, char **argv)
if (n == 0)
fatal("%s: %s", identity_file, strerror(errno));
exit(0);
} else {
}
else {
n += do_print_resource_record(pw,
_PATH_HOST_RSA_KEY_FILE, rr_hostname);
@ -2771,7 +2806,8 @@ main(int argc, char **argv)
"file \"%s\": %s", identity_file,
strerror(errno));
}
} else
}
else
in = stdin;
if (out == NULL) {
@ -2816,10 +2852,12 @@ main(int argc, char **argv)
if (errno != ENOENT) {
error("Could not stat %s: %s", dotsshdir,
strerror(errno));
} else if (mkdir(dotsshdir, 0700) < 0) {
}
else if (mkdir(dotsshdir, 0700) < 0) {
error("Could not create directory '%s': %s",
dotsshdir, strerror(errno));
} else if (!quiet)
}
else if (!quiet)
printf("Created directory '%s'.\n", dotsshdir);
}
}
@ -2865,7 +2903,8 @@ passphrase_again:
if (identity_comment) {
strlcpy(comment, identity_comment, sizeof(comment));
} else {
}
else {
/* Create default comment field for the passphrase. */
snprintf(comment, sizeof comment, "%s@%s", pw->pw_name, hostname);
}