Exemplo n.º 1
0
int main(int argc, char** argv)
{
	int err = -1;
	int fd1 = 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 );
		fd1 = smbc_open( url, O_RDWR | O_CREAT, 0666 );
		smbc_close( fd1 );	

		smbc_rename( url, NULL );

		err = errno;	

	}

	return err;

}
Exemplo n.º 2
0
/* rename or move (file&folder) */
int SMB_remo(char *localoldpath, char *localnewpath, int index)
{
        SMB_init(index);
        char *serveroldpath, *servernewpath;
        serveroldpath = localpath_to_serverpath(localoldpath, index);
        servernewpath = localpath_to_serverpath(localnewpath, index);
        int res = smbc_rename(serveroldpath, servernewpath);
        if(res != 0)
        {
                if(!test_if_dir(localnewpath)){
                        res = SMB_upload(localnewpath, index);
                        if(res == 0)
                        {
                                time_t modtime = Getmodtime(servernewpath, index);
                                if(ChangeFile_modtime(localnewpath, modtime, index))
                                {
                                        printf("ChangeFile_modtime failed!\n");
                                }
                        }
                }else{
                        res = moveFolder(localoldpath, localnewpath, index);
                }
        }
        free(serveroldpath);
        free(servernewpath);
        return res;
}
Exemplo n.º 3
0
int main(int argc, char** argv)
{
	int err = -1;
	char url[MAX_BUFF_SIZE];

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

	if ( argc == 6 )
	{

		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);
		err = smbc_rename( url, argv[5] );

		if ( err < 0 )
			err = 1;


	}

	return err;

}
Exemplo n.º 4
0
int main(int argc, char** argv)
{
	int err = -1;
	char url[MAX_BUFF_SIZE];

	memset(g_workgroup, '\0', MAX_BUFF_SIZE);
	memset(url, '\0', MAX_BUFF_SIZE);

	if ( argc == 6 )
	{
		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);
		smbc_rename( url, argv[5] );

		err = errno;

	}

	return err;

}
Exemplo n.º 5
0
uint32_t smbc_wrapper_rename(connection* con, char *src, char *dst)
{
	if(con->mode== SMB_BASIC)
		return smbc_rename(src, dst);
	else if(con->mode == SMB_NTLM)
		return smbc_cli_rename(con->smb_info->cli, src, dst);

	return 0;
}
Exemplo n.º 6
0
int FSSmb::Rename( FSPath&  oldpath, FSPath& newpath, int* err,  FSCInfo* info )
{
	FREPARE_SMB_OPER( lock, info, &_param );

	int n = smbc_rename(
	           pathBuffer1.SetPath( oldpath ),
	           pathBuffer2.SetPath( newpath )
	        );
	SetError( err, errno );
	return n < 0 ? -1 : n;
}
Exemplo n.º 7
0
/***************************************************** 
a wrapper for rename()
*******************************************************/
int smbw_rename(const char *oldname, const char *newname)
{
        char path_old[PATH_MAX];
        char path_new[PATH_MAX];

        SMBW_INIT();

        smbw_fix_path(oldname, path_old);
        smbw_fix_path(newname, path_new);
        return smbc_rename(path_old, path_new);
}
Exemplo n.º 8
0
bool CFile::Rename(const CURL& url, const CURL& urlnew)
{
  smb.Init();
  CStdString strFile = GetAuthenticatedPath(url);
  CStdString strFileNew = GetAuthenticatedPath(urlnew);
  CLockObject lock(smb);

  int result = smbc_rename(strFile.c_str(), strFileNew.c_str());

  if(result != 0)
    XBMC->Log(LOG_ERROR, "%s - Error( %s )", __FUNCTION__, strerror(errno));

  return (result == 0);
}
Exemplo n.º 9
0
bool Rename(VFSURL* url, VFSURL* url2)
{
  CSMB2::Get().Init();
  std::string strFile = GetAuthenticatedPath(url);
  std::string strFileNew = GetAuthenticatedPath(url2);
  PLATFORM::CLockObject lock(CSMB2::Get());

  int result = smbc_rename(strFile.c_str(), strFileNew.c_str());

  if(result != 0)
    XBMC->Log(ADDON::LOG_ERROR, "%s - Error( %s )", __FUNCTION__, strerror(errno));

  return (result == 0);
}
Exemplo n.º 10
0
int main(int argc, char** argv)
{
    int err = -1;
    int fd1 = 0;
    int fd2 = 0;
    char url[MAX_BUFF_SIZE];

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

    if ( argc == 7 )
    {
        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 );
        fd1 = smbc_open( url, O_RDWR | O_CREAT, 0666 );
        smbc_close( fd1 );

        smbc_mkdir( argv[5], 0666 );
        smbc_rename( url, argv[6] );

        fd1 = smbc_open( url, O_RDWR, 0666 );
        fd2 = smbc_open( argv[6], O_RDWR, 0666 );

        if ( fd1 == -1 && fd2 != -1 )
            err = 0;

        else
            err = 1;


    }

    return err;

}
Exemplo n.º 11
0
int FileRename( const char *src, const char *dst )
{
	char *ptr;
	int c;

	if( (ptr = strchr( src, ':' )) == NULL ) {
#ifdef _DEBUG
		printf("FileRename : Invalid Path (ptr = NULL)\n");
#endif
		return -1;
	}

	c = ptr - src;

	if( !strncmp( src, "pfs", 3 ) )
	{
		return fileXioRename( src, dst );
	}
	else if( !strncmp( src, "mc0:", c ) || !strncmp( src, "mc1:", c ) )
	{
		// Note : mcRename doesn't work
		// TODO : mc renaming not implemented yet
		printf("FileRename : Not implemented for Memory Card!\n");
		return -1;
	}
	else if( !strncmp( src, "mass:", c ) ) 
	{
		// TODO : usb renaming not implemented yet
		printf("FileRename : Not implemented for USB!\n");
		return -1;
	}
	else if( !strncmp( src, "smb:", c ) )
	{
		return smbc_rename( src, dst );
	}

	return -1;
}
Exemplo n.º 12
0
Arquivo: main.cpp Projeto: aont/smbcfs
static int smbcfs_rename(const char* const ourl, const char* const nurl)
{

  const std::string smb_ourl = smbcfs_root_path + ourl;
  const std::string smb_nurl = smbcfs_root_path + nurl;

#ifdef MUTEX_LOCK
  pthread_mutex_lock(&mutex_lock);  
#endif

  const int ret_rename = smbc_rename(smb_ourl.c_str(), smb_nurl.c_str());

#ifdef MUTEX_LOCK
  pthread_mutex_unlock(&mutex_lock);  
#endif

#ifdef SMBCFS_DEBUG
  fprintf(stderr, "[smbc_rename] %s %s => %d\n",
	  smb_ourl.c_str(), smb_nurl.c_str(), ret_rename);
#endif

  return ret_rename;

}			
Exemplo n.º 13
0
int main(int argc, char *argv[])
{
  int err, fd, dh1, dsize, dirc;
  const char *file = "smb://samba/public/testfile.txt";
  const char *file2 = "smb://samba/public/testfile2.txt";
  char buff[256];
  char dirbuf[512];
  char *dirp;
  struct stat st1, st2;

  err = smbc_init(get_auth_data_fn,  10); /* Initialize things */

  if (err < 0) {

    fprintf(stderr, "Initializing the smbclient library ...: %s\n", strerror(errno));

  }

  if (argc > 1) {

    if ((dh1 = smbc_opendir(argv[1]))<1) {

      fprintf(stderr, "Could not open directory: %s: %s\n",
	      argv[1], strerror(errno));

      exit(1);

    }

    fprintf(stdout, "Directory handle: %u\n", dh1);

    /* Now, list those directories, but in funny ways ... */

    dirp = (char *)dirbuf;

    if ((dirc = smbc_getdents(dh1, (struct smbc_dirent *)dirp, 
			      sizeof(dirbuf))) < 0) {

      fprintf(stderr, "Problems getting directory entries: %s\n",
	      strerror(errno));

      exit(1);

    }

    /* Now, process the list of names ... */

    fprintf(stdout, "Directory listing, size = %u\n", dirc);

    while (dirc > 0) {

      dsize = ((struct smbc_dirent *)dirp)->dirlen;
      fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n",
	      ((struct smbc_dirent *)dirp)->smbc_type, 
	      ((struct smbc_dirent *)dirp)->name, 
	      ((struct smbc_dirent *)dirp)->comment);

      dirp += dsize;
      dirc -= dsize;

    }

    dirp = (char *)dirbuf;

    exit(1);

  }

  /* For now, open a file on a server that is hard coded ... later will
   * read from the command line ...
   */

  fd = smbc_open(file, O_RDWR | O_CREAT | O_TRUNC, 0666);

  if (fd < 0) {

    fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Opened or created file: %s\n", file);

  /* Now, write some date to the file ... */

  memset(buff, '\0', sizeof(buff));
  snprintf(buff, sizeof(buff), "%s", "Some test data for the moment ...");

  err = smbc_write(fd, buff, sizeof(buff));

  if (err < 0) {
    
    fprintf(stderr, "writing file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Wrote %lu bytes to file: %s\n",
          (unsigned long) sizeof(buff), buff);

  /* Now, seek the file back to offset 0 */

  err = smbc_lseek(fd, SEEK_SET, 0);

  if (err < 0) {

    fprintf(stderr, "Seeking file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Completed lseek on file: %s\n", file);

  /* Now, read the file contents back ... */

  err = smbc_read(fd, buff, sizeof(buff));

  if (err < 0) {

    fprintf(stderr, "Reading file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Read file: %s\n", buff);  /* Should check the contents */

  fprintf(stdout, "Now fstat'ing file: %s\n", file);

  err = smbc_fstat(fd, &st1);

  if (err < 0) {

    fprintf(stderr, "Fstat'ing file: %s: %s\n", file, strerror(errno));
    exit(0);

  }


  /* Now, close the file ... */

  err = smbc_close(fd);

  if (err < 0) {

    fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));

  }

  /* Now, rename the file ... */

  err = smbc_rename(file, file2);

  if (err < 0) {

    fprintf(stderr, "Renaming file: %s to %s: %s\n", file, file2, strerror(errno));

  }

  fprintf(stdout, "Renamed file %s to %s\n", file, file2);

  /* Now, create a file and delete it ... */

  fprintf(stdout, "Now, creating file: %s so we can delete it.\n", file);

  fd = smbc_open(file, O_RDWR | O_CREAT, 0666);

  if (fd < 0) {

    fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Opened or created file: %s\n", file);

  err = smbc_close(fd);

  if (err < 0) {

    fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));
    exit(0);

  }
  
  /* Now, delete the file ... */

  fprintf(stdout, "File %s created, now deleting ...\n", file);

  err = smbc_unlink(file);

  if (err < 0) {

    fprintf(stderr, "Deleting file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  /* Now, stat the file, file 2 ... */

  fprintf(stdout, "Now stat'ing file: %s\n", file);

  err = smbc_stat(file2, &st2);

  if (err < 0) {

    fprintf(stderr, "Stat'ing file: %s: %s\n", file, strerror(errno));
    exit(0);

  }

  fprintf(stdout, "Stat'ed file:   %s. Size = %d, mode = %04X\n", file2, 
	  (int)st2.st_size, (unsigned int)st2.st_mode);
  fprintf(stdout, "    time: %s\n", ctime(&st2.st_atime));
  fprintf(stdout, "Earlier stat:   %s, Size = %d, mode = %04X\n", file, 
	  (int)st1.st_size, (unsigned int)st1.st_mode);
  fprintf(stdout, "    time: %s\n", ctime(&st1.st_atime));

  /* Now, make a directory ... */

  fprintf(stdout, "Making directory smb://samba/public/make-dir\n");

  if (smbc_mkdir("smb://samba/public/make-dir", 0666) < 0) {

    fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n", 
	    strerror(errno));

    if (errno == EEXIST) { /* Try to delete the directory */

      fprintf(stdout, "Trying to delete directory: smb://samba/public/make-dir\n");

      if (smbc_rmdir("smb://samba/public/make-dir") < 0) { /* Error */

	fprintf(stderr, "Error removing directory: smb://samba/public/make-dir: %s\n", strerror(errno));

	exit(0);

      }

      fprintf(stdout, "Making directory: smb://samba/public/make-dir\n");

      if (smbc_mkdir("smb://samba/public/make-dir", 666) < 0) {

	fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n",
		strerror(errno));

	fprintf(stderr, "I give up!\n");

	exit(1);

      }

    }

    exit(0);
    
  }

  fprintf(stdout, "Made dir: make-dir\n");
  return 0;
}
Exemplo n.º 14
0
static int _rename(const char *olduri, const char *newuri) {
  return smbc_rename(olduri, newuri);
}
Exemplo n.º 15
0
//===========================================================================
void SMBSlave::rename( const QUrl& ksrc, const QUrl& kdest, KIO::JobFlags flags )
{

    SMBUrl      src;
    SMBUrl      dst;
    int         errNum = 0;
    int         retVal = 0;

    qCDebug(KIO_SMB) << "old name = " << ksrc << ", new name = " << kdest;

    src = ksrc;
    dst = kdest;

    // Check to se if the destination exists

    qCDebug(KIO_SMB) << "stat dst";
    errNum = cache_stat(dst, &st);
    if( errNum == 0 )
    {
        if(S_ISDIR(st.st_mode))
        {
            qCDebug(KIO_SMB) << "KIO::ERR_DIR_ALREADY_EXIST";
            error( KIO::ERR_DIR_ALREADY_EXIST, dst.toDisplayString());
            return;
        }
        if(!(flags & KIO::Overwrite))
        {
            qCDebug(KIO_SMB) << "KIO::ERR_FILE_ALREADY_EXIST";
            error( KIO::ERR_FILE_ALREADY_EXIST, dst.toDisplayString());
            return;
        }
    }
    qCDebug(KIO_SMB ) << "smbc_rename " << src.toSmbcUrl() << " " << dst.toSmbcUrl();
    retVal = smbc_rename(src.toSmbcUrl(), dst.toSmbcUrl());
    if( retVal < 0 ){
        errNum = errno;
    } else {
        errNum = 0;
    }

    if( retVal < 0 )
    {
      qCDebug(KIO_SMB ) << "failed ";
      switch(errNum)
      {
        case ENOENT:
          errNum = cache_stat(src, &st);
          if( errNum != 0 )
          {
              if(errNum == EACCES)
	      {
	        qCDebug(KIO_SMB) << "KIO::ERR_ACCESS_DENIED";
                error(KIO::ERR_ACCESS_DENIED, src.toDisplayString());
              }
              else
              {
		qCDebug(KIO_SMB) << "KIO::ERR_DOES_NOT_EXIST";
                error(KIO::ERR_DOES_NOT_EXIST, src.toDisplayString());
              }
          }
          break;

        case EACCES:
        case EPERM:
          qCDebug(KIO_SMB) << "KIO::ERR_ACCESS_DENIED";
          error( KIO::ERR_ACCESS_DENIED, dst.toDisplayString() );
          break;

        default:
          qCDebug(KIO_SMB) << "KIO::ERR_CANNOT_RENAME";
          error( KIO::ERR_CANNOT_RENAME, src.toDisplayString() );

      }

      qCDebug(KIO_SMB) << "exit with error";
      return;
    }

    qCDebug(KIO_SMB ) << "everything fine\n";
    finished();
}
Exemplo n.º 16
0
void SMBSlave::smbCopyPut(const QUrl& ksrc, const QUrl& kdst, int permissions, KIO::JobFlags flags)
{
    qCDebug(KIO_SMB) << "src = " << ksrc << ", dest = " << kdst;

    QFile srcFile (ksrc.toLocalFile());
    const QFileInfo srcInfo (srcFile);

    if (srcInfo.exists()) {
        if (srcInfo.isDir()) {
            error(KIO::ERR_IS_DIRECTORY, ksrc.toDisplayString());
            return;
        }
    } else {
        error(KIO::ERR_DOES_NOT_EXIST, ksrc.toDisplayString());
        return;
    }

    if (!srcFile.open(QFile::ReadOnly)) {
        qCDebug(KIO_SMB) << "could not read from" << ksrc;
        switch (srcFile.error()) {
          case QFile::PermissionsError:
              error(KIO::ERR_WRITE_ACCESS_DENIED, ksrc.toDisplayString());
              break;
          case QFile::OpenError:
          default:
              error(KIO::ERR_CANNOT_OPEN_FOR_READING, ksrc.toDisplayString());
              break;
        }
        return;
    }

    totalSize(static_cast<filesize_t>(srcInfo.size()));

    bool bResume = false;
    bool bPartExists = false;
    const bool bMarkPartial = config()->readEntry("MarkPartial", true);
    const SMBUrl dstOrigUrl (kdst);

    if (bMarkPartial) {
        const int errNum = cache_stat(dstOrigUrl.partUrl(), &st);
        bPartExists = (errNum == 0);
        if (bPartExists) {
            if (!(flags & KIO::Overwrite) && !(flags & KIO::Resume)) {
                bResume = canResume(st.st_size);
            } else {
                bResume = (flags & KIO::Resume);
            }
        }
    }

    int dstfd = -1;
    int errNum = cache_stat(dstOrigUrl, &st);

    if (errNum == 0 && !(flags & KIO::Overwrite) && !(flags & KIO::Resume)) {
        if (S_ISDIR(st.st_mode)) {
            error( KIO::ERR_IS_DIRECTORY, dstOrigUrl.toDisplayString());
        } else {
            error( KIO::ERR_FILE_ALREADY_EXIST, dstOrigUrl.toDisplayString());
        }
        return;
    }

    KIO::filesize_t processed_size = 0;
    const SMBUrl dstUrl(bMarkPartial ? dstOrigUrl.partUrl() : dstOrigUrl);

    if (bResume) {
        // append if resuming
        qCDebug(KIO_SMB) << "resume" << dstUrl;
        dstfd = smbc_open(dstUrl.toSmbcUrl(), O_RDWR, 0 );
        if (dstfd < 0) {
            errNum = errno;
        } else {
            const off_t offset = smbc_lseek(dstfd, 0, SEEK_END);
            if (offset == (off_t)-1) {
                error(KIO::ERR_COULD_NOT_SEEK, dstUrl.toDisplayString());
                smbc_close(dstfd);
                return;
            } else {
                processed_size = offset;
            }
        }
    } else {
        mode_t mode;
        if (permissions == -1) {
            mode = 600;
        } else {
            mode = permissions | S_IRUSR | S_IWUSR;
        }

        qCDebug(KIO_SMB) << "NO resume" << dstUrl;
        dstfd = smbc_open(dstUrl.toSmbcUrl(), O_CREAT | O_TRUNC | O_WRONLY, mode);
        if (dstfd < 0) {
            errNum = errno;
        }
    }

    if (dstfd < 0) {
        if (errNum == EACCES) {
            qCDebug(KIO_SMB) << "access denied";
            error( KIO::ERR_WRITE_ACCESS_DENIED, dstUrl.toDisplayString());
        }
        else {
            qCDebug(KIO_SMB) << "can not open for writing";
            error( KIO::ERR_CANNOT_OPEN_FOR_WRITING, dstUrl.toDisplayString());
        }
        return;
    }

    bool isErr = false;

    if (processed_size == 0 || srcFile.seek(processed_size)) {
        // Perform the copy
        char buf[MAX_XFER_BUF_SIZE];

        while (1) {
            const ssize_t bytesRead = srcFile.read(buf, MAX_XFER_BUF_SIZE);
            if (bytesRead <= 0) {
                if (bytesRead < 0) {
                    error(KIO::ERR_COULD_NOT_READ, ksrc.toDisplayString());
                    isErr = true;
                }
                break;
            }

            const qint64 bytesWritten = smbc_write(dstfd, buf, bytesRead);
            if (bytesWritten == -1) {
                error(KIO::ERR_COULD_NOT_WRITE, kdst.toDisplayString());
                isErr = true;
                break;
            }

            processed_size += bytesWritten;
            processedSize(processed_size);
        }
    } else {
        isErr = true;
        error(KIO::ERR_COULD_NOT_SEEK, ksrc.toDisplayString());
    }

    // FINISHED
    if (smbc_close(dstfd) < 0) {
        qCDebug(KIO_SMB) << dstUrl << "could not write";
        error( KIO::ERR_COULD_NOT_WRITE, dstUrl.toDisplayString());
        return;
    }

    // Handle error condition.
    if (isErr) {
        if (bMarkPartial) {
            const int size = config()->readEntry("MinimumKeepSize", DEFAULT_MINIMUM_KEEP_SIZE);
            const int errNum = cache_stat(dstUrl, &st);
            if (errNum == 0 && st.st_size < size) {
                smbc_unlink(dstUrl.toSmbcUrl());
            }
        }
        return;
    }

    // Rename partial file to its original name.
    if (bMarkPartial) {
        smbc_unlink(dstOrigUrl.toSmbcUrl());
        if (smbc_rename(dstUrl.toSmbcUrl(), dstOrigUrl.toSmbcUrl()) < 0) {
            qCDebug(KIO_SMB) << "failed to rename" << dstUrl << "to" << dstOrigUrl << "->" << strerror(errno);
            error(ERR_CANNOT_RENAME_PARTIAL, dstUrl.toDisplayString());
            return;
        }
    }

#ifdef HAVE_UTIME_H
    // set modification time
    const QString mtimeStr = metaData( "modified" );
    if (!mtimeStr.isEmpty() ) {
        QDateTime dt = QDateTime::fromString( mtimeStr, Qt::ISODate );
        if ( dt.isValid() ) {
            struct utimbuf utbuf;
            utbuf.actime = st.st_atime; // access time, unchanged
            utbuf.modtime = dt.toTime_t(); // modification time
            smbc_utime( dstUrl.toSmbcUrl(), &utbuf );
        }
    }
#endif

    // We have done our job => finish
    finished();
}