Make all groups appear in LDAP, get posix GIDs
This commit is contained in:
parent
ef819b0a2e
commit
48f5b3f71a
@ -260,18 +260,8 @@ class AuthController extends Controller {
|
||||
group.user_ids = user_ids
|
||||
}
|
||||
|
||||
if ( group.grants_sudo ) {
|
||||
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')
|
||||
}
|
||||
|
||||
group.posix_group_id = last_uid + 1
|
||||
await Setting.set('ldap.last_alloc_uid', group.posix_group_id)
|
||||
}
|
||||
|
||||
await group.save()
|
||||
await group.get_gid_number()
|
||||
return res.api(await group.to_api())
|
||||
}
|
||||
|
||||
@ -381,18 +371,8 @@ class AuthController extends Controller {
|
||||
group.name = req.body.name
|
||||
group.grants_sudo = !!req.body.grants_sudo
|
||||
|
||||
if ( group.grants_sudo && !group.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')
|
||||
}
|
||||
|
||||
group.posix_group_id = last_uid + 1
|
||||
await Setting.set('ldap.last_alloc_uid', group.posix_group_id)
|
||||
}
|
||||
|
||||
await group.save()
|
||||
await group.get_gid_number()
|
||||
return res.api()
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
const LDAPController = require('./LDAPController')
|
||||
const LDAP = require('ldapjs')
|
||||
|
||||
class GroupsController extends LDAPController {
|
||||
static get services() {
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user