Replace getgid and getfreegid by class method

This commit is contained in:
Victor LABORIE 2017-12-17 21:24:17 +01:00
parent c335ab2f27
commit 116cf60655
2 changed files with 20 additions and 4 deletions

View file

@ -5,7 +5,7 @@ class LdapDomain extends LdapServer {
static $dn='cn';
protected $domain,$active=false,$server;
private $quota="0M/0M",$mail_accounts=array(),$mail_alias=array(),$posix_accounts=array(),$smb_accounts=array(),$accounts=array(),$alias=array();
private $gid,$quota="0M/0M",$mail_accounts=array(),$mail_alias=array(),$posix_accounts=array(),$smb_accounts=array(),$accounts=array(),$alias=array();
public function __construct(LdapServer $server, $name) {
$this->server = $server;
@ -19,6 +19,7 @@ class LdapDomain extends LdapServer {
if (!empty($object['objectclass'])) {
if (in_array(self::$objectClass[0], $object['objectclass'])) {
$this->active = ($object['isactive'][0] == "TRUE") ? true : false;
$this->gid = $object['gidnumber'][0];
}
if (in_array("posixAccount",$object['objectclass'])) {
array_push($this->posix_accounts,$object['uid'][0]);
@ -77,8 +78,8 @@ class LdapDomain extends LdapServer {
$info[LdapAccount::$dn] = $mail;
$info["cn"] = $name;
$info["homeDirectory"] = "/home/vmail/" .$this->getName(). "/" .$uid. "/";
$info["uidNumber"]= $conf['unix']['uid'];
$info["gidNumber"]= getgid($this->getName());
$info["uidNumber"] = $conf['unix']['uid'];
$info["gidNumber"] = $this->getGid();
$info["isActive"] = ($active) ? 'TRUE' : 'FALSE';
$info["isAdmin"] = ($admin) ? 'TRUE' : 'FALSE';
$info["objectclass"] = LdapAccount::$objectClass;
@ -153,6 +154,10 @@ class LdapDomain extends LdapServer {
return $this->domain;
}
public function getGid() {
return $this->gid;
}
public function isActive() {
return $this->active;
}

View file

@ -102,7 +102,7 @@ class LdapServer {
$info[LdapDomain::$dn]=$name;
$info["objectclass"] = LdapDomain::$objectClass;
$info["isActive"] = ($active) ? 'TRUE' : 'FALSE';
$info["gidNumber"]= getfreegid();
$info["gidNumber"] = $this->getFree('gidnumber');
if (!@ldap_add($this->conn, LdapDomain::getBaseDN($this, $name), $info)) {
$error = ldap_error($this->conn);
@ -131,6 +131,17 @@ class LdapServer {
}
}
protected function getFree($type) {
$sr = ldap_search($this->conn, self::getBaseDN($this), '('.$type.'=*)');
$info = ldap_get_entries($this->conn, $sr);
$id = 1;
foreach ($info as $entry) {
$id = ($entry[$type][0] >= $id) ? (int) $entry[$type][0] : $id;
}
$id++;
return $id;
}
public function isSuperAdmin() {
return $this->superadmin;
}