From 64539a4a0d1c24bfe631a7dd6a64b98ac9a14bba Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 17:57:51 +0200 Subject: [PATCH] refs #5770 updates with real environment --- modules/account/back/models/samba-config.js | 24 +++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/account/back/models/samba-config.js b/modules/account/back/models/samba-config.js index c1643ae30..2035cd0d4 100644 --- a/modules/account/back/models/samba-config.js +++ b/modules/account/back/models/samba-config.js @@ -1,8 +1,9 @@ const app = require('vn-loopback/server/server'); const ldap = require('../util/ldapjs-extra'); const { differences, handleExecResponse, toMap } = require('../util/helpers'); +const { stdout } = require('process'); const execFile = require('child_process').execFile; - +const ROLE_PREFIX = 'VN_'; /** * Summary of userAccountControl flags: * https://docs.microsoft.com/en-us/troubleshoot/windows-server/identity/useraccountcontrol-manipulate-account-properties @@ -187,10 +188,10 @@ module.exports = Self => { order: 'modified DESC', limit: 1 })); - let rolesMap = roles.map(role => role.name); + let rolesMap = roles;//.map(({id, name, description}) => ({id, name, description})); // OBTENER SAMBA ROLES - let sambaCurrentRoles = handleExecResponse(await this.sambaTool('group', ['list'])); + let sambaCurrentRoles = handleExecResponse(await this.sambaTool('group', ['list'])).filter(group => group.startsWith(ROLE_PREFIX)); // Encontrar elementos a eliminar const rolesToDelete = differences(sambaCurrentRoles, rolesMap); @@ -248,15 +249,26 @@ module.exports = Self => { if (rolesToInsert.length > 0) { // PROCEDIMIENTO PARA INSERTAR ROLES const resultsRoleInsert = await Promise.all( - rolesToInsert.map(role => this.sambaTool('group', ['add', role])) + rolesToInsert.map(({id, description,name}) => this.sambaTool('group', ['add', `${ROLE_PREFIX}${name}`, `--description="${description}"`])) ); + resultsRoleInsert.forEach(({stdout}) => console.log(stdout)); // PROCEDIMIENTO PARA INSERTAR USUARIOS ASOCIADOS AL ROL - let usersToInsert = rolesToInsert.flatMap(role => usersMap.get(role).map( - a => this.sambaTool('group', ['addmembers', role, a]) + let usersToInsert = rolesToInsert.flatMap(role => usersMap.get(role.name).map( + a => this.sambaTool('user', ['add', a, + '--random-password', '--must-change-at-next-login']) ) ); const resultsUserInsert = await Promise.all(usersToInsert); + resultsUserInsert.forEach(({stdout}) => console.log(stdout)); + + // PROCEDIMIENTO PARA INSERTAR USUARIOS ASOCIADOS AL ROL + let usersToGroup = rolesToInsert.flatMap(role => usersMap.get(role).map( + a => this.sambaTool('group', ['addmembers', `${ROLE_PREFIX}${role}`, a]) + ) + ); + const resultsUserGroup = await Promise.all(usersToGroup); + resultsUserGroup.forEach(({stdout}) => console.log(stdout)); } if (rolesToUpdate.length > 0) {