aboutsummaryrefslogtreecommitdiff
path: root/sncspkm1.c
blob: e565b6d1e3243741361da21206eee084d9161c11 (plain)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
static char * this_File = "sncspkm1.c";
static char * cvs_id =
  "$Id: sncspkm1.c,v 1.1.1.1 1999/08/24 14:36:21 d019080 Exp $";
/*
 *  (C) Copyright 1999  SAP AG Walldorf
 *
 * SAP AG DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL SAP AG BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 * OF THIS SOFTWARE.
 */




/************************************************************************/
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
/*									*/
/*  Configurable Parameters that describe the characteristics		*/
/*  of the security mechanism to which this adapter interfaces		*/
/*  To register a MECH_PREFIX or MECH_ID with SAP,			*/
/*  send a request via Email to <Martin.Rex@sap-ag.de> including        */
/*  the following information:                                          */
/*       - mechanism OID of gssapi mechanism				*/
/*       - gssapi mechanism name (for open protocol specs)		*/
/*         OR product name of proprietary gssapi mechanism		*/
/*	 - default nametype OID						*/
/*       - proposed printable prefix (up to seven characters)		*/
/*       - Email address of technical contact				*/
/*									*/
/*  In case you're implementing a published gssapi mechanism spec,      */
/*  a SAPGSS_MECH_ID and SAPGSS_MECH_PREFIX may already be assigned.	*/
/*  You can check the "sncgss.h" Header file first.			*/
/*									*/
/*									*/
/*  ADAPTER_MECH_NAME		Name of gssapi mechanism protocol       */
/*				(for open protocol specifications)      */
/*                              OR name of a software product for       */
/*                              a proprietary gssapi mechanism          */
/*									*/
/*  ADAPTER_MECH_PREFIX		(must REGISTER with SAP)		*/
/*				ASCII-string up to 7 chars to		*/
/*				identify the mechanism			*/
/*									*/
/*  ADAPTER_MECH_ID		(must REGISTER with SAP)		*/
/*				numeric constant taken from the		*/
/*				SAPGSS_MECH_ID enumerator in "sncgss.h" */
/*									*/
/*  ADAPTER_MECHANISM_OID	ASN.1 OID (written as gss_OID_desc)	*/
/*			        of the gssapi mechanism to which this   */
/*				SNC-Adapter will be linked		*/
/*									*/
/*  ADAPTER_NAMETYPE_OID        ASN.1 OID (written as gss_OID_desc)	*/
/*			        of the default/canonical/native nametype*/
/*			        of above gssapi mechanism		*/
/*									*/
/*  ADAPTER_MAJOR_REVISION      cosmetic, no functional purpose		*/
/*  ADAPTER_MINOR_REVISION	cosmetic, no functional purpose		*/
/*									*/
/*  ADAPTER_CONF_AVAIL		(0 or 1) REQUIRED			*/
/*				implementation guarantees availability  */
/*				of message confidentiality protection   */
/*				for all established security contexts	*/
/*									*/
/*  ADAPTER_INTEG_AVAIL		(0 or 1) REQUIRED			*/
/*				implementation guarantees availability  */
/*				of message integrity protection for all */
/*				established security contexts           */
/*									*/
/*  ADAPTER_MUTUAL_AUTH		(0 or 1) REQUIRED			*/
/*				implemenation guarantees availability   */
/*				of mutual authentication on security    */
/*				contexts.  Absence of mutual auth is    */
/*				a serious security problem in           */
/*				distributed applications		*/
/*									*/
/*  ADAPTER_REPLAY_PROT		(0 or 1) REQUIRED			*/
/*				implementation guarantees availability  */
/*				of replay detection of protected	*/
/*				messages on all security contexts.	*/
/*				SAP R/3 process all messages on a	*/
/*			        particular security context strictly    */
/*			        sequential, so it's acceptable		*/
/*				if replay detection is only available   */
/*				in combination with sequence protection */
/*									*/
/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
/************************************************************************/


#define ADAPTER_MECH_NAME    SAPGSS_SPKM1_NAME
					    /* Name of the gssapi mechanism or product    */
					    /* that this SNC-Adapter interfaces to        */
					    /* (less than 80 characters, please !!)	  */


#define ADAPTER_MECH_PREFIX  SAPGSS_SPKM1_PREFIX
				            /* Mech prefix for mechanism                  */
					    /* (register this prefix with SAP)            */
					    /* Alphanumeric, must be <= 7 characters long */
					    /* This prefix may be used within SNC-Names   */
					    /* i.e. "p/sapntlm:NTDomain\User"             */


