fips_addchecksum.c revision 32e0ab73531b6e6e8957e9ecdbbd42603865f2d0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <libelf.h>
#include <gelf.h>
#include <stdlib.h>
#include <string.h>
#include <sha1.h>
#include <sys/elf_SPARC.h>
#include <fips/fips_checksum.h>
#define FAIL_EXIT \
return (-1)
static const char fips_section_name[] = ".SUNW_fips";
static int
add_fips_section(int fd)
{
/* Obtain the ELF descriptor */
(void) elf_version(EV_CURRENT);
}
NULL) {
}
/* Traverse input file to see if the fips section already exists */
}
/*
* If the fips section already exists, make sure that
* the section is large enough.
*/
}
}
}
}
/* If the fips section does not exist, allocate the section. */
/* add the section name at the end of the .shstrtab section */
}
}
/* Initialize the fips section */
}
/*
* sh_name is the starting position of the name
* within the shstrtab_data->d_buf buffer
*/
}
}
}
return (0);
}
int
{
int fd;
char sha1buf[SHA1_DIGEST_LENGTH];
if (argc != 2) {
return (-1);
}
/* Open the driver file */
goto errorexit;
}
/* Read the ELF header */
goto errorexit;
}
/* check if it is an ELF file */
for (i = 0; i < SELFMAG; i++) {
goto errorexit;
}
}
goto errorexit;
}
}
goto errorexit;
}
/* calculate the file checksum */
goto errorexit;
}
(void) elf_version(EV_CURRENT);
goto errorexit;
}
goto errorexit;
NULL) {
goto errorexit;
goto errorexit;
}
/* Add the checksum to the fips section */
goto errorexit;
}
goto errorexit;
}
}
}
return (0);
}