Merge branch 'dev' into 4159-tableQ_filter
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-11-03 07:43:14 +00:00
commit 12df808844
2 changed files with 26 additions and 14 deletions

View File

@ -5,6 +5,8 @@ const crypto = require('crypto');
const nthash = require('smbhash').nthash; const nthash = require('smbhash').nthash;
module.exports = Self => { module.exports = Self => {
const shouldSync = process.env.NODE_ENV !== 'test';
Self.getSynchronizer = async function() { Self.getSynchronizer = async function() {
return await Self.findOne({ return await Self.findOne({
fields: [ fields: [
@ -30,6 +32,7 @@ module.exports = Self => {
}, },
async syncUser(userName, info, password) { async syncUser(userName, info, password) {
let { let {
client, client,
accountConfig accountConfig
@ -130,12 +133,13 @@ module.exports = Self => {
})); }));
} }
if (changes.length) if (shouldSync && changes.length)
await client.modify(dn, changes); await client.modify(dn, changes);
} else } else if (shouldSync)
await client.add(dn, newEntry); await client.add(dn, newEntry);
} else { } else {
try { try {
if (shouldSync)
await client.del(dn); await client.del(dn);
console.log(` -> User '${userName}' removed from LDAP`); console.log(` -> User '${userName}' removed from LDAP`);
} catch (e) { } catch (e) {
@ -196,10 +200,12 @@ module.exports = Self => {
for (let group of groups) { for (let group of groups) {
try { try {
let dn = `cn=${group},${groupDn}`; let dn = `cn=${group},${groupDn}`;
if (shouldSync) {
await client.modify(dn, new ldap.Change({ await client.modify(dn, new ldap.Change({
operation, operation,
modification: {memberUid: userName} modification: {memberUid: userName}
})); }));
}
} catch (err) { } catch (err) {
if (err.name !== 'NoSuchObjectError') if (err.name !== 'NoSuchObjectError')
throw err; throw err;
@ -266,8 +272,10 @@ module.exports = Self => {
filter: 'objectClass=posixGroup' filter: 'objectClass=posixGroup'
}; };
let reqs = []; let reqs = [];
await client.searchForeach(this.groupDn, opts, await client.searchForeach(this.groupDn, opts, object => {
o => reqs.push(client.del(o.dn))); if (shouldSync)
reqs.push(client.del(object.dn));
});
await Promise.all(reqs); await Promise.all(reqs);
// Recreate roles // Recreate roles
@ -291,6 +299,7 @@ module.exports = Self => {
} }
let dn = `cn=${role.name},${this.groupDn}`; let dn = `cn=${role.name},${this.groupDn}`;
if (shouldSync)
reqs.push(client.add(dn, newEntry)); reqs.push(client.add(dn, newEntry));
} }
await Promise.all(reqs); await Promise.all(reqs);

View File

@ -71,6 +71,9 @@ module.exports = Self => {
let isEnabled = sambaUser let isEnabled = sambaUser
&& !(sambaUser.userAccountControl & UserAccountControlFlags.ACCOUNTDISABLE); && !(sambaUser.userAccountControl & UserAccountControlFlags.ACCOUNTDISABLE);
if (process.env.NODE_ENV === 'test')
return;
if (info.hasAccount) { if (info.hasAccount) {
if (!sambaUser) { if (!sambaUser) {
await sshClient.exec('samba-tool user create', [ await sshClient.exec('samba-tool user create', [