Ejemplo n.º 1
0
uint_t ftpServerGetFilePermCallback(FtpClientConnection *connection,
   const char_t *user, const char_t *path)
{
   uint_t perm;

   //Debug message
   TRACE_INFO("FTP server: Checking access rights for %s\r\n", path);

   //Manage access rights
   if(!strcmp(user, "anonymous"))
   {
      //Allow read/write access to temp directory
      if(pathMatch(path, "/temp/*"))
         perm = FTP_FILE_PERM_LIST | FTP_FILE_PERM_READ | FTP_FILE_PERM_WRITE;
      //Allow read access only to other directories
      else
         perm = FTP_FILE_PERM_LIST | FTP_FILE_PERM_READ;
   }
   else if(!strcmp(user, "admin"))
   {
      //Allow read/write access
      perm = FTP_FILE_PERM_LIST | FTP_FILE_PERM_READ | FTP_FILE_PERM_WRITE;
   }
   else
   {
      //Deny access
      perm = 0;
   }

   //Return the relevant permissions
   return perm;
}
Ejemplo n.º 2
0
HttpAccessStatus httpServerAuthCallback(HttpConnection *connection,
   const char_t *user, const char_t *uri)
{
   HttpAccessStatus status;

   //Manage access rights
   if(pathMatch(uri, "/passwords.txt"))
   {
      //This file is not visible
      status = HTTP_ACCESS_DENIED;
   }
   else if(pathMatch(uri, "/config/*"))
   {
      //This directory is not visible
      status = HTTP_ACCESS_DENIED;
   }
   else if(pathMatch(uri, "/admin/*"))
   {
      //Only the administrator can access this directory
      if(!strcmp(user, "administrator"))
      {
         //Check the administrator password
         if(httpCheckPassword(connection, "password", HTTP_AUTH_MODE_BASIC))
            status = HTTP_ACCESS_ALLOWED;
         else
            status = HTTP_ACCESS_BASIC_AUTH_REQUIRED;
      }
      else
      {
         //Users other than administrator cannot access this directory
         status = HTTP_ACCESS_BASIC_AUTH_REQUIRED;
      }
   }
   else
   {
      //No restriction for other directories
      status = HTTP_ACCESS_ALLOWED;
   }

   //Return access status
   return status;
}
Ejemplo n.º 3
0
bool_t pathMatch(const char_t *path, const char_t* pattern)
{
   size_t i = 0;
   size_t j = 0;

   //Parse the pattern string
   while(pattern[j] != '\0')
   {
      //Any wildcard character found?
      if(pattern[j] == '?')
      {
         //The question mark matches a single character
         if(path[i] == '\0')
         {
            return FALSE;
         }
         else
         {
            //Advance position in pathname
            i++;
            //Advance position in pattern string
            j++;
         }
      }
      else if(pattern[j] == '*')
      {
         //The asterisk sign matches zero or more characters
         if(path[i] == '\0')
         {
            //Advance position in pattern string
            j++;
         }
         else if(pathMatch(path + i, pattern + j + 1))
         {
            return TRUE;
         }
         else
         {
            //Advance position in pathname
            i++;
         }
      }
      else
      {
         //Case insensitive comparison
         if(tolower((uint8_t) path[i]) != tolower((uint8_t) pattern[j]))
         {
            return FALSE;
         }
         else
         {
            //Advance position in pathname
            i++;
            //Advance position in pattern string
            j++;
         }
      }
   }

   //Check whether the file name matches the specified pattern
   if(path[i] == '\0' && pattern[j] == '\0')
      return TRUE;
   else
      return FALSE;
}