View | Details | Raw Unified | Return to bug 3156
Collapse All | Expand All

(-)hostfile.c (+27 lines)
Lines 55-60 Link Here
55
#include "hostfile.h"
55
#include "hostfile.h"
56
#include "log.h"
56
#include "log.h"
57
#include "misc.h"
57
#include "misc.h"
58
#include "pathnames.h"
58
#include "ssherr.h"
59
#include "ssherr.h"
59
#include "digest.h"
60
#include "digest.h"
60
#include "hmac.h"
61
#include "hmac.h"
Lines 448-453 write_host_entry(FILE *f, const char *ho Link Here
448
}
449
}
449
450
450
/*
451
/*
452
 * Create user ~/.ssh directory if it doesn't exist and we want to write to it.
453
 */
454
static void
455
create_user_ssh_dir(const char *filename)
456
{
457
	char *dirname = NULL, *p;
458
	size_t len;
459
	struct stat st;
460
461
	if ((p = strrchr(filename, '/')) == NULL)
462
		goto done;
463
	len = p - filename;
464
	dirname = tilde_expand_filename("~/" _PATH_SSH_USER_DIR, getuid());
465
	if (strlen(dirname) > len || strncmp(filename, dirname, len) != 0 ||
466
	    stat(dirname, &st) == 0)
467
		goto done;  /* path not in ~/.ssh or directory exists */
468
	debug3("%s: creating directory %s", __func__, dirname);
469
	if (mkdir(dirname, 0700) == -1)
470
		error("Could not create directory '%.200s' (%s).",
471
		    dirname, strerror(errno));
472
 done:
473
	free(dirname);
474
}
475
476
/*
451
 * Appends an entry to the host file.  Returns false if the entry could not
477
 * Appends an entry to the host file.  Returns false if the entry could not
452
 * be appended.
478
 * be appended.
453
 */
479
 */
Lines 460-465 add_host_to_hostfile(const char *filenam Link Here
460
486
461
	if (key == NULL)
487
	if (key == NULL)
462
		return 1;	/* XXX ? */
488
		return 1;	/* XXX ? */
489
	create_user_ssh_dir(filename);
463
	f = fopen(filename, "a");
490
	f = fopen(filename, "a");
464
	if (!f)
491
	if (!f)
465
		return 0;
492
		return 0;
(-)ssh.c (-11 / +1 lines)
Lines 629-635 main(int ac, char **av) Link Here
629
	struct ssh *ssh = NULL;
629
	struct ssh *ssh = NULL;
630
	int i, r, opt, exit_status, use_syslog, direct, timeout_ms;
630
	int i, r, opt, exit_status, use_syslog, direct, timeout_ms;
631
	int was_addr, config_test = 0, opt_terminated = 0, want_final_pass = 0;
631
	int was_addr, config_test = 0, opt_terminated = 0, want_final_pass = 0;
632
	char *p, *cp, *line, *argv0, buf[PATH_MAX], *logfile;
632
	char *p, *cp, *line, *argv0, *logfile;
633
	char cname[NI_MAXHOST];
633
	char cname[NI_MAXHOST];
634
	struct stat st;
634
	struct stat st;
635
	struct passwd *pw;
635
	struct passwd *pw;
Lines 1549-1564 main(int ac, char **av) Link Here
1549
			L_CERT(_PATH_HOST_XMSS_KEY_FILE, 8);
1549
			L_CERT(_PATH_HOST_XMSS_KEY_FILE, 8);
1550
			L_PUBKEY(_PATH_HOST_XMSS_KEY_FILE, 9);
1550
			L_PUBKEY(_PATH_HOST_XMSS_KEY_FILE, 9);
1551
		}
1551
		}
1552
	}
1553
1554
	/* Create ~/.ssh * directory if it doesn't already exist. */
1555
	if (config == NULL) {
1556
		r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir,
1557
		    strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR);
1558
		if (r > 0 && (size_t)r < sizeof(buf) && stat(buf, &st) == -1)
1559
			if (mkdir(buf, 0700) == -1)
1560
				error("Could not create directory '%.200s'.",
1561
				    buf);
1562
	}
1552
	}
1563
1553
1564
	/* load options.identity_files */
1554
	/* load options.identity_files */

Return to bug 3156