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) ...@@ -41,20 +41,21 @@ if (config.routes.preferences)
app.get(config.routes.preferences, routes.preferences) app.get(config.routes.preferences, routes.preferences)
// Listening // 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 if (err) {
try { console.log(err)
process.setgid(config.user); return
process.setuid(config.user); }
} catch (err) {
if (err.code == 'EPERM') { // Checking nodejs with sudo:
console.error('Changing user id %s: permission denied. Running as %s.', config.user, process.getuid()); // Find out which user used sudo through the environment variable
} // and set his user id
else { var uid = parseInt(process.env.SUDO_UID);
console.error('Error changing user id.', err) if (uid) {
process.exit(1) console.log("Please do not run nodejs with sudo. Changing user to %d", uid)
} process.setgid(uid);
process.setuid(uid);
} }
// statuses // statuses
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
// #start config-auto-export // #start config-auto-export
var config = {} 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.host = 'localhost'
config.port = 3000 config.port = 3000
config.user = 'www-data' // who will run server [not fully tested yet]
config.socket = {} config.socket = {}
config.socket.log = false config.socket.log = false
...@@ -117,14 +121,15 @@ function _merge(object1, object2) { ...@@ -117,14 +121,15 @@ function _merge(object1, object2) {
try { try {
user_config = require('../user.config.js') user_config = require('../user.config.js')
console.log("Reading user configutation ...") console.log("Reading user configutation ...")
module.exports = _merge(config, user_config) config = _merge(config, user_config)
} catch (err) { } catch (err) {
if (err.code == 'MODULE_NOT_FOUND') { if (err.code == 'MODULE_NOT_FOUND') {
console.log("User configutation not found. Using global settings.") console.log("User configutation not found. Using global settings.")
module.exports = config
} }
else { else {
console.error("Error reading user configutation", err) console.error("Error reading user configutation", err);
process.exit(1) process.exit(1)
} }
} } finally {
\ No newline at end of file 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