2017-03-05 13:34:41 +01:00
|
|
|
diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm64/usr/include/pwd.h ./usr/include/pwd.h
|
|
|
|
--- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm64/usr/include/pwd.h 2017-02-27 17:27:10.000000000 +0100
|
|
|
|
+++ ./usr/include/pwd.h 2017-03-05 13:28:19.227658358 +0100
|
2015-08-04 02:32:49 +02:00
|
|
|
@@ -65,6 +65,10 @@
|
2015-07-15 19:12:28 +02:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2015-08-04 02:32:49 +02:00
|
|
|
+/* For access() and realpath(): */
|
2015-07-15 19:12:28 +02:00
|
|
|
+#include <unistd.h>
|
2015-08-04 02:32:49 +02:00
|
|
|
+#include <stdlib.h>
|
2015-07-15 19:12:28 +02:00
|
|
|
+
|
|
|
|
#define _PATH_PASSWD "/etc/passwd"
|
|
|
|
#define _PATH_MASTERPASSWD "/etc/master.passwd"
|
|
|
|
#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
|
2017-03-05 13:34:41 +01:00
|
|
|
@@ -119,7 +123,52 @@
|
2015-07-15 19:12:28 +02:00
|
|
|
int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**);
|
|
|
|
int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**);
|
|
|
|
|
2016-03-10 21:24:52 +01:00
|
|
|
-void endpwent(void);
|
2015-06-13 01:03:31 +02:00
|
|
|
+static void android_setup_pwd(struct passwd* pw) {
|
2015-07-15 19:12:28 +02:00
|
|
|
+ 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) {
|
2015-07-31 01:47:00 +02:00
|
|
|
+ char const* bash_path = "@TERMUX_PREFIX@/bin/bash";
|
2015-07-31 03:20:15 +02:00
|
|
|
+ if (access(bash_path, X_OK) != -1) pw->pw_shell = (char*) bash_path;
|
2017-03-05 13:34:41 +01:00
|
|
|
+ else pw->pw_shell = "@TERMUX_PREFIX@/bin/sh";
|
2015-06-13 01:03:31 +02:00
|
|
|
+ } else {
|
2017-03-05 13:34:41 +01:00
|
|
|
+ pw->pw_shell = realpath_buffer;
|
2015-06-13 01:03:31 +02:00
|
|
|
+ }
|
|
|
|
+ pw->pw_dir = "@TERMUX_HOME@";
|
|
|
|
+ pw->pw_passwd = "*";
|
2016-03-12 21:40:05 +01:00
|
|
|
+#ifdef __LP64__
|
|
|
|
+ pw->pw_gecos = ""; /* Avoid NULL field. */
|
|
|
|
+#endif
|
2015-06-13 01:03:31 +02:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+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);
|
2017-03-05 13:34:41 +01:00
|
|
|
+ return pw;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int android_polyfill_getpwuid_r(uid_t uid,
|
|
|
|
+ struct passwd *pwd,
|
|
|
|
+ char *buffer,
|
|
|
|
+ size_t bufsize,
|
|
|
|
+ struct passwd **result) {
|
|
|
|
+ int ret = getpwuid_r(uid, pwd, buffer, bufsize, result);
|
|
|
|
+ if (ret != 0) return ret;
|
|
|
|
+ android_setup_pwd(pwd);
|
|
|
|
+ return 0;
|
2015-06-13 01:03:31 +02:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#define getpwnam android_polyfill_getpwnam
|
|
|
|
+#define getpwuid android_polyfill_getpwuid
|
2017-03-05 13:34:41 +01:00
|
|
|
+#define getpwuid_r android_polyfill_getpwuid_r
|
2016-03-10 21:24:52 +01:00
|
|
|
+static void endpwent(void) { /* Do nothing. */ }
|
2015-07-15 19:12:28 +02:00
|
|
|
struct passwd* getpwent(void);
|
|
|
|
int setpwent(void);
|
2017-03-05 13:34:41 +01:00
|
|
|
|