@ai-ecoverse/slicc-kernel 1.175.0 → 1.176.0

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.
@@ -7514,7 +7514,7 @@ var init_version = __esm({
7514
7514
  "src/version.ts"() {
7515
7515
  "use strict";
7516
7516
  init_captured_globals();
7517
- KERNEL_VERSION = true ? "1.175.0" : "0.0.0-dev";
7517
+ KERNEL_VERSION = true ? "1.176.0" : "0.0.0-dev";
7518
7518
  OS_RELEASE = "6.0.0-slicc";
7519
7519
  }
7520
7520
  });
@@ -7513,7 +7513,7 @@ var init_version = __esm({
7513
7513
  "src/version.ts"() {
7514
7514
  "use strict";
7515
7515
  init_captured_globals();
7516
- KERNEL_VERSION = true ? "1.175.0" : "0.0.0-dev";
7516
+ KERNEL_VERSION = true ? "1.176.0" : "0.0.0-dev";
7517
7517
  OS_RELEASE = "6.0.0-slicc";
7518
7518
  }
7519
7519
  });
package/dist/node.js CHANGED
@@ -3702,7 +3702,7 @@ function satisfies(version, range2) {
3702
3702
  }
3703
3703
 
3704
3704
  // src/version.ts
3705
- var KERNEL_VERSION = true ? "1.175.0" : "0.0.0-dev";
3705
+ var KERNEL_VERSION = true ? "1.176.0" : "0.0.0-dev";
3706
3706
  var OS_RELEASE = "6.0.0-slicc";
