16 #include "mysys_priv.h" 
   39 int my_access(
const char *path, 
int amode) 
 
   44   result= GetFileAttributesEx(path, GetFileExInfoStandard, &fileinfo);
 
   46       (fileinfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) && (amode & W_OK))
 
   48     my_errno= errno= EACCES;
 
   65 static const char *reserved_names[]=
 
   68   "CON", 
"PRN", 
"AUX", 
"NUL",
 
   69   "COM1", 
"COM2", 
"COM3", 
"COM4", 
"COM5", 
"COM6", 
"COM7", 
"COM8", 
"COM9",
 
   70   "LPT1", 
"LPT2", 
"LPT3", 
"LPT4", 
"LPT5", 
"LPT6", 
"LPT7", 
"LPT8", 
"LPT9",
 
   74 #define MAX_RESERVED_NAME_LENGTH 6 
   90 static int str_list_find(
const char **list, 
const char *str)
 
   93   for (name= list; *
name; name++)
 
   95     if (!my_strcasecmp(&my_charset_latin1, *name, str))
 
  109 static char reserved_map[256]=
 
  111   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  112   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  113   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  114   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  115   0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, 
 
  116   3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, 
 
  117   0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, 
 
  118   3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, 
 
  119   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  120   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  121   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  122   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  123   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  124   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  125   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
 
  126   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  
 
  148 int check_if_legal_tablename(
const char *name)
 
  150   DBUG_ENTER(
"check_if_legal_tablename");
 
  151   DBUG_RETURN(name[0] != 0 && name[1] != 0 &&
 
  152               (reserved_map[(uchar) name[0]] & 1) &&
 
  153               (reserved_map[(uchar) name[1]] & 2) &&
 
  154               (reserved_map[(uchar) name[2]] & 4) &&
 
  155               str_list_find(&reserved_names[1], name));
 
  168 static my_bool does_drive_exists(
char drive_letter)
 
  170   DWORD drive_mask= GetLogicalDrives();
 
  171   drive_letter= toupper(drive_letter);
 
  173   return (drive_letter >= 
'A' && drive_letter <= 
'Z') &&
 
  174          (drive_mask & (0x1 << (drive_letter - 
'A')));
 
  190 my_bool is_filename_allowed(
const char *name __attribute__((unused)),
 
  191                             size_t length __attribute__((unused)),
 
  192                             my_bool allow_current_dir __attribute__((unused)))
 
  198   const char* ch = NULL;
 
  199   for (ch= name + length - 1; ch >= 
name; --ch)
 
  201     if (FN_LIBCHAR == *ch || 
'/' == *ch)
 
  211       return (allow_current_dir && (ch - name == 1) && 
 
  212               does_drive_exists(*name));
 
  219 #if defined(__WIN__) || defined(__EMX__) 
  234 int check_if_legal_filename(
const char *path)
 
  237   const char **reserved_name;
 
  238   DBUG_ENTER(
"check_if_legal_filename");
 
  240   if (!is_filename_allowed(path, strlen(path), TRUE))
 
  243   path+= dirname_length(path);                  
 
  244   if (!(end= strchr(path, FN_EXTCHAR)))
 
  246   if (path == end || (uint) (end - path) > MAX_RESERVED_NAME_LENGTH)
 
  249   for (reserved_name= reserved_names; *reserved_name; reserved_name++)
 
  251     const char *reserved= *reserved_name;       
 
  252     const char *name= path;
 
  256       if (*reserved != my_toupper(&my_charset_latin1, *name))
 
  258       if (++name == end && !reserved[1])
 
  260     } 
while (*++reserved);