Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
equinox0815 committed Nov 9, 2023
1 parent 7a98144 commit 44be4e6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion auth/backend_ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewLDAPBackend(conf *LDAPConfig, infoLog, dbgLog *log.Logger) (Backend, err
if conf.TLS != nil {
var err error
if b.tlsConf, err = conf.TLS.ToGoTLSConfig(); err != nil {
return nil, err
return nil, fmt.Errorf("ldap: %v", err)
}
}
infoLog.Printf("ldap: successfully initialized")
Expand Down
6 changes: 3 additions & 3 deletions auth/backend_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func NewStaticBackend(conf *StaticConfig, infoLog, dbgLog *log.Logger) (Backend,
return b, nil
}

func (w *StaticBackend) Authenticate(username, password string) error {
// TODO: call w.htpasswd.Reload() ??
ok := w.htpasswd.Match(username, password)
func (b *StaticBackend) Authenticate(username, password string) error {
// TODO: call b.htpasswd.Reload() ??
ok := b.htpasswd.Match(username, password)
if !ok {
return fmt.Errorf("invalid username or password")
}
Expand Down
16 changes: 8 additions & 8 deletions auth/backend_whawty.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,29 @@ func remoteHTTPUpgrader(upgradeChan <-chan whawtyUpgradeRequest, remote string,
}
}

func (w *WhawtyAuthBackend) runRemoteUpgrader(remote string) error {
func (b *WhawtyAuthBackend) runRemoteUpgrader(remote string) error {
r, err := url.Parse(remote)
if err != nil {
return err
}
switch r.Scheme {
case "http":
w.infoLog.Printf("whaty: using insecure url for remote upgrades: %s", remote)
b.infoLog.Printf("whaty: using insecure url for remote upgrades: %s", remote)
fallthrough
case "https":
w.upgradeChan = make(chan whawtyUpgradeRequest, 10)
go remoteHTTPUpgrader(w.upgradeChan, remote, w.infoLog, w.dbgLog)
b.upgradeChan = make(chan whawtyUpgradeRequest, 10)
go remoteHTTPUpgrader(b.upgradeChan, remote, b.infoLog, b.dbgLog)
default:
return fmt.Errorf("whawty-auth: invalid upgrade url: %s", remote)
}
return nil
}

func (w *WhawtyAuthBackend) Authenticate(username, password string) error {
ok, _, upgradeable, _, err := w.store.Authenticate(username, password)
if ok && upgradeable && w.upgradeChan != nil {
func (b *WhawtyAuthBackend) Authenticate(username, password string) error {
ok, _, upgradeable, _, err := b.store.Authenticate(username, password)
if ok && upgradeable && b.upgradeChan != nil {
select {
case w.upgradeChan <- whawtyUpgradeRequest{Username: username, OldPassword: password}:
case b.upgradeChan <- whawtyUpgradeRequest{Username: username, OldPassword: password}:
default: // remote upgrades are opportunistic
}
}
Expand Down
6 changes: 3 additions & 3 deletions auth/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ func (t TLSClientConfig) ToGoTLSConfig() (*tls.Config, error) {
cfg.RootCAs = x509.NewCertPool()
if t.CACertificates != "" {
if ok := cfg.RootCAs.AppendCertsFromPEM([]byte(t.CACertificates)); !ok {
return nil, fmt.Errorf("ldap: no certificates found in ca-certificates content")
return nil, fmt.Errorf("no certificates found in ca-certificates content")
}
}
for _, cert := range t.CACertificateFiles {
pemData, err := loadFile(cert)
if err != nil {
return nil, fmt.Errorf("ldap: loading ca-certificates failed: %v", err)
return nil, fmt.Errorf("loading ca-certificate file failed: %v", err)
}

ok := cfg.RootCAs.AppendCertsFromPEM(pemData)
if !ok {
return nil, fmt.Errorf("ldap: no certificates found in file '%s'", cert)
return nil, fmt.Errorf("no ca-certificates found in file '%s'", cert)
}
}
return cfg, nil
Expand Down

0 comments on commit 44be4e6

Please sign in to comment.