/*@null@*/ static PyObject * rpmfi_iternext(rpmfiObject * s) /*@globals _Py_NoneStruct @*/ /*@modifies s, _Py_NoneStruct @*/ { PyObject * result = NULL; /* Reset loop indices on 1st entry. */ if (!s->active) { s->fi = rpmfiInit(s->fi, 0); s->active = 1; } /* If more to do, return the file tuple. */ if (rpmfiNext(s->fi) >= 0) { const char * FN = rpmfiFN(s->fi); int FSize = rpmfiFSize(s->fi); int FMode = rpmfiFMode(s->fi); int FMtime = rpmfiFMtime(s->fi); int FFlags = rpmfiFFlags(s->fi); int FRdev = rpmfiFRdev(s->fi); int FInode = rpmfiFInode(s->fi); int FNlink = rpmfiFNlink(s->fi); int FState = rpmfiFState(s->fi); int VFlags = rpmfiVFlags(s->fi); const char * FUser = rpmfiFUser(s->fi); const char * FGroup = rpmfiFGroup(s->fi); result = PyTuple_New(13); if (FN == NULL) { Py_INCREF(Py_None); PyTuple_SET_ITEM(result, 0, Py_None); } else PyTuple_SET_ITEM(result, 0, Py_BuildValue("s", FN)); PyTuple_SET_ITEM(result, 1, PyInt_FromLong(FSize)); PyTuple_SET_ITEM(result, 2, PyInt_FromLong(FMode)); PyTuple_SET_ITEM(result, 3, PyInt_FromLong(FMtime)); PyTuple_SET_ITEM(result, 4, PyInt_FromLong(FFlags)); PyTuple_SET_ITEM(result, 5, PyInt_FromLong(FRdev)); PyTuple_SET_ITEM(result, 6, PyInt_FromLong(FInode)); PyTuple_SET_ITEM(result, 7, PyInt_FromLong(FNlink)); PyTuple_SET_ITEM(result, 8, PyInt_FromLong(FState)); PyTuple_SET_ITEM(result, 9, PyInt_FromLong(VFlags)); if (FUser == NULL) { Py_INCREF(Py_None); PyTuple_SET_ITEM(result, 10, Py_None); } else PyTuple_SET_ITEM(result, 10, Py_BuildValue("s", FUser)); if (FGroup == NULL) { Py_INCREF(Py_None); PyTuple_SET_ITEM(result, 11, Py_None); } else PyTuple_SET_ITEM(result, 11, Py_BuildValue("s", FGroup)); PyTuple_SET_ITEM(result, 12, rpmfi_Digest(s)); } else s->active = 0; return result; }
/*@only@*/ static rpmvf rpmvfNew(rpmts ts, rpmfi fi, int i, rpmVerifyAttrs omitMask) /*@*/ { rpmvf vf = DRD_xcalloc(1, sizeof(*vf)); #ifdef NOTYET vf->_item.use = yarnNewLock(1); vf->_item.pool = NULL; #endif /*@-mods@*/ vf->fn = rpmGetPath(rpmtsRootDir(ts), fi->dnl[fi->dil[i]], fi->bnl[i], NULL); /*@=mods@*/ vf->flink = fi->flinks[i]; vf->fuser = fi->fuser[i]; vf->fgroup = fi->fgroup[i]; { struct stat *st = &vf->sb; st->st_dev = st->st_rdev = fi->frdevs[i]; st->st_ino = fi->finodes[i]; st->st_mode = fi->fmodes[i]; #ifdef NOTNEEDED st->st_nlink = rpmfiFNlink(fi) + (int)S_ISDIR(st->st_mode); #endif if (unameToUid(vf->fuser, &st->st_uid) == -1) st->st_uid = 0; /* XXX */ if (gnameToGid(vf->fgroup, &st->st_gid) == -1) st->st_gid = 0; /* XXX */ st->st_size = fi->fsizes[i]; st->st_blksize = 4 * 1024; /* XXX */ st->st_blocks = (st->st_size + (st->st_blksize - 1)) / st->st_blksize; st->st_atime = st->st_ctime = st->st_mtime = fi->fmtimes[i]; } vf->fflags = fi->fflags[i]; vf->fstate = fi->fstates[i]; vf->vflags = fi->vflags[i]; vf->dalgo = fi->fdigestalgos ? fi->fdigestalgos[i] : fi->digestalgo; vf->dlen = fi->digestlen; vf->digest = fi->digests + (fi->digestlen * i); /* Don't verify any features in omitMask. */ vf->vflags &= ~(omitMask | RPMVERIFY_FAILURES); /* Content checks of %ghost files are meaningless. */ if (vf->fflags & RPMFILE_GHOST) vf->vflags &= ~(RPMVERIFY_FDIGEST | RPMVERIFY_FILESIZE | RPMVERIFY_MTIME | RPMVERIFY_LINKTO | RPMVERIFY_HMAC); return vf; }
static int filenlinksTag(Header h, rpmtd td, headerGetFlags hgflags) { rpmfi fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, RPMFI_NOHEADER); rpm_count_t fc = rpmfiFC(fi); if (fc > 0) { uint32_t *nlinks = xmalloc(fc * sizeof(*nlinks)); int ix; while ((ix = rpmfiNext(fi)) >= 0) { nlinks[ix] = rpmfiFNlink(fi); } td->data = nlinks; td->type = RPM_INT32_TYPE; td->count = fc; td->flags = RPMTD_ALLOCED; } rpmfiFree(fi); return (fc > 0); }
static int fsmMkfile(rpmfi fi, const char *dest, rpmfiles files, rpmpsm psm, int nodigest, int *setmeta, int * firsthardlink, FD_t *firstlinkfile) { int rc = 0; int numHardlinks = rpmfiFNlink(fi); if (numHardlinks > 1) { /* Create first hardlinked file empty */ if (*firsthardlink < 0) { *firsthardlink = rpmfiFX(fi); rc = wfd_open(firstlinkfile, dest); } else { /* Create hard links for others */ char *fn = rpmfilesFN(files, *firsthardlink); rc = link(fn, dest); if (rc < 0) { rc = RPMERR_LINK_FAILED; } free(fn); } } /* Write normal files or fill the last hardlinked (already existing) file with content */ if (numHardlinks<=1) { if (!rc) rc = expandRegular(fi, dest, psm, nodigest); } else if (rpmfiArchiveHasContent(fi)) { if (!rc) rc = rpmfiArchiveReadToFilePsm(fi, *firstlinkfile, nodigest, psm); wfd_close(firstlinkfile); *firsthardlink = -1; } else { *setmeta = 0; } return rc; }
static int process_package(rpmts ts, char * filename) { FD_t fdi; FD_t gzdi; Header h; int rc = 0; char * rpmio_flags = NULL; struct archive *a; struct archive_entry *entry; if (!strcmp(filename, "-")) { fdi = fdDup(STDIN_FILENO); } else { fdi = Fopen(filename, "r.ufdio"); } if (Ferror(fdi)) { fprintf(stderr, "rpm2archive: %s: %s\n", filename, Fstrerror(fdi)); exit(EXIT_FAILURE); } rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h); switch (rc) { case RPMRC_OK: case RPMRC_NOKEY: case RPMRC_NOTTRUSTED: break; case RPMRC_NOTFOUND: fprintf(stderr, _("argument is not an RPM package\n")); exit(EXIT_FAILURE); break; case RPMRC_FAIL: default: fprintf(stderr, _("error reading header from package\n")); exit(EXIT_FAILURE); break; } /* Retrieve payload size and compression type. */ { const char *compr = headerGetString(h, RPMTAG_PAYLOADCOMPRESSOR); rpmio_flags = rstrscat(NULL, "r.", compr ? compr : "gzip", NULL); } gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */ free(rpmio_flags); if (gzdi == NULL) { fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi)); exit(EXIT_FAILURE); } rpmfiles files = rpmfilesNew(NULL, h, 0, RPMFI_KEEPHEADER); rpmfi fi = rpmfiNewArchiveReader(gzdi, files, RPMFI_ITER_READ_ARCHIVE_CONTENT_FIRST); /* create archive */ a = archive_write_new(); archive_write_add_filter_gzip(a); archive_write_set_format_pax_restricted(a); if (!strcmp(filename, "-")) { if (isatty(STDOUT_FILENO)) { fprintf(stderr, "Error: refusing to output archive data to a terminal.\n"); exit(EXIT_FAILURE); } archive_write_open_fd(a, STDOUT_FILENO); } else { char * outname = rstrscat(NULL, filename, ".tgz", NULL); archive_write_open_filename(a, outname); _free(outname); // XXX error handling } entry = archive_entry_new(); char * buf = xmalloc(BUFSIZE); char * hardlink = NULL; rc = 0; while (rc >= 0) { rc = rpmfiNext(fi); if (rc == RPMERR_ITER_END) { break; } rpm_mode_t mode = rpmfiFMode(fi); int nlink = rpmfiFNlink(fi); fill_archive_entry(a, entry, fi); if (nlink > 1) { if (rpmfiArchiveHasContent(fi)) { _free(hardlink); hardlink = rstrscat(NULL, ".", rpmfiFN(fi), NULL); } else { archive_entry_set_hardlink(entry, hardlink); } } archive_write_header(a, entry); if (S_ISREG(mode) && (nlink == 1 || rpmfiArchiveHasContent(fi))) { write_file_content(a, buf, fi); } } /* End of iteration is not an error */ if (rc == RPMERR_ITER_END) { rc = 0; } _free(hardlink); Fclose(gzdi); /* XXX gzdi == fdi */ archive_entry_free(entry); archive_write_close(a); archive_write_free(a); buf = _free(buf); rpmfilesFree(files); rpmfiFree(fi); headerFree(h); return rc; }