#define ADAPTER_MECH_ID	     SAPGSS_ID_SPKM1
					    /* Mechanism identifier			  */
					    /* numeric (16-bit unsigned integer)	  */
					    /* used internally by SNC for tagging	  */
					    /* and to distinguish different gssapi mechs  */


   /* ASN.1 OID of the gssapi mechanism to which this  */
   /* SNC-Adapter is linked			       */
#define ADAPTER_MECHANISM_OID	 SAPGSS_SPKM1_MECH_OID

   /* ASN.1 OID of the default/canonical nametype that		*/
   /* this gssapi mechanism will accept with gss_import_name()  */
   /* and emit with gss_display_name() for canonical names      */
#define ADAPTER_NAMETYPE_OID	 SAPGSS_SPKM1_CNAME_OID


/*******************/
/* 16-bit Integers */
/*******************/
#define ADAPTER_MAJOR_REVISION	1	/* indicates API changes */

#define ADAPTER_MINOR_REVISION	0	/* indicates fixes or    */
					/* cosmetic changes      */

/*******************/
/* BOOLEAN values  */
/*******************/
#define ADAPTER_CONF_AVAIL      1	/* Confidentiality available         */
#define ADAPTER_INTEG_AVAIL	1	/* Integrity available               */

#define ADAPTER_MUTUAL_AUTH	1	/* supports mutual authentication    */
#define ADAPTER_REPLAY_PROT	1	/* supports message replay detection */


/************************************************************************/
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
/************************************************************************/




/* Some ANSI-C standard headers */
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>

/**********************************************************************/
/*								      */
/*  Microsoft Windows DLL support				      */
/*								      */
/**********************************************************************/

#ifdef _WIN32
#  include <windows.h>
  BOOL APIENTRY
  DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
  {
     return 1;

     UNREFERENCED_PARAMETER(hInst);
     UNREFERENCED_PARAMETER(ul_reason_being_called);
     UNREFERENCED_PARAMETER(lpReserved);
  }
#else

#  if defined(_WINDOWS)
#	include <windows.h>
#	ifndef UNREFERENCED_PARAMETER
#	    define UNREFERENCED_PARAMETER(x) ((x)=(x))
#	endif

	BOOL CALLBACK
	LibMain (HINSTANCE hInst, WORD wDataSeg, WORD cbHeap, LPSTR CmdLine)
	{
		UNREFERENCED_PARAMETER(hInst);
		UNREFERENCED_PARAMETER(wDataSeg);
		UNREFERENCED_PARAMETER(cbHeap);
		UNREFERENCED_PARAMETER(CmdLine);

		return 1;
	}

	int CALLBACK __export
	WEP(int nParam)
	{
		UNREFERENCED_PARAMETER(nParam);

		return 1;
	}
#  endif

#endif

/**********************************************************************/
/*								      */
/*  Import interface						      */
/*    - include files of other projects				      */
/*  Declare gss_* function prototypes as __declspec(dllimport)        */
/*								      */
/**********************************************************************/

#include "platform.h"

#undef DLL_DATA_DECO
#undef DLL_FUNC_DECO
#define DLL_DATA_DECO	      IMPORT_DATA
#define DLL_FUNC_DECO	      IMPORT_FUNCTION
#include "gssapi_2.h"

/**********************************************************************/
/*								      */
/*  Export interface						      */
/*    - header files of this project				      */
/*  Declare our sapgss_* function prototypes as __declspec(dllexport) */
/*								      */
/**********************************************************************/

#undef DLL_DATA_DECO
#undef DLL_FUNC_DECO
#define DLL_DATA_DECO	      EXPORT_DATA
#define DLL_FUNC_DECO         EXPORT_FUNCTION
#include "sncgss.h"




/************************************************************************/
/*  (27-jun-95) Martin Rex						*/
/*  With the following two macros one can convert macros into		*/
/*  string literals to include them in constant strings.		*/
/*    see ANSI-C, X3.159-1989 section 3.8.3.2 and example on pg. 93	*/
/************************************************************************/
#define LITERAL_MACRO(x)          # x
#define XLITERAL_MACRO(x)         LITERAL_MACRO(x)



/****************************************************/
/* we don't need to export/share OID data at the    */
/* shared library interface for SAP R/3,	    */
/* and is not part of the draft-ietf-cat-wingss-... */
/****************************************************/

