bool textSource::isHTMLtagComing(wint_t ch) { bool ret = false; if(ch != WEOF && ch != 26 && (html_tag.*tagState)(ch) == tag) { long curr_pos = Ftell(sourceFile); //assert(html_tag.*tagState == &html_tag_class::lt); estate Seq = notag; do { ch = Getc(sourceFile); if(ch == WEOF || ch == 26) { Seq = notag; break; } Seq = (html_tag.*tagState)(ch); } while(Seq == tag || Seq == endoftag_startoftag); /*notag,tag,endoftag,endoftag_startoftag*/ if(Seq == notag) { // Not an HTML tag. Backtrack. } else // endoftag { // ch == '>' assert(ch == '>'); tagendpos = Ftell(sourceFile);// position of first char after '>' ret = true; } Fseek(sourceFile,curr_pos,_SEEK_SET); } return ret; }
static PyObject *rpmfd_tell(rpmfdObject *s) { off_t offset; Py_BEGIN_ALLOW_THREADS offset = Ftell(s->fd); Py_END_ALLOW_THREADS return Py_BuildValue("L", offset); }
/* * Returns -1 if an error seeking; otherwise the routine * returns the size of a file in bytes and leaves the file * at the beginning when finished (successful). * * This routine assumes FSEEK and FTELL are present on the system. */ long int filesize(FILE *fp) { long int fsize; if (Fseek(fp, 0L, SEEK_END) != 0) { wipoutput(stderr, "Error searching for the end of the file.\n"); return(-1L); } fsize = Ftell(fp); if (Fseek(fp, 0L, SEEK_SET) != 0) { wipoutput(stderr, "Error finding the beginning of the file.\n"); return(-1L); } return(fsize); }
//============================================================================= // FUNCTION: IndexFileAdd // ---------------------------------------------------------------------------- //! Add an entry to the index file. //! //! \param FileHandle //! The handle for the index file to use. //! \param FileIndex //! The index that we are looking to add to the list of indexes. //! //! \retval DB_ERROR_CRITICAL //! Something really bad happened and we have no way to recover. //! \retval DB_ERROR_NONE //! The index was successfully added to the index file. //! //============================================================================= static _reentrant INT IndexFileAdd(INT FileHandle, INT FileIndex) { INT TempIndex; LONG FilePosition; LONG lPosition; // // Need to see if this entry has already been deleted. // FilePosition = Ftell(FileHandle); lPosition = FilePosition; Fseek(FileHandle, 0, SEEK_SET); while (lPosition > 0) { if (DB_STRING_HANDLE_SIZE != Fread(FileHandle, &TempIndex, DB_STRING_HANDLE_SIZE, DEFAULT_MEMORY, -1)) { return(DB_ERROR_CRITICAL); } if (TempIndex == FileIndex) { break; } lPosition -= DB_STRING_HANDLE_SIZE; } if (0 == lPosition) { // // Seek back to the original position. // Fseek(FileHandle, FilePosition, SEEK_SET); // // Update deleted list. // if (DB_STRING_HANDLE_SIZE != Fwrite(FileHandle, &FileIndex, DB_STRING_HANDLE_SIZE, DEFAULT_MEMORY, -1)) { return(DB_ERROR_CRITICAL); } } return(DB_ERROR_NONE); }
/* * Print out the contents of the file f, one screenful at a time. */ void screen(FILE *f, int num_lines) { int ch; int nchars; int length; /* length of current line */ static int prev_len = 1; /* length of previous line */ for (;;) { while (num_lines > 0 && !Pause) { if ((nchars = get_line(f, &length)) == EOF) { if (clreol) clreos(); return; } if (ssp_opt && length == 0 && prev_len == 0) continue; prev_len = length; if (bad_so || (Senter && *Senter == ' ' && promptlen > 0)) erasep(0); /* * Must clear before drawing line since tabs on some * terminals do not erase what they tab over. */ if (clreol) cleareol(); prbuf(Line, length); if (nchars < promptlen) { /* erasep() sets promptlen to 0 */ erasep(nchars); } else promptlen = 0; #if 0 /* XXX - is this needed? */ if (clreol) { /* must clear again in case we wrapped * */ cleareol(); } #endif if (nchars < Mcol || !fold_opt) { /* will turn off UL if necessary */ prbuf("\n", 1); } if (nchars == STOP) break; num_lines--; } if (pstate) { tputs(ULexit, 1, putch); pstate = 0; } fflush(stdout); if ((ch = Getc(f)) == EOF) { if (clreol) clreos(); return; } if (Pause && clreol) clreos(); Ungetc(ch, f); Pause = 0; startup = 0; if ((num_lines = command(NULL, f)) == 0) return; if (hard && promptlen > 0) erasep(0); if (noscroll && num_lines >= dlines) { if (clreol) home(); else doclear(); } /* * XXX - should store the *first* line on the screen, * not the last (but we don't know the file position). * Fixing this requires keeping an arry of dline off_ts * and updating each one when a new line is started. */ screen_start.line = Currline; screen_start.chrctr = Ftell(f); } }
/* * Search for nth occurrence of regular expression contained in buf in the file */ int search(char *buf, FILE *file, int n) { off_t startline = Ftell(file); off_t line1 = startline; off_t line2 = startline; off_t line3 = startline; off_t saveln; int lncount, rv; char ebuf[BUFSIZ]; static regex_t reg; static int initialized; context.line = saveln = Currline; context.chrctr = startline; lncount = 0; if (buf != NULL && *buf != '\0') { if ((rv = regcomp(®, buf, REG_NOSUB)) != 0) { initialized = 0; regerror(rv, ®, ebuf, sizeof(ebuf)); regfree(®); error(ebuf); return (-1); } initialized = 1; } else if (!initialized) { error("No previous regular expression"); return (-1); } while (!feof(file)) { line3 = line2; line2 = line1; line1 = Ftell(file); rdline(file); lncount++; if ((rv = regexec(®, Line, 0, NULL, 0)) == 0) { if (--n == 0) { if (lncount > 3 || (lncount > 1 && no_intty)) { putchar('\n'); if (clreol) cleareol(); fputs("...skipping\n", stdout); } if (!no_intty) { Currline -= (lncount >= 3 ? 3 : lncount); Fseek(file, line3); if (noscroll) { if (clreol) { home(); cleareol(); } else doclear(); } } else { kill_line(); if (noscroll) { if (clreol) { home(); cleareol(); } else doclear(); } fputs(Line, stdout); putchar('\n'); } break; } } else if (rv != REG_NOMATCH) { regerror(rv, ®, ebuf, sizeof(ebuf)); error(ebuf); return (-1); } } if (feof(file)) { if (!no_intty) { Currline = saveln; Fseek(file, startline); } else { fputs("\nPattern not found\n", stdout); end_it(); } error("Pattern not found"); return (-1); } return (0); }
/** \ingroup rpmcli * Create/modify elements in signature header. * @param rpm path to package * @param deleting adding or deleting signature? * @param signfiles sign files if non-zero * @return 0 on success, -1 on error */ static int rpmSign(const char *rpm, int deleting, int signfiles) { FD_t fd = NULL; FD_t ofd = NULL; char *trpm = NULL; Header sigh = NULL; Header h = NULL; char *msg = NULL; int res = -1; /* assume failure */ rpmRC rc; struct rpmtd_s utd; off_t headerStart; off_t sigStart; struct sigTarget_s sigt_v3; struct sigTarget_s sigt_v4; unsigned int origSigSize; int insSig = 0; fprintf(stdout, "%s:\n", rpm); if (manageFile(&fd, rpm, O_RDWR)) goto exit; if ((rc = rpmLeadRead(fd, &msg)) != RPMRC_OK) { rpmlog(RPMLOG_ERR, "%s: %s\n", rpm, msg); goto exit; } sigStart = Ftell(fd); rc = rpmReadSignature(fd, &sigh, &msg); if (rc != RPMRC_OK) { rpmlog(RPMLOG_ERR, _("%s: rpmReadSignature failed: %s"), rpm, (msg && *msg ? msg : "\n")); goto exit; } headerStart = Ftell(fd); if (rpmReadHeader(NULL, fd, &h, &msg) != RPMRC_OK) { rpmlog(RPMLOG_ERR, _("%s: headerRead failed: %s\n"), rpm, msg); goto exit; } if (!headerIsEntry(h, RPMTAG_HEADERIMMUTABLE)) { rpmlog(RPMLOG_ERR, _("Cannot sign RPM v3 packages\n")); goto exit; } unloadImmutableRegion(&sigh, RPMTAG_HEADERSIGNATURES); origSigSize = headerSizeof(sigh, HEADER_MAGIC_YES); if (signfiles) { if (includeFileSignatures(&sigh, &h)) goto exit; } if (deleting) { /* Nuke all the signature tags. */ deleteSigs(sigh); } else { /* Signature target containing header + payload */ sigt_v3.fd = fd; sigt_v3.start = headerStart; sigt_v3.fileName = rpm; sigt_v3.size = fdSize(fd) - headerStart; /* Signature target containing only header */ sigt_v4 = sigt_v3; sigt_v4.size = headerSizeof(h, HEADER_MAGIC_YES); res = replaceSignature(sigh, &sigt_v3, &sigt_v4); if (res != 0) { if (res == 1) { rpmlog(RPMLOG_WARNING, _("%s already contains identical signature, skipping\n"), rpm); /* Identical signature is not an error */ res = 0; } goto exit; } res = -1; } /* Try to make new signature smaller to have size of original signature */ rpmtdReset(&utd); if (headerGet(sigh, RPMSIGTAG_RESERVEDSPACE, &utd, HEADERGET_MINMEM)) { int diff; int count; char *reservedSpace = NULL; count = utd.count; diff = headerSizeof(sigh, HEADER_MAGIC_YES) - origSigSize; if (diff < count) { reservedSpace = xcalloc(count - diff, sizeof(char)); headerDel(sigh, RPMSIGTAG_RESERVEDSPACE); rpmtdReset(&utd); utd.tag = RPMSIGTAG_RESERVEDSPACE; utd.count = count - diff; utd.type = RPM_BIN_TYPE; utd.data = reservedSpace; headerPut(sigh, &utd, HEADERPUT_DEFAULT); free(reservedSpace); insSig = 1; } } /* Reallocate the signature into one contiguous region. */ sigh = headerReload(sigh, RPMTAG_HEADERSIGNATURES); if (sigh == NULL) /* XXX can't happen */ goto exit; if (insSig) { /* Insert new signature into original rpm */ if (Fseek(fd, sigStart, SEEK_SET) < 0) { rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"), rpm, Fstrerror(fd)); goto exit; } if (rpmWriteSignature(fd, sigh)) { rpmlog(RPMLOG_ERR, _("%s: rpmWriteSignature failed: %s\n"), rpm, Fstrerror(fd)); goto exit; } res = 0; } else { /* Replace orignal rpm with new rpm containing new signature */ rasprintf(&trpm, "%s.XXXXXX", rpm); ofd = rpmMkTemp(trpm); if (ofd == NULL || Ferror(ofd)) { rpmlog(RPMLOG_ERR, _("rpmMkTemp failed\n")); goto exit; } /* Write the lead/signature of the output rpm */ rc = rpmLeadWrite(ofd, h); if (rc != RPMRC_OK) { rpmlog(RPMLOG_ERR, _("%s: writeLead failed: %s\n"), trpm, Fstrerror(ofd)); goto exit; } if (rpmWriteSignature(ofd, sigh)) { rpmlog(RPMLOG_ERR, _("%s: rpmWriteSignature failed: %s\n"), trpm, Fstrerror(ofd)); goto exit; } if (Fseek(fd, headerStart, SEEK_SET) < 0) { rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"), rpm, Fstrerror(fd)); goto exit; } /* Append the header and archive from the temp file */ if (copyFile(&fd, rpm, &ofd, trpm) == 0) { struct stat st; /* Move final target into place, restore file permissions. */ if (stat(rpm, &st) == 0 && unlink(rpm) == 0 && rename(trpm, rpm) == 0 && chmod(rpm, st.st_mode) == 0) { res = 0; } else { rpmlog(RPMLOG_ERR, _("replacing %s failed: %s\n"), rpm, strerror(errno)); } } } exit: if (fd) (void) closeFile(&fd); if (ofd) (void) closeFile(&ofd); headerFree(sigh); headerFree(h); free(msg); /* Clean up intermediate target */ if (trpm) { (void) unlink(trpm); free(trpm); } return res; }
LONG _reentrant ftell(INT Handle) { return Ftell(Handle); }
/* * This is more than just a little insane: * In order to write the signature, we need to know the size and * the size and digests of the header and payload, which are located * after the signature on disk. We also need a digest of the compressed * payload for the main header, and of course the payload is after the * header on disk. So we need to create placeholders for both the * signature and main header that exactly match the final sizes, calculate * the payload digest, then generate and write the real main header to * be able to FINALLY calculate the digests we need for the signature * header. In other words, we need to write things in the exact opposite * order to how the RPM format is laid on disk. */ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp, const char *fileName, char **cookie) { FD_t fd = NULL; char * rpmio_flags = NULL; char * SHA1 = NULL; char * SHA256 = NULL; uint8_t * MD5 = NULL; char * pld = NULL; uint32_t pld_algo = PGPHASHALGO_SHA256; /* TODO: macro configuration */ rpmRC rc = RPMRC_FAIL; /* assume failure */ rpm_loff_t archiveSize = 0; off_t sigStart, hdrStart, payloadStart, payloadEnd; if (pkgidp) *pkgidp = NULL; rpmio_flags = getIOFlags(pkg); if (!rpmio_flags) goto exit; finalizeDeps(pkg); /* Create and add the cookie */ if (cookie) { rasprintf(cookie, "%s %d", buildHost(), (int) (*getBuildTime())); headerPutString(pkg->header, RPMTAG_COOKIE, *cookie); } /* Create a dummy payload digest to get the header size right */ pld = nullDigest(pld_algo, 1); headerPutUint32(pkg->header, RPMTAG_PAYLOADDIGESTALGO, &pld_algo, 1); headerPutString(pkg->header, RPMTAG_PAYLOADDIGEST, pld); pld = _free(pld); /* Check for UTF-8 encoding of string tags, add encoding tag if all good */ if (checkForEncoding(pkg->header, 1)) goto exit; /* Open the output file */ fd = Fopen(fileName, "w+.ufdio"); if (fd == NULL || Ferror(fd)) { rpmlog(RPMLOG_ERR, _("Could not open %s: %s\n"), fileName, Fstrerror(fd)); goto exit; } /* Write the lead section into the package. */ if (rpmLeadWrite(fd, pkg->header)) { rpmlog(RPMLOG_ERR, _("Unable to write package: %s\n"), Fstrerror(fd)); goto exit; } /* Save the position of signature section */ sigStart = Ftell(fd); /* Generate and write a placeholder signature header */ SHA1 = nullDigest(PGPHASHALGO_SHA1, 1); SHA256 = nullDigest(PGPHASHALGO_SHA256, 1); MD5 = nullDigest(PGPHASHALGO_MD5, 0); if (rpmGenerateSignature(SHA256, SHA1, MD5, 0, 0, fd)) goto exit; SHA1 = _free(SHA1); SHA256 = _free(SHA256); MD5 = _free(MD5); /* Write a placeholder header. */ hdrStart = Ftell(fd); if (writeHdr(fd, pkg->header)) goto exit; /* Write payload section (cpio archive) */ payloadStart = Ftell(fd); if (cpio_doio(fd, pkg, rpmio_flags, &archiveSize)) goto exit; payloadEnd = Ftell(fd); /* Re-read payload to calculate compressed digest */ fdInitDigestID(fd, pld_algo, RPMTAG_PAYLOADDIGEST, 0); if (fdConsume(fd, payloadStart, payloadEnd - payloadStart)) goto exit; fdFiniDigest(fd, RPMTAG_PAYLOADDIGEST, (void **)&pld, NULL, 1); /* Insert the payload digest in main header */ headerDel(pkg->header, RPMTAG_PAYLOADDIGEST); headerPutString(pkg->header, RPMTAG_PAYLOADDIGEST, pld); pld = _free(pld); /* Write the final header */ if (fdJump(fd, hdrStart)) goto exit; if (writeHdr(fd, pkg->header)) goto exit; /* Calculate digests: SHA on header, legacy MD5 on header + payload */ fdInitDigestID(fd, PGPHASHALGO_MD5, RPMTAG_SIGMD5, 0); fdInitDigestID(fd, PGPHASHALGO_SHA1, RPMTAG_SHA1HEADER, 0); fdInitDigestID(fd, PGPHASHALGO_SHA256, RPMTAG_SHA256HEADER, 0); if (fdConsume(fd, hdrStart, payloadStart - hdrStart)) goto exit; fdFiniDigest(fd, RPMTAG_SHA1HEADER, (void **)&SHA1, NULL, 1); fdFiniDigest(fd, RPMTAG_SHA256HEADER, (void **)&SHA256, NULL, 1); if (fdConsume(fd, 0, payloadEnd - payloadStart)) goto exit; fdFiniDigest(fd, RPMTAG_SIGMD5, (void **)&MD5, NULL, 0); if (fdJump(fd, sigStart)) goto exit; /* Generate the signature. Now with right values */ if (rpmGenerateSignature(SHA256, SHA1, MD5, payloadEnd - hdrStart, archiveSize, fd)) goto exit; rc = RPMRC_OK; exit: free(rpmio_flags); free(SHA1); free(SHA256); /* XXX Fish the pkgid out of the signature header. */ if (pkgidp != NULL) { if (MD5 != NULL) { *pkgidp = MD5; } } else { free(MD5); } Fclose(fd); if (rc == RPMRC_OK) rpmlog(RPMLOG_NOTICE, _("Wrote: %s\n"), fileName); else (void) unlink(fileName); return rc; }
bool textSource::segment(int level ,int sstatus ,bool PrevIsField // True if previous sibling block contains a \field ,charprops CharProps ) { wint_t ch; curr_pos = Ftell(sourceFile);// After parsing a html-tag, seeking to curr_pos brings you back to the position where the parsed sequence started. if(Option.keepEOLsequence) { copyEOLsequence(); // SourceFile is rewinded } do { ch = Getc(sourceFile); end_offset = Ftell(sourceFile); if(curr_pos >= tagendpos) { // We are not inside an HTML-tag. if(flgs.inhtmltag) { flgs.firstafterhtmltag = true; flgs.inhtmltag = false; } // Check whether a well-formed HTML tag is ahead. Returns sourceFile // in same file position. flgs.htmltagcoming = isHTMLtagComing(ch); // assert(new_pos == Ftell(sourceFile)); assert(end_offset == Ftell(sourceFile)); } else if(flgs.htmltagcoming) { // We are leaving an HTML-tag and entering a new one. flgs.inhtmltag = true; flgs.htmltagcoming = false; } /* Scan in advance, checking whether the line to come is a heading and therefore must be preceded with a newline (WritePar will then be set to true.) */ if( ch == '\n' || ch == '\r' || ch == WEOF || ch == 26 ) { flgs.in_fileName = false; heading = isHeading(firsttext,ch,WriteParAfterHeadingOrField); if(!skipSegmentation(firsttext,ch)) { doTheSegmentation(CharProps,true,false); // Bart 20040120. true because: Suppose that end of line is end of segment if(!WriteParAfterHeadingOrField && heading) {// A normal line after a heading has WritePar==false and heading==true WriteParAfterHeadingOrField = true; heading = false; } } if(firsttext.EOL) firsttext.b.LS = 1; } else { updateFlags(ch,flgs); int EOL = firsttext.EOL; bool sentenceEnd = checkSentenceStartDueToBullet(ch); if( sentenceEnd || flgs.htmltagcoming || flgs.inhtmltag || (end_offset - begin_offset > MAXSEGMENTLENGTH && isSpace(ch)) // check for buffer overflow ) { doTheSegmentation(CharProps,false,false); firsttext.b.SD = 1; firsttext.b.LS = 0; } if(isSpace(ch)) { if(EOL) firsttext.b.LS = 1; } else { firsttext.b.LS = 0; firsttext.EOL = 0; // resets SD, CR and LF } } curr_pos = end_offset; } while(ch != WEOF && ch != 26); outputtext->PutHandlingLine('\n',flgs); // 20100106 Flush last line return false; }
int _reentrant OpenSMVFile(int aa, int b, int *pPtr) { void _Y * pBuffer = (WORD *) &g_wUserScratchY; _packed char szFilename[MAX_FILENAME_LENGTH]; SONGFILEINFO SongInfo; int a, rtn = MVIDEO_ERROR; DWORD dwValue; aa;b;pPtr; if(stc_iHandle == -1) { SongInfo.m_wBufferLength = MAX_FILENAME_LENGTH; SongInfo.m_pFilename = (_packed BYTE*)szFilename; #ifndef USE_PLAYLIST3 if( SysCallFunction(RSRC_PLAYLIST_CODEBANK,Playlist_GetCurrentSongFileInfo, 0, 0, (INT*)&SongInfo ) == PLAYLIST_SUCCESS ) #else if(JpegFile_GetCurrentSongFileInfo(0,0,(INT*)&SongInfo) == PLAYLIST_SUCCESS) #endif { //open smw file #ifdef USE_PLAYLIST5 g_CurrentFastKey = ((g_PL5_Playback.queue)->pos + g_PL5_Playback.currentplay)->file.lFastKey; stc_iHandle = FSFastOpen(g_CurrentFastKey, READ); if(stc_iHandle < 0) #else if((stc_iHandle = Fopen( szFilename, (_packed char *)"r" )) < 0) #endif { stc_iHandle = -1; return(rtn); } // read RIFF trunk Fread( stc_iHandle, (void*)pBuffer, 8, DEFAULT_MEMORY, (INT)-1 ); dwValue = 0; for( a = 7; a > 3; a-- ) dwValue = (dwValue << 8 ) + GetByteFromArrayInY( pBuffer, a ); //skip wave audio part if(Fseek( stc_iHandle, dwValue, SEEK_CUR ) < 0) { Fclose( stc_iHandle ); stc_iHandle = -1; return(rtn); } //extract motion video graphic header Fread( stc_iHandle, (void*)pBuffer, (16*3)+3, DEFAULT_MEMORY, (INT)-1 ); stc_iByteinJpegBlock = 0; for( a = 23; a > 20; a-- ) stc_iByteinJpegBlock = (stc_iByteinJpegBlock << 8) + GetByteFromArrayInY( pBuffer, a ); stc_iVideoWidth = GetByteFromArrayInY( pBuffer, 9 ); stc_iVideoHeight = GetByteFromArrayInY( pBuffer, 12 ); if(stc_iVideoHeight & 0x0F) stc_iFrameHeight = (stc_iVideoHeight + 16) - (stc_iVideoHeight % 16); else stc_iFrameHeight = stc_iVideoHeight; stc_iFramePerSec = GetByteFromArrayInY( pBuffer, 24 ); stc_iFrameDuration = (DWORD)1000000 / (DWORD)stc_iFramePerSec; // Use us for handling non-integer FrameDuration stc_dwTotalFrame = 0; for( a = 29; a > 26; a-- ) stc_dwTotalFrame = (stc_dwTotalFrame << 8) + GetByteFromArrayInY( pBuffer, a ); stc_dwTotalFrameBackup = stc_dwTotalFrame; stc_iFrameDrop = stc_iFrameDuration * 3 / 2; stc_iFrameInJpegBlock = 0; for( a = 38; a > 35; a-- ) stc_iFrameInJpegBlock = (stc_iFrameInJpegBlock << 8) + GetByteFromArrayInY( pBuffer, a ); stc_iDurationInJpegBlock = stc_iFrameDuration * stc_iFrameInJpegBlock; //the beginning of the first Jpeg block for frame data stc_dwVideoStart = Ftell(stc_iHandle); rtn = MVIDEO_SUCCESS; } } return(rtn); }
static rpmRC includeFileSignatures(FD_t fd, const char *rpm, Header *sigp, Header *hdrp, off_t sigStart, off_t headerStart) { FD_t ofd = NULL; char *trpm = NULL; char *key; char *keypass; char *SHA1 = NULL; uint8_t *MD5 = NULL; size_t sha1len; size_t md5len; off_t sigTargetSize; rpmRC rc = RPMRC_OK; struct rpmtd_s osigtd; char *o_sha1 = NULL; uint8_t o_md5[16]; #ifndef WITH_IMAEVM rpmlog(RPMLOG_ERR, _("missing libimaevm\n")); return RPMRC_FAIL; #endif unloadImmutableRegion(hdrp, RPMTAG_HEADERIMMUTABLE); key = rpmExpand("%{?_file_signing_key}", NULL); keypass = rpmExpand("%{_file_signing_key_password}", NULL); if (rstreq(keypass, "")) { free(keypass); keypass = NULL; } rc = rpmSignFiles(*hdrp, key, keypass); if (rc != RPMRC_OK) { goto exit; } *hdrp = headerReload(*hdrp, RPMTAG_HEADERIMMUTABLE); if (*hdrp == NULL) { rc = RPMRC_FAIL; rpmlog(RPMLOG_ERR, _("headerReload failed\n")); goto exit; } ofd = rpmMkTempFile(NULL, &trpm); if (ofd == NULL || Ferror(ofd)) { rc = RPMRC_FAIL; rpmlog(RPMLOG_ERR, _("rpmMkTemp failed\n")); goto exit; } /* Copy archive to temp file */ if (copyFile(&fd, rpm, &ofd, trpm)) { rc = RPMRC_FAIL; rpmlog(RPMLOG_ERR, _("copyFile failed\n")); goto exit; } if (Fseek(fd, headerStart, SEEK_SET) < 0) { rc = RPMRC_FAIL; rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"), rpm, Fstrerror(fd)); goto exit; } /* Start MD5 calculation */ fdInitDigest(fd, PGPHASHALGO_MD5, 0); /* Write header to rpm and recalculate SHA1 */ fdInitDigest(fd, PGPHASHALGO_SHA1, 0); rc = headerWrite(fd, *hdrp, HEADER_MAGIC_YES); if (rc != RPMRC_OK) { rpmlog(RPMLOG_ERR, _("headerWrite failed\n")); goto exit; } fdFiniDigest(fd, PGPHASHALGO_SHA1, (void **)&SHA1, &sha1len, 1); /* Copy archive from temp file */ if (Fseek(ofd, 0, SEEK_SET) < 0) { rc = RPMRC_FAIL; rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"), rpm, Fstrerror(fd)); goto exit; } if (copyFile(&ofd, trpm, &fd, rpm)) { rc = RPMRC_FAIL; rpmlog(RPMLOG_ERR, _("copyFile failed\n")); goto exit; } unlink(trpm); sigTargetSize = Ftell(fd) - headerStart; fdFiniDigest(fd, PGPHASHALGO_MD5, (void **)&MD5, &md5len, 0); if (headerGet(*sigp, RPMSIGTAG_MD5, &osigtd, HEADERGET_DEFAULT)) { memcpy(o_md5, osigtd.data, 16); rpmtdFreeData(&osigtd); } if (headerGet(*sigp, RPMSIGTAG_SHA1, &osigtd, HEADERGET_DEFAULT)) { o_sha1 = xstrdup(osigtd.data); rpmtdFreeData(&osigtd); } if (memcmp(MD5, o_md5, md5len) == 0 && strcmp(SHA1, o_sha1) == 0) rpmlog(RPMLOG_WARNING, _("%s already contains identical file signatures\n"), rpm); else replaceSigDigests(fd, rpm, sigp, sigStart, sigTargetSize, SHA1, MD5); exit: free(trpm); free(MD5); free(SHA1); free(o_sha1); free(keypass); free(key); if (ofd) (void) closeFile(&ofd); return rc; }
/* Get a logical line */ static int get_line(register FILE *f, int *length) { int c; char *p; int column; static int colflg; #ifdef HAVE_WIDECHAR size_t i; wchar_t wc; int wc_width; mbstate_t state, state_bak; /* Current status of the stream. */ char mbc[MB_LEN_MAX]; /* Buffer for one multibyte char. */ size_t mblength; /* Byte length of multibyte char. */ size_t mbc_pos = 0; /* Position of the MBC. */ int use_mbc_buffer_flag = 0; /* If 1, mbc has data. */ int break_flag = 0; /* If 1, exit while(). */ long file_pos_bak = Ftell(f); memset(&state, '\0', sizeof(mbstate_t)); #endif prepare_line_buffer(); p = Line; column = 0; c = Getc(f); if (colflg && c == '\n') { Currline++; c = Getc(f); } while (p < &Line[LineLen - 1]) { #ifdef HAVE_WIDECHAR if (fold_opt && use_mbc_buffer_flag && MB_CUR_MAX > 1) { use_mbc_buffer_flag = 0; state_bak = state; mbc[mbc_pos++] = c; process_mbc: mblength = mbrtowc(&wc, mbc, mbc_pos, &state); switch (mblength) { case (size_t)-2: /* Incomplete multibyte character. */ use_mbc_buffer_flag = 1; state = state_bak; break; case (size_t)-1: /* Invalid as a multibyte character. */ *p++ = mbc[0]; state = state_bak; column++; file_pos_bak++; if (column >= Mcol) { Fseek(f, file_pos_bak); } else { memmove(mbc, mbc + 1, --mbc_pos); if (mbc_pos > 0) { mbc[mbc_pos] = '\0'; goto process_mbc; } } break; default: wc_width = wcwidth(wc); if (column + wc_width > Mcol) { Fseek(f, file_pos_bak); break_flag = 1; } else { for (i = 0; p < &Line[LineLen - 1] && i < mbc_pos; i++) *p++ = mbc[i]; if (wc_width > 0) column += wc_width; } } if (break_flag || column >= Mcol) break; c = Getc(f); continue; } #endif /* HAVE_WIDECHAR */ if (c == EOF) { if (p > Line) { *p = '\0'; *length = p - Line; return (column); } *length = p - Line; return (EOF); } if (c == '\n') { Currline++; break; } *p++ = c; #if 0 if (c == '\033') { /* ESC */ c = Getc(f); while (c > ' ' && c < '0' && p < &Line[LineLen - 1]) { *p++ = c; c = Getc(f); } if (c >= '0' && c < '\177' && p < &Line[LineLen - 1]) { *p++ = c; c = Getc(f); continue; } } #endif /* 0 */ if (c == '\t') { if (!hardtabs || (column < promptlen && !hard)) { if (hardtabs && eraseln && !dumb) { column = 1 + (column | 7); putstring(eraseln); promptlen = 0; } else { for (--p; p < &Line[LineLen - 1];) { *p++ = ' '; if ((++column & 7) == 0) break; } if (column >= promptlen) promptlen = 0; } } else column = 1 + (column | 7); } else if (c == '\b' && column > 0) { column--; } else if (c == '\r') { int next = Getc(f); if (next == '\n') { p--; Currline++; break; } Ungetc(next, f); column = 0; } else if (c == '\f' && stop_opt) { p[-1] = '^'; *p++ = 'L'; column += 2; Pause++; } else if (c == EOF) { *length = p - Line; return (column); } else { #ifdef HAVE_WIDECHAR if (fold_opt && MB_CUR_MAX > 1) { memset(mbc, '\0', MB_LEN_MAX); mbc_pos = 0; mbc[mbc_pos++] = c; state_bak = state; mblength = mbrtowc(&wc, mbc, mbc_pos, &state); /* The value of mblength is always less than 2 here. */ switch (mblength) { case (size_t)-2: p--; file_pos_bak = Ftell(f) - 1; state = state_bak; use_mbc_buffer_flag = 1; break; case (size_t)-1: state = state_bak; column++; break; default: wc_width = wcwidth(wc); if (wc_width > 0) column += wc_width; } } else #endif /* HAVE_WIDECHAR */ { if (isprint(c)) column++; } } if (column >= Mcol && fold_opt) break; #ifdef HAVE_WIDECHAR if (use_mbc_buffer_flag == 0 && p >= &Line[LineLen - 1 - 4]) /* don't read another char if there is no space for * whole multibyte sequence */ break; #endif c = Getc(f); } if (column >= Mcol && Mcol > 0) { if (!Wrap) { *p++ = '\n'; } } colflg = column == Mcol && fold_opt; if (colflg && eatnl && Wrap) { *p++ = '\n'; /* simulate normal wrap */ } *length = p - Line; *p = 0; return (column); }