You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
1.9 KiB

diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h ./usr/include/pwd.h
--- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h 2014-10-14 22:53:49.000000000 -0400
+++ ./usr/include/pwd.h 2015-07-15 09:42:32.974621965 -0400
@@ -65,6 +65,9 @@
#include <sys/cdefs.h>
#include <sys/types.h>
+/* For access(): */
+#include <unistd.h>
+
#define _PATH_PASSWD "/etc/passwd"
#define _PATH_MASTERPASSWD "/etc/master.passwd"
#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
@@ -119,6 +122,39 @@
int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**);
int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**);
+extern char *realpath(const char *path, char *resolved_path);
+extern void free(void *ptr);
+extern void *memcpy(void *dest, const void *src, size_t n);
+extern size_t strlen(const char *s);
+
+static void android_setup_pwd(struct passwd* pw) {
+ static char realpath_buffer[4096/*PATH_MAX*/];
+ char* result = realpath("@TERMUX_HOME@/.termux/shell", realpath_buffer);
+ if (result == NULL || access(realpath_buffer, X_OK) == -1) {
+ pw->pw_shell = "@TERMUX_PREFIX@/bin/ash";
+ } else {
+ pw->pw_shell = realpath_buffer;
+ }
+ pw->pw_dir = "@TERMUX_HOME@";
+ pw->pw_passwd = "*";
+}
+
+static struct passwd* android_polyfill_getpwuid(uid_t t) {
+ struct passwd* pw = getpwuid(t);
+ if (pw == NULL) return NULL;
+ android_setup_pwd(pw);
+ return pw;
+}
+
+static struct passwd* android_polyfill_getpwnam(const char* name) {
+ struct passwd* pw = getpwnam(name);
+ if (pw == NULL) return NULL;
+ android_setup_pwd(pw);
+ return pw;
+}
+
+#define getpwnam android_polyfill_getpwnam
+#define getpwuid android_polyfill_getpwuid
void endpwent(void);
struct passwd* getpwent(void);
int setpwent(void);