From b58ea042394c66eabe67c3f58906c5d76b1e119d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 7 Sep 2017 23:28:47 -0400 Subject: nslcd_{server,systemd}: FIX, BREAKING CHANGE: add limits Added types: nslcd_server: type Limits struct { ...} nslcd_server: type Conn interface{ ... } // a subset of net.Conn nslcd_server.HandleRequest() signature change: -func HandleRequest(backend Backend, in io.Reader, out io.Writer, cred unix.Ucred) (err error) { +func HandleRequest(backend Backend, limits Limits, conn Conn, cred unix.Ucred) (err error) { The `limits Limits` argument is added, and `conn Conn` replaces `in io.Reader` and `out io.Writer`. nslcd_systemd.Main() signature change: -func Main(backend Backend) uint8 { +func Main(backend Backend, limits nslcd_server.Limits) uint8 { The `limits Limits` argument is added. --- nslcd_systemd/misc_test.go | 4 +++- nslcd_systemd/nslcd_systemd.go | 16 ++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'nslcd_systemd') diff --git a/nslcd_systemd/misc_test.go b/nslcd_systemd/misc_test.go index d2b2a7e..a910cd9 100644 --- a/nslcd_systemd/misc_test.go +++ b/nslcd_systemd/misc_test.go @@ -77,7 +77,9 @@ func testBadClient(t *testContext, backend nslcd_systemd.Backend, toclose bool) // server ////////////////////////////////////////////////////////////// errfatal(sdActivatedStream(t.tmpdir + "/nslcd.sock")) go func() { - evExitServer <- nslcd_systemd.Main(backend) + evExitServer <- nslcd_systemd.Main(backend, nslcd_server.Limits{ + Timeout: 1 * time.Second, + }) }() // client/driver /////////////////////////////////////////////////////// diff --git a/nslcd_systemd/nslcd_systemd.go b/nslcd_systemd/nslcd_systemd.go index 97991c8..8bae046 100644 --- a/nslcd_systemd/nslcd_systemd.go +++ b/nslcd_systemd/nslcd_systemd.go @@ -24,11 +24,15 @@ // // package main // -// import "nslcd/systemd" +// import ( +// "git.lukeshu.com/go/libnslcd/nslcd_server" +// "git.lukeshu.com/go/libnslcd/nslcd_systemd" +// ) // // func main() { // backend := ... -// os.Exit(int(nslcd_systemd.Main(backend))) +// limits := nslcd_server.Limits{ ... } +// os.Exit(int(nslcd_systemd.Main(backend, limits))) // } package nslcd_systemd // import "git.lukeshu.com/go/libnslcd/nslcd_systemd" @@ -88,7 +92,7 @@ func getpeercred(conn *net.UnixConn) (cred unix.Ucred, err error) { return } -func handler(conn *net.UnixConn, backend nslcd_server.Backend) { +func handler(backend nslcd_server.Backend, limits nslcd_server.Limits, conn *net.UnixConn) { defer conn.Close() cred, err := getpeercred(conn) if err != nil { @@ -97,13 +101,13 @@ func handler(conn *net.UnixConn, backend nslcd_server.Backend) { sd_daemon.Log.Debug(fmt.Sprintf("Connection from pid=%v uid=%v gid=%v", cred.Pid, cred.Uid, cred.Gid)) } - err = nslcd_server.HandleRequest(backend, conn, conn, cred) + err = nslcd_server.HandleRequest(backend, limits, conn, cred) if err != nil { sd_daemon.Log.Notice(fmt.Sprintf("Error while handling request: %v", err)) } } -func Main(backend Backend) uint8 { +func Main(backend Backend, limits nslcd_server.Limits) uint8 { defer sd_daemon.Recover() var err error = nil @@ -165,7 +169,7 @@ func Main(backend Backend) uint8 { go func() { defer sd_daemon.Recover() defer wg.Done() - handler(conn.(*net.UnixConn), backend) + handler(backend, limits, conn.(*net.UnixConn)) }() } } -- cgit v1.2.3-2-g168b