From 379e4d7e4d2539f35d559d4b0752531e546238a9 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 18 Dec 2017 15:07:24 -0500 Subject: nslcd_{server,systemd}: BREAKING CHANGE: use contexts --- nslcd_server/ctx.go | 46 ++++++++++++++++++++++++++++++++++ nslcd_server/func_handlerequest.go.gen | 26 +++++++++++++++---- nslcd_server/interface_backend.go.gen | 9 ++++--- nslcd_server/type_nilbackend.go.gen | 7 +++--- nslcd_systemd/misc_test.go | 7 +++--- nslcd_systemd/nslcd_systemd.go | 23 +++++++++++++---- 6 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 nslcd_server/ctx.go diff --git a/nslcd_server/ctx.go b/nslcd_server/ctx.go new file mode 100644 index 0000000..5214adc --- /dev/null +++ b/nslcd_server/ctx.go @@ -0,0 +1,46 @@ +// Copyright (C) 2017 Luke Shumaker +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301 USA + +package nslcd_server + +import ( + "context" + + "golang.org/x/sys/unix" +) + +// contextKey is a value for use with context.WithValue. It's used as +// a pointer so it fits in an interface{} without allocation. +type contextKey struct { + name string +} + +var ( + // PeerCredKey is a context key. It can be used in backend + // methods to access the credentials of the client process. + // The associated value will be of type + // "golang.org/x/sys/unix".Ucred + PeerCredKey = &contextKey{"peercred"} +) + +// PeerCredFromContext is a convenience function for +// +// cred, ok := ctx.Value(nslcd_server.PeerCredKey).(unix.Ucred) +func PeerCredFromContext(ctx context.Context) (unix.Ucred, bool) { + cred, ok := ctx.Value(PeerCredKey).(unix.Ucred) + return cred, ok +} diff --git a/nslcd_server/func_handlerequest.go.gen b/nslcd_server/func_handlerequest.go.gen index 00e9663..750a7b0 100755 --- a/nslcd_server/func_handlerequest.go.gen +++ b/nslcd_server/func_handlerequest.go.gen @@ -25,12 +25,12 @@ cat < +# Copyright (C) 2015, 2017 Luke Shumaker # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -24,7 +24,8 @@ cat <