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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user