Files
efsldap/main.go
Shin'ya Minazuki e4d9b92061 * Rename fsldap to efsldap
* Use gopkg.in/ini.v1 over github.com/joho/godotenv
* Fix typos

Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
2026-01-07 19:42:00 -03:00

55 lines
1022 B
Go

package main
import (
"log"
"os"
"os/signal"
"syscall"
ldap "github.com/vjeantet/ldapserver"
cfg "git.laidback.moe/YakumoLabs/efsldap/config"
"git.laidback.moe/YakumoLabs/efsldap/handler"
flag "github.com/spf13/pflag"
)
var (
configPath string
)
func main() {
flag.StringVarP(&configPath, "config", "c", "", "Path to configuration file")
flag.Parse()
if configPath != "" {
cfg.ConfigPath = configPath
cfg.ConfInit()
} else {
log.Fatal("Unable to load configuration file")
}
server := ldap.NewServer()
routes := ldap.NewRouteMux()
routes.Bind(handler.Bind)
routes.Extended(handler.WhoAmI).
RequestName(ldap.NoticeOfWhoAmI).Label("Ext - WhoAmI")
routes.Search(handler.Search).Label("Search - Generic")
server.Handle(routes)
log.Print("Starting EFSLDAP server...")
go func(){
err := server.ListenAndServe("127.0.0.1:389")
if err != nil{
log.Fatal(err)
}
}()
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
close(ch)
server.Stop()
}