Imported Upstream version 1.15.1
[platform/upstream/krb5.git] / src / lib / krb5 / ccache / t_cccursor.c
index a0c7586..4323b77 100644 (file)
@@ -28,7 +28,9 @@
  * Displays a list of caches returned by the cccol cursor.  The first argument,
  * if given, is set to the default cache name for the context before iterating.
  * Any remaining argments are resolved as caches and kept open during the
- * iteration.
+ * iteration.  If the argument "CONTENT" is given as one of the cache names,
+ * immediately exit with status 0 if the collection contains credentials and 1
+ * if it does not.
  */
 
 #include "k5-int.h"
@@ -36,6 +38,7 @@
 int
 main(int argc, char **argv)
 {
+    krb5_error_code ret;
     krb5_context ctx;
     krb5_cccol_cursor cursor;
     krb5_ccache cache, hold[64];
@@ -48,8 +51,14 @@ main(int argc, char **argv)
 
     if (argc > 2) {
         assert(argc < 60);
-        for (i = 2; i < argc; i++)
+        for (i = 2; i < argc; i++) {
+            if (strcmp(argv[i], "CONTENT") == 0) {
+                ret = krb5_cccol_have_content(ctx);
+                krb5_free_context(ctx);
+                return ret != 0;
+            }
             assert(krb5_cc_resolve(ctx, argv[i], &hold[i - 2]) == 0);
+        }
     }
 
     assert(krb5_cccol_cursor_new(ctx, &cursor) == 0);
@@ -66,5 +75,7 @@ main(int argc, char **argv)
 
     for (i = 2; i < argc; i++)
         krb5_cc_close(ctx, hold[i - 2]);
+
+    krb5_free_context(ctx);
     return 0;
 }