fuchsia: allow arbitrary usernames < 32 chars

This opens the door for later changes wherein we'd want user specific
username.

Change-Id: I82204e454408e1772d18394eb4e031550df43ba2
diff --git a/fuchsia/fuchsia-compat.c b/fuchsia/fuchsia-compat.c
index 3aed8d9..9d28402 100644
--- a/fuchsia/fuchsia-compat.c
+++ b/fuchsia/fuchsia-compat.c
@@ -59,26 +59,31 @@
 	return 0;
 }
 
-struct passwd* getpwent(void) {
-	static struct passwd static_passwd = {
-			.pw_name = "fuchsia",
-			.pw_passwd = "",
-			.pw_uid = 23,  // matches ZX_UID
-			.pw_gid = 23,
-			.pw_gecos = "Fuchsia",
-			.pw_dir = "/",
-			.pw_shell = "/boot/bin/sh",
-	};
+#define USERNAME_MAX 32
+static char username[USERNAME_MAX + 1] = { 'f', 'u', 'c', 'h', 's', 'i', 'a', 0 };
+static struct passwd static_passwd = {
+	.pw_name = username,
+	.pw_passwd = "",
+	.pw_uid = 23,  // matches ZX_UID
+	.pw_gid = 23,
+	.pw_gecos = "Fuchsia",
+	.pw_dir = "/",
+	.pw_shell = "/boot/bin/sh",
+};
 
+struct passwd* getpwnam(const char* name) {
+	size_t len = strlen(name);
+	if (len > USERNAME_MAX) {
+		errno = EINVAL;
+		return NULL;
+	}
+	strncpy(username, name, len);
+	username[len] = 0;
 	return &static_passwd;
 }
 
-struct passwd* getpwnam(const char* name) {
-	return getpwent();
-}
-
 struct passwd* getpwuid(uid_t uid) {
-	return getpwent();
+	return &static_passwd;
 }
 
 #define ARGV_MAX 256