From c68c11b63894711cfd5de6436c68665cf2fdc0e6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 20 May 2024 23:26:23 +0200 Subject: [PATCH] feat(salix): refs #5770 move samTool to sambaHelper --- modules/account/back/models/samba-config.js | 29 ++------------------- modules/account/back/models/samba-helper.js | 29 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/modules/account/back/models/samba-config.js b/modules/account/back/models/samba-config.js index 70ea3fb15..5b1999e71 100644 --- a/modules/account/back/models/samba-config.js +++ b/modules/account/back/models/samba-config.js @@ -13,7 +13,6 @@ const UserAccountControlFlags = { module.exports = Self => { const shouldSync = process.env.NODE_ENV !== 'test'; - let sambaHandler = null; Self.getLinker = async function() { return await Self.findOne({ @@ -57,30 +56,6 @@ module.exports = Self => { await this.adClient.unbind(); }, - async sambaTool(command, args = []) { - let authArgs = [ - '--URL', `ldaps://${this.adController}`, - '--simple-bind-dn', this.bindDn, - '--password', this.adPassword - ]; - if (!this.verifyCert) - authArgs.push('--option', 'tls verify peer = no_check'); - - const allArgs = [command].concat( - args, authArgs - ); - - if (!shouldSync) return; - return await new Promise((resolve, reject) => { - execFile('samba-tool', allArgs, (err, stdout, stderr) => { - if (err) - reject(err); - else - resolve({stdout, stderr}); - }); - }); - }, - async getAdUser(userName) { const sambaUser = await this.adClient.searchOne(this.fullUsersDn, { scope: 'sub', @@ -108,7 +83,7 @@ module.exports = Self => { if (info.hasAccount) { if (!sambaUser) { - await this.sambaTool('user', [ + await this.sambaHandler.sambaTool('user', [ 'create', userName, '--userou', this.userDn, '--random-password' @@ -116,7 +91,7 @@ module.exports = Self => { sambaUser = await this.getAdUser(userName); } if (password) { - await this.sambaTool('user', [ + await this.sambaHandler.sambaTool('user', [ 'setpassword', userName, '--newpassword', password ]); diff --git a/modules/account/back/models/samba-helper.js b/modules/account/back/models/samba-helper.js index 36789c0c2..713ed71c7 100644 --- a/modules/account/back/models/samba-helper.js +++ b/modules/account/back/models/samba-helper.js @@ -6,9 +6,34 @@ const app = require('vn-loopback/server/server'); module.exports = class SambaHelper { constructor(ctx) { - const {sambaTool, verifyCert, adPassword, adController, groupDn, userDn} = ctx; - Object.assign(this, {...ctx, verifyCert, adPassword, adController, groupDn, userDn, sambaTool}); + const {verifyCert, adPassword, adController, groupDn, userDn} = ctx; + Object.assign(this, {...ctx, verifyCert, adPassword, adController, groupDn, userDn}); } + + async sambaTool(command, args = []) { + let authArgs = [ + '--URL', `ldaps://${this.adController}`, + '--simple-bind-dn', this.bindDn, + '--password', this.adPassword + ]; + if (!this.verifyCert) + authArgs.push('--option', 'tls verify peer = no_check'); + + const allArgs = [command].concat( + args, authArgs + ); + + if (!shouldSync) return; + return await new Promise((resolve, reject) => { + execFile('samba-tool', allArgs, (err, stdout, stderr) => { + if (err) + reject(err); + else + resolve({stdout, stderr}); + }); + }); + } + async getRoles() { this.roles = (await app.models.VnRole.find({ fields: ['id', 'name', 'description'],