feat(native): guests see the session hostname from uname and gethostname

This commit is contained in:
Kurt Himebauch committed 2026-11-09 13:36:38 -05:00
1 parent bde8c9fbed
commit 0c5219b225
6 files changed
+43 -2

No files matched your search

+1
View File
@@ -19,6 +19,7 @@
#include <sys/statfs.h>
#include <sys/statvfs.h>
#include <sys/socket.h>
#include <sys/utsname.h>
#include <sys/un.h>
#include <sys/prctl.h>
#include <sys/resource.h>
+10 -1
View File
@@ -92,6 +92,7 @@ static char **prepare_ddnatv_env(char *const envp[], const char *real_exe) {
// are compared (this was 13 strncmp() calls for each of the 30 or so variables)
int has_nt = 0;
int has_binds = 0;
int has_hostname = 0;
int has_preload_list = 0;
const char *preload_value = NULL;
while (envp && envp[count]) {
@@ -119,6 +120,7 @@ static char **prepare_ddnatv_env(char *const envp[], const char *real_exe) {
else if (strncmp(e, "DDNATV_NT=", 10) == 0) has_nt = 1;
else if (strncmp(e, "DDNATV_BINDS=", 13) == 0) has_binds = 1;
else if (strncmp(e, "DDNATV_PRELOAD=", 15) == 0) has_preload_list = 1;
else if (strncmp(e, "DDNATV_HOSTNAME=", 16) == 0) has_hostname = 1;
else if (strncmp(e, "DPKG_DEB_THREADS_MAX=", 21) == 0) has_threads_max = 1;
else if (strncmp(e, "DEBIAN_FRONTEND=", 16) == 0) has_frontend = 1;
else if (strncmp(e, "DEBCONF_FRONTEND=", 17) == 0) has_debconf_frontend = 1;
@@ -130,7 +132,7 @@ static char **prepare_ddnatv_env(char *const envp[], const char *real_exe) {
count++;
}
char **new_env = calloc(count + 22, sizeof(char *));
char **new_env = calloc(count + 23, sizeof(char *));
int dst = 0;
for (int i = 0; i < count; i++) {
if (has_preload && envp[i][0] == 'L' && strncmp(envp[i], "LD_PRELOAD=", 11) == 0) {
@@ -215,6 +217,13 @@ static char **prepare_ddnatv_env(char *const envp[], const char *real_exe) {
new_env[dst++] = str;
}
}
if (!has_hostname && g_hostname[0]) {
char *str = malloc(16 + sizeof(g_hostname));
if (str) {
snprintf(str, 16 + sizeof(g_hostname), "DDNATV_HOSTNAME=%s", g_hostname);
new_env[dst++] = str;
}
}
if (!has_binds && g_binds_raw) {
size_t len = strlen(g_binds_raw);
char *str = malloc(13 + len + 1);
+26
View File
@@ -51,6 +51,32 @@ int getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups) {
return -1;
}
// The session's host name, as proot's --kernel-release gave it: Steam names the device after it
int uname(struct utsname *buf) {
static int (*orig_uname)(struct utsname *) = NULL;
if (!orig_uname) orig_uname = (int (*)(struct utsname *))dlsym(RTLD_NEXT, "uname");
int ret = orig_uname ? orig_uname(buf) : -1;
if (ret == 0 && buf && g_hostname[0]) {
ddnatv_copy_cstr(buf->nodename, sizeof(buf->nodename), g_hostname);
ddnatv_copy_cstr(buf->domainname, sizeof(buf->domainname), "localdomain");
}
return ret;
}
int gethostname(char *name, size_t len) {
static int (*orig_gethostname)(char *, size_t) = NULL;
if (!orig_gethostname) orig_gethostname = (int (*)(char *, size_t))dlsym(RTLD_NEXT, "gethostname");
if (!g_hostname[0]) return orig_gethostname ? orig_gethostname(name, len) : -1;
size_t n = strlen(g_hostname) + 1;
if (!name || n > len) {
if (name && len) memcpy(name, g_hostname, len);
errno = ENAMETOOLONG;
return -1;
}
memcpy(name, g_hostname, n);
return 0;
}
#endif /* !DDNATV_HOST_TEST */
static uid_t real_uid(void) {
+2
View File
@@ -32,6 +32,8 @@ struct ddnatv_bind {
static struct ddnatv_bind *g_binds = NULL;
static int g_nbinds = 0;
static char *g_binds_raw = NULL;
// The session's host name (DDNATV_HOSTNAME), what proot put in uname(): Android's kernel says "localhost"
static char g_hostname[65];
static int ddnatv_bind_longer_first(const void *a, const void *b) {
const struct ddnatv_bind *x = a, *y = b;
+2
View File
@@ -34,6 +34,8 @@ static void init_ddnatv_hook(void) {
}
}
ddnatv_load_binds(getenv("DDNATV_BINDS"));
const char *hostname = getenv("DDNATV_HOSTNAME");
if (hostname && hostname[0] && strlen(hostname) < sizeof(g_hostname)) ddnatv_copy_cstr(g_hostname, sizeof(g_hostname), hostname);
const char *preload = getenv("DDNATV_PRELOAD");
if (preload && preload[0] && g_ddnatv_root_len > 0) {
size_t cap = strlen(preload) + (g_ddnatv_root_len + 1) * 16 + 1;