Print this page
3299 file should only care about object capabilities
3300 file should care about all object capabilities


  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  22 /*        All Rights Reserved   */
  23 
  24 
  25 /*      Copyright (c) 1987, 1988 Microsoft Corporation  */
  26 /*        All Rights Reserved   */
  27 
  28 /*
  29  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  30  * Use is subject to license terms.
  31  */
  32 
  33 #pragma ident   "%Z%%M% %I%     %E% SMI"
  34 
  35 /*
  36  * ELF files can exceed 2GB in size. A standard 32-bit program
  37  * like 'file' cannot read past 2GB, and will be unable to see
  38  * the ELF section headers that typically are at the end of the
  39  * object. The simplest solution to this problem would be to make
  40  * the 'file' command a 64-bit application. However, as a matter of
  41  * policy, we do not want to require this. A simple command like
  42  * 'file' should not carry such a requirement, especially as we
  43  * support 32-bit only hardware.
  44  *
  45  * An alternative solution is to build this code as 32-bit
  46  * large file aware. The usual way to do this is to define a pair
  47  * of preprocessor definitions:
  48  *
  49  *      _LARGEFILE64_SOURCE
  50  *              Map standard I/O routines to their largefile aware versions.
  51  *
  52  *      _FILE_OFFSET_BITS=64
  53  *              Map off_t to off64_t
  54  *


 441                 return (ELF_READ_FAIL);
 442 
 443         if (pread64(EI->elffd, section_name, shdr->sh_size, shdr->sh_offset)
 444             != shdr->sh_size)
 445                 return (ELF_READ_FAIL);
 446 
 447         /* read all the sections and process them */
 448         for (idx = 1, i = 0; i < EI_Ehdr_shnum; idx++, i++) {
 449                 char *str;
 450 
 451                 if (get_shdr(EI, i) == ELF_READ_FAIL)
 452                         return (ELF_READ_FAIL);
 453 
 454                 if (shdr->sh_type == SHT_NULL) {
 455                         idx--;
 456                         continue;
 457                 }
 458 
 459                 cap_off = shdr->sh_offset;
 460                 if (shdr->sh_type == SHT_SUNW_cap) {


 461                         if (shdr->sh_size == 0 || shdr->sh_entsize == 0) {
 462                                 (void) fprintf(stderr, ELF_ERR_ELFCAP1,
 463                                     File, EI->file);
 464                                 return (ELF_READ_FAIL);
 465                         }
 466                         capn = (shdr->sh_size / shdr->sh_entsize);
 467                         for (j = 0; j < capn; j++) {
 468                                 /*
 469                                  * read cap and xlate the values
 470                                  */
 471                                 if (pread64(EI->elffd, &Chdr, csize, cap_off)
 472                                     != csize ||
 473                                     file_xlatetom(ELF_T_CAP, (char *)&Chdr)
 474                                     == 0) {
 475                                         (void) fprintf(stderr, ELF_ERR_ELFCAP2,
 476                                             File, EI->file);
 477                                         return (ELF_READ_FAIL);
 478                                 }
 479 
 480                                 if (Chdr.c_tag != CA_SUNW_NULL) {
 481                                         (void) elfcap_tag_to_str(
 482                                             ELFCAP_STYLE_UC, Chdr.c_tag,
 483                                             Chdr.c_un.c_val, EI->cap_str,
 484                                             sizeof (EI->cap_str),
 485                                             ELFCAP_FMT_SNGSPACE, mac);
 486                                 }
 487                                 cap_off += csize;





















 488                         }
 489                 }
 490 
 491                 /*
 492                  * Definition time:
 493                  *      - "not stripped" means that an executable file
 494                  *      contains a Symbol Table (.symtab)
 495                  *      - "stripped" means that an executable file
 496                  *      does not contain a Symbol Table.
 497                  * When strip -l or strip -x is run, it strips the
 498                  * debugging information (.line section name (strip -l),
 499                  * .line, .debug*, .stabs*, .dwarf* section names
 500                  * and SHT_SUNW_DEBUGSTR and SHT_SUNW_DEBUG
 501                  * section types (strip -x), however the Symbol
 502                  * Table will still be present.
 503                  * Therefore, if
 504                  *      - No Symbol Table present, then report
 505                  *              "stripped"
 506                  *      - Symbol Table present with debugging
 507                  *      information (line number or debug section names,




  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  22 /*        All Rights Reserved   */
  23 
  24 
  25 /*      Copyright (c) 1987, 1988 Microsoft Corporation  */
  26 /*        All Rights Reserved   */
  27 
  28 /*
  29  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  30  * Use is subject to license terms.
  31  */
  32 


  33 /*
  34  * ELF files can exceed 2GB in size. A standard 32-bit program
  35  * like 'file' cannot read past 2GB, and will be unable to see
  36  * the ELF section headers that typically are at the end of the
  37  * object. The simplest solution to this problem would be to make
  38  * the 'file' command a 64-bit application. However, as a matter of
  39  * policy, we do not want to require this. A simple command like
  40  * 'file' should not carry such a requirement, especially as we
  41  * support 32-bit only hardware.
  42  *
  43  * An alternative solution is to build this code as 32-bit
  44  * large file aware. The usual way to do this is to define a pair
  45  * of preprocessor definitions:
  46  *
  47  *      _LARGEFILE64_SOURCE
  48  *              Map standard I/O routines to their largefile aware versions.
  49  *
  50  *      _FILE_OFFSET_BITS=64
  51  *              Map off_t to off64_t
  52  *


 439                 return (ELF_READ_FAIL);
 440 
 441         if (pread64(EI->elffd, section_name, shdr->sh_size, shdr->sh_offset)
 442             != shdr->sh_size)
 443                 return (ELF_READ_FAIL);
 444 
 445         /* read all the sections and process them */
 446         for (idx = 1, i = 0; i < EI_Ehdr_shnum; idx++, i++) {
 447                 char *str;
 448 
 449                 if (get_shdr(EI, i) == ELF_READ_FAIL)
 450                         return (ELF_READ_FAIL);
 451 
 452                 if (shdr->sh_type == SHT_NULL) {
 453                         idx--;
 454                         continue;
 455                 }
 456 
 457                 cap_off = shdr->sh_offset;
 458                 if (shdr->sh_type == SHT_SUNW_cap) {
 459                         char capstr[128];
 460 
 461                         if (shdr->sh_size == 0 || shdr->sh_entsize == 0) {
 462                                 (void) fprintf(stderr, ELF_ERR_ELFCAP1,
 463                                     File, EI->file);
 464                                 return (ELF_READ_FAIL);
 465                         }
 466                         capn = (shdr->sh_size / shdr->sh_entsize);
 467                         for (j = 0; j < capn; j++) {
 468                                 /*
 469                                  * read cap and xlate the values
 470                                  */
 471                                 if (pread64(EI->elffd, &Chdr, csize, cap_off)
 472                                     != csize ||
 473                                     file_xlatetom(ELF_T_CAP, (char *)&Chdr)
 474                                     == 0) {
 475                                         (void) fprintf(stderr, ELF_ERR_ELFCAP2,
 476                                             File, EI->file);
 477                                         return (ELF_READ_FAIL);
 478                                 }
 479 







 480                                 cap_off += csize;
 481 
 482                                 /*
 483                                  * Each capatibility group is terminated with
 484                                  * CA_SUNW_NULL.  Groups other than the first
 485                                  * represent symbol capabilities, and aren't
 486                                  * interesting here.
 487                                  */
 488                                 if (Chdr.c_tag == CA_SUNW_NULL)
 489                                         break;
 490 
 491                                 (void) elfcap_tag_to_str(ELFCAP_STYLE_UC,
 492                                     Chdr.c_tag, Chdr.c_un.c_val, capstr,
 493                                     sizeof (capstr), ELFCAP_FMT_SNGSPACE,
 494                                     mac);
 495 
 496                                 if ((*EI->cap_str != '\0') && (*capstr != '\0'))
 497                                         (void) strlcat(EI->cap_str, " ",
 498                                             sizeof (EI->cap_str));
 499 
 500                                 (void) strlcat(EI->cap_str, capstr,
 501                                     sizeof (EI->cap_str));
 502                         }
 503                 }
 504 
 505                 /*
 506                  * Definition time:
 507                  *      - "not stripped" means that an executable file
 508                  *      contains a Symbol Table (.symtab)
 509                  *      - "stripped" means that an executable file
 510                  *      does not contain a Symbol Table.
 511                  * When strip -l or strip -x is run, it strips the
 512                  * debugging information (.line section name (strip -l),
 513                  * .line, .debug*, .stabs*, .dwarf* section names
 514                  * and SHT_SUNW_DEBUGSTR and SHT_SUNW_DEBUG
 515                  * section types (strip -x), however the Symbol
 516                  * Table will still be present.
 517                  * Therefore, if
 518                  *      - No Symbol Table present, then report
 519                  *              "stripped"
 520                  *      - Symbol Table present with debugging
 521                  *      information (line number or debug section names,