From 8692fa525b0f1522ee7ddb169618b91c668b6988 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Wed, 19 Jul 2023 13:59:42 +1000 Subject: [PATCH] initial commit --- .drone.sh | 9 +++++++++ .drone.yml | 28 ++++++++++++++++++++++++++++ .gitignore | 1 + README.md | 0 go.mod | 11 +++++++++++ go.sum | 10 ++++++++++ main.go | 37 +++++++++++++++++++++++++++++++++++++ 7 files changed, 96 insertions(+) create mode 100644 .drone.sh create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.drone.sh b/.drone.sh new file mode 100644 index 0000000..5ab523a --- /dev/null +++ b/.drone.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +export now=$(TZ=Australia/Sydney date '+%Y%m%d-%H%M%S') +echo $now +echo "build commences" +go build -ldflags "-X main.sha1ver=`git rev-parse HEAD` -X main.buildTime=$now" -o authcheck +echo "build complete" +sha256sum authcheck > authcheck_checksum.txt +ls -lah \ No newline at end of file diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..8fb5270 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,28 @@ +kind: pipeline +type: docker +name: default + +# Docs at https://docs.drone.io/pipeline/exec/overview/ +# Also see https://github.com/harness/drone-cli/blob/master/.drone.yml + +steps: +- name: build + image: golang + commands: + - sh ./.drone.sh + +- name: dell-deploy +# # https://github.com/cschlosser/drone-ftps/blob/master/README.md + image: cschlosser/drone-ftps + environment: + FTP_USERNAME: + from_secret: FTP_USERNAME + FTP_PASSWORD: + from_secret: FTP_PASSWORD + PLUGIN_HOSTNAME: ftp.emc.com:21 + PLUGIN_SECURE: false + PLUGIN_VERIFY: false + PLUGIN_CHMOD: false + #PLUGIN_DEBUG: false + PLUGIN_INCLUDE: ^authcheck$,^authcheck_checksum.txt$ + PLUGIN_EXCLUDE: ^\.git/$ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89547ba --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +log.txt \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..89b5397 --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module go-authcheck + +go 1.19 + +require github.com/korylprince/go-ad-auth/v3 v3.3.0 + +require ( + github.com/go-asn1-ber/asn1-ber v1.4.1 // indirect + github.com/go-ldap/ldap/v3 v3.1.7 // indirect + golang.org/x/text v0.3.2 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..97abf39 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/go-asn1-ber/asn1-ber v1.3.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= +github.com/go-asn1-ber/asn1-ber v1.4.1 h1:qP/QDxOtmMoJVgXHCXNzDpA0+wkgYB2x5QoLMVOciyw= +github.com/go-asn1-ber/asn1-ber v1.4.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= +github.com/go-ldap/ldap/v3 v3.1.7 h1:aHjuWTgZsnxjMgqzx0JHwNqz4jBYZTcNarbPFkW1Oww= +github.com/go-ldap/ldap/v3 v3.1.7/go.mod h1:5Zun81jBTabRaI8lzN7E1JjyEl1g6zI6u9pd8luAK4Q= +github.com/korylprince/go-ad-auth/v3 v3.3.0 h1:iXuB+sCk4GniHnpUn0BAHH8rKeOLTKuYcBNvERa773Y= +github.com/korylprince/go-ad-auth/v3 v3.3.0/go.mod h1:19M0geaOeNN489k1MO6GCqOCgbruYRQkHRBfhhUZAoE= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/main.go b/main.go new file mode 100644 index 0000000..23c921a --- /dev/null +++ b/main.go @@ -0,0 +1,37 @@ +package main + +import ( + "flag" + "fmt" + + auth "github.com/korylprince/go-ad-auth/v3" +) + +func main() { + // 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") + username := flag.String("username", "user", "Username to use when attempting to bind to AD") + password := flag.String("password", "pass", "Password to use when attempting to bind to AD") + + config := &auth.Config{ + Server: *server, + Port: 636, + BaseDN: *baseDN, + Security: auth.SecurityStartTLS, + } + + status, err := auth.Authenticate(config, *username, *password) + + if err != nil { + //handle err + fmt.Println(err) + } + + if !status { + //handle failed authentication + fmt.Println(err) + } + + fmt.Println("success") +}