Commit | Line | Data |
---|---|---|
b57fc0bb | 1 | diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h ./usr/include/pwd.h |
e8735a9e FF |
2 | --- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h 2016-03-03 16:54:24.000000000 -0500 |
3 | +++ ./usr/include/pwd.h 2016-03-10 08:11:16.795710172 -0500 | |
6d5e9115 | 4 | @@ -65,6 +65,10 @@ |
b57fc0bb FF |
5 | #include <sys/cdefs.h> |
6 | #include <sys/types.h> | |
7 | ||
6d5e9115 | 8 | +/* For access() and realpath(): */ |
b57fc0bb | 9 | +#include <unistd.h> |
6d5e9115 | 10 | +#include <stdlib.h> |
b57fc0bb FF |
11 | + |
12 | #define _PATH_PASSWD "/etc/passwd" | |
13 | #define _PATH_MASTERPASSWD "/etc/master.passwd" | |
14 | #define _PATH_MASTERPASSWD_LOCK "/etc/ptmp" | |
cb9e3a9a | 15 | @@ -119,7 +123,40 @@ |
b57fc0bb FF |
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**); | |
18 | ||
e8735a9e | 19 | -void endpwent(void); |
59f0d218 | 20 | +static void android_setup_pwd(struct passwd* pw) { |
b57fc0bb FF |
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) { | |
02b55df6 | 24 | + char const* bash_path = "@TERMUX_PREFIX@/bin/bash"; |
34165430 | 25 | + if (access(bash_path, X_OK) != -1) pw->pw_shell = (char*) bash_path; |
02b55df6 | 26 | + else pw->pw_shell = "@TERMUX_PREFIX@/bin/ash"; |
59f0d218 | 27 | + } else { |
394bbb64 | 28 | + pw->pw_shell = strcmp(realpath_buffer, "@TERMUX_PREFIX@/bin/busybox") == 0 ? (char*)"@TERMUX_PREFIX@/bin/ash" : realpath_buffer; |
59f0d218 | 29 | + } |
59f0d218 FF |
30 | + pw->pw_dir = "@TERMUX_HOME@"; |
31 | + pw->pw_passwd = "*"; | |
cb9e3a9a FF |
32 | +#ifdef __LP64__ |
33 | + pw->pw_gecos = ""; /* Avoid NULL field. */ | |
34 | +#endif | |
59f0d218 FF |
35 | +} |
36 | + | |
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); | |
41 | + return pw; | |
42 | +} | |
43 | + | |
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); | |
48 | + return pw; | |
49 | +} | |
50 | + | |
51 | +#define getpwnam android_polyfill_getpwnam | |
52 | +#define getpwuid android_polyfill_getpwuid | |
e8735a9e | 53 | +static void endpwent(void) { /* Do nothing. */ } |
b57fc0bb FF |
54 | struct passwd* getpwent(void); |
55 | int setpwent(void); |