You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ro...@apache.org on 2018/05/17 22:41:38 UTC

[incubator-trafficcontrol] 19/19: increase logging in ldap methods for debugging

This is an automated email from the ASF dual-hosted git repository.

rob pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 9d85130fb990d861cf503e96b83d3ee7ebbf0a14
Author: Dylan Volz <Dy...@comcast.com>
AuthorDate: Tue May 15 09:26:02 2018 -0600

    increase logging in ldap methods for debugging
---
 traffic_ops/traffic_ops_golang/auth/ldap.go          | 5 ++++-
 traffic_ops/traffic_ops_golang/auth/login.go         | 4 ++--
 traffic_ops/traffic_ops_golang/config/config.go      | 7 ++++---
 traffic_ops/traffic_ops_golang/traffic_ops_golang.go | 1 -
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/auth/ldap.go b/traffic_ops/traffic_ops_golang/auth/ldap.go
index 4ab19d0..9f8291c 100644
--- a/traffic_ops/traffic_ops_golang/auth/ldap.go
+++ b/traffic_ops/traffic_ops_golang/auth/ldap.go
@@ -72,6 +72,7 @@ func ConnectToLDAP(cfg *config.ConfigLDAP) (*ldap.Conn, error) {
 func LookupUserDN(username string, cfg *config.ConfigLDAP) (string, bool, error) {
 	l, err := ConnectToLDAP(cfg)
 	if err != nil {
+		log.Errorln("unable to connect to ldap to lookup user")
 		return "", false, err
 	}
 	defer l.Close()
@@ -93,7 +94,7 @@ func LookupUserDN(username string, cfg *config.ConfigLDAP) (string, bool, error)
 
 	sr, err := l.Search(searchRequest)
 	if err != nil {
-		log.Errorln("error issuing search:")
+		log.Errorln("error issuing search: ", err)
 		return "", false, err
 	}
 
@@ -107,6 +108,7 @@ func LookupUserDN(username string, cfg *config.ConfigLDAP) (string, bool, error)
 func AuthenticateUserDN(userDN string, password string, cfg *config.ConfigLDAP) (bool, error) {
 	l, err := ConnectToLDAP(cfg)
 	if err != nil {
+		log.Errorln("unable to connect to ldap to authenticate user")
 		return false, err
 	}
 	defer l.Close()
@@ -114,6 +116,7 @@ func AuthenticateUserDN(userDN string, password string, cfg *config.ConfigLDAP)
 	// Bind as the user to verify their password
 	err = l.Bind(userDN, password)
 	if err != nil {
+		log.Errorf("unable to bind as user: %+v\n", userDN)
 		return false, err
 	}
 	return true, nil
diff --git a/traffic_ops/traffic_ops_golang/auth/login.go b/traffic_ops/traffic_ops_golang/auth/login.go
index 8e4123c..6021593 100644
--- a/traffic_ops/traffic_ops_golang/auth/login.go
+++ b/traffic_ops/traffic_ops_golang/auth/login.go
@@ -105,12 +105,12 @@ func LoginHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
 
 func CheckLocalUserIsAllowed(form passwordForm, db *sqlx.DB) (bool, error) {
 	var roleName string
-	err := db.Get(&roleName, "SELECT role.name FROM role INNER JOIN tm_user ON tm_user.role = role.id where username=$1",form.Username)
+	err := db.Get(&roleName, "SELECT role.name FROM role INNER JOIN tm_user ON tm_user.role = role.id where username=$1", form.Username)
 	if err != nil {
 		return false, err
 	}
 	if roleName != "" {
-		if roleName != disallowed{ //relies on unchanging role name assumption.
+		if roleName != disallowed { //relies on unchanging role name assumption.
 			return true, nil
 		}
 	}
diff --git a/traffic_ops/traffic_ops_golang/config/config.go b/traffic_ops/traffic_ops_golang/config/config.go
index d85d20c..17248cf 100644
--- a/traffic_ops/traffic_ops_golang/config/config.go
+++ b/traffic_ops/traffic_ops_golang/config/config.go
@@ -24,12 +24,12 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/url"
+	"os"
+	"path/filepath"
 
 	"github.com/apache/incubator-trafficcontrol/lib/go-log"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/riaksvc"
 	"github.com/basho/riak-go-client"
-	"path/filepath"
-	"os"
 )
 
 // Config reflects the structure of the cdn.conf file
@@ -126,6 +126,7 @@ func (c Config) EventLog() log.LogLocation {
 
 const BlockStartup = true
 const AllowStartup = false
+
 // LoadConfig - reads the config file into the Config struct
 
 func LoadConfig(cdnConfPath string, dbConfPath string, riakConfPath string, appVersion string) (Config, []error, bool) {
@@ -170,7 +171,7 @@ func LoadConfig(cdnConfPath string, dbConfPath string, riakConfPath string, appV
 		}
 	} else { // ldap config location not specified in cdn.conf, check in directory with cdn.conf for backwards compatibility with perl.
 		confDir := filepath.Dir(cdnConfPath)
-		genericLDAPConfPath := filepath.Join(confDir,"cdn.conf")
+		genericLDAPConfPath := filepath.Join(confDir, "cdn.conf")
 		if _, err := os.Stat(genericLDAPConfPath); !os.IsNotExist(err) { // ldap.conf exists and we should error if it is not readable/parseable.
 			cfg.LDAPEnabled, cfg.ConfigLDAP, err = GetLDAPConfig(genericLDAPConfPath)
 			if err != nil { // no config or unparseable, do not enable LDAP
diff --git a/traffic_ops/traffic_ops_golang/traffic_ops_golang.go b/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
index 782e991..d8cea78 100644
--- a/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
+++ b/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
@@ -66,7 +66,6 @@ func main() {
 		os.Exit(1)
 	}
 
-
 	if err := log.InitCfg(cfg); err != nil {
 		fmt.Printf("Error initializing loggers: %v\n", err)
 		for _, err := range errsToLog {

-- 
To stop receiving notification emails like this one, please contact
rob@apache.org.