Beispiel #1
0
//int CFile::OpenFile(const CURL &url, CStdString& strAuth)
int CFile::OpenFile()
{
  int fd = -1;
  smb.Init();

  //strAuth = GetAuthenticatedPath(url);
  //CStdString strPath = strAuth;
  CStdString strPath = m_fileName;

  {
    CLockObject lock(smb);
    fd = smbc_open(strPath.c_str(), O_RDONLY, 0);
  }

  // file open failed, try to open the directory to force authentication
  if (fd < 0 && errno == EACCES)
  {
#if 0
    CURL urlshare(url);

    /* just replace the filename with the sharename */
    urlshare.SetFileName(url.GetShareName());

    CSMBDirectory smbDir;
    // TODO: Currently we always allow prompting on files.  This may need to
    // change in the future as background scanners are more prolific.
    smbDir.SetFlags(DIR_FLAG_ALLOW_PROMPT);
    fd = smbDir.Open(urlshare);

    // directory open worked, try opening the file again
    if (fd >= 0)
    {
      CLockObject lock(smb);
      // close current directory filehandle
      // dont need to purge since its the same server and share
      smbc_closedir(fd);

      // set up new filehandle (as CFile::Open does)
      strPath = GetAuthenticatedPath(url);

      fd = smbc_open(strPath.c_str(), O_RDONLY, 0);
    }
#else
  XBMC->Log(LOG_ERROR, "%s: File open on %s failed\n", __FUNCTION__, strPath.c_str());
#endif
  }

//  if (fd >= 0)
//    strAuth = strPath;

  return fd;
}
Beispiel #2
0
int CFileSMB::OpenFile(const CURL &url, CStdString& strAuth)
{
  int fd = -1;
  smb.Init();

  strAuth = GetAuthenticatedPath(url);
  CStdString strPath = strAuth;

  {
    CSingleLock lock(smb);
    fd = smbc_open(strPath.c_str(), O_RDONLY, 0);
  }

  // file open failed, try to open the directory to force authentication
#ifndef _LINUX
  if (fd < 0 && smb.ConvertUnixToNT(errno) == NT_STATUS_ACCESS_DENIED)
#else
  if (fd < 0 && errno == EACCES)
#endif
  {
    CURL urlshare(url);

    /* just replace the filename with the sharename */
    urlshare.SetFileName(url.GetShareName());

    CSMBDirectory smbDir;
    // TODO: Currently we always allow prompting on files.  This may need to
    // change in the future as background scanners are more prolific.
    smbDir.SetAllowPrompting(true);
    fd = smbDir.Open(urlshare);

    // directory open worked, try opening the file again
    if (fd >= 0)
    {
      CSingleLock lock(smb);
      // close current directory filehandle
      // dont need to purge since its the same server and share
      smbc_closedir(fd);

      // set up new filehandle (as CFileSMB::Open does)
      strPath = GetAuthenticatedPath(url);

      fd = smbc_open(strPath.c_str(), O_RDONLY, 0);
    }
  }

  if (fd >= 0)
    strAuth = strPath;

  return fd;
}
Beispiel #3
0
bool cPVRClientForTheRecord::ShareErrorsFound(void)
{
  bool bShareErrors = false;
  Json::Value activeplugins;
  int rc = ForTheRecord::GetPluginServices(false, activeplugins);
  if (rc != NOERROR)
  {
    XBMC->Log(LOG_ERROR, "Unable to get the ForTheRecord plugin services to check share accessiblity.");
    return false;
  }
 
  // parse plugins list
  int size = activeplugins.size();
  for ( int index =0; index < size; ++index )
  {
    std::string tunerName = activeplugins[index]["Name"].asString();
    XBMC->Log(LOG_DEBUG, "Checking tuner \"%s\" for accessibility.", tunerName.c_str());
    Json::Value accesibleshares;
    rc = ForTheRecord::AreRecordingSharesAccessible(activeplugins[index], accesibleshares);
    if (rc != NOERROR)
    {
      XBMC->Log(LOG_ERROR, "Unable to get the share status for tuner \"%s\".", tunerName.c_str());
      continue;
    }
    int numberofshares = accesibleshares.size();
    for (int j = 0; j < numberofshares; j++)
    {
      Json::Value accesibleshare = accesibleshares[j];
      tunerName = accesibleshare["RecorderTunerName"].asString();
      std::string sharename = accesibleshare["Share"].asString();
      bool isAccessibleByFTR = accesibleshare["ShareAccessible"].asBool();
      bool isAccessibleByAddon = false;
      std::string accessMsg = "";
#if defined(TARGET_WINDOWS)
      // Try to open the directory
      HANDLE hFile = ::CreateFile(sharename.c_str(),      // The filename
        (DWORD) GENERIC_READ,             // File access
        (DWORD) FILE_SHARE_READ,          // Share access
        NULL,                             // Security
        (DWORD) OPEN_EXISTING,            // Open flags
        (DWORD) FILE_FLAG_BACKUP_SEMANTICS, // More flags
        NULL);                            // Template
      if (hFile != INVALID_HANDLE_VALUE)
      {
        (void) CloseHandle(hFile);
        isAccessibleByAddon = true;
      }
      else
      {
        LPVOID lpMsgBuf;
        DWORD dwErr = GetLastError();
        FormatMessage(
          FORMAT_MESSAGE_ALLOCATE_BUFFER | 
          FORMAT_MESSAGE_FROM_SYSTEM |
          FORMAT_MESSAGE_IGNORE_INSERTS,
          NULL,
          dwErr,
          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
          (LPTSTR) &lpMsgBuf,
          0, NULL );
        accessMsg = (char*) lpMsgBuf;
        LocalFree(lpMsgBuf);
      }
#elif defined(TARGET_LINUX) || defined(TARGET_OSX)
      std::string CIFSname = sharename;
      std::string SMBPrefix = "smb://";
      if (g_szUser.length() > 0)
      {
        SMBPrefix += g_szUser;
        if (g_szPass.length() > 0)
        {
          SMBPrefix += ":" + g_szPass;
        }
      }
      else
      {
        SMBPrefix += "Guest";
      }
      SMBPrefix += "@";
      size_t found;
      while ((found = CIFSname.find("\\")) != std::string::npos)
      {
        CIFSname.replace(found, 1, "/");
      }
      CIFSname.erase(0,2);
      CIFSname.insert(0, SMBPrefix);
      CSMBDirectory smbDir;
      CURL curl(CIFSname);
      int iRc = smbDir.Open(curl);
      isAccessibleByAddon = (iRc > 0);
#else
#error implement for your OS!
#endif
      // write analysis results to the log
      if (isAccessibleByFTR)
      {
        XBMC->Log(LOG_DEBUG, "  Share \"%s\" is accessible to the ForTheRecord server.", sharename.c_str());
      }
      else
      {
        bShareErrors = true;
        XBMC->Log(LOG_ERROR, "  Share \"%s\" is NOT accessible to the ForTheRecord server.", sharename.c_str());
      }
      if (isAccessibleByAddon)
      {
        XBMC->Log(LOG_DEBUG, "  Share \"%s\" is readable from this client add-on.", sharename.c_str());
      }
      else
      {
        bShareErrors = true;
        XBMC->Log(LOG_ERROR, "  Share \"%s\" is NOT readable from this client add-on (\"%s\").", sharename.c_str(), accessMsg.c_str());
      }
    }
  }
  return bShareErrors;
}