From c716c1154f350d90d9acaa3e82ad789a6d72e284 Mon Sep 17 00:00:00 2001 From: Thomas Merkel Date: Wed, 5 Dec 2012 10:34:03 +0100 Subject: [PATCH] drop root privileges in node.js --- setup.js | 8 ++++++++ web.js | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/setup.js b/setup.js index 210e761..3430faf 100644 --- a/setup.js +++ b/setup.js @@ -1,3 +1,11 @@ +// listen port +exports.port = 80; + +// uid and gid to drop root priv. +exports.uid = 'light'; +exports.gid = 'users'; + +// setup devices exports.setup = { presets: [ { diff --git a/web.js b/web.js index 19b532d..c8b4111 100644 --- a/web.js +++ b/web.js @@ -49,7 +49,15 @@ exports.init = function(dmx) { var app = http.createServer(handler) - app.listen(8080, '::'); + app.listen(setup.port, '::', null, function() { + try { + process.setuid(setup.uid); + process.setgid(setup.gid); + } catch (err) { + console.log(err); + process.exit(1); + } + }); io.listen(app).sockets.on('connection', function (socket) { socket.emit('init', {'devices': dmx.devices, 'setup': dmx.setup});