示例#1
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_rmdir( url );

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

		err = errno;	


	}

	return err;

}
示例#2
0
文件: file.c 项目: smiley22/myPS2
int FileMkdir( const char *path )
{
	char *ptr;
	int c;

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

	c = ptr - path;

	if( !strncmp( path, "pfs", 3 ) ) {
		return fileXioMkdir( path, O_RDWR | O_CREAT );
	}
	else if( !strncmp( path, "mc0:", c ) || !strncmp( path, "mc1:", c ) ) {
		return fioMkdir( path );
	}
	else if( !strncmp( path, "mass:", c ) ) {
		return fioMkdir( path );
	}
	else if( !strncmp( path, "smb:", c ) ) {
		return smbc_mkdir( path, 0666 );
	}

	return -1;
}
示例#3
0
int FSSmb::MkDir( FSPath& path, int mode, int* err,  FSCInfo* info )
{
	FREPARE_SMB_OPER( lock, info, &_param );

	int n = smbc_mkdir( pathBuffer1.SetPath( path ), mode );
	SetError( err, errno );
	return n < 0 ? -1 : n;
}
示例#4
0
/* mkdir (folder) */
int SMB_mkdir(char *localpath, int index)
{
        if(access(localpath, F_OK) != 0)
        {
                printf("Local has no %s\n", localpath);
                return LOCAL_FILE_LOST;
        }

        SMB_init(index);

        char *serverpath = localpath_to_serverpath(localpath, index);
        int res = smbc_mkdir(serverpath, DIR_MODE);
        free(serverpath);
        return res;
}
示例#5
0
//===========================================================================
void SMBSlave::mkdir( const QUrl &kurl, int permissions )
{
    qCDebug(KIO_SMB) << kurl;
    int errNum = 0;
    int retVal = 0;
    m_current_url = kurl;

    retVal = smbc_mkdir(m_current_url.toSmbcUrl(), 0777);
    if( retVal < 0 ){
        errNum = errno;
    } else {
        errNum = 0;
    }

    if( retVal < 0 )
    {
        if (errNum == EEXIST) {
            errNum = cache_stat(m_current_url, &st );
            if (errNum == 0 && S_ISDIR(st.st_mode))
            {
                error( KIO::ERR_DIR_ALREADY_EXIST, m_current_url.toDisplayString());
            }
            else
            {
                error( KIO::ERR_FILE_ALREADY_EXIST, m_current_url.toDisplayString());
            }
        }
        else
        {
            reportError(kurl, errNum);
        }
        qCDebug(KIO_SMB) << "exit with error " << kurl;
    }
    else // success
    {
        if(permissions != -1)
        {
            // TODO enable the following when complete
            //smbc_chmod( url.toSmbcUrl(), permissions );
        }
        finished();
    }
}
示例#6
0
/* mkdir (folder) */
int SMB_mkdir(char *localpath, int index)
{
    DEBUG("SMB_mkdir start\n");
        if(access(localpath, F_OK) != 0)
        {
                printf("Local has no %s\n", localpath);
                return LOCAL_FILE_LOST;
        }

        SMB_init(index);

        char *serverpath = localpath_to_serverpath(localpath, index);
        DEBUG("SMB_mkdir --serverpath=%s\n",serverpath);
        int res = smbc_mkdir(serverpath, DIR_MODE);
        DEBUG("SMB_mkdir --res=%d\n",res);
        free(serverpath);
        DEBUG("SMB_mkdir end\n");
        return res;
}
示例#7
0
uint32_t smbc_wrapper_mkdir(connection* con, const char *fname, mode_t mode)
{
	if(con->mode== SMB_BASIC)
		return smbc_mkdir(fname, mode);
	else if(con->mode == SMB_NTLM){
		smb_file_t *fp;
		
		if((fp = smbc_cli_ntcreate(con->smb_info->cli, fname,
						FILE_READ_DATA | FILE_WRITE_DATA, FILE_CREATE, FILE_DIRECTORY_FILE)) == NULL)
		{
			return -1;
		}
		else{
			smbc_cli_close(con->smb_info->cli, fp);
		}
	}
	
	return 0;
}
示例#8
0
文件: rename_8.c 项目: gojdic/samba
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;

}
示例#9
0
bool CreateDirectory(VFSURL* url)
{
  bool success = true;
  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_mkdir(strFileName.c_str(), 0);
  success = (result == 0 || EEXIST == errno);
  if(!success)
    XBMC->Log(ADDON::LOG_ERROR, "%s - Error( %s )", __FUNCTION__, strerror(errno));

  return success;
}
示例#10
0
文件: main.cpp 项目: aont/smbcfs
static int smbcfs_mkdir(const char* const path, const mode_t mode)
{

  const std::string smbcfs_path = smbcfs_root_path + path;

#ifdef MUTEX_LOCK
  pthread_mutex_lock(&mutex_lock);  
#endif

  const int ret_mkdir = smbc_mkdir(smbcfs_path.c_str(), mode);

#ifdef MUTEX_LOCK
  pthread_mutex_unlock(&mutex_lock);  
#endif

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



  return ret_mkdir;
}
示例#11
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;

}
示例#12
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;

}
示例#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;
}
示例#14
0
文件: telldir_5.c 项目: sprymak/samba
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;

}
示例#15
0
static int _mkdir(const char *uri, mode_t mode) {
  return smbc_mkdir(uri, mode);
}
示例#16
0
static void generate_files()
{
        /* on playback, load the number of files */
        if (config.replay!=NULL) {
                fscanf(config.player,"number of files: %i\n",&config.number);
	}
	int list[config.number];
	int i,z;
	int fd, fd2;
	int bytecount;
	int debug=0;
	char buffer[40000];
	srand(time(NULL) + getpid());
	for(i=0;i<config.number;i++)
	{
		list[i]=(rand() % (config.size-(config.number-i)));
		config.size=config.size-list[i];
	}
	list[config.number-1]=config.size;

	/* when recording, store the list of files and sizes */
        if (config.record!=NULL) {
                /* when recording, store the time to wait here          */
                fprintf(config.recorder,"number of files: %i\n",config.number);
		for (z=0;z<config.number;z++) {
			fprintf(config.recorder,"file size: %i\n",list[z]);
		}
        }
	/* on playback, load the list of files and sizes */
        if (config.replay!=NULL) {
		for (z=0;z<config.number;z++) {
			fscanf(config.player,"file size: %i\n",&list[z]);
		}
        }


	if (config.verbose == 1)
	{
		printf("Stage 1: creating now the files on both shares\n");
	}

	for (i=0;i<config.number;i++) {
		char *t = NULL;
		if (config.replay == NULL) t = get_random_filename();
                if (config.replay != NULL) {
                        fscanf(config.player,"Filename: %ms\n",&t);
                        }

		char *Dateiname1 = (char *) malloc(sizeof(char) * (strlen(config.share1)+strlen(t)+5));
		char *Dateiname2 = (char *) malloc(sizeof(char) * (strlen(config.share2)+strlen(t)+5));
		/* when recording, write the list of filenames + paths */
		if (config.record!=NULL) {
			fprintf(config.recorder,"Filename: %s\n", t);
			}
                strcpy(Dateiname1,config.share1);
                strcpy(Dateiname2,config.share2);
                strcat(Dateiname1,t);
                strcat(Dateiname2,t);
		fnamelist[i]=t;
		// create directories
                smbc_init(get_auth_data_fn, debug);
		int z= 0;
		char *sname = (char *) malloc(sizeof(char) * (strlen(config.share1)+strlen(t)+5 + strlen(config.share2)));
		while (z<strlen(t)) {
			if (t[z]=='/') {
				t[z]='\0';
				strcpy(sname,config.share1);
				strcat(sname,t);
				printf("Creating Directory: %s\n",sname);
				smbc_mkdir(sname,0777);
				strcpy(sname,config.share2);
				strcat(sname,t);
				printf("Creating Directory: %s\n",sname);
				smbc_mkdir(sname,0777);
				t[z]='/';
				
			}
			z++;
		}
		free(sname);
	
		if ((fd = smbc_open(Dateiname1,
			O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
			{
			perror("smbc_open: writing failed");
			}

		bytecount=list[i];
		while (bytecount>40000) {
			smbc_write( fd,buffer,40000);
			bytecount=bytecount-40000;
		}

		if (bytecount<40000) {
			smbc_write(fd,buffer,bytecount);
			bytecount=0;
		}

		smbc_close(fd);

		if ((fd2 = smbc_open(Dateiname2, 
			O_WRONLY | O_CREAT | O_TRUNC, 0) < 0))

			{
			perror("smbc_open: failed");
			exit(1);
			}

		bytecount=list[i];
		while (bytecount>40000) {
			smbc_write(fd, buffer, 40000);
			bytecount=bytecount-40000;
		}

		if (bytecount<40000) {
			smbc_write(fd, buffer, bytecount),
			bytecount=0;
		}

		if(config.verbose==1)
		{
			printf("File %s written with %u Bytes\n", Dateiname1, list[i]);
		}

		if(i==config.number-1)
		{
			printf("All files successfully written."
				" Now it's torture time!\n");
		}

		smbc_close(fd2);
		free(Dateiname1);
		free(Dateiname2);
	}

}
示例#17
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;

}