summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nshd/main.go19
-rw-r--r--src/nslcd_proto/.gitignore3
-rw-r--r--src/nslcd_proto/Makefile39
-rw-r--r--src/nslcd_proto/enumerator@T.got9
-rwxr-xr-xsrc/nslcd_proto/func_handlerequest.go.sh3
-rwxr-xr-xsrc/nslcd_proto/interface_backend.go.sh17
-rwxr-xr-xsrc/nslcd_proto/struct_backend.go.sh12
-rwxr-xr-xsrc/nslcd_proto/struct_null_backend.go.sh12
-rw-r--r--src/nslcd_proto/util.go7
-rw-r--r--src/nslcd_systemd/nslcd_systemd.go12
10 files changed, 91 insertions, 42 deletions
diff --git a/src/nshd/main.go b/src/nshd/main.go
index 986e019..8230734 100644
--- a/src/nshd/main.go
+++ b/src/nshd/main.go
@@ -3,9 +3,26 @@ package main
import (
_ "golang.org/x/exp/inotify"
_ "gopkg.in/yaml.v2"
+ "nslcd_proto"
"nslcd_systemd"
)
+type hackersBackend struct {
+ nslcd_proto.NullBackend
+}
+
+var _ nslcd_systemd.Backend = &hackersBackend{}
+
+func (o *hackersBackend) Reload() {
+ // TODO
+}
+
+func newHackersBackend() *hackersBackend {
+ // TODO
+ return &hackersBackend{}
+}
+
func main() {
- nslcd_systemd.Main(nil)
+ backend := newHackersBackend()
+ nslcd_systemd.Main(backend)
}
diff --git a/src/nslcd_proto/.gitignore b/src/nslcd_proto/.gitignore
index 8a88ae3..c655813 100644
--- a/src/nslcd_proto/.gitignore
+++ b/src/nslcd_proto/.gitignore
@@ -1,4 +1,5 @@
-/struct_backend.go
+/interface_backend.go
+/struct_null_backend.go
/func_handlerequest.go
/requests.txt
/responses.txt
diff --git a/src/nslcd_proto/Makefile b/src/nslcd_proto/Makefile
index 2014bdd..fcb46d6 100644
--- a/src/nslcd_proto/Makefile
+++ b/src/nslcd_proto/Makefile
@@ -1,31 +1,44 @@
-all: struct_backend.go func_handlerequest.go
+_ := $(MAKEFILE_LIST)
+d := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
+
+generate := $d/interface_backend.go $d/func_handlerequest.go $d/struct_null_backend.go
+secondary := $d/enumerator-list.mk $d/requests.txt $d/responses.txt $d/enumerator@*.go
+
+ifeq (,$(filter clean,$(MAKECMDGOALS)))
+-include $d/enumerator-list.mk
+endif
+
+ifeq (1,$(words $_))
+
+all: generate
.PHONY: all
+generate: $(generate)
+.PHONY: generate
+
clean:
- rm -f -- struct_backend.go func_handlerequest.go enumerator@*.go
- rm -f -- enumerator-list.mk requests.txt responses.txt
+ rm -f -- $(generate) $(secondary)
.PHONY: clean
-ifeq (,$(filter clean,$(MAKECMDGOALS)))
--include enumerator-list.mk
endif
-
-enumerator@%.go: enumerator@T.got
+
+$d/enumerator@%.go: $d/enumerator@T.got
< $< sed 's/<T>/$*/g' > $@
-enumerator-list.mk: responses.txt Makefile
- < $< sed -rn 's/.*/all: enumerator@&.go/p' > $@
+$d/enumerator-list.mk: $d/responses.txt $d/Makefile
+ < $< sed -rn 's|.*|generate += $$d/enumerator@&.go|p' > $@
-requests.txt: nslcd_h.go Makefile
+$d/requests.txt: $d/nslcd_h.go $d/Makefile
< $< grep -Eo 'Request_([^_ ]+)(_\S+)?' | sed 's/^Request_//' > $@
-responses.txt: struct_backend.go Makefile
+$d/responses.txt: $d/interface_backend.go $d/Makefile
< $< sed -rn 's/.* (\S+)_Enumerator$$/\1/p' | sort -u > $@
%.go: %.go.sh
./$^ > $@
-struct_backend.go: requests.txt
-func_handlerequest.go: requests.txt
+$d/interface_backend.go: $d/requests.txt
+$d/func_handlerequest.go: $d/requests.txt
+$d/struct_null_backend.go: $d/interface_backend.go
.DELETE_ON_ERROR:
.SECONDARY:
diff --git a/src/nslcd_proto/enumerator@T.got b/src/nslcd_proto/enumerator@T.got
index 06d6171..5a540ae 100644
--- a/src/nslcd_proto/enumerator@T.got
+++ b/src/nslcd_proto/enumerator@T.got
@@ -11,6 +11,8 @@ type <T>_List struct {
i int
}
+var _ <T>_Enumerator = &<T>_List{}
+
func New_<T>_List(ary []<T>) *<T>_List {
return &<T>_List{ary, 0}
}
@@ -23,15 +25,18 @@ func (o *<T>_List) GetNext() (n *<T>, err error) {
err = nil
return
}
+
func (o *<T>_List) GenericGetNext() (n interface{}, err error) {
return o.GetNext()
}
type <T>_Ø struct{}
-func (o *<T>_Ø) GetNext() (*<T>, error) {
+var _ <T>_Enumerator = <T>_Ø{}
+
+func (o <T>_Ø) GetNext() (*<T>, error) {
return nil, nil
}
-func (o *<T>_Ø) GenericGetNext() (interface{}, error) {
+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 6c6f988..4008dd5 100755
--- a/src/nslcd_proto/func_handlerequest.go.sh
+++ b/src/nslcd_proto/func_handlerequest.go.sh
@@ -7,14 +7,13 @@ package nslcd_proto
import (
"fmt"
"io"
- "syscall"
)
type enumerator interface {
GenericGetNext() (n interface{}, err error)
}
-func handleRequest(backend Backend, in io.Reader, out io.Writer, cred syscall.Ucred) {
+func handleRequest(backend Backend, in io.Reader, out io.Writer, cred Ucred) {
var version int32
read(in, &version)
if version != NSLCD_VERSION {
diff --git a/src/nslcd_proto/interface_backend.go.sh b/src/nslcd_proto/interface_backend.go.sh
new file mode 100755
index 0000000..99e0a36
--- /dev/null
+++ b/src/nslcd_proto/interface_backend.go.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+# -*- Mode: Go -*-
+requests=$1
+cat <<EOF | gofmt
+package nslcd_proto
+
+import "syscall"
+
+type Ucred struct {
+ syscall.Ucred
+}
+
+type Backend interface {
+ $(sed -rn 's/([^_]+)(.*)/\1\2(Ucred, Request_\1\2) \1_Enumerator/p' "$requests" | grep -v PAM)
+ $(sed -rn 's/(PAM)(.*)/\1\2(Ucred, Request_\1\2) \1\2_Enumerator/p' "$requests")
+}
+EOF
diff --git a/src/nslcd_proto/struct_backend.go.sh b/src/nslcd_proto/struct_backend.go.sh
deleted file mode 100755
index 4728a87..0000000
--- a/src/nslcd_proto/struct_backend.go.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env bash
-requests=$1
-cat <<EOF | gofmt
-package nslcd_proto
-
-import "syscall"
-
-type Backend interface {
- $(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/struct_null_backend.go.sh b/src/nslcd_proto/struct_null_backend.go.sh
new file mode 100755
index 0000000..99788aa
--- /dev/null
+++ b/src/nslcd_proto/struct_null_backend.go.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+# -*- Mode: Go -*-
+interface=$1
+cat <<EOF | gofmt
+package nslcd_proto
+
+type NullBackend struct{}
+
+$(< "$interface" sed -rn 's/^\t(.*\) (\S+)_Enumerator)$/func (o NullBackend) \1 { return \2_Ø{} }/p')
+
+var _ Backend = NullBackend{}
+EOF
diff --git a/src/nslcd_proto/util.go b/src/nslcd_proto/util.go
index 1f38c8e..de00445 100644
--- a/src/nslcd_proto/util.go
+++ b/src/nslcd_proto/util.go
@@ -1,9 +1,6 @@
package nslcd_proto
-import (
- "io"
- "syscall"
-)
+import "io"
type NslcdError string
@@ -43,7 +40,7 @@ func Read(fd io.Reader, data interface{}) (err error) {
return
}
-func HandleRequest(backend Backend, in io.Reader, out io.Writer, cred syscall.Ucred) (err error) {
+func HandleRequest(backend Backend, in io.Reader, out io.Writer, cred Ucred) (err error) {
err = nil
defer func() {
if r := recover(); r != nil {
diff --git a/src/nslcd_systemd/nslcd_systemd.go b/src/nslcd_systemd/nslcd_systemd.go
index 80e23b2..9868581 100644
--- a/src/nslcd_systemd/nslcd_systemd.go
+++ b/src/nslcd_systemd/nslcd_systemd.go
@@ -34,14 +34,14 @@ func get_socket() (socket net.Listener, err error) {
return
}
-func getpeercred(conn *net.UnixConn) (cred *syscall.Ucred, err error) {
- cred = nil
+func getpeercred(conn *net.UnixConn) (cred nslcd_proto.Ucred, err error) {
file, err := conn.File()
if err != nil {
return
}
defer file.Close()
- cred, err = syscall.GetsockoptUcred(int(file.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED)
+ _cred, err := syscall.GetsockoptUcred(int(file.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED)
+ cred = nslcd_proto.Ucred{*_cred}
return
}
@@ -54,7 +54,7 @@ func handler(conn *net.UnixConn, backend nslcd_proto.Backend) {
logger.Debug("connection from pid=%v uid=%v gid=%v",
cred.Pid, cred.Uid, cred.Gid)
}
- err = nslcd_proto.HandleRequest(backend, conn, conn, *cred)
+ err = nslcd_proto.HandleRequest(backend, conn, conn, cred)
if err != nil {
logger.Debug("Error while handling request: %v", err)
}
@@ -89,10 +89,10 @@ func Main(backend Backend) {
sock <- conn.(*net.UnixConn)
}
}()
-
+
var wg sync.WaitGroup
sd.Notify(false, "READY=1")
-Loop:
+Loop:
for {
select {
case sig := <-sigs: