termux-packages/ndk_patches/pwd.patch

56 lines
2.1 KiB
Diff
Raw Normal View History

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 2016-03-03 16:54:24.000000000 -0500
+++ ./usr/include/pwd.h 2016-03-10 08:11:16.795710172 -0500
2015-08-04 02:32:49 +02:00
@@ -65,6 +65,10 @@
#include <sys/cdefs.h>
#include <sys/types.h>
2015-08-04 02:32:49 +02:00
+/* For access() and realpath(): */
+#include <unistd.h>
2015-08-04 02:32:49 +02:00
+#include <stdlib.h>
+
#define _PATH_PASSWD "/etc/passwd"
#define _PATH_MASTERPASSWD "/etc/master.passwd"
#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
@@ -119,7 +123,40 @@
int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**);
int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**);
-void endpwent(void);
2015-06-13 01:03:31 +02:00
+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) {
2015-07-31 01:47:00 +02:00
+ char const* bash_path = "@TERMUX_PREFIX@/bin/bash";
+ if (access(bash_path, X_OK) != -1) pw->pw_shell = (char*) bash_path;
2015-07-31 01:47:00 +02:00
+ else pw->pw_shell = "@TERMUX_PREFIX@/bin/ash";
2015-06-13 01:03:31 +02:00
+ } else {
2015-08-12 07:29:50 +02:00
+ pw->pw_shell = strcmp(realpath_buffer, "@TERMUX_PREFIX@/bin/busybox") == 0 ? (char*)"@TERMUX_PREFIX@/bin/ash" : realpath_buffer;
2015-06-13 01:03:31 +02:00
+ }
+ pw->pw_dir = "@TERMUX_HOME@";
+ pw->pw_passwd = "*";
+#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);
+ return pw;
+}
+
+#define getpwnam android_polyfill_getpwnam
+#define getpwuid android_polyfill_getpwuid
+static void endpwent(void) { /* Do nothing. */ }
struct passwd* getpwent(void);
int setpwent(void);