diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2007-12-10 15:05:26 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2007-12-10 15:05:26 +0000 |
commit | dbcb537597b881246ac37f4a70de371d3ccda614 (patch) | |
tree | 4b1cc198a4d18c004f7af9d5390ea71c693ddcb0 /URPM.xs | |
parent | 54e360b2cfa968b21527f534dac595a356130a4a (diff) | |
download | perl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.tar perl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.tar.gz perl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.tar.bz2 perl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.tar.xz perl-URPM-dbcb537597b881246ac37f4a70de371d3ccda614.zip |
- replace ->import_needed_pubkeys and ->import_pubkey in favor of
import_needed_pubkeys_from_file() and ->import_pubkey_file
(! this breaks API !)
- import_pubkey is dropped because it messes to much with rpmlib internals,
whereas import_pubkey_file is plain simple
- in Signature.pm, dropping compare_pubkeys() options
(since they are not used anymore)
- import_needed_pubkeys_from_file() may not do a clean job if the pubkey file
contains more than one pubkey.
Diffstat (limited to 'URPM.xs')
-rw-r--r-- | URPM.xs | 219 |
1 files changed, 30 insertions, 189 deletions
@@ -128,11 +128,9 @@ typedef struct s_Package* URPM__Package; static ssize_t write_nocheck(int fd, const void *buf, size_t count) { return write(fd, buf, count); } -#ifdef RPM_ORG static const void* unused_variable(const void *p) { return p; } -#endif static int rpmError_callback_data; void rpmError_callback() { @@ -142,10 +140,6 @@ void rpmError_callback() { write_nocheck(rpmError_callback_data, rpmlogMessage(), strlen(rpmlogMessage())); } -/* needed for importing keys (from rpmio) */ -int rpmioSlurp(const char * fn, const byte ** bp, ssize_t * blenp); -int b64decode (const char * s, void ** datap, size_t *lenp); - static int rpm_codeset_is_utf8 = 0; static SV* @@ -3674,193 +3668,40 @@ Urpm_verify_signature(filename) OUTPUT: RETVAL + int -Urpm_import_pubkey(...) - PREINIT: - int i; - URPM__DB db = NULL; - char *root = "/"; - STRLEN block_len = 0; - char *block = NULL; - STRLEN filename_len = 0; - char *filename = NULL; - rpmts ts; - const unsigned char *pkt = NULL; - ssize_t pktlen = 0; - const byte * b = NULL; - ssize_t blen; - int rc; - CODE: - for (i = 0; i < items-1; i+=2) { - STRLEN len; - char *s = SvPV(ST(i), len); +Urpm_import_pubkey_file(db, filename) + URPM::DB db + char * filename + PREINIT: + const byte * pkt = NULL; + size_t pktlen = 0; + int rc; + CODE: - if (len == 2 && !memcmp(s, "db", 2)) { - if (sv_derived_from(ST(i+1), "URPM::DB")) { - IV tmp = SvIV((SV*)SvRV(ST(i+1))); - db = INT2PTR(URPM__DB, tmp); - } - } else if (len == 4) { - if (!memcmp(s, "root", 4)) - root = SvPV_nolen(ST(i+1)); - } else if (len == 5) { - if (!memcmp(s, "block", 5)) - block = SvPV(ST(i+1), block_len); - } else if (len == 8) { - if (!memcmp(s, "filename", 8)) - filename = SvPV(ST(i+1), filename_len); - } - } - RETVAL = 1; - /* get transaction for importing keys, open rpmdb in write mode */ - if (db) { - ts = db->ts = rpmtsLink(db->ts, "URPM::import_pubkey"); - } else { - /* compabilty mode to use rpmdb installed on / */ - ts = rpmtsCreate(); - read_config_files(0); - rpmtsSetRootDir(ts, root); - rpmtsOpenDB(ts, O_RDWR | O_CREAT); - } - rpmtsClean(ts); - /* from pgpReadPkts the filename should be slurped directly in memory */ - if (filename) { - rc = rpmioSlurp(filename, &b, &blen); - } else if (block) { - blen = block_len; - b = memcpy(malloc(blen+1), block, blen+1); /* XXX should use xmalloc instead */ - rc = 0; - } else { - rc = 0; - } - if (rc || b == NULL || blen <= 0) { - /* error reading file, or no file or block */ - RETVAL = 0; - } else { - /* from pgpReadPkts the remaining of method */ - const char * enc = NULL; - const char * crcenc = NULL; - byte * dec; - byte * crcdec; - size_t declen; - size_t crclen; - u_int32_t crcpkt, crc; - const char * armortype = NULL; - char * t, * te; - int pstate = 0; - int _rc; - - rc = PGPARMOR_ERROR; /* XXX assume failure */ - - if (pgpIsPkt(b)) { -#ifdef NOTYET /* XXX ASCII Pubkeys only, please. */ - rc = 0; /* XXX fish out pkt type. */ -#endif - goto exit; - } -#define TOKEQ(_s, _tok) (!strncmp((_s), (_tok), sizeof(_tok)-1)) - for (t = (char *)b; t && *t; t = te) { - if ((te = strchr(t, '\n')) == NULL) - te = t + strlen(t); - else - te++; - - switch (pstate) { - case 0: - armortype = NULL; - if (!TOKEQ(t, "-----BEGIN PGP ")) - continue; - t += sizeof("-----BEGIN PGP ")-1; - - _rc = pgpValTok(pgpArmorTbl, t, te); - if (_rc < 0) - goto exit; - if (_rc != PGPARMOR_PUBKEY) /* XXX ASCII Pubkeys only, please. */ - continue; - armortype = t; - - t = te - (sizeof("-----\n")-1); - if (!TOKEQ(t, "-----\n")) - continue; - *t = '\0'; - pstate++; - /*@switchbreak@*/ break; - case 1: - enc = NULL; - _rc = pgpValTok(pgpArmorKeyTbl, t, te); - if (_rc >= 0) - continue; - if (*t != '\n') { - pstate = 0; - continue; - } - enc = te; /* Start of encoded packets */ - pstate++; - /*@switchbreak@*/ break; - case 2: - crcenc = NULL; - if (*t != '=') - continue; - *t++ = '\0'; /* Terminate encoded packets */ - crcenc = t; /* Start of encoded crc */ - pstate++; - /*@switchbreak@*/ break; - case 3: - pstate = 0; - if (!TOKEQ(t, "-----END PGP ")) - goto exit; - *t = '\0'; /* Terminate encoded crc */ - t += sizeof("-----END PGP ")-1; - - if (armortype == NULL) /* XXX can't happen */ - continue; - _rc = strncmp(t, armortype, strlen(armortype)); - if (_rc) - continue; - - t = te - (sizeof("-----\n")-1); - if (!TOKEQ(t, "-----\n")) - goto exit; - - if (b64decode(crcenc, (void **)&crcdec, &crclen) != 0) - continue; - crcpkt = pgpGrab(crcdec, crclen); - crcdec = _free(crcdec); - if (b64decode(enc, (void **)&dec, &declen) != 0) - goto exit; - crc = pgpCRC(dec, declen); - if (crcpkt != crc) - goto exit; - b = _free(b); - b = dec; - blen = declen; - rc = PGPARMOR_PUBKEY; /* XXX ASCII Pubkeys only, please. */ - goto exit; - /*@notreached@*/ /*@switchbreak@*/ break; - } + rpmts ts = rpmtsLink(db->ts, "URPM::import_pubkey_file"); + rpmtsClean(ts); + + if ((rc = pgpReadPkts(filename, &pkt, &pktlen)) <= 0) { + RETVAL = 0; + } else if (rc != PGPARMOR_PUBKEY) { + RETVAL = 0; + } else if (rpmcliImportPubkey(ts, pkt, pktlen) != RPMRC_OK) { + RETVAL = 0; + } else { + RETVAL = 1; } - rc = PGPARMOR_NONE; + _free(pkt); + rpmtsFree(ts); + OUTPUT: + RETVAL - exit: - if (rc > PGPARMOR_NONE) - pkt = b; - else if (b != NULL) - b = _free(b); - pktlen = blen; - } - if (rc < 0) { - /* import read failed */ - RETVAL = 0; - } else if (rc != PGPARMOR_PUBKEY) { - /* not armored public key */ - RETVAL = 0; - } else if ((rc = rpmcliImportPubkey(ts, pkt, pktlen)) != 0) { - /* import failed */ - RETVAL = 0; - } - rpmtsClean(ts); - _free(pkt); - rpmtsFree(ts); +int +Urpm_import_pubkey(...) + CODE: + unused_variable(&items); + croak("import_pubkey() is dead. use import_pubkey_file() instead"); + RETVAL = 1; OUTPUT: RETVAL |