summaryrefslogtreecommitdiff
path: root/nslcd_proto/nslcd_h.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-09-04 19:11:14 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-09-08 16:55:55 -0400
commit542c732b94e0a5e7c02fd209a60bd068dbbfa03b (patch)
tree780a49011174abc3f01f5110fc590d107989518a /nslcd_proto/nslcd_h.go
parent3e1d4d0c562ab99e5a81030a08d224e8174152b9 (diff)
nslcd_proto: BREAKING CHANGE: Rethink the panic strategy
nslcd_proto.Read() and .Write() panic() with any errors that they may need to emit. This made composition really simple, I was OK with it being against the normal Go style. But, I'm not happy with it anymore; have them return errors now. This leads us in to nslcd_server.HandleRequest() using those panics for control flow. Add a maybePanic(error) function to wrap all of the proto.Read() and proto.Write() calls to restore the panicing behavior.
Diffstat (limited to 'nslcd_proto/nslcd_h.go')
-rw-r--r--nslcd_proto/nslcd_h.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/nslcd_proto/nslcd_h.go b/nslcd_proto/nslcd_h.go
index cb210cd..d8eee9f 100644
--- a/nslcd_proto/nslcd_h.go
+++ b/nslcd_proto/nslcd_h.go
@@ -1,5 +1,5 @@
// This file is based heavily on nslcd.h from nss-pam-ldapd
-// Copyright (C) 2015 Luke Shumaker
+// Copyright (C) 2015, 2017 Luke Shumaker
/*
nslcd.h - file describing client/server protocol
@@ -171,19 +171,19 @@ func (data Netgroup_PartList) nslcdWrite(fd io.Writer) {
t = NSLCD_NETGROUP_TYPE_TRIPLE
}
if t < 0 {
- panic("unrecognized netgroup type")
+ panic(fmt.Sprintf("unrecognized netgroup type: %#08x", t))
}
- Write(fd, t)
- Write(fd, part)
+ write(fd, t)
+ write(fd, part)
}
- Write(fd, NSLCD_NETGROUP_TYPE_END)
+ write(fd, NSLCD_NETGROUP_TYPE_END)
}
func (data *Netgroup_PartList) nslcdRead(fd io.Reader) {
*data = make([]interface{}, 0)
for {
var t int32
var v interface{}
- Read(fd, &t)
+ read(fd, &t)
switch t {
case NSLCD_NETGROUP_TYPE_NETGROUP:
v = Netgroup_Netgroup{}
@@ -192,9 +192,9 @@ func (data *Netgroup_PartList) nslcdRead(fd io.Reader) {
case NSLCD_NETGROUP_TYPE_END:
return
default:
- panic(NslcdError(fmt.Sprintf("unrecognized netgroup type: %#08x", t)))
+ npanic(NslcdError(fmt.Sprintf("unrecognized netgroup type: %#08x", t)))
}
- Read(fd, &v)
+ read(fd, &v)
*data = append(*data, v)
}
}
@@ -384,20 +384,20 @@ type UserMod_Item struct {
type UserMod_ItemList []UserMod_Item
func (data UserMod_ItemList) nslcdWrite(fd io.Writer) {
for _, item := range data {
- Write(fd, item)
+ write(fd, item)
}
- Write(fd, NSLCD_USERMOD_END)
+ write(fd, NSLCD_USERMOD_END)
}
func (data *UserMod_ItemList) nslcdRead(fd io.Reader) {
*data = make([]UserMod_Item, 0)
for {
var t int32
- Read(fd, &t)
+ read(fd, &t)
if t == NSLCD_USERMOD_END {
return
}
var v UserMod_Item
- Read(fd, &v)
+ read(fd, &v)
*data = append(*data, v)
}
}