Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the correct way to delete a non-leaf node #407

Open
aesoper101 opened this issue Dec 27, 2022 · 4 comments
Open

What is the correct way to delete a non-leaf node #407

aesoper101 opened this issue Dec 27, 2022 · 4 comments

Comments

@aesoper101
Copy link

aesoper101 commented Dec 27, 2022

Hi, I have a non-leaf node in OpenLDAP directory. I want to delete the node. One approach is to delete all the children from the bottom most level in the tree and then finally delete the non-leaf node. Is there any other approach to solve this issue?

When I try to delete the non-leaf node, sends me the following exception:

LDAP Result Code 66 "Not Allowed On Non Leaf": subordinate objects must be deleted first

@cpuschma
Copy link
Member

cpuschma commented Dec 27, 2022

You'll have to empty the container first before you can delete it. You can also use the Subtree Delete Control within your delete request to delete all child elements.

ldap/control.go

Lines 533 to 535 in 7d3b8d4

func NewControlSubtreeDelete() *ControlSubtreeDelete {
return &ControlSubtreeDelete{}
}

@aesoper101
Copy link
Author

@cpuschma Hi , I had use the Subtree Delete Control like this

func TestDeleteNonLeafNode(t *testing.T) {
	conn, err := ldap.DialURL("ldap://localhost:389")
	assert.Nil(t, err)
	assert.NotNil(t, conn)

	defer conn.Close()

	control := make([]ldap.Control, 0)
	control = append(control, ldap.NewControlSubtreeDelete())

	simpleBindRequest := ldap.NewSimpleBindRequest("cn=admin,dc=example,dc=org", "admin", control)

	_, err = conn.SimpleBind(simpleBindRequest)
	assert.Nil(t, err)

	delReq := ldap.NewDelRequest("o=test,dc=example,dc=org", control)
	err = conn.Del(delReq)
	t.Log(err)
	assert.Nil(t, err)
}

but not working

@james-d-elliott
Copy link
Contributor

Can you show the ldap.Error field values?

@kumo-rn5s
Copy link

Hi, i got same error.
I just discovered that my LDAP server did not have the SubtreeDelete Control enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants