NOT TESTED
add a group entry

@param string $group_dn as ldap dn
@param array $attributes in key value form
$attributes = array(
"attribute1" = "value",
"attribute2" = array("value1", "value2"),
)
@return boolean success
420544
public function groupAddGroup($group_dn, $attributes = array()) {

    //debug("this->dnExists(   $group_dn, boolean)"); debug($this->dnExists($group_dn, 'boolean'));
   // debug("this->dnExists(   $group_dn, boolean)"); debug($this->dnExists($group_dn));
    if ($this->dnExists($group_dn, 'boolean')) {
      return FALSE;
    }

    $attributes = array_change_key_case($attributes, CASE_LOWER);
    $objectclass = (empty($attributes['objectclass'])) ? $this->groupObjectClass : $attributes['objectclass'];
    $attributes['objectclass'] = $objectclass;

    /**
     * 2. give other modules a chance to add or alter attributes
     */
    $context = array(
      'action' => 'add',
      'corresponding_drupal_data' => array($group_dn => $attributes),
      'corresponding_drupal_data_type' => 'group',
    );
    $ldap_entries = array($group_dn => $attributes);
    drupal_alter('ldap_entry_pre_provision', $ldap_entries, $this, $context);
    $attributes = $ldap_entries[$group_dn];


     /**
     * 4. provision ldap entry
     *   @todo how is error handling done here?
     */
    $ldap_entry_created = $this->createLdapEntry($attributes, $group_dn);


     /**
     * 5. allow other modules to react to provisioned ldap entry
     *   @todo how is error handling done here?
     */
    if ($ldap_entry_created) {
      module_invoke_all('ldap_entry_post_provision', $ldap_entries, $this, $context);
      return TRUE;
    }
    else {
      return FALSE;
    }

  }
584616
@Override
    public boolean setGroup(Node node) throws Exception {
        LdapGroup newLdapGroup = (LdapGroup) node;
        newLdapGroup = updateGroupMembers(newLdapGroup);
        LdapGroup oldLdapGroup = (LdapGroup) getGroup(newLdapGroup.getCn());
        if (oldLdapGroup.isEmpty()) {
            creationCount++;
            Logger.info(LOG_BIND + getOuForNode(newLdapGroup));
            ctx.bind(getOuForNode(newLdapGroup), null, newLdapGroup.getAttributes());
            return true;
        } else {
            ModificationItem[] mods = buildModificationsForGroup(newLdapGroup, oldLdapGroup);
            if (mods.length > 0) {
                modificationCount++;
                Logger.info(LOG_MODIFY_ATTRIBUTES + getOuForNode(newLdapGroup));
                ctx.modifyAttributes(getOuForNode(newLdapGroup), mods);
                return true;
            }
        }
        return false;
    }
51750
public function modify($dn, $attribute)
	{
		if (!$this->isBound || !$this->isConnected())
		{
			return false;
		}

		return ldap_modify($this->resource, $dn, $attribute);
	}
22891
public function addOptgroup($label, $attributes = null)
    {
        $optgroup = new HTML_QuickForm2_Element_Select_Optgroup(
                            $this->values, $this->possibleValues,
                            $label, $attributes
                        );
        $this->options[] = $optgroup;
        return $optgroup;
    }
1244115
public function group(array $attributes = [])
    {
        $model = $this->schema->groupModel();

        return (new $model($attributes, $this->query))
            ->setAttribute($this->schema->objectClass(), [
                $this->schema->top(),
                $this->schema->objectCategoryGroup(),
            ]);
    }
812318
public function setRawAttributes(array $attributes = [])
    {
        // We'll filter out those annoying 'count' keys returned with LDAP results,
        // and lowercase all root array keys to prevent any casing issues.
        $this->attributes = array_change_key_case($this->filterRawAttributes($attributes), CASE_LOWER);

        // We'll pull out the distinguished name from our raw attributes
        // and set it into our attributes array with the full attribute
        // definition. This allows us to normalize distinguished
        // names across different LDAP variants.
        if ($dn = Arr::get($attributes, 'dn')) {
            // In some LDAP variants, the distinguished
            // name is returned as an array.
            if (is_array($dn)) {
                $dn = Arr::first($dn);
            }

            $this->setDistinguishedName($dn);
        }

        $this->syncOriginal();

        // Set exists to true since raw attributes are only
        // set in the case of attributes being loaded by
        // query results.
        $this->exists = true;

        return $this;
    }
307748
public function addLDAPUserToGroup($userDn, $groupDn)
    {
        $members = $this->getLDAPGroupMembers($groupDn);

        // this user is already in the group, no need to do anything.
        if (in_array($userDn, $members)) {
            return;
        }

        $members[] = $userDn;

        try {
            $this->update($groupDn, ['member' => $members]);
        } catch (Exception $e) {
            throw new ValidationException('LDAP group membership add failure: ' . $e->getMessage());
        }
    }
207471
public function mod_add($dn, $entry)
    {
        $this->_debug("C: Add $dn: ".print_r($entry, true));

        if (!ldap_mod_add($this->conn, $dn, $entry)) {
            $this->_error("ldap_mod_add() failed with " . ldap_error($this->conn));
            return false;
        }

        $this->_debug("S: OK");
        return true;
    }
