Skip to content

Commit b2de9dd

Browse files
authored
Merge branch 'master' into lunny/fix_webhook
2 parents 726b7e8 + d2ee122 commit b2de9dd

19 files changed

+104
-50
lines changed

.drone.yml

+24
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ steps:
3333
GOSUMDB: sum.golang.org
3434
TAGS: bindata sqlite sqlite_unlock_notify
3535

36+
- name: lint-backend-windows
37+
pull: always
38+
image: golang:1.15
39+
commands:
40+
- make golangci-lint vet
41+
environment:
42+
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
43+
GOSUMDB: sum.golang.org
44+
TAGS: bindata sqlite sqlite_unlock_notify
45+
GOOS: windows
46+
GOARCH: amd64
47+
3648
- name: lint-backend-gogit
3749
pull: always
3850
image: golang:1.15
@@ -85,6 +97,18 @@ steps:
8597
- rm ./gitea # clean
8698
depends_on: [checks-backend]
8799

100+
- name: build-backend-windows
101+
image: golang:1.15
102+
environment:
103+
GO111MODULE: on
104+
GOPROXY: off
105+
GOOS: windows
106+
GOARCH: amd64
107+
TAGS: bindata gogit
108+
commands:
109+
- go build -mod=vendor -o gitea_windows
110+
depends_on: [checks-backend]
111+
88112
- name: build-backend-386
89113
image: golang:1.15
90114
environment:

docs/content/page/index.en-us.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Windows, on architectures like amd64, i386, ARM, PowerPC, and others.
268268
## Components
269269

