Added support for the ktf_remove function
authorTheodore Tso <tytso@mit.edu>
Tue, 29 Sep 1992 13:53:20 +0000 (13:53 +0000)
committerTheodore Tso <tytso@mit.edu>
Tue, 29 Sep 1992 13:53:20 +0000 (13:53 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2422 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/keytab/file/ktf_remove.c

index 8f068ee890320002d6e562856619720eef323a0c..d79e380d6bac72d6281fa3d71801b546dd8df992 100644 (file)
@@ -40,5 +40,52 @@ krb5_ktfile_remove(id, entry)
 krb5_keytab id;
 krb5_keytab_entry *entry;
 {
-    return EOPNOTSUPP;
+    krb5_keytab_entry   *cur_entry;
+    krb5_error_code     kerror;
+    krb5_int32          delete_point;
+    krb5_boolean        found = FALSE;
+
+    if (kerror = krb5_ktfileint_openw(id)) {
+       return kerror;
+    }
+
+    /* 
+     * For efficiency and simplicity, we'll use a while true that 
+     * is exited with a break statement.
+     */
+    while (TRUE) {
+       cur_entry = 0;
+       if (kerror = krb5_ktfileint_internal_read_entry(id, &cur_entry,
+                                                            &delete_point))
+           break;
+
+       if ((entry->vno == cur_entry->vno) &&
+            (entry->key.keytype == cur_entry->key.keytype) &&
+           krb5_principal_compare(entry->principal, cur_entry->principal)) {
+           /* found a match */
+            found = TRUE;
+            krb5_kt_free_entry(cur_entry);
+           break;
+       }
+       krb5_kt_free_entry(cur_entry);
+    }
+
+    if (kerror && kerror != KRB5_KT_END) {
+       (void) krb5_ktfileint_close(id);
+       return kerror;
+    }
+
+    if (found) {
+        kerror = krb5_ktfileint_delete_entry(id, delete_point);
+    } else {
+        kerror = KRB5_KT_NOTFOUND;
+    }
+
+    if (kerror) {
+       (void) krb5_ktfileint_close(id);
+    } else {
+        kerror = krb5_ktfileint_close(id);
+    }
+
+    return kerror;
 }