929050
public function group(array $attributes, Closure $callback)
    {
        $previousGroupAttributes = $this->groupAttributes;
        $this->groupAttributes = array_merge_recursive($previousGroupAttributes, $attributes);

        \call_user_func($callback, $this);

        $this->groupAttributes = $previousGroupAttributes;
    }
227487
public function create(array $attributes)
    {
        $user = new User($attributes);

        if ($user->hasAttribute('password') && !$this->connection->canChangePasswords()) {
            throw new AdldapException('SSL must be configured on your web server and enabled in the class to set passwords.');
        }

        // Translate the schema
        $add = $this->adldap->ldapSchema($user->toCreateSchema());

        // Additional stuff only used for adding accounts
        $add['cn'][0] = $user->getAttribute('display_name');
        $add[$this->adldap->getUserIdKey()][0] = $user->getAttribute('username');
        $add['objectclass'][0] = 'top';
        $add['objectclass'][1] = 'person';
        $add['objectclass'][2] = 'organizationalPerson';
        $add['objectclass'][3] = 'user';

        // Set the account control attribute
        $controlOptions = ['NORMAL_ACCOUNT' => true];

        if (!$user->hasAttribute('enabled')) {
            $controlOptions['ACCOUNTDISABLE'] = true;
        }

        $add['userAccountControl'][0] = $this->accountControl($controlOptions);

        // Determine the container
        $attributes['container'] = array_reverse($user->getAttribute('container'));

        $container = 'OU='.implode(',OU=', $user->getAttribute('container'));

        $dn = 'CN='.$add['cn'][0].','.$container.','.$this->adldap->getBaseDn();

        // Add the entry
        return $this->connection->add($dn, $add);
    }
32757
public function group(array $attributes, $routes)
    {
        $this->updateGroupStack($attributes);

        // Once we have updated the group stack, we'll load the provided routes and
        // merge in the group's attributes when the routes are created. After we
        // have created the routes, we will pop the attributes off the stack.
        $this->loadRoutes($routes);

        array_pop($this->groupStack);
    }
1009601
function group_info($group_name,$fields=NULL){
        if ($group_name==NULL){ return (false); }
        if (!$this->_bind){ return (false); }
        
        $filter="(&(objectCategory=group)(".$this->_group_cn_identifier."=".$this->ldap_search_encode($group_name)."))";

        if ($fields==NULL){ $fields=array("member",$this->_group_attribute,"cn","description","distinguishedname","objectcategory",$this->_group_cn_identifier); }
        
        $sr=@ldap_search($this->_conn,$this->_base_dn,$filter,$fields);
        if (FALSE === $sr) {
            $this->_warning_message = "group_info: ldap_search error ".ldap_errno($this->_conn).": ".ldap_error($this->_conn);
            echo "DEBUG: ".$this->_warning_message."\n";
        }
        // Search: (&(objectCategory=group)(cn=gr10000))
        // (&(objectCategory=group)(cn=gr10))
        // PHP Warning:  ldap_search(): Search: Critical extension is unavailable in // C:\data\projects\multiotp\core\contrib\MultiotpAdLdap.php on line 591
        // Search: (&(objectCategory=group)(cn=gr10))
        $entries = $this->ldap_get_entries_raw($sr);

        // DEBUG
        if (0 == count($entries)) {
            $this->_warning_message = "group_info: No entry for the specified filter $filter";
            echo "DEBUG: ".$this->_warning_message."\n";
        }

        return ($entries);
    }
74039
public function addAttributes($attributes, $html = [])
    {
        if (!empty($attributes)) {
            foreach ($attributes as $key => $value) {
                if (!is_null($value)) {
                    $html[] = $key.'="'.Html::entities($value).'"';
                }
            }
        }

        return (count($html) > 0) ? ' '.implode(' ', $html) : '';
    }
770917
public function addGroup($groupName)
    {
        if (true === is_string($groupName) && false === in_array($groupName, $this->groups)) {
            $this->groups[] = $groupName;
        }
        return $this;
    }
454357
public function addContact($groupName, $contactDn)
    {
        $groupDn = $this->dn($groupName);

        if ($groupDn && $contactDn) {
            $add = [];
            $add['member'] = $contactDn;

            return $this->connection->modAdd($groupDn, $add);
        }

        return false;
    }
1053214
public function dnStrToArr($dnStr, $excludeBaseDn = true, $includeAttributes = false)
    {
        if ($excludeBaseDn) {
            return ldap_explode_dn($dnStr, ($includeAttributes ? 0 : 1));
        } else {
            return ldap_explode_dn($this->adldap->getBaseDn().$dnStr, ($includeAttributes ? 0 : 1));
        }
    }
163274
protected function updateGroupStack(array $attributes = [])
    {
        if (count($this->groupStack) > 0) {
            $attributes = $this->mergeWithLastGroup($attributes);
        }

        $this->groupStack[] = $attributes;
    }