270270
* Web framework: [Macaron](http://go-macaron.com/)
271-
* ORM: [XORM](https://github.com/go-xorm/xorm)
271+
* ORM: [XORM](https://xorm.io)
272272
* UI components:
273273
* [Semantic UI](http://semantic-ui.com/)
274274
* [GitHub Octicons](https://octicons.github.com/)

docs/content/page/index.fr-fr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Le but de ce projet est de fournir de la manière la plus simple, la plus rapide
255255
## Composants
256256

257257
* Framework web : [Macaron](http://go-macaron.com/)
258-
* ORM : [XORM](https://github.com/go-xorm/xorm)
258+
* ORM: [XORM](https://xorm.io)
259259
* Interface graphique :
260260
* [Semantic UI](http://semantic-ui.com/)
261261
* [GitHub Octicons](https://octicons.github.com/)

docs/content/page/index.zh-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Gitea的首要目标是创建一个极易安装,运行非常快速,安装和
4848
## 组件
4949

5050
* Web框架: [Macaron](http://go-macaron.com/)
51-
* ORM [XORM](https://github.com/go-xorm/xorm)
51+
* ORM: [XORM](https://xorm.io)
5252
* UI组件:
5353
* [Semantic UI](http://semantic-ui.com/)
5454
* [GitHub Octicons](https://octicons.github.com/)

docs/content/page/index.zh-tw.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Gitea 的首要目標是建立一個容易安裝,運行快速,安装和使
4848
## 元件
4949

5050
* Web 框架: [Macaron](http://go-macaron.com/)
51-
* ORM: [XORM](https://github.com/go-xorm/xorm)
51+
* ORM: [XORM](https://xorm.io)
5252
* UI 元件:
5353
* [Semantic UI](http://semantic-ui.com/)
5454
* [GitHub Octicons](https://octicons.github.com/)

modules/auth/sso/basic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (b *Basic) IsEnabled() bool {
4747
// "Authorization" header of the request and returns the corresponding user object for that
4848
// name/token on successful validation.
4949
// Returns nil if header is empty or validation fails.
50-
func (b *Basic) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
50+
func (b *Basic) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
5151
baHead := req.Header.Get("Authorization")
5252
if len(baHead) == 0 {
5353
return nil

modules/auth/sso/interface.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ type SingleSignOn interface {
4040
// or a new user object (with id = 0) populated with the information that was found
4141
// in the authentication data (username or email).
4242
// Returns nil if verification fails.
43-
VerifyAuthData(http *http.Request, store DataStore, sess SessionStore) *models.User
43+
VerifyAuthData(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User
4444
}

modules/auth/sso/oauth2.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (o *OAuth2) IsEnabled() bool {
114114
// or the "Authorization" header and returns the corresponding user object for that ID.
115115
// If verification is successful returns an existing user object.
116116
// Returns nil if verification fails.
117-
func (o *OAuth2) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
117+
func (o *OAuth2) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
118118
if !models.HasEngine {
119119
return nil
120120
}

modules/auth/sso/reverseproxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (r *ReverseProxy) IsEnabled() bool {
6060
// If a username is available in the "setting.ReverseProxyAuthUser" header an existing
6161
// user object is returned (populated with username or email found in header).
6262
// Returns nil if header is empty.
63-
func (r *ReverseProxy) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
63+
func (r *ReverseProxy) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
6464
username := r.getUserName(req)
6565
if len(username) == 0 {
6666
return nil

modules/auth/sso/session.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *Session) IsEnabled() bool {
3939
// VerifyAuthData checks if there is a user uid stored in the session and returns the user
4040
// object for that uid.
4141
// Returns nil if there is no user uid stored in the session.
42-
func (s *Session) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
42+
func (s *Session) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
4343
user := SessionUser(sess)
4444
if user != nil {
4545
return user

modules/auth/sso/sspi_windows.go

+35-32
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ package sso
77
import (
88
"errors"
99
"net/http"
10-
"reflect"
1110
"strings"
1211

1312
"code.gitea.io/gitea/models"
1413
"code.gitea.io/gitea/modules/base"
1514
"code.gitea.io/gitea/modules/log"
1615
"code.gitea.io/gitea/modules/setting"
17-
18-
"gitea.com/macaron/macaron"
19-
"gitea.com/macaron/session"
16+
"code.gitea.io/gitea/modules/templates"
2017

2118
gouuid "github.com/google/uuid"
2219
"github.com/quasoft/websspi"
20+
"github.com/unrolled/render"
2321
)
2422

2523
const (
@@ -41,14 +39,26 @@ var (
4139
// On successful authentication returns a valid user object.
4240
// Returns nil if authentication fails.
4341
type SSPI struct {
42+
rnd *render.Render
4443
}
4544

4645
// Init creates a new global websspi.Authenticator object
4746
func (s *SSPI) Init() error {
4847
config := websspi.NewConfig()
4948
var err error
5049
sspiAuth, err = websspi.New(config)
51-
return err
50+
if err != nil {
51+
return err
52+
}
53+
s.rnd = render.New(render.Options{
54+
Extensions: []string{".tmpl"},
55+
Directory: "templates",
56+
Funcs: templates.NewFuncMap(),
57+
Asset: templates.GetAsset,
58+
AssetNames: templates.GetAssetNames,
59+
IsDevelopment: setting.RunMode != "prod",
60+
})
61+
return nil
5262
}
5363

5464
// Free releases resources used by the global websspi.Authenticator object
@@ -65,8 +75,8 @@ func (s *SSPI) IsEnabled() bool {
6575
// If authentication is successful, returs the corresponding user object.
6676
// If negotiation should continue or authentication fails, immediately returns a 401 HTTP
6777
// response code, as required by the SPNEGO protocol.
68-
func (s *SSPI) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
69-
if !s.shouldAuthenticate(ctx) {
78+
func (s *SSPI) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
79+
if !s.shouldAuthenticate(req) {
7080
return nil
7181
}
7282

@@ -76,22 +86,29 @@ func (s *SSPI) VerifyAuthData(req *http.Request, store DataStore, sess SessionSt
7686
return nil
7787
}
7888

79-
userInfo, outToken, err := sspiAuth.Authenticate(req, ctx.Resp)
89+
userInfo, outToken, err := sspiAuth.Authenticate(req, w)
8090
if err != nil {
8191
log.Warn("Authentication failed with error: %v\n", err)
82-
sspiAuth.AppendAuthenticateHeader(ctx.Resp, outToken)
92+
sspiAuth.AppendAuthenticateHeader(w, outToken)
8393

8494
// Include the user login page in the 401 response to allow the user
8595
// to login with another authentication method if SSPI authentication
8696
// fails
87-
addFlashErr(ctx, ctx.Tr("auth.sspi_auth_failed"))
88-
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
89-
ctx.Data["EnableSSPI"] = true
90-
ctx.HTML(401, string(tplSignIn))
97+
store.GetData()["Flash"] = map[string]string{
98+
"ErrMsg": err.Error(),
99+
}
100+
store.GetData()["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
101+
store.GetData()["EnableSSPI"] = true
102+
103+
err := s.rnd.HTML(w, 401, string(tplSignIn), templates.BaseVars().Merge(store.GetData()))
104+
if err != nil {
105+
log.Error("%v", err)
106+
}
107+
91108
return nil
92109
}
93110
if outToken != "" {
94-
sspiAuth.AppendAuthenticateHeader(ctx.Resp, outToken)
111+
sspiAuth.AppendAuthenticateHeader(w, outToken)
95112
}
96113

97114
username := sanitizeUsername(userInfo.Username, cfg)
@@ -110,16 +127,16 @@ func (s *SSPI) VerifyAuthData(req *http.Request, store DataStore, sess SessionSt
110127
log.Error("User '%s' not found", username)
111128
return nil
112129
}
113-
user, err = s.newUser(ctx, username, cfg)
130+
user, err = s.newUser(username, cfg)
114131
if err != nil {
115132
log.Error("CreateUser: %v", err)
116133
return nil
117134
}
118135
}
119136

120137
// Make sure requests to API paths and PWA resources do not create a new session
121-
if !isAPIPath(ctx) && !isAttachmentDownload(ctx) {
122-
handleSignIn(ctx, sess, user)
138+
if !isAPIPath(req) && !isAttachmentDownload(req) {
139+
handleSignIn(w, req, sess, user)
123140
}
124141

125142
return user
@@ -146,7 +163,7 @@ func (s *SSPI) shouldAuthenticate(req *http.Request) (shouldAuth bool) {
146163
if path == "/user/login" {
147164
if req.FormValue("user_name") != "" && req.FormValue("password") != "" {
148165
shouldAuth = false
149-
} else if ctx.Req.FormValue("auth_with_sspi") == "1" {
166+
} else if req.FormValue("auth_with_sspi") == "1" {
150167
shouldAuth = true
151168
}
152169
} else if isInternalPath(req) {
@@ -217,20 +234,6 @@ func sanitizeUsername(username string, cfg *models.SSPIConfig) string {
217234
return username
218235
}
219236

220-
// addFlashErr adds an error message to the Flash object mapped to a macaron.Context
221-
func addFlashErr(ctx *macaron.Context, err string) {
222-
fv := ctx.GetVal(reflect.TypeOf(&session.Flash{}))
223-
if !fv.IsValid() {
224-
return
225-
}
226-
flash, ok := fv.Interface().(*session.Flash)
227-
if !ok {
228-
return
229-
}
230-
flash.Error(err)
231-
ctx.Data["Flash"] = flash
232-
}
233-
234237
// init registers the SSPI auth method as the last method in the list.
235238
// The SSPI plugin is expected to be executed last, as it returns 401 status code if negotiation
236239
// fails (or if negotiation should continue), which would prevent other authentication methods

modules/auth/sso/user.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// SignedInUser returns the user object of signed user.
1414
// It returns a bool value to indicate whether user uses basic auth or not.
15-
func SignedInUser(req *http.Request, ds DataStore, sess SessionStore) (*models.User, bool) {
15+
func SignedInUser(req *http.Request, w http.ResponseWriter, ds DataStore, sess SessionStore) (*models.User, bool) {
1616
if !models.HasEngine {
1717
return nil, false
1818
}
@@ -22,7 +22,7 @@ func SignedInUser(req *http.Request, ds DataStore, sess SessionStore) (*models.U
2222
if !ssoMethod.IsEnabled() {
2323
continue
2424
}
25-
user := ssoMethod.VerifyAuthData(req, ds, sess)
25+
user := ssoMethod.VerifyAuthData(req, w, ds, sess)
2626
if user != nil {
2727
_, isBasic := ssoMethod.(*Basic)
2828
return user, isBasic

modules/context/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func Contexter() macaron.Handler {
309309
}
310310

311311
// Get user from session if logged in.
312-
ctx.User, ctx.IsBasicAuth = sso.SignedInUser(ctx.Req.Request, ctx, ctx.Session)
312+
ctx.User, ctx.IsBasicAuth = sso.SignedInUser(ctx.Req.Request, c.Resp, ctx, ctx.Session)
313313

314314
if ctx.User != nil {
315315
ctx.IsSigned = true

modules/graceful/manager_windows.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@ func (g *Manager) start() {
7373

7474
// Make SVC process
7575
run := svc.Run
76-
isInteractive, err := svc.IsAnInteractiveSession()
76+
isInteractive, err := svc.IsWindowsService()
7777
if err != nil {
7878
log.Error("Unable to ascertain if running as an Interactive Session: %v", err)
7979
return
8080
}
8181
if isInteractive {
8282
run = debug.Run
8383
}
84-
go run(WindowsServiceName, g)
84+
go func() {
85+
_ = run(WindowsServiceName, g)
86+
}()
8587
}
8688

8789
// Execute makes Manager implement svc.Handler

modules/log/console_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func enableVTMode(console windows.Handle) bool {
2323
// https://docs.microsoft.com/en-us/windows/console/setconsolemode
2424
// It only works on windows 10. Earlier terminals will fail with an err which we will
2525
// handle to say don't color
26-
mode = mode | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING
26+
mode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING
2727
err = windows.SetConsoleMode(console, mode)
2828
return err == nil
2929
}

0 commit comments

Comments
 (0)