1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-03-02 11:21:14 +00:00

1. Fixed typo with upstart service manager .conf definition

2. Added support for installedDate in service manager
3. Fixed compiler warnings
This commit is contained in:
Bryan Roe
2020-06-25 12:34:56 -07:00
parent 788adeb246
commit 10bde8c328
5 changed files with 104 additions and 14 deletions

View File

@@ -272,7 +272,13 @@ if (process.platform == 'darwin')
});
}
Object.defineProperty(ret, 'daemon', { value: ret.plist.split('/LaunchDaemons/').length > 1 ? true : false });
try
{
Object.defineProperty(ret, 'installedDate', { value: require('fs').statSync(ret.plist).ctime });
}
catch(xx)
{
}
ret.appWorkingDirectory = function appWorkingDirectory()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
@@ -728,6 +734,16 @@ function serviceManager()
}
}
});
try
{
Object.defineProperty(retVal, 'installedDate',
{
value: require('win-registry').QueryKeyLastModified(require('win-registry').HKEY.LocalMachine, 'SYSTEM\\CurrentControlSet\\Services\\' + name, 'ImagePath')
});
}
catch(xx)
{
}
if (retVal.status.state != 'UNKNOWN')
{
require('events').EventEmitter.call(retVal);
@@ -774,7 +790,6 @@ function serviceManager()
if (ret.startsWith('"')) { ret = ret.substring(1); }
return (ret);
};
retVal.appWorkingDirectory = function ()
{
var tokens = this.appLocation().split('\\');
@@ -1038,6 +1053,14 @@ function serviceManager()
}
return (ret);
};
try
{
Object.defineProperty(ret, 'installedDate', { value: require('fs').statSync(ret.rc).ctime });
}
catch (xx)
{
}
ret.appLocation = function appLocation()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
@@ -1129,7 +1152,7 @@ function serviceManager()
if ((platform == 'init' && require('fs').existsSync('/etc/init.d/' + name)) ||
(platform == 'upstart' && require('fs').existsSync('/etc/init/' + name + '.conf')))
{
ret.conf = (platform == 'upstart' ? ('/etc/init' + name + '.conf') : ('/etc/init.d/' + name));
ret.conf = (platform == 'upstart' ? ('/etc/init/' + name + '.conf') : ('/etc/init.d/' + name));
ret.serviceType = platform;
Object.defineProperty(ret, "startType",
{
@@ -1298,7 +1321,6 @@ function serviceManager()
return (child.stdout._str);
};
ret.status.platform = platform;
return (ret);
}
else
{
@@ -1418,7 +1440,6 @@ function serviceManager()
child.waitExit();
return (child.stdout._str);
};
return (ret);
}
else
{
@@ -1526,7 +1547,6 @@ function serviceManager()
return (false);
}
};
return (ret);
}
else
{
@@ -1534,6 +1554,15 @@ function serviceManager()
}
break;
}
try
{
Object.defineProperty(ret, 'installedDate', { value: require('fs').statSync(ret.conf).ctime });
}
catch (xx)
{
console.log(xx);
}
return (ret);
};
}
this.enumerateService = function (options)

View File

@@ -38,6 +38,8 @@ function windows_registry()
{
this._ObjectId = 'win-registry';
this._marshal = require('_GenericMarshal');
this._Kernel32 = this._marshal.CreateNativeProxy('Kernel32.dll');
this._Kernel32.CreateMethod('FileTimeToSystemTime');
this._AdvApi = this._marshal.CreateNativeProxy('Advapi32.dll');
this._AdvApi.CreateMethod('RegCreateKeyExW');
this._AdvApi.CreateMethod('RegEnumKeyExW');
@@ -154,6 +156,45 @@ function windows_registry()
this._AdvApi.RegCloseKey(h.Deref());
return (retVal);
};
this.QueryKeyLastModified = function QueryKeyLastModified(hkey, path, key)
{
var v;
var err;
var h = this._marshal.CreatePointer();
var HK = this._marshal.CreatePointer(hkey);
var retVal = null;
if (key) { key = this._marshal.CreateVariable(key, { wide: true }); }
if (!path) { path = ''; }
if ((err = this._AdvApi.RegOpenKeyExW(HK, this._marshal.CreateVariable(path, { wide: true }), 0, KEY_QUERY_VALUE, h).Val) != 0)
{
throw ('Opening Registry Key: ' + path + ' => Returned Error: ' + err);
}
var achClass = this._marshal.CreateVariable(1024);
var achKey = this._marshal.CreateVariable(1024);
var achValue = this._marshal.CreateVariable(32768);
var achValueSize = this._marshal.CreateVariable(4);
var nameSize = this._marshal.CreateVariable(4);
var achClassSize = this._marshal.CreateVariable(4); achClassSize.toBuffer().writeUInt32LE(1024);
var numSubKeys = this._marshal.CreateVariable(4);
var numValues = this._marshal.CreateVariable(4);
var longestSubkeySize = this._marshal.CreateVariable(4);
var longestClassString = this._marshal.CreateVariable(4);
var longestValueName = this._marshal.CreateVariable(4);
var longestValueData = this._marshal.CreateVariable(4);
var securityDescriptor = this._marshal.CreateVariable(4);
var lastWriteTime = this._marshal.CreateVariable(8);
v = this._AdvApi.RegQueryInfoKeyW(h.Deref(), achClass, achClassSize, 0,
numSubKeys, longestSubkeySize, longestClassString, numValues,
longestValueName, longestValueData, securityDescriptor, lastWriteTime);
if (v.Val != 0) { throw ('RegQueryInfoKeyW() returned error: ' + v.Val); }
var systime = this._marshal.CreateVariable(16);
if (this._Kernel32.FileTimeToSystemTime(lastWriteTime, systime).Val == 0) { throw ('Error parsing time'); }
return (require('fs').convertFileTime(lastWriteTime));
};
this.WriteKey = function WriteKey(hkey, path, key, value)
{
var result;