diff -r 159067260aad -r c9c90315ea24 librazor/util.c --- a/librazor/util.c Fri Jan 09 12:32:57 2009 +0000 +++ b/librazor/util.c Wed Apr 22 15:09:17 2009 +0100 @@ -30,19 +30,49 @@ #include #include #include +#ifdef MSWIN_API +#include +#endif #if HAVE_SYS_MMAN_H #include #endif +#include "razor.h" #include "razor-internal.h" #ifndef O_BINARY #define O_BINARY 0 #endif +#define RAZOR_ASCII_ISALPHA(c) \ + ((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z') + /* Required by gnulib on non-libc platforms */ char *program_name = "librazor"; +static int allow_all_root_names = 0; + +/* + * Primarily intended for testing named roots under UNIX platforms. + */ +RAZOR_EXPORT void razor_disable_root_name_checks(int disable) +{ + allow_all_root_names = disable; +} + +static int razor_valid_root_name(const char *name) +{ + if (allow_all_root_names) + return !strchr(name,'/'); + +#ifdef MSWIN_API + return RAZOR_ASCII_ISALPHA(name[0]) && name[1] == ':' && + name[2] == '\0'; +#else + return name[0] == '\0'; +#endif +} + int razor_create_dir(const char *root, const char *path) { @@ -51,8 +81,9 @@ struct stat buf; /* Create all sub-directories in dir. We know root exists and - * is a dir, root does not end in a '/', and path has a - * leading '/'. */ + * is a dir, root does not end in a '/', and path either has a + * leading '/' or (on MS-Windows only) root is the empty string + * and path starts with drive (eg., "c:/windows"). */ strcpy(buffer, root); p = buffer + strlen(buffer); @@ -66,6 +97,9 @@ p += next - slash; *p = '\0'; + if (razor_valid_root_name(buffer)) + continue; + if (stat(buffer, &buf) == 0) { if (!S_ISDIR(buf.st_mode)) { fprintf(stderr,