diff options
| author | Joseph Richey <joerichey@google.com> | 2017-07-17 18:26:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-17 18:26:19 -0700 |
| commit | 3d08d9f6891db3ca94337e9b987ef62cba535fe1 (patch) | |
| tree | ca9476a0aecaf79cfc8716875db073ea54d5f748 /cmd/fscrypt/prompt.go | |
| parent | 6f32bbc8bf51d615ef23ed37aa40910ec23cd587 (diff) | |
| parent | 1a4a020ad5766fce3b3ad719d85593a3e8159733 (diff) | |
Merge pull request #21 from google/fix
Add PAM package
Diffstat (limited to 'cmd/fscrypt/prompt.go')
| -rw-r--r-- | cmd/fscrypt/prompt.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/cmd/fscrypt/prompt.go b/cmd/fscrypt/prompt.go index fdbef81..52f8c47 100644 --- a/cmd/fscrypt/prompt.go +++ b/cmd/fscrypt/prompt.go @@ -27,6 +27,8 @@ import ( "strconv" "strings" + "github.com/pkg/errors" + "github.com/google/fscrypt/actions" "github.com/google/fscrypt/metadata" "github.com/google/fscrypt/util" @@ -106,21 +108,31 @@ func askConfirmation(question string, defaultChoice bool, warning string) error return nil } -// getUsername returns the username for the provided UID. If the UID does not -// correspond to a user or the username is blank, "UID=<uid>" is returned. -func getUsername(uid int64) string { +// usernameFromID returns the username for the provided UID. If the UID does not +// correspond to a user or the username is blank, an error is returned. +func usernameFromID(uid int64) (string, error) { u, err := user.LookupId(strconv.Itoa(int(uid))) if err != nil || u.Username == "" { - return fmt.Sprintf("UID=%d", uid) + return "", errors.Wrapf(ErrUnknownUser, "uid %d", uid) + } + return u.Username, nil +} + +// formatUsername either returns the username for the provided UID, or a string +// containing the error for unknown UIDs. +func formatUsername(uid int64) string { + username, err := usernameFromID(uid) + if err != nil { + return fmt.Sprintf("[%v]", err) } - return u.Username + return username } // formatInfo gives a string description of metadata.ProtectorData. func formatInfo(data actions.ProtectorInfo) string { switch data.Source() { case metadata.SourceType_pam_passphrase: - return "login protector for " + getUsername(data.UID()) + return "login protector for " + formatUsername(data.UID()) case metadata.SourceType_custom_passphrase: return fmt.Sprintf("custom protector %q", data.Name()) case metadata.SourceType_raw_key: |