Example #1
0
// Delete an item
func (c *Manager) Delete(item Item) error {
	deleteRequest := ldap.NewDeleteRequest(c.appendBaseDn(item.Dn()))

	if c.Debug {
		log.Println("Delete Request:", deleteRequest)
	}

	return c.conn.Delete(deleteRequest)
}
Example #2
0
// Helper method to recursively delete a subtree
func (c *Manager) deleteRecursive(dn string) error {
	// first recursively delete all subentrys
	searchRequest := ldap.NewSimpleSearchRequest(dn, ldap.ScopeSingleLevel, "(objectClass=*)", nil)

	if c.Debug {
		log.Println("Search Request:", searchRequest)
	}

	results, err := c.conn.Search(searchRequest)
	if err != nil {
		return err
	}

	for _, v := range results.Entries {
		err = c.deleteRecursive(v.DN)
		if err != nil {
			return err
		}
	}

	// delete the root of the current tree
	deleteRequest := ldap.NewDeleteRequest(dn)
	return c.conn.Delete(deleteRequest)
}