Beispiel #1
0
static int
compare_names_for_qsort (void const *file1, void const *file2)
{
  char const *const *f1 = file1;
  char const *const *f2 = file2;
  return compare_names (*f1, *f2);
}
Beispiel #2
0
int32
DirEntryBlock::FindInsertionIndex(const char* name, size_t nameLength,
	bool& _exactMatch) const
{
	int32 entryCount = EntryCount();
	if (entryCount == 0) {
		_exactMatch = false;
		return 0;
	}

	const char* entryNames = (char*)(fBlock->nameEnds + entryCount);
	uint32 nameOffset = 0;

	int32 index = 0;
	int cmp = -1;

	// TODO: Binary search!
	for (; index < entryCount; index++) {
		const char* entryName = entryNames + nameOffset;
		size_t entryNameLength = fBlock->nameEnds[index] - nameOffset;

		cmp = compare_names(entryName, entryNameLength, name, nameLength);
		if (cmp >= 0)
			break;

		nameOffset += entryNameLength;
	}

	_exactMatch = cmp == 0;
	return index;
}
Beispiel #3
0
/*
 * Choose the name of the file to be patched based the "best" one
 * available.
 */
static char *
best_name(const struct file_name *names, bool assume_exists)
{
	char *best;

	best = compare_names(names, assume_exists, 1);
	if (best == NULL) {
		best = compare_names(names, assume_exists, 2);
		/*
		 * Still no match?  Check to see if the diff could be creating
		 * a new file.
		 */
		if (best == NULL && ok_to_create_file &&
		    names[NEW_FILE].path != NULL)
			best = names[NEW_FILE].path;
	}

	return best ? savestr(best) : NULL;
}
Beispiel #4
0
void Character::add_character(const Character *to_insert)
{
    if(compare_names(to_insert))
    {
        insert(left, to_insert);
    }
    else 
    {
        insert(right, to_insert);
    }
}
static TSK_WALK_RET_ENUM
dir_walk_comp_cb(TSK_FS_FILE * a_fs_file, const char *a_path, void *a_ptr)
{
    const TSK_FS_FILE *fs_file2 = (const TSK_FS_FILE *) a_ptr;

    if (compare_names(a_fs_file->name, fs_file2->name, 0) == 0) {
        s_found = 1;
        return TSK_WALK_STOP;
    }

    return TSK_WALK_CONT;
}
Beispiel #6
0
char *
find_dir_file_pathname (char const *dir, char const *file)
{
  /* The 'IF_LINT (volatile)' works around what appears to be a bug in
     gcc 4.8.0 20120825; see
     <http://lists.gnu.org/archive/html/bug-diffutils/2012-08/msg00007.html>.
     */
  char const * IF_LINT (volatile) match = file;

  char *val;
  struct dirdata dirdata;
  dirdata.names = NULL;
  dirdata.data = NULL;

  if (ignore_file_name_case)
    {
      struct file_data filedata;
      filedata.name = dir;
      filedata.desc = 0;

      if (dir_read (&filedata, &dirdata))
	{
	  locale_specific_sorting = true;
	  if (setjmp (failed_locale_specific_sorting))
	    match = file; /* longjmp may mess up MATCH.  */
	  else
	    {
	      for (char const **p = dirdata.names; *p; p++)
		if (compare_names (*p, file) == 0)
		  {
		    if (file_name_cmp (*p, file) == 0)
		      {
			match = *p;
			break;
		      }
		    if (match == file)
		      match = *p;
		  }
	    }
	}
    }

  val = file_name_concat (dir, match, NULL);
  free (dirdata.names);
  free (dirdata.data);
  return val;
}
Beispiel #7
0
/*
 * Check if we want to use the PANTONE color processing logic for the given
 * Separation color space.
 */
static bool
client_pantone_install_Separation(client_custom_color_params_t * pparam,
			gs_color_space * pcs, gs_state * pgs)
{
    const gs_separation_name name = pcs->params.separation.sep_name;
    int pan_index;
    byte * pname;
    uint name_size;
    gx_device * dev = pgs->device;
    int num_pantone_colors = count_of(pantone_list);
    bool use_custom_color_callback = false;

    /* Exit if we have already installed this color space. */
    if (pcs->pclient_color_space_data != NULL)
		return true;

    /*
     * Get the character string and length for the component name.
     */
    pcs->params.separation.get_colorname_string(dev->memory, name,
						&pname, &name_size);
    /*
    * Compare the colorant name to those in our PANTONE color list.
    */
    for (pan_index = 0; pan_index < num_pantone_colors ; pan_index++) {
	const char * pan_name = pantone_list[pan_index].name;

	if (compare_names(pname, name_size, pan_name, strlen(pan_name))) {
	    use_custom_color_callback = true;
	    break;
	}
    }

    if (use_custom_color_callback) {
        demo_color_space_data_t * pclient_data =
		allocate_client_data_block(1, pcs->rc.memory->stable_memory);

	if (pclient_data == NULL)
		return false;
	pclient_data->color_index[0] = pan_index;
        pcs->pclient_color_space_data =
	       (client_color_space_data_t *) pclient_data;
    }
    return use_custom_color_callback;
}
Beispiel #8
0
OM_uint32
gssint_userok(OM_uint32 *minor,
	    const gss_name_t name,
	    const char *user,
	    int *user_ok)

