// Query if name/passwd can login against PAM // Create a local user if success // Return the same LoginUserPlain semantic func LoginUserPAMSource(u *User, name, passwd string, sourceId int64, cfg *PAMConfig, autoRegister bool) (*User, error) { if err := pam.PAMAuth(cfg.ServiceName, name, passwd); err != nil { if strings.Contains(err.Error(), "Authentication failure") { return nil, ErrUserNotExist{0, name} } return nil, err } if !autoRegister { return u, nil } // fake a local user creation u = &User{ LowerName: strings.ToLower(name), Name: name, LoginType: PAM, LoginSource: sourceId, LoginName: name, IsActive: true, Passwd: passwd, Email: name, } return u, CreateUser(u) }
// LoginViaPAM queries if login/password is valid against the PAM, // and create a local user if success when enabled. func LoginViaPAM(user *User, login, password string, sourceID int64, cfg *PAMConfig, autoRegister bool) (*User, error) { if err := pam.PAMAuth(cfg.ServiceName, login, password); err != nil { if strings.Contains(err.Error(), "Authentication failure") { return nil, ErrUserNotExist{0, login} } return nil, err } if !autoRegister { return user, nil } user = &User{ LowerName: strings.ToLower(login), Name: login, Email: login, Passwd: password, LoginType: LOGIN_PAM, LoginSource: sourceID, LoginName: login, IsActive: true, } return user, CreateUser(user) }