Skip to content

Commit

Permalink
launch startx using su TigerVNC#2
Browse files Browse the repository at this point in the history
  • Loading branch information
gschwind committed Aug 30, 2019
1 parent a262b7c commit 60835a7
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions unix/spawnvncserver/spawnvncserver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <strings.h>
#include <sys/types.h>
#include <pwd.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
Expand Down Expand Up @@ -177,7 +178,7 @@ class FileTcpFilter : public TcpFilter

std::list<std::tuple<int, Display*, Geometry*, XDesktop*>> displays;

int startXserver(int n)
int startXserver(int n, char const * const userName, char const * const home)
{
vlog.info("Starting the X11 server connection");

Expand All @@ -195,24 +196,20 @@ int startXserver(int n)

vlog.info("CHILD");

char const * home = getenv("HOME");
char * xorg_cmd = nullptr;
asprintf(&xorg_cmd, "/usr/bin/env XAUTHORITY=%s/TESTAUTH "
"/usr/bin/startx -- :%d -config simple-vnc-xdummy.conf -logfile %s/Xorg.%d.log",
home, n, home, n);

char * xx;
asprintf(&xx, ":%d", n);

char * logfile;
asprintf(&logfile, "/Xorg.%d.log", n);

std::string log = std::string{home}+std::string{logfile};
vlog.info("start command %s", xorg_cmd);

// good news: su --login preserve XAUTHORITY.
char * exec_args[] = {
strdup("/usr/bin/startx"),
strdup("--"),
strdup(xx),
strdup("-config"),
strdup("simple-vnc-xdummy.conf"),
strdup("-logfile"),
strdup(log.c_str()),
strdup("/bin/su"),
strdup("--login"),
strdup(userName),
strdup("--command"),
xorg_cmd,
0
};

Expand All @@ -229,16 +226,18 @@ struct VNCServerSpawnXS : public VNCServerSpawnXBase
{
VNCServerSpawnXS(const char* name_) : VNCServerSpawnXBase(name_) { }

virtual SDesktop * create_sdesktop() override {
virtual SDesktop * create_sdesktop(std::string const & userName) override {

int n = 10 + displays.size();

char const * home = getenv("HOME");
passwd * pw = getpwnam(userName.c_str());

char const * home = pw->pw_dir;

std::string xauthority = std::string{home}+std::string{"/TESTAUTH"};
setenv("XAUTHORITY", xauthority.c_str(), 1);

int pid = startXserver(n);
int pid = startXserver(n, userName.c_str(), home);

vlog.info("Starting the X11 display connection");

Expand All @@ -250,7 +249,7 @@ struct VNCServerSpawnXS : public VNCServerSpawnXBase
if (!(dpy = XOpenDisplay(xx))) {
// FIXME: Why not vlog.error(...)?
fprintf(stderr,"%s: unable to open display \"%s\"\r\n",
"TODO", XDisplayName(NULL));
"TODO", XDisplayName(xx));
exit(1);
}

Expand Down

0 comments on commit 60835a7

Please sign in to comment.