From 382abe9f6d50fdea277db888d273ba1366d18bde Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sun, 19 Jul 2020 11:46:34 -0600 Subject: [PATCH] Add some more environment variables --- backend/src/api.ts | 2 +- backend/src/sandbox.ts | 2 +- backend/src/util.ts | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/api.ts b/backend/src/api.ts index 845fffe..292b9b4 100644 --- a/backend/src/api.ts +++ b/backend/src/api.ts @@ -57,7 +57,7 @@ export class Session { } get env() { - return util.getEnv(this.uuid); + return util.getEnv(this.context); } log = (msg: string) => console.log(`[${this.uuid}] ${msg}`); diff --git a/backend/src/sandbox.ts b/backend/src/sandbox.ts index a2774f4..f987a52 100644 --- a/backend/src/sandbox.ts +++ b/backend/src/sandbox.ts @@ -44,7 +44,7 @@ async function main() { await run(privilegedSetup({ uid, uuid }), log); const args = privilegedSpawn({ uid, uuid }, ["bash"]); const proc = spawn(args[0], args.slice(1), { - env: getEnv(uuid), + env: getEnv({ uid, uuid }), stdio: "inherit", }); await new Promise((resolve, reject) => { diff --git a/backend/src/util.ts b/backend/src/util.ts index 808ca8c..8178696 100644 --- a/backend/src/util.ts +++ b/backend/src/util.ts @@ -1,8 +1,11 @@ import { spawn, SpawnOptions } from "child_process"; +import * as os from "os"; import * as process from "process"; import * as appRoot from "app-root-path"; +import { MIN_UID, MAX_UID } from "./users"; + export interface Options extends SpawnOptions { input?: string; check?: boolean; @@ -17,7 +20,7 @@ export const rijuSystemPrivileged = appRoot.resolve( "system/out/riju-system-privileged" ); -export function getEnv(uuid: string) { +export function getEnv({ uid, uuid }: Context) { const cwd = `/tmp/riju/${uuid}`; const path = [ `${cwd}/.gem/ruby/2.7.0/bin`, @@ -29,15 +32,20 @@ export function getEnv(uuid: string) { `/usr/bin`, `/bin`, ]; + const username = + uid >= MIN_UID && uid < MAX_UID ? `riju${uid}` : os.userInfo().username; return { HOME: cwd, HOSTNAME: "riju", LANG: process.env.LANG || "", LC_ALL: process.env.LC_ALL || "", + LOGNAME: username, PATH: path.join(":"), PWD: cwd, SHELL: "/usr/bin/bash", - TERM: "xterm-color", + TERM: "xterm-256color", + USER: username, + USERNAME: username, }; }