~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to sm/keydb.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * GnuPG is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * the Free Software Foundation; either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
11
 * GnuPG is distributed in the hope that it will be useful,
14
14
 * GNU General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
#include <config.h>
70
69
 
71
70
/*
72
71
 * Register a resource (which currently may only be a keybox file).
73
 
 * The first keybox which is added by this function is
74
 
 * created if it does not exist.
75
 
 * Note: this function may be called before secure memory is
76
 
 * available.
 
72
 * The first keybox which is added by this function is created if it
 
73
 * does not exist.  If AUTO_CREATED is not NULL it will be set to true
 
74
 * if the function has created a a new keybox. 
77
75
 */
78
76
int
79
 
keydb_add_resource (const char *url, int force, int secret)
 
77
keydb_add_resource (const char *url, int force, int secret, int *auto_created)
80
78
{
81
79
  static int any_secret, any_public;
82
80
  const char *resname = url;
86
84
  KeydbResourceType rt = KEYDB_RESOURCE_TYPE_NONE;
87
85
  const char *created_fname = NULL;
88
86
 
 
87
  if (auto_created)
 
88
    *auto_created = 0;
 
89
 
89
90
  /* Do we have an URL?
90
91
     gnupg-kbx:filename := this is a plain keybox
91
92
     filename := See what is is, but create as plain keybox.
194
195
          if (!opt.quiet)
195
196
            log_info (_("keybox `%s' created\n"), filename);
196
197
          created_fname = filename;
 
198
          if (auto_created)
 
199
            *auto_created = 1;
197
200
        }
198
201
        fclose (fp);
199
202
        fp = NULL;
696
699
  else
697
700
    return gpg_error (GPG_ERR_GENERAL);
698
701
 
699
 
  rc = lock_all (hd);
700
 
  if (rc)
701
 
    return rc;
 
702
  if (!hd->locked)
 
703
    return gpg_error (GPG_ERR_NOT_LOCKED);
702
704
 
703
705
  gpgsm_get_fingerprint (cert, GCRY_MD_SHA1, digest, NULL); /* kludge*/
704
706
 
718
720
 
719
721
 
720
722
 
721
 
/* update the current keyblock with KB */
 
723
/* Update the current keyblock with KB.  */
722
724
int
723
725
keydb_update_cert (KEYDB_HANDLE hd, ksba_cert_t cert)
724
726
{
759
761
 * The current keyblock or cert will be deleted.
760
762
 */
761
763
int
762
 
keydb_delete (KEYDB_HANDLE hd)
 
764
keydb_delete (KEYDB_HANDLE hd, int unlock)
763
765
{
764
766
  int rc = -1;
765
767
  
785
787
      break;
786
788
    }
787
789
 
788
 
  unlock_all (hd);
 
790
  if (unlock)
 
791
    unlock_all (hd);
789
792
  return rc;
790
793
}
791
794
 
1010
1013
 
1011
1014
 
1012
1015
static int
1013
 
hextobyte (const char *string)
1014
 
{
1015
 
  const unsigned char *s = (const unsigned char *)string;
1016
 
  int c;
1017
 
 
1018
 
  if( *s >= '0' && *s <= '9' )
1019
 
    c = 16 * (*s - '0');
1020
 
  else if ( *s >= 'A' && *s <= 'F' )
1021
 
    c = 16 * (10 + *s - 'A');
1022
 
  else if ( *s >= 'a' && *s <= 'f' )
1023
 
    c = 16 * (10 + *s - 'a');
1024
 
  else
1025
 
    return -1;
1026
 
  s++;
1027
 
  if ( *s >= '0' && *s <= '9' )
1028
 
    c += *s - '0';
1029
 
  else if ( *s >= 'A' && *s <= 'F' )
1030
 
    c += 10 + *s - 'A';
1031
 
  else if ( *s >= 'a' && *s <= 'f' )
1032
 
    c += 10 + *s - 'a';
1033
 
  else
1034
 
    return -1;
1035
 
  return c;
1036
 
}
1037
 
 
1038
 
 
1039
 
static int
1040
1016
classify_user_id (const char *name, 
1041
1017
                  KEYDB_SEARCH_DESC *desc,
1042
1018
                  int *force_exact )
1162
1138
        mode = KEYDB_SEARCH_MODE_FPR;
1163
1139
      } 
1164
1140
      break;
1165
 
           
 
1141
 
 
1142
    case '&': /* Keygrip*/
 
1143
      {  
 
1144
        if (hex2bin (s+1, desc->u.grip, 20) < 0)
 
1145
          return 0; /* Invalid. */
 
1146
        mode = KEYDB_SEARCH_MODE_KEYGRIP;
 
1147
      } 
 
1148
      break;
 
1149
 
1166
1150
    default:
1167
1151
      if (s[0] == '0' && s[1] == 'x')
1168
1152
        {
1337
1321
  if (ephemeral)
1338
1322
    keydb_set_ephemeral (kh, 1);
1339
1323
  
 
1324
  rc = lock_all (kh);
 
1325
  if (rc)
 
1326
    return rc;
 
1327
 
1340
1328
  rc = keydb_search_fpr (kh, fpr);
1341
1329
  if (rc != -1)
1342
1330
    {
1376
1364
   transaction by locating the certificate in the DB and updating the
1377
1365
   flags. */
1378
1366
gpg_error_t
1379
 
keydb_set_cert_flags (ksba_cert_t cert, int which, int idx, unsigned int value)
 
1367
keydb_set_cert_flags (ksba_cert_t cert, int ephemeral, 
 
1368
                      int which, int idx, 
 
1369
                      unsigned int mask, unsigned int value)
1380
1370
{
1381
1371
  KEYDB_HANDLE kh;
1382
1372
  gpg_error_t err;
1396
1386
      return gpg_error (GPG_ERR_ENOMEM);;
1397
1387
    }
1398
1388
 
 
1389
  if (ephemeral)
 
1390
    keydb_set_ephemeral (kh, 1);
 
1391
 
1399
1392
  err = keydb_lock (kh);
1400
1393
  if (err)
1401
1394
    {
1407
1400
  err = keydb_search_fpr (kh, fpr);
1408
1401
  if (err)
1409
1402
    {
1410
 
      log_error (_("problem re-searching certificate: %s\n"),
1411
 
                 gpg_strerror (err));
 
1403
      if (err == -1)
 
1404
        err = gpg_error (GPG_ERR_NOT_FOUND);
 
1405
      else
 
1406
        log_error (_("problem re-searching certificate: %s\n"),
 
1407
                   gpg_strerror (err));
1412
1408
      keydb_release (kh);
1413
1409
      return err;
1414
1410
    }
1420
1416
      keydb_release (kh);
1421
1417
      return err;
1422
1418
    }
 
1419
 
 
1420
  value = ((old_value & ~mask) | (value & mask));
 
1421
 
1423
1422
  if (value != old_value)
1424
1423
    {
1425
1424
      err = keydb_set_flags (kh, which, idx, value);
1430
1429
          return err;
1431
1430
        }
1432
1431
    }
 
1432
 
1433
1433
  keydb_release (kh);               
1434
1434
  return 0;
1435
1435
}
1438
1438
/* Reset all the certificate flags we have stored with the certificates
1439
1439
   for performance reasons. */
1440
1440
void
1441
 
keydb_clear_some_cert_flags (ctrl_t ctrl, STRLIST names)
 
1441
keydb_clear_some_cert_flags (ctrl_t ctrl, strlist_t names)
1442
1442
{
1443
1443
  gpg_error_t err;
1444
1444
  KEYDB_HANDLE hd = NULL;
1445
1445
  KEYDB_SEARCH_DESC *desc = NULL;
1446
1446
  int ndesc;
1447
 
  STRLIST sl;
 
1447
  strlist_t sl;
1448
1448
  int rc=0;
1449
1449
  unsigned int old_value, value;
1450
1450
  
1467
1467
  if (!ndesc)
1468
1468
    {
1469
1469
      log_error ("allocating memory failed: %s\n",
1470
 
                 gpg_strerror (OUT_OF_CORE (errno)));
 
1470
                 gpg_strerror (out_of_core ()));
1471
1471
      goto leave;
1472
1472
    }
1473
1473