Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 # include "config.h"
00025 #endif
00026
00027
00028 #include "saml20.h"
00029
00030
00031 #include <string.h>
00032
00033
00034 #include <stdlib.h>
00035
00036
00037 #include "mechtools.h"
00038
00039 struct saml20_server_state
00040 {
00041 int step;
00042 };
00043
00044 int
00045 _gsasl_saml20_server_start (Gsasl_session * sctx, void **mech_data)
00046 {
00047 struct saml20_server_state *state;
00048
00049 state = (struct saml20_server_state *) calloc (sizeof (*state), 1);
00050 if (state == NULL)
00051 return GSASL_MALLOC_ERROR;
00052
00053 *mech_data = state;
00054
00055 return GSASL_OK;
00056 }
00057
00058 int
00059 _gsasl_saml20_server_step (Gsasl_session * sctx,
00060 void *mech_data,
00061 const char *input, size_t input_len,
00062 char **output, size_t * output_len)
00063 {
00064 struct saml20_server_state *state = mech_data;
00065 int res = GSASL_MECHANISM_CALLED_TOO_MANY_TIMES;
00066
00067 *output_len = 0;
00068 *output = NULL;
00069
00070 switch (state->step)
00071 {
00072 case 0:
00073 {
00074 const char *p;
00075 char *authzid;
00076 size_t headerlen;
00077
00078 if (input_len == 0)
00079 return GSASL_NEEDS_MORE;
00080
00081 res = _gsasl_parse_gs2_header (input, input_len,
00082 &authzid, &headerlen);
00083 if (res != GSASL_OK)
00084 return res;
00085
00086 if (authzid)
00087 {
00088 gsasl_property_set (sctx, GSASL_AUTHZID, authzid);
00089 free (authzid);
00090 }
00091
00092 input += headerlen;
00093 input_len -= headerlen;
00094
00095 gsasl_property_set_raw (sctx, GSASL_SAML20_IDP_IDENTIFIER,
00096 input, input_len);
00097
00098 p = gsasl_property_get (sctx, GSASL_SAML20_REDIRECT_URL);
00099 if (!p || !*p)
00100 return GSASL_NO_SAML20_REDIRECT_URL;
00101
00102 *output_len = strlen (p);
00103 *output = malloc (*output_len);
00104 if (!*output)
00105 return GSASL_MALLOC_ERROR;
00106
00107 memcpy (*output, p, *output_len);
00108
00109 res = GSASL_NEEDS_MORE;
00110 state->step++;
00111 break;
00112 }
00113
00114 case 1:
00115 {
00116 res = gsasl_callback (NULL, sctx, GSASL_VALIDATE_SAML20);
00117 state->step++;
00118 break;
00119 }
00120
00121 default:
00122 break;
00123 }
00124
00125 return res;
00126 }
00127
00128 void
00129 _gsasl_saml20_server_finish (Gsasl_session * sctx, void *mech_data)
00130 {
00131 struct saml20_server_state *state = mech_data;
00132
00133 if (!state)
00134 return;
00135
00136 free (state);
00137 }