Mercurial > go > multipass
comparison file/file.go @ 13:da6c493cf08a
Move Unix-specific user auth files into unix_users.go.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Thu, 29 Oct 2015 21:29:27 -0400 |
| parents | 1246b4b9028b |
| children | 9b4ec6b5c23e |
comparison
equal
deleted
inserted
replaced
| 12:1c194fa9bbf4 | 13:da6c493cf08a |
|---|---|
| 8 | 8 |
| 9 import ( | 9 import ( |
| 10 "bufio" | 10 "bufio" |
| 11 "errors" | 11 "errors" |
| 12 "os" | 12 "os" |
| 13 "os/user" | |
| 14 "path" | |
| 15 "syscall" | 13 "syscall" |
| 16 "time" | 14 "time" |
| 17 | 15 |
| 18 "golang.org/x/sys/unix" | 16 "golang.org/x/sys/unix" |
| 19 "pfish.zone/go/multipass/auth" | 17 "pfish.zone/go/multipass/auth" |
| 29 ErrorBadFile = errors.New("multipass/file: Invalid file format") | 27 ErrorBadFile = errors.New("multipass/file: Invalid file format") |
| 30 ) | 28 ) |
| 31 | 29 |
| 32 type ShadowFile struct { | 30 type ShadowFile struct { |
| 33 name string | 31 name string |
| 34 } | |
| 35 | |
| 36 // ForUser gets the given user's ShadowFile. | |
| 37 func ForUser(username string) (*ShadowFile, error) { | |
| 38 u, err := user.Lookup(username) | |
| 39 if err != nil { | |
| 40 return nil, err | |
| 41 } | |
| 42 return New(path.Join(u.HomeDir, MultipassFile)), nil | |
| 43 } | |
| 44 | |
| 45 // ForMe gets the current user's ShadowFile. | |
| 46 func ForMe() (*ShadowFile, error) { | |
| 47 u, err := user.Current() | |
| 48 if err != nil { | |
| 49 return nil, err | |
| 50 } | |
| 51 return New(path.Join(u.HomeDir, MultipassFile)), nil | |
| 52 } | 32 } |
| 53 | 33 |
| 54 // New creates a ShadowFile for reading at the given path. | 34 // New creates a ShadowFile for reading at the given path. |
| 55 // If a file needs to be created, uses the given GID to create it. | 35 // If a file needs to be created, uses the given GID to create it. |
| 56 func New(name string) *ShadowFile { | 36 func New(name string) *ShadowFile { |
