Commit ed95eb93 authored by Leo Iannacone's avatar Leo Iannacone

ok ... config.user has more problems than I expected - removed at least for...

ok ... config.user has more problems than I expected - removed at least for now capability to select a uid - still checking if node has been launched with sudo and go down permission to original user id
parent 438785f8
......@@ -41,20 +41,21 @@ if (config.routes.preferences)
app.get(config.routes.preferences, routes.preferences)
// Listening
var server = app.listen(config.port, config.host, null, function(){
var server = app.listen(config.port, config.host, null, function(err){
// set uid e gid - drop root privileges
try {
process.setgid(config.user);
process.setuid(config.user);
} catch (err) {
if (err.code == 'EPERM') {
console.error('Changing user id %s: permission denied. Running as %s.', config.user, process.getuid());
}
else {
console.error('Error changing user id.', err)
process.exit(1)
}
if (err) {
console.log(err)
return
}
// Checking nodejs with sudo:
// Find out which user used sudo through the environment variable
// and set his user id
var uid = parseInt(process.env.SUDO_UID);
if (uid) {
console.log("Please do not run nodejs with sudo. Changing user to %d", uid)
process.setgid(uid);
process.setuid(uid);
}
// statuses
......
......@@ -8,9 +8,13 @@
// #start config-auto-export
var config = {}
/*
* Configure host and port.
* Please for ports < 1000 use authbind. DO NOT RUN nodejs as root.
* $ authbind nodejs index.js
*/
config.host = 'localhost'
config.port = 3000
config.user = 'www-data' // who will run server [not fully tested yet]
config.socket = {}
config.socket.log = false
......@@ -117,14 +121,15 @@ function _merge(object1, object2) {
try {
user_config = require('../user.config.js')
console.log("Reading user configutation ...")
module.exports = _merge(config, user_config)
config = _merge(config, user_config)
} catch (err) {
if (err.code == 'MODULE_NOT_FOUND') {
console.log("User configutation not found. Using global settings.")
module.exports = config
}
else {
console.error("Error reading user configutation", err)
console.error("Error reading user configutation", err);
process.exit(1)
}
}
\ No newline at end of file
} finally {
module.exports = config
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment