*
* GnuPG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GnuPG is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
/*
* Register a resource (which currently may only be a keybox file).
- * The first keybox which is added by this function is
- * created if it does not exist.
- * Note: this function may be called before secure memory is
- * available.
+ * The first keybox which is added by this function is created if it
+ * does not exist. If AUTO_CREATED is not NULL it will be set to true
+ * if the function has created a a new keybox.
*/
int
-keydb_add_resource (const char *url, int force, int secret)
+keydb_add_resource (const char *url, int force, int secret, int *auto_created)
{
static int any_secret, any_public;
const char *resname = url;
KeydbResourceType rt = KEYDB_RESOURCE_TYPE_NONE;
const char *created_fname = NULL;
+ if (auto_created)
+ *auto_created = 0;
+
/* Do we have an URL?
gnupg-kbx:filename := this is a plain keybox
filename := See what is is, but create as plain keybox.
if (!opt.quiet)
log_info (_("keybox `%s' created\n"), filename);
created_fname = filename;
+ if (auto_created)
+ *auto_created = 1;
}
fclose (fp);
fp = NULL;
-/* update the current keyblock with KB */
+/* Update the current keyblock with KB. */
int
keydb_update_cert (KEYDB_HANDLE hd, ksba_cert_t cert)
{
mode = KEYDB_SEARCH_MODE_FPR;
}
break;
-
+
+ case '&': /* Keygrip*/
+ {
+ if (hex2bin (s+1, desc->u.grip, 20) < 0)
+ return 0; /* Invalid. */
+ mode = KEYDB_SEARCH_MODE_KEYGRIP;
+ }
+ break;
+
default:
if (s[0] == '0' && s[1] == 'x')
{
transaction by locating the certificate in the DB and updating the
flags. */
gpg_error_t
-keydb_set_cert_flags (ksba_cert_t cert, int which, int idx, unsigned int value)
+keydb_set_cert_flags (ksba_cert_t cert, int ephemeral,
+ int which, int idx,
+ unsigned int mask, unsigned int value)
{
KEYDB_HANDLE kh;
gpg_error_t err;
return gpg_error (GPG_ERR_ENOMEM);;
}
+ if (ephemeral)
+ keydb_set_ephemeral (kh, 1);
+
err = keydb_lock (kh);
if (err)
{
err = keydb_search_fpr (kh, fpr);
if (err)
{
- log_error (_("problem re-searching certificate: %s\n"),
- gpg_strerror (err));
+ if (err == -1)
+ err = gpg_error (GPG_ERR_NOT_FOUND);
+ else
+ log_error (_("problem re-searching certificate: %s\n"),
+ gpg_strerror (err));
keydb_release (kh);
return err;
}
keydb_release (kh);
return err;
}
+
+ value = ((old_value & ~mask) | (value & mask));
+
if (value != old_value)
{
err = keydb_set_flags (kh, which, idx, value);
return err;
}
}
+
keydb_release (kh);
return 0;
}
/* Reset all the certificate flags we have stored with the certificates
for performance reasons. */
void
-keydb_clear_some_cert_flags (ctrl_t ctrl, STRLIST names)
+keydb_clear_some_cert_flags (ctrl_t ctrl, strlist_t names)
{
gpg_error_t err;
KEYDB_HANDLE hd = NULL;
KEYDB_SEARCH_DESC *desc = NULL;
int ndesc;
- STRLIST sl;
+ strlist_t sl;
int rc=0;
unsigned int old_value, value;
if (!ndesc)
{
log_error ("allocating memory failed: %s\n",
- gpg_strerror (OUT_OF_CORE (errno)));
+ gpg_strerror (out_of_core ()));
goto leave;
}