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

	memset(g_workgroup, '\0', MAX_BUFF_SIZE);
	memset(url, '\0', 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 );

		err = smbc_rmdir( url );

		if ( err < 0 )
			err = 1;

		else
			err = 0;	


	}

	return err;

}
Ejemplo n.º 2
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 == 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 );
		smbc_rmdir( url );
		smbc_mkdir( url, 0666 );

		err = errno;	


	}

	return err;

}
Ejemplo 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 == 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 );
		smbc_mkdir( url, 700 );

		err = smbc_rmdir( url );

		if ( err < 0 )
			err = 1;

		else
			err = 0;	


	}

	return err;

}
Ejemplo n.º 4
0
int FSSmb::RmDir( FSPath& path, int* err, FSCInfo* info )
{
	FREPARE_SMB_OPER( lock, info, &_param );

	int n = smbc_rmdir( pathBuffer1.SetPath( path ) );
	SetError( err, errno );
	return n < 0 ? -1 : n;
}
Ejemplo n.º 5
0
uint32_t smbc_wrapper_rmdir(connection* con, const char *dname)
{
	if(con->mode== SMB_BASIC)
		return smbc_rmdir(dname);
	else if(con->mode == SMB_NTLM)
		return smbc_cli_rmdir(con->smb_info->cli, dname);

	return 0;
}
Ejemplo n.º 6
0
Archivo: main.cpp Proyecto: aont/smbcfs
static int smbcfs_rmdir(const char* const path)
{

  const std::string smbcfs_path = smbcfs_root_path + path;

#ifdef MUTEX_LOCK
  pthread_mutex_lock(&mutex_lock);  
#endif

  const int ret_rmdir = smbc_rmdir(smbcfs_path.c_str());

#ifdef MUTEX_LOCK
  pthread_mutex_unlock(&mutex_lock);  
#endif

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

  return ret_rmdir;
}
Ejemplo n.º 7
0
//===========================================================================
void SMBSlave::del( const QUrl &kurl, bool isfile)
{
    qCDebug(KIO_SMB) << kurl;
    m_current_url = kurl;
    int errNum = 0;
    int retVal = 0;

    if(isfile)
    {
        // Delete file
        qCDebug(KIO_SMB) << kurl;
        retVal = smbc_unlink(m_current_url.toSmbcUrl());
        if ( retVal < 0 ){
            errNum = errno;
        } else {
            errNum = 0;
        }
    }
    else
    {
        qCDebug(KIO_SMB) << kurl;
        // Delete directory
        retVal = smbc_rmdir(m_current_url.toSmbcUrl());
        if( retVal < 0 ) {
            errNum = errno;
        } else {
            errNum = 0;
        }
    }

    if( errNum != 0 )
    {
        reportError(kurl, errNum);
    }
    else
    {
        finished();
    }
}
Ejemplo n.º 8
0
int SMB_del(char *url, int index)
{
        SMB_init(index);
        int res = 0;
        int dh = 0;
        dh = smbc_opendir(url);
        printf("SMB_del() - dh = %d\n", dh);
        if(dh < 0){
                res = smbc_unlink(url);
        }
        else{
                struct smbc_dirent* dirptr;
                if(url[strlen(url) - 1] != '/')
                        strcat(url, "/");
                while((dirptr = smbc_readdir(dh)) != NULL){
                        if(!strcmp(dirptr->name, ".") || !strcmp(dirptr->name, ".."))
                                continue;

                        char new_url[255] = {0};
                        sprintf(new_url, "%s%s", url, dirptr->name);

                        printf("-------%s\n", new_url);

                        if(dirptr->smbc_type == SMBC_DIR) {
                                if(new_url[strlen(new_url) - 1] != '/')
                                        strcat(new_url, "/");
                                SMB_del(new_url, index);
                        }
                        else if(dirptr->smbc_type == SMBC_FILE) {
                                res = smbc_unlink(new_url);
                        }
                }
                res = smbc_rmdir(url);//删除成功返回0,失败返回-1
        }
        smbc_closedir(dh);
        return res;
}
Ejemplo n.º 9
0
bool RemoveDirectory(VFSURL* url)
{
  PLATFORM::CLockObject lock(CSMB2::Get());
  CSMB2::Get().Init();

  if (!XBMC->AuthenticateURL(url))
    return false;

  std::string strFileName = CSMB2::Get().URLEncode(url->domain, url->hostname, url->filename,
                                                  url->username, url->password);

  XBMC->FreeString((char*)url->username);
  XBMC->FreeString((char*)url->password);

  int result = smbc_rmdir(strFileName.c_str());

  if(result != 0 && errno != ENOENT)
  {
    XBMC->Log(ADDON::LOG_ERROR, "%s - Error( %s )", __FUNCTION__, strerror(errno));
    return false;
  }

  return true;
}
Ejemplo n.º 10
0
int main(int argc, char** argv)
{
	int err = -1;
	int fd = 0;
	int dh = 0; 
	int entry_num = 0;
	int i = 0;
	char *file_name;
	char *tmp_file_ptr;

	char buff[MAX_BUFF_SIZE];
	char url[MAX_BUFF_SIZE];
	char file_url[MAX_BUFF_SIZE];
	char dir_url[MAX_BUFF_SIZE];

	bzero(g_workgroup,MAX_BUFF_SIZE);
	bzero(url,MAX_BUFF_SIZE);
	bzero(file_url,MAX_BUFF_SIZE);
	bzero(dir_url,MAX_BUFF_SIZE);
	bzero(buff,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);

		strncpy(file_url,"tempfile-",9);
		tmp_file_ptr = file_url;
		tmp_file_ptr += 9;

		smbc_rmdir(url);
		smbc_mkdir(url,0666);

		entry_num = atoi(argv[5]);
		strcat(dir_url,url);
		strcat(dir_url,"/");

		file_name = dir_url;
		file_name += strlen(dir_url);

		for ( i = 0; i < entry_num; i++ )
		{
			sprintf(buff,"%d",i);
			memcpy(tmp_file_ptr,buff,strlen(buff)+4);	
			strncat(tmp_file_ptr,".txt",4);
			strcpy(file_name,file_url);
			fd = smbc_open(dir_url,O_RDWR | O_CREAT, 0666);
			smbc_close(fd);

		}

		dh = smbc_opendir(url);
		smbc_telldir(dh);
	
		err = errno;

	}

	return err;

}
Ejemplo n.º 11
0
int main(int argc, char** argv)
{
	int err = -1;
	int fd = 0;
	int dh = 0; 
	int entry_num = 0;
	int i = 0;
	int j = 0;
	char *file_name;
	char *tmp_file_ptr;
	int direntsize = 0;
	int diramount = 0;

	struct smbc_dirent *dirptr;


	char buff[MAX_BUFF_SIZE];
	char url[MAX_BUFF_SIZE];
	char file_url[MAX_BUFF_SIZE];
	char dir_url[MAX_BUFF_SIZE];
	char dirbuff[MAX_BUFF_SIZE];

	bzero(g_workgroup,MAX_BUFF_SIZE);
	bzero(url,MAX_BUFF_SIZE);
	bzero(file_url,MAX_BUFF_SIZE);
	bzero(dir_url,MAX_BUFF_SIZE);
	bzero(buff,MAX_BUFF_SIZE);

	if ( argc == 6 )
	{

		dirptr = (struct smbc_dirent *) dirbuff;

		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);

		strncpy(file_url,"tempfile-",9);
		tmp_file_ptr = file_url;
		tmp_file_ptr += 9;

		smbc_rmdir(url);
		smbc_mkdir(url,0666);

		entry_num = atoi(argv[5]);
		strcat(dir_url,url);
		strcat(dir_url,"/");

		file_name = dir_url;
		file_name += strlen(dir_url);

		for ( i = 0; i < entry_num; i++ )
		{
			sprintf(buff,"%d",i);
			memcpy(tmp_file_ptr,buff,strlen(buff)+4);
			strncat(tmp_file_ptr,".txt",4);
			strcpy(file_name,file_url);
			fd = smbc_open(dir_url,O_RDWR | O_CREAT, 0666);
			smbc_close(fd);

		}

		dh = smbc_opendir(url);
		diramount = smbc_getdents( dh, dirptr, sizeof(dirbuff));

		err = 0;
		i = 0;
		bzero(buff,MAX_BUFF_SIZE);
		bzero(tmp_file_ptr,MAX_BUFF_SIZE-9);

		while ( diramount > 0 )
		{
			direntsize = dirptr->dirlen;
			/* printf("Name: %s\n",dirptr->name); */
			if ( j == 0 )
			{
				if ( !(( strncmp(dirptr->name,".",1) == 0 )) ) 
				{
					break;
					err = 1; 
				}

			} else if ( j == 1 ) {	

				if ( !(( strncmp(dirptr->name,"..",2) == 0 )) )
			       	{
					break;
					err = 1; 
				} 
			
			} else if ( j > 1 ) {

					sprintf(buff,"%d",i);
					memcpy(tmp_file_ptr,buff,strlen(buff)+4);
					strncat(tmp_file_ptr,".txt",4);

					if ( !((strcmp(dirptr->name,file_url) == 0 )) ) /* make sure entries match */
					{
						err = 1;
						break;
					}

					i++;

			}

			(char *)dirptr += direntsize;
			(char *)diramount -= direntsize;
			j++;

		}
	
		if ( ! err )
		{
			if ( (j - 2) != entry_num ) /* Make sure that all entries created are counted and returned - minus . and .. */
				err = 1;
		}	

	}

	return err;

}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
int main(int argc, char** argv)
{
	int err = -1;
	int fd = 0;
	int dh = 0; 
	int entry_num = 0;
	int i = 0;
	int offset = 0;
	int dirsize = 0;
	char *file_name;
	char *tmp_file_ptr;

	struct smbc_dirent *dirptr;


	char buff[MAX_BUFF_SIZE];
	char url[MAX_BUFF_SIZE];
	char file_url[MAX_BUFF_SIZE];
	char dir_url[MAX_BUFF_SIZE];
	char dirbuff[MAX_BUFF_SIZE];

	memset(g_workgroup, '\0', MAX_BUFF_SIZE);
	memset(url, '\0', MAX_BUFF_SIZE);
	memset(file_url, '\0', MAX_BUFF_SIZE);
	memset(dir_url, '\0', MAX_BUFF_SIZE);
	memset(buff, '\0', MAX_BUFF_SIZE);

	if ( argc == 6 )
	{

		dirptr = (struct smbc_dirent *) dirbuff;

		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);

		strncpy(file_url,"tempfile-",9);
		tmp_file_ptr = file_url;
		tmp_file_ptr += 9;

		smbc_rmdir(url);
		smbc_mkdir(url,0666);

		entry_num = atoi(argv[5]);
		strcat(dir_url,url);
		strcat(dir_url,"/");

		file_name = dir_url;
		file_name += strlen(dir_url);

		for ( i = 0; i < entry_num; i++ )
		{
			sprintf(buff,"%d",i);
			memcpy(tmp_file_ptr,buff,strlen(buff)+4);
			strncat(tmp_file_ptr,".txt",4);
			strcpy(file_name,file_url);
			fd = smbc_open(dir_url,O_RDWR | O_CREAT, 0666);
			smbc_close(fd);

		}

		dh = smbc_opendir(url);
		err = 0;

		while ( 1 )
		{
			dirptr = smbc_readdir(dh);

			if ( dirptr == NULL )
			{
				break;
			}

			dirsize += dirptr->dirlen;

		}
		
		offset = smbc_telldir(dh);	

		if ( offset != dirsize )
		{
/*
                        printf("offset: %i dirsize: %i\n", offset, dirsize);
*/
			err = 1;
		}	

	}

	return err;

}
Ejemplo n.º 14
0
static int _rmdir(const char *uri) {
  return smbc_rmdir(uri);
}
Ejemplo n.º 15
0
int main(int argc, char** argv)
{
	int err = -1;
	int fd = 0;
	int dh = 0; 
	int entry_num = 0;
	int i = 0;
	char *file_name;
	char *tmp_file_ptr;

	char buff[MAX_BUFF_SIZE];
	char url[MAX_BUFF_SIZE];
	char file_url[MAX_BUFF_SIZE];
	char dir_url[MAX_BUFF_SIZE];

	memset(g_workgroup, '\0', MAX_BUFF_SIZE);
	memset(url, '\0', MAX_BUFF_SIZE);
	memset(file_url, '\0', MAX_BUFF_SIZE);
	memset(dir_url, '\0', MAX_BUFF_SIZE);
	memset(buff, '\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);

		strncpy(file_url,"tempfile-",9);
		tmp_file_ptr = file_url;
		tmp_file_ptr += 9;

		smbc_rmdir(url);
		smbc_mkdir(url,0666);

		entry_num = atoi(argv[5]);
		strcat(dir_url,url);
		strcat(dir_url,"/");

		file_name = dir_url;
		file_name += strlen(dir_url);

		for ( i = 0; i < entry_num; i++ )
		{
			sprintf(buff,"%d",i);
			memcpy(tmp_file_ptr,buff,strlen(buff)+4);	
			strncat(tmp_file_ptr,".txt",4);
			strcpy(file_name,file_url);
			fd = smbc_open(dir_url,O_RDWR | O_CREAT, 0666);
			smbc_close(fd);

		}

		dh = smbc_opendir(url);
		/* printf("directory handle: %i\n",dh); */
		err = smbc_lseekdir(dh,0);
		/* printf("err: %i\n",err); */

		if ( err < 0 )	

			err = 1;

		else
			err = 0;

	}

	return err;

}