Added logic to remove 'safemode' from console command on Windows 32 bit agents running on 64 bit windows.
Bryan Roe committed
Mar 28, 2022 at 22:15 UTC
e4b483354a611a77911c31356de669f87aee2a0a
1 file changed
+57
-9
agents/meshcore.js
+57
-9
@@ -46,6 +46,18 @@ var MESHRIGHT_CHATNOTIFY = 16384;
46
var MESHRIGHT_UNINSTALL = 32768;
47
var MESHRIGHT_NODESKTOP = 65536;
48
49
+
50
+function bcdOK()
51
+{
52
+ if (process.platform != 'win32') { return (false); }
53
+ if(require('os').arch() == 'x64')
54
+ {
55
+ return (require('_GenericMarshal').PointerSize == 8);
56
+ }
57
+ return (true);
58
+}
59
+
60
+
61
try {
62
Object.defineProperty(Array.prototype, 'findIndex', {
63
value: function (func) {
@@ -109,6 +121,32 @@ function getCoreTranslation() {
121
}
122
var currentTranslation = getCoreTranslation();
123
124
+try
125
+{
126
+ require('kvm-helper');
127
+}
128
+catch (e)
129
+{
130
+ var j =
131
+ {
132
+ users: function ()
133
+ {
134
+ var r = {};
135
+ require('user-sessions').Current(function (c) { r = c; });
136
+ if (process.platform != 'win32')
137
+ {
138
+ for (var i in r)
139
+ {
140
+ r[i].SessionId = r[i].uid;
141
+ }
142
+ }
143
+ return (r);
144
+ }
145
+ };
146
+ addModuleObject('kvm-helper', j);
147
+}
148
+
149
+
150
function lockDesktop(uid) {
151
switch (process.platform) {
152
case 'linux':
@@ -1294,12 +1332,7 @@ function handleServerCommand(data) {
1332
break;
1333
}
1334
case 'userSessions': {
1297
- // Send back current user sessions list, this is Windows only.
1298
- //sendConsoleText('userSessions: ' + JSON.stringify(data));
1299
- if (process.platform != 'win32') break;
1300
- var p = require('user-sessions').enumerateUsers();
1301
- p.sessionid = data.sessionid;
1302
- p.then(function (u) { mesh.SendCommand({ action: 'msg', type: 'userSessions', sessionid: data.sessionid, data: u, tag: data.tag }); });
1335
+ mesh.SendCommand({ action: 'msg', type: 'userSessions', sessionid: data.sessionid, data: require('kvm-helper').users(), tag: data.tag });
1336
break;
1337
}
1338
case 'cpuinfo':
@@ -3238,7 +3271,11 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3271
var fin = '', f = '', availcommands = 'translations,agentupdate,errorlog,msh,timerinfo,coreinfo,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,wslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg,task';
3272
if (require('os').dns != null) { availcommands += ',dnsinfo'; }
3273
try { require('linux-dhcp'); availcommands += ',dhcp'; } catch (ex) { }
3241
- if (process.platform == 'win32') { availcommands += ',cs,safemode,wpfhwacceleration,uac,volumes'; }
3274
+ if (process.platform == 'win32')
3275
+ {
3276
+ availcommands += ',cs,wpfhwacceleration,uac,volumes';
3277
+ if (bcdOK()) { availcommands += ',safemode'; }
3278
+ }
3279
if (amt != null) { availcommands += ',amt,amtconfig,amtevents'; }
3280
if (process.platform != 'freebsd') { availcommands += ',vm'; }
3281
if (require('MeshAgent').maxKvmTileSize != null) { availcommands += ',kvmmode'; }
@@ -3759,9 +3796,17 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3796
}
3797
break;
3798
case 'safemode':
3762
- if (process.platform != 'win32') {
3799
+ if (process.platform != 'win32')
3800
+ {
3801
response = 'safemode only supported on Windows Platforms'
3764
- } else {
3802
+ }
3803
+ else
3804
+ {
3805
+ if (!bcdOK())
3806
+ {
3807
+ response = 'safemode not supported on 64 bit Windows from a 32 bit process'
3808
+ break;
3809
+ }
3810
if (args['_'].length != 1) {
3811
response = 'Proper usage: safemode (ON|OFF|STATUS)'; // Display usage
3812
}
@@ -3883,6 +3928,9 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3928
require('user-sessions').enumerateUsers().then(function (u) { for (var i in u) { sendConsoleText(u[i]); } });
3929
break;
3930
}
3931
+ case 'kvmusers':
3932
+ response = JSON.stringify(require('kvm-helper').users(), null, 1);
3933
+ break;
3934
case 'toast': {
3935
if (args['_'].length < 1) { response = 'Proper usage: toast "message"'; } else {
3936
if (require('MeshAgent')._tsid == null) {