From 91e7247840ae4a7af912ebd621d323204ed66596 Mon Sep 17 00:00:00 2001 From: Marten Jacobs Date: Wed, 12 May 2021 11:01:45 +0200 Subject: [PATCH] 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 () {