diff options
author | Richard Ipsum <richardipsum@fastmail.co.uk> | 2015-07-10 22:13:29 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-10-30 18:54:37 +0100 |
commit | 25ba9b74ee5eeddf7cbc6a9c3d3770bbf9653d7f (patch) | |
tree | 4d1fcbaafa743bf4bef15867f9cabae571ac5c06 | |
parent | 8e29fb9c131a7e77eb15423d76acbc2df2c4c907 (diff) | |
download | gitano-25ba9b74ee5eeddf7cbc6a9c3d3770bbf9653d7f.tar.gz |
Fix empty command bug
This fixes a bug that causes gitano to crash when it's given an empty
command list
Opening and closing of the log should be done in the application,
so it can log before checking for authorization, log after, and
clean up at the end
-rw-r--r-- | bin/gitano-auth.in | 7 | ||||
-rwxr-xr-x | bin/gitano-command.cgi.in | 8 | ||||
-rwxr-xr-x | bin/gitano-smart-http.cgi.in | 10 | ||||
-rw-r--r-- | lib/gitano/auth.lua | 8 |
4 files changed, 25 insertions, 8 deletions
diff --git a/bin/gitano-auth.in b/bin/gitano-auth.in index 2190ae0..2ec6c45 100644 --- a/bin/gitano-auth.in +++ b/bin/gitano-auth.in @@ -20,6 +20,10 @@ local sp = require "luxio.subprocess" -- @@GITANO_SHARE_PATH -- @@GITANO_PLUGIN_PATH +local start_log_level = gitano.log.get_level() +gitano.log.cap_level(gitano.log.level.INFO) +local transactionid = gitano.log.syslog.open() + local repo_root, user, keytag = ... gitano.config.repo_path(repo_root) @@ -31,7 +35,8 @@ if cmdline:match("^[ \t\n]*$") then end local authorized, cmd, parsed_cmdline, config, env, repo = - gitano.auth.is_authorized(user, "ssh", cmdline, repo_root) + gitano.auth.is_authorized(user, "ssh", cmdline, repo_root, + transactionid, start_log_level) if authorized then local exit = gitano.util.run_command(cmd, cmdline, parsed_cmdline, diff --git a/bin/gitano-command.cgi.in b/bin/gitano-command.cgi.in index 2fa1db2..94c5dd5 100755 --- a/bin/gitano-command.cgi.in +++ b/bin/gitano-command.cgi.in @@ -52,9 +52,13 @@ if os.getenv("QUERY_STRING") then local user = os.getenv("REMOTE_USER") or "gitano/anonymous" gitano.log.buffer_output() + local start_log_level = gitano.log.get_level() + gitano.log.cap_level(gitano.log.level.INFO) + local transactionid = gitano.log.syslog.open() local authorized, cmd, parsed_cmdline, config, env, repo = - gitano.auth.is_authorized(user, "http", cmdline, os.getenv("GITANO_ROOT")) + gitano.auth.is_authorized(user, "http", cmdline, os.getenv("GITANO_ROOT"), + transactionid, start_log_level) if authorized then local exit = gitano.util.run_command(cmd, cmdline, parsed_cmdline, @@ -67,6 +71,8 @@ if os.getenv("QUERY_STRING") then stdout:write("Status: 403 Forbidden\r\n\r\n") stdout:write(gitano.log.get_buffered_output() or "") end + + gitano.log.syslog.close() else stdout:write("Status: 400 Bad request\r\n\r\n") stdout:write("Malformed command line, format: ?cmd=arg0 arg1 ... argn\n") diff --git a/bin/gitano-smart-http.cgi.in b/bin/gitano-smart-http.cgi.in index f294b28..6f8fdee 100755 --- a/bin/gitano-smart-http.cgi.in +++ b/bin/gitano-smart-http.cgi.in @@ -59,8 +59,14 @@ if request_method == "GET" or request_method == "POST" then local user = os.getenv("REMOTE_USER") or "gitano/anonymous" local cmdline = parse_request(request_method) + local start_log_level = gitano.log.get_level() + gitano.log.cap_level(gitano.log.level.INFO) + local transactionid = gitano.log.syslog.open() + if cmdline and gitano.auth.is_authorized(user, "http", cmdline, - os.getenv("GITANO_ROOT")) then + os.getenv("GITANO_ROOT"), + transactionid, + start_log_level) then local proc = subprocess.spawn_simple({"git", "http-backend"}) local exit_code @@ -72,6 +78,8 @@ if request_method == "GET" or request_method == "POST" then else stdout:write("Status: 403 Forbidden\r\n\r\n") end + + gitano.log.syslog.close() else stdout:write("Status: 405 Method Not Allowed\r\n") stdout:write("Allow: GET, POST\r\n\r\n") diff --git a/lib/gitano/auth.lua b/lib/gitano/auth.lua index be3f9fc..2583d79 100644 --- a/lib/gitano/auth.lua +++ b/lib/gitano/auth.lua @@ -51,14 +51,12 @@ local function set_environment(repo_root, repo, context, transactionid) return env end -local function is_authorized(user, source, cmdline, repo_root) +local function is_authorized(user, source, cmdline, repo_root, + transactionid, start_log_level) + local keytag = "" local authorized = false - local start_log_level = log.get_level() - log.cap_level(log.level.INFO) - local transactionid = log.syslog.open() - config.repo_path(repo_root) if not user or not cmdline then |