1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-22 03:03:18 +00:00

Added getGroupname on Linux, FreeBSD, and MacOS

This commit is contained in:
Bryan Roe
2019-09-26 14:43:08 -07:00
parent 42673ee19f
commit d4b9f813b6
2 changed files with 44 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@@ -618,6 +618,16 @@ function UserSessions()
if (child.stdout.str.length > 0) { return (child.stdout.str.trim()); } if (child.stdout.str.length > 0) { return (child.stdout.str.trim()); }
throw ('uid: ' + uid + ' NOT FOUND'); throw ('uid: ' + uid + ' NOT FOUND');
}; };
this.getGroupname = function getGroupname(gid)
{
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("getent group " + gid + " | awk -F: '{print $1}'\nexit\n");
child.waitExit();
if (child.stdout.str.length > 0) { return (child.stdout.str.trim()); }
throw ('gid: ' + gid + ' NOT FOUND');
};
this.whoami = function whoami() this.whoami = function whoami()
{ {
var child = require('child_process').execFile('/bin/sh', ['sh']); var child = require('child_process').execFile('/bin/sh', ['sh']);
@@ -732,6 +742,24 @@ function UserSessions()
throw ('uid: ' + uid + ' not found'); throw ('uid: ' + uid + ' not found');
} }
}; };
this.getGroupname = function getGroupname(gid)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stderr.str = '';
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stderr.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write("dscl . list /Groups PrimaryGroupID | grep " + gid + " | awk '{ if($2==" + gid + "){ print $1 }}'\nexit\n");
child.waitExit();
if(child.stdout.str.trim() != '')
{
return (child.stdout.str.trim());
}
else
{
throw ('gid: ' + gid + ' not found');
}
};
this.consoleUid = function consoleUid() this.consoleUid = function consoleUid()
{ {
var child = require('child_process').execFile('/bin/sh', ['sh']); var child = require('child_process').execFile('/bin/sh', ['sh']);