MCPcopy Create free account
hub / github.com/Synzack/ldapper / DeleteSPN

Function DeleteSPN

Commands/ModifySPN.go:34–56  ·  view source on GitHub ↗
(targetUser string, spn string, baseDN string, conn *ldap.Conn)

Source from the content-addressed store, hash-verified

32}
33
34func DeleteSPN(targetUser string, spn string, baseDN string, conn *ldap.Conn) (spnResult string) {
35
36 query := fmt.Sprintf("(sAMAccountName=%s)", targetUser) // Build the query
37 searchReq := Globals.LdapSearch(baseDN, query) // Search the baseDN
38 result, err := conn.Search(searchReq) // Execute the search
39 if err != nil {
40 fmt.Printf("Query error, %s", err)
41 }
42 if len(result.Entries) > 0 {
43 targetDN := result.Entries[0].DN
44 modSPN := ldap.NewModifyRequest(targetDN, []ldap.Control{})
45 modSPN.Delete("servicePrincipalName", []string{spn})
46 err = conn.Modify(modSPN)
47 if err != nil {
48 spnResult = fmt.Sprintf("Error: %s", err)
49 return
50 }
51 spnResult = fmt.Sprintf("Successfully deleted SPN: \"%s\" for user \"%s\"\n", spn, targetUser)
52 } else {
53 spnResult = fmt.Sprintf("Error: User \"%s\" not found", targetUser)
54 }
55 return
56}

Callers 1

mainFunction · 0.92

Calls 1

LdapSearchFunction · 0.92

Tested by

no test coverage detected