Skip to content

Commit b5a57ed

Browse files
Write username to file
1 parent 695750e commit b5a57ed

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
const defaultConfigFilePath = "/etc/https-user-management/config.yaml"
1111
const defaultTokenFilePath = "/etc/https-user-management/user.token"
12+
const defaultUserFilePath = "/etc/https-user-management/user.name"
1213

1314
var AppConfig *Config
1415
var ConfigError bool
@@ -22,6 +23,7 @@ type Config struct {
2223
Debug bool
2324
URL string
2425
TokenFile string
26+
UserFile string
2527
}
2628

2729
func NewConfig(configPath string) (*Config, error) {
@@ -67,6 +69,10 @@ func init() {
6769
AppConfig.TokenFile = defaultTokenFilePath
6870
}
6971

72+
if AppConfig.UserFile == "" {
73+
AppConfig.UserFile = defaultUserFilePath
74+
}
75+
7076
logger.Infof("AppConfig: %+v", *AppConfig)
7177

7278
if AppConfig.Debug {

pam-https/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ func (mp *mypam) Authenticate(hdl pam.Handle, args pam.Args) pam.Value {
2727
humcommon.Log().Infof("Got request for user: %v", user)
2828
humcommon.Log().Debugf("Got request for user: %v", user)
2929

30+
if err := writeUserFile(user); err != nil {
31+
humcommon.Log().Warnf("Error writing user file: %v", err)
32+
return pam.AuthInfoUnavailable
33+
}
34+
3035
userPassword, err := hdl.GetItem(pam.AuthToken)
3136
if err != nil {
3237
humcommon.Log().Warnf("Error getting PAM passwd for user: %v", err)
@@ -82,6 +87,13 @@ func writeTokenFile(token string) error {
8287
return nil
8388
}
8489

90+
func writeUserFile(user string) error {
91+
if _, err := os.Stat(humcommon.AppConfig.UserFile); os.IsNotExist(err) {
92+
return ioutil.WriteFile(humcommon.AppConfig.UserFile, []byte(user), 0644)
93+
}
94+
return nil
95+
}
96+
8597
func fileContains(line []byte, filePath string) (bool, error) {
8698
data, err := ioutil.ReadFile(filePath)
8799
if err != nil {

0 commit comments

Comments
 (0)