1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-23 11:43:26 +00:00

Updated user-sessions on MacOS to support getHomeFolder and getUsername

This commit is contained in:
Bryan Roe
2019-05-30 14:59:32 -07:00
parent e08d1996d5
commit 5b0a4899e2
3 changed files with 207 additions and 192 deletions

View File

@@ -652,6 +652,38 @@ function UserSessions()
}
else if(process.platform == 'darwin')
{
this.getUsername = function getUsername(uid)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write("dscl . list /Users UniqueID | grep " + uid + " | awk '{ if($2==" + uid + "){ print $1 }}'\nexit\n");
child.waitExit();
if(child.stdout.str.trim() != '')
{
return (child.stdout.str.trim());
}
else
{
throw ('uid: ' + uid + ' not found');
}
};
this.getHomeFolder = function getHomeFolder(user)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write("dscl . -read /Users/" + user + " | grep NFSHomeDirectory | awk -F: '{ print $2 }'\nexit\n");
child.waitExit();
if (child.stdout.str.trim() != '')
{
return (child.stdout.str.trim());
}
else
{
throw ('user: ' + user + ' not found');
}
};
this._users = function ()
{
var child = require('child_process').execFile('/usr/bin/dscl', ['dscl', '.', 'list', '/Users', 'UniqueID']);