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 () {