#!/usr/bin/env bash # -*- Mode: Go -*- # 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 # 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 requests=$1 printf '//' printf ' %q' "$0" "$@" printf '\n// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT\n\n' cat < 0 { in = &io.LimitedReader{R: in, N: limits.RequestMaxSize} } out := conn var version int32 maybePanic(p.Read(in, &version)) if version != p.NSLCD_VERSION { return p.NslcdError(fmt.Sprintf("Version mismatch: server=%#08x client=%#08x", p.NSLCD_VERSION, version)) } var action int32 maybePanic(p.Read(in, &action)) switch action { $( while read -r request; do cat < 0 {' echo ' _req.OldPassword = sensitive' echo '}' echo '_req.NewPassword = sensitive' echo 'log.Info(fmt.Sprintf("Request: %#v", _req))' ;; PAM_UserMod) echo '_req := req' echo '_req.Password = sensitive' echo 'log.Info(fmt.Sprintf("Request: %#v", _req))' ;; *) echo 'log.Info(fmt.Sprintf("Request: %#v", req))' ;; esac ) if limits.WriteTimeout != 0 { deadlineWrite = time.Now().Add(limits.WriteTimeout) if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { deadlineWrite = deadlineAll } } if !deadlineWrite.IsZero() { err = out.SetWriteDeadline(deadlineWrite) if err != nil { return err } } var cancel context.CancelFunc if deadline, ok := ctx.Deadline(); !ok || (!deadlineWrite.IsZero() && deadline.After(deadlineWrite)) { ctx, cancel = context.WithDeadline(ctx, deadlineWrite) } else { ctx, cancel = context.WithCancel(ctx) } defer cancel() maybePanic(p.Write(out, p.NSLCD_VERSION)) maybePanic(p.Write(out, action)) ch := backend.${request}(ctx, req) for result := range ch { if err == nil { err = p.Write(out, p.NSLCD_RESULT_BEGIN) } if err == nil { err = p.Write(out, result) } } maybePanic(err) maybePanic(p.Write(out, p.NSLCD_RESULT_END)) return ctx.Err() // probably nil EOT done < "$requests" ) default: return p.NslcdError(fmt.Sprintf("Unknown request action: %#08x", action)) } } EOF