{
	gss_mechanism mech;
	gss_union_name_t intName;
	gss_name_t mechName = NULL;
	OM_uint32 major;

	if (minor == NULL || user_ok == NULL)
		return (GSS_S_CALL_INACCESSIBLE_WRITE);

	if (name == NULL || user == NULL)
		return (GSS_S_CALL_INACCESSIBLE_READ);

	*user_ok = 0;
	*minor = GSS_S_COMPLETE;

	intName = (gss_union_name_t)name;

	mech = gssint_get_mechanism(intName->mech_type);
	if (mech == NULL)
		return (GSS_S_UNAVAILABLE);

	/* may need to import the name if this is not MN */
	if (intName->mech_type == NULL) {
		return (GSS_S_FAILURE);
	} else
		mechName = intName->mech_name;

	if (mech->gssint_userok) {
		major = mech->gssint_userok(minor, mechName,
				user, user_ok);
		if (major != GSS_S_COMPLETE)
		    map_error(minor_status, mech);
	} else
		major = compare_names(minor, intName->mech_type,
				    name, user, user_ok);

	return (major);
} /* gss_userok */
Beispiel #9
0
int
diff_dirs (struct comparison const *cmp,
	   int (*handle_file) (struct comparison const *,
			       char const *, char const *))
{
  struct dirdata dirdata[2];
  int volatile val = EXIT_SUCCESS;
  int i;

  if ((cmp->file[0].desc == -1 || dir_loop (cmp, 0))
      && (cmp->file[1].desc == -1 || dir_loop (cmp, 1)))
    {
      error (0, 0, _("%s: recursive directory loop"),
	     cmp->file[cmp->file[0].desc == -1].name);
      return EXIT_TROUBLE;
    }

  /* Get contents of both dirs.  */
  for (i = 0; i < 2; i++)
    if (! dir_read (&cmp->file[i], &dirdata[i]))
      {
	perror_with_name (cmp->file[i].name);
	val = EXIT_TROUBLE;
      }

  if (val == EXIT_SUCCESS)
    {
      char const **volatile names[2];
      names[0] = dirdata[0].names;
      names[1] = dirdata[1].names;

      /* Use locale-specific sorting if possible, else native byte order.  */
      locale_specific_sorting = true;
      if (setjmp (failed_locale_specific_sorting))
	locale_specific_sorting = false;

      /* Sort the directories.  */
      for (i = 0; i < 2; i++)
	qsort (names[i], dirdata[i].nnames, sizeof *dirdata[i].names,
	       compare_names_for_qsort);

      /* If `-S name' was given, and this is the topmost level of comparison,
	 ignore all file names less than the specified starting name.  */

      if (starting_file && ! cmp->parent)
	{
	  while (*names[0] && compare_names (*names[0], starting_file) < 0)
	    names[0]++;
	  while (*names[1] && compare_names (*names[1], starting_file) < 0)
	    names[1]++;
	}

      /* Loop while files remain in one or both dirs.  */
      while (*names[0] || *names[1])
	{
	  /* Compare next name in dir 0 with next name in dir 1.
	     At the end of a dir,
	     pretend the "next name" in that dir is very large.  */
	  int nameorder = (!*names[0] ? 1 : !*names[1] ? -1
			   : compare_names (*names[0], *names[1]));
	  int v1 = (*handle_file) (cmp,
				   0 < nameorder ? 0 : *names[0]++,
				   nameorder < 0 ? 0 : *names[1]++);
	  if (val < v1)
	    val = v1;
	}
    }

  for (i = 0; i < 2; i++)
    {
      free (dirdata[i].names);
      free (dirdata[i].data);
    }

  return val;
}
Beispiel #10
0
int main(int argc, char **argv)
  {
    /* System variables */
    int option; /* Command line option character */
    int physical_flag; /* Option to use a physical device */
    int lax; /* Option to relax file name checking */
    int lif_device; /* Descriptor of input device */
    char cmp_name[10]; /* File name to look for */
    int i;
    
    /* LIF disk values */
    unsigned int dir_start; /* first block of the directory */
    unsigned int dir_length; /* length of directory in blocks */

    /* Directory search values */
    unsigned int dir_end; /* Set at end of directory */
    unsigned int found_file; /* Set when file found */
    unsigned int dir_entry; /* Directory entry within current block */
    unsigned int dir_block; /* Current block offset from start of directory */
    unsigned int abs_entry; /* entry number of file in directory */
    unsigned int file_type; /* file type word */
    unsigned char dir_data[SECTOR_SIZE]; /* Current directory block data */

    /* File values */
    int file_start; /* Starting block number of the file to purge */
    int file_len; /* Length of file in bytes */
    unsigned char filedata[SECTOR_SIZE];

    for(i=0;i<SECTOR_SIZE;i++) filedata[i]=0xFF;

    /* Process command line options */
    physical_flag=0;
    lax=0;

    optind=1;
    while ((option=getopt(argc,argv,"pl?"))!=-1)
      {
        switch(option)
          {
            case 'p' : physical_flag=1;
                       break;
            case 'l' : lax=1;
                       break;
            case '?' : usage();
                       break;
          }
      }

    /* Are the right number of names specified ? */
    if( optind != argc-2  )
      {
        /* No, give an error */
        usage();
      }

    /* Check file name */
    if(check_filename(argv[optind+1],lax)==0) 
      {
        fprintf(stderr,"Illegal file name\n");
        exit(1);
      }


    /* Open lif device */
    if((lif_device=lif_open(argv[optind],O_RDWR | O_BINARY,0,physical_flag))==-1)
      {
        fprintf(stderr,"Error opening %s\n",argv[optind]);
        exit(1);
      }


    /* Now read block 0 to find where the directory is */
    lif_read_block(lif_device,0,dir_data);

    /* Make sure it's a LIF disk */
    if(get_lif_int(dir_data+0,2)!=0x8000)
      {
        fprintf(stderr,"This is not a LIF disk!\n");
        exit(1);
      }

    /* Find the directory */
    dir_start=get_lif_int(dir_data+8,4);
    dir_length=get_lif_int(dir_data+16,4);

    /* Pad the filename with spaces to enable comparison */
    pad_name(argv[optind+1],cmp_name);

    /* Scan the directory */
    dir_end=0;
    found_file=0;
    abs_entry=-1;
    for(dir_block=0; dir_block<dir_length; dir_block++)
      {
        lif_read_block(lif_device,dir_block+dir_start,dir_data);
        for(dir_entry=0; dir_entry<8; dir_entry++)
          {
            file_type=get_lif_int(dir_data+(dir_entry<<5)+10,2);
            abs_entry++;
            if(file_type==0) { continue; } /* Skip deleted files */ 
            if(file_type==0xFFFF)
              {
                /* End of directory */
                dir_end=1;
                break;
              }
            if(compare_names((char *)dir_data+(dir_entry<<5),cmp_name))
              {
                /* Found the file */
                found_file=1;
                break;
              }
          }
        if(dir_end || found_file) { break; }; /* Quit at end or if file found */
      }

    if(!found_file)
      {
        /* Give file not found error */
        fprintf(stderr,"File %s not found\n",argv[optind+1]);
        exit(2);
      }


    /* Find the file start and length */
    file_start=get_lif_int(dir_data+(dir_entry<<5)+12,4);
    file_len=get_lif_int(dir_data+(dir_entry<<5)+16,4);
    debug_print("file_start %d\n",file_start);
    debug_print("file_len %d\n",file_len);
    debug_print("abs_entry %d\n",abs_entry);
    debug_print("dir_block %d\n",dir_block);
    debug_print("dir_start %d\n",dir_start);

    /* Actually zero the file */ 
    for(i=0; i< file_len; i++) lif_write_block(lif_device,file_start+i, filedata);

    /* Actually delete the directory entry */
   dir_data[(dir_entry<<5)+10]=0x0;
   dir_data[(dir_entry<<5)+11]=0x0;
   lif_write_dir_entry(lif_device,dir_start,abs_entry, dir_data+(dir_entry<<5));

    /* tidy up and quit */
    lif_close(lif_device);
    exit(0);      
  }
