From 542c732b94e0a5e7c02fd209a60bd068dbbfa03b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 4 Sep 2017 19:11:14 -0400 Subject: 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. --- nslcd_proto/nslcd_h.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'nslcd_proto/nslcd_h.go') 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) } } -- cgit v1.2.3-2-g168b