Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert object keys to numbers #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand All @@ -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!'
Expand Down Expand Up @@ -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 () {
Expand Down
15 changes: 14 additions & 1 deletion lib/marshall-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down