This commit is contained in:
Kreyren 2020-01-19 16:57:26 +00:00
parent 43e522e563
commit 3e5b93a629

@ -68,28 +68,37 @@ macro_rules! unimplemented {
// Sanitized method to make a new directory // Sanitized method to make a new directory
fn emkdir<PATH: AsRef<std::path::Path>>(pathname: PATH) { fn emkdir<PATH: AsRef<std::path::Path>>(pathname: PATH) {
unimplemented!("Mkdir needs implementation"); //unimplemented!("Mkdir needs implementation");
// FIXME: Verify that parsed argument is valid // FIXME: Verify that parsed argument is valid
// FIXME-TEST: Make sure that this works on Linux // FIXME-TEST: Make sure that this works on Linux
// FIXME-TEST: Make sure that this works on Windows // FIXME-TEST: Make sure that this works on Windows
// FIXME-TEST: Make sure that this works on Redox // FIXME-TEST: Make sure that this works on Redox
// FIXME-TEST: Make sure that this works on MacOS // FIXME-TEST: Make sure that this works on MacOS
// FIXME-TEST: Make sure that this works on FreeBSD // FIXME-TEST: Make sure that this works on FreeBSD
fixme!("Die() doesn't accept pathname println!();-way, using some/path as stub"); // FIXME: Implement permission management for new directory
if metadata(pathname).unwrap().is_dir() { fixme!("die() doesn't accept pathname println!();-way, using some/path as stub");
match fs::create_dir(pathname) { // FIXME: This fails if metadata(pathname.as_ref()).unwrap().is_dir() {
Ok(..) => { info!("Created a new directory in some/path"); }, match fs::create_dir(pathname.as_ref()) {
Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => { Ok(..) => { trace!("Created a new directory in some/path"); },
unimplemented!("Unexpected happend while creating new directory in some/path checking for already existing"); Err(ref error) if error.kind() == io::ErrorKind::AlreadyExists => {
// FIXME: Check if file or a directory // For scenerio where pathname was parsed after sanity checks and prior to create_dir() call
if metadata(pathname.as_ref()).unwrap().is_file() {
die!(1; "Pathname some/path points to a file, created after sanity checks and prior to create_dir() call, suspecting malicous injection");
} else if metadata(pathname.as_ref()).unwrap().is_dir() {
die!(1; "Pathname some/path points to already existing directory, created after sanity checks and prior to create_dir() call suspecting malicious injection");
} else if false { // FIXME: Check for symlink
die!(1; "Pathname some/path points to already existing symlink, created after sanity checks and prior to create_dir() call, suspecting malicious injection");
} else {
die!(256; "Unexpected happend for creation of some/path after sanity checks and prior to create_dir() call");
}
}, },
Err(e) => { die!(256; "Unexpected happend while creating a directory some/path"); } Err(e) => { die!(256; "Unexpected happend while creating a directory some/path"); }
} }
} else if metadata(pathname).unwrap().is_dir() { } else if metadata(pathname.as_ref()).unwrap().is_dir() {
info!("Directory {} already exists"); info!("Directory {} already exists");
} else if metadata(pathname).unwrap().is_file() { } else if metadata(pathname.as_ref()).unwrap().is_file() {
// FIXMEL die!(1; "Path {} is already a file which is unexpected", pathname); // FIXME: die!(1; "Path {} is already a file which is unexpected", pathname);
die!(1; "Path some/path is already a file which is unexpected"); die!(1; "Path somepath is already a file which is unexpected");
} else if false { // FIXME: Implement checking for symlink } else if false { // FIXME: Implement checking for symlink
die!(1; "Path some/path is a symlink which is unexpected for creating a directory"); die!(1; "Path some/path is a symlink which is unexpected for creating a directory");
} else { } else {