Remove a wasted check of XMLHttpResponse state
[gssweb.git] / gssapi_utils / gssapi_utils.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <errno.h>
6
7 #include "gssapi_utils.h"
8
9 OM_uint32
10 gss_construct_sec_context(
11     gss_status_t status,
12     gss_cred_id_t unused_cred_handle,
13     gss_ctx_id_t *context_handle,
14     gss_name_t target_name,
15     gss_OID mech_type,
16     OM_uint32 req_flags,
17     OM_uint32 time_req,
18     gss_channel_bindings_t unused_input_chan_bindings)
19 {
20   gss_buffer_desc input_token;
21   gss_OID actual_mech_type;
22   gss_buffer_desc output_token;
23   OM_uint32 ret_flags;
24   OM_uint32 time_rec;
25   
26   gss_cred_id_t cred_handle = GSS_C_NO_CREDENTIAL;
27   gss_channel_bindings_t input_chan_bindings = GSS_C_NO_CHANNEL_BINDINGS;
28   
29   /* Setup - input validation */
30   if (status == NULL)
31   {
32     /* nothing much to be done here */
33     return(GSS_S_CALL_INACCESSIBLE_WRITE);
34   }
35   
36   if (target_name == NULL)
37   {
38     /* Kinda hard to do any meaningful processing here ... */
39     status->major = GSS_S_CALL_INACCESSIBLE_READ;
40     return(1);
41   }
42   else
43   {
44     OM_uint32 maj;
45     OM_uint32 min;
46     gss_buffer_desc printable;
47     gss_OID nametype;
48
49     maj = gss_display_name(&min, target_name, &printable, &nametype);
50     
51     fprintf(stderr, "target_name:\n");
52     fprintf(stderr, "    value: %s\n", (char *)(printable.value) );
53     fprintf(stderr, "    nametype: [ length: %u, elements: %s ]\n",
54             nametype->length,
55             (char *)(nametype->elements));
56   }
57   
58   if (mech_type == NULL)
59   {
60     fprintf(stderr, "NULL mech_type; putting in one for SPNEGO\n");
61     /* Defaut to SPNEGO - 1.3.6.1.5.5.2 */
62     OM_uint32 maj = 0;
63     OM_uint32 min = 0;
64     gss_buffer_desc spnego_str;
65
66     char *elems;
67     
68     spnego_str.value = "1.3.6.1.5.5.2";
69     spnego_str.length = 13;
70     mech_type = (gss_OID)malloc(sizeof(gss_OID_desc));
71     maj = gss_str_to_oid(&min, &spnego_str, &mech_type);
72
73     elems = (char *)malloc(mech_type->length + 1);
74     strncpy(elems, (char *)(mech_type->elements), mech_type->length);
75     elems[mech_type->length] = '\0';
76     fprintf(stderr, "str_to_oid major/minor %u/%u\n", maj, min);
77     fprintf(stderr, "mech_type: [length: %u, elements: %s]\n",
78             mech_type->length,
79             elems);
80   }
81   /* mech_type = GSS_C_NO_OID; */
82   
83   /* Main processing */
84   
85   status->major = gss_init_sec_context(&(status->minor),
86                                        cred_handle,
87                                        context_handle,
88                                        target_name,
89                                        mech_type,
90                                        req_flags,
91                                        time_req,
92                                        input_chan_bindings,
93                                        &input_token,
94                                        &actual_mech_type,
95                                        &output_token,
96                                        &ret_flags,
97                                        &time_rec);
98
99   if (status->major != 0)
100   {
101     OM_uint32 maj;
102     OM_uint32 min;
103     OM_uint32 context = 0;
104     gss_buffer_desc statbuf;
105     
106     fprintf(stderr, "major status is: 0x%x\n", status->major);
107     do {
108       maj = gss_display_status(&min, status->major, GSS_C_GSS_CODE, 
109                                mech_type, &context, &statbuf);
110       fprintf(stderr, "Major status: %s\n", (char *)(statbuf.value));
111     } while(context != 0);
112     
113     if (actual_mech_type == NULL)
114       fprintf(stderr, "actual mech type is NULL.\n");
115     else
116     {
117       fprintf(stderr, "actual_mech_type: [length: %u, elements: %s]\n",
118               actual_mech_type->length,
119               (char *)(actual_mech_type->elements));
120     }
121     
122   }
123   if (status->minor != 0)
124   {
125     OM_uint32 maj;
126     OM_uint32 min;
127     OM_uint32 context = 0;
128     gss_buffer_desc statbuf;
129
130     fprintf(stderr, "minor status is: %d/0x%x/%s\n", 
131             status->minor, 
132             status->minor, 
133             strerror(status->minor));
134     do {
135       maj = gss_display_status(&min, status->minor, GSS_C_MECH_CODE, 
136                                GSS_C_NO_OID, &context, &statbuf);
137       fprintf(stderr, "Minor status: %s\n", (char *)(statbuf.value));
138     } while(context != 0);
139   }    
140   return(0);
141 }
142