mirror of https://github.com/go-gitea/gitea.git
fix HTTP/HTTPS push update func call panic #1037 and `http: multiple response.WriteHeader calls`
This commit is contained in:
parent
34102f7889
commit
4aafeace23
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.5.16.0311 Beta"
|
const APP_VER = "0.5.16.0312 Beta"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -215,11 +215,9 @@ func UserSignIn(uname, passwd string) (*User, error) {
|
||||||
|
|
||||||
switch u.LoginType {
|
switch u.LoginType {
|
||||||
case LDAP:
|
case LDAP:
|
||||||
return LoginUserLdapSource(u, u.LoginName, passwd,
|
return LoginUserLdapSource(u, u.LoginName, passwd, source.Id, source.Cfg.(*LDAPConfig), false)
|
||||||
source.Id, source.Cfg.(*LDAPConfig), false)
|
|
||||||
case SMTP:
|
case SMTP:
|
||||||
return LoginUserSMTPSource(u, u.LoginName, passwd,
|
return LoginUserSMTPSource(u, u.LoginName, passwd, source.Id, source.Cfg.(*SMTPConfig), false)
|
||||||
source.Id, source.Cfg.(*SMTPConfig), false)
|
|
||||||
}
|
}
|
||||||
return nil, ErrUnsupportedLoginType
|
return nil, ErrUnsupportedLoginType
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,15 +254,16 @@ func saveAuthorizedKeyFile(keys ...*PublicKey) error {
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
finfo, err := f.Stat()
|
fi, err := f.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: following command does not support in Windows.
|
// FIXME: following command does not support in Windows.
|
||||||
if !setting.IsWindows {
|
if !setting.IsWindows {
|
||||||
if finfo.Mode().Perm() > 0600 {
|
// .ssh directory should have mode 700, and authorized_keys file should have mode 600.
|
||||||
log.Error(4, "authorized_keys file has unusual permission flags: %s - setting to -rw-------", finfo.Mode().Perm().String())
|
if fi.Mode().Perm() > 0600 {
|
||||||
|
log.Error(4, "authorized_keys file has unusual permission flags: %s - setting to -rw-------", fi.Mode().Perm().String())
|
||||||
if err = f.Chmod(0600); err != nil {
|
if err = f.Chmod(0600); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ func Http(ctx *middleware.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
authUser, err := models.UserSignIn(authUsername, authPasswd)
|
authUser, err = models.UserSignIn(authUsername, authPasswd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != models.ErrUserNotExist {
|
if err != models.ErrUserNotExist {
|
||||||
ctx.Handle(500, "UserSignIn error: %v", err)
|
ctx.Handle(500, "UserSignIn error: %v", err)
|
||||||
|
@ -160,7 +160,7 @@ func Http(ctx *middleware.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var f = func(rpc string, input []byte) {
|
callback := func(rpc string, input []byte) {
|
||||||
if rpc == "receive-pack" {
|
if rpc == "receive-pack" {
|
||||||
var lastLine int64 = 0
|
var lastLine int64 = 0
|
||||||
|
|
||||||
|
@ -189,6 +189,7 @@ func Http(ctx *middleware.Context) {
|
||||||
newCommitId := fields[1]
|
newCommitId := fields[1]
|
||||||
refName := fields[2]
|
refName := fields[2]
|
||||||
|
|
||||||
|
// FIXME: handle error.
|
||||||
models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id)
|
models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id)
|
||||||
}
|
}
|
||||||
lastLine = lastLine + size
|
lastLine = lastLine + size
|
||||||
|
@ -199,21 +200,19 @@ func Http(ctx *middleware.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config := Config{setting.RepoRootPath, "git", true, true, f}
|
HTTPBackend(&Config{
|
||||||
|
RepoRootPath: setting.RepoRootPath,
|
||||||
|
GitBinPath: "git",
|
||||||
|
UploadPack: true,
|
||||||
|
ReceivePack: true,
|
||||||
|
OnSucceed: callback,
|
||||||
|
})(ctx.Resp, ctx.Req.Request)
|
||||||
|
|
||||||
handler := HttpBackend(&config)
|
|
||||||
handler(ctx.Resp, ctx.Req.Request)
|
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
}
|
}
|
||||||
|
|
||||||
type route struct {
|
|
||||||
cr *regexp.Regexp
|
|
||||||
method string
|
|
||||||
handler func(handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ReposRoot string
|
RepoRootPath string
|
||||||
GitBinPath string
|
GitBinPath string
|
||||||
UploadPack bool
|
UploadPack bool
|
||||||
ReceivePack bool
|
ReceivePack bool
|
||||||
|
@ -228,6 +227,12 @@ type handler struct {
|
||||||
File string
|
File string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type route struct {
|
||||||
|
cr *regexp.Regexp
|
||||||
|
method string
|
||||||
|
handler func(handler)
|
||||||
|
}
|
||||||
|
|
||||||
var routes = []route{
|
var routes = []route{
|
||||||
{regexp.MustCompile("(.*?)/git-upload-pack$"), "POST", serviceUploadPack},
|
{regexp.MustCompile("(.*?)/git-upload-pack$"), "POST", serviceUploadPack},
|
||||||
{regexp.MustCompile("(.*?)/git-receive-pack$"), "POST", serviceReceivePack},
|
{regexp.MustCompile("(.*?)/git-receive-pack$"), "POST", serviceReceivePack},
|
||||||
|
@ -243,7 +248,7 @@ var routes = []route{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request handling function
|
// Request handling function
|
||||||
func HttpBackend(config *Config) http.HandlerFunc {
|
func HTTPBackend(config *Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
r.URL.Path = strings.ToLower(r.URL.Path) // blue: In case some repo name has upper case name
|
r.URL.Path = strings.ToLower(r.URL.Path) // blue: In case some repo name has upper case name
|
||||||
|
@ -285,8 +290,7 @@ func serviceReceivePack(hr handler) {
|
||||||
func serviceRpc(rpc string, hr handler) {
|
func serviceRpc(rpc string, hr handler) {
|
||||||
w, r, dir := hr.w, hr.r, hr.Dir
|
w, r, dir := hr.w, hr.r, hr.Dir
|
||||||
|
|
||||||
access := hasAccess(r, hr.Config, dir, rpc, true)
|
if !hasAccess(r, hr.Config, dir, rpc, true) {
|
||||||
if access == false {
|
|
||||||
renderNoAccess(w)
|
renderNoAccess(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -337,7 +341,6 @@ func serviceRpc(rpc string, hr handler) {
|
||||||
if hr.Config.OnSucceed != nil {
|
if hr.Config.OnSucceed != nil {
|
||||||
hr.Config.OnSucceed(rpc, input)
|
hr.Config.OnSucceed(rpc, input)
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInfoRefs(hr handler) {
|
func getInfoRefs(hr handler) {
|
||||||
|
@ -408,7 +411,7 @@ func sendFile(contentType string, hr handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGitDir(config *Config, fPath string) (string, error) {
|
func getGitDir(config *Config, fPath string) (string, error) {
|
||||||
root := config.ReposRoot
|
root := config.RepoRootPath
|
||||||
|
|
||||||
if root == "" {
|
if root == "" {
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.5.16.0311 Beta
|
0.5.16.0312 Beta
|
Loading…
Reference in New Issue