ssh-client-wrapper 3.3.0 → 3.3.1
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.
- package/lib/agent.js +2 -2
- package/lib/fork.js +2 -2
- package/lib/util.js +29 -0
- package/package.json +1 -1
package/lib/agent.js
CHANGED
|
@@ -6,7 +6,7 @@ import { promisify } from "node:util";
|
|
|
6
6
|
import { setTimeout as setTimeoutPromise } from "node:timers/promises";
|
|
7
7
|
import Debug from "debug";
|
|
8
8
|
import { spawn } from "node-pty";
|
|
9
|
-
import { rePhPrompt } from "./util.js";
|
|
9
|
+
import { rePhPrompt, resolveExecutable } from "./util.js";
|
|
10
10
|
|
|
11
11
|
const debug = Debug("sshClientWrapper:debug:agent");
|
|
12
12
|
const debugVerbose = Debug("sshClientWrapper:verbose:agent");
|
|
@@ -244,7 +244,7 @@ async function resolvePassphrase(ph) {
|
|
|
244
244
|
*/
|
|
245
245
|
function addKey(sock, keyFile, phCallback, ttl) {
|
|
246
246
|
return new Promise((resolve, reject)=>{
|
|
247
|
-
const pty = _internal.spawn("ssh-add", ["-t", String(ttl), keyFile], {
|
|
247
|
+
const pty = _internal.spawn(resolveExecutable("ssh-add"), ["-t", String(ttl), keyFile], {
|
|
248
248
|
windowsHide: true,
|
|
249
249
|
env: sockEnv(sock)
|
|
250
250
|
});
|
package/lib/fork.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Debug from "debug";
|
|
2
2
|
import { spawn } from "node-pty";
|
|
3
3
|
|
|
4
|
-
import { rePwPrompt, rePhPrompt, reNewHostPrompt, reRemoteHostIdentificationHasChanged, buff2String, sendPty, watchDogTimer } from "./util.js";
|
|
4
|
+
import { resolveExecutable, rePwPrompt, rePhPrompt, reNewHostPrompt, reRemoteHostIdentificationHasChanged, buff2String, sendPty, watchDogTimer } from "./util.js";
|
|
5
5
|
|
|
6
6
|
const debug = Debug("sshClientWrapper:debug:fork");
|
|
7
7
|
const debugVerbose = Debug("sshClientWrapper:verbose:fork");
|
|
@@ -86,7 +86,7 @@ export async function fork(hostInfo, cmd, args, timeout, outputCallback, retryab
|
|
|
86
86
|
return new Promise((resolve, reject)=>{
|
|
87
87
|
debug(`cmd=${cmd}: args=${args}`);
|
|
88
88
|
//node-pty accepts only string arguments (e.g. the port number is a number)
|
|
89
|
-
const ptyProcess = spawn(cmd, args.map(String), nodePtyOpt);
|
|
89
|
+
const ptyProcess = spawn(resolveExecutable(cmd), args.map(String), nodePtyOpt);
|
|
90
90
|
let ac = null;
|
|
91
91
|
if (timeout > 0) {
|
|
92
92
|
ac = watchDogTimer(timeout, cmd, ()=>{
|
package/lib/util.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EOL } from "os";
|
|
2
2
|
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
3
4
|
import Debug from "debug";
|
|
4
5
|
import { setTimeout as setTimeoutPromise } from "timers/promises";
|
|
5
6
|
import Ajv from "ajv";
|
|
@@ -11,6 +12,34 @@ export const sshCmd = "ssh";
|
|
|
11
12
|
export const rsyncCmd = "rsync";
|
|
12
13
|
export const acceptableRsyncRetrunCodes = [10, 11, 12, 13, 14];
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* resolve a command name to the path of the executable file to be spawned in a pty
|
|
17
|
+
* node-pty on Windows does not add an extension (.exe) to the command, and it does not find a command in the last directory of PATH.
|
|
18
|
+
* @param {string} cmd - command name or path
|
|
19
|
+
* @param {object} opt - options (platform, env and isFile are injectable for tests)
|
|
20
|
+
* @param {string} opt.platform - platform name
|
|
21
|
+
* @param {object} opt.env - environment variables
|
|
22
|
+
* @param {Function} opt.isFile - function which checks if given path is a file
|
|
23
|
+
* @returns {string} - full path of the executable on win32 if it is found, otherwise given cmd as it is
|
|
24
|
+
*/
|
|
25
|
+
export const resolveExecutable = (cmd, { platform = process.platform, env = process.env, isFile = (p)=>{ return fs.statSync(p, { throwIfNoEntry: false })?.isFile() === true; } } = {})=>{
|
|
26
|
+
if (platform !== "win32" || /[\\/]/.test(cmd)) {
|
|
27
|
+
return cmd;
|
|
28
|
+
}
|
|
29
|
+
const dirs = (env.Path ?? env.PATH ?? "").split(";").filter(Boolean);
|
|
30
|
+
const names = path.win32.extname(cmd) === "" ? [`${cmd}.exe`] : [cmd];
|
|
31
|
+
for (const dir of dirs) {
|
|
32
|
+
for (const name of names) {
|
|
33
|
+
const candidate = path.win32.join(dir, name);
|
|
34
|
+
if (isFile(candidate)) {
|
|
35
|
+
return candidate;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
debug(`${cmd} not found in PATH`);
|
|
40
|
+
return cmd;
|
|
41
|
+
};
|
|
42
|
+
|
|
14
43
|
export const rePwPrompt = /password:/;
|
|
15
44
|
export const rePhPrompt = /Enter passphrase for key/;
|
|
16
45
|
export const reNewHostPrompt = /Are you sure you want to continue connecting/;
|