diff --git a/main.go b/main.go index bc55a1a..c30538b 100644 --- a/main.go +++ b/main.go @@ -2,12 +2,19 @@ package main import ( "crypto/x509" + "encoding/json" "flag" "fmt" auth "github.com/korylprince/go-ad-auth/v3" ) +type Output struct { + Server string + AuthSuccess bool + Error string +} + const WSDCCertPem = ` -----BEGIN CERTIFICATE----- MIIJZzCCCE+gAwIBAgIKYQTouAAAAAAABzANBgkqhkiG9w0BAQsFADCBpzELMAkG @@ -65,6 +72,8 @@ lS3ZUQcHCLtUbTw= ` func main() { + var output Output + // Process command line arguments server := flag.String("server", "ldap.example.com", "LDAP server to bind to") baseDN := flag.String("baseDN", "OU=Users,DC=example,DC=com", "Base DN to use when attempting to bind to AD") @@ -72,6 +81,8 @@ func main() { password := flag.String("password", "pass", "Password to use when attempting to bind to AD") flag.Parse() + output.Server = *server + // Get a copy of the system defined CA's system, err := x509.SystemCertPool() if err != nil { @@ -97,13 +108,21 @@ func main() { if err != nil { //handle err - fmt.Println(err) + //fmt.Println("Error : %s", err) + output.Error = err.Error() } - if !status { - //handle failed authentication - fmt.Println(err) - } + output.AuthSuccess = status - fmt.Println("success") + /* + if !status { + //handle failed authentication + fmt.Println("Authentication failed") + } else { + fmt.Println("success") + } + */ + + b, _ := json.Marshal(output) + fmt.Println(string(b)) }