1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 * Copyright 1996, Massachusetts Institute of Technology.
4 * All Rights Reserved.
5 *
6 * Export of this software from the United States of America may
7 * require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
10 *
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. Furthermore if you modify this software you must label
19 * your software as modified software and not distribute it in such a
20 * fashion that it might be confused with the original M.I.T. software.
21 * M.I.T. makes no representations about the suitability of
22 * this software for any purpose. It is provided "as is" without express
23 * or implied warranty.
24 */
25
26 /*
27 * Simple test program for testing how GSSAPI import name works. (May
28 * be made into a more full-fledged test program later.)
29 */
30
31 #include <stdio.h>
32 #include <string.h>
33
34 #include "common.h"
35
36 static const char *
oid_str(char type)37 oid_str(char type)
38 {
39 switch (type) {
40 case 'p': /* GSS_KRB5_NT_PRINCIPAL_NAME */
41 return "{ 1 2 840 113554 1 2 2 1 }";
42 case 'e': /* GSS_KRB5_NT_ENTERPRISE_NAME */
43 return "{ 1 2 840 113554 1 2 2 6 }";
44 case 'c': /* GSS_KRB5_NT_X509_CERT */
45 return "{ 1 2 840 113554 1 2 2 7 }";
46 case 'h': /* GSS_C_NT_HOSTBASED_SERVICE */
47 return "{ 1 2 840 113554 1 2 1 4 }";
48 }
49 return "no_oid";
50 }
51
52 /* Return true if buf has the same contents as str, plus a zero byte if
53 * indicated by buf_includes_nullterm. */
54 static int
buf_eq_str(gss_buffer_t buf,const char * str,int buf_includes_nullterm)55 buf_eq_str(gss_buffer_t buf, const char *str, int buf_includes_nullterm)
56 {
57 size_t len = strlen(str) + (buf_includes_nullterm ? 1 : 0);
58
59 return (buf->length == len && memcmp(buf->value, str, len) == 0);
60 }
61
62 static void
test_import_name(const char * name)63 test_import_name(const char *name)
64 {
65 OM_uint32 major, minor;
66 gss_name_t gss_name;
67 gss_buffer_desc buf;
68 gss_OID name_oid;
69
70 gss_name = import_name(name);
71
72 major = gss_display_name(&minor, gss_name, &buf, &name_oid);
73 check_gsserr("gss_display_name", major, minor);
74 if (!buf_eq_str(&buf, name + 2, 0))
75 errout("wrong name string");
76 (void)gss_release_buffer(&minor, &buf);
77
78 major = gss_oid_to_str(&minor, name_oid, &buf);
79 check_gsserr("gss_oid_to_str", major, minor);
80 if (!buf_eq_str(&buf, oid_str(*name), 1))
81 errout("wrong name type");
82 (void)gss_release_buffer(&minor, &buf);
83 (void)gss_release_name(&minor, &gss_name);
84 }
85
86 int
main(int argc,char ** argv)87 main(int argc, char **argv)
88 {
89 test_import_name("p:user@MIT.EDU");
90 test_import_name("e:enterprise@mit.edu@MIT.EDU");
91 test_import_name("h:HOST@dc1.mit.edu");
92
93 return 0;
94 }
95