From 6d87adb2e6dae1950730c0fcdcb1b244513c120a Mon Sep 17 00:00:00 2001 From: Hubert Date: Wed, 21 Jul 2021 13:33:12 +0200 Subject: [PATCH] validator for git proto --- src/gitutils/gitproto.rs | 9 ++++++--- src/main.rs | 4 +++- src/webutils/auth.rs | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/gitutils/gitproto.rs b/src/gitutils/gitproto.rs index 2e9bf22..e1b5249 100644 --- a/src/gitutils/gitproto.rs +++ b/src/gitutils/gitproto.rs @@ -15,15 +15,18 @@ use tokio::process::{Child, Command}; use crate::gitust::Gitust; use crate::reader::ToStream; use crate::error; +use crate::webutils::auth; //#[get("/git/{owner}/{repo}.git/{path:.*}")] -pub async fn git_proto( +pub async fn git_proto( mut payload : web::Payload, web::Path((owner, reponame, path)): web::Path<(String, String, String)>, mut req: HttpRequest, gitust : web::Data, - auth : BasicAuth, + authenticator : web::Data, + auth : Option, ) -> Result{ + let user = auth.and_then(|a| authenticator.check_basic(&a)).ok_or(error::Error::Unauthorized("git_proto".to_string()))?; //println!("enter git_proto"); let mut cmd = Command::new("git"); cmd.arg("http-backend"); @@ -32,7 +35,7 @@ pub async fn git_proto( cmd.env("REQUEST_METHOD", req.method().as_str()); cmd.env("GIT_PROJECT_ROOT", &gitust.repo_root_path); cmd.env("PATH_INFO", format!("/{}/{}.git/{}",owner, reponame, path)); - cmd.env("REMOTE_USER", auth.user_id().to_string()); + cmd.env("REMOTE_USER", user.get_name()); //cmd.env("REMOTE_ADDR", req.remote_addr().to_string()); cmd.env("QUERY_STRING", req.query_string()); cmd.env("CONTENT_TYPE", header(&req, header::CONTENT_TYPE)); diff --git a/src/main.rs b/src/main.rs index c7d62df..2edcd5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,7 @@ use gitutils::gitfile::GitFile; use gitutils::gitproto; use gitutils::gitrepo::GitRepo; use web::repo; +use webutils::auth; use crate::git::GitBrowseEntry; use crate::gitust::Gitust; @@ -165,6 +166,7 @@ async fn main() -> std::io::Result<()> { // .wrap(Logger::new("%a %{User-Agent}i")) .wrap(CookieSession::signed(session_key).secure(false)) .data(gitust) + .data(auth::TestValidator) .service(hello) .service(echo) .service(hello_test) @@ -186,7 +188,7 @@ async fn main() -> std::io::Result<()> { ) .service( webx::resource("/git/{user}/{repo}.git/{path:.*}") - .route(webx::route().to(gitproto::git_proto)) + .route(webx::route().to(gitproto::git_proto::)) ) .service( Files::new("/static", "static") diff --git a/src/webutils/auth.rs b/src/webutils/auth.rs index c236602..2f0fb91 100644 --- a/src/webutils/auth.rs +++ b/src/webutils/auth.rs @@ -31,3 +31,9 @@ impl AuthValidator for TestValidator { } pub struct User(String); + +impl User { + pub fn get_name(&self) -> String { + self.0.clone() + } +}