Skip to content

Commit

Permalink
fix: go-simple-ldap update broke stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDevMinerTV committed Aug 25, 2023
1 parent 95ab5d7 commit 4427989
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 7 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

var httpAddress, ldapServer, ldapBaseDN, dbLocation, readUser, readPassword, ldapAdminGroupDB string
var ldapIsAd bool

var serveCmd = &cobra.Command{
Use: "serve",
Expand All @@ -35,7 +36,10 @@ var serveCmd = &cobra.Command{
return err
}

srv := server.New(db, ldapServer, ldapBaseDN, readUser, readPassword, ldapAdminGroupDB)
srv, err := server.New(db, ldapServer, ldapBaseDN, readUser, readPassword, ldapAdminGroupDB, ldapIsAd)
if err != nil {
return err
}

return srv.Listen(httpAddress)
},
Expand All @@ -54,6 +58,8 @@ func init() {

serveCmd.Flags().StringVarP(&ldapAdminGroupDB, "ldap-admin-group-dn", "g", "", "LDAP group DN to use for identifying administrators")

serveCmd.Flags().BoolVar(&ldapIsAd, "ldap-is-ad", false, "Whether the LDAP server is Active Directory")

if err := serveCmd.MarkFlagRequired("ldap-read-user"); err != nil {
log.Fatalln(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/server/auth_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func basicAuth(auth string) (string, string, error) {
return parts[0], parts[1], nil
}

func authMiddleware(authHeader string, l ldap.LDAP) (*ldap.User, error) {
func authMiddleware(authHeader string, l *ldap.LDAP) (*ldap.User, error) {
sAMAccountName, password, err := basicAuth(authHeader)
if err != nil {
return nil, err
Expand Down
13 changes: 9 additions & 4 deletions internal/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ type Server struct {
app *fiber.App
db *bbolt.DB

ldap ldap.LDAP
ldap *ldap.LDAP
ldapAdminGroupDN string
}

func New(db *bbolt.DB, ldapServer, ldapBaseDN, ldapReadUser, ldapReadPassword, ldapAdminGroupDN string) *Server {
func New(db *bbolt.DB, ldapServer, ldapBaseDN, ldapReadUser, ldapReadPassword, ldapAdminGroupDN string, isAD bool) (*Server, error) {
l, err := ldap.New(ldapServer, ldapBaseDN, ldapReadUser, ldapReadPassword, isAD)
if err != nil {
return nil, err
}

srv := &Server{
fiber.New(),
db,

ldap.New(ldapServer, ldapBaseDN, ldapReadUser, ldapReadPassword),
l,
ldapAdminGroupDN,
}

srv.init()

return srv
return srv, nil
}

func (s *Server) init() {
Expand Down

0 comments on commit 4427989

Please sign in to comment.