Dump attributes differently in t_saslname
authorGreg Hudson <ghudson@mit.edu>
Fri, 3 Feb 2012 03:19:28 +0000 (03:19 +0000)
committerGreg Hudson <ghudson@mit.edu>
Fri, 3 Feb 2012 03:19:28 +0000 (03:19 +0000)
Dump the known attributes only once, before iterating over the
mechanisms, and display the short and long desc as well as the names
when doing so.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25667 dc483132-0cff-0310-8789-dd5450dbe970

src/tests/gssapi/t_saslname.c

index 8d1b28c20525975b7401e485309ebed528decbe2..27cc22d51edd10e37471d8ab864869be83724c5d 100644 (file)
@@ -57,8 +57,8 @@ displayStatus(char *msg, OM_uint32 maj_stat, OM_uint32 min_stat)
     displayStatus_1(msg, min_stat, GSS_C_MECH_CODE);
 }
 
-static
-OM_uint32 dumpMechAttrs(OM_uint32 *minor, gss_OID mech)
+static OM_uint32
+dumpKnownMechAttrs(OM_uint32 *minor, gss_OID mech)
 {
     OM_uint32 major, tmpMinor;
     gss_OID_set mech_attrs = GSS_C_NO_OID_SET;
@@ -71,34 +71,54 @@ OM_uint32 dumpMechAttrs(OM_uint32 *minor, gss_OID mech)
         return major;
     }
 
-    printf("Mech attrs:  ");
-
-    for (i = 0; i < mech_attrs->count; i++) {
+    printf("Known attributes\n");
+    printf("----------------\n");
+    for (i = 0; i < known_attrs->count; i++) {
         gss_buffer_desc name = GSS_C_EMPTY_BUFFER;
         gss_buffer_desc short_desc = GSS_C_EMPTY_BUFFER;
         gss_buffer_desc long_desc = GSS_C_EMPTY_BUFFER;
 
-        major = gss_display_mech_attr(minor, &mech_attrs->elements[i],
+        major = gss_display_mech_attr(minor, &known_attrs->elements[i],
                                       &name, &short_desc, &long_desc);
         if (GSS_ERROR(major)) {
             displayStatus("gss_display_mech_attr", major, *minor);
             continue;
         }
-        printf("%.*s ", (int)name.length, (char *)name.value);
+        printf("%.*s (%.*s): %.*s\n", (int)short_desc.length,
+               (char *)short_desc.value, (int)name.length, (char *)name.value,
+               (int)long_desc.length, (char *)long_desc.value);
         gss_release_buffer(minor, &name);
         gss_release_buffer(minor, &short_desc);
         gss_release_buffer(minor, &long_desc);
     }
     printf("\n");
+    gss_release_oid_set(&tmpMinor, &mech_attrs);
+    gss_release_oid_set(&tmpMinor, &known_attrs);
+    return GSS_S_COMPLETE;
+}
+
+static
+OM_uint32 dumpMechAttrs(OM_uint32 *minor, gss_OID mech)
+{
+    OM_uint32 major, tmpMinor;
+    gss_OID_set mech_attrs = GSS_C_NO_OID_SET;
+    gss_OID_set known_attrs = GSS_C_NO_OID_SET;
+    size_t i;
+
+    major = gss_inquire_attrs_for_mech(minor, mech, &mech_attrs, &known_attrs);
+    if (GSS_ERROR(major)) {
+        displayStatus("gss_inquire_attrs_for_mech", major, *minor);
+        return major;
+    }
 
-    printf("Known attrs: ");
+    printf("Mech attrs:  ");
 
-    for (i = 0; i < known_attrs->count; i++) {
+    for (i = 0; i < mech_attrs->count; i++) {
         gss_buffer_desc name = GSS_C_EMPTY_BUFFER;
         gss_buffer_desc short_desc = GSS_C_EMPTY_BUFFER;
         gss_buffer_desc long_desc = GSS_C_EMPTY_BUFFER;
 
-        major = gss_display_mech_attr(minor, &known_attrs->elements[i],
+        major = gss_display_mech_attr(minor, &mech_attrs->elements[i],
                                       &name, &short_desc, &long_desc);
         if (GSS_ERROR(major)) {
             displayStatus("gss_display_mech_attr", major, *minor);
@@ -129,6 +149,8 @@ int main(int argc, char *argv[])
         return major;
     }
 
+    if (mechs->count > 0)
+        dumpKnownMechAttrs(&minor, mechs->elements);
     for (i = 0; i < mechs->count; i++) {
         gss_buffer_desc oidstr = GSS_C_EMPTY_BUFFER;
         gss_buffer_desc sasl_mech_name = GSS_C_EMPTY_BUFFER;