-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpmcheck1.c
executable file
·75 lines (59 loc) · 1.85 KB
/
rpmcheck1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Use some stuff
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <rpm/rpmlib.h>
// Here we've defined the program's storage. Note in particular the HeaderIterator, Header, and int_32 datatypes.
void main(int argc, char ** argv)
{
HeaderIterator iter;
Header h, sig;
int_32 itertag, type, count;
void **p = NULL;
char *blather;
char * name;
int fd, stat;
if (argc == 1) {
fd = 0;
} else {
fd = open(argv[1], O_RDONLY, 0644);
}
if (fd < 0) {
perror("open");
exit(1);
}
stat = rpmReadPackageInfo(fd, &sig, &h);
if (stat) {
fprintf(stderr,
"rpmReadPackageInfo error status: %d\n%s\n",
stat, strerror(errno));
exit(stat);
}
headerGetEntry(h, RPMTAG_NAME, &type, (void **) &name, &count);
if (headerIsEntry(h, RPMTAG_PREIN)) {
printf("There is a preinstall script for %s\n", name);
}
if (headerIsEntry(h, RPMTAG_POSTIN)) {
printf("There is a postinstall script for %s\n", name);
}
printf("Dumping signatures...\n");
headerDump(sig, stdout, 1);
rpmFreeSignature(sig);
printf("Iterating through the header...\n");
iter = headerInitIterator(h);
while (headerNextIterator(iter, &itertag, &type, p, &count)) {
switch (itertag) {
case RPMTAG_SUMMARY:
blather = *p;
printf("The Summary: %s\n", blather);
break;
case RPMTAG_FILENAMES:
printf("There are %d files in this package\n", count);
break;
}
}
headerFreeIterator(iter);
headerFree(h);
}