static gss_OID_desc oids[] = {
   ADAPTER_NAMETYPE_OID,	 /* nametype OID for canonical printable name */
   ADAPTER_MECHANISM_OID         /* mechanism OID of the gssapi mechanism     */
};

static gss_OID sapsnc_nt_canon_printable_name   = &(oids[0]);
static gss_OID sapsnc_mech_oid                  = &(oids[1]);

#define SAPSNC_CANON_NAME_OID sapsnc_nt_canon_printable_name

/**********************************************************************
 *  sapsnc_init_adapter():
 *
 *  Description:
 *    This function must be called before other functions of the
 *    gss-api are used.	 It sets up all translation pointers
 *    exported by the gss-api.
 *
 *  Parameters:
 *    p_info	IN REF	the structure referenced by this
 *			pointer (see sapgss.h) describes
 *			some characteristics of the security
 *			mechanism to which this adapter interfaces
 *
 *    p_length	IN	Length of the structure supplied by the
 *			SNC-Layer.
 *			Initialization policy for future enhancements:
 *			  * SNC-Layer zeroes out structure before calling.
 *			  * future extensions must be appended to the
 *			    existing structure only
 *			  * Unknown structure elements will not be changed.
 *			  * The Adapter must initialize only fields known
 *			    to the calling SNC-layer
 *			    (i.e. no elements past p_length)
 *
 *  Returns:
 *    0		 Initialization o.k.
 *   -1		 FAILURE -- something is definitely broken if this happens
 **********************************************************************/
OM_uint32 EXPORT_FUNCTION
sapsnc_init_adapter( struct sapgss_info_s *p_info, size_t p_length,
		     int adapter_idx )
{
   UNREFERENCED_PARAMETER(adapter_idx);

   if ( p_info==NULL  ||  p_length<=SNCADAPT_BASIC_INFO_LEN ) {

      /* At least we want to fill in the basic set of information */
      return(1);

   } else {

      memset( p_info, 0, p_length );

      p_info->major_rev         = (int) ADAPTER_MAJOR_REVISION;
      p_info->minor_rev         = (int) ADAPTER_MINOR_REVISION;

      p_info->adapter_name      = 
                "External SNC-Adapter"
	        " (Rev "  XLITERAL_MACRO(ADAPTER_MAJOR_REVISION)
                         "." XLITERAL_MACRO(ADAPTER_MINOR_REVISION) ") to "
                ADAPTER_MECH_NAME;

      p_info->mech_id              = ADAPTER_MECH_ID;

      p_info->nt_canonical_name    = SAPSNC_CANON_NAME_OID;
      p_info->nt_private_name1     = sapsnc_nt_canon_printable_name;
      p_info->nt_private_name2     = (gss_OID_desc *)0;
      p_info->nt_private_name3	   = (gss_OID_desc *)0;
      p_info->nt_private_name4	   = (gss_OID_desc *)0;

      p_info->integ_avail          = ADAPTER_INTEG_AVAIL;
      p_info->conf_avail           = ADAPTER_CONF_AVAIL;
      p_info->unused1	           = 0; /* historic/expirmental,   MUST be 0 */
      p_info->export_sec_context   = 1; /* required functionality, MUST be 1 */
      p_info->mutual_auth          = ADAPTER_MUTUAL_AUTH;
      p_info->replay_prot          = ADAPTER_REPLAY_PROT;

      p_info->unused2	           = 0; /* historic/experimental,  MUST be 0 */

      p_info->mech_prefix_string   = ADAPTER_MECH_PREFIX;

      if ( p_length>=SNCADAPT_INFO_LEN(mech_oid) ) {
	 p_info->mech_oid          = sapsnc_mech_oid;
      }

   }

   /* Initialize future elements only if the supplied structure is large */
   /* enough,                                                            */
   /* i.e. the calling SNC-layer is as recent or newer as the adapter    */

   return(0);

} /* sapsnc_init_adapter() */



/* 
 * sapsnc_export_cname_blob()
 *
 * BETTER LEAVE THIS ALONE !!
 *
 * This call was a temporary intermediate before the two calls
 * gss_canonicalize_name() and gss_export_name() were added
 * to the GSS-API v2 spec.
 *
 * However it is still required for R/3 up to 3.1H components
 * and for interoperability with those components or incomplete
 * gssapi v2 implementations of (MIT) Kerberos 5 and SECUDE
 */

