From 116cf60655936f3ae64fe33843d94c0f26793a7c Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Sun, 17 Dec 2017 21:24:17 +0100 Subject: [PATCH] Replace getgid and getfreegid by class method --- htdocs/lib/class.ldapdomain.php | 11 ++++++++--- htdocs/lib/class.ldapserver.php | 13 ++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/htdocs/lib/class.ldapdomain.php b/htdocs/lib/class.ldapdomain.php index 4fc28f6..2561c48 100644 --- a/htdocs/lib/class.ldapdomain.php +++ b/htdocs/lib/class.ldapdomain.php @@ -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; } diff --git a/htdocs/lib/class.ldapserver.php b/htdocs/lib/class.ldapserver.php index a2431e8..b725482 100644 --- a/htdocs/lib/class.ldapserver.php +++ b/htdocs/lib/class.ldapserver.php @@ -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; }