static int write_host_entry(FILE *f, const char *host, const char *ip, const struct sshkey *key, int store_hash) { int r, success = 0; char *hashed_host = NULL; if (store_hash) { if ((hashed_host = host_hash(host, NULL, 0)) == NULL) { error("%s: host_hash failed", __func__); return 0; } fprintf(f, "%s ", hashed_host); } else if (ip != NULL) fprintf(f, "%s,%s ", host, ip); else fprintf(f, "%s ", host); if ((r = sshkey_write(key, f)) == 0) success = 1; else error("%s: sshkey_write failed: %s", __func__, ssh_err(r)); fputc('\n', f); return success; }
int add_host_to_hostfile(const char *filename, const char *host, const struct sshkey *key, int store_hash) { FILE *f; int r, success = 0; char *hashed_host = NULL; if (key == NULL) return 1; /* XXX ? */ f = fopen(filename, "a"); if (!f) return 0; if (store_hash) { if ((hashed_host = host_hash(host, NULL, 0)) == NULL) { error("add_host_to_hostfile: host_hash failed"); fclose(f); return 0; } } fprintf(f, "%s ", store_hash ? hashed_host : host); if ((r = sshkey_write(key, f)) != 0) { error("%s: saving key in %s failed: %s", __func__, filename, ssh_err(r)); } else success = 1; fputs("\n", f); fclose(f); return success; }
static void keyprint(con *c, struct sshkey *key) { char *host = c->c_output_name ? c->c_output_name : c->c_name; if (!key) return; if (hash_hosts && (host = host_hash(host, NULL, 0)) == NULL) fatal("host_hash failed"); fprintf(stdout, "%s ", host); sshkey_write(key, stdout); fputs("\n", stdout); }
static void keyprint_one(char *host, struct sshkey *key) { char *hostport; if (hash_hosts && (host = host_hash(host, NULL, 0)) == NULL) fatal("host_hash failed"); hostport = put_host_port(host, ssh_port); if (!get_cert) fprintf(stdout, "%s ", hostport); sshkey_write(key, stdout); fputs("\n", stdout); free(hostport); }
static void keyprint_one(const char *host, struct sshkey *key) { char *hostport; const char *known_host, *hashed; found_one = 1; if (print_sshfp) { export_dns_rr(host, key, stdout, 0); return; } hostport = put_host_port(host, ssh_port); lowercase(hostport); if (hash_hosts && (hashed = host_hash(host, NULL, 0)) == NULL) fatal("host_hash failed"); known_host = hash_hosts ? hashed : hostport; if (!get_cert) fprintf(stdout, "%s ", known_host); sshkey_write(key, stdout); fputs("\n", stdout); free(hostport); }
int key_write(const Key *key, FILE *f) { return sshkey_write(key, f) == 0 ? 1 : 0; }