diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-08-26 20:25:52 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-08-26 20:25:52 -0600 |
commit | 13bb2e14fcdd260d060b7240357d4a8a80002114 (patch) | |
tree | 8bd49d988aa597c98578833b0b82b952b203c98b /src/nslcd_proto | |
parent | a6ac8f680062069b2821214f5b74cc96673ee4ca (diff) |
work
Diffstat (limited to 'src/nslcd_proto')
-rw-r--r-- | src/nslcd_proto/enumerator@T.got | 19 | ||||
-rwxr-xr-x | src/nslcd_proto/func_handlerequest.go.sh | 5 | ||||
-rw-r--r-- | src/nslcd_proto/io.go | 12 | ||||
-rw-r--r-- | src/nslcd_proto/nslcd_h.go | 3 | ||||
-rwxr-xr-x | src/nslcd_proto/struct_backend.go.sh | 6 | ||||
-rw-r--r-- | src/nslcd_proto/util.go | 14 |
6 files changed, 36 insertions, 23 deletions
diff --git a/src/nslcd_proto/enumerator@T.got b/src/nslcd_proto/enumerator@T.got index 88c3603..06d6171 100644 --- a/src/nslcd_proto/enumerator@T.got +++ b/src/nslcd_proto/enumerator@T.got @@ -2,7 +2,7 @@ package nslcd_proto type <T>_Enumerator interface { - GetNext() (n <T>, err error) + GetNext() (n *<T>, err error) GenericGetNext() (n interface{}, err error) } @@ -15,12 +15,23 @@ func New_<T>_List(ary []<T>) *<T>_List { return &<T>_List{ary, 0} } -func (o *<T>_List) GetNext() (n <T>, err error) { - n = o.dat[o.i] +func (o *<T>_List) GetNext() (n *<T>, err error) { + if o.i < len(o.dat) { + n = &o.dat[o.i] + o.i++ + } err = nil - o.i++ return } func (o *<T>_List) GenericGetNext() (n interface{}, err error) { return o.GetNext() } + +type <T>_Ø struct{} + +func (o *<T>_Ø) GetNext() (*<T>, error) { + return nil, nil +} +func (o *<T>_Ø) GenericGetNext() (interface{}, error) { + return nil, nil +} diff --git a/src/nslcd_proto/func_handlerequest.go.sh b/src/nslcd_proto/func_handlerequest.go.sh index 0f0c686..6c6f988 100755 --- a/src/nslcd_proto/func_handlerequest.go.sh +++ b/src/nslcd_proto/func_handlerequest.go.sh @@ -7,13 +7,14 @@ package nslcd_proto import ( "fmt" "io" + "syscall" ) type enumerator interface { GenericGetNext() (n interface{}, err error) } -func handleRequest(in io.Reader, out io.Writer, backend Backend) { +func handleRequest(backend Backend, in io.Reader, out io.Writer, cred syscall.Ucred) { var version int32 read(in, &version) if version != NSLCD_VERSION { @@ -30,7 +31,7 @@ while read -r request; do case NSLCD_ACTION_${request^^}: var req Request_${request} read(in, &req) - res = backend.${request}(req) + res = backend.${request}(cred, req) EOT done < "$requests" ) diff --git a/src/nslcd_proto/io.go b/src/nslcd_proto/io.go index 0804e98..e31aabc 100644 --- a/src/nslcd_proto/io.go +++ b/src/nslcd_proto/io.go @@ -6,11 +6,9 @@ import ( "io" "net" "reflect" + "syscall" ) -//#include <sys/socket.h> -import "C" - type NslcdObject interface { NslcdWrite(fd io.Writer) } @@ -46,9 +44,9 @@ func write(fd io.Writer, data interface{}) { var af int32 = -1 switch len(data) { case net.IPv4len: - af = C.AF_INET + af = syscall.AF_INET case net.IPv6len: - af = C.AF_INET6 + af = syscall.AF_INET6 } var bytes []byte if af < 0 { @@ -112,9 +110,9 @@ func read(fd io.Reader, data interface{}) { read(fd, &af) var _len int32 switch af { - case C.AF_INET: + case syscall.AF_INET: _len = net.IPv4len - case C.AF_INET6: + case syscall.AF_INET6: _len = net.IPv6len default: panic(NslcdError(fmt.Sprintf("incorrect address family specified: %d", af))) diff --git a/src/nslcd_proto/nslcd_h.go b/src/nslcd_proto/nslcd_h.go index 56c1316..4034472 100644 --- a/src/nslcd_proto/nslcd_h.go +++ b/src/nslcd_proto/nslcd_h.go @@ -1,4 +1,5 @@ // This file is based heavily on nslcd.h from nss-pam-ldapd +// Copyright (C) 2015 Luke Shumaker /* nslcd.h - file describing client/server protocol @@ -272,6 +273,8 @@ const NSLCD_ACTION_SERVICE_ALL int32 = 0x000b0008; type Request_Service_Al /* Extended user account (/etc/shadow) information requests. Result values for a single entry are: */ type Shadow struct { + // It is my understanding that an empty value for an INT32 + // field is expressed with a negative number. -- lukeshu Name string Password string LastChangeDate int32 diff --git a/src/nslcd_proto/struct_backend.go.sh b/src/nslcd_proto/struct_backend.go.sh index 792ae84..4728a87 100755 --- a/src/nslcd_proto/struct_backend.go.sh +++ b/src/nslcd_proto/struct_backend.go.sh @@ -3,8 +3,10 @@ requests=$1 cat <<EOF | gofmt package nslcd_proto +import "syscall" + type Backend interface { - $(sed -rn 's/([^_]+)(.*)/\1\2(Request_\1\2) \1_Enumerator/p' "$requests" | grep -v PAM) - $(sed -rn 's/(PAM)(.*)/\1\2(Request_\1\2) \1\2_Enumerator/p' "$requests") + $(sed -rn 's/([^_]+)(.*)/\1\2(syscall.Ucred, Request_\1\2) \1_Enumerator/p' "$requests" | grep -v PAM) + $(sed -rn 's/(PAM)(.*)/\1\2(syscall.Ucred, Request_\1\2) \1\2_Enumerator/p' "$requests") } EOF diff --git a/src/nslcd_proto/util.go b/src/nslcd_proto/util.go index 38c5705..1f38c8e 100644 --- a/src/nslcd_proto/util.go +++ b/src/nslcd_proto/util.go @@ -1,6 +1,9 @@ package nslcd_proto -import "io" +import ( + "io" + "syscall" +) type NslcdError string @@ -40,7 +43,7 @@ func Read(fd io.Reader, data interface{}) (err error) { return } -func HandleRequest(in io.Reader, out io.Writer, backend Backend) (err error) { +func HandleRequest(backend Backend, in io.Reader, out io.Writer, cred syscall.Ucred) (err error) { err = nil defer func() { if r := recover(); r != nil { @@ -52,11 +55,6 @@ func HandleRequest(in io.Reader, out io.Writer, backend Backend) (err error) { } } }() - handleRequest(in, out, backend) + handleRequest(backend, in, out, cred) return } - -// Initialize() error { func -// e := c.SetReadDeadline(...) -// e := c.SetWriteDeadline(...) -// } |