]> git.proxmox.com Git - proxmox-backup.git/commitdiff
move normalize_path to tools::normalize_uri_path
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 7 May 2019 07:44:34 +0000 (09:44 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 7 May 2019 07:44:34 +0000 (09:44 +0200)
src/server/rest.rs
src/tools.rs

index eda55f36b2e761899e97e1152acee03903cf6e0b..cdd8f6fbae402af1dfb751ab2d4579c2094bc107 100644 (file)
@@ -488,29 +488,6 @@ fn check_auth(method: &hyper::Method, ticket: &Option<String>, token: &Option<St
     Ok(username)
 }
 
-// normalize path
-// do not allow ".", "..", or hidden files ".XXXX"
-// also remove empty path components
-fn normalize_path(path: &str) -> Result<(String, Vec<&str>), Error> {
-
-    let items = path.split('/');
-
-    let mut path = String::new();
-    let mut components = vec![];
-
-    for name in items {
-        if name.is_empty() { continue; }
-        if name.starts_with(".") {
-            bail!("Path contains illegal components.");
-        }
-        path.push('/');
-        path.push_str(name);
-        components.push(name);
-    }
-
-    Ok((path, components))
-}
-
 fn delayed_response(resp: Response<Body>, delay_unauth_time: std::time::Instant) -> BoxFut {
 
     Box::new(tokio::timer::Delay::new(delay_unauth_time)
@@ -524,7 +501,7 @@ pub fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> BoxFut {
 
     let method = parts.method.clone();
 
-    let (path, components) = match normalize_path(parts.uri.path()) {
+    let (path, components) = match tools::normalize_uri_path(parts.uri.path()) {
         Ok((p,c)) => (p, c),
         Err(err) => return Box::new(future::err(http_err!(BAD_REQUEST, err.to_string()))),
     };
index 5f3fb8972f93f05bd1d3cdea861b5514a0e5b071..54a7703d6a271be6af33f56e0a73f0f4ee3a7d15 100644 (file)
@@ -618,6 +618,30 @@ pub fn join(data: &Vec<String>, sep: char) -> String {
     list
 }
 
+/// normalize uri path
+///
+/// Do not allow ".", "..", or hidden files ".XXXX"
+/// Also remove empty path components
+pub fn normalize_uri_path(path: &str) -> Result<(String, Vec<&str>), Error> {
+
+    let items = path.split('/');
+
+    let mut path = String::new();
+    let mut components = vec![];
+
+    for name in items {
+        if name.is_empty() { continue; }
+        if name.starts_with(".") {
+            bail!("Path contains illegal components.");
+        }
+        path.push('/');
+        path.push_str(name);
+        components.push(name);
+    }
+
+    Ok((path, components))
+}
+
 pub fn fd_change_cloexec(fd: RawFd, on: bool) -> Result<(), Error> {
     use nix::fcntl::{fcntl, F_GETFD, F_SETFD, FdFlag};
     let mut flags = FdFlag::from_bits(fcntl(fd, F_GETFD)?)