7 #if defined(HAVE_GELF_H)
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
17 #if defined(__LCLINT__)
19 typedef long long loff_t;
24 #if !defined(DT_GNU_PRELINKED)
25 #define DT_GNU_PRELINKED 0x6ffffdf5
27 #if !defined(DT_GNU_LIBLIST)
28 #define DT_GNU_LIBLIST 0x6ffffef9
39 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
49 static int open_dso(
const char * path, pid_t * pidp,
size_t *fsizep)
59 struct stat sb, * st = &sb;
60 if (stat(path, st) < 0)
62 *fsizep = (size_t)st->st_size;
65 fdno = open(path, O_RDONLY);
69 #if defined(HAVE_GELF_H) && defined(HAVE_LIBELF)
72 Elf_Data *
data = NULL;
79 static const char ** cmd_av = NULL;
80 static int cmd_ac = 0;
87 const char *
cmd =
rpmExpand(
"%{?__prelink_undo_cmd}", NULL);
88 (void) poptParseArgvString(cmd, &cmd_ac, &cmd_av);
98 (void) elf_version(EV_CURRENT);
101 if ((elf = elf_begin (fdno, ELF_C_READ, NULL)) == NULL
102 || elf_kind(elf) != ELF_K_ELF
103 || gelf_getehdr(elf, &ehdr) == NULL
104 || !(ehdr.e_type == ET_DYN || ehdr.e_type == ET_EXEC))
106 if (elf) (void) elf_end(elf);
114 while (!bingo && (scn = elf_nextscn(elf, scn)) != NULL) {
115 (void) gelf_getshdr(scn, &shdr);
116 if (shdr.sh_type != SHT_DYNAMIC || shdr.sh_entsize == 0)
118 while (!bingo && (data = elf_getdata (scn, data)) != NULL) {
119 unsigned maxndx = (unsigned) (data->d_size / shdr.sh_entsize);
122 for (ndx = 0; ndx < maxndx; ++ndx) {
124 (void) gelf_getdyn (data, ndx, &dyn);
126 if (!(dyn.d_tag == DT_GNU_PRELINKED || dyn.d_tag == DT_GNU_LIBLIST))
138 if (pidp != NULL && bingo) {
139 int pipes[2] = { -1, -1 };
147 {
const char ** av = NULL;
149 xx = close(pipes[0]);
150 xx = dup2(pipes[1], STDOUT_FILENO);
151 xx = close(pipes[1]);
152 if (!poptDupArgv(cmd_ac, cmd_av, &ac, &av)) {
156 xx = execve(av[0], (
char *
const *)av+1,
environ);
163 xx = close(pipes[1]);
176 static const char hmackey[] =
"orboDeJITITejsirpADONivirpUkvarP";
178 int dodigest(
int dalgo,
const char * fn,
unsigned char * digest,
179 unsigned dflags,
size_t *fsizep)
181 int asAscii = dflags & 0x01;
182 int doHmac = dflags & 0x02;
185 unsigned char * dsum = NULL;
187 unsigned char buf[32*BUFSIZ];
194 #if defined(HAVE_MMAP)
199 fdno =
open_dso(path, &pid, &fsize);
207 use_mmap = (pid == 0 && fsize <= 0x07ffffff);
212 #if defined(HAVE_MMAP)
215 void * mapped = NULL;
218 mapped = mmap(NULL, fsize, PROT_READ, MAP_SHARED, fdno, 0);
219 if (mapped == (
void *)-1) {
225 #if defined(HAVE_MADVISE) && defined(MADV_SEQUENTIAL)
226 xx = madvise(mapped, fsize, MADV_SEQUENTIAL);
237 xx = munmap(mapped, fsize);
249 fd = (pid != 0) ?
fdDup(fdno) :
Fopen(fn,
"r.fdio");
251 if (fd == NULL ||
Ferror(fd)) {
262 while ((rc = (
int)
Fread(buf,
sizeof(buf[0]),
sizeof(buf), fd)) > 0)
276 (void) waitpid(pid, &status, 0);
278 if (!WIFEXITED(status) || WEXITSTATUS(status))
286 memcpy(digest, dsum, dlen);
287 if (asAscii) digest[dlen] =
'\0';
#define PTHREAD_MUTEX_INITIALIZER
enum urltype_e urltype
Supported URL types.
void yarnPossess(yarnLock bolt)
const char const char * cmd
#define ANNOTATE_IGNORE_READS_AND_WRITES_END()
FD_t Fopen(const char *path, const char *_fmode)
fopen(3) clone.
DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags)
Initialize digest context.
enum pgpHashAlgo_e pgpHashAlgo
9.4.
static int open_dso(const char *path, pid_t *pidp, size_t *fsizep)
Open a file descriptor to verify file MD5 and size.
#define pthread_mutex_lock(__mutex)
static void fdInitHmac(FD_t fd, const void *key, size_t keylen)
Attach digest to fd.
int dodigest(int dalgo, const char *fn, unsigned char *digest, unsigned dflags, size_t *fsizep)
Return digest and size of a file.
static void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int _flags)
Attach digest to fd.
int rpmHmacInit(DIGEST_CTX ctx, const void *key, size_t keylen)
Compute key material and add to digest context.
int rpmDigestUpdate(DIGEST_CTX ctx, const void *data, size_t len)
Update context with next plain text buffer.
const char const bson * data
#define pthread_mutex_unlock(__mutex)
yarnLock yarnNewLock(long initial)
The FD_t File Handle data structure.
static void fdFiniDigest(FD_t fd, pgpHashAlgo hashalgo, void *datap, size_t *lenp, int asAscii)
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
size_t Fread(void *buf, size_t size, size_t nmemb, FD_t fd)
fread(3) clone.
void unsetenv(const char *name)
int Fclose(FD_t fd)
fclose(3) clone.
void yarnRelease(yarnLock bolt)
int Ferror(FD_t fd)
ferror(3) clone.
urltype urlPath(const char *url, const char **pathp)
Return path component of URL.
#define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN()
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int rpmDigestFinal(DIGEST_CTX ctx, void *datap, size_t *lenp, int asAscii)
Return digest and destroy context.
static const char hmackey[]