From 5d1fe0000ba409ffbce62db439ae303e30a1eeb0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 24 Aug 2021 22:04:56 -0600 Subject: Generate artifacts --- nslcd_server/.gitignore | 4 - nslcd_server/func_handlerequest.go | 1751 ++++++++++++++++++++++++++++++++++++ nslcd_server/interface_backend.go | 55 ++ nslcd_server/requests.txt | 38 + nslcd_server/type_nilbackend.go | 209 +++++ 5 files changed, 2053 insertions(+), 4 deletions(-) delete mode 100644 nslcd_server/.gitignore create mode 100644 nslcd_server/func_handlerequest.go create mode 100644 nslcd_server/interface_backend.go create mode 100644 nslcd_server/requests.txt create mode 100644 nslcd_server/type_nilbackend.go diff --git a/nslcd_server/.gitignore b/nslcd_server/.gitignore deleted file mode 100644 index 8a2b4eb..0000000 --- a/nslcd_server/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/func_handlerequest.go -/interface_backend.go -/type_nilbackend.go -/requests.txt diff --git a/nslcd_server/func_handlerequest.go b/nslcd_server/func_handlerequest.go new file mode 100644 index 0000000..ce3061a --- /dev/null +++ b/nslcd_server/func_handlerequest.go @@ -0,0 +1,1751 @@ +// ./func_handlerequest.go.gen requests.txt +// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT + +package nslcd_server + +import ( + "context" + "fmt" + "io" + "time" + + p "git.lukeshu.com/go/libnslcd/nslcd_proto" +) + +const sensitive = "" + +func maybePanic(err error) { + if err != nil { + panic(err) + } +} + +type Limits struct { + // What is the maximum total amount of time that we spend + // handling a single request. This includes both the time + // reading the request and the time creating and writing the + // response. + Timeout time.Duration + + // How long can we spend reading a request? + ReadTimeout time.Duration + + // How long can we spend writing a response? + WriteTimeout time.Duration + + // What is the maximum request length in bytes that we are + // willing to handle? + RequestMaxSize int64 +} + +type Conn interface { + // This is a subset of net.Conn; semantics are the same. + + Read(b []byte) (n int, err error) + Write(b []byte) (n int, err error) + SetDeadline(t time.Time) error + SetReadDeadline(t time.Time) error + SetWriteDeadline(t time.Time) error +} + +// Handle a request to nslcd. The caller is responsible for +// initializing the context with PeerCredKey. +func HandleRequest(backend Backend, limits Limits, conn Conn, ctx context.Context) (err error) { + defer func() { + if r := recover(); r != nil { + switch r := r.(type) { + case p.NslcdError: + err = r + default: + panic(r) + } + } + }() + + now := time.Now() + deadlineAll := time.Time{} + deadlineRead := time.Time{} + if limits.Timeout != 0 { + deadlineAll = now.Add(limits.Timeout) + } + if deadline, ok := ctx.Deadline(); ok { + if deadlineAll.IsZero() || deadline.Before(deadlineAll) { + deadlineAll = deadline + } + } + if limits.ReadTimeout != 0 { + deadlineRead = now.Add(limits.ReadTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineRead) { + deadlineRead = deadlineAll + } + } + deadlineWrite := deadlineAll + if !deadlineRead.IsZero() { + err = conn.SetReadDeadline(deadlineRead) + if err != nil { + return err + } + } + + log := LoggerFromContext(ctx) + + var in io.Reader = conn + if limits.RequestMaxSize > 0 { + in = &io.LimitedReader{R: in, N: limits.RequestMaxSize} + } + out := conn + + var version int32 + maybePanic(p.Read(in, &version)) + if version != p.NSLCD_VERSION { + return p.NslcdError(fmt.Sprintf("Version mismatch: server=%#08x client=%#08x", p.NSLCD_VERSION, version)) + } + var action int32 + maybePanic(p.Read(in, &action)) + + switch action { + case p.NSLCD_ACTION_CONFIG_GET: + var req p.Request_Config_Get + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Config_Get(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_ALIAS_BYNAME: + var req p.Request_Alias_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Alias_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_ALIAS_ALL: + var req p.Request_Alias_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Alias_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_ETHER_BYNAME: + var req p.Request_Ether_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Ether_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_ETHER_BYETHER: + var req p.Request_Ether_ByEther + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Ether_ByEther(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_ETHER_ALL: + var req p.Request_Ether_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Ether_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_GROUP_BYNAME: + var req p.Request_Group_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Group_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_GROUP_BYGID: + var req p.Request_Group_ByGid + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Group_ByGid(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_GROUP_BYMEMBER: + var req p.Request_Group_ByMember + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Group_ByMember(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_GROUP_ALL: + var req p.Request_Group_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Group_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_HOST_BYNAME: + var req p.Request_Host_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Host_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_HOST_BYADDR: + var req p.Request_Host_ByAddr + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Host_ByAddr(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_HOST_ALL: + var req p.Request_Host_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Host_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_NETGROUP_BYNAME: + var req p.Request_Netgroup_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Netgroup_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_NETGROUP_ALL: + var req p.Request_Netgroup_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Netgroup_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_NETWORK_BYNAME: + var req p.Request_Network_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Network_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_NETWORK_BYADDR: + var req p.Request_Network_ByAddr + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Network_ByAddr(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_NETWORK_ALL: + var req p.Request_Network_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Network_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PASSWD_BYNAME: + var req p.Request_Passwd_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Passwd_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PASSWD_BYUID: + var req p.Request_Passwd_ByUID + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Passwd_ByUID(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PASSWD_ALL: + var req p.Request_Passwd_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Passwd_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PROTOCOL_BYNAME: + var req p.Request_Protocol_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Protocol_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PROTOCOL_BYNUMBER: + var req p.Request_Protocol_ByNumber + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Protocol_ByNumber(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PROTOCOL_ALL: + var req p.Request_Protocol_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Protocol_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_RPC_BYNAME: + var req p.Request_RPC_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.RPC_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_RPC_BYNUMBER: + var req p.Request_RPC_ByNumber + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.RPC_ByNumber(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_RPC_ALL: + var req p.Request_RPC_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.RPC_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_SERVICE_BYNAME: + var req p.Request_Service_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Service_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_SERVICE_BYNUMBER: + var req p.Request_Service_ByNumber + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Service_ByNumber(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_SERVICE_ALL: + var req p.Request_Service_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Service_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_SHADOW_BYNAME: + var req p.Request_Shadow_ByName + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Shadow_ByName(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_SHADOW_ALL: + var req p.Request_Shadow_All + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.Shadow_All(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PAM_AUTHENTICATION: + var req p.Request_PAM_Authentication + maybePanic(p.Read(in, &req)) + _req := req + _req.Password = sensitive + log.Info(fmt.Sprintf("Request: %#v\n", _req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.PAM_Authentication(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PAM_AUTHORIZATION: + var req p.Request_PAM_Authorization + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.PAM_Authorization(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PAM_SESSIONOPEN: + var req p.Request_PAM_SessionOpen + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.PAM_SessionOpen(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PAM_SESSIONCLOSE: + var req p.Request_PAM_SessionClose + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.PAM_SessionClose(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_PAM_PWMOD: + var req p.Request_PAM_PwMod + maybePanic(p.Read(in, &req)) + _req := req + if len(_req.OldPassword) > 0 { + _req.OldPassword = sensitive + } + _req.NewPassword = sensitive + log.Info(fmt.Sprintf("Request: %#v", _req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.PAM_PwMod(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + case p.NSLCD_ACTION_USERMOD: + var req p.Request_UserMod + maybePanic(p.Read(in, &req)) + log.Info(fmt.Sprintf("Request: %#v", req)) + + if limits.WriteTimeout != 0 { + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) + if err != nil { + return err + } + } + + var cancel context.CancelFunc + if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { + ctx, cancel = context.WithDeadline(ctx, deadlineWrite) + } else { + ctx, cancel = context.WithCancel(ctx) + } + defer cancel() + + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.UserMod(ctx, req) + n := 0 + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) + } + n++ + log.Info(fmt.Sprintf("Wrote %d results / err = %v", n, err)) + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return ctx.Err() // probably nil + default: + return p.NslcdError(fmt.Sprintf("Unknown request action: %#08x", action)) + } +} diff --git a/nslcd_server/interface_backend.go b/nslcd_server/interface_backend.go new file mode 100644 index 0000000..de9b99a --- /dev/null +++ b/nslcd_server/interface_backend.go @@ -0,0 +1,55 @@ +// ./interface_backend.go.gen requests.txt +// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT + +package nslcd_server + +import ( + "context" + + p "git.lukeshu.com/go/libnslcd/nslcd_proto" +) + +// The Backend interface allows the backend store to be implemented +// separately from the protocol implementation. Each request type +// that the nslcd server may reply to is implemented simply as a +// method that returns a channel of the resulting values. +type Backend interface { + Config_Get(context.Context, p.Request_Config_Get) <-chan p.Config + Alias_ByName(context.Context, p.Request_Alias_ByName) <-chan p.Alias + Alias_All(context.Context, p.Request_Alias_All) <-chan p.Alias + Ether_ByName(context.Context, p.Request_Ether_ByName) <-chan p.Ether + Ether_ByEther(context.Context, p.Request_Ether_ByEther) <-chan p.Ether + Ether_All(context.Context, p.Request_Ether_All) <-chan p.Ether + Group_ByName(context.Context, p.Request_Group_ByName) <-chan p.Group + Group_ByGid(context.Context, p.Request_Group_ByGid) <-chan p.Group + Group_ByMember(context.Context, p.Request_Group_ByMember) <-chan p.Group + Group_All(context.Context, p.Request_Group_All) <-chan p.Group + Host_ByName(context.Context, p.Request_Host_ByName) <-chan p.Host + Host_ByAddr(context.Context, p.Request_Host_ByAddr) <-chan p.Host + Host_All(context.Context, p.Request_Host_All) <-chan p.Host + Netgroup_ByName(context.Context, p.Request_Netgroup_ByName) <-chan p.Netgroup + Netgroup_All(context.Context, p.Request_Netgroup_All) <-chan p.Netgroup + Network_ByName(context.Context, p.Request_Network_ByName) <-chan p.Network + Network_ByAddr(context.Context, p.Request_Network_ByAddr) <-chan p.Network + Network_All(context.Context, p.Request_Network_All) <-chan p.Network + Passwd_ByName(context.Context, p.Request_Passwd_ByName) <-chan p.Passwd + Passwd_ByUID(context.Context, p.Request_Passwd_ByUID) <-chan p.Passwd + Passwd_All(context.Context, p.Request_Passwd_All) <-chan p.Passwd + Protocol_ByName(context.Context, p.Request_Protocol_ByName) <-chan p.Protocol + Protocol_ByNumber(context.Context, p.Request_Protocol_ByNumber) <-chan p.Protocol + Protocol_All(context.Context, p.Request_Protocol_All) <-chan p.Protocol + RPC_ByName(context.Context, p.Request_RPC_ByName) <-chan p.RPC + RPC_ByNumber(context.Context, p.Request_RPC_ByNumber) <-chan p.RPC + RPC_All(context.Context, p.Request_RPC_All) <-chan p.RPC + Service_ByName(context.Context, p.Request_Service_ByName) <-chan p.Service + Service_ByNumber(context.Context, p.Request_Service_ByNumber) <-chan p.Service + Service_All(context.Context, p.Request_Service_All) <-chan p.Service + Shadow_ByName(context.Context, p.Request_Shadow_ByName) <-chan p.Shadow + Shadow_All(context.Context, p.Request_Shadow_All) <-chan p.Shadow + UserMod(context.Context, p.Request_UserMod) <-chan p.UserMod + PAM_Authentication(context.Context, p.Request_PAM_Authentication) <-chan p.PAM_Authentication + PAM_Authorization(context.Context, p.Request_PAM_Authorization) <-chan p.PAM_Authorization + PAM_SessionOpen(context.Context, p.Request_PAM_SessionOpen) <-chan p.PAM_SessionOpen + PAM_SessionClose(context.Context, p.Request_PAM_SessionClose) <-chan p.PAM_SessionClose + PAM_PwMod(context.Context, p.Request_PAM_PwMod) <-chan p.PAM_PwMod +} diff --git a/nslcd_server/requests.txt b/nslcd_server/requests.txt new file mode 100644 index 0000000..e5c3ada --- /dev/null +++ b/nslcd_server/requests.txt @@ -0,0 +1,38 @@ +Config_Get +Alias_ByName +Alias_All +Ether_ByName +Ether_ByEther +Ether_All +Group_ByName +Group_ByGid +Group_ByMember +Group_All +Host_ByName +Host_ByAddr +Host_All +Netgroup_ByName +Netgroup_All +Network_ByName +Network_ByAddr +Network_All +Passwd_ByName +Passwd_ByUID +Passwd_All +Protocol_ByName +Protocol_ByNumber +Protocol_All +RPC_ByName +RPC_ByNumber +RPC_All +Service_ByName +Service_ByNumber +Service_All +Shadow_ByName +Shadow_All +PAM_Authentication +PAM_Authorization +PAM_SessionOpen +PAM_SessionClose +PAM_PwMod +UserMod diff --git a/nslcd_server/type_nilbackend.go b/nslcd_server/type_nilbackend.go new file mode 100644 index 0000000..208b62f --- /dev/null +++ b/nslcd_server/type_nilbackend.go @@ -0,0 +1,209 @@ +// ./type_nilbackend.go.gen interface_backend.go +// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT + +package nslcd_server + +import ( + "context" + + p "git.lukeshu.com/go/libnslcd/nslcd_proto" +) + +// NilBackend implements the Backend interface, but only returns empty +// responses. It is useful to add as an anonymous member of a backend +// implementation that does not return results for all of the +// databases. +type NilBackend struct{} + +func (o NilBackend) Config_Get(context.Context, p.Request_Config_Get) <-chan p.Config { + r := make(chan p.Config) + close(r) + return r +} +func (o NilBackend) Alias_ByName(context.Context, p.Request_Alias_ByName) <-chan p.Alias { + r := make(chan p.Alias) + close(r) + return r +} +func (o NilBackend) Alias_All(context.Context, p.Request_Alias_All) <-chan p.Alias { + r := make(chan p.Alias) + close(r) + return r +} +func (o NilBackend) Ether_ByName(context.Context, p.Request_Ether_ByName) <-chan p.Ether { + r := make(chan p.Ether) + close(r) + return r +} +func (o NilBackend) Ether_ByEther(context.Context, p.Request_Ether_ByEther) <-chan p.Ether { + r := make(chan p.Ether) + close(r) + return r +} +func (o NilBackend) Ether_All(context.Context, p.Request_Ether_All) <-chan p.Ether { + r := make(chan p.Ether) + close(r) + return r +} +func (o NilBackend) Group_ByName(context.Context, p.Request_Group_ByName) <-chan p.Group { + r := make(chan p.Group) + close(r) + return r +} +func (o NilBackend) Group_ByGid(context.Context, p.Request_Group_ByGid) <-chan p.Group { + r := make(chan p.Group) + close(r) + return r +} +func (o NilBackend) Group_ByMember(context.Context, p.Request_Group_ByMember) <-chan p.Group { + r := make(chan p.Group) + close(r) + return r +} +func (o NilBackend) Group_All(context.Context, p.Request_Group_All) <-chan p.Group { + r := make(chan p.Group) + close(r) + return r +} +func (o NilBackend) Host_ByName(context.Context, p.Request_Host_ByName) <-chan p.Host { + r := make(chan p.Host) + close(r) + return r +} +func (o NilBackend) Host_ByAddr(context.Context, p.Request_Host_ByAddr) <-chan p.Host { + r := make(chan p.Host) + close(r) + return r +} +func (o NilBackend) Host_All(context.Context, p.Request_Host_All) <-chan p.Host { + r := make(chan p.Host) + close(r) + return r +} +func (o NilBackend) Netgroup_ByName(context.Context, p.Request_Netgroup_ByName) <-chan p.Netgroup { + r := make(chan p.Netgroup) + close(r) + return r +} +func (o NilBackend) Netgroup_All(context.Context, p.Request_Netgroup_All) <-chan p.Netgroup { + r := make(chan p.Netgroup) + close(r) + return r +} +func (o NilBackend) Network_ByName(context.Context, p.Request_Network_ByName) <-chan p.Network { + r := make(chan p.Network) + close(r) + return r +} +func (o NilBackend) Network_ByAddr(context.Context, p.Request_Network_ByAddr) <-chan p.Network { + r := make(chan p.Network) + close(r) + return r +} +func (o NilBackend) Network_All(context.Context, p.Request_Network_All) <-chan p.Network { + r := make(chan p.Network) + close(r) + return r +} +func (o NilBackend) Passwd_ByName(context.Context, p.Request_Passwd_ByName) <-chan p.Passwd { + r := make(chan p.Passwd) + close(r) + return r +} +func (o NilBackend) Passwd_ByUID(context.Context, p.Request_Passwd_ByUID) <-chan p.Passwd { + r := make(chan p.Passwd) + close(r) + return r +} +func (o NilBackend) Passwd_All(context.Context, p.Request_Passwd_All) <-chan p.Passwd { + r := make(chan p.Passwd) + close(r) + return r +} +func (o NilBackend) Protocol_ByName(context.Context, p.Request_Protocol_ByName) <-chan p.Protocol { + r := make(chan p.Protocol) + close(r) + return r +} +func (o NilBackend) Protocol_ByNumber(context.Context, p.Request_Protocol_ByNumber) <-chan p.Protocol { + r := make(chan p.Protocol) + close(r) + return r +} +func (o NilBackend) Protocol_All(context.Context, p.Request_Protocol_All) <-chan p.Protocol { + r := make(chan p.Protocol) + close(r) + return r +} +func (o NilBackend) RPC_ByName(context.Context, p.Request_RPC_ByName) <-chan p.RPC { + r := make(chan p.RPC) + close(r) + return r +} +func (o NilBackend) RPC_ByNumber(context.Context, p.Request_RPC_ByNumber) <-chan p.RPC { + r := make(chan p.RPC) + close(r) + return r +} +func (o NilBackend) RPC_All(context.Context, p.Request_RPC_All) <-chan p.RPC { + r := make(chan p.RPC) + close(r) + return r +} +func (o NilBackend) Service_ByName(context.Context, p.Request_Service_ByName) <-chan p.Service { + r := make(chan p.Service) + close(r) + return r +} +func (o NilBackend) Service_ByNumber(context.Context, p.Request_Service_ByNumber) <-chan p.Service { + r := make(chan p.Service) + close(r) + return r +} +func (o NilBackend) Service_All(context.Context, p.Request_Service_All) <-chan p.Service { + r := make(chan p.Service) + close(r) + return r +} +func (o NilBackend) Shadow_ByName(context.Context, p.Request_Shadow_ByName) <-chan p.Shadow { + r := make(chan p.Shadow) + close(r) + return r +} +func (o NilBackend) Shadow_All(context.Context, p.Request_Shadow_All) <-chan p.Shadow { + r := make(chan p.Shadow) + close(r) + return r +} +func (o NilBackend) UserMod(context.Context, p.Request_UserMod) <-chan p.UserMod { + r := make(chan p.UserMod) + close(r) + return r +} +func (o NilBackend) PAM_Authentication(context.Context, p.Request_PAM_Authentication) <-chan p.PAM_Authentication { + r := make(chan p.PAM_Authentication) + close(r) + return r +} +func (o NilBackend) PAM_Authorization(context.Context, p.Request_PAM_Authorization) <-chan p.PAM_Authorization { + r := make(chan p.PAM_Authorization) + close(r) + return r +} +func (o NilBackend) PAM_SessionOpen(context.Context, p.Request_PAM_SessionOpen) <-chan p.PAM_SessionOpen { + r := make(chan p.PAM_SessionOpen) + close(r) + return r +} +func (o NilBackend) PAM_SessionClose(context.Context, p.Request_PAM_SessionClose) <-chan p.PAM_SessionClose { + r := make(chan p.PAM_SessionClose) + close(r) + return r +} +func (o NilBackend) PAM_PwMod(context.Context, p.Request_PAM_PwMod) <-chan p.PAM_PwMod { + r := make(chan p.PAM_PwMod) + close(r) + return r +} + +var _ Backend = NilBackend{} -- cgit v1.2.3-54-g00ecf