1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-04-17 19:18:06 -05:00

Idiot me _twice_! The new store_host_key() was failing in the

absence of an existing host key file. Duhh.

[originally from svn r3737]
This commit is contained in:
Simon Tatham 2004-01-19 09:37:17 +00:00
parent b4b7ebd5e3
commit 2dd7514b07

View File

@ -507,24 +507,30 @@ void store_host_key(const char *hostname, int port,
/* /*
* Open both the old file and a new file. * Open both the old file and a new file.
*/ */
make_filename(filename, INDEX_HOSTKEYS, NULL);
rfp = fopen(filename, "r");
if (!rfp)
return;
make_filename(tmpfilename, INDEX_HOSTKEYS_TMP, NULL); make_filename(tmpfilename, INDEX_HOSTKEYS_TMP, NULL);
wfp = fopen(tmpfilename, "w"); wfp = fopen(tmpfilename, "w");
if (!wfp) { if (!wfp) {
fclose(rfp); char dir[FILENAME_MAX];
return;
make_filename(dir, INDEX_DIR, NULL);
mkdir(dir, 0700);
wfp = fopen(tmpfilename, "w");
} }
if (!wfp)
return;
make_filename(filename, INDEX_HOSTKEYS, NULL);
rfp = fopen(filename, "r");
/* /*
* Copy all lines from the old file to the new one that _don't_ * Copy all lines from the old file to the new one that _don't_
* involve the same host key identifier as the one we're adding. * involve the same host key identifier as the one we're adding.
*/ */
while ( (line = fgetline(rfp)) ) { if (rfp) {
if (strncmp(line, newtext, headerlen)) while ( (line = fgetline(rfp)) ) {
fputs(line, wfp); if (strncmp(line, newtext, headerlen))
fputs(line, wfp);
}
fclose(rfp);
} }
/* /*
@ -532,7 +538,6 @@ void store_host_key(const char *hostname, int port,
*/ */
fputs(newtext, wfp); fputs(newtext, wfp);
fclose(rfp);
fclose(wfp); fclose(wfp);
rename(tmpfilename, filename); rename(tmpfilename, filename);