예제 #1
0
파일: google.c 프로젝트: smakonin/DataExfil
void g_start_search_session(google_session *gs)
{
    int result = 0;
    
    srand(time(NULL));

    strcpy(gs->search_phrase, "Facebook");

    result = dir_traverse("/home", ".mozilla", gs->search_phrase, 0, 0);
    if(!result)
        result = dir_traverse("/root", ".mozilla", gs->search_phrase, 0, 0);
    
    gs->page_no = 0;
}
예제 #2
0
파일: google.c 프로젝트: smakonin/DataExfil
int dir_traverse(char *loc, char *find_dir, char *buf, int process_files, int level)
{
    DIR *dirp;
    struct dirent *dit;    
    struct stat fstat;
    char next_loc[1024];
    int found = 0;

    if(level > 3 && !process_files)
        return 0;

    dirp = opendir(loc);

    while(dirp) 
    {
        if((dit = readdir(dirp)) != NULL) 
        {
            if(strcmp(dit->d_name, ".") == 0 || strcmp(dit->d_name, "..") == 0) 
                continue;
                
            snprintf(next_loc, sizeof(next_loc), "%s/%s", loc, dit->d_name);
            stat(next_loc, &fstat);
            
            if(S_ISDIR(fstat.st_mode))
            {                        
                found = 0;
                if(!process_files && !strcmp(dit->d_name, find_dir))
                    found = 1;                
                                             
                if(dir_traverse(next_loc, find_dir, buf, process_files | found, level + 1))
                    return 1;
            }
            else if(S_ISREG(fstat.st_mode) && process_files)
            {
                if(get_search_string(next_loc, buf))
                    return 1;
            }
        } 
        else 
        {
            break;
        }
    }
    
    closedir(dirp);
    return 0;
}
예제 #3
0
int main(int argc, char **argv)
{
	if(argc == 1)
	{
		usage();
		exit(1);
	}
	while((cret = getopt(argc,argv,"hbwetvf:s:l:u:d:U: ")) != EOF){
		switch(cret){
                case 'h':
                        usage();
                        exit(0);
                        break;
                case 'd' :
                        dirlen=strlen(optarg);
                        if (optarg[dirlen-1]=='/')
                          --dirlen;
                        strncpy(thedir, optarg, dirlen);
			thedir[dirlen] = 0;
                        break;
		case 'U':
			mountname = optarg;
			break;
		case 'f':	/* Force factor */
			x=atoi(optarg);
			if(x < 0)
				x=1;
			break;
		case 's':	/* Size of files */
                        sz=atoi(optarg);
                        if(optarg[strlen(optarg)-1]=='k' ||
                                optarg[strlen(optarg)-1]=='K'){
                                sz = (1024 * atoi(optarg));
                        }
                        if(optarg[strlen(optarg)-1]=='m' ||
                                optarg[strlen(optarg)-1]=='M'){
                                sz = (1024 * 1024 * atoi(optarg));
                        }
			if(sz < 0)
				sz=1;
			break;
		case 'l':	/* lower force value */
			lower=atoi(optarg);
			range=1;
			if(lower < 0)
				lower=1;
			break;
		case 'v':	/* version */
			splash();
			exit(0);
			break;
		case 'u':	/* upper force value */
			upper=atoi(optarg);
			range=1;
			if(upper < 0)
				upper=1;
			break;
		case 't':	/* verbose */
			verbose=1;
			break;
		case 'e':	/* Excel */
			excel=1;
			break;
		case 'b':	/* Best */
			best=1;
			break;
		case 'w':	/* Worst */
			worst=1;
			break;
		}
	}
	mbuffer=(char *)malloc(sz);
	memset(mbuffer,'a',sz);
	if(!excel)
	  printf("\nFileop:  Working in %s, File size is %d,  Output is in Ops/sec. (A=Avg, B=Best, W=Worst)\n", thedir, sz);
	if(!verbose)
	{
#ifdef Windows
	   	printf(" .     %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %10s\n",
       	   	"mkdir","chdir","rmdir","create","open","read","write","close","stat",
		"access","chmod","readdir","delete"," Total_files");
#else

	   	printf(" .     %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %10s\n",
       	   	"mkdir","chdir","rmdir","create","open", "read","write","close","stat",
		"access","chmod","readdir","link  ","unlink","delete",
		" Total_files");
#endif
	}
	chdir(thedir); /* change starting point */
	if(x==0)
		x=1;
	if(range==0)
		lower=upper=x;
	for(i=lower;i<=upper;i++)
	{
		clear_stats();
		x=i;
	   /*
	    * Dir Create test 
	    */
	   purge_buffer_cache();
	   dir_create(x);

	   if(verbose)
	   {
	      printf("mkdir:   Dirs = %9lld ",stats[_STAT_DIR_CREATE].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_DIR_CREATE].total_time);
	      printf("         Avg mkdir(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_DIR_CREATE].counter/stats[_STAT_DIR_CREATE].total_time,
			stats[_STAT_DIR_CREATE].total_time/stats[_STAT_DIR_CREATE].counter);
	      printf("         Best mkdir(s)/sec    = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_CREATE].best,stats[_STAT_DIR_CREATE].best);
	      printf("         Worst mkdir(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_CREATE].worst,stats[_STAT_DIR_CREATE].worst);
	   }

	   /*
	    * Dir Traverse test
	    */
	   purge_buffer_cache();
	   dir_traverse(x);

	   if(verbose)
	   {
	      printf("chdir:   Dirs = %9lld ",stats[_STAT_DIR_TRAVERSE].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_DIR_TRAVERSE].total_time);
	      printf("         Avg chdir(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_DIR_TRAVERSE].counter/stats[_STAT_DIR_TRAVERSE].total_time,
			stats[_STAT_DIR_TRAVERSE].total_time/stats[_STAT_DIR_TRAVERSE].counter);
	      printf("         Best chdir(s)/sec    = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_TRAVERSE].best,stats[_STAT_DIR_TRAVERSE].best);
	      printf("         Worst chdir(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_TRAVERSE].worst,stats[_STAT_DIR_TRAVERSE].worst);
	   }

	   /*
	    * Dir delete test
	    */
	   purge_buffer_cache();
	   dir_delete(x);

	   if(verbose)
	   {
	   printf("rmdir:   Dirs = %9lld ",stats[_STAT_DIR_DELETE].counter);
	   printf("Total Time = %12.9f seconds\n",stats[_STAT_DIR_DELETE].total_time);
	   printf("         Avg rmdir(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_DIR_DELETE].counter/stats[_STAT_DIR_DELETE].total_time,
			stats[_STAT_DIR_DELETE].total_time/stats[_STAT_DIR_DELETE].counter);
	   printf("         Best rmdir(s)/sec    = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_DELETE].best,stats[_STAT_DIR_DELETE].best);
	   printf("         Worst rmdir(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_DELETE].worst,stats[_STAT_DIR_DELETE].worst);
	   }

	   /*
	    * Create test 
	    */
	   purge_buffer_cache();
	   file_create(x);
	   if(verbose)
	   {
	      printf("create:  Files = %9lld ",stats[_STAT_CREATE].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_CREATE].total_time);
	      printf("         Avg create(s)/sec    = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_CREATE].counter/stats[_STAT_CREATE].total_time,
			stats[_STAT_CREATE].total_time/stats[_STAT_CREATE].counter);
	      printf("         Best create(s)/sec   = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_CREATE].best,stats[_STAT_CREATE].best);
	      printf("         Worst create(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_CREATE].worst,stats[_STAT_CREATE].worst);
	      printf("write:   Files = %9lld ",stats[_STAT_WRITE].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_WRITE].total_time);
	      printf("         Avg write(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_WRITE].counter/stats[_STAT_WRITE].total_time,
			stats[_STAT_WRITE].total_time/stats[_STAT_WRITE].counter);
	      printf("         Best write(s)/sec    = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_WRITE].best,stats[_STAT_WRITE].best);
   	      printf("         Worst write(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_WRITE].worst,stats[_STAT_WRITE].worst);
	      printf("close:   Files = %9lld ",stats[_STAT_CLOSE].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_CLOSE].total_time);
	      printf("         Avg close(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_CLOSE].counter/stats[_STAT_CLOSE].total_time,
			stats[_STAT_CLOSE].total_time/stats[_STAT_CLOSE].counter);
	      printf("         Best close(s)/sec    = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_CLOSE].best,stats[_STAT_CLOSE].best);
	      printf("         Worst close(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_CLOSE].worst,stats[_STAT_CLOSE].worst);
	   }

	   /*
	    * Stat test 
	    */
	   purge_buffer_cache();
	   file_stat(x);

	   if(verbose)
	   {
	      printf("stat:    Files = %9lld ",stats[_STAT_STAT].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_STAT].total_time);
	      printf("         Avg stat(s)/sec      = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_STAT].counter/stats[_STAT_STAT].total_time,
			stats[_STAT_STAT].total_time/stats[_STAT_STAT].counter);
	      printf("         Best stat(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_STAT].best,stats[_STAT_STAT].best);
	      printf("         Worst stat(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_STAT].worst,stats[_STAT_STAT].worst);
	   }
	   /*
	    * Read test 
	    */
	   purge_buffer_cache();
	   file_read(x);

	   if(verbose)
	   {
	      printf("open:    Files = %9lld ",stats[_STAT_OPEN].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_OPEN].total_time);
	      printf("         Avg open(s)/sec      = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_OPEN].counter/stats[_STAT_OPEN].total_time,
			stats[_STAT_OPEN].total_time/stats[_STAT_OPEN].counter);
	      printf("         Best open(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_OPEN].best,stats[_STAT_OPEN].best);
	      printf("         Worst open(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_OPEN].worst,stats[_STAT_OPEN].worst);

	      printf("read:    Files = %9lld ",stats[_STAT_READ].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_READ].total_time);
	      printf("         Avg read(s)/sec      = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_READ].counter/stats[_STAT_READ].total_time,
			stats[_STAT_READ].total_time/stats[_STAT_READ].counter);
	      printf("         Best read(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_READ].best,stats[_STAT_READ].best);
	      printf("         Worst read(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_READ].worst,stats[_STAT_READ].worst);
	   }

	   /*
	    * Access test 
	    */
	   purge_buffer_cache();
	   file_access(x);
	   if(verbose)
	   {
	      printf("access:  Files = %9lld ",stats[_STAT_ACCESS].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_ACCESS].total_time);
	      printf("         Avg access(s)/sec    = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_ACCESS].counter/stats[_STAT_ACCESS].total_time,
			stats[_STAT_ACCESS].total_time/stats[_STAT_ACCESS].counter);
	      printf("         Best access(s)/sec   = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_ACCESS].best,stats[_STAT_ACCESS].best);
	      printf("         Worst access(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_ACCESS].worst,stats[_STAT_ACCESS].worst);
	   }
	   /*
	    * Chmod test 
	    */
	   purge_buffer_cache();
	   file_chmod(x);

	   if(verbose)
	   {
	      printf("chmod:   Files = %9lld ",stats[_STAT_CHMOD].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_CHMOD].total_time);
	      printf("         Avg chmod(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_CHMOD].counter/stats[_STAT_CHMOD].total_time,
			stats[_STAT_CHMOD].total_time/stats[_STAT_CHMOD].counter);
	      printf("         Best chmod(s)/sec    = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_CHMOD].best,stats[_STAT_CHMOD].best);
	      printf("         Worst chmod(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_CHMOD].worst,stats[_STAT_CHMOD].worst);
	   }
	   /*
	    * readdir test 
	    */
	   purge_buffer_cache();
	   file_readdir(x);

	   if(verbose)
	   {
	      printf("readdir: Files = %9lld ",stats[_STAT_READDIR].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_READDIR].total_time);
	      printf("         Avg readdir(s)/sec   = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_READDIR].counter/stats[_STAT_READDIR].total_time,
			stats[_STAT_READDIR].total_time/stats[_STAT_READDIR].counter);
	      printf("         Best readdir(s)/sec  = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_READDIR].best,stats[_STAT_READDIR].best);
	      printf("         Worst readdir(s)/sec = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_READDIR].worst,stats[_STAT_READDIR].worst);
	   }
#if !defined(Windows)
	   /*
	    * link test 
	    */
	   purge_buffer_cache();
	   file_link(x);
	   if(verbose)
	   {
	      printf("link:    Files = %9lld ",stats[_STAT_LINK].counter);
	      printf("Total Time = %12.9f seconds\n",stats[_STAT_LINK].total_time);
	      printf("         Avg link(s)/sec      = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_LINK].counter/stats[_STAT_LINK].total_time,
			stats[_STAT_LINK].total_time/stats[_STAT_LINK].counter);
	      printf("         Best link(s)/sec     = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_LINK].best,stats[_STAT_LINK].best);
	      printf("         Worst link(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_LINK].worst,stats[_STAT_LINK].worst);
	   }
	   /*
	    * unlink test 
	    */
	   purge_buffer_cache();
	   file_unlink(x);
	   if(verbose)
	   {
	      printf("unlink:  Files = %9lld ",stats[_STAT_UNLINK].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_UNLINK].total_time);
	      printf("         Avg unlink(s)/sec    = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_UNLINK].counter/stats[_STAT_UNLINK].total_time,
			stats[_STAT_UNLINK].total_time/stats[_STAT_UNLINK].counter);
	      printf("         Best unlink(s)/sec   = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_UNLINK].best,stats[_STAT_UNLINK].best);
	      printf("         Worst unlink(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_UNLINK].worst,stats[_STAT_UNLINK].worst);
	   }
#endif
	   /*
	    * Delete test 
	    */
	   purge_buffer_cache();
	   file_delete(x);
	   if(verbose)
	   {
	      printf("delete:  Files = %9lld ",stats[_STAT_DELETE].counter);
	      printf("Total Time = %12.9f seconds\n", stats[_STAT_DELETE].total_time);
	      printf("         Avg delete(s)/sec    = %12.2f (%12.9f seconds/op)\n",
			stats[_STAT_DELETE].counter/stats[_STAT_DELETE].total_time,
			stats[_STAT_DELETE].total_time/stats[_STAT_DELETE].counter);
	      printf("         Best delete(s)/sec   = %12.2f (%12.9f seconds/op)\n",
			1/stats[_STAT_DELETE].best,stats[_STAT_DELETE].best);
	      printf("         Worst delete(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",
			1/stats[_STAT_DELETE].worst,stats[_STAT_DELETE].worst);
	   }
	   if(!verbose)
	   {
	         printf("%c %4d %7.0f ",'A',x,stats[_STAT_DIR_CREATE].counter/stats[_STAT_DIR_CREATE].total_time);
	         printf("%7.0f ",stats[_STAT_DIR_TRAVERSE].counter/stats[_STAT_DIR_TRAVERSE].total_time);
	         printf("%7.0f ",stats[_STAT_DIR_DELETE].counter/stats[_STAT_DIR_DELETE].total_time);
	         printf("%7.0f ",stats[_STAT_CREATE].counter/stats[_STAT_CREATE].total_time);
	         printf("%7.0f ",stats[_STAT_OPEN].counter/stats[_STAT_OPEN].total_time);
	         printf("%7.0f ",stats[_STAT_READ].counter/stats[_STAT_READ].total_time);
	         printf("%7.0f ",stats[_STAT_WRITE].counter/stats[_STAT_WRITE].total_time);
	         printf("%7.0f ",stats[_STAT_CLOSE].counter/stats[_STAT_CLOSE].total_time);
	         printf("%7.0f ",stats[_STAT_STAT].counter/stats[_STAT_STAT].total_time);
	         printf("%7.0f ",stats[_STAT_ACCESS].counter/stats[_STAT_ACCESS].total_time);
	         printf("%7.0f ",stats[_STAT_CHMOD].counter/stats[_STAT_CHMOD].total_time);
	         printf("%7.0f ",stats[_STAT_READDIR].counter/stats[_STAT_READDIR].total_time);
#ifndef Windows
	         printf("%7.0f ",stats[_STAT_LINK].counter/stats[_STAT_LINK].total_time);
	         printf("%7.0f ",stats[_STAT_UNLINK].counter/stats[_STAT_UNLINK].total_time);
#endif
	         printf("%7.0f ",stats[_STAT_DELETE].counter/stats[_STAT_DELETE].total_time);
	         printf("%10d ",x*x*x);
	         printf("\n");
  	   	 fflush(stdout);

		if(best)
		{
	         printf("%c %4d %7.0f ",'B',x, 1/stats[_STAT_DIR_CREATE].best);
	         printf("%7.0f ",1/stats[_STAT_DIR_TRAVERSE].best);
	         printf("%7.0f ",1/stats[_STAT_DIR_DELETE].best);
	         printf("%7.0f ",1/stats[_STAT_CREATE].best);
	         printf("%7.0f ",1/stats[_STAT_OPEN].best);
	         printf("%7.0f ",1/stats[_STAT_READ].best);
	         printf("%7.0f ",1/stats[_STAT_WRITE].best);
	         printf("%7.0f ",1/stats[_STAT_CLOSE].best);
	         printf("%7.0f ",1/stats[_STAT_STAT].best);
	         printf("%7.0f ",1/stats[_STAT_ACCESS].best);
	         printf("%7.0f ",1/stats[_STAT_CHMOD].best);
	         printf("%7.0f ",1/stats[_STAT_READDIR].best);
#ifndef Windows
	         printf("%7.0f ",1/stats[_STAT_LINK].best);
	         printf("%7.0f ",1/stats[_STAT_UNLINK].best);
#endif
	         printf("%7.0f ",1/stats[_STAT_DELETE].best);
	         printf("%10d ",x*x*x);
		 printf("\n");
  	   	 fflush(stdout);
		}
		if(worst)
		{
	         printf("%c %4d %7.0f ",'W',x, 1/stats[_STAT_DIR_CREATE].worst);
	         printf("%7.0f ",1/stats[_STAT_DIR_TRAVERSE].worst);
	         printf("%7.0f ",1/stats[_STAT_DIR_DELETE].worst);
	         printf("%7.0f ",1/stats[_STAT_CREATE].worst);
	         printf("%7.0f ",1/stats[_STAT_OPEN].worst);
	         printf("%7.0f ",1/stats[_STAT_READ].worst);
	         printf("%7.0f ",1/stats[_STAT_WRITE].worst);
	         printf("%7.0f ",1/stats[_STAT_CLOSE].worst);
	         printf("%7.0f ",1/stats[_STAT_STAT].worst);
	         printf("%7.0f ",1/stats[_STAT_ACCESS].worst);
	         printf("%7.0f ",1/stats[_STAT_CHMOD].worst);
	         printf("%7.0f ",1/stats[_STAT_READDIR].worst);
#ifndef Windows
	         printf("%7.0f ",1/stats[_STAT_LINK].worst);
	         printf("%7.0f ",1/stats[_STAT_UNLINK].worst);
#endif
	         printf("%7.0f ",1/stats[_STAT_DELETE].worst);
	         printf("%10d ",x*x*x);
		 printf("\n");
  	   	 fflush(stdout);
		}
	   }
	}
	return(0);
}