Beispiel #11
0
int main(int argc, char **argv)
  {
    /* System variables */
    int option; /* Command line option character */
    int output_device; /* Descriptor of output device */
    FILE *input_file; /* Input file stream */
    unsigned char cmp_name[NAME_LEN]; /* File name to look for */
    unsigned char chk_name[NAME_LEN+1]; /* File from input file to check */
    int data_length; /* length of input file in bytes without header */
    int num_blocks; /* size of input file in blocks */
    int physical_flag; /* Option to use a physical device */
    int lax; /* option to relax file name checking */
    struct blocktype {
       int startblock;
       int filelength;
    }  *blocklist, tempentry; /* list of blocks */
    int dir_entry_count; /* number of directory enries (including deleted) */
    int blocklist_count; /* number of entries in block list */
    int last_data_block; /* last data block in medium */
    int free_space; /* size of contiguous free blocks */
    int extend_dir;  /* flag if end of dir marker has to be moved */
    int fbytes;  /* file length of current directory entry */
    int fblocks; /* file length in blocks of current directory entry */
    int fstart;  /* start block of file of current directory entry */
    int i,j,n,t;

    
    /* LIF disk values */
    unsigned int dir_start; /* first block of the directory */
    unsigned int dir_length; /* length of directory in blocks */
    unsigned int medium_size; /* number of data blocks of medium */
    unsigned int tracks, surfaces, blocks;

    /* Directory search values */
    unsigned int dir_end; /* Set at end of directory */
    unsigned int found_file; /* Set when file found */
    unsigned int dir_entry; /* Directory entry within current block */
    unsigned int dir_block; /* Current block offset from start of directory */
    unsigned int file_type; /* file type word */
    unsigned char dir_data[SECTOR_SIZE]; /* Current directory block data */

    /* new file entry values */
    int free_dir_entry; /* number of the new directory entry */
    int file_start; /* Start block number of the new file */
    unsigned char new_dir_entry[ENTRY_SIZE]; /* Directory Entry of new file */
    char typestring[10];

    /* Process command line options */
    physical_flag=0;
    lax=0;
    optind=1;
    while ((option=getopt(argc,argv,"pl?"))!=-1)
      {
        switch(option)
          {
            case 'p' : physical_flag=1;
                       break;

            case 'l' : lax=1;
                       break;

            case '?' : usage();
                       break;
          }
      }

    /* Are the right number of names specified ? */
    if( (optind != argc-1) && (optind != argc-2) )
      {
        /* No, give an error */
        usage();
      }

    /* Open output device */
    if((output_device=lif_open(argv[optind],O_RDWR| O_BINARY,0,physical_flag))==-1)
      {
        fprintf(stderr,"Error opening %s\n",argv[optind]);
        exit(1);
      }

    /* Now read block 0 to find where the directory is */
    lif_read_block(output_device,0,dir_data);

    /* Make sure it's a LIF disk */
    if(get_lif_int(dir_data+0,2)!=0x8000)
      {
        fprintf(stderr,"This is not a LIF disk!\n");
        exit(1);
      }

    /* Find the directory */
    dir_start=get_lif_int(dir_data+8,4);
    dir_length=get_lif_int(dir_data+16,4);

   /* get medium information */
   tracks=get_lif_int(dir_data+24,4);
   surfaces=get_lif_int(dir_data+28,4);
   blocks=get_lif_int(dir_data+32,4);
   medium_size= tracks*surfaces*blocks;
   if((tracks == surfaces) && (surfaces == blocks)) {
      fprintf(stderr,"Medium was not initialized properly\n");
      exit(1);
    }

    debug_print("%s\n","medium Information");
    debug_print("medium size %d\n",medium_size);
    debug_print("dir_start %d dir_length %d\n\n",dir_start,dir_length);

    /* open input file, if none specified use standard input */
    if ( optind == argc -2) {
       input_file= fopen(argv[optind+1],"rb");
       if (input_file == (FILE *) NULL ) {
          fprintf(stderr,"can't open File %s\n",argv[optind+1]);
          exit(2);
       }
    }
    else {
       SETMODE_STDIN_BINARY;
       input_file= stdin;
    }

    /* read lif entry from input file header */
    fread(new_dir_entry,sizeof(unsigned char),ENTRY_SIZE,input_file);
    data_length= file_length(new_dir_entry,typestring);
    num_blocks= filelength_in_blocks(data_length);
    file_type= get_lif_int(&new_dir_entry[10],2);

    /* check file type */
    if(typestring[0]== '?') {
          fprintf(stderr,"illegal file type\n");
          exit(2);
    }

    /* set address to zero */
    new_dir_entry[12]=0;
    new_dir_entry[13]=0;
    new_dir_entry[14]=0;
    new_dir_entry[15]=0;

    /* get file name */
    for (i=0; i<NAME_LEN; i++) 
       cmp_name[i]= new_dir_entry[i];

    /* check the file name */
    for (i=0; i<NAME_LEN; i++) 
       if (new_dir_entry[i]==' ') 
          chk_name[i]= '\0';
       else
          chk_name[i]= new_dir_entry[i];
    chk_name[NAME_LEN]='\0';
    debug_print("File name to check: %s\n",chk_name);
    if (check_filename(chk_name,lax)==0) {
          fprintf(stderr,"illegal file name\n");
          exit(2);
    }
     
    debug_print("%s","input file: ");
    for (i=0; i<NAME_LEN; i++) debug_print("%c",cmp_name[i]);
    debug_print("%s","\n");

    debug_print("file type %x\n",file_type);
    debug_print("data_length %d\n",data_length);
    debug_print("num_blocks %d\n\n",num_blocks);
    

    /* Scan the directory, look for free diretory entries and
       build block list */
    dir_end=0;
    found_file=0;
    free_dir_entry=-1;
    dir_entry_count=0;
    blocklist_count=0;
    blocklist= malloc(8*dir_length*sizeof(struct blocktype));
    extend_dir= FALSE;
    debug_print("%s\n","directory scan");
    for(dir_block=0; dir_block<dir_length; dir_block++)
      {
        lif_read_block(output_device,dir_block+dir_start,dir_data);
        for(dir_entry=0; dir_entry<8; dir_entry++)
          {
            debug_print("dir entry no: %d\n",dir_entry_count);
            file_type=get_lif_int(dir_data+(dir_entry<<5)+10,2);

            /* Deleted file */
            if(file_type==0) {
               if(free_dir_entry== -1) free_dir_entry= dir_entry_count;
               debug_print("%s\n","deleted file");
            }
            else if(file_type==0xFFFF) {
               /* End of directory */
               debug_print("%s\n\n","end of dir mark");
               dir_end=1;
               if(free_dir_entry== -1) {
                  free_dir_entry= dir_entry_count;
                  /* do not move end of dir mark if we are in the last entry */
                  if(! (dir_entry_count == ((dir_length*8)-1)))
                     extend_dir= TRUE;
               }
               break;
            }
            else {
               fbytes=file_length(dir_data+(dir_entry<<5),NULL) ;
               fstart=get_lif_int(dir_data+(dir_entry<<5)+12,4);
               fblocks= filelength_in_blocks(fbytes);
               debug_print("Entry file type %04x startblock %d filelength %d (%d)\n",file_type, fstart,fbytes,fblocks);
               blocklist[blocklist_count].startblock= fstart;
               blocklist[blocklist_count].filelength= fblocks;
               blocklist_count++;

               if(compare_names((char *) dir_data+(dir_entry<<5),cmp_name)) {
                   /* Found the file */
                   found_file=1;
                   break;
                }
            }
            dir_entry_count+=1;
          }
        if(dir_end) { break; }; /* Quit at end */
      }

    if(found_file)
      {
        /* Give duplicate file error */
        fprintf(stderr,"Duplicate filename: ");
        for (i=0; i<NAME_LEN; i++) fprintf(stderr,"%c",cmp_name[i]);
        fprintf(stderr,"\n");
        free(blocklist);
        exit(2);
      }

    /* insert pseudo file entry as end of file */
    blocklist[blocklist_count].startblock= medium_size+1;
    blocklist[blocklist_count].filelength=0;
    blocklist_count++;

    /* no free directory entry ? */
    if (free_dir_entry == -1) {
      fprintf(stderr,"Directory full\n");
      free(blocklist);
      exit(2);
    }


    /* sort blocklist */
    j=1; t=1;
    n= blocklist_count;
    while (n-- && t) {
       for (j=t = 0; j < n; j++) {
          if (blocklist[j].startblock <= blocklist[j+1].startblock) continue;
          tempentry= blocklist [j];
          blocklist[j]= blocklist[j+1];
          blocklist[j+1]=tempentry;
          t=1;
       }
    } 
    debug_print("%s","sorted blocklist\n");
    for (i=0; i< blocklist_count; i++) 
        debug_print("start %d length %d\n",blocklist[i].startblock, blocklist[i].filelength);
    debug_print("%s\n","");

    /* find fist contigous block, which is large enough */
    file_start=-1;
    last_data_block=dir_start+dir_length;
    for (i=0; i< blocklist_count; i++) {
       free_space= blocklist[i].startblock - last_data_block;
       debug_print("free space %d at %d\n",free_space,last_data_block);
       if (num_blocks <= free_space) {
          file_start= last_data_block;
          break;
       }
       last_data_block= blocklist[i].startblock + blocklist[i].filelength;
    }
    if ( file_start == -1 ) {
       fprintf(stderr,"No room\n");
       free(blocklist);
       exit(2);
    }

    debug_print("%s\n","New file");
    debug_print("dir entry at: %d\n",free_dir_entry);
    debug_print("file starts at block %d\n",file_start);
    debug_print("free space %d (blocks)\n", free_space);
    debug_print("move end of dir mark %d\n\n",extend_dir);

    /* Modify start of file in new directory entry */
    put_lif_int(new_dir_entry+12,4,file_start);

    /* Actually copy the file */ 
    debug_print("%s\n","copy file");
    file_copy(output_device,input_file,file_start,data_length);

    /* write directory record */
    debug_print("%s\n","write directory");
    lif_write_dir_entry(output_device,dir_start,free_dir_entry,new_dir_entry);
    if(extend_dir) {
       debug_print("%s\n","write end of directory mark");
       for(i=0;i<ENTRY_SIZE;i++) new_dir_entry[i]=0;
       new_dir_entry[10]= (unsigned char) 0xFF;
       new_dir_entry[11]= (unsigned char) 0xFF;
       lif_write_dir_entry(output_device,dir_start,free_dir_entry+1,new_dir_entry);
    }

    /* tidy up and quit */
    free(blocklist);
    fclose(input_file);
    lif_close(output_device);
    debug_print("%s\n","finished");
    exit(0);      
  }