3707
3707
  function procVersion() {
3708
3708
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -9064,6 +9064,7 @@ var EmbedderBroker = class {
9064
9064
  budget;
9065
9065
  open = /* @__PURE__ */ new Map();
9066
9066
  tagsOf;
9067
+ denied;
9067
9068
  constructor(users, lookup4, tagsOf2 = () => void 0, budget = EMBEDDER_BUDGET) {
9068
9069
  this.users = users;
9069
9070
  this.tagsOf = tagsOf2;
@@ -9081,7 +9082,8 @@ var EmbedderBroker = class {
9081
9082
  return this.hooks.get(client);
9082
9083
  }
9083
9084
  async allowed(policy, caller) {
9084
- if (caller.euid === 0 || caller.euid === caller.sessionUid) return true;
9085
+ if (caller.euid === 0) return true;
9086
+ if (policy.session !== false && caller.euid === caller.sessionUid) return true;
9085
9087
  if (policy.group !== void 0) {
9086
9088
  const gid = await this.lookup.groupId(policy.group);
9087
9089
  if (gid !== void 0 && (caller.egid === gid || caller.groups.includes(gid))) return true;
@@ -9097,9 +9099,22 @@ var EmbedderBroker = class {
9097
9099
  if (!hook) throw new KernelError("ENOTSUP", "no page answers requests for this session");
9098
9100
  const policy = Object.hasOwn(hook.kinds, kind) ? hook.kinds[kind] : void 0;
9099
9101
  if (!policy) throw new KernelError("ENOTSUP", `this embedder does not answer ${kind}`);
9100
- if (this.users !== "off" && !await this.allowed(policy, caller))
9101
- throw new KernelError("EACCES", `${kind} is not allowed for this user`);
9102
9102
  const tags = caller.tags;
9103
+ if (this.users !== "off" && !await this.allowed(policy, caller)) {
9104
+ try {
9105
+ this.denied?.({
9106
+ pid: caller.pid,
9107
+ uid: caller.euid,
9108
+ op: "embedder",
9109
+ path: EMBEDDER_PATH,
9110
+ errno: "EACCES",
9111
+ kind,
9112
+ ...tags?.length ? { tag: tags[0] } : {}
9113
+ });
9114
+ } catch {
9115
+ }
9116
+ throw new KernelError("EACCES", `${kind} is not allowed for this user`);
9117
+ }
9103
9118
  return {
9104
9119
  pid: caller.shownPid,
9105
9120
  uid: caller.euid,
@@ -9142,7 +9157,8 @@ function kindsOf(hook) {
9142
9157
  kind,
9143
9158
  {
9144
9159
  ...policy?.group !== void 0 ? { group: String(policy.group) } : {},
9145
- ...policy?.users ? { users: [...policy.users] } : {}
9160
+ ...policy?.users ? { users: [...policy.users] } : {},
9161
+ ...policy?.session === false ? { session: false } : {}
9146
9162
  }
9147
9163
  ])
9148
9164
  );
@@ -15429,11 +15445,12 @@ function parsePolicy(text, file) {
15429
15445
  var PASSWD = "/etc/passwd";
15430
15446
  var GROUP = "/etc/group";
15431
15447
  var DEFAULT_PASSWD = "root:x:0:0:root:/root:/bin/bash\nnobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin\n";
15432
- var DEFAULT_GROUP = "root:x:0:\nsudo:x:27:\nusers:x:100:\nnogroup:x:65534:\n";
15448
+ var DEFAULT_GROUP = "root:x:0:\ndialout:x:20:\nsudo:x:27:\nusers:x:100:\nnogroup:x:65534:\n";
15433
15449
  var NAME3 = /^[a-z_][a-z0-9_.-]*$/;
15434
15450
  var MAX_NAME = 255;
15435
15451
  var FIRST_UID = 1e3;
15436
15452
  var LAST_UID = 6e4;
15453
+ var MAX_GID = 4294967294;
15437
15454
  var USERS_GROUP = "users";
15438
15455
  var HOME_DIR = /^\/home\/[^/]+$/;
15439
15456
  var SYSTEM_PNPM_HOME = "/usr/local/share/pnpm";
@@ -15729,6 +15746,26 @@ var UserDb = class {
15729
15746
  const { group } = await this.tables();
15730
15747
  return parsed(group).map(({ name: name2, gid, members }) => ({ name: name2, gid, members: [...members] }));
15731
15748
  }
15749
+ addGroup(name2, gid) {
15750
+ return this.serial(async () => {
15751
+ if (typeof name2 !== "string" || name2.length > MAX_NAME || !NAME3.test(name2)) {
15752
+ throw fsError("EINVAL", `not a group name: ${String(name2)}`);
15753
+ }
15754
+ if (typeof gid !== "number" || !Number.isInteger(gid) || gid < 0 || gid > MAX_GID) {
15755
+ throw fsError("EINVAL", `not a group id: ${String(gid)}`);
15756
+ }
15757
+ const { group } = await this.tables();
15758
+ const rows = parsed(group);
15759
+ const found = rows.find((g) => g.name === name2);
15760
+ if (found) return { name: found.name, gid: found.gid, members: [...found.members] };
15761
+ const taken = rows.find((g) => g.gid === gid);
15762
+ if (taken) throw fsError("EEXIST", `group id ${gid} is group ${taken.name}`);
15763
+ group.push({ name: name2, gid, members: [] });
15764
+ await this.fs.mkdir("/etc", { recursive: true });
15765
+ await this.fs.writeFile(GROUP, formatGroup(group));
15766
+ return { name: name2, gid, members: [] };
15767
+ });
15768
+ }
15732
15769
  addMember(group, user) {
15733
15770
  return this.member(group, user, true);
15734
15771
  }
@@ -28304,8 +28341,10 @@ var OpfsFs = class {
28304
28341
  for (let at = from; at < parts2.length; at++) {
28305
28342
  this.calls++;
28306
28343
  dir = await dir.getDirectoryHandle(parts2[at]);
28307
- this.dirs.set(`/${parts2.slice(0, at + 1).join("/")}`, dir);
28344
+ const path = `/${parts2.slice(0, at + 1).join("/")}`;
28345
+ this.dirs.set(path, dir);
28308
28346
  this.checked.set(dir, performance.now());
28347
+ this.absent.delete(path);
28309
28348
  }
28310
28349
  return dir;
28311
28350
  }
@@ -28387,6 +28426,7 @@ var OpfsFs = class {
28387
28426
  if (looked) {
28388
28427
  this.dirs.set(path, handle);
28389
28428
  this.checked.set(handle, performance.now());
28429
+ this.absent.delete(path);
28390
28430
  }
28391
28431
  return handle;
28392
28432
  }
@@ -29037,7 +29077,8 @@ var OpfsFs = class {
29037
29077
  }
29038
29078
  const [entry] = await this.meta.get([path]);
29039
29079
  const wanted = entry?.link === void 0 ? path : resolvePath(parentOf9(path), entry.link);
29040
- return [resolvePath((await this.locate(parentOf9(wanted), true)).path, baseOf3(wanted)), false];
29080
+ const parent = await this.exactly(() => this.locate(parentOf9(wanted), true));
29081
+ return [resolvePath(parent.path, baseOf3(wanted)), false];
29041
29082
  }
29042
29083
  async fileFor(path, create = true) {
29043
29084
  const [target, existed] = await this.writeTarget(path);
@@ -29144,10 +29185,12 @@ var OpfsFs = class {
29144
29185
  await this.mkdir(parentOf9(path), { recursive: true, ...above ? { owner: above } : {} });
29145
29186
  const parent = await this.locate(parentOf9(path), true);
29146
29187
  if (parent.handle?.kind !== "directory") throw fsError("ENOTDIR", path);
29147
- this.refuse(resolvePath(parent.path, baseOf3(path)));
29148
- await this.io(parent.handle.getDirectoryHandle(baseOf3(path), { create: true }));
29188
+ const made2 = resolvePath(parent.path, baseOf3(path));
29189
+ this.forget(made2);
29190
+ this.refuse(made2);
29191
+ const handle = await this.io(parent.handle.getDirectoryHandle(baseOf3(path), { create: true }));
29192
+ this.remember(made2, handle, true);
29149
29193
  const now = Date.now();
29150
- const made2 = `${parent.path === "/" ? "" : parent.path}/${baseOf3(path)}`;
29151
29194
  await this.stampNew(made2, owner, true);
29152
29195
  this.touch(now, parent.path, made2);
29153
29196
  }
@@ -32354,6 +32397,7 @@ var Launcher = class {
32354
32397
  (pid) => this.tagsOf(pid)
32355
32398
  );
32356
32399
  this.embedder = this.embedderBroker(options.embedder);
32400
+ this.embedder.denied = options.onDenial;
32357
32401
  this.sealed = new SealedBroker(
32358
32402
  options.sealed,
32359
32403
  this.usersMode,
@@ -37680,6 +37724,7 @@ async function createNodeKernel(options = {}) {
37680
37724
  },
37681
37725
  groups: {
37682
37726
  list: () => guard2(() => launcher.users.groups()),
37727
+ add: (name2, options2) => guard2(() => launcher.users.addGroup(name2, options2?.gid)),
37683
37728
  addMember: (group, user) => guard2(() => launcher.users.addMember(group, user)),
37684
37729
  removeMember: (group, user) => guard2(() => launcher.users.removeMember(group, user))
37685
37730
  },