1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-27 21:53:20 +00:00

Fixed XAUTHORITY logic when loginctl is used to find display, to check to make sure xauthority token is present in default location. If not, will try to find XAUTHORITY in environment variables in one of the session processes.

This commit is contained in:
Bryan Roe
2021-09-01 23:28:15 -07:00
parent 1ad21b6050
commit 3464f88dba
2 changed files with 49 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
/*
/*
Copyright 2018 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
@@ -584,9 +584,54 @@ function monitorinfo()
child.waitExit();
ret = { tty: '?', xauthority: (require('user-sessions').getHomeFolder(consoleuid) + '/.Xauthority').split('//').join('/'), display: child.stdout.str.trim(), exportEnv: exportEnv };
return (xinfo_xdm(ret, consoleuid));
}
if (!require('fs').existsSync(ret.xauthority))
{
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write('loginctl session-status ' + sids.join(' ') + " | tr '\\n' '`' | awk '{");
child.stdin.write('len=split($0,X,"`");');
child.stdin.write('Z="";');
child.stdin.write('printf "[";');
child.stdin.write('for(i=1;i<=len;++i)');
child.stdin.write('{');
child.stdin.write(' if(X[i]~/^.+├─/)');
child.stdin.write(' {');
child.stdin.write(' gsub(/^.+├─/,"",X[i]);');
child.stdin.write(' split(X[i],VAL," ");');
child.stdin.write(' printf "%s%s",Z,VAL[1];');
child.stdin.write(' Z=",";');
child.stdin.write(' }');
child.stdin.write('}');
child.stdin.write('printf "]";');
child.stdin.write("}'\nexit\n");
child.waitExit();
var pids = null;
try
{
pids = JSON.parse(child.stdout.str);
}
catch(z)
{
}
if (pids != null)
{
var e, i;
for (i in pids)
{
e = require('user-sessions').getEnvFromPid(pids[i]);
if (e.XAUTHORITY)
{
ret.xauthority = e.XAUTHORITY;
break;
}
}
}
}
return (xinfo_xdm(ret, consoleuid));
}
// So we're going to brute force it, by enumerating all processes owned by this user, and inspect the environment variables