Skip to content

Commit

Permalink
增加TLS连接方式
Browse files Browse the repository at this point in the history
  • Loading branch information
Rvn0xsy committed Oct 9, 2021
1 parent 7cf2531 commit 0762f2e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"flag"
"fmt"
"github.com/go-ldap/ldap"
Expand Down Expand Up @@ -36,6 +37,8 @@ type FlagStruct struct{
OutputMarkdown bool
Filter string
Columns string
TLSConnection bool
VerifyTLS bool
}


Expand Down Expand Up @@ -74,10 +77,16 @@ func (ldapClient * LdapClient )SetLDAPBaseDN(baseDN string) {
ldapClient.baseDN = baseDN
}

func (ldapClient * LdapClient )ConnectLDAP(){
func (ldapClient * LdapClient )ConnectLDAP(enableTLS bool,skipVerify bool){
var err error
connectAddr := fmt.Sprintf("%s:%d", ldapClient.ldapServerHost, ldapClient.ldapServerPort)
ldapClient.ldapCon ,err = ldap.Dial(ldapClient.ldapServerConnectProtocol,connectAddr)

if enableTLS {
ldapClient.ldapCon, err = ldap.DialTLS(ldapClient.ldapServerConnectProtocol,connectAddr,&tls.Config{InsecureSkipVerify: skipVerify})
}else{
ldapClient.ldapCon ,err = ldap.Dial(ldapClient.ldapServerConnectProtocol,connectAddr)
}

ldapClient.checkErrorPrintExit(err)

err = ldapClient.ldapCon.Bind(ldapClient.bindUsername, ldapClient.bindPassword)
Expand Down Expand Up @@ -276,6 +285,8 @@ func init() {
flag.BoolVar(&flagStruct.OutputMarkdown,"markdown",false,"Output Markdown Format")
flag.StringVar(&flagStruct.Filter,"filter","","LDAP Filter Query")
flag.StringVar(&flagStruct.Columns,"columns","","LDAP Result Columns e.g. DN,name,SID")
flag.BoolVar(&flagStruct.TLSConnection,"tls",false,"Enable TLS Connection")
flag.BoolVar(&flagStruct.VerifyTLS,"skip-verify",true,"SkipVerify TLS Connection")
flag.Parse()
if flagStruct.LDAPHost == "" || flagStruct.Username == "" || flagStruct.Password == ""{
flag.Usage()
Expand All @@ -297,7 +308,7 @@ func main() {
Dumper.SetLDAPBaseDN(flagStruct.BaseDN)

Dumper.SetLDAPServerConnect(flagStruct.LDAPHost, flagStruct.LDAPPort,connectPro)
Dumper.ConnectLDAP()
Dumper.ConnectLDAP(flagStruct.TLSConnection, flagStruct.VerifyTLS)
if flagStruct.GetComputer {
ldapResult := Dumper.Search(FilterComputerQuery)
Dumper.GetComputers(ldapResult)
Expand Down

0 comments on commit 0762f2e

Please sign in to comment.