From 91e7247840ae4a7af912ebd621d323204ed66596 Mon Sep 17 00:00:00 2001 From: Marten Jacobs Date: Wed, 12 May 2021 11:01:45 +0200 Subject: [PATCH 1/2] Generalized fetching of uid and add support for DBUS_UID env var --- lib/handshake.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/handshake.js b/lib/handshake.js index 83304ae..0d52a5e 100644 --- a/lib/handshake.js +++ b/lib/handshake.js @@ -12,7 +12,15 @@ function sha1 (input) { return shasum.digest('hex'); } -function getUserHome () { +function getUid() { + if ('DBUS_UID' in process.env) + return Number(process.env.DBUS_UID); + if ('getuid' in process) + return process.getuid(); + return null +} + +function getUserHome() { return process.env[process.platform.match(/$win/) ? 'USERPROFILE' : 'HOME']; } @@ -33,7 +41,8 @@ function getCookie (context, id, cb) { ) ); } - if ('getuid' in process && stat.uid !== process.getuid()) { + const uid = getUid(); + if (uid !== null && stat.uid !== uid) { return cb( new Error( 'Keyrings directory is not owned by the current user. Aborting authentication!' @@ -74,7 +83,7 @@ function tryAuth (stream, methods, cb) { } const authMethod = methods.shift(); - const uid = 'getuid' in process ? process.getuid() : 0; + const uid = getUid() || 0; const id = hexlify(uid); function beginOrNextAuth () { From e948d209397f5d4ff7e9775384046ec431a8c362 Mon Sep 17 00:00:00 2001 From: Ivan Chalyk Date: Thu, 23 Dec 2021 14:57:35 +0600 Subject: [PATCH 2/2] convert object keys to numbers --- lib/marshall-compat.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/marshall-compat.js b/lib/marshall-compat.js index bdf1556..22cb88f 100644 --- a/lib/marshall-compat.js +++ b/lib/marshall-compat.js @@ -110,8 +110,18 @@ function jsToMarshalFmt (signature, value) { if (value.constructor !== Object) { throw new Error(`expecting an object for signature '${signatureStr}' (got ${typeof value})`); } - for (const k of Object.keys(value)) { + for (const key of Object.keys(value)) { + let k = key; const v = value[k]; + if ( + signature.child[0].child[0].type === 'y' || + signature.child[0].child[0].type === 'n' || + signature.child[0].child[0].type === 'q' || + signature.child[0].child[0].type === 'i' || + signature.child[0].child[0].type === 'u' + ) { + k = parseInt(key) + } if (v.constructor === Variant) { result.push([k, jsToMarshalFmt(v.signature, v.value)]); } else { @@ -180,6 +190,9 @@ function marshallMessage (msg) { } } + // console.log('marshallerBody') + // console.log(JSON.stringify(marshallerBody, null, 2)) + msg.signature = signature; msg.body = marshallerBody; return message.marshall(msg);