From e2352d510f8282771753625cba322dbf0b0020d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Thu, 6 Jun 2024 18:48:38 +0200 Subject: listen on custom network (ex. unix socket) --- README.adoc | 2 ++ go.mod | 2 +- go.sum | 4 ++-- main.go | 20 +++++++++++--------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.adoc b/README.adoc index ab692d8..d5ba33d 100644 --- a/README.adoc +++ b/README.adoc @@ -63,6 +63,8 @@ Example Configuration: `listen` :: Listen IP address and port like `0.0.0.0:0000` +You may optionally listen on a UNIX socket by setting the JSON configuration key "network" to "unix" and "listen" to "/path/to/your.sock". You may actually listen on any network that is supported by https://pkg.go.dev/net#Listen + `pamservicename` :: PAM authentication requires service-name like `login`, `su`. You can choose existing service or create a new. Existing service can be seen typing `ls /etc/pam.d/` For more service, see http://www.linux-pam.org/Linux-PAM-html/sag-configuration-file.html diff --git a/go.mod b/go.mod index dd05de7..df220db 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module 4a.si/pamldapd go 1.22.3 require ( + 4a.si/ldap v0.0.0-20240606163048-4e98bda1ca75 github.com/msteinert/pam v1.2.0 github.com/nmcclain/asn1-ber v0.0.0-20170104154839-2661553a0484 - github.com/nmcclain/ldap v0.0.0-20210720162743-7f8d1e44eeba ) diff --git a/go.sum b/go.sum index 338c0ec..e7d0b24 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,9 @@ +4a.si/ldap v0.0.0-20240606163048-4e98bda1ca75 h1:9gKsHSqpmcvJv/m4NE9FDGE0xYX20RGgl3+8yMOLHSo= +4a.si/ldap v0.0.0-20240606163048-4e98bda1ca75/go.mod h1:KaEI+oGtvDXWoYzDjfASiQZnLDm4JUJcMeEE1Qou4Uk= github.com/msteinert/pam v1.2.0 h1:mYfjlvN2KYs2Pb9G6nb/1f/nPfAttT/Jee5Sq9r3bGE= github.com/msteinert/pam v1.2.0/go.mod h1:d2n0DCUK8rGecChV3JzvmsDjOY4R7AYbsNxAT+ftQl0= github.com/nmcclain/asn1-ber v0.0.0-20170104154839-2661553a0484 h1:D9EvfGQvlkKaDr2CRKN++7HbSXbefUNDrPq60T+g24s= github.com/nmcclain/asn1-ber v0.0.0-20170104154839-2661553a0484/go.mod h1:O1EljZ+oHprtxDDPHiMWVo/5dBT6PlvWX5PSwj80aBA= -github.com/nmcclain/ldap v0.0.0-20210720162743-7f8d1e44eeba h1:DO8NFYdcRv1dnyAINJIBm6Bw2XibtLvQniNFGzf2W8E= -github.com/nmcclain/ldap v0.0.0-20210720162743-7f8d1e44eeba/go.mod h1:4S0XndRL8HNOaQBfdViJ2F/GPCgL524xlXRuXFH12/U= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= diff --git a/main.go b/main.go index 9685b3e..bc83365 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,7 @@ import ( "fmt" "github.com/msteinert/pam" "github.com/nmcclain/asn1-ber" - "github.com/nmcclain/ldap" + "4a.si/ldap" "log" "net" "os" @@ -19,12 +19,13 @@ type Backend struct { ldap.Binder ldap.Searcher ldap.Closer - logger *log.Logger - Listen string - PAMServiceName string - PeopleDN string - GroupsDN string - BindAdminDN string + logger *log.Logger + Listen string + Network string + PAMServiceName string + PeopleDN string + GroupsDN string + BindAdminDN string BindAdminPassword string } @@ -33,6 +34,7 @@ func main() { var logfile = flag.String("l", "", "Log file (STDOUT if blank)") flag.Parse() var backend = Backend{} + backend.Network = "tcp" { confighandle, err := os.Open(*configfile) if err != nil { @@ -74,8 +76,8 @@ func main() { l.BindFunc("", backend) l.SearchFunc("", backend) l.CloseFunc("", backend) - backend.logger.Printf("LDAP server listen: %s", backend.Listen) - if err := l.ListenAndServe(backend.Listen); err != nil { + 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) } -- cgit v1.2.3