summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-06-06 20:24:08 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2024-06-06 20:24:08 +0200
commit4b642834e01b0cf512c23666a1f959810d5cbe6e (patch)
tree4b51cbd8cf8c503e6bcf3ce33ae0f6be135bcda0 /main.go
parentlisten on custom network (ex. unix socket) (diff)
downloadpamldapd-4b642834e01b0cf512c23666a1f959810d5cbe6e.tar
pamldapd-4b642834e01b0cf512c23666a1f959810d5cbe6e.tar.gz
pamldapd-4b642834e01b0cf512c23666a1f959810d5cbe6e.tar.bz2
pamldapd-4b642834e01b0cf512c23666a1f959810d5cbe6e.tar.lz
pamldapd-4b642834e01b0cf512c23666a1f959810d5cbe6e.tar.xz
pamldapd-4b642834e01b0cf512c23666a1f959810d5cbe6e.tar.zst
pamldapd-4b642834e01b0cf512c23666a1f959810d5cbe6e.zip
Diffstat (limited to '')
-rw-r--r--main.go29
1 files changed, 25 insertions, 4 deletions
diff --git a/main.go b/main.go
index bc83365..c650d1c 100644
--- a/main.go
+++ b/main.go
@@ -12,6 +12,8 @@ import (
"net"
"os"
"os/user"
+ "os/signal"
+ "syscall"
"strings"
)
@@ -77,10 +79,28 @@ func main() {
l.SearchFunc("", backend)
l.CloseFunc("", backend)
backend.logger.Printf("LDAP server listen: %s, network %s", backend.Listen, backend.Network)
- if err := l.ListenAndServe(backend.Listen, backend.Network); err != nil {
- backend.logger.Printf("LDAP server listen failed: %s", err.Error())
- os.Exit(1)
- }
+ can_quit := make(chan bool, 1)
+ go func() {
+ if err := l.ListenAndServe(backend.Listen, backend.Network); err != nil {
+ backend.logger.Printf("LDAP server listen failed: %s", err.Error())
+ os.Exit(1)
+ }
+ can_quit <- true
+ }()
+ sigs := make(chan os.Signal, 1)
+ signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
+ done := make(chan bool, 1)
+ go func() {
+ sig := <-sigs
+ backend.logger.Printf("Received a signal %s", sig.String())
+ done <- true
+ }()
+ backend.logger.Printf("Running ...")
+ <-done
+ l.Quit <- true
+ backend.logger.Printf("Signalling LDAP server to terminate ...");
+ <-can_quit
+ backend.logger.Printf("Exiting ...")
}
func (b Backend) Bind(bindDN, bindSimplePw string, conn net.Conn) (resultCode ldap.LDAPResultCode, err error) {
@@ -159,6 +179,7 @@ func (b Backend) Search(bindDN string, req ldap.SearchRequest, conn net.Conn) (r
func (b Backend) Close(bindDN string, conn net.Conn) (err error) {
b.logger.Printf("Close addr=%s", conn.RemoteAddr().String())
+ conn.Close()
return nil
}