From 13bb2e14fcdd260d060b7240357d4a8a80002114 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 26 Aug 2015 20:25:52 -0600 Subject: work --- src/nslcd_proto/enumerator@T.got | 19 +++++++++++++++---- src/nslcd_proto/func_handlerequest.go.sh | 5 +++-- src/nslcd_proto/io.go | 12 +++++------- src/nslcd_proto/nslcd_h.go | 3 +++ src/nslcd_proto/struct_backend.go.sh | 6 ++++-- src/nslcd_proto/util.go | 14 ++++++-------- 6 files changed, 36 insertions(+), 23 deletions(-) (limited to 'src/nslcd_proto') 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 _Enumerator interface { - GetNext() (n , err error) + GetNext() (n *, err error) GenericGetNext() (n interface{}, err error) } @@ -15,12 +15,23 @@ func New__List(ary []) *_List { return &_List{ary, 0} } -func (o *_List) GetNext() (n , err error) { - n = o.dat[o.i] +func (o *_List) GetNext() (n *, err error) { + if o.i < len(o.dat) { + n = &o.dat[o.i] + o.i++ + } err = nil - o.i++ return } func (o *_List) GenericGetNext() (n interface{}, err error) { return o.GetNext() } + +type _Ø struct{} + +func (o *_Ø) GetNext() (*, error) { + return nil, nil +} +func (o *_Ø) 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 -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 <