From b9c756f442b528f9c9d5e4b83404d08c72c9872e Mon Sep 17 00:00:00 2001 From: Rin Date: Sun, 17 Jul 2022 15:14:23 +0100 Subject: [PATCH] Add setuid/setgid --- src/config.ts | 6 ++++++ src/index.ts | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/config.ts b/src/config.ts index 702e3c9..fd9821f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -6,6 +6,12 @@ export interface ConfigFile { regionName: string; serverIp?: string; gameOptions: GameOptions; + unix?: UnixOptions; +} + +export interface UnixOptions { + setuid: number; + setgid: number; } export interface GameOptions { diff --git a/src/index.ts b/src/index.ts index bfcc824..d844c04 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,8 @@ import fs from 'fs'; import bodyParser from 'body-parser'; import AllnetModule from './allnet'; import MuchaModule from './mucha'; +import { Config } from './config'; +import process from 'process'; globalAgent.options.keepAlive = true; // @ts-ignore @@ -70,6 +72,13 @@ let cert = fs.readFileSync('./server_wangan.crt'); http.createServer(allnetApp).listen(PORT_ALLNET, '0.0.0.0', 511, () => { console.log(`ALL.net server listening on port ${PORT_ALLNET}!`); + let unix = Config.getConfig().unix; + if (unix && process.platform == 'linux') { + console.log('Downgrading permissions...'); + process.setuid!(unix.setuid); + process.setgid!(unix.setgid); + console.log('Done!'); + } }) https.createServer({key, cert}, muchaApp).listen(PORT_MUCHA, '0.0.0.0', 511, () => {