OM_uint32 EXPORT_FUNCTION
sapsnc_export_cname_blob(
        OM_uint32     * min_stat,          /* minor_status       */
        gss_name_t      in_name,           /* input_name         */
        gss_buffer_t    out_identity,      /* output_name_buffer */
        int             adapter_idx
     )
{
   UNREFERENCED_PARAMETER(adapter_idx);
   UNREFERENCED_PARAMETER(in_name);

   if ( out_identity!=NULL ) {
      out_identity->length = 0;
      out_identity->value  = NULL;
   }

   if ( min_stat!=NULL )
      (*min_stat) = 0;

   return(GSS_S_FAILURE);

} /* sapsnc_export_cname_blob() */



/*
 * sapsnc_export_cname_blob()
 *
 * BETTER LEAVE THIS ALONE !!
 *
 * This call was a temporary intermediate before the two calls
 * gss_canonicalize_name() and gss_export_name() were added
 * to the GSS-API v2 spec.
 *
 * However it is still required for R/3 up to 3.1H components
 * and for interoperability with those components or incomplete
 * gssapi v2 implementations of (MIT) Kerberos 5 and SECUDE
 */
OM_uint32 EXPORT_FUNCTION
sapsnc_import_cname_blob(
	OM_uint32     * min_stat,          /* minor_status      */
	gss_buffer_t    in_identity,       /* input_name_buffer */
	gss_name_t    * out_name,          /* output_name       */
	int             adapter_idx
     )
{
   UNREFERENCED_PARAMETER(adapter_idx);

   return( gss_import_name( min_stat, in_identity,
			    (gss_OID)SAPSNC_CANON_NAME_OID, out_name ) );

} /* sapsnc_import_cname_blob() */


/*********************************************************************
 *
 * All functions following this comment are CALL ADAPTERS
 * to the GSS-API functions.
 *
 *********************************************************************/

/**********************************************************************/
/**********************************************************************/
/*******************                                *******************/
/*******************  GSS-API v1 ( RFC 1508/1509 )  *******************/
/*******************                                *******************/
/**********************************************************************/
/**********************************************************************/


/* sapgss_acquire_cred() */

OM_uint32 EXPORT_FUNCTION
sapgss_acquire_cred(
        OM_uint32      * min_stat,          /* minor_status */
        gss_name_t       my_gss_name,       /* desired_name */
        OM_uint32        in_lifetime,       /* time_req */
        gss_OID_set      in_mechs,          /* desired_mechs */
        gss_cred_usage_t in_cred_usage,     /* cred_usage */
        gss_cred_id_t  * out_cred,          /* output_cred_handle */
        gss_OID_set    * out_mechs,         /* actual_mechs */
        OM_uint32      * out_lifetime       /* time_rec */
     )
{
   return( gss_acquire_cred( min_stat,  my_gss_name,  in_lifetime,
			     in_mechs,  in_cred_usage,
			     out_cred,  out_mechs,     out_lifetime ) );
}



/* sapgss_release_cred() */

OM_uint32 EXPORT_FUNCTION
sapgss_release_cred(
        OM_uint32      * min_stat,          /* minor_status */
        gss_cred_id_t  * in_cred            /* cred_handle */
     )
{
   return( gss_release_cred( min_stat, in_cred ) );
}



/* sapgss_init_sec_context() */

OM_uint32 EXPORT_FUNCTION
sapgss_init_sec_context(
        OM_uint32      * min_stat,          /* minor_status */
        gss_cred_id_t    in_cred,           /* claimant_cred_handle */
        gss_ctx_id_t   * in_context,        /* context_handle */
        gss_name_t       in_name,           /* target_name */
        gss_OID          in_mech,           /* mech_type */
        OM_uint32        in_service_opts,   /* req_flags */
        OM_uint32        in_lifetime,       /* time_req */
        gss_channel_bindings_t
                         in_channel_bind,   /* input_chan_bindings */
        gss_buffer_t     in_token,          /* input_token */
        gss_OID        * out_mech,          /* actual_mech_type */
        gss_buffer_t     out_token,         /* output_token */
        OM_uint32      * out_service_opts,  /* ret_flags */
        OM_uint32      * out_lifetime       /* time_rec */
     )
{
   return( gss_init_sec_context( min_stat, in_cred, in_context, in_name,
				 in_mech, in_service_opts, in_lifetime,
				 in_channel_bind, in_token, out_mech,
				 out_token, out_service_opts, out_lifetime ) );
}



/* sapgss_accept_sec_context() */

