Beispiel #1
0
bool CFile::OpenForWrite(const CURL& url, bool bOverWrite)
{
  m_fileSize = 0;

  Close();
  smb.Init();
  // we can't open files like smb://file.f or smb://server/file.f
  // if a file matches the if below return false, it can't exist on a samba share.
  if (!IsValidFile(url.GetFileName())) return false;

  CStdString strFileName = GetAuthenticatedPath(url);
  CLockObject lock(smb);

  if (bOverWrite)
  {
    XBMC->Log(LOG_WARNING, "FileSmb::OpenForWrite() called with overwriting enabled! - %s", strFileName.c_str());
    m_fd = smbc_creat(strFileName.c_str(), 0);
  }
  else
  {
    m_fd = smbc_open(strFileName.c_str(), O_RDWR, 0);
  }

  if (m_fd == -1)
  {
    // write error to logfile
    XBMC->Log(LOG_ERROR, "FileSmb->Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", strFileName.c_str(), errno, strerror(errno));
    return false;
  }

  // We've successfully opened the file!
  return true;
}
Beispiel #2
0
/***************************************************** 
a wrapper for open()
*******************************************************/
int smbw_open(const char *fname, int flags, mode_t mode)
{
        int client_fd;
        int smbw_fd;
	char path[PATH_MAX];

	SMBW_INIT();

	if (!fname) {
		errno = EINVAL;
		return -1;
	}

	smbw_fd = (smbw_libc.open)(SMBW_DUMMY, O_WRONLY, 0200);
	if (smbw_fd == -1) {
		errno = EMFILE;
                return -1;
	}

        smbw_fix_path(fname, path);
        if (flags == creat_bits) {
                client_fd =  smbc_creat(path, mode);
        } else {
                client_fd = smbc_open(path, flags, mode);
        }

        if (client_fd < 0) {
                (* smbw_libc.close)(smbw_fd);
                return -1;
        }

        smbw_fd_map[smbw_fd] = client_fd;
        smbw_ref(client_fd, SMBW_RCT_Increment);
        return smbw_fd;
}
Beispiel #3
0
void* OpenForWrite(VFSURL* url, bool bOverWrite)
{ 
  CSMB2::Get().Init();
  // we can't open files like smb://file.f or smb://server/file.f
  // if a file matches the if below return false, it can't exist on a samba share.
  if (!IsValidFile(url->filename))
    return NULL;

  std::string strFileName = GetAuthenticatedPath(url);
  PLATFORM::CLockObject lock(CSMB2::Get());

  SMBContext* result = new SMBContext;
  if (bOverWrite)
  {
    XBMC->Log(ADDON::LOG_INFO, "FileSmb::OpenForWrite() called with overwriting enabled! - %s", strFileName.c_str());
    result->fd = smbc_creat(strFileName.c_str(), 0);
  }
  else
  {
    result->fd = smbc_open(strFileName.c_str(), O_RDWR, 0);
  }

  if (result->fd == -1)
  {
    // write error to logfile
    XBMC->Log(ADDON::LOG_ERROR, "FileSmb->Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", strFileName.c_str(), errno, strerror(errno));
    delete result;
    return NULL;
  }

  // We've successfully opened the file!
  return result;
}
Beispiel #4
0
int main(int argc, char** argv)
{
	int err = -1;
	int fd = 0; 
	char url[MAX_BUFF_SIZE];

	bzero(g_workgroup,MAX_BUFF_SIZE);
	bzero(url,MAX_BUFF_SIZE);

	if ( argc == 5 )
	{

		strncpy(g_workgroup,argv[1],strlen(argv[1]));
		strncpy(g_username,argv[2],strlen(argv[2]));
		strncpy(g_password,argv[3],strlen(argv[3]));
		strncpy(url,argv[4],strlen(argv[4]));

		smbc_init(auth_fn, 0);
		fd = smbc_creat(url, 0666);

		if ( fd < 0 )
			err = 1;

		else
			err = 0;

	}

	return err;

}
Beispiel #5
0
int smbc_wrapper_create(connection* con, const char *furl, int flags, mode_t mode)
{
	if(con->mode== SMB_BASIC)
		return smbc_creat(furl, mode);
	else if(con->mode == SMB_NTLM)
		return smbc_cli_ntcreate(con->smb_info->cli, furl, flags, FILE_CREATE, mode);

	return -1;
}
Beispiel #6
0
static csync_vio_method_handle_t *_creat(const char *durl, mode_t mode) {
  smb_fhandle_t *handle = NULL;
  int fd = -1;

  if ((fd = smbc_creat(durl, mode)) < 0) {
    return NULL;
  }

  handle = c_malloc(sizeof(smb_fhandle_t));
  if (handle == NULL) {
    return NULL;
  }

  handle->fd = fd;
  return (csync_vio_method_handle_t *) handle;
}
Beispiel #7
0
static int smbcfs_create(const char* const path, const mode_t mode, struct fuse_file_info* const fi)
{

  const std::string smbcfs_path = smbcfs_root_path + path;

#ifdef MUTEX_LOCK
  pthread_mutex_lock(&mutex_lock);  
#endif

  const int ret_creat = smbc_creat(smbcfs_path.c_str(), mode);

#ifdef MUTEX_LOCK
  pthread_mutex_unlock(&mutex_lock);  
#endif

#ifdef SMBCFS_DEBUG
  fprintf(stderr, "[smbc_creat] %s %d => %d\n", smbcfs_path.c_str(), mode, ret_creat);
#endif

  if(ret_creat<0) { return ret_creat; }

  fi->fh = ret_creat;
  return 0;
}