1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 15:53:55 +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

File diff suppressed because one or more lines are too long

View File

@@ -2274,6 +2274,25 @@ duk_ret_t ILibDuktape_fs_chownSync(duk_context *ctx)
} }
} }
#endif #endif
#ifdef WIN32
duk_ret_t ILibDuktape_fs_convertFileTime(duk_context *ctx)
{
if (!(duk_is_object(ctx, 0) && duk_has_prop_string(ctx, -1, "_ptr"))) { return(ILibDuktape_Error(ctx, "Invalid Input Parameters")); }
FILETIME *ft = (FILETIME*)Duktape_GetPointerProperty(ctx, 0, "_ptr");
SYSTEMTIME st;
if (ft == NULL) { return(ILibDuktape_Error(ctx, "Invalid Input Parameters")); }
if (FileTimeToSystemTime(ft, &st) != 0)
{
duk_push_string(ctx, ILibDuktape_fs_convertTime(&st, ILibScratchPad, sizeof(ILibScratchPad)));
return(1);
}
else
{
return(ILibDuktape_Error(ctx, "Error converting time"));
}
}
#endif
void ILibDuktape_fs_PUSH(duk_context *ctx, void *chain) void ILibDuktape_fs_PUSH(duk_context *ctx, void *chain)
{ {
duk_push_object(ctx); // [fs] duk_push_object(ctx); // [fs]
@@ -2307,6 +2326,7 @@ void ILibDuktape_fs_PUSH(duk_context *ctx, void *chain)
#ifdef WIN32 #ifdef WIN32
ILibDuktape_CreateInstanceMethod(ctx, "_readdirSync", ILibDuktape_fs_readdirSync, DUK_VARARGS); ILibDuktape_CreateInstanceMethod(ctx, "_readdirSync", ILibDuktape_fs_readdirSync, DUK_VARARGS);
ILibDuktape_CreateInstanceMethod(ctx, "_statSync", ILibDuktape_fs_statSync, 1); ILibDuktape_CreateInstanceMethod(ctx, "_statSync", ILibDuktape_fs_statSync, 1);
ILibDuktape_CreateInstanceMethod(ctx, "convertFileTime", ILibDuktape_fs_convertFileTime, 1);
#else #else
ILibDuktape_CreateInstanceMethod(ctx, "readdirSync", ILibDuktape_fs_readdirSync, DUK_VARARGS); ILibDuktape_CreateInstanceMethod(ctx, "readdirSync", ILibDuktape_fs_readdirSync, DUK_VARARGS);
ILibDuktape_CreateInstanceMethod(ctx, "statSync", ILibDuktape_fs_statSync, 1); ILibDuktape_CreateInstanceMethod(ctx, "statSync", ILibDuktape_fs_statSync, 1);

View File

@@ -827,7 +827,7 @@ __EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char*
// Before returning an error, check if this is a compressed record // Before returning an error, check if this is a compressed record
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t)); char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen); memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, tmpkey, keyLen); ((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)tmpkey, keyLen);
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey)); entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
ILibMemory_Free(tmpkey); ILibMemory_Free(tmpkey);
if (entry != NULL) { isCompressed = 1; } if (entry != NULL) { isCompressed = 1; }
@@ -886,7 +886,7 @@ __EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore,
// Before we return an error, let's check if this is a compressed record // Before we return an error, let's check if this is a compressed record
char* tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t)); char* tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen); memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, key, (uint32_t)keyLen); ((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, (uint32_t)keyLen);
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey)); entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
ILibMemory_Free(tmpkey); ILibMemory_Free(tmpkey);
} }
@@ -912,7 +912,7 @@ __EXPORT_TYPE int ILibSimpleDataStore_DeleteEx(ILibSimpleDataStore dataStore, ch
// Check to see if this is a compressed record, before we return an error // Check to see if this is a compressed record, before we return an error
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t)); char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen); memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, key, keyLen); ((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, keyLen);
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Remove(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey)); entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Remove(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
if (entry != NULL) if (entry != NULL)
{ {
@@ -1013,7 +1013,7 @@ void ILibSimpleDataStore_EnumerateKeysSink(ILibHashtable sender, void *Key1, cha
if (Key2Len > sizeof(uint32_t)) if (Key2Len > sizeof(uint32_t))
{ {
// Check if this is a compressed entry // Check if this is a compressed entry
if (crc32c(0, Key2, Key2Len - sizeof(uint32_t)) == ((uint32_t*)(Key2 + Key2Len - sizeof(uint32_t)))[0]) if (crc32c(0, (unsigned char*)Key2, Key2Len - sizeof(uint32_t)) == ((uint32_t*)(Key2 + Key2Len - sizeof(uint32_t)))[0])
{ {
Key2Len -= sizeof(uint32_t); Key2Len -= sizeof(uint32_t);
} }

View File

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

View File

@@ -38,6 +38,8 @@ function windows_registry()
{ {
this._ObjectId = 'win-registry'; this._ObjectId = 'win-registry';
this._marshal = require('_GenericMarshal'); this._marshal = require('_GenericMarshal');
this._Kernel32 = this._marshal.CreateNativeProxy('Kernel32.dll');
this._Kernel32.CreateMethod('FileTimeToSystemTime');
this._AdvApi = this._marshal.CreateNativeProxy('Advapi32.dll'); this._AdvApi = this._marshal.CreateNativeProxy('Advapi32.dll');
this._AdvApi.CreateMethod('RegCreateKeyExW'); this._AdvApi.CreateMethod('RegCreateKeyExW');
this._AdvApi.CreateMethod('RegEnumKeyExW'); this._AdvApi.CreateMethod('RegEnumKeyExW');
@@ -154,6 +156,45 @@ function windows_registry()
this._AdvApi.RegCloseKey(h.Deref()); this._AdvApi.RegCloseKey(h.Deref());
return (retVal); 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) this.WriteKey = function WriteKey(hkey, path, key, value)
{ {
var result; var result;