Compare commits

..

2 Commits

2 changed files with 16 additions and 2 deletions

View File

@ -98,7 +98,7 @@ func internalLdapSearch(conLdap *MyLdap, searchReq *ldap.SearchRequest, attempt
func searchByCn(myldap *MyLdap, baseDn, cn, class, attributes string) (*ldap.SearchResult, error) {
var filter string
if false == strings.EqualFold(cn, "ALL") {
filter = fmt.Sprintf("(cn=%s)", cn)
filter = fmt.Sprintf("cn=%s", cn)
} else {
filter = cn
}

16
main.go
View File

@ -22,7 +22,7 @@ import (
)
var (
gVersion = "0.5.6"
gVersion = "0.5.8"
gRoLdap *MyLdap
)
@ -263,6 +263,7 @@ func initRouter(r *gin.Engine) {
c.AbortWithError(http.StatusInternalServerError, nil)
return
}
defer ldapCon.Conn.Close()
// json format is the default
format := c.DefaultQuery("format", "json")
@ -298,6 +299,7 @@ func initRouter(r *gin.Engine) {
c.AbortWithError(http.StatusInternalServerError, nil)
return
}
defer ldapCon.Conn.Close()
modified, err := checkIfModifiedSince(c, ldapCon, ou, cn, class, "ALL")
if err != nil {
@ -334,6 +336,7 @@ func initRouter(r *gin.Engine) {
c.AbortWithError(http.StatusInternalServerError, nil)
return
}
defer ldapCon.Conn.Close()
res, err := searchByCn(ldapCon, ou, cn, class, attr)
if err != nil {
@ -365,6 +368,7 @@ func initRouter(r *gin.Engine) {
c.AbortWithError(http.StatusInternalServerError, nil)
return
}
defer ldapCon.Conn.Close()
modified, err := checkIfModifiedSince(c, ldapCon, ou, cn, class, attr)
if err != nil {
@ -405,6 +409,7 @@ func initRouter(r *gin.Engine) {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
defer ldapCon.Conn.Close()
// Unmarshall json body to a map
if c.Request.Header.Get("Content-Type") == "application/json" {
@ -468,6 +473,7 @@ func initRouter(r *gin.Engine) {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
defer ldapCon.Conn.Close()
// Unmarshall json body to a map
if c.Request.Header.Get("Content-Type") == "application/json" {
@ -521,6 +527,7 @@ func initRouter(r *gin.Engine) {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
defer ldapCon.Conn.Close()
// Unmarshall json body to a map
if c.Request.Header.Get("Content-Type") == "application/json" {
@ -570,6 +577,7 @@ func main() {
var tlsCert string
var doTls bool
var debug bool
var showversion bool
flag.StringVar(&confFile, "config", "", "Path to the config file (optional)")
flag.StringVar(&listen, "listen-addr", "0.0.0.0:8080", "listen address for server")
@ -582,9 +590,15 @@ func main() {
flag.StringVar(&tlsPrivKey, "ssl-private-key", "", "SSL Private key")
flag.StringVar(&tlsCert, "ssl-certificate", "", "SSL certificate (PEM format)")
flag.BoolVar(&debug, "debug", false, "Set log level to debug")
flag.BoolVar(&showversion, "version", false, "Show version then exit")
flag.Parse()
if showversion {
fmt.Printf("GlApi v%s\n", gVersion)
return
}
if len(confFile) > 0 {
viper.SetConfigFile(confFile)
if err := viper.ReadInConfig(); err != nil {