Skip to content

Commit 36512f2

Browse files
author
oothman
committed
Better logging.
1 parent 961288b commit 36512f2

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
)
2828

2929
func main() {
30-
3130
setupProfiling()
3231
cmd.Execute()
3332
}

pkg/backend.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type session struct {
4040
}
4141

4242
func (bmcLdap *BmcLdap) Bind(ctx ldap.Context, req *ldap.BindRequest) (bindResponse *ldap.BindResponse, err error) {
43-
4443
log := bmcLdap.logger
4544

4645
if req.DN == "" {
@@ -98,7 +97,7 @@ func (bmcLdap *BmcLdap) Bind(ctx ldap.Context, req *ldap.BindRequest) (bindRespo
9897
log.Debug(fmt.Sprintf("Bind accept response %#v", bindResponse))
9998
return bindResponse, err
10099
} else {
101-
log.Debug(fmt.Sprintf("BIND reject response %#v", bindResponse))
100+
log.Debug(fmt.Sprintf("Bind reject response %#v", bindResponse))
102101
return bindResponse, err
103102
}
104103
}
@@ -276,6 +275,5 @@ func (bmcLdap *BmcLdap) ModifyDN(ctx ldap.Context, req *ldap.ModifyDNRequest) (*
276275

277276
// Method added to conform to ldap.Server interface
278277
func (bmcLdap *BmcLdap) PasswordModify(ctx ldap.Context, req *ldap.PasswordModifyRequest) ([]byte, error) {
279-
280278
return []byte{}, nil
281279
}

pkg/providers/common.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929

3030
// ConnectRemoteServer returns a client to a remote ldap server
3131
func ConnectRemoteServer(ctx context.Context, clientCaCert string, server string, port int) (client *ldap.Client, err error) {
32-
3332
clientChan := make(chan *ldap.Client)
3433

3534
go func(clientChan chan<- *ldap.Client) {
@@ -56,7 +55,6 @@ func ConnectRemoteServer(ctx context.Context, clientCaCert string, server string
5655
case <-ctx.Done():
5756
return client, errors.New("LDAP client went away while connecting to backend LDAP server!")
5857
}
59-
6058
}
6159

6260
// returns tls config with RootCA certs loaded

pkg/providers/dell/dell.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,28 @@ func (d *Dell) Authenticate(ctx context.Context, bindDN string, bindPassword []b
5656
return true
5757
}
5858

59-
func (d *Dell) Authorize(ctx context.Context, req *ldap.SearchRequest) ([]*ldap.SearchResult, error) {
60-
searchResults := ldap.SearchResult{}
61-
59+
func (d *Dell) Authorize(ctx context.Context, req *ldap.SearchRequest) (results []*ldap.SearchResult, err error) {
6260
ldapClient, err := providers.ConnectRemoteServer(ctx, d.Config.ClientCaCert, d.Config.RemoteServerName, d.Config.RemoteServerPortTLS)
6361
defer ldapClient.Close()
6462

6563
if err != nil {
6664
d.Logger.Warn(err)
67-
return []*ldap.SearchResult{&searchResults}, err
65+
return results, err
6866
}
6967

70-
d.Logger.Debug("Filter string is " + req.Filter.String())
71-
7268
// Dell Search request 1: BMC validating the user account is present under the base DN.
7369
// Pass this request to the backend LDAP server and return the response to the client as is.
7470
if strings.Contains(req.Filter.String(), "objectClass=posixAccount") {
7571
// req.BaseDN at this point is set to "cn=dell".
7672
// This needs to be updated to a valid search base (starting point in the tree).
7773
req.BaseDN = d.Config.BaseDN
7874

79-
d.Logger.Debug("Starting Dell Search 1 for " + req.BaseDN)
75+
d.Logger.Debug("Starting Dell Search 1 for " + req.BaseDN + ", request filter is " + req.Filter.String())
8076
searchResponse, err := ldapClient.Search(req)
8177
if err != nil {
82-
d.Logger.Warn(fmt.Sprintf("Remote LDAP search 1 request returned an error: %s", err))
78+
d.Logger.Warn(fmt.Sprintf("Remote LDAP Search 1 request returned an error: %s", err))
79+
} else {
80+
d.Logger.Info(fmt.Sprintf("Remote LDAP Search 1 request succeeded, response: %+v", searchResponse))
8381
}
8482
return searchResponse, nil
8583
}
@@ -89,7 +87,7 @@ func (d *Dell) Authorize(ctx context.Context, req *ldap.SearchRequest) ([]*ldap.
8987
if strings.Contains(req.Filter.String(), "memberUid=") {
9088
// req.BaseDN at this point would contain "cn=dell", to identify this BMC as Dell.
9189
// (e.g. "cn=dell,cn=fooUsers,ou=Group,dc=example,dc=com")
92-
d.Logger.Debug("Starting Dell Search 2 for " + req.BaseDN)
90+
d.Logger.Debug("Starting Dell Search 2 for " + req.BaseDN + ", request filter is " + req.Filter.String())
9391

9492
// Strip out "cn=dell," from the request Base DN.
9593
mainDN := strings.Replace(req.BaseDN, "cn=dell,", "", 1)
@@ -98,7 +96,7 @@ func (d *Dell) Authorize(ctx context.Context, req *ldap.SearchRequest) ([]*ldap.
9896
req.BaseDN = strings.Replace(mainDN, "cn=", "cn="+prefix, -1)
9997

10098
// Indicate that we have changed something...
101-
msg := "Performing actual search for " + req.BaseDN
99+
msg := "Performing actual search for " + req.BaseDN + ", request filter is " + req.Filter.String()
102100
if prefix != "" {
103101
msg += " after adding " + prefix
104102
}
@@ -107,7 +105,7 @@ func (d *Dell) Authorize(ctx context.Context, req *ldap.SearchRequest) ([]*ldap.
107105
// The actual search.
108106
searchResponse, err := ldapClient.Search(req)
109107
if err != nil {
110-
d.Logger.Warn(fmt.Sprintf("Remote LDAP search 2 request returned an error: %s", err))
108+
d.Logger.Warn(fmt.Sprintf("Remote LDAP Search 2 request returned an error: %s", err))
111109
}
112110

113111
if len(searchResponse) > 0 {
@@ -117,5 +115,7 @@ func (d *Dell) Authorize(ctx context.Context, req *ldap.SearchRequest) ([]*ldap.
117115
}
118116
}
119117

120-
return []*ldap.SearchResult{&searchResults}, nil
118+
d.Logger.Info(fmt.Sprintf("Filter %s not found in group %s", req.Filter.String(), req.BaseDN))
119+
120+
return results, nil
121121
}

0 commit comments

Comments
 (0)