@ai-ecoverse/slicc-kernel 1.196.17 → 1.196.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9053,9 +9053,9 @@ async function accountOf(l, user) {
9053
9053
  if (!found) throw fsError("ENOENT", `no user ${String(user)}`);
9054
9054
  return found;
9055
9055
  }
9056
- async function runAs(l, self, requested2) {
9057
- if (requested2 === void 0) return self;
9058
- const target = await accountOf(l, requested2);
9056
+ async function runAs(l, self, requested) {
9057
+ if (requested === void 0) return self;
9058
+ const target = await accountOf(l, requested);
9059
9059
  if (self.uid !== 0 && target.uid !== self.uid) {
9060
9060
  throw fsError("EPERM", `${self.name} may not run as ${target.name}`);
9061
9061
  }
@@ -9626,7 +9626,7 @@ function satisfies(version, range2) {
9626
9626
  }
9627
9627
 
9628
9628
  // src/version.ts
9629
- var KERNEL_VERSION = true ? "1.196.17" : "0.0.0-dev";
9629
+ var KERNEL_VERSION = true ? "1.196.18" : "0.0.0-dev";
9630
9630
  var OS_RELEASE = "6.0.0-slicc";
9631
9631
  function procVersion() {
9632
9632
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -13827,12 +13827,8 @@ var SpawnError = class extends Error {
13827
13827
  }
13828
13828
  };
13829
13829
  var ChangedError = class extends SpawnError {
13830
- notice;
13831
- file;
13832
- constructor(notice, file) {
13830
+ constructor() {
13833
13831
  super("EPERM");
13834
- this.notice = notice;
13835
- this.file = file;
13836
13832
  }
13837
13833
  };
13838
13834
  function interrupted(signal) {
@@ -23227,11 +23223,11 @@ function stdinMatches(rule, stdin) {
23227
23223
  function recordable(cwd, argv) {
23228
23224
  return !hasControl(cwd) && !argv.some(hasControl);
23229
23225
  }
23230
- function changedText(file) {
23231
- return `sudo: ${file} changed since it was approved`;
23226
+ function changedText(word) {
23227
+ return `sudo: ${quoteWord(word)} changed since it was approved`;
23232
23228
  }
23233
- function requestedText(file) {
23234
- return `sudo: ${file} changed since it was requested`;
23229
+ function requestedText(word) {
23230
+ return `sudo: ${quoteWord(word)} changed since it was requested`;
23235
23231
  }
23236
23232
  function changedFile(approved, now) {
23237
23233
  const files = /* @__PURE__ */ new Set([...Object.keys(approved), ...Object.keys(now)]);
@@ -23698,12 +23694,12 @@ var Sudo = class {
23698
23694
  if (file.split("/").includes("..")) return physicalPathAsync(fs, file, true);
23699
23695
  return await fs.realpath?.(file, true).catch(() => file) ?? file;
23700
23696
  }
23701
- async moved({ routes }, loading2 = false) {
23697
+ async moved({ routes }) {
23702
23698
  for (const [asked, approved] of Object.entries(routes)) {
23703
23699
  const real = await this.real(asked).catch(() => void 0);
23704
- if (real !== approved) return loading2 ? real ?? asked : approved;
23700
+ if (real !== approved) return true;
23705
23701
  }
23706
- return void 0;
23702
+ return false;
23707
23703
  }
23708
23704
  async missingBacking(hashes, except) {
23709
23705
  for (const path of Object.keys(hashes)) {
@@ -23746,6 +23742,11 @@ var Sudo = class {
23746
23742
  await lstat("/");
23747
23743
  return physicalPathAsync({ lstat, readlink: (at) => fs.readlink(at) }, path, true);
23748
23744
  }
23745
+ async executablePath(fs, cred, asked) {
23746
+ const path = await this.searched(fs, cred, asked);
23747
+ const st = await fs.stat(path);
23748
+ return st.isFile && (st.mode & 73) !== 0 ? path : void 0;
23749
+ }
23749
23750
  async locate(word, cwd, reads, target) {
23750
23751
  const fs = this.o.planFs?.(reads) ?? this.o.fs;
23751
23752
  const candidates = word.includes("/") ? [askedPath(cwd, word)] : SECURE_PATH.split(":").map((dir) => `${dir}/${word}`);
@@ -23753,9 +23754,8 @@ var Sudo = class {
23753
23754
  let denial;
23754
23755
  for (const asked of candidates) {
23755
23756
  try {
23756
- const path = await this.searched(fs, cred, asked);
23757
- const st = await fs.stat(path);
23758
- if (st.isFile && (st.mode & 73) !== 0) return { path, asked };
23757
+ const path = await this.executablePath(fs, cred, asked);
23758
+ if (path !== void 0) return { path, asked };
23759
23759
  } catch (err) {
23760
23760
  const code = err.code;
23761
23761
  if (code === "EACCES") denial = failed2(code, `sudo: ${word}: Permission denied`);
@@ -23834,7 +23834,7 @@ ${SCRIPT_HELP}
23834
23834
  const [word = "", ...args] = r.argv;
23835
23835
  const argv = [r.path, ...args];
23836
23836
  if (!await this.mayAsk(self, target, r, argv)) {
23837
- const quoted = argv.map(quoteWord).join(" ");
23837
+ const quoted = r.argv.map(quoteWord).join(" ");
23838
23838
  return failed2(
23839
23839
  "EACCES",
23840
23840
  `sudo: ${self.name} may no longer ask to run ${quoted} as ${target.name}`
@@ -23854,19 +23854,19 @@ ${SCRIPT_HELP}
23854
23854
  if (located && "error" in located) return located;
23855
23855
  if (!located) {
23856
23856
  const gone = await this.missingBacking(r.bound, r.path);
23857
- return gone ? failed2("EPERM", requestedText(gone)) : failed2("ENOENT", `sudo: ${word}: command not found`);
23857
+ return gone ? failed2("EPERM", requestedText(word)) : failed2("ENOENT", `sudo: ${word}: command not found`);
23858
23858
  }
23859
23859
  const { path, asked } = located;
23860
- if (path !== r.path) return failed2("EPERM", `sudo: ${word} now runs ${path}, not ${r.path}`);
23860
+ if (path !== r.path) return failed2("EPERM", requestedText(word));
23861
23861
  const bound3 = await this.bound(path, r.cwd, asked, void 0, reads);
23862
- if (!bound3) return failed2("EPERM", requestedText(await this.missingBacking(r.bound) ?? path));
23862
+ if (!bound3) return failed2("EPERM", requestedText(word));
23863
23863
  const changed2 = changedDecision(r.bound, r, bound3, path);
23864
23864
  if (changed2 !== void 0) {
23865
23865
  const missing7 = ["chainSha256", "routeSha256"].filter(
23866
23866
  (key) => bound3[key] !== void 0 && r[key] === void 0
23867
23867
  );
23868
23868
  const hint = missing7.length && changedFile(r.bound, bound3.hashes) === void 0 ? `; the saved request lacks ${missing7.join(" and ")}; pass back the whole request from approve unchanged` : "";
23869
- return failed2("EPERM", requestedText(changed2) + hint);
23869
+ return failed2("EPERM", requestedText(word) + hint);
23870
23870
  }
23871
23871
  const now = await this.rootOnly(r.cwd, args);
23872
23872
  const flipped = Object.keys(r.rootOnly).find((at) => r.rootOnly[at] && now[at] !== true);
@@ -23901,6 +23901,11 @@ ${SCRIPT_HELP}
23901
23901
  const { caller, self, target, parsed: parsed3 } = s;
23902
23902
  const { cred } = caller;
23903
23903
  const [word = "", ...args] = parsed3.command;
23904
+ const notAllowed = () => failed2(
23905
+ "EPERM",
23906
+ `sudo: ${self.name} is not allowed to run ${parsed3.command.map(quoteWord).join(" ")} as ${target.name}`
23907
+ );
23908
+ if (!root && mine.length === 0) return notAllowed();
23904
23909
  const cwd = await this.canonical(call.cwd, cred);
23905
23910
  if (cwd === void 0 || !await this.reachable(cred, cwd)) {
23906
23911
  return failed2(
@@ -23921,13 +23926,7 @@ ${SCRIPT_HELP}
23921
23926
  const matching = applicable.filter((rule) => pinned(rule, bound3.hashes, bound3));
23922
23927
  const grant = () => this.grant(self, target, cred, parsed3.command, path, cwd, call.term, bound3, s.kept, asked);
23923
23928
  if (root || matching.some((rule) => rule.nopasswd)) return grant();
23924
- const quoted = argv.map(quoteWord).join(" ");
23925
- if (matching.length === 0) {
23926
- return failed2(
23927
- "EPERM",
23928
- `sudo: ${self.name} is not allowed to run ${quoted} as ${target.name}`
23929
- );
23930
- }
23929
+ if (matching.length === 0) return notAllowed();
23931
23930
  if (!parsed3.reset && this.timestamps.current(s.owner, s.policy, stampOf(bound3))) {
23932
23931
  this.timestamps.stamp(s.owner, s.policy, stampOf(bound3));
23933
23932
  this.logged(s, cwd, argv);
@@ -23951,14 +23950,11 @@ ${SCRIPT_HELP}
23951
23950
  if (await this.canonical(call.cwd, cred) !== cwd || !await this.reachable(cred, cwd)) {
23952
23951
  return failed2("EACCES", `sudo: ${call.cwd} changed while the request waited`);
23953
23952
  }
23954
- const moved2 = await this.moved(bound3);
23955
- if (moved2 !== void 0) return failed2("EPERM", changedText(moved2));
23953
+ if (await this.moved(bound3)) return failed2("EPERM", changedText(word));
23956
23954
  if (answer2.answer === "once" && !answer2.person) return grant();
23957
23955
  const now = await this.bound(path, cwd, asked, caller.pid);
23958
- if (!now)
23959
- return failed2("EPERM", changedText(await this.missingBacking(bound3.hashes) ?? path));
23960
- const changed2 = changedDecision(bound3.hashes, bound3, now, path);
23961
- if (changed2 !== void 0) return failed2("EPERM", changedText(changed2));
23956
+ if (!now || changedDecision(bound3.hashes, bound3, now, path) !== void 0)
23957
+ return failed2("EPERM", changedText(word));
23962
23958
  const shown2 = recordable(cwd, [...parsed3.command, ...Object.keys(bound3.hashes)]);
23963
23959
  const result = answer2.answer === "once" ? grant() : await this.always(
23964
23960
  self,
@@ -32841,8 +32837,8 @@ var WasmProcess = class _WasmProcess {
32841
32837
  close: () => source.release()
32842
32838
  });
32843
32839
  }
32844
- nonblocking(fd, requested2) {
32845
- return requested2 === true || !this.options.perCallNonblock && ((this.fds.statusFlags(fd) ?? 0) & O_NONBLOCK2) !== 0;
32840
+ nonblocking(fd, requested) {
32841
+ return requested === true || !this.options.perCallNonblock && ((this.fds.statusFlags(fd) ?? 0) & O_NONBLOCK2) !== 0;
32846
32842
  }
32847
32843
  async fdSyscall(req, cancelled) {
32848
32844
  if (isVfsSyscall(req)) return this.vfsSyscall(req);
@@ -33724,7 +33720,8 @@ var WasmProcess = class _WasmProcess {
33724
33720
  })
33725
33721
  };
33726
33722
  } catch (err) {
33727
- if (err instanceof ChangedError) return { error: err.notice, errno: err.code };
33723
+ if (err instanceof ChangedError)
33724
+ return { error: changedText(argv[0] ?? asked), errno: err.code };
33728
33725
  throw err;
33729
33726
  }
33730
33727
  }
@@ -38093,8 +38090,7 @@ function describe(req, tty) {
38093
38090
  return { argv: [req.argv0, ...req.args], tty, started: Date.now(), ...exe };
38094
38091
  }
38095
38092
  function refuseChanged(approved, now) {
38096
- const changed2 = changedFile(approved, now);
38097
- if (changed2 !== void 0) throw new ChangedError(changedText(changed2), changed2);
38093
+ if (changedFile(approved, now) !== void 0) throw new ChangedError();
38098
38094
  }
38099
38095
  var O_WRONLY2 = 1;
38100
38096
  var OUTPUT_MODE = 384;
@@ -38113,10 +38109,14 @@ function sudoCause(err) {
38113
38109
  if (typeof code !== "string") throw err;
38114
38110
  return code;
38115
38111
  }
38116
- function requested(err) {
38117
- if (err instanceof ChangedError) throw sudoFailure(err.code, requestedText(err.file));
38118
- throw err;
38119
- }
38112
+ var LOST_ROUTE = /* @__PURE__ */ new Set([
38113
+ "ENOENT",
38114
+ "ENOTDIR",
38115
+ "EACCES",
38116
+ "ELOOP",
38117
+ "ESTALE",
38118
+ "ENAMETOOLONG"
38119
+ ]);
38120
38120
  var MAX_SPAWN_TAGS = 8;
38121
38121
  function tagList(value2) {
38122
38122
  if (!Array.isArray(value2)) {
@@ -39416,16 +39416,20 @@ var Launcher = class {
39416
39416
  const refused5 = (err) => {
39417
39417
  throw codeOf9(err) === "EACCES" ? new SpawnError("EACCES") : err;
39418
39418
  };
39419
+ const lost = (err) => {
39420
+ if (LOST_ROUTE.has(codeOf9(err))) throw new ChangedError();
39421
+ throw err;
39422
+ };
39419
39423
  const { file, parentHops } = await this.execFile(
39420
39424
  req.file,
39421
39425
  req.cwd,
39422
39426
  this.execGuard(cred, ppid),
39423
39427
  ppid
39424
- ).catch(refused5);
39428
+ ).catch(grant?.files ? lost : refused5);
39425
39429
  const reads = prepared ?? (grant?.files && await this.scriptReads(grant.files, cred, ppid));
39426
39430
  if (grant?.asked && reads) {
39427
- const destination = await this.sudoer.searched(this.sudoFs(reads), cred, grant.asked).catch(refused5);
39428
- if (destination !== file) throw new ChangedError(changedText(file), file);
39431
+ const destination = await this.sudoer.executablePath(this.sudoFs(reads), cred, grant.asked).catch(lost);
39432
+ if (destination !== file) throw new ChangedError();
39429
39433
  }
39430
39434
  const plan = await this.plan(file, req.argv, req.cwd, scope, {
39431
39435
  argv0: req.argv0,
@@ -39444,10 +39448,7 @@ var Launcher = class {
39444
39448
  async checkFailedPlan(file, req, scope, grant) {
39445
39449
  const reads = this.sudoer.reads();
39446
39450
  const { planned } = await this.plan(file, req.argv, req.cwd, scope, { reads });
39447
- if (!planned) {
39448
- const gone = await this.sudoer.missingBacking(grant.files.hashes) ?? file;
39449
- throw new ChangedError(changedText(gone), gone);
39450
- }
39451
+ if (!planned) throw new ChangedError();
39451
39452
  await this.unchanged({ ...planned, reads }, file, req.cwd, grant);
39452
39453
  }
39453
39454
  async enterable(g, cwd) {
@@ -39601,26 +39602,26 @@ var Launcher = class {
39601
39602
  const now = await planned.reads.bind([file, grant.asked ?? file, ...files]);
39602
39603
  refuseChanged(approved.hashes, now.hashes);
39603
39604
  refuseChanged(approved.routes, now.routes);
39604
- if (now.chainSha256 !== approved.chainSha256) throw new ChangedError(changedText(file), file);
39605
+ if (now.chainSha256 !== approved.chainSha256) throw new ChangedError();
39605
39606
  return { pinned: approved };
39606
39607
  }
39607
39608
  approvedChain(planned, file, cwd, grant) {
39608
39609
  if (!grant) return void 0;
39609
39610
  return async (next3) => {
39610
39611
  const chain2 = (p) => [...p.via ?? [], ...p.binfmts ?? []];
39611
- if (!sameList(chain2(next3), chain2(planned))) throw new ChangedError(changedText(file), file);
39612
+ if (!sameList(chain2(next3), chain2(planned))) throw new ChangedError();
39612
39613
  await this.unchanged(next3, file, cwd, grant);
39613
39614
  };
39614
39615
  }
39615
39616
  async scriptReads(files, cred, pid) {
39616
- await this.checkRoutes(files, false);
39617
+ await this.checkRoutes(files);
39617
39618
  const snapshots = /* @__PURE__ */ new Map();
39618
39619
  const reads = this.sudoer.reads(snapshots);
39619
39620
  const guard2 = { fs: this.sudoFs(reads), dac: this.dac, cred, pid, links: cred.euid };
39620
39621
  for (const path of files.scripts ?? []) {
39621
39622
  const real = files.routes[path];
39622
39623
  const walked2 = await need(guard2, "open", path, R_OK, { directory: false });
39623
- if (walked2.missing || walked2.path !== real) throw new ChangedError(changedText(path), path);
39624
+ if (walked2.missing || walked2.path !== real) throw new ChangedError();
39624
39625
  if (!snapshots.has(real))
39625
39626
  snapshots.set(real, new Uint8Array(await this.noLinksFs.readFileBuffer(real)));
39626
39627
  }
@@ -39633,14 +39634,13 @@ var Launcher = class {
39633
39634
  const real = files.routes[path];
39634
39635
  if (real === void 0) continue;
39635
39636
  const bytes = reads.snapshots.get(real);
39636
- if (!bytes) throw new ChangedError(changedText(path), path);
39637
+ if (!bytes) throw new ChangedError();
39637
39638
  args[args.length - fromEnd] = scriptFd(fds, bytes);
39638
39639
  }
39639
39640
  return { ...planned, args };
39640
39641
  }
39641
- async checkRoutes(files, loading2) {
39642
- const file = await this.sudoer.moved(files, loading2);
39643
- if (file !== void 0) throw new ChangedError(changedText(file), file);
39642
+ async checkRoutes(files) {
39643
+ if (await this.sudoer.moved(files)) throw new ChangedError();
39644
39644
  }
39645
39645
  async pinOf(path, caller) {
39646
39646
  const { pinned: pinned2 } = caller;
@@ -39648,7 +39648,7 @@ var Launcher = class {
39648
39648
  const real = await this.sudoer.real(path);
39649
39649
  const approved = pinned2.routes[path];
39650
39650
  if (approved !== real && (approved !== void 0 || !await this.sudoer.trustedThrough(path)))
39651
- throw new ChangedError(changedText(real), real);
39651
+ throw new ChangedError();
39652
39652
  const hex4 = pinned2.hashes[real];
39653
39653
  return hex4 === void 0 ? {} : { [real]: hex4 };
39654
39654
  }
@@ -40090,7 +40090,7 @@ var Launcher = class {
40090
40090
  const own = env.HOSTNAME;
40091
40091
  if (asked.target.abi === "wasi") env.HOSTNAME = this.hostname;
40092
40092
  const planned = chosen2(asked, env);
40093
- if (req.pinned) await this.checkRoutes(req.pinned, true);
40093
+ if (req.pinned) await this.checkRoutes(req.pinned);
40094
40094
  const caller = {
40095
40095
  pid: req.ppid ?? 0,
40096
40096
  uid: req.cred.euid,
@@ -41901,12 +41901,16 @@ var Launcher = class {
41901
41901
  this.resetCatalogs();
41902
41902
  const req = { file: grant.file, argv: grant.argv, env: grant.env, cwd: grant.cwd };
41903
41903
  const ctx = { ppid: 0, cred: grant.cred, scope: "", grant };
41904
+ const word = grant.argv[0] ?? grant.asked;
41905
+ const requested = (err2) => {
41906
+ if (err2 instanceof ChangedError) throw sudoFailure(err2.code, requestedText(word));
41907
+ throw err2;
41908
+ };
41904
41909
  const planned = await this.planOne(req, ctx).catch((err2) => {
41905
41910
  if (err2 instanceof ChangedError) requested(err2);
41906
41911
  const code = sudoCause(err2);
41907
- const word = grant.argv[0] ?? grant.file;
41908
- if (code === "ENOENT") throw sudoFailure(code, `sudo: ${word}: command not found`);
41909
- throw sudoFailure(code, `sudo: ${grant.file}: ${ERRNO_TEXT[code] ?? code}`);
41912
+ if (code === "ENOENT") throw sudoFailure(code, `sudo: ${quoteWord(word)}: command not found`);
41913
+ throw sudoFailure(code, `sudo: ${quoteWord(word)}: ${ERRNO_TEXT[code] ?? code}`);
41910
41914
  });
41911
41915
  const pin = await this.unchanged(planned, grant.file, grant.cwd, grant).catch(requested);
41912
41916
  const fds = await this.sudoOutputs(options, caller, this.stackFor(tags, tagged.tagBase));