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

Function AddSPN

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

Source from the content-addressed store, hash-verified

8)
9
10func AddSPN(targetUser string, spn string, baseDN string, conn *ldap.Conn) (spnResult string) {
11
12 query := fmt.Sprintf("(sAMAccountName=%s)", targetUser) // Build the query
13 searchReq := Globals.LdapSearch(baseDN, query) // Search the baseDN
14 result, err := conn.Search(searchReq) // Execute the search
15 if err != nil {
16 fmt.Printf("Query error, %s", err)
17 }
18 if len(result.Entries) > 0 {
19 targetDN := result.Entries[0].DN
20 modSPN := ldap.NewModifyRequest(targetDN, []ldap.Control{})
21 modSPN.Add("servicePrincipalName", []string{spn})
22 err = conn.Modify(modSPN)
23 if err != nil {
24 spnResult = fmt.Sprintf("Error: %s", err)
25 return
26 }
27 spnResult = fmt.Sprintf("Successfully added SPN: \"%s\" for user \"%s\"\n", spn, targetUser)
28 } else {
29 spnResult = fmt.Sprintf("Error: User \"%s\" not found", targetUser)
30 }
31 return
32}
33
34func DeleteSPN(targetUser string, spn string, baseDN string, conn *ldap.Conn) (spnResult string) {
35

Callers 1

mainFunction · 0.92

Calls 1

LdapSearchFunction · 0.92

Tested by

no test coverage detected