mirror of
https://github.com/danbulant/node-x11
synced 2026-07-03 02:00:44 +00:00
commit
f21cdb187b
3 changed files with 38 additions and 19 deletions
50
lib/auth.js
50
lib/auth.js
|
|
@ -5,6 +5,19 @@ var Buffer = require('buffer').Buffer;
|
||||||
// add 'unpack' method for buffer
|
// add 'unpack' method for buffer
|
||||||
require('./unpackbuffer').addUnpack(Buffer);
|
require('./unpackbuffer').addUnpack(Buffer);
|
||||||
|
|
||||||
|
var typeToName = {
|
||||||
|
256: 'Local',
|
||||||
|
65535: 'Wild',
|
||||||
|
254: 'Netname',
|
||||||
|
253: 'Krb5Principal',
|
||||||
|
252: 'LocalHost',
|
||||||
|
0: 'Internet',
|
||||||
|
1: 'DECnet',
|
||||||
|
2: 'Chaos',
|
||||||
|
5: 'ServerInterpreted',
|
||||||
|
6: 'InternetV6'
|
||||||
|
};
|
||||||
|
|
||||||
function parseXauth( buf )
|
function parseXauth( buf )
|
||||||
{
|
{
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
|
|
@ -14,20 +27,7 @@ function parseXauth( buf )
|
||||||
while (offset < buf.length)
|
while (offset < buf.length)
|
||||||
{
|
{
|
||||||
var cookie = {};
|
var cookie = {};
|
||||||
var typeToName = {
|
|
||||||
256: 'Local',
|
|
||||||
65535: 'Wild',
|
|
||||||
254: 'Netname',
|
|
||||||
253: 'Krb5Principal',
|
|
||||||
252: 'LocalHost',
|
|
||||||
0: 'Internet',
|
|
||||||
1: 'DECnet',
|
|
||||||
2: 'Chaos',
|
|
||||||
5: 'ServerInterpreted',
|
|
||||||
6: 'InternetV6'
|
|
||||||
};
|
|
||||||
cookie.type = buf.readUInt16LE(offset);
|
cookie.type = buf.readUInt16LE(offset);
|
||||||
console.log('Cookie type: ');
|
|
||||||
if (!typeToName[cookie.type]) {
|
if (!typeToName[cookie.type]) {
|
||||||
console.warn('Unknown address type');
|
console.warn('Unknown address type');
|
||||||
}
|
}
|
||||||
|
|
@ -49,18 +49,24 @@ function parseXauth( buf )
|
||||||
return auth;
|
return auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
var os = require('os');
|
var homedir = require('os-homedir');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
function readXauthority(cb) {
|
function readXauthority(cb) {
|
||||||
var filename = process.env.XAUTHORITY || path.join(os.homedir(), '.Xauthority');
|
var filename = process.env.XAUTHORITY || path.join(homedir(), '.Xauthority');
|
||||||
fs.readFile(filename, function(err, data) {
|
fs.readFile(filename, function(err, data) {
|
||||||
if (!err)
|
if (!err)
|
||||||
return cb(null, data);
|
return cb(null, data);
|
||||||
if(err.code == 'ENOENT') {
|
if(err.code == 'ENOENT') {
|
||||||
// Xming/windows uses %HOME%/Xauthority ( .Xauthority with no dot ) - try with this name
|
// Xming/windows uses %HOME%/Xauthority ( .Xauthority with no dot ) - try with this name
|
||||||
filename = process.env.XAUTHORITY || path.join(os.homedir(), 'Xauthority');
|
filename = process.env.XAUTHORITY || path.join(homedir(), 'Xauthority');
|
||||||
return fs.readFile(filename, cb);
|
fs.readFile(filename, function (err, data) {
|
||||||
|
if (err.code == 'ENOENT') {
|
||||||
|
cb(null, null);
|
||||||
|
} else {
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
cb(err);
|
cb(err);
|
||||||
}
|
}
|
||||||
|
|
@ -72,11 +78,19 @@ module.exports = function( display, host, cb )
|
||||||
readXauthority(function(err, data) {
|
readXauthority(function(err, data) {
|
||||||
if(err) return cb(err);
|
if(err) return cb(err);
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
return cb(null, {
|
||||||
|
authName: '',
|
||||||
|
authData: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var auth = parseXauth(data);
|
var auth = parseXauth(data);
|
||||||
for (var cookieNum in auth)
|
for (var cookieNum in auth)
|
||||||
{
|
{
|
||||||
var cookie = auth[cookieNum];
|
var cookie = auth[cookieNum];
|
||||||
if (cookie.display === display && cookie.address === host)
|
if ((typeToName[cookie.family] === 'Wild' || cookie.address === host) &&
|
||||||
|
(cookie.display.length === 0 || cookie.display === display))
|
||||||
return cb( null, cookie );
|
return cb( null, cookie );
|
||||||
}
|
}
|
||||||
cb(new Error('No auth cookie matching display=' + display + ' and host=' + host));
|
cb(new Error('No auth cookie matching display=' + display + ' and host=' + host));
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,9 @@ function getByteOrder() {
|
||||||
function writeClientHello(stream, displayNum, authHost)
|
function writeClientHello(stream, displayNum, authHost)
|
||||||
{
|
{
|
||||||
getAuthString( displayNum, authHost, function( err, cookie ) {
|
getAuthString( displayNum, authHost, function( err, cookie ) {
|
||||||
debugger;
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
var byte_order = getByteOrder();
|
var byte_order = getByteOrder();
|
||||||
var protocol_major = 11; // TODO: config? env?
|
var protocol_major = 11; // TODO: config? env?
|
||||||
var protocol_minor = 0;
|
var protocol_minor = 0;
|
||||||
|
|
|
||||||
|
|
@ -49,5 +49,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node test-runner.js",
|
"test": "node test-runner.js",
|
||||||
"prepublish": "npm prune"
|
"prepublish": "npm prune"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"os-homedir": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue