@@ -111,8 +111,17 @@ func ServCommand(ctx *context.PrivateContext) {
111
111
112
112
owner , err := user_model .GetUserByName (results .OwnerName )
113
113
if err != nil {
114
+ if user_model .IsErrUserNotExist (err ) {
115
+ // User is fetching/cloning a non-existent repository
116
+ log .Warn ("Failed authentication attempt (cannot find repository: %s/%s) from %s" , results .OwnerName , results .RepoName , ctx .RemoteAddr ())
117
+ ctx .JSON (http .StatusNotFound , private.ErrServCommand {
118
+ Results : results ,
119
+ Err : fmt .Sprintf ("Cannot find repository: %s/%s" , results .OwnerName , results .RepoName ),
120
+ })
121
+ return
122
+ }
114
123
log .Error ("Unable to get repository owner: %s/%s Error: %v" , results .OwnerName , results .RepoName , err )
115
- ctx .JSON (http .StatusInternalServerError , private.ErrServCommand {
124
+ ctx .JSON (http .StatusForbidden , private.ErrServCommand {
116
125
Results : results ,
117
126
Err : fmt .Sprintf ("Unable to get repository owner: %s/%s %v" , results .OwnerName , results .RepoName , err ),
118
127
})
@@ -135,7 +144,7 @@ func ServCommand(ctx *context.PrivateContext) {
135
144
for _ , verb := range ctx .FormStrings ("verb" ) {
136
145
if "git-upload-pack" == verb {
137
146
// User is fetching/cloning a non-existent repository
138
- log .Error ("Failed authentication attempt (cannot find repository: %s/%s) from %s" , results .OwnerName , results .RepoName , ctx .RemoteAddr ())
147
+ log .Warn ("Failed authentication attempt (cannot find repository: %s/%s) from %s" , results .OwnerName , results .RepoName , ctx .RemoteAddr ())
139
148
ctx .JSON (http .StatusNotFound , private.ErrServCommand {
140
149
Results : results ,
141
150
Err : fmt .Sprintf ("Cannot find repository: %s/%s" , results .OwnerName , results .RepoName ),
@@ -325,7 +334,7 @@ func ServCommand(ctx *context.PrivateContext) {
325
334
userMode := perm .UnitAccessMode (unitType )
326
335
327
336
if userMode < mode {
328
- log .Error ("Failed authentication attempt for %s with key %s (not authorized to %s %s/%s) from %s" , user .Name , key .Name , modeString , ownerName , repoName , ctx .RemoteAddr ())
337
+ log .Warn ("Failed authentication attempt for %s with key %s (not authorized to %s %s/%s) from %s" , user .Name , key .Name , modeString , ownerName , repoName , ctx .RemoteAddr ())
329
338
ctx .JSON (http .StatusUnauthorized , private.ErrServCommand {
330
339
Results : results ,
331
340
Err : fmt .Sprintf ("User: %d:%s with Key: %d:%s is not authorized to %s %s/%s." , user .ID , user .Name , key .ID , key .Name , modeString , ownerName , repoName ),
0 commit comments