00001
00002
00003 #include "system.h"
00004 const char *__progname;
00005
00006 #include <rpmlib.h>
00007 #include <rpmpgp.h>
00008
00009 #include "depends.c"
00010
00011 #include "debug.h"
00012
00013 int main(int argc, char **argv)
00014 {
00015 FD_t fdi, fdo;
00016 Header h;
00017 char * rpmio_flags;
00018 rpmRC rc;
00019 FD_t gzdi;
00020
00021 setprogname(argv[0]);
00022 if (argc == 1)
00023 fdi = fdDup(STDIN_FILENO);
00024 else
00025 fdi = Fopen(argv[1], "r.ufdio");
00026
00027 if (Ferror(fdi)) {
00028 fprintf(stderr, "%s: %s: %s\n", argv[0],
00029 (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
00030 exit(EXIT_FAILURE);
00031 }
00032 fdo = fdDup(STDOUT_FILENO);
00033
00034 { rpmts ts = rpmtsCreate();
00035 rpmVSFlags vsflags = 0;
00036
00037
00038 vsflags |= _RPMVSF_NODIGESTS;
00039 vsflags |= _RPMVSF_NOSIGNATURES;
00040 vsflags |= RPMVSF_NOHDRCHK;
00041 (void) rpmtsSetVSFlags(ts, vsflags);
00042
00043
00044 rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h);
00045
00046
00047 ts = rpmtsFree(ts);
00048 }
00049
00050 switch (rc) {
00051 case RPMRC_OK:
00052 case RPMRC_NOKEY:
00053 case RPMRC_NOTTRUSTED:
00054 break;
00055 case RPMRC_NOTFOUND:
00056 fprintf(stderr, _("argument is not an RPM package\n"));
00057 exit(EXIT_FAILURE);
00058 break;
00059 case RPMRC_FAIL:
00060 default:
00061 fprintf(stderr, _("error reading header from package\n"));
00062 exit(EXIT_FAILURE);
00063 break;
00064 }
00065
00066
00067 { const char * payload_compressor = NULL;
00068 char * t;
00069
00070 if (!headerGetEntry(h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
00071 (void **) &payload_compressor, NULL))
00072 payload_compressor = "gzip";
00073 rpmio_flags = t = alloca(sizeof("r.gzdio"));
00074 *t++ = 'r';
00075 if (!strcmp(payload_compressor, "gzip"))
00076 t = stpcpy(t, ".gzdio");
00077 if (!strcmp(payload_compressor, "bzip2"))
00078 t = stpcpy(t, ".bzdio");
00079 }
00080
00081 gzdi = Fdopen(fdi, rpmio_flags);
00082 if (gzdi == NULL) {
00083 fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
00084 exit(EXIT_FAILURE);
00085 }
00086
00087 rc = ufdCopy(gzdi, fdo);
00088 rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
00089 Fclose(fdo);
00090
00091 Fclose(gzdi);
00092
00093 return rc;
00094 }