@phren/cli 0.3.77 → 0.3.78

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.
@@ -101,6 +101,9 @@ export interface ProcessRecord {
101
101
  }
102
102
  /** One process's parent, effective uid, name and arguments. */
103
103
  export declare function readProcess(pid: number): Promise<ProcessRecord | undefined>;
104
+ /** Linux: whether any process of the owner's other than `exclude` holds a
105
+ * descriptor that links to `target` (`pipe:[n]`, `socket:[n]`). */
106
+ export declare function heldElsewhere(target: string, exclude: number[]): Promise<boolean>;
104
107
  /** Whether `pid`'s stdout is a pipe that no process of the owner's other than
105
108
  * `allowed` holds. sudo, running as root, is never visible here. */
106
109
  export declare function stdoutReaders(pid: number, allowed: number[]): Promise<"sudo" | "other" | "unknown">;
@@ -145,6 +148,8 @@ export interface AskerCheck {
145
148
  script: string;
146
149
  unprivilegedSudo?: boolean;
147
150
  }
151
+ /** What would run other code in the shell script (which drops the rest) or in node. */
152
+ export declare const PRELOADS: string[], NODE_LOADERS: string[];
148
153
  /** The chain from askpass up to sudo, or why it is refused. */
149
154
  export declare function verifyAsker(pid: number, check: AskerCheck): Promise<{
150
155
  sudo: ProcessRecord;
@@ -178,6 +183,12 @@ export interface SudoBrokerOptions {
178
183
  account?: string;
179
184
  now?: () => number;
180
185
  }
186
+ export declare function placeFrom(value: unknown): {
187
+ server: string;
188
+ workspace: string;
189
+ tab: string;
190
+ pane: string;
191
+ } | undefined;
181
192
  export interface Verified {
182
193
  sudo: ProcessRecord;
183
194
  sudoPid: number;
@@ -217,6 +228,7 @@ export declare class SudoBroker {
217
228
  /** The agent.sock `/sudo` route. */
218
229
  handle(req: IncomingMessage, res: ServerResponse): Promise<void>;
219
230
  }
231
+ export declare function userName(): string | undefined;
220
232
  /** A password as sudo reads it from askpass: one line, nothing it would cut. */
221
233
  export declare function sudoAnswer(data: Json): {
222
234
  id: string;
@@ -233,6 +245,15 @@ export declare class SudoAnswerError extends Error {
233
245
  /** The bundle's `askpass` command, run by sudo through `<bridge>/askpass`.
234
246
  * Prints the password and exits 0, or explains on stderr and exits 1. */
235
247
  export declare function askpass(prompt: string | undefined, env?: NodeJS.ProcessEnv): Promise<number>;
248
+ export interface DeliveryListener {
249
+ delivery: AskpassDelivery;
250
+ printed: () => boolean;
251
+ close: () => void;
252
+ }
253
+ /** An abstract socket that takes one password from a connection that sends
254
+ * the nonce first, prints it to stdout, and acknowledges. Any other
255
+ * connection is dropped without an answer. */
256
+ export declare function deliveryListener(take?: (secret: string) => void): Promise<DeliveryListener>;
236
257
  /** `phren sudo <command...>`: `sudo -A` with this Hook's askpass, so the
237
258
  * password comes from the phone even with no terminal (a `!` command, an
238
259
  * agent's shell). Exits with sudo's status. */
@@ -152,7 +152,7 @@ export async function readProcess(pid) {
152
152
  }
153
153
  /** Linux: whether any process of the owner's other than `exclude` holds a
154
154
  * descriptor that links to `target` (`pipe:[n]`, `socket:[n]`). */
155
- async function heldElsewhere(target, exclude) {
155
+ export async function heldElsewhere(target, exclude) {
156
156
  const holders = (await readdir("/proc")).map(Number).filter(holder => Number.isInteger(holder) && !exclude.includes(holder));
157
157
  let next = 0, other = false;
158
158
  // Busy machines can have thousands of descriptors. Bound the process
@@ -329,7 +329,7 @@ async function writeToAsker(pid, start, password) {
329
329
  }
330
330
  }
331
331
  /** What would run other code in the shell script (which drops the rest) or in node. */
332
- const PRELOADS = ["LD_PRELOAD", "DYLD_INSERT_LIBRARIES"], NODE_LOADERS = [...PRELOADS, "NODE_OPTIONS"];
332
+ export const PRELOADS = ["LD_PRELOAD", "DYLD_INSERT_LIBRARIES"], NODE_LOADERS = [...PRELOADS, "NODE_OPTIONS"];
333
333
  /** The chain from askpass up to sudo, or why it is refused. */
334
334
  export async function verifyAsker(pid, check) {
335
335
  const asker = await check.processes(pid);
@@ -356,7 +356,7 @@ export async function verifyAsker(pid, check) {
356
356
  return { sudo, sudoPid: script.ppid };
357
357
  }
358
358
  const placeName = /^[A-Za-z0-9_.:%@-]{1,128}$/;
359
- function placeFrom(value) {
359
+ export function placeFrom(value) {
360
360
  const item = object(value);
361
361
  const fields = ["server", "workspace", "tab", "pane"];
362
362
  if (!fields.every(key => typeof item[key] === "string" && placeName.test(item[key])))
@@ -542,7 +542,7 @@ export class SudoBroker {
542
542
  held.cancel();
543
543
  }
544
544
  }
545
- function userName() { try {
545
+ export function userName() { try {
546
546
  return userInfo().username || undefined;
547
547
  }
548
548
  catch {
@@ -591,7 +591,7 @@ export async function askpass(prompt, env = process.env) {
591
591
  /** An abstract socket that takes one password from a connection that sends
592
592
  * the nonce first, prints it to stdout, and acknowledges. Any other
593
593
  * connection is dropped without an answer. */
594
- function deliveryListener() {
594
+ export function deliveryListener(take = secret => { process.stdout.write(`${secret}\n`); }) {
595
595
  const delivery = newDelivery(), expected = Buffer.from(delivery.nonce);
596
596
  let printed = false;
597
597
  const server = createServer(socket => {
@@ -617,7 +617,7 @@ function deliveryListener() {
617
617
  return;
618
618
  }
619
619
  printed = true;
620
- process.stdout.write(`${lines[1]}\n`);
620
+ take(lines[1]);
621
621
  text = "";
622
622
  socket.end("ok\n");
623
623
  server.close();