1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#!/usr/bin/env bash
# -*- Mode: Go -*-
requests=$1
cat <<EOF
package nslcd_proto
import (
"fmt"
"io"
)
type enumerator interface {
GenericGetNext() (n interface{}, err error)
}
func handleRequest(backend Backend, in io.Reader, out io.Writer, cred Ucred) {
var version int32
read(in, &version)
if version != NSLCD_VERSION {
panic(NslcdError(fmt.Sprintf("version mismatch: server=%#08x client=%#08x", NSLCD_VERSION, version)))
}
var action int32
read(in, &action)
var res enumerator = nil
switch action {
$(
while read -r request; do
cat <<EOT
case NSLCD_ACTION_${request^^}:
var req Request_${request}
read(in, &req)
fmt.Printf("request: %#v\n", req)
res = backend.${request}(cred, req)
EOT
done < "$requests"
)
default:
panic(NslcdError(fmt.Sprintf("unknown request action: %#08x", action)))
}
if res == nil {
return
}
write(out, NSLCD_VERSION)
write(out, action)
var result interface{}
var err error
for result, err = res.GenericGetNext(); (result != nil) && (err == nil); result, err = res.GenericGetNext() {
write(out, NSLCD_RESULT_BEGIN)
write(out, result)
}
if err != nil {
panic(err)
}
write(out, NSLCD_RESULT_END)
}
EOF
|