Commit | Line | Data |
---|---|---|
b57fc0bb FF |
1 | diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h ./usr/include/pwd.h |
2 | --- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h 2014-10-14 22:53:49.000000000 -0400 | |
3 | +++ ./usr/include/pwd.h 2015-07-15 09:42:32.974621965 -0400 | |
4 | @@ -65,6 +65,9 @@ | |
5 | #include <sys/cdefs.h> | |
6 | #include <sys/types.h> | |
7 | ||
8 | +/* For access(): */ | |
9 | +#include <unistd.h> | |
10 | + | |
11 | #define _PATH_PASSWD "/etc/passwd" | |
12 | #define _PATH_MASTERPASSWD "/etc/master.passwd" | |
13 | #define _PATH_MASTERPASSWD_LOCK "/etc/ptmp" | |
02b55df6 | 14 | @@ -119,6 +122,41 @@ |
b57fc0bb FF |
15 | int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**); |
16 | int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**); | |
17 | ||
59f0d218 FF |
18 | +extern char *realpath(const char *path, char *resolved_path); |
19 | +extern void free(void *ptr); | |
20 | +extern void *memcpy(void *dest, const void *src, size_t n); | |
21 | +extern size_t strlen(const char *s); | |
22 | + | |
23 | +static void android_setup_pwd(struct passwd* pw) { | |
b57fc0bb FF |
24 | + static char realpath_buffer[4096/*PATH_MAX*/]; |
25 | + char* result = realpath("@TERMUX_HOME@/.termux/shell", realpath_buffer); | |
26 | + if (result == NULL || access(realpath_buffer, X_OK) == -1) { | |
02b55df6 FF |
27 | + char const* bash_path = "@TERMUX_PREFIX@/bin/bash"; |
28 | + if (access(bash_path, X_OK) != -1) pw->pw_shell = bash_path; | |
29 | + else pw->pw_shell = "@TERMUX_PREFIX@/bin/ash"; | |
59f0d218 | 30 | + } else { |
59f0d218 FF |
31 | + pw->pw_shell = realpath_buffer; |
32 | + } | |
59f0d218 FF |
33 | + pw->pw_dir = "@TERMUX_HOME@"; |
34 | + pw->pw_passwd = "*"; | |
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 | |
53 | void endpwent(void); | |
b57fc0bb FF |
54 | struct passwd* getpwent(void); |
55 | int setpwent(void); |