Comparing version 2.0.4 to 2.0.5
101
lib/auth.js
@@ -14,12 +14,5 @@ // TODO: http://en.wikipedia.org/wiki/X_Window_authorization | ||
function handleCookieProperty(property) { | ||
var length = buf.unpack('n', offset)[0]; | ||
offset += 2; | ||
cookie[property] = buf.unpackString(length, offset); | ||
offset += length; | ||
} | ||
while (offset < buf.length) | ||
{ | ||
var cookie = {}; | ||
var cookie = {}; | ||
var typeToName = { | ||
@@ -29,11 +22,12 @@ 256: 'Local', | ||
254: 'Netname', | ||
253: 'Krb5Principal', | ||
253: 'Krb5Principal', | ||
252: 'LocalHost', | ||
0: 'Internet', | ||
1: 'DECnet', | ||
0: 'Internet', | ||
1: 'DECnet', | ||
2: 'Chaos', | ||
5: 'ServerInterpreted', | ||
5: 'ServerInterpreted', | ||
6: 'InternetV6' | ||
}; | ||
cookie.type = buf.unpack('n')[0]; | ||
cookie.type = buf.readUInt16LE(offset); | ||
console.log('Cookie type: '); | ||
if (!typeToName[cookie.type]) { | ||
@@ -43,4 +37,14 @@ console.warn('Unknown address type'); | ||
offset += 2; | ||
//JSHint becomes angry when handleCookieProperty is declared inside loop | ||
cookieProperties.forEach(handleCookieProperty); | ||
cookieProperties.forEach(function(property) { | ||
var length = buf.unpack('n', offset)[0]; | ||
offset += 2; | ||
if (cookie.type === 0 && property == 'address') { // Internet | ||
// 4 bytes of ip addess, convert to w.x.y.z string | ||
cookie.address = [ buf[offset], buf[offset+1], buf[offset+2], buf[offset+3]] | ||
.map(function(octet) { return octet.toString(10) }).join('.'); | ||
} else { | ||
cookie[property] = buf.unpackString(length, offset); | ||
} | ||
offset += length; | ||
}); | ||
auth.push(cookie); | ||
@@ -51,45 +55,34 @@ } | ||
var os = require('os'); | ||
var path = require('path'); | ||
function readXauthority(cb) { | ||
var filename = process.env.XAUTHORITY || path.join(os.homedir(), '.Xauthority'); | ||
fs.readFile(filename, function(err, data) { | ||
if (!err) | ||
return cb(null, data); | ||
if(err.code == 'ENOENT') { | ||
// Xming/windows uses %HOME%/Xauthority ( .Xauthority with no dot ) - try with this name | ||
filename = process.env.XAUTHORITY || path.join(os.homedir(), 'Xauthority'); | ||
return fs.readFile(filename, cb); | ||
} else { | ||
cb(err); | ||
} | ||
}); | ||
} | ||
module.exports = function( display, host, cb ) | ||
{ | ||
var XAuthorityFile = process.env.XAUTHORITY; | ||
if (!XAuthorityFile) | ||
readXauthority(function(err, data) { | ||
if(err) return cb(err); | ||
var auth = parseXauth(data); | ||
for (var cookieNum in auth) | ||
{ | ||
if ( process.platform.match(/win/) ) { | ||
// http://www.straightrunning.com/XmingNotes/trouble.php | ||
// | ||
// The Xming magic cookie program, xauth (user-based), uses an | ||
// Xauthority file (not the traditional .Xauthority file) in | ||
// the %HOME% directory. To use xauth from Command Processor | ||
// e.g. on Windows machine 192.168.0.2 with user colin... | ||
XAuthorityFile = process.env.USERPROFILE + '\\Xauthority'; | ||
} else { | ||
XAuthorityFile = process.env.HOME + '/.Xauthority'; | ||
} | ||
var cookie = auth[cookieNum]; | ||
if (cookie.display === display && cookie.address === host) | ||
return cb( null, cookie ); | ||
} | ||
fs.readFile(XAuthorityFile, function (err, data) { | ||
if (err) | ||
{ | ||
if (err.code == 'ENOENT') | ||
{ | ||
cb('',''); | ||
return; | ||
} | ||
throw err; | ||
} | ||
var auth = parseXauth(data); | ||
for (var cookieNum in auth) | ||
{ | ||
var cookie = auth[cookieNum]; | ||
if (cookie.display == display && cookie.address == host) | ||
{ | ||
cb( cookie.authName, cookie.authData ); | ||
return; | ||
} | ||
} | ||
// throw 'No auth cookie matching display=' + display + ' and host=' + host; | ||
cb( '', '' ); | ||
}); | ||
cb(new Error('No auth cookie matching display=' + display + ' and host=' + host)); | ||
}); | ||
}; |
@@ -15,5 +15,5 @@ var getAuthString = require('./auth'); | ||
[ | ||
'L vid', | ||
'C class', | ||
'C bits_per_rgb', | ||
'L vid', | ||
'C class', | ||
'C bits_per_rgb', | ||
'S map_ent', | ||
@@ -24,3 +24,3 @@ 'L red_mask', | ||
'xxxx' | ||
], | ||
], | ||
function() { | ||
@@ -33,3 +33,3 @@ var vid = visual.vid; | ||
else | ||
readVisuals(bl, visuals, n_visuals, cb); | ||
readVisuals(bl, visuals, n_visuals, cb); | ||
}); | ||
@@ -57,3 +57,3 @@ } | ||
readDepths(bl, display, depths, n_depths, cb); | ||
}); | ||
}); | ||
}); | ||
@@ -69,14 +69,14 @@ } | ||
[ | ||
'L root', | ||
'L root', | ||
'L default_colormap', | ||
'L white_pixel', | ||
'L white_pixel', | ||
'L black_pixel', | ||
'L input_masks', | ||
'S pixel_width', | ||
'S pixel_height', | ||
'S mm_width', | ||
'S mm_height', | ||
'S min_installed_maps', | ||
'L input_masks', | ||
'S pixel_width', | ||
'S pixel_height', | ||
'S mm_width', | ||
'S mm_height', | ||
'S min_installed_maps', | ||
'S max_installed_maps', | ||
'L root_visual', | ||
'L root_visual', | ||
'C root_depth', | ||
@@ -86,3 +86,3 @@ 'C backing_stores', | ||
'C num_depths' | ||
], | ||
], | ||
function () { | ||
@@ -95,3 +95,3 @@ var depths = {}; | ||
display.screen.push(scr); | ||
if (display.screen.length == display.screen_num) | ||
@@ -106,3 +106,3 @@ { | ||
}); | ||
}); | ||
}); | ||
} | ||
@@ -115,3 +115,3 @@ } | ||
bl.unpack('C', function(res) { | ||
if (res[0] == 0) | ||
@@ -136,6 +136,6 @@ { | ||
'S xlen', | ||
'L release', | ||
'L resource_base', | ||
'L resource_mask', | ||
'L motion_buffer_size', | ||
'L release', | ||
'L resource_base', | ||
'L resource_mask', | ||
'L motion_buffer_size', | ||
'S vlen', | ||
@@ -152,4 +152,4 @@ 'S max_request_length', | ||
'xxxx' | ||
], | ||
], | ||
function() | ||
@@ -162,3 +162,3 @@ { | ||
var mask = display.resource_mask; | ||
display.rsrc_shift = 0; | ||
display.rsrc_shift = 0; | ||
while (!( (mask >> display.rsrc_shift) & 1) ) | ||
@@ -168,3 +168,3 @@ display.rsrc_shift++; | ||
bl.get(pvlen, function(vendor) | ||
bl.get(pvlen, function(vendor) | ||
{ | ||
@@ -188,3 +188,3 @@ display.vendor = vendor.toString().substr(0, display.vlen); // utf8 by default? | ||
}); | ||
} | ||
} | ||
}); | ||
@@ -208,3 +208,4 @@ } | ||
{ | ||
getAuthString( displayNum, authHost, function( authType, authData ) { | ||
getAuthString( displayNum, authHost, function( err, cookie ) { | ||
debugger; | ||
var byte_order = getByteOrder(); | ||
@@ -214,14 +215,14 @@ var protocol_major = 11; // TODO: config? env? | ||
stream.pack( | ||
'CxSSSSxxpp', | ||
[ | ||
'CxSSSSxxpp', | ||
[ | ||
byte_order, | ||
protocol_major, | ||
protocol_minor, | ||
authType.length, | ||
authData.length, | ||
authType, | ||
authData | ||
cookie.authName.length, | ||
cookie.authData.length, | ||
cookie.authName, | ||
cookie.authData | ||
] | ||
); | ||
stream.flush(); | ||
stream.flush(); | ||
}); | ||
@@ -228,0 +229,0 @@ } |
@@ -523,4 +523,3 @@ var util = require('util'); // util.inherits | ||
XClient.prototype.startHandshake = function() | ||
{ | ||
XClient.prototype.startHandshake = function() { | ||
var client = this; | ||
@@ -527,0 +526,0 @@ |
@@ -15,3 +15,3 @@ { | ||
"homepage": "https://github.com/sidorares/node-x11", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"maintainers": [ | ||
@@ -18,0 +18,0 @@ { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
22
1621008
17380