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.

62 lines
1.8 KiB

--- sysroot.orig/usr/include/pwd.h 2019-07-30 14:15:53.170288784 -0400
+++ sysroot/usr/include/pwd.h 2019-07-30 14:12:44.446936650 -0400
@@ -89,7 +89,6 @@
struct passwd* getpwent(void) __INTRODUCED_IN(26);
void setpwent(void) __INTRODUCED_IN(26);
-void endpwent(void) __INTRODUCED_IN(26);
#endif /* __ANDROID_API__ >= 26 */
@@ -98,6 +97,50 @@
int access(const char* __path, int __mode);
+static void android_setup_pwd(struct passwd* pw) {
+ char const* result = "@TERMUX_PREFIX@/bin/login";
+ if (result == NULL || access(result, /*X_OK*/1) == -1) {
+ pw->pw_shell = (char *) "@TERMUX_PREFIX@/bin/bash";
+ } else {
+ pw->pw_shell = (char*) result;
+ }
+ pw->pw_dir = (char *) "@TERMUX_HOME@";
+ pw->pw_passwd = (char *) "*";
+#ifdef __LP64__
+ pw->pw_gecos = (char *) ""; /* Avoid NULL field. */
+#endif
+}
+
+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;
+}
+
+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;
+}
+
+#define getpwnam android_polyfill_getpwnam
+#define getpwuid android_polyfill_getpwuid
+#define getpwuid_r android_polyfill_getpwuid_r
+static void endpwent(void) { /* Do nothing. */ }
+
__END_DECLS
#endif