File: saslname.c

package info (click to toggle)
gss 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,228 kB
  • ctags: 2,436
  • sloc: sh: 13,069; ansic: 11,900; python: 2,873; perl: 623; makefile: 172; sed: 16
file content (180 lines) | stat: -rw-r--r-- 6,012 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* saslname.c --- Test of new SASL GS2 related GSS-API functions
 * Copyright (C) 2003-2014 Simon Josefsson
 *
 * This file is part of the Generic Security Service (GSS).
 *
 * GSS is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * GSS is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GSS; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>

/* Get GSS prototypes. */
#include <gss.h>

#include "utils.c"

int
main (int argc, char *argv[])
{
  gss_uint32 maj_stat, min_stat;
  gss_buffer_desc bufdesc;
  gss_OID oid;

  do
    if (strcmp (argv[argc - 1], "-v") == 0 ||
	strcmp (argv[argc - 1], "--verbose") == 0)
      debug = 1;
    else if (strcmp (argv[argc - 1], "-b") == 0 ||
	     strcmp (argv[argc - 1], "--break-on-error") == 0)
      break_on_error = 1;
    else if (strcmp (argv[argc - 1], "-h") == 0 ||
	     strcmp (argv[argc - 1], "-?") == 0 ||
	     strcmp (argv[argc - 1], "--help") == 0)
      {
	printf ("Usage: %s [-vbh?] [--verbose] [--break-on-error] [--help]\n",
		argv[0]);
	return 1;
      }
  while (argc-- > 1);

  maj_stat = gss_inquire_mech_for_saslname (&min_stat, NULL, NULL);
  if (maj_stat == GSS_S_CALL_INACCESSIBLE_READ)
    success ("gss_inquire_mech_for_saslname (NULL, NULL) success\n");
  else
    fail ("gss_inquire_mech_for_saslname (NULL, NULL) failed (%d,%d)\n",
	  maj_stat, min_stat);

  bufdesc.value = NULL;
  bufdesc.length = 0;

  maj_stat = gss_inquire_mech_for_saslname (&min_stat, &bufdesc, NULL);
  if (maj_stat == GSS_S_BAD_MECH)
    success ("gss_inquire_mech_for_saslname (EMPTY, NULL) success\n");
  else
    fail ("gss_inquire_mech_for_saslname (EMPTY, NULL) failed (%d,%d)\n",
	  maj_stat, min_stat);

#ifdef USE_KERBEROS5
  bufdesc.length = 8;
  bufdesc.value = malloc (bufdesc.length);
  memcpy (bufdesc.value, "GS2-KRB5", bufdesc.length);

  maj_stat = gss_inquire_mech_for_saslname (&min_stat, &bufdesc, NULL);
  if (maj_stat == GSS_S_COMPLETE)
    success ("gss_inquire_mech_for_saslname (GS2-KRB5, NULL) success\n");
  else
    fail ("gss_inquire_mech_for_saslname (GS2-KRB5, NULL) failed (%d,%d)\n",
	  maj_stat, min_stat);

  maj_stat = gss_inquire_mech_for_saslname (&min_stat, &bufdesc, &oid);
  if (maj_stat == GSS_S_COMPLETE)
    success ("gss_inquire_mech_for_saslname (GS2-KRB5, OID) success\n");
  else
    fail ("gss_inquire_mech_for_saslname (GS2-KRB5, OID) failed (%d,%d)\n",
	  maj_stat, min_stat);

  if (oid != GSS_KRB5 || !gss_oid_equal (oid, GSS_KRB5))
    fail ("GS2-OID not Krb5?!\n");

  free (bufdesc.value);
#endif

  maj_stat =
    gss_inquire_saslname_for_mech (&min_stat, NULL, NULL, NULL, NULL);
  if (maj_stat == GSS_S_CALL_INACCESSIBLE_READ)
    success ("gss_inquire_saslname_for_mech (NULL) success\n");
  else
    fail ("gss_inquire_saslname_for_mech (NULL) failed (%d,%d)\n",
	  maj_stat, min_stat);

  maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_C_NT_USER_NAME,
					    NULL, NULL, NULL);
  if (maj_stat == GSS_S_BAD_MECH)
    success ("gss_inquire_saslname_for_mech (NT_USER_NAME) success\n");
  else
    fail ("gss_inquire_saslname_for_mech (NT_USER_NAME) failed (%d,%d)\n",
	  maj_stat, min_stat);

#ifdef USE_KERBEROS5
  maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_KRB5,
					    NULL, NULL, NULL);
  if (maj_stat == GSS_S_COMPLETE)
    success ("gss_inquire_saslname_for_mech (GSS-KRB5) success\n");
  else
    fail ("gss_inquire_saslname_for_mech (GSS-KRB5) failed (%d,%d)\n",
	  maj_stat, min_stat);

  bufdesc.value = NULL;
  bufdesc.length = 0;

  maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_KRB5,
					    &bufdesc, NULL, NULL);
  if (maj_stat == GSS_S_COMPLETE)
    success ("gss_inquire_saslname_for_mech (GSS-KRB5) success: %.*s\n",
	     (int) bufdesc.length, (char *) bufdesc.value);
  else
    fail ("gss_inquire_saslname_for_mech (GSS-KRB5) failed (%d,%d)\n",
	  maj_stat, min_stat);

  maj_stat = gss_release_buffer (&min_stat, &bufdesc);
  if (maj_stat == GSS_S_COMPLETE)
    success ("gss_release_buffer() OK\n");
  else
    fail ("gss_release_buffer() failed (%d,%d)\n", maj_stat, min_stat);

  maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_KRB5,
					    NULL, &bufdesc, NULL);
  if (maj_stat == GSS_S_COMPLETE)
    success ("gss_inquire_saslname_for_mech (GSS-KRB5-2) success: %.*s\n",
	     (int) bufdesc.length, (char *) bufdesc.value);
  else
    fail ("gss_inquire_saslname_for_mech (GSS-KRB5-2) failed (%d,%d)\n",
	  maj_stat, min_stat);

  maj_stat = gss_release_buffer (&min_stat, &bufdesc);
  if (maj_stat == GSS_S_COMPLETE)
    success ("gss_release_buffer() OK\n");
  else
    fail ("gss_release_buffer() failed (%d,%d)\n", maj_stat, min_stat);

  maj_stat = gss_inquire_saslname_for_mech (&min_stat, GSS_KRB5,
					    NULL, NULL, &bufdesc);
  if (maj_stat == GSS_S_COMPLETE)
    success ("gss_inquire_saslname_for_mech (GSS-KRB5-3) success: %.*s\n",
	     (int) bufdesc.length, (char *) bufdesc.value);
  else
    fail ("gss_inquire_saslname_for_mech (GSS-KRB5-3) failed (%d,%d)\n",
	  maj_stat, min_stat);

  maj_stat = gss_release_buffer (&min_stat, &bufdesc);
  if (maj_stat == GSS_S_COMPLETE)
    success ("gss_release_buffer() OK\n");
  else
    fail ("gss_release_buffer() failed (%d,%d)\n", maj_stat, min_stat);
#endif

  if (debug)
    printf ("Basic self tests done with %d errors\n", error_count);

  return error_count ? 1 : 0;
}