OM_uint32 EXPORT_FUNCTION
sapgss_accept_sec_context(
        OM_uint32      *min_stat,          /* minor_status */
        gss_ctx_id_t   *in_context,        /* context_handle */
        gss_cred_id_t   in_cred,           /* verifier_cred_handle */
        gss_buffer_t    in_token,          /* input_token_buffer */
        gss_channel_bindings_t
                        in_channel_bind,   /* input_chan_bindings */
        gss_name_t     *peer_name,         /* src_name */
        gss_OID        *out_mech,          /* mech_type */
        gss_buffer_t    out_token,         /* output_token */
        OM_uint32      *out_service_opts,  /* ret_flags */
        OM_uint32      *out_lifetime,      /* time_rec */
        gss_cred_id_t  *out_cred           /* delegated_cred_handle */
     )
{
   return( gss_accept_sec_context( min_stat, in_context, in_cred, in_token,
				   in_channel_bind, peer_name, out_mech,
				   out_token, out_service_opts, out_lifetime,
				   out_cred ) );
}



/* sapgss_process_context_token() */

OM_uint32 EXPORT_FUNCTION
sapgss_process_context_token(
        OM_uint32      *min_stat,         /* minor_status */
        gss_ctx_id_t    in_context,       /* context_handle */
        gss_buffer_t    in_token          /* token_buffer */
     )
{
   return( gss_process_context_token( min_stat, in_context, in_token ) );
}



/* sapgss_delete_sec_context() */

OM_uint32 EXPORT_FUNCTION
sapgss_delete_sec_context(
        OM_uint32      *min_stat,         /* minor_status */
        gss_ctx_id_t   *in_context,       /* context_handle */
        gss_buffer_t    out_token         /* output_token */
     )
{
   return( gss_delete_sec_context( min_stat, in_context, out_token ) );
}



/* sapgss_context_time() */

OM_uint32 EXPORT_FUNCTION
sapgss_context_time(
        OM_uint32      * min_stat,         /* minor_status */
        gss_ctx_id_t     in_context,       /* context_handle */
        OM_uint32      * out_lifetime      /* time_rec */
     )
{
   return( gss_context_time( min_stat, in_context, out_lifetime ) );
}



/* sapgss_get_mic() */

OM_uint32 EXPORT_FUNCTION
sapgss_get_mic(
        OM_uint32      * min_stat,         /* minor_status */
        gss_ctx_id_t     in_context,       /* context_handle */
        gss_qop_t        in_qop,           /* qop_req */
        gss_buffer_t     in_msg,           /* message_buffer */
        gss_buffer_t     out_token         /* message_token */
     )
{
   return( gss_get_mic( min_stat, in_context, in_qop, in_msg, out_token ) );
}



/* sapgss_verify_mic() */

OM_uint32 EXPORT_FUNCTION
sapgss_verify_mic(
        OM_uint32      * min_stat,         /* minor_status */
        gss_ctx_id_t     in_context,       /* context_handle */
        gss_buffer_t     in_msg,           /* message_buffer */
        gss_buffer_t     in_token,         /* token_buffer */
        gss_qop_t      * out_qop           /* qop_state */
     )
{
   return( gss_verify_mic( min_stat, in_context, in_msg, in_token, out_qop ) );
}



/* sapgss_wrap() */

OM_uint32 EXPORT_FUNCTION
sapgss_wrap(
        OM_uint32      * min_stat,         /* minor_status */
        gss_ctx_id_t     in_context,       /* context_handle */
        int              in_want_conf,     /* conf_req_flag */
        gss_qop_t        in_qop,           /* qop_req */
        gss_buffer_t     in_msg,           /* input_message_buffer */
        int            * out_is_conf,      /* conf_state */
        gss_buffer_t     out_token         /* output_message_buffer */
     )
{
   return( gss_wrap( min_stat, in_context, in_want_conf,
		     in_qop, in_msg, out_is_conf, out_token ) );
}



/* sapgss_unwrap() */

OM_uint32 EXPORT_FUNCTION
sapgss_unwrap(
        OM_uint32      * min_stat,         /* minor_status */
        gss_ctx_id_t     in_context,       /* context_handle */
        gss_buffer_t     in_token,         /* input_message_buffer */
        gss_buffer_t     out_msg,          /* output_message_buffer */
        int            * out_is_conf,      /* conf_state */
        gss_qop_t      * out_qop           /* qop_state */
     )
{
   return( gss_unwrap( min_stat, in_context, in_token,
		       out_msg, out_is_conf, out_qop ) );
}



/* sapgss_display_status() */

