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