00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "internal.h"
00024
00025 static char **
00026 map (Gsasl_session * sctx, Gsasl_property prop)
00027 {
00028 char **p = NULL;
00029
00030 if (!sctx)
00031 return NULL;
00032
00033 switch (prop)
00034 {
00035 case GSASL_ANONYMOUS_TOKEN:
00036 p = &sctx->anonymous_token;
00037 break;
00038
00039 case GSASL_SERVICE:
00040 p = &sctx->service;
00041 break;
00042
00043 case GSASL_HOSTNAME:
00044 p = &sctx->hostname;
00045 break;
00046
00047 case GSASL_AUTHID:
00048 p = &sctx->authid;
00049 break;
00050
00051 case GSASL_AUTHZID:
00052 p = &sctx->authzid;
00053 break;
00054
00055 case GSASL_PASSWORD:
00056 p = &sctx->password;
00057 break;
00058
00059 case GSASL_PASSCODE:
00060 p = &sctx->passcode;
00061 break;
00062
00063 case GSASL_PIN:
00064 p = &sctx->pin;
00065 break;
00066
00067 case GSASL_SUGGESTED_PIN:
00068 p = &sctx->suggestedpin;
00069 break;
00070
00071 case GSASL_GSSAPI_DISPLAY_NAME:
00072 p = &sctx->gssapi_display_name;
00073 break;
00074
00075 case GSASL_REALM:
00076 p = &sctx->realm;
00077 break;
00078
00079 default:
00080 break;
00081 }
00082
00083 return p;
00084 }
00085
00101 void
00102 gsasl_property_set (Gsasl_session * sctx, Gsasl_property prop,
00103 const char *data)
00104 {
00105 gsasl_property_set_raw (sctx, prop, data, data ? strlen (data) : 0);
00106 }
00107
00127 void
00128 gsasl_property_set_raw (Gsasl_session * sctx, Gsasl_property prop,
00129 const char *data, size_t len)
00130 {
00131 char **p = map (sctx, prop);
00132
00133 if (p)
00134 {
00135 if (*p)
00136 free (*p);
00137 if (data)
00138 {
00139 *p = malloc (len + 1);
00140 if (*p)
00141 {
00142 memcpy (*p, data, len);
00143 (*p)[len] = '\0';
00144 }
00145 }
00146 else
00147 *p = NULL;
00148 }
00149 }
00150
00170 const char *
00171 gsasl_property_fast (Gsasl_session * sctx, Gsasl_property prop)
00172 {
00173 char **p = map (sctx, prop);
00174
00175 if (p)
00176 return *p;
00177
00178 return NULL;
00179 }
00180
00207 const char *
00208 gsasl_property_get (Gsasl_session * sctx, Gsasl_property prop)
00209 {
00210 const char *p = gsasl_property_fast (sctx, prop);
00211
00212 if (!p)
00213 {
00214 gsasl_callback (NULL, sctx, prop);
00215 p = gsasl_property_fast (sctx, prop);
00216 }
00217
00218 #ifndef GSASL_NO_OBSOLETE
00219 if (!p)
00220 {
00221 Gsasl_client_callback_anonymous cb_anonymous;
00222 Gsasl_client_callback_authorization_id cb_authorization_id;
00223 Gsasl_client_callback_authentication_id cb_authentication_id;
00224 Gsasl_client_callback_password cb_password;
00225 Gsasl_client_callback_passcode cb_passcode;
00226 Gsasl_client_callback_pin cb_pin;
00227 Gsasl_client_callback_service cb_service;
00228 Gsasl_client_callback_realm cb_realm;
00229 char buf[BUFSIZ];
00230 size_t buflen = BUFSIZ - 1;
00231 int res;
00232
00233 buf[0] = '\0';
00234
00235
00236
00237
00238 switch (prop)
00239 {
00240 case GSASL_SERVICE:
00241 cb_service = gsasl_client_callback_service_get (sctx->ctx);
00242 if (!cb_service)
00243 break;
00244 res = cb_service (sctx, buf, &buflen, NULL, 0, NULL, 0);
00245 if (res != GSASL_OK)
00246 break;
00247 buf[buflen] = '\0';
00248 gsasl_property_set (sctx, prop, buf);
00249 break;
00250
00251 case GSASL_HOSTNAME:
00252 cb_service = gsasl_client_callback_service_get (sctx->ctx);
00253 if (!cb_service)
00254 break;
00255 res = cb_service (sctx, NULL, 0, buf, &buflen, NULL, 0);
00256 if (res != GSASL_OK)
00257 break;
00258 buf[buflen] = '\0';
00259 gsasl_property_set (sctx, prop, buf);
00260 break;
00261
00262 case GSASL_ANONYMOUS_TOKEN:
00263 cb_anonymous = gsasl_client_callback_anonymous_get (sctx->ctx);
00264 if (!cb_anonymous)
00265 break;
00266 res = cb_anonymous (sctx, buf, &buflen);
00267 if (res != GSASL_OK)
00268 break;
00269 buf[buflen] = '\0';
00270 gsasl_property_set (sctx, prop, buf);
00271 break;
00272
00273 case GSASL_AUTHID:
00274 cb_authentication_id =
00275 gsasl_client_callback_authentication_id_get (sctx->ctx);
00276 if (!cb_authentication_id)
00277 break;
00278 res = cb_authentication_id (sctx, buf, &buflen);
00279 if (res != GSASL_OK)
00280 break;
00281 buf[buflen] = '\0';
00282 gsasl_property_set (sctx, prop, buf);
00283 break;
00284
00285 case GSASL_AUTHZID:
00286 cb_authorization_id =
00287 gsasl_client_callback_authorization_id_get (sctx->ctx);
00288 if (!cb_authorization_id)
00289 break;
00290 res = cb_authorization_id (sctx, buf, &buflen);
00291 if (res != GSASL_OK)
00292 break;
00293 buf[buflen] = '\0';
00294 gsasl_property_set (sctx, prop, buf);
00295 break;
00296
00297 case GSASL_PASSWORD:
00298 cb_password = gsasl_client_callback_password_get (sctx->ctx);
00299 if (!cb_password)
00300 break;
00301 res = cb_password (sctx, buf, &buflen);
00302 if (res != GSASL_OK)
00303 break;
00304 buf[buflen] = '\0';
00305 gsasl_property_set (sctx, prop, buf);
00306 break;
00307
00308 case GSASL_PASSCODE:
00309 cb_passcode = gsasl_client_callback_passcode_get (sctx->ctx);
00310 if (!cb_passcode)
00311 break;
00312 res = cb_passcode (sctx, buf, &buflen);
00313 if (res != GSASL_OK)
00314 break;
00315 buf[buflen] = '\0';
00316 gsasl_property_set (sctx, prop, buf);
00317 break;
00318
00319 case GSASL_PIN:
00320 cb_pin = gsasl_client_callback_pin_get (sctx->ctx);
00321 if (!cb_pin)
00322 break;
00323 res = cb_pin (sctx, sctx->suggestedpin, buf, &buflen);
00324 if (res != GSASL_OK)
00325 break;
00326 buf[buflen] = '\0';
00327 gsasl_property_set (sctx, prop, buf);
00328 break;
00329
00330 case GSASL_REALM:
00331 cb_realm = gsasl_client_callback_realm_get (sctx->ctx);
00332 if (!cb_realm)
00333 break;
00334 res = cb_realm (sctx, buf, &buflen);
00335 if (res != GSASL_OK)
00336 break;
00337 buf[buflen] = '\0';
00338 gsasl_property_set (sctx, prop, buf);
00339 break;
00340
00341
00342 default:
00343 break;
00344 }
00345 p = gsasl_property_fast (sctx, prop);
00346 }
00347 #endif
00348
00349 return p;
00350 }