Major and incompatible overhaul of key_data representation. Fix leaks.
[u/mdw/catacomb] / key-attr.c
index 27f4490..2d33b9c 100644 (file)
@@ -179,6 +179,28 @@ int key_putattr(key_file *f, key *k, const char *n, const char *v)
   return (0);
 }
 
+/* --- @key_setkeydata@ --- *
+ *
+ * Arguments:  @key_file *kf@ = pointer to key file
+ *             @key *k@ = pointer to key
+ *             @key_data *kd@ = new key data
+ *
+ * Returns:    Zero on success, or a @KERR_@ error code on failure.
+ *
+ * Use:                Sets the key data for a key.
+ */
+
+int key_setkeydata(key_file *kf, key *k, key_data *kd)
+{
+  if (!(kf->f & KF_WRITE))
+    return (KERR_READONLY);
+  key_drop(k->k);
+  key_incref(kd);
+  k->k = kd;
+  kf->f |= KF_MODIFIED;
+  return (0);
+}
+
 /* --- @key_setcomment@ --- *
  *
  * Arguments:  @key_file *f@ = pointer to key file block