cifs: use credentials file
this supports special characters in passwords better https://forum.cloudron.io/topic/6577/failed-to-mount-inactive-mount-error-13-when-mounting-cifs-from-synology
This commit is contained in:
+13
-3
@@ -87,11 +87,17 @@ function renderMountFile(mount) {
|
||||
|
||||
let options, what, type;
|
||||
switch (mountType) {
|
||||
case 'cifs':
|
||||
case 'cifs': {
|
||||
const out = safe.child_process.execSync(`systemd-escape -p '${hostPath}'`, { encoding: 'utf8' }); // this ensures uniqueness of creds file
|
||||
if (!out) throw new BoxError(BoxError.FS_ERROR, `Could not determine credentials file name: ${safe.error.message}`);
|
||||
const credentialsFilePath = path.join(paths.CIFS_CREDENTIALS_DIR, `${out.trim()}.cred`);
|
||||
if (!safe.fs.writeFileSync(credentialsFilePath, `username=${mountOptions.username}\npassword=${mountOptions.password}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write credentials file: ${safe.error.message}`);
|
||||
|
||||
type = 'cifs';
|
||||
what = `//${mountOptions.host}` + path.join('/', mountOptions.remoteDir);
|
||||
options = `username=${mountOptions.username},password=${mountOptions.password},rw,${mountOptions.seal ? 'seal,' : ''}iocharset=utf8,file_mode=0666,dir_mode=0777,uid=yellowtent,gid=yellowtent`;
|
||||
options = `credentials=${credentialsFilePath},rw,${mountOptions.seal ? 'seal,' : ''}iocharset=utf8,file_mode=0666,dir_mode=0777,uid=yellowtent,gid=yellowtent`;
|
||||
break;
|
||||
}
|
||||
case 'nfs':
|
||||
type = 'nfs';
|
||||
what = `${mountOptions.host}:${mountOptions.remoteDir}`;
|
||||
@@ -104,7 +110,6 @@ function renderMountFile(mount) {
|
||||
break;
|
||||
case 'sshfs': {
|
||||
const keyFilePath = path.join(paths.SSHFS_KEYS_DIR, `id_rsa_${mountOptions.host}`);
|
||||
|
||||
if (!safe.fs.writeFileSync(keyFilePath, `${mount.mountOptions.privateKey}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write private key: ${safe.error.message}`);
|
||||
|
||||
type = 'fuse.sshfs';
|
||||
@@ -132,6 +137,11 @@ async function removeMount(mount) {
|
||||
if (mountType === 'sshfs') {
|
||||
const keyFilePath = path.join(paths.SSHFS_KEYS_DIR, `id_rsa_${mountOptions.host}`);
|
||||
safe.fs.unlinkSync(keyFilePath);
|
||||
} else if (mountType === 'cifs') {
|
||||
const out = safe.child_process.execSync(`systemd-escape -p '${hostPath}'`, { encoding: 'utf8' });
|
||||
if (!out) return;
|
||||
const credentialsFilePath = path.join(paths.CIFS_CREDENTIALS_DIR, `${out.trim()}.cred`);
|
||||
safe.fs.unlinkSync(credentialsFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user