OM_uint32 EXPORT_FUNCTION
sapgss_display_status(
        OM_uint32      *min_stat,         /* minor_status */
        OM_uint32       in_status,        /* status_value */
        int             in_status_type,   /* status_type */
        gss_OID         in_mech,          /* mech_type */
        OM_uint32      *out_more_text,    /* message_context */
        gss_buffer_t    out_text          /* status_string */
     )
{
   return( gss_display_status( min_stat, in_status, in_status_type,
			       in_mech, out_more_text, out_text ) );
}



/*
 * sapgss_indicate_mechs()
 *
 * IMPORTANT:  This call MUST return the correct mech_OID
 * for this implementation in the first position of the
 * out_mechs OID array!
 */
OM_uint32 EXPORT_FUNCTION
sapgss_indicate_mechs(
        OM_uint32      *min_stat,         /* minor_status */
        gss_OID_set    *out_mechs         /* mech_set */
     )
{
   OM_uint32   maj_stat;
   OM_uint32   min_stat2;

   maj_stat = gss_indicate_mechs( min_stat, out_mechs );

   if ( maj_stat==GSS_S_COMPLETE ) {
      if ( out_mechs==NULL
	   ||  (*out_mechs)==GSS_C_NO_OID_SET
	   ||  (*out_mechs)->count==0
	   ||  (*out_mechs)->elements==GSS_C_NO_OID
	   ||  ((*out_mechs)->elements[0]).length!=sapsnc_mech_oid->length
	   ||  memcmp( ((*out_mechs)->elements[0]).elements,
		       sapsnc_mech_oid->elements, sapsnc_mech_oid->length )!=0 ) {

	 (void)sapgss_release_oid_set( &min_stat2, out_mechs );

	 (*out_mechs) = GSS_C_NO_OID_SET;
	 (*min_stat)  = 0;

	 return(GSS_S_BAD_MECH);

      }
   }

   return(maj_stat);

}



/* sapgss_compare_name() */

OM_uint32 EXPORT_FUNCTION
sapgss_compare_name(
        OM_uint32      *min_stat,         /* minor_status */
        gss_name_t      in_name1,         /* name1 */
        gss_name_t      in_name2,         /* name2 */
        int            *out_are_equal     /* name_equal */
     )
{
   return( gss_compare_name( min_stat, in_name1, in_name2, out_are_equal ) );
}



/* sapgss_display_name() */

OM_uint32 EXPORT_FUNCTION
sapgss_display_name(
        OM_uint32      *min_stat,          /* minor_status */
        gss_name_t      in_name,           /* input_name */
        gss_buffer_t    out_identity,      /* output_name_buffer */
        gss_OID        *out_oid            /* output_name_type */
     )
{
   return( gss_display_name( min_stat, in_name, out_identity, out_oid ) );
}



/* sapgss_import_name() */

OM_uint32 EXPORT_FUNCTION
sapgss_import_name(
        OM_uint32      *min_stat,          /* minor_status */
        gss_buffer_t    in_identity,       /* input_name_buffer */
        gss_OID         in_oid,            /* input_name_type */
        gss_name_t     *out_name           /* output_name */
     )
{
   return( gss_import_name( min_stat, in_identity, in_oid, out_name ) );
}



/* sapgss_release_name() */

OM_uint32 EXPORT_FUNCTION
sapgss_release_name(
        OM_uint32      *min_stat,          /* minor_status */
        gss_name_t     *in_name            /* input_name */
     )
{
   return( gss_release_name( min_stat, in_name ) );
}



/* sapgss_release_buffer() */

OM_uint32 EXPORT_FUNCTION
sapgss_release_buffer(
        OM_uint32      *min_stat,          /* minor_status */
        gss_buffer_t    in_buffer          /* buffer */
     )
{
   return( gss_release_buffer( min_stat, in_buffer ) );
}



/* sapgss_release_oid_set() */

OM_uint32 EXPORT_FUNCTION
sapgss_release_oid_set(
        OM_uint32      *min_stat,          /* minor_status */
        gss_OID_set    *in_oids            /* set */
     )
{
   return( gss_release_oid_set( min_stat, in_oids ) );
}



/* sapgss_inquire_cred() */

OM_uint32 EXPORT_FUNCTION
sapgss_inquire_cred(
        OM_uint32         * min_stat,          /* minor_status */
        gss_cred_id_t       in_cred,           /* cred_handle */
        gss_name_t        * out_name,          /* name */
        OM_uint32         * out_lifetime,      /* lifetime */
        gss_cred_usage_t  * out_cred_usage,    /* cred_usage */
        gss_OID_set       * out_mechs          /* mechanisms */
     )
{
   return( gss_inquire_cred( min_stat, in_cred, out_name,
			     out_lifetime, out_cred_usage, out_mechs ) );
}


/**********************************************************************/
/**********************************************************************/
/*******************                               ********************/
/*******************  New fuctions for GSS-API v2  ********************/
/*******************                               ********************/
/**********************************************************************/
/**********************************************************************/

/*
 * sapgss_add_cred()
 *
 * Status:  not used by SNC in R/3 release 3.x and 4.0
 *
 */
OM_uint32 EXPORT_FUNCTION
sapgss_add_cred(
        OM_uint32     FAR * min_stat,           /* minor_status        */
	gss_cred_id_t       input_cred_handle,  /* input_cred_handle   */
	gss_name_t          desired_name,       /* desired_name        */
	gss_OID             desired_mech,       /* desired_mech        */
	gss_cred_usage_t    cred_usage,         /* cred_usage          */
	OM_uint32           initiator_time_req, /* initiator_time_req  */
	OM_uint32           acceptor_time_req,  /* acceptor_time_req   */
	gss_cred_id_t FAR * output_cred_handle,	/* output_cred_handle  */
	gss_OID_set   FAR * actual_mechs,       /* actual_mechs        */
	OM_uint32     FAR * initiator_time_rec, /* initiator_time_rec  */
	OM_uint32     FAR * acceptor_time_rec   /* acceptor_time_rec   */
     )
{
   return( gss_add_cred( min_stat, input_cred_handle, desired_name,
			 desired_mech, cred_usage, initiator_time_req,
			 acceptor_time_req,
			 output_cred_handle, actual_mechs,
			 initiator_time_rec, acceptor_time_rec ) );
}



/*
 * sapgss_inquire_cred_by_mech()
 *
 * Status:  not used by SNC in R/3 release 3.x and 4.0
 *          this may change in future releases
 */
OM_uint32 EXPORT_FUNCTION
sapgss_inquire_cred_by_mech(
        OM_uint32     FAR * min_stat,           /* minor_status        */
	gss_cred_id_t       cred_handle,        /* cred_handle         */
	gss_OID             mech_type,          /* mech_type           */
	gss_name_t    FAR * name,               /* name                */
	OM_uint32     FAR * initiator_lifetime, /* initiator_lifetime  */
	OM_uint32     FAR * acceptor_lifetime,  /* acceptor_lifetime   */
	gss_cred_usage_t FAR * cred_usage       /* cred_usage          */
     )
{
   return( gss_inquire_cred_by_mech( min_stat, cred_handle, mech_type,
				     name, initiator_lifetime,
				     acceptor_lifetime, cred_usage ) );
}



/* sapgss_inquire_context() */

OM_uint32 EXPORT_FUNCTION
sapgss_inquire_context(
        OM_uint32      *min_stat,          /* minor_status */
        gss_ctx_id_t    in_context,        /* context_handle */
        gss_name_t     *out_myname,        /* initiator_name */
        gss_name_t     *out_peername,      /* acceptor_name */
	OM_uint32      *out_lifetime,      /* lifetime_rec */
	gss_OID        *out_mech,          /* mech_type */
	OM_uint32      *out_service_opts,  /* ctx_flags */
	int            *out_initiator,     /* locally_initiated */
        int            *out_open           /* open */
     )
{
   return( gss_inquire_context( min_stat, in_context, out_myname,
				out_peername, out_lifetime, out_mech,
				out_service_opts, out_initiator, out_open) );
}



/*
 * sapgss_wrap_size_limit()
 *
 * Status:  not used by SNC in R/3 release 3.x and 4.0
 *          this may change in future releases
 */
OM_uint32 EXPORT_FUNCTION
sapgss_wrap_size_limit(
        OM_uint32       * min_stat,        /* minor_status          */
        gss_ctx_id_t      in_context,      /* context handle        */
        int               in_want_conf,    /* conf_req_flag         */
        gss_qop_t         qop_req,         /* qop_req               */
        OM_uint32         out_size,        /* requested output size */
        OM_uint32       * max_in_size      /* maximum input size    */
     )
{
   return( gss_wrap_size_limit( min_stat,  in_context,  in_want_conf,
				qop_req,   out_size,    max_in_size) );
}



/* sapgss_export_sec_context() */

OM_uint32 EXPORT_FUNCTION
sapgss_export_sec_context(
        OM_uint32     * min_stat,      /* minor_status */
        gss_ctx_id_t  * in_ctx,        /* context_handle */
        gss_buffer_t    out_buffer     /* interprocess_token */
     )
{
   return( gss_export_sec_context( min_stat, in_ctx, out_buffer ) );
}



/* sapgss_import_sec_context() */

OM_uint32 EXPORT_FUNCTION
sapgss_import_sec_context(
        OM_uint32     * min_stat,      /* minor_status */
        gss_buffer_t    in_buffer,     /* interprocess_token */
        gss_ctx_id_t  * out_ctx        /* context_handle */
     )
{
   return( gss_import_sec_context( min_stat, in_buffer, out_ctx ) );
}



/*
 * sapgss_create_empty_oid_set()
 *
 * Status: don't care
 */
OM_uint32 EXPORT_FUNCTION
sapgss_create_empty_oid_set(
        OM_uint32    FAR * min_stat,          /* minor_status            */
	gss_OID_set  FAR * oid_set            /* oid_set                 */
     )
{
   return( gss_create_empty_oid_set( min_stat, oid_set ) );
}



/*
 * sapgss_add_oid_set_member()
 *
 * Status: don't care
 */
OM_uint32 EXPORT_FUNCTION
sapgss_add_oid_set_member(
        OM_uint32    FAR * min_stat,          /* minor_status            */
	gss_OID            member_oid,        /* member_oid              */
        gss_OID_set  FAR * oid_set            /* oid_set                 */
     )
{
   return( gss_add_oid_set_member( min_stat, member_oid, oid_set ) );
}



/*
 * sapgss_test_oid_set_member()
 *
 * Status: don't care
 */
OM_uint32 EXPORT_FUNCTION
sapgss_test_oid_set_member(
        OM_uint32    FAR * min_stat,          /* minor_status           */
	gss_OID            member,            /* member                 */
        gss_OID_set        set,               /* set                    */
        int          FAR * present            /* present                */
     )
{
   return( gss_test_oid_set_member( min_stat, member, set, present ) );
}



/*
 * sapgss_inquire_names_for_mech()
 *
 * Status:  not used by SNC in R/3 release 3.x and 4.0
 *          this may change in future releases
 */

OM_uint32 EXPORT_FUNCTION
sapgss_inquire_names_for_mech(
        OM_uint32    FAR * min_stat,          /* minor_status           */
	gss_OID            mech_oid,          /* mechanism_oid          */
	gss_OID_set  FAR * name_types         /* name_types             */
     )
{
   return( gss_inquire_names_for_mech( min_stat, mech_oid, name_types ) );
}



/*
 * sapgss_inquire_mechs_for_name()
 *
 * Status: don't care
 */
OM_uint32 EXPORT_FUNCTION
sapgss_inquire_mechs_for_name(
	OM_uint32    FAR * min_stat,		/* minor_status		*/
	gss_name_t	   input_name,		/* input_name		*/
	gss_OID_set  FAR * mech_set		/* mechanism_oids	*/
     )
{
   return( gss_inquire_mechs_for_name( min_stat, input_name, mech_set ) );
}


/* sapgss_canonicalize_name() */

OM_uint32 EXPORT_FUNCTION
sapgss_canonicalize_name(
        OM_uint32    FAR * min_stat,            /* minor_status         */
	gss_name_t	   input_name,		/* input_name		*/
	gss_OID		   mech_type,		/* mech_type		*/
	gss_name_t   FAR * output_name		/* output_name		*/
     )
{
    return( gss_canonicalize_name( min_stat, input_name,
				   mech_type, output_name ) );
}


/* sapgss_export_name() */

OM_uint32 EXPORT_FUNCTION
sapgss_export_name(
        OM_uint32    FAR * min_stat,            /* minor_status         */
	gss_name_t	   input_name,		/* input_name		*/
	gss_buffer_t	   output_name_blob	/* output_name_blob	*/
     )
{
    return( gss_export_name( min_stat, input_name, output_name_blob ) );
}


/*
 * sapgss_duplicate_name()
 *
 * Status: Don't care
 */
OM_uint32 EXPORT_FUNCTION
sapgss_duplicate_name(
        OM_uint32    FAR * min_stat,            /* minor_status         */
        gss_name_t         src_name,            /* src_name             */
        gss_name_t   FAR * dest_name            /* dest_name            */
     )  
{
   return( gss_duplicate_name( min_stat, src_name, dest_name ) );
}


/* end of sncspkm1.c */