From edd786446c0f7a1581be08dbe7697c339790c2c1 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 9 Aug 2016 17:41:18 -0700 Subject: #3158 skip RUN_USER check on Windows --- modules/setting/setting.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'modules/setting/setting.go') diff --git a/modules/setting/setting.go b/modules/setting/setting.go index aa618ad6..a56c4824 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -285,6 +285,19 @@ func forcePathSeparator(path string) { } } +// IsRunUserMatchCurrentUser returns false if configured run user does not match +// actual user that runs the app. The first return value is the actual user name. +// This check is ignored under Windows since SSH remote login is not the main +// method to login on Windows. +func IsRunUserMatchCurrentUser(runUser string) (string, bool) { + if IsWindows { + return "", true + } + + currentUser := user.CurrentUsername() + return currentUser, runUser == currentUser +} + // NewContext initializes configuration context. // NOTE: do not print any log except error. func NewContext() { @@ -431,10 +444,12 @@ func NewContext() { }[Cfg.Section("time").Key("FORMAT").MustString("RFC1123")] RunUser = Cfg.Section("").Key("RUN_USER").String() - curUser := user.CurrentUsername() // Does not check run user when the install lock is off. - if InstallLock && RunUser != curUser { - log.Fatal(4, "Expect user(%s) but current user is: %s", RunUser, curUser) + if InstallLock { + currentUser, match := IsRunUserMatchCurrentUser(RunUser) + if !match { + log.Fatal(4, "Expect user '%s' but current user is: %s", RunUser, currentUser) + } } // Determine and create root git repository path. -- cgit v1.2.3