| 8 | ) |
| 9 | |
| 10 | func 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 | |
| 34 | func DeleteSPN(targetUser string, spn string, baseDN string, conn *ldap.Conn) (spnResult string) { |
| 35 | |