Make all groups appear in LDAP, get posix GIDs

This commit is contained in:
2021-03-10 20:12:06 -06:00
parent ef819b0a2e
commit 48f5b3f71a
3 changed files with 22 additions and 31 deletions

View File

@@ -32,21 +32,31 @@ class GroupModel extends Model {
return await User.find({ _id: { $in: this.user_ids.map(x => this.constructor.to_object_id(x)) } })
}
async get_gid_number() {
if ( !this.posix_group_id ) {
const Setting = this.models.get('Setting')
let last_uid = await Setting.get('ldap.last_alloc_uid')
if ( last_uid < 1 ) {
last_uid = this.configs.get('ldap:server.schema.start_uid')
}
this.posix_group_id = last_uid + 1
await Setting.set('ldap.last_alloc_uid', this.posix_group_id)
await this.save()
}
return this.posix_group_id
}
async to_ldap() {
const users = await this.users()
const data = {
return {
cn: this.name,
dn: this.dn.format(this.configs.get('ldap:server.format')),
objectClass: ['groupOfNames'],
objectClass: ['groupOfNames', 'posixGroup'],
gidNumber: await this.get_gid_number(),
member: users.map(x => x.dn.format(this.configs.get('ldap:server.format'))),
}
if ( this.posix_group_id ) {
data.objectClass.push('posixGroup')
data.gidNumber = String(this.posix_group_id)
}
return data
}
static async ldap_directory() {