commit 768c0a54a09e1d7bc3fc71e422de37ce9b33638c Author: Paul Date: Mon Mar 2 16:17:46 2020 +0100 initial commit for adradius diff --git a/cmd/adradius/main.go b/cmd/adradius/main.go new file mode 100644 index 0000000..32c29c3 --- /dev/null +++ b/cmd/adradius/main.go @@ -0,0 +1,59 @@ +package main + +import ( + "log" + + auth "github.com/korylprince/go-ad-auth" + "layeh.com/radius" + "layeh.com/radius/rfc2865" +) + +func main() { + + config := &auth.Config{ + Server: "ldap.example.com", + Port: 389, + BaseDN: "OU=Users,DC=example,DC=com", + //Security: auth.SecurityStartTLS, + } + + handler := func(w radius.ResponseWriter, r *radius.Request) { + username := rfc2865.UserName_GetString(r.Packet) + password := rfc2865.UserPassword_GetString(r.Packet) + + var code radius.Code + + status, _ := ADauth(config, username, password) + + if status { + code = radius.CodeAccessAccept + } else { + code = radius.CodeAccessReject + } + log.Printf("Writing %v to %v", code, r.RemoteAddr) + w.Write(r.Response(code)) + } + + server := radius.PacketServer{ + Handler: radius.HandlerFunc(handler), + SecretSource: radius.StaticSecretSource([]byte(`secret`)), + } + + log.Printf("Starting server on :1812") + if err := server.ListenAndServe(); err != nil { + log.Fatal(err) + } +} + +func ADauth(config *auth.Config, username string, password string) (status bool, err error) { + status, err = auth.Authenticate(config, username, password) + //if err != nil { + // //handle err + // return + //} + //if !status { + // //handle failed authentication + // return + //} + return +}