go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/auth/unix/unix.go (about) 1 // Copyright ©2018 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package unix contains the implementation of unix security provider. 6 package unix // import "go-hep.org/x/hep/xrootd/xrdproto/auth/unix" 7 8 import ( 9 "os/user" 10 11 "go-hep.org/x/hep/xrootd/xrdproto/auth" 12 ) 13 14 // Default is an unix security provider configured from current username and group. 15 // If the credentials could not be correctly configured, Default will be nil. 16 var Default auth.Auther 17 18 func init() { 19 u, err := user.Current() 20 if err != nil { 21 return 22 } 23 g, err := lookupGroupID(u) 24 if err != nil { 25 return 26 } 27 Default = &Auth{User: u.Username, Group: g} 28 } 29 30 // Auth implements unix security provider. 31 type Auth struct { 32 User string 33 Group string 34 } 35 36 // Provider implements auth.Auther 37 func (*Auth) Provider() string { 38 return "unix" 39 } 40 41 // Type indicates that unix authentication protocol is used. 42 var Type = [4]byte{'u', 'n', 'i', 'x'} 43 44 // Request implements auth.Auther 45 func (a *Auth) Request(params []string) (*auth.Request, error) { 46 return &auth.Request{Type: Type, Credentials: "unix\000" + a.User + " " + a.Group + "\000"}, nil 47 } 48 49 var ( 50 _ auth.Auther = (*Auth)(nil) 51 )