// +build pam// Copyright 2014 The Gogs Authors. All rights reserved.// Use of this source code is governed by a MIT-style// license that can be found in the LICENSE file.packagepamimport("errors""github.com/msteinert/pam")funcPAMAuth(serviceName,userName,passwdstring)error{t,err:=pam.StartFunc(serviceName,userName,func(spam.Style,msgstring)(string,error){switchs{casepam.PromptEchoOff:returnpasswd,nilcasepam.PromptEchoOn,pam.ErrorMsg,pam.TextInfo:return"",nil}return"",errors.New("Unrecognized PAM message style")})iferr!=nil{returnerr}iferr=t.Authenticate(0);err!=nil{returnerr}returnnil}