Beispiel #12
0
/*
 * Check if we want to use the PANTONE color processing logic for the given
 * DeviceN color space.
 */
static bool
client_pantone_install_DeviceN(client_custom_color_params_t * pparam,
			gs_color_space * pcs, gs_state * pgs)
{
    const gs_separation_name *names = pcs->params.device_n.names;
    int num_comp = pcs->params.device_n.num_components;
    int i;
    int pan_index;
    byte * pname;
    uint name_size;
    gx_device * dev = pgs->device;
    int num_pantone_colors = count_of(pantone_list);
    bool pantone_found = false;
    bool other_separation_found = false;
    bool use_pantone;
    const char none_str[] = "None";
    const uint none_size = strlen(none_str);
    const char cyan_str[] = "Cyan";
    const uint cyan_size = strlen(cyan_str);
    const char magenta_str[] = "Magenta";
    const uint magenta_size = strlen(magenta_str);
    const char yellow_str[] = "Yellow";
    const uint yellow_size = strlen(yellow_str);
    const char black_str[] = "Black";
    const uint black_size = strlen(black_str);
    int pantone_color_index[GS_CLIENT_COLOR_MAX_COMPONENTS];

    /* Exit if we have already installed this color space. */
    if (pcs->pclient_color_space_data != NULL)
		return true;

    /*
     * Now check the names of the color components.
     */
    for(i = 0; i < num_comp; i++ ) {
	bool match = false;

	/*
	 * Get the character string and length for the component name.
	 */
	pcs->params.device_n.get_colorname_string(dev->memory, names[i],
							&pname, &name_size);
	/*
         * Postscript does not include /None as a color component but it is
         * allowed in PDF so we accept it.  We simply skip components named
	 * 'None'.
         */
	if (compare_names(none_str, none_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_NONE;
	    continue;
	}
	/*
	 * Check if our color space includes the CMYK process colors.
	 */
	if (compare_names(cyan_str, cyan_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_CYAN;
	    continue;
	}
	if (compare_names(magenta_str, magenta_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_MAGENTA;
	    continue;
	}
	if (compare_names(yellow_str, yellow_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_YELLOW;
	    continue;
	}
	if (compare_names(black_str, black_size, pname, name_size)) {
	    pantone_color_index[i] = PANTONE_BLACK;
	    continue;
	}
	/*
	 * Compare the colorant name to those in our Pantone color list.
	 */
	for (pan_index = 0; pan_index < num_pantone_colors ; pan_index++) {
	    const char * pan_name = pantone_list[pan_index].name;

	    if (compare_names(pname, name_size, pan_name, strlen(pan_name))) {
	        pantone_color_index[i] = pan_index;
		match = pantone_found = true;
		break;
	    }
	}
	if (!match) {		/* Exit if we find a non Pantone color */
	    other_separation_found = true;
	    break;
	}
    }
    /*
     * Handle this color space as a 'pantone color space' if we have only
     * PANTONE colors and CMYK.  Any other separations will force us to
     * use the normal Ghostscript processing for a DeviceN color space.
     */
    use_pantone = pantone_found && !other_separation_found;
    if (use_pantone) {
        demo_color_space_data_t * pclient_data =
		allocate_client_data_block(1, pcs->rc.memory->stable_memory);

        if (pclient_data == NULL)
	    return false;
        for(i = 0; i < num_comp; i++ )
	    pclient_data->color_index[i] = pantone_color_index[i];
        pcs->pclient_color_space_data =
	       (client_color_space_data_t *) pclient_data;
    }
    return use_pantone;
}
Beispiel #13
0
bool
DirEntryBlock::Check() const
{
	int32 entryCount = EntryCount();
	if (entryCount == 0)
		return true;

	// Check size: Both name ends and block index arrays must fit and we need
	// at least one byte per name.
	size_t size = sizeof(*fBlock) + entryCount * 10;
	if (size + entryCount > fBlockSize) {
		ERROR("Invalid dir entry block: entry count %d requires minimum size "
			"of %" B_PRIuSIZE " + %d bytes, but block size is %" B_PRIuSIZE
			"\n", (int)entryCount, size, (int)entryCount, fBlockSize);
		return false;
	}

	// check the name ends and block indices arrays and the names
	const char* entryNames = (char*)(fBlock->nameEnds + entryCount);
	const uint64* blockIndices = (uint64*)((uint8*)fBlock + fBlockSize) - 1;
	const char* previousName = NULL;
	uint16 previousNameLength = 0;
	uint16 previousEnd = 0;

	for (int32 i = 0; i < entryCount; i++) {
		// check name end
		uint16 nameEnd = fBlock->nameEnds[i];
		if (nameEnd <= previousEnd || nameEnd > fBlockSize - size) {
			ERROR("Invalid dir entry block: name end offset of entry %" B_PRId32
				": %u, previous: %u\n", i, nameEnd, previousEnd);
			return false;
		}

		// check name length
		uint16 nameLength = nameEnd - previousEnd;
		if (nameLength > kCheckSumFSNameLength) {
			ERROR("Invalid dir entry block: name of entry %" B_PRId32 " too "
				"long: %u\n", i, nameLength);
			return false;
		}

		// verify that the name doesn't contain a null char
		const char* name = entryNames + previousEnd;
		if (strnlen(name, nameLength) != nameLength) {
			ERROR("Invalid dir entry block: name of entry %" B_PRId32
				" contains a null char\n", i);
			return false;
		}

		// compare the name with the previous name
		if (i > 0) {
			int cmp = compare_names(previousName, previousNameLength, name,
				nameLength);
			if (cmp == 0) {
				ERROR("Invalid dir entry block: entries %" B_PRId32 "/%"
					B_PRId32 " have the same name: \"%.*s\"\n", i - 1, i,
					(int)nameLength, name);
				return false;
			} else if (cmp > 0) {
				ERROR("Invalid dir entry block: entries %" B_PRId32 "/%"
					B_PRId32 " out of order: \"%.*s\" > \"%.*s\"\n", i - 1, i,
					(int)previousNameLength, previousName, (int)nameLength,
					name);
				return false;
			}
		}

		// check the block index
		if (blockIndices[-i] < kCheckSumFSSuperBlockOffset / B_PAGE_SIZE) {
			ERROR("Invalid dir entry block: entry %" B_PRId32
				" has invalid block index: %" B_PRIu64, i, blockIndices[-i]);
			return false;
		}

		previousName = name;
		previousNameLength = nameLength;
		previousEnd = nameEnd;
	}

	return true;
}
/* Compare the differences between dir_open_meta and dir_open 
 * @param a_path Path of directory to open
 * @param a_addr The metadata address of the same directory as the path
 * @returns 1 if a test failed
 */
static int
test_dir_open_apis(TSK_FS_INFO * a_fs, const char *a_path,
    TSK_INUM_T a_addr)
{
    TSK_FS_DIR *fs_dir_m;
    TSK_FS_DIR *fs_dir_p;
    TSK_FS_DIR *fs_dir_tmp;
    TSK_FS_FILE *fs_file_m;
    TSK_FS_FILE *fs_file_p;
    int retval = 0;
    size_t entry = 0;

    // open via inode addr
    fs_dir_m = tsk_fs_dir_open_meta(a_fs, a_addr);
    if (!fs_dir_m) {
        fprintf(stderr, "Error opening dir %" PRIuINUM " via meta\n",
            a_addr);
        tsk_error_print(stderr);
        return 1;
    }

    /* open the root directory to throw some more state into the system
     * in case data is cached from first call */
    fs_dir_tmp = tsk_fs_dir_open_meta(a_fs, a_fs->root_inum);
    if (!fs_dir_tmp) {
        fprintf(stderr, "Error opening root directory via meta\n");
        tsk_error_print(stderr);
        return 1;
    }

    // open via path
    fs_dir_p = tsk_fs_dir_open(a_fs, a_path);
    if (!fs_dir_p) {
        fprintf(stderr, "Error opening directory %s\n", a_path);
        tsk_error_print(stderr);
        return 1;
    }

    // test that path has the name structure set (correctly)
    if ((fs_dir_p->fs_file == NULL) || (fs_dir_p->fs_file->name == NULL)) {
        fprintf(stderr, "dir opened via path has null name (%s)\n",
            a_path);
        retval = 1;
        goto open_cleanup;
    }

    if (fs_dir_p->fs_file->name->meta_addr !=
        fs_dir_p->fs_file->meta->addr) {
        fprintf(stderr,
            "dir opened via path has different meta addresses in name and meta (%s) (%"
            PRIuINUM " vs %" PRIuINUM "\n", a_path,
            fs_dir_p->fs_file->name->meta_addr,
            fs_dir_p->fs_file->meta->addr);
        retval = 1;
        goto open_cleanup;
    }

    // verify both methods have same dir addr
    if (fs_dir_p->fs_file->meta->addr != fs_dir_m->fs_file->meta->addr) {
        fprintf(stderr,
            "parent dir addrs from fs_dir_open_meta and via path are different: %"
            PRIuINUM " vs %" PRIuINUM " (%s - %" PRIuINUM "\n",
            fs_dir_p->fs_file->meta->addr, fs_dir_m->fs_file->meta->addr,
            a_path, a_addr);
        retval = 1;
        goto open_cleanup;
    }

    // verify path method has same dir addr as open via meta
    if (fs_dir_p->fs_file->meta->addr != a_addr) {
        fprintf(stderr,
            "parent dir addrs from fs_dir_open is diff from meta address %"
            PRIuINUM " (%s - %" PRIuINUM "\n",
            fs_dir_p->fs_file->meta->addr, a_path, a_addr);
        retval = 1;
        goto open_cleanup;
    }

    // verify both have same size
    if (tsk_fs_dir_getsize(fs_dir_p) != tsk_fs_dir_getsize(fs_dir_m)) {
        fprintf(stderr,
            "sizes from fs_dir_open_meta and via path are different: %"
            PRIuSIZE " vs %" PRIuSIZE " (%s - %" PRIuINUM "\n",
            tsk_fs_dir_getsize(fs_dir_p), tsk_fs_dir_getsize(fs_dir_m),
            a_path, a_addr);
        retval = 1;
        goto open_cleanup;
    }


    // compare the first entry in both. 
    if (tsk_fs_dir_getsize(fs_dir_p) == 0) {
        fprintf(stderr, "directory sizes are 0\n");
        retval = 1;
        goto open_cleanup;
    }

    fs_file_m = tsk_fs_dir_get(fs_dir_m, 0);
    if (fs_file_m == NULL) {
        fprintf(stderr,
            "Error opening entry 0 from meta open: %" PRIuINUM "\n",
            a_addr);
        tsk_error_print(stderr);
        retval = 1;
        goto open_cleanup;
    }

    fs_file_p = tsk_fs_dir_get(fs_dir_p, 0);
    if (fs_file_p == NULL) {
        fprintf(stderr,
            "Error opening entry 0 from path open: %" PRIuINUM "\n",
            a_addr);
        tsk_error_print(stderr);
        retval = 1;
        goto open_cleanup;
    }

    if (compare_names(fs_file_p->name, fs_file_m->name, 1)) {
        fprintf(stderr, "results from entry 0 are different\n");
        retval = 1;
        goto open_cleanup;
    }
    tsk_fs_file_close(fs_file_m);
    tsk_fs_file_close(fs_file_p);


    // compare the last entry in both
    entry = tsk_fs_dir_getsize(fs_dir_m) - 1;
    fs_file_m = tsk_fs_dir_get(fs_dir_m, entry);
    if (fs_file_m == NULL) {
        fprintf(stderr,
            "Error opening entry %" PRIuSIZE " from meta open: %" PRIuINUM
            "\n", entry, a_addr);
        tsk_error_print(stderr);
        retval = 1;
        goto open_cleanup;
    }

    fs_file_p = tsk_fs_dir_get(fs_dir_p, entry);
    if (fs_file_p == NULL) {
        fprintf(stderr,
            "Error opening entry %" PRIuSIZE " from path open: %" PRIuINUM
            "\n", entry, a_addr);
        tsk_error_print(stderr);
        retval = 1;
        goto open_cleanup;
    }

    if (compare_names(fs_file_p->name, fs_file_m->name, 1)) {
        fprintf(stderr, "results from entry %" PRIuSIZE " are different\n",
            entry);
        retval = 1;
        goto open_cleanup;
    }
    tsk_fs_file_close(fs_file_m);
    tsk_fs_file_close(fs_file_p);


  open_cleanup:
    tsk_fs_dir_close(fs_dir_p);
    tsk_fs_dir_close(fs_dir_tmp);
    tsk_fs_dir_close(fs_dir_m);

    return retval;
}
Beispiel #15
0
int
diff_dirs (struct comparison const *cmp,
	   int (*handle_file) (struct comparison const *,
			       char const *, char const *))
{
  struct dirdata dirdata[2];
  int volatile val = EXIT_SUCCESS;
  int i;

  if ((cmp->file[0].desc == -1 || dir_loop (cmp, 0))
      && (cmp->file[1].desc == -1 || dir_loop (cmp, 1)))
    {
      error (0, 0, _("%s: recursive directory loop"),
	     cmp->file[cmp->file[0].desc == -1].name);
      return EXIT_TROUBLE;
    }

  /* Get contents of both dirs.  */
  for (i = 0; i < 2; i++)
    if (! dir_read (&cmp->file[i], &dirdata[i]))
      {
	perror_with_name (cmp->file[i].name);
	val = EXIT_TROUBLE;
      }

  if (val == EXIT_SUCCESS)
    {
      char const **volatile names[2];
      names[0] = dirdata[0].names;
      names[1] = dirdata[1].names;

      /* Use locale-specific sorting if possible, else native byte order.  */
      locale_specific_sorting = true;
      if (setjmp (failed_locale_specific_sorting))
	locale_specific_sorting = false;

      /* Sort the directories.  */
      for (i = 0; i < 2; i++)
	qsort (names[i], dirdata[i].nnames, sizeof *dirdata[i].names,
	       compare_names_for_qsort);

      /* If '-S name' was given, and this is the topmost level of comparison,
	 ignore all file names less than the specified starting name.  */

      if (starting_file && ! cmp->parent)
	{
	  while (*names[0] && compare_names (*names[0], starting_file) < 0)
	    names[0]++;
	  while (*names[1] && compare_names (*names[1], starting_file) < 0)
	    names[1]++;
	}

      /* Loop while files remain in one or both dirs.  */
      while (*names[0] || *names[1])
	{
	  /* Compare next name in dir 0 with next name in dir 1.
	     At the end of a dir,
	     pretend the "next name" in that dir is very large.  */
	  int nameorder = (!*names[0] ? 1 : !*names[1] ? -1
			   : compare_names (*names[0], *names[1]));

	  /* Prefer a file_name_cmp match if available.  This algorithm is
	     O(N**2), where N is the number of names in a directory
	     that compare_names says are all equal, but in practice N
	     is so small it's not worth tuning.  */
	  if (nameorder == 0 && ignore_file_name_case)
	    {
	      int raw_order = file_name_cmp (*names[0], *names[1]);
	      if (raw_order != 0)
		{
		  int greater_side = raw_order < 0;
		  int lesser_side = 1 - greater_side;
		  char const **lesser = names[lesser_side];
		  char const *greater_name = *names[greater_side];
		  char const **p;

		  for (p = lesser + 1;
		       *p && compare_names (*p, greater_name) == 0;
		       p++)
		    {
		      int c = file_name_cmp (*p, greater_name);
		      if (0 <= c)
			{
			  if (c == 0)
			    {
			      memmove (lesser + 1, lesser,
				       (char *) p - (char *) lesser);
			      *lesser = greater_name;
			    }
			  break;
			}
		    }
		}
	    }

	  int v1 = (*handle_file) (cmp,
				   0 < nameorder ? 0 : *names[0]++,
				   nameorder < 0 ? 0 : *names[1]++);
	  if (val < v1)
	    val = v1;
	}
    }

  for (i = 0; i < 2; i++)
    {
      free (dirdata[i].names);
      free (dirdata[i].data);
    }

  return val;
}