diff dbutil.c @ 995:6fb4c010c448

Default client key path ~/.ssh/id_dropbear
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jan 2015 00:05:26 +0800
parents db9fa5971d24
children 257f7d5fca97
line wrap: on
line diff
--- a/dbutil.c	Fri Jan 23 23:00:25 2015 +0800
+++ b/dbutil.c	Sat Jan 24 00:05:26 2015 +0800
@@ -936,6 +936,23 @@
 	}
 }
 
+/* Returns malloced path. Only expands ~ in first character */
+char * expand_tilde(const char *inpath) {
+	struct passwd *pw = NULL;
+	if (inpath[0] == '~') {
+		pw = getpwuid(getuid());
+		if (pw && pw->pw_dir) {
+			int len = strlen(inpath) + strlen(pw->pw_dir) + 1;
+			char *buf = m_malloc(len);
+			snprintf(buf, len, "%s/%s", pw->pw_dir, &inpath[1]);
+			return buf;
+		}
+	}
+
+	/* Fallback */
+	return m_strdup(inpath);
+}
+
 int constant_time_memcmp(const void* a, const void *b, size_t n)
 {
 	const char *xa = a, *xb = b;