diff -rup old/Makefile new/Makefile --- old/Makefile 2018-05-06 01:12:36.000000000 +0200 +++ new/Makefile 2019-07-24 22:29:12.874257700 +0200 @@ -8,7 +8,9 @@ all : ../out/wslbridge-backend -static-libgcc -static-libstdc++ \ -D_GNU_SOURCE \ -DWSLBRIDGE_VERSION=$(shell cat ../VERSION.txt) \ - -Wall -O2 $< ../common/SocketIo.cc -o $@ -lutil -pthread + -Wall -O2 $< ../common/SocketIo.cc -o $@ \ + -ldl -lutil -static -pthread \ + -Wl,--whole-archive -lpthread -Wl,--no-whole-archive $(STRIP) $@ clean: diff -rup old/wslbridge-backend.cc new/wslbridge-backend.cc --- old/wslbridge-backend.cc 2018-05-06 01:12:36.000000000 +0200 +++ new/wslbridge-backend.cc 2019-07-24 22:55:25.324307400 +0200 @@ -494,6 +494,58 @@ static void frontendVersionCheck(const c } // namespace +#define getpwuid _getpwuid + +#include +typedef struct passwd * (*__getpwuid_t)(int uid); + +struct passwd * getpwuid(int uid) +{ + void * dl = dlopen(0, 0); +printf("dlopen %p\n", dl); + if (dl) { + struct passwd * (*__getpwuid)(int uid) = + (__getpwuid_t)dlsym(dl, "getpwuid"); +printf("dlsym %p\n", __getpwuid); + if (__getpwuid) + return __getpwuid(uid); + } + + FILE * pwd = fopen("/etc/passwd", "r"); + if (pwd) { + char pwbuf[222]; + static struct passwd pw; + pw.pw_shell = 0; + while (fgets(pwbuf, sizeof pwbuf, pwd)) { + char * sep = strchr(pwbuf, ':'); + if (!sep) continue; + sep = strchr(++sep, ':'); + if (!sep) continue; + int pwuid; + if (sscanf(sep, ":%d:", &pwuid) == 1 && pwuid == uid) { + // pw_name:pw_passwd:pw_uid:pw_gid:pw_gecos:pw_dir:pw_shell + // ^ + sep = strchr(++sep, ':'); + if (!sep) continue; + sep = strchr(++sep, ':'); + if (!sep) continue; + sep = strchr(++sep, ':'); + if (!sep) continue; + sep = strchr(++sep, ':'); + if (!sep) continue; + pw.pw_shell = ++sep; + sep = strchr(++sep, '\n'); + if (sep) + *sep = 0; + break; + } + } + fclose(pwd); + return &pw; + } + return 0; +} + int main(int argc, char *argv[]) { // If the backend crashes, it prints a message to its stderr, which is a