Simple test program for testing how GSSAPI import name works. (May be
authorTheodore Tso <tytso@mit.edu>
Sat, 24 Feb 1996 05:14:23 +0000 (05:14 +0000)
committerTheodore Tso <tytso@mit.edu>
Sat, 24 Feb 1996 05:14:23 +0000 (05:14 +0000)
made into a more full-fledged test program later.)

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

src/tests/gssapi/Makefile.in [new file with mode: 0644]
src/tests/gssapi/configure.in [new file with mode: 0644]
src/tests/gssapi/t_imp_name.c [new file with mode: 0644]

diff --git a/src/tests/gssapi/Makefile.in b/src/tests/gssapi/Makefile.in
new file mode 100644 (file)
index 0000000..fb0e683
--- /dev/null
@@ -0,0 +1,17 @@
+CFLAGS = $(CCOPTS) $(DEFS) $(LOCALINCLUDE) -DUSE_AUTOCONF_H
+
+SRCS= t_imp_name.c
+
+OBJS= t_imp_name.o
+
+all:: t_imp_name
+
+LOCAL_LIBRARIES = -lgssapi_krb5
+DEPLOCAL_LIBRARIES = $(TOPLIBD)/gssapi/libgssapi_krb5.a
+
+t_imp_name: t_imp_name.o $(DEPLIBS)
+       $(LD) $(LDFLAGS) $(LDARGS) -o t_imp_name t_imp_name.o $(LIBS)
+
+clean::
+       $(RM) t_imp_name
+
diff --git a/src/tests/gssapi/configure.in b/src/tests/gssapi/configure.in
new file mode 100644 (file)
index 0000000..12cb482
--- /dev/null
@@ -0,0 +1,9 @@
+AC_INIT(t_imp_name.c)
+CONFIG_RULES
+AC_CHECK_HEADERS(unistd.h stdlib.h)
+AC_CHECK_HEADER(string.h,AC_DEFINE(USE_STRING_H))
+AC_CONST
+AC_PROG_INSTALL
+KRB5_LIBRARIES
+V5_USE_SHARED_LIB
+V5_AC_OUTPUT_MAKEFILE
diff --git a/src/tests/gssapi/t_imp_name.c b/src/tests/gssapi/t_imp_name.c
new file mode 100644 (file)
index 0000000..f1b3cd2
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright 1996, Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ *   require a specific license from the United States Government.
+ *   It is the responsibility of any person or organization contemplating
+ *   export to obtain such a license before exporting.
+ * 
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission.  M.I.T. makes no representations about the suitability of
+ * this software for any purpose.  It is provided "as is" without express
+ * or implied warranty.
+ *
+ * Simple test program for testing how GSSAPI import name works.  (May
+ * be made into a more full-fledged test program later.)
+ * 
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <gssapi/gssapi.h>
+#include <gssapi/gssapi_generic.h>
+
+void display_status();
+static void display_status_1();
+static void display_buffer();
+static int test_import_name();
+
+FILE *display_file = stdout;
+
+int main(argc, argv)
+       int argc;
+       char **argv;
+{
+       int retval;
+       
+       retval = test_import_name("host@dcl.mit.edu");
+
+       return retval;
+}
+
+static int test_import_name(name)
+       char *name;
+{
+       OM_uint32 maj_stat, min_stat;
+       gss_name_t gss_name;
+       gss_buffer_desc buffer_name;
+       gss_OID name_oid;
+
+       buffer_name.value = name;
+       buffer_name.length = strlen(name) + 1;
+       maj_stat = gss_import_name(&min_stat, &buffer_name,
+                                  (gss_OID) gss_nt_service_name,
+                                  &gss_name);
+       if (maj_stat != GSS_S_COMPLETE) {
+               display_status("parsing name", maj_stat, min_stat);
+               return -1;
+       }
+       
+       maj_stat = gss_display_name(&min_stat, gss_name, &buffer_name,
+                                   &name_oid);
+       if (maj_stat != GSS_S_COMPLETE) {
+               display_status("displaying context", maj_stat, min_stat);
+               return -1;
+       }
+       printf("name is: ");
+       display_buffer(buffer_name);
+       printf("\n");
+       (void) gss_release_buffer(&min_stat, &buffer_name);
+
+       gss_oid_to_str(&min_stat, name_oid, &buffer_name);
+       printf("name type is: ");
+       display_buffer(buffer_name);
+       printf("\n");
+       (void) gss_release_buffer(&min_stat, &buffer_name);
+
+       (void) gss_release_oid(&min_stat, &name_oid);
+       (void) gss_release_name(&min_stat, &gss_name);
+       return 0;
+}
+
+static void display_buffer(buffer)
+       gss_buffer_desc buffer;
+{
+    char *namebuf;
+    
+    namebuf = malloc(buffer.length+1);    
+    if (!namebuf) {
+       fprintf(stderr, "display_buffer: couldn't allocate buffer!\n");
+       exit(1);
+    }
+    strncpy(namebuf, buffer.value, buffer.length);
+    namebuf[buffer.length] = '\0';
+    printf("%s", namebuf);
+    free(namebuf);
+}
+
+void display_status(msg, maj_stat, min_stat)
+     char *msg;
+     OM_uint32 maj_stat;
+     OM_uint32 min_stat;
+{
+     display_status_1(msg, maj_stat, GSS_C_GSS_CODE);
+     display_status_1(msg, min_stat, GSS_C_MECH_CODE);
+}
+
+static void display_status_1(m, code, type)
+     char *m;
+     OM_uint32 code;
+     int type;
+{
+     OM_uint32 maj_stat, min_stat;
+     gss_buffer_desc msg;
+#ifdef GSSAPI_V2
+     OM_uint32 msg_ctx;
+#else  /* GSSAPI_V2 */
+     int msg_ctx;
+#endif /* GSSAPI_V2 */
+     
+     msg_ctx = 0;
+     while (1) {
+         maj_stat = gss_display_status(&min_stat, code,
+                                      type, GSS_C_NULL_OID,
+                                      &msg_ctx, &msg);
+         if (display_file)
+             fprintf(display_file, "GSS-API error %s: %s\n", m,
+                     (char *)msg.value); 
+         (void) gss_release_buffer(&min_stat, &msg);
+         
+         if (!msg_ctx)
+              break;
+     }
+}
+