@@ -12,7 +12,6 @@ import (
12
12
"fmt"
13
13
"net/smtp"
14
14
"net/textproto"
15
- "regexp"
16
15
"strings"
17
16
18
17
"code.gitea.io/gitea/modules/auth/ldap"
@@ -455,10 +454,6 @@ func composeFullName(firstname, surname, username string) string {
455
454
}
456
455
}
457
456
458
- var (
459
- alphaDashDotPattern = regexp .MustCompile (`[^\w-\.]` )
460
- )
461
-
462
457
// LoginViaLDAP queries if login/password is valid against the LDAP directory pool,
463
458
// and create a local user if success when enabled.
464
459
func LoginViaLDAP (user * User , login , password string , source * LoginSource ) (* User , error ) {
@@ -503,10 +498,6 @@ func LoginViaLDAP(user *User, login, password string, source *LoginSource) (*Use
503
498
if len (sr .Username ) == 0 {
504
499
sr .Username = login
505
500
}
506
- // Validate username make sure it satisfies requirement.
507
- if alphaDashDotPattern .MatchString (sr .Username ) {
508
- return nil , fmt .Errorf ("Invalid pattern for attribute 'username' [%s]: must be valid alpha or numeric or dash(-_) or dot characters" , sr .Username )
509
- }
510
501
511
502
if len (sr .Mail ) == 0 {
512
503
sr .Mail = fmt .Sprintf ("%s@localhost" , sr .Username )
@@ -666,7 +657,8 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
666
657
// LoginViaPAM queries if login/password is valid against the PAM,
667
658
// and create a local user if success when enabled.
668
659
func LoginViaPAM (user * User , login , password string , sourceID int64 , cfg * PAMConfig ) (* User , error ) {
669
- if err := pam .Auth (cfg .ServiceName , login , password ); err != nil {
660
+ pamLogin , err := pam .Auth (cfg .ServiceName , login , password )
661
+ if err != nil {
670
662
if strings .Contains (err .Error (), "Authentication failure" ) {
671
663
return nil , ErrUserNotExist {0 , login , 0 }
672
664
}
@@ -677,14 +669,21 @@ func LoginViaPAM(user *User, login, password string, sourceID int64, cfg *PAMCon
677
669
return user , nil
678
670
}
679
671
672
+ // Allow PAM sources with `@` in their name, like from Active Directory
673
+ username := pamLogin
674
+ idx := strings .Index (pamLogin , "@" )
675
+ if idx > - 1 {
676
+ username = pamLogin [:idx ]
677
+ }
678
+
680
679
user = & User {
681
- LowerName : strings .ToLower (login ),
682
- Name : login ,
683
- Email : login ,
680
+ LowerName : strings .ToLower (username ),
681
+ Name : username ,
682
+ Email : pamLogin ,
684
683
Passwd : password ,
685
684
LoginType : LoginPAM ,
686
685
LoginSource : sourceID ,
687
- LoginName : login ,
686
+ LoginName : login , // This is what the user typed in
688
687
IsActive : true ,
689
688
}
690
689
return user , CreateUser (user )
0 commit comments