2019-09-08 19:54:08 +02:00
|
|
|
diff -uNr sysroot.orig/usr/include/pwd.h sysroot/usr/include/pwd.h
|
|
|
|
--- sysroot.orig/usr/include/pwd.h 2019-02-12 16:12:24.000000000 +0000
|
|
|
|
+++ sysroot/usr/include/pwd.h 2019-03-20 13:26:24.283060011 +0000
|
|
|
|
@@ -89,13 +89,58 @@
|
2017-06-18 20:57:16 +02:00
|
|
|
struct passwd* getpwent(void) __INTRODUCED_IN(26);
|
|
|
|
|
|
|
|
void setpwent(void) __INTRODUCED_IN(26);
|
|
|
|
-void endpwent(void) __INTRODUCED_IN(26);
|
|
|
|
#endif /* __ANDROID_API__ >= 26 */
|
|
|
|
|
|
|
|
|
2019-09-08 19:54:08 +02:00
|
|
|
int getpwnam_r(const char* __name, struct passwd* __pwd, char* __buf, size_t __n, struct passwd** __result) __INTRODUCED_IN(12);
|
|
|
|
int getpwuid_r(uid_t __uid, struct passwd* __pwd, char* __buf, size_t __n, struct passwd** __result) __INTRODUCED_IN(12);
|
2019-03-20 14:37:12 +01:00
|
|
|
|
2019-09-08 19:54:08 +02:00
|
|
|
+int access(const char* __path, int __mode);
|
|
|
|
+
|
2017-06-18 20:57:16 +02:00
|
|
|
+static void android_setup_pwd(struct passwd* pw) {
|
2017-09-17 15:55:41 +02:00
|
|
|
+ char const* result = "@TERMUX_PREFIX@/bin/login";
|
|
|
|
+ if (result == NULL || access(result, /*X_OK*/1) == -1) {
|
2019-09-08 19:54:08 +02:00
|
|
|
+ pw->pw_shell = "@TERMUX_PREFIX@/bin/bash";
|
2017-06-18 20:57:16 +02:00
|
|
|
+ } else {
|
2017-09-17 20:51:35 +02:00
|
|
|
+ pw->pw_shell = (char*) result;
|
2017-06-18 20:57:16 +02:00
|
|
|
+ }
|
2019-09-08 19:54:08 +02:00
|
|
|
+ pw->pw_dir = "@TERMUX_HOME@";
|
|
|
|
+ pw->pw_passwd = "*";
|
2017-06-18 20:57:16 +02:00
|
|
|
+#ifdef __LP64__
|
2019-09-08 19:54:08 +02:00
|
|
|
+ pw->pw_gecos = ""; /* Avoid NULL field. */
|
2017-06-18 20:57:16 +02:00
|
|
|
+#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. */ }
|
2019-03-20 14:37:12 +01:00
|
|
|
+
|
2017-06-18 20:57:16 +02:00
|
|
|
__END_DECLS
|
|
|
|
|
2019-03-20 14:37:12 +01:00
|
|
|
#endif
|