8 #if LIBELF_H_LFS_CONFLICT
12 # undef _LARGEFILE64_SOURCE
13 # undef _LARGEFILE_SOURCE
14 # undef _FILE_OFFSET_BITS
15 # define _FILE_OFFSET_BITS 32
19 #if !defined(DT_GNU_PRELINKED)
20 #define DT_GNU_PRELINKED 0x6ffffdf5
22 #if !defined(DT_GNU_LIBLIST)
23 #define DT_GNU_LIBLIST 0x6ffffef9
35 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
44 static int open_dso(
const char * path, pid_t * pidp,
size_t *fsizep)
50 static const char * cmd = NULL;
51 static int initted = 0;
55 cmd =
rpmExpand(
"%{?__prelink_undo_cmd}", NULL);
63 struct stat sb, * st = &sb;
64 if (stat(path, st) < 0)
66 *fsizep = st->st_size;
70 fdno = open(path, O_RDONLY);
79 #if HAVE_GELF_H && HAVE_LIBELF
82 Elf_Data *data = NULL;
88 (void) elf_version(EV_CURRENT);
91 if ((elf = elf_begin (fdno, ELF_C_READ, NULL)) == NULL
92 || elf_kind(elf) != ELF_K_ELF
93 || gelf_getehdr(elf, &ehdr) == NULL
94 || !(ehdr.e_type == ET_DYN || ehdr.e_type == ET_EXEC))
100 while (!bingo && (scn = elf_nextscn(elf, scn)) != NULL) {
101 (void) gelf_getshdr(scn, &shdr);
102 if (shdr.sh_type != SHT_DYNAMIC)
104 while (!bingo && (data = elf_getdata (scn, data)) != NULL) {
105 int maxndx = data->d_size / shdr.sh_entsize;
108 for (ndx = 0; ndx < maxndx; ++ndx) {
109 (void) gelf_getdyn (data, ndx, &dyn);
110 if (!(dyn.d_tag == DT_GNU_PRELINKED || dyn.d_tag == DT_GNU_LIBLIST))
120 if (pidp != NULL && bingo) {
126 pipes[0] = pipes[1] = -1;
128 if (!(pid = fork())) {
131 xx = close(pipes[0]);
132 xx = dup2(pipes[1], STDOUT_FILENO);
133 xx = close(pipes[1]);
134 if (!poptParseArgvString(cmd, &ac, &av)) {
138 xx = execve(av[0], (
char *
const *)av+1, environ);
144 xx = close(pipes[1]);
149 if (elf) (void) elf_end(elf);
156 int dodigest(
int digestalgo,
const char * fn,
unsigned char * digest,
int asAscii,
size_t *fsizep)
160 unsigned char * dsum = NULL;
162 unsigned char buf[32*BUFSIZ];
172 fdno =
open_dso(path, &pid, &fsize);
180 use_mmap = (pid == 0 && fsize <= 0x07ffffff);
188 void * mapped = NULL;
191 mapped = mmap(NULL, fsize, PROT_READ, MAP_SHARED, fdno, 0);
192 if (mapped == (
void *)-1) {
198 #ifdef MADV_SEQUENTIAL
199 xx = madvise(mapped, fsize, MADV_SEQUENTIAL);
208 xx = munmap(mapped, fsize);
220 fd = (pid != 0) ?
fdDup(fdno) :
Fopen(fn,
"r");
222 if (fd == NULL ||
Ferror(fd)) {
231 while ((rc =
Fread(buf,
sizeof(buf[0]),
sizeof(buf), fd)) > 0)
244 (void) waitpid(pid, &status, 0);
245 if (!WIFEXITED(status) || WEXITSTATUS(status))
254 memcpy(digest, dsum, dlen);
261 int domd5(
const char * fn,
unsigned char * digest,
int asAscii,
size_t *fsizep)
267 const char *** fnp,
int * fcp)
271 const char ** baseNames;
272 const char ** dirNames;
275 const char ** fileNames;
291 if (!hge(h, tagN, &bnt, &baseNames, &count)) {
292 if (fnp) *fnp = NULL;
297 xx = hge(h, dirNameTag, &dnt, &dirNames, NULL);
298 xx = hge(h, dirIndexesTag, NULL, &dirIndexes, &count);
300 size =
sizeof(*fileNames) * count;
301 for (i = 0; i < count; i++) {
302 const char * dn = NULL;
303 (void)
urlPath(dirNames[dirIndexes[i]], &dn);
304 size += strlen(baseNames[i]) + strlen(dn) + 1;
308 t = ((
char *) fileNames) + (
sizeof(*fileNames) * count);
310 for (i = 0; i < count; i++) {
311 const char * dn = NULL;
313 (void)
urlPath(dirNames[dirIndexes[i]], &dn);
318 baseNames = hfd(baseNames, bnt);
319 dirNames = hfd(dirNames, dnt);
325 fileNames =
_free(fileNames);
327 if (fcp) *fcp = count;