int
keyring_insert_keyblock (KEYRING_HANDLE hd, KBNODE kb)
{
    int rc;
    const char *fname;

    if (!hd)
        fname = NULL;
    else if (hd->found.kr)
        fname = hd->found.kr->fname;
    else if (hd->current.kr)
        fname = hd->current.kr->fname;
    else 
        fname = hd->resource? hd->resource->fname:NULL;

    if (!fname)
        return G10ERR_GENERAL; 

    /* close this one otherwise we will lose the position for
     * a next search.  Fixme: it would be better to adjust the position
     * after the write opertions.
     */
    iobuf_close (hd->current.iobuf);
    hd->current.iobuf = NULL;

    /* do the insert */
    rc = do_copy (1, fname, kb, hd->secret, 0, 0 );
    if (!rc && !hd->secret && kr_offtbl)
      {
        update_offset_hash_table_from_kb (kr_offtbl, kb, 0);
      }
      
    return rc;
}
Beispiel #2
0
int
keyring_insert_keyblock (KEYRING_HANDLE hd, KBNODE kb)
{
	printf("starting keyring_insert_keyblock\n" );
    int rc;
    const char *fname;

    if (!hd)
        fname = NULL;
    else if (hd->found.kr)
      {
        fname = hd->found.kr->fname;
        if (hd->found.kr->readonly)
          return gpg_error (GPG_ERR_EACCES);
      }
    else if (hd->current.kr)
      {
        fname = hd->current.kr->fname;
        if (hd->current.kr->readonly)
          return gpg_error (GPG_ERR_EACCES);
      }
    else
        fname = hd->resource? hd->resource->fname:NULL;

    if (!fname)
        return G10ERR_GENERAL;

    /* Close this one otherwise we will lose the position for
     * a next search.  Fixme: it would be better to adjust the position
     * after the write opertions.
     */
    iobuf_close (hd->current.iobuf);
    hd->current.iobuf = NULL;
    printf("before do copy\n");
    /* do the insert */
    rc = do_copy (1, fname, kb, hd->secret, 0, 0 );
    printf("after do copy\n");
    if (!rc && !hd->secret && kr_offtbl)
      {
        update_offset_hash_table_from_kb (kr_offtbl, kb, 0);
      }
	printf("finish keyring_insert_keyblock\n" );
    return rc;
}
Beispiel #3
0
int
keyring_update_keyblock (KEYRING_HANDLE hd, KBNODE kb)
{
    int rc;

    if (!hd->found.kr)
        return -1; /* no successful prior search */

    if (hd->found.kr->readonly)
      return gpg_error (GPG_ERR_EACCES);

    if (!hd->found.n_packets) {
        /* need to know the number of packets - do a dummy get_keyblock*/
        rc = keyring_get_keyblock (hd, NULL);
        if (rc) {
            log_error ("re-reading keyblock failed: %s\n", g10_errstr (rc));
            return rc;
        }
        if (!hd->found.n_packets)
            BUG ();
    }

    /* The open iobuf isn't needed anymore and in fact is a problem when
       it comes to renaming the keyring files on some operating systems,
       so close it here */
    iobuf_close(hd->current.iobuf);
    hd->current.iobuf = NULL;

    /* do the update */
    rc = do_copy (3, hd->found.kr->fname, kb, hd->secret,
                  hd->found.offset, hd->found.n_packets );
    if (!rc) {
      if (!hd->secret && kr_offtbl)
        {
          update_offset_hash_table_from_kb (kr_offtbl, kb, 0);
        }
      /* better reset the found info */
      hd->found.kr = NULL;
      hd->found.offset = 0;
    }
    return rc;
}