drop root privileges in node.js

This commit is contained in:
Thomas Merkel 2012-12-05 10:34:03 +01:00
parent 95323c5ce1
commit c716c1154f
2 changed files with 17 additions and 1 deletions

View file

@ -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 = { exports.setup = {
presets: [ presets: [
{ {

10
web.js
View file

@ -49,7 +49,15 @@ exports.init = function(dmx) {
var app = http.createServer(handler) 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) { io.listen(app).sockets.on('connection', function (socket) {
socket.emit('init', {'devices': dmx.devices, 'setup': dmx.setup}); socket.emit('init', {'devices': dmx.devices, 'setup': dmx.setup});