1 diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm64/usr/include/pwd.h ./usr/include/pwd.h
2 --- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm64/usr/include/pwd.h 2017-02-27 17:27:10.000000000 +0100
3 +++ ./usr/include/pwd.h 2017-03-05 13:28:19.227658358 +0100
8 +/* For access() and realpath(): */
12 #define _PATH_PASSWD "/etc/passwd"
13 #define _PATH_MASTERPASSWD "/etc/master.passwd"
14 #define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
16 int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**);
17 int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**);
20 +static void android_setup_pwd(struct passwd* pw) {
21 + static char realpath_buffer[4096/*PATH_MAX*/];
22 + char* result = realpath("@TERMUX_HOME@/.termux/shell", realpath_buffer);
23 + if (result == NULL || access(realpath_buffer, X_OK) == -1) {
24 + char const* bash_path = "@TERMUX_PREFIX@/bin/bash";
25 + if (access(bash_path, X_OK) != -1) pw->pw_shell = (char*) bash_path;
26 + else pw->pw_shell = "@TERMUX_PREFIX@/bin/sh";
28 + pw->pw_shell = realpath_buffer;
30 + pw->pw_dir = "@TERMUX_HOME@";
31 + pw->pw_passwd = "*";
33 + pw->pw_gecos = ""; /* Avoid NULL field. */
37 +static struct passwd* android_polyfill_getpwuid(uid_t t) {
38 + struct passwd* pw = getpwuid(t);
39 + if (pw == NULL) return NULL;
40 + android_setup_pwd(pw);
44 +static struct passwd* android_polyfill_getpwnam(const char* name) {
45 + struct passwd* pw = getpwnam(name);
46 + if (pw == NULL) return NULL;
47 + android_setup_pwd(pw);
51 +static int android_polyfill_getpwuid_r(uid_t uid,
55 + struct passwd **result) {
56 + int ret = getpwuid_r(uid, pwd, buffer, bufsize, result);
57 + if (ret != 0) return ret;
58 + android_setup_pwd(pwd);
62 +#define getpwnam android_polyfill_getpwnam
63 +#define getpwuid android_polyfill_getpwuid
64 +#define getpwuid_r android_polyfill_getpwuid_r
65 +static void endpwent(void) { /* Do nothing. */ }
66 struct passwd* getpwent(void);