termux-packages/ndk_patches/pwd.patch

48 lines
1.8 KiB
Diff
Raw Normal View History

2015-06-13 01:03:31 +02:00
diff -u -r /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/include/pwd.h ./usr/include/pwd.h
--- /home/fornwall/lib/android-ndk/platforms/android-19/arch-arm/usr/include/pwd.h 2012-08-21 07:23:12.000000000 +0200
+++ ./usr/include/pwd.h 2014-07-06 04:39:02.731221101 +0200
@@ -114,6 +114,43 @@
struct passwd* getpwnam(const char*);
struct passwd* getpwuid(uid_t);
+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[255];
+ size_t allocated_realpath_len;
+ char* allocated_realpath = realpath("@TERMUX_HOME@/.termux/shell", NULL);
+ if (allocated_realpath == NULL || (allocated_realpath_len = strlen(allocated_realpath)) >= sizeof(realpath_buffer)) {
+ pw->pw_shell = "@TERMUX_PREFIX@/bin/ash";
+ } else {
+ memcpy(realpath_buffer, allocated_realpath, allocated_realpath_len);
+ realpath_buffer[allocated_realpath_len] = 0;
+ pw->pw_shell = realpath_buffer;
+ }
+ free(allocated_realpath);
+ 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);
#if 0 /* MISSING FROM BIONIC */