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
00041 int
00042 gsasl_client_listmech (Gsasl * ctx, char *out, size_t * outlen)
00043 {
00044 char *tmp;
00045 int rc;
00046
00047 rc = gsasl_client_mechlist (ctx, &tmp);
00048
00049 if (rc == GSASL_OK)
00050 {
00051 size_t tmplen = strlen (tmp);
00052
00053 if (tmplen >= *outlen)
00054 {
00055 free (tmp);
00056 return GSASL_TOO_SMALL_BUFFER;
00057 }
00058
00059 if (out)
00060 strcpy (out, tmp);
00061 *outlen = tmplen + 1;
00062 free (tmp);
00063 }
00064
00065 return rc;
00066 }
00067
00084 int
00085 gsasl_server_listmech (Gsasl * ctx, char *out, size_t * outlen)
00086 {
00087 char *tmp;
00088 int rc;
00089
00090 rc = gsasl_server_mechlist (ctx, &tmp);
00091
00092 if (rc == GSASL_OK)
00093 {
00094 size_t tmplen = strlen (tmp);
00095
00096 if (tmplen >= *outlen)
00097 {
00098 free (tmp);
00099 return GSASL_TOO_SMALL_BUFFER;
00100 }
00101
00102 if (out)
00103 strcpy (out, tmp);
00104 *outlen = tmplen + 1;
00105 free (tmp);
00106 }
00107
00108 return rc;
00109 }
00110
00111 static int
00112 _gsasl_step (Gsasl_session * sctx,
00113 const char *input, size_t input_len,
00114 char *output, size_t * output_len)
00115 {
00116 char *tmp;
00117 size_t tmplen;
00118 int rc;
00119
00120 rc = gsasl_step (sctx, input, input_len, &tmp, &tmplen);
00121
00122 if (rc == GSASL_OK || rc == GSASL_NEEDS_MORE)
00123 {
00124 if (tmplen >= *output_len)
00125 {
00126 free (tmp);
00127
00128 return GSASL_TOO_SMALL_BUFFER;
00129 }
00130
00131 if (output)
00132 memcpy (output, tmp, tmplen);
00133 *output_len = tmplen;
00134 free (tmp);
00135 }
00136
00137 return rc;
00138 }
00139
00162 int
00163 gsasl_client_step (Gsasl_session * sctx,
00164 const char *input,
00165 size_t input_len, char *output, size_t * output_len)
00166 {
00167 return _gsasl_step (sctx, input, input_len, output, output_len);
00168 }
00169
00192 int
00193 gsasl_server_step (Gsasl_session * sctx,
00194 const char *input,
00195 size_t input_len, char *output, size_t * output_len)
00196 {
00197 return _gsasl_step (sctx, input, input_len, output, output_len);
00198 }
00199
00200 static int
00201 _gsasl_step64 (Gsasl_session * sctx,
00202 const char *b64input, char *b64output, size_t b64output_len)
00203 {
00204 char *tmp;
00205 int rc;
00206
00207 rc = gsasl_step64 (sctx, b64input, &tmp);
00208
00209 if (rc == GSASL_OK || rc == GSASL_NEEDS_MORE)
00210 {
00211 if (b64output_len <= strlen (tmp))
00212 {
00213 free (tmp);
00214
00215 return GSASL_TOO_SMALL_BUFFER;
00216 }
00217
00218 if (b64output)
00219 strcpy (b64output, tmp);
00220 free (tmp);
00221 }
00222
00223 return rc;
00224 }
00225
00240 int
00241 gsasl_client_step_base64 (Gsasl_session * sctx,
00242 const char *b64input,
00243 char *b64output, size_t b64output_len)
00244 {
00245 return _gsasl_step64 (sctx, b64input, b64output, b64output_len);
00246 }
00247
00262 int
00263 gsasl_server_step_base64 (Gsasl_session * sctx,
00264 const char *b64input,
00265 char *b64output, size_t b64output_len)
00266 {
00267 return _gsasl_step64 (sctx, b64input, b64output, b64output_len);
00268 }
00269
00279 void
00280 gsasl_client_finish (Gsasl_session * sctx)
00281 {
00282 gsasl_finish (sctx);
00283 }
00284
00294 void
00295 gsasl_server_finish (Gsasl_session * sctx)
00296 {
00297 gsasl_finish (sctx);
00298 }
00299
00308 Gsasl *
00309 gsasl_client_ctx_get (Gsasl_session * sctx)
00310 {
00311 return sctx->ctx;
00312 }
00313
00328 void
00329 gsasl_client_application_data_set (Gsasl_session * sctx,
00330 void *application_data)
00331 {
00332 gsasl_appinfo_set (sctx, application_data);
00333 }
00334
00349 void *
00350 gsasl_client_application_data_get (Gsasl_session * sctx)
00351 {
00352 return gsasl_appinfo_get (sctx);
00353 }
00354
00363 Gsasl *
00364 gsasl_server_ctx_get (Gsasl_session * sctx)
00365 {
00366 return sctx->ctx;
00367 }
00368
00383 void
00384 gsasl_server_application_data_set (Gsasl_session * sctx,
00385 void *application_data)
00386 {
00387 gsasl_appinfo_set (sctx, application_data);
00388 }
00389
00404 void *
00405 gsasl_server_application_data_get (Gsasl_session * sctx)
00406 {
00407 return gsasl_appinfo_get (sctx);
00408 }
00409
00423 int
00424 gsasl_randomize (int strong, char *data, size_t datalen)
00425 {
00426 if (strong)
00427 return gsasl_random (data, datalen);
00428 return gsasl_nonce (data, datalen);
00429 }
00430
00439 Gsasl *
00440 gsasl_ctx_get (Gsasl_session * sctx)
00441 {
00442 return sctx->ctx;
00443 }
00444
00463 int
00464 gsasl_encode_inline (Gsasl_session * sctx,
00465 const char *input, size_t input_len,
00466 char *output, size_t * output_len)
00467 {
00468 char *tmp;
00469 size_t tmplen;
00470 int res;
00471
00472 res = gsasl_encode (sctx, input, input_len, &tmp, &tmplen);
00473 if (res == GSASL_OK)
00474 {
00475 if (*output_len < tmplen)
00476 return GSASL_TOO_SMALL_BUFFER;
00477 *output_len = tmplen;
00478 memcpy (output, tmp, tmplen);
00479 free (output);
00480 }
00481
00482 return res;
00483 }
00484
00503 int
00504 gsasl_decode_inline (Gsasl_session * sctx,
00505 const char *input, size_t input_len,
00506 char *output, size_t * output_len)
00507 {
00508 char *tmp;
00509 size_t tmplen;
00510 int res;
00511
00512 res = gsasl_decode (sctx, input, input_len, &tmp, &tmplen);
00513 if (res == GSASL_OK)
00514 {
00515 if (*output_len < tmplen)
00516 return GSASL_TOO_SMALL_BUFFER;
00517 *output_len = tmplen;
00518 memcpy (output, tmp, tmplen);
00519 free (output);
00520 }
00521
00522 return res;
00523 }
00524
00538 void
00539 gsasl_application_data_set (Gsasl * ctx, void *appdata)
00540 {
00541 ctx->application_hook = appdata;
00542 }
00543
00557 void *
00558 gsasl_application_data_get (Gsasl * ctx)
00559 {
00560 return ctx->application_hook;
00561 }
00562
00576 void
00577 gsasl_appinfo_set (Gsasl_session * sctx, void *appdata)
00578 {
00579 sctx->application_data = appdata;
00580 }
00581
00595 void *
00596 gsasl_appinfo_get (Gsasl_session * sctx)
00597 {
00598 return sctx->application_data;
00599 }
00600
00613 const char *
00614 gsasl_server_suggest_mechanism (Gsasl * ctx, const char *mechlist)
00615 {
00616 return NULL;
00617 }
00618
00633 void
00634 gsasl_client_callback_authentication_id_set (Gsasl * ctx,
00635 Gsasl_client_callback_authentication_id
00636 cb)
00637 {
00638 ctx->cbc_authentication_id = cb;
00639 }
00640
00653 Gsasl_client_callback_authentication_id
00654 gsasl_client_callback_authentication_id_get (Gsasl * ctx)
00655 {
00656 return ctx ? ctx->cbc_authentication_id : NULL;
00657 }
00658
00673 void
00674 gsasl_client_callback_authorization_id_set (Gsasl * ctx,
00675 Gsasl_client_callback_authorization_id
00676 cb)
00677 {
00678 ctx->cbc_authorization_id = cb;
00679 }
00680
00693 Gsasl_client_callback_authorization_id
00694 gsasl_client_callback_authorization_id_get (Gsasl * ctx)
00695 {
00696 return ctx ? ctx->cbc_authorization_id : NULL;
00697 }
00698
00713 void
00714 gsasl_client_callback_password_set (Gsasl * ctx,
00715 Gsasl_client_callback_password cb)
00716 {
00717 ctx->cbc_password = cb;
00718 }
00719
00720
00733 Gsasl_client_callback_password
00734 gsasl_client_callback_password_get (Gsasl * ctx)
00735 {
00736 return ctx ? ctx->cbc_password : NULL;
00737 }
00738
00753 void
00754 gsasl_client_callback_passcode_set (Gsasl * ctx,
00755 Gsasl_client_callback_passcode cb)
00756 {
00757 ctx->cbc_passcode = cb;
00758 }
00759
00760
00773 Gsasl_client_callback_passcode
00774 gsasl_client_callback_passcode_get (Gsasl * ctx)
00775 {
00776 return ctx ? ctx->cbc_passcode : NULL;
00777 }
00778
00795 void
00796 gsasl_client_callback_pin_set (Gsasl * ctx, Gsasl_client_callback_pin cb)
00797 {
00798 ctx->cbc_pin = cb;
00799 }
00800
00801
00814 Gsasl_client_callback_pin
00815 gsasl_client_callback_pin_get (Gsasl * ctx)
00816 {
00817 return ctx ? ctx->cbc_pin : NULL;
00818 }
00819
00837 void
00838 gsasl_client_callback_service_set (Gsasl * ctx,
00839 Gsasl_client_callback_service cb)
00840 {
00841 ctx->cbc_service = cb;
00842 }
00843
00856 Gsasl_client_callback_service
00857 gsasl_client_callback_service_get (Gsasl * ctx)
00858 {
00859 return ctx ? ctx->cbc_service : NULL;
00860 }
00861
00877 void
00878 gsasl_client_callback_anonymous_set (Gsasl * ctx,
00879 Gsasl_client_callback_anonymous cb)
00880 {
00881 ctx->cbc_anonymous = cb;
00882 }
00883
00896 Gsasl_client_callback_anonymous
00897 gsasl_client_callback_anonymous_get (Gsasl * ctx)
00898 {
00899 return ctx ? ctx->cbc_anonymous : NULL;
00900 }
00901
00916 void
00917 gsasl_client_callback_qop_set (Gsasl * ctx, Gsasl_client_callback_qop cb)
00918 {
00919 ctx->cbc_qop = cb;
00920 }
00921
00934 Gsasl_client_callback_qop
00935 gsasl_client_callback_qop_get (Gsasl * ctx)
00936 {
00937 return ctx ? ctx->cbc_qop : NULL;
00938 }
00939
00957 void
00958 gsasl_client_callback_maxbuf_set (Gsasl * ctx,
00959 Gsasl_client_callback_maxbuf cb)
00960 {
00961 ctx->cbc_maxbuf = cb;
00962 }
00963
00976 Gsasl_client_callback_maxbuf
00977 gsasl_client_callback_maxbuf_get (Gsasl * ctx)
00978 {
00979 return ctx ? ctx->cbc_maxbuf : NULL;
00980 }
00981
00997 void
00998 gsasl_client_callback_realm_set (Gsasl * ctx, Gsasl_client_callback_realm cb)
00999 {
01000 ctx->cbc_realm = cb;
01001 }
01002
01015 Gsasl_client_callback_realm
01016 gsasl_client_callback_realm_get (Gsasl * ctx)
01017 {
01018 return ctx ? ctx->cbc_realm : NULL;
01019 }
01020
01036 void
01037 gsasl_server_callback_validate_set (Gsasl * ctx,
01038 Gsasl_server_callback_validate cb)
01039 {
01040 ctx->cbs_validate = cb;
01041 }
01042
01055 Gsasl_server_callback_validate
01056 gsasl_server_callback_validate_get (Gsasl * ctx)
01057 {
01058 return ctx ? ctx->cbs_validate : NULL;
01059 }
01060
01076 void
01077 gsasl_server_callback_retrieve_set (Gsasl * ctx,
01078 Gsasl_server_callback_retrieve cb)
01079 {
01080 ctx->cbs_retrieve = cb;
01081 }
01082
01095 Gsasl_server_callback_retrieve
01096 gsasl_server_callback_retrieve_get (Gsasl * ctx)
01097 {
01098 return ctx ? ctx->cbs_retrieve : NULL;
01099 }
01100
01116 void
01117 gsasl_server_callback_cram_md5_set (Gsasl * ctx,
01118 Gsasl_server_callback_cram_md5 cb)
01119 {
01120 ctx->cbs_cram_md5 = cb;
01121 }
01122
01135 Gsasl_server_callback_cram_md5
01136 gsasl_server_callback_cram_md5_get (Gsasl * ctx)
01137 {
01138 return ctx ? ctx->cbs_cram_md5 : NULL;
01139 }
01140
01156 void
01157 gsasl_server_callback_digest_md5_set (Gsasl * ctx,
01158 Gsasl_server_callback_digest_md5 cb)
01159 {
01160 ctx->cbs_digest_md5 = cb;
01161 }
01162
01175 Gsasl_server_callback_digest_md5
01176 gsasl_server_callback_digest_md5_get (Gsasl * ctx)
01177 {
01178 return ctx->cbs_digest_md5;
01179 }
01180
01195 void
01196 gsasl_server_callback_external_set (Gsasl * ctx,
01197 Gsasl_server_callback_external cb)
01198 {
01199 ctx->cbs_external = cb;
01200 }
01201
01214 Gsasl_server_callback_external
01215 gsasl_server_callback_external_get (Gsasl * ctx)
01216 {
01217 return ctx ? ctx->cbs_external : NULL;
01218 }
01219
01234 void
01235 gsasl_server_callback_anonymous_set (Gsasl * ctx,
01236 Gsasl_server_callback_anonymous cb)
01237 {
01238 ctx->cbs_anonymous = cb;
01239 }
01240
01253 Gsasl_server_callback_anonymous
01254 gsasl_server_callback_anonymous_get (Gsasl * ctx)
01255 {
01256 return ctx ? ctx->cbs_anonymous : NULL;
01257 }
01258
01274 void
01275 gsasl_server_callback_realm_set (Gsasl * ctx, Gsasl_server_callback_realm cb)
01276 {
01277 ctx->cbs_realm = cb;
01278 }
01279
01292 Gsasl_server_callback_realm
01293 gsasl_server_callback_realm_get (Gsasl * ctx)
01294 {
01295 return ctx ? ctx->cbs_realm : NULL;
01296 }
01297
01314 void
01315 gsasl_server_callback_qop_set (Gsasl * ctx, Gsasl_server_callback_qop cb)
01316 {
01317 ctx->cbs_qop = cb;
01318 }
01319
01332 Gsasl_server_callback_qop
01333 gsasl_server_callback_qop_get (Gsasl * ctx)
01334 {
01335 return ctx ? ctx->cbs_qop : NULL;
01336 }
01337
01355 void
01356 gsasl_server_callback_maxbuf_set (Gsasl * ctx,
01357 Gsasl_server_callback_maxbuf cb)
01358 {
01359 ctx->cbs_maxbuf = cb;
01360 }
01361
01374 Gsasl_server_callback_maxbuf
01375 gsasl_server_callback_maxbuf_get (Gsasl * ctx)
01376 {
01377 return ctx ? ctx->cbs_maxbuf : NULL;
01378 }
01379
01396 void
01397 gsasl_server_callback_cipher_set (Gsasl * ctx,
01398 Gsasl_server_callback_cipher cb)
01399 {
01400 ctx->cbs_cipher = cb;
01401 }
01402
01415 Gsasl_server_callback_cipher
01416 gsasl_server_callback_cipher_get (Gsasl * ctx)
01417 {
01418 return ctx ? ctx->cbs_cipher : NULL;
01419 }
01420
01442 void
01443 gsasl_server_callback_securid_set (Gsasl * ctx,
01444 Gsasl_server_callback_securid cb)
01445 {
01446 ctx->cbs_securid = cb;
01447 }
01448
01461 Gsasl_server_callback_securid
01462 gsasl_server_callback_securid_get (Gsasl * ctx)
01463 {
01464 return ctx ? ctx->cbs_securid : NULL;
01465 }
01466
01484 void
01485 gsasl_server_callback_gssapi_set (Gsasl * ctx,
01486 Gsasl_server_callback_gssapi cb)
01487 {
01488 ctx->cbs_gssapi = cb;
01489 }
01490
01503 Gsasl_server_callback_gssapi
01504 gsasl_server_callback_gssapi_get (Gsasl * ctx)
01505 {
01506 return ctx ? ctx->cbs_gssapi : NULL;
01507 }
01508
01525 void
01526 gsasl_server_callback_service_set (Gsasl * ctx,
01527 Gsasl_server_callback_service cb)
01528 {
01529 ctx->cbs_service = cb;
01530 }
01531
01544 Gsasl_server_callback_service
01545 gsasl_server_callback_service_get (Gsasl * ctx)
01546 {
01547 return ctx ? ctx->cbs_service : NULL;
01548 }
01549
01550 #if WITH_SASLPREP
01551 # include <stringprep.h>
01552 #endif
01553
01580 char *
01581 gsasl_stringprep_nfkc (const char *in, ssize_t len)
01582 {
01583 char *out = NULL;
01584
01585 #if WITH_SASLPREP
01586 out = stringprep_utf8_nfkc_normalize (in, len);
01587 #endif
01588
01589 return out;
01590 }
01591
01611 char *
01612 gsasl_stringprep_saslprep (const char *in, int *stringprep_rc)
01613 {
01614 char *out = NULL;
01615 #if WITH_SASLPREP
01616 int rc;
01617
01618 rc = stringprep_profile (in, &out, "SASLprep", 0);
01619 if (stringprep_rc)
01620 *stringprep_rc = rc;
01621 if (rc != STRINGPREP_OK)
01622 out = NULL;
01623 #endif
01624
01625 return out;
01626 }
01627
01645 char *
01646 gsasl_stringprep_trace (const char *in, int *stringprep_rc)
01647 {
01648 char *out = NULL;
01649 #if WITH_SASLPREP
01650 int rc;
01651
01652 rc = stringprep_profile (in, &out, "trace", 0);
01653 if (stringprep_rc)
01654 *stringprep_rc = rc;
01655 if (rc != STRINGPREP_OK)
01656 out = NULL;
01657 #endif
01658
01659 return out;
01660 }
01661
01686 int
01687 gsasl_md5pwd_get_password (const char *filename,
01688 const char *username, char *key, size_t * keylen)
01689 {
01690 char matchbuf[BUFSIZ];
01691 char line[BUFSIZ];
01692 FILE *fh;
01693
01694 fh = fopen (filename, "r");
01695 if (fh == NULL)
01696 return GSASL_FOPEN_ERROR;
01697
01698 sprintf (matchbuf, "%s\t", username);
01699
01700 while (!feof (fh))
01701 {
01702 if (fgets (line, BUFSIZ, fh) == NULL)
01703 break;
01704
01705 if (line[0] == '#')
01706 continue;
01707
01708 while (strlen (line) > 0 && (line[strlen (line) - 1] == '\n' ||
01709 line[strlen (line) - 1] == '\r'))
01710 line[strlen (line) - 1] = '\0';
01711
01712 if (strlen (line) <= strlen (matchbuf))
01713 continue;
01714
01715 if (strncmp (matchbuf, line, strlen (matchbuf)) == 0)
01716 {
01717 if (*keylen < strlen (line) - strlen (matchbuf))
01718 {
01719 fclose (fh);
01720 return GSASL_TOO_SMALL_BUFFER;
01721 }
01722
01723 *keylen = strlen (line) - strlen (matchbuf);
01724
01725 if (key)
01726 memcpy (key, &line[strlen (matchbuf)], *keylen);
01727
01728 fclose (fh);
01729
01730 return GSASL_OK;
01731 }
01732 }
01733
01734 if (fclose (fh) != 0)
01735 return GSASL_FCLOSE_ERROR;
01736
01737 return GSASL_AUTHENTICATION_ERROR;
01738 }
01739
01740 #include <minmax.h>
01741
01758 int
01759 gsasl_base64_encode (char const *src,
01760 size_t srclength, char *target, size_t targsize)
01761 {
01762 int rc;
01763 char *out;
01764 size_t outlen;
01765 int copied;
01766
01767 rc = gsasl_base64_to (src, srclength, &out, &outlen);
01768 if (rc)
01769 return -1;
01770
01771 copied = MIN (outlen, targsize);
01772 memcpy (target, out, copied);
01773 free (out);
01774
01775 return copied;
01776 }
01777
01793 int
01794 gsasl_base64_decode (char const *src, char *target, size_t targsize)
01795 {
01796 int rc;
01797 char *out;
01798 size_t outlen;
01799 int copied;
01800
01801 rc = gsasl_base64_from (src, strlen (src), &out, &outlen);
01802 if (rc)
01803 return -1;
01804
01805 copied = MIN (outlen, targsize);
01806 memcpy (target, out, copied);
01807 free (out);
01808
01809 return copied;
01810 }
01811
01812 const char *
01813 _gsasl_obsolete_property_map (Gsasl_session * sctx, Gsasl_property prop)
01814 {
01815 char buf[BUFSIZ];
01816 size_t buflen = BUFSIZ - 1;
01817 int res;
01818
01819 buf[0] = '\0';
01820
01821
01822
01823 switch (prop)
01824 {
01825 case GSASL_SERVICE:
01826 {
01827 Gsasl_client_callback_service cb_service
01828 = gsasl_client_callback_service_get (sctx->ctx);
01829 if (!cb_service)
01830 break;
01831 res = cb_service (sctx, buf, &buflen, NULL, 0, NULL, 0);
01832 if (res != GSASL_OK)
01833 break;
01834 buf[buflen] = '\0';
01835 gsasl_property_set (sctx, prop, buf);
01836 break;
01837 }
01838
01839 case GSASL_HOSTNAME:
01840 {
01841 Gsasl_client_callback_service cb_service
01842 = gsasl_client_callback_service_get (sctx->ctx);
01843 if (!cb_service)
01844 break;
01845 res = cb_service (sctx, NULL, 0, buf, &buflen, NULL, 0);
01846 if (res != GSASL_OK)
01847 break;
01848 buf[buflen] = '\0';
01849 gsasl_property_set (sctx, prop, buf);
01850 break;
01851 }
01852
01853 case GSASL_ANONYMOUS_TOKEN:
01854 {
01855 Gsasl_client_callback_anonymous cb_anonymous
01856 = gsasl_client_callback_anonymous_get (sctx->ctx);
01857 if (!cb_anonymous)
01858 break;
01859 res = cb_anonymous (sctx, buf, &buflen);
01860 if (res != GSASL_OK)
01861 break;
01862 buf[buflen] = '\0';
01863 gsasl_property_set (sctx, prop, buf);
01864 break;
01865 }
01866
01867 case GSASL_AUTHID:
01868 {
01869 Gsasl_client_callback_authentication_id cb_authentication_id
01870 = gsasl_client_callback_authentication_id_get (sctx->ctx);
01871 if (!cb_authentication_id)
01872 break;
01873 res = cb_authentication_id (sctx, buf, &buflen);
01874 if (res != GSASL_OK)
01875 break;
01876 buf[buflen] = '\0';
01877 gsasl_property_set (sctx, prop, buf);
01878 break;
01879 }
01880
01881 case GSASL_AUTHZID:
01882 {
01883 Gsasl_client_callback_authorization_id cb_authorization_id
01884 = gsasl_client_callback_authorization_id_get (sctx->ctx);
01885 if (!cb_authorization_id)
01886 break;
01887 res = cb_authorization_id (sctx, buf, &buflen);
01888 if (res != GSASL_OK)
01889 break;
01890 buf[buflen] = '\0';
01891 gsasl_property_set (sctx, prop, buf);
01892 break;
01893 }
01894
01895 case GSASL_PASSWORD:
01896 {
01897 Gsasl_client_callback_password cb_password
01898 = gsasl_client_callback_password_get (sctx->ctx);
01899 if (!cb_password)
01900 break;
01901 res = cb_password (sctx, buf, &buflen);
01902 if (res != GSASL_OK)
01903 break;
01904 buf[buflen] = '\0';
01905 gsasl_property_set (sctx, prop, buf);
01906 break;
01907 }
01908
01909 case GSASL_PASSCODE:
01910 {
01911 Gsasl_client_callback_passcode cb_passcode
01912 = gsasl_client_callback_passcode_get (sctx->ctx);
01913 if (!cb_passcode)
01914 break;
01915 res = cb_passcode (sctx, buf, &buflen);
01916 if (res != GSASL_OK)
01917 break;
01918 buf[buflen] = '\0';
01919 gsasl_property_set (sctx, prop, buf);
01920 break;
01921 }
01922
01923 case GSASL_PIN:
01924 {
01925 Gsasl_client_callback_pin cb_pin
01926 = gsasl_client_callback_pin_get (sctx->ctx);
01927 if (!cb_pin)
01928 break;
01929 res = cb_pin (sctx, sctx->suggestedpin, buf, &buflen);
01930 if (res != GSASL_OK)
01931 break;
01932 buf[buflen] = '\0';
01933 gsasl_property_set (sctx, prop, buf);
01934 break;
01935 }
01936
01937 case GSASL_REALM:
01938 {
01939 Gsasl_client_callback_realm cb_realm
01940 = gsasl_client_callback_realm_get (sctx->ctx);
01941 if (!cb_realm)
01942 break;
01943 res = cb_realm (sctx, buf, &buflen);
01944 if (res != GSASL_OK)
01945 break;
01946 buf[buflen] = '\0';
01947 gsasl_property_set (sctx, prop, buf);
01948 break;
01949 }
01950
01951 default:
01952 break;
01953 }
01954
01955 return gsasl_property_fast (sctx, prop);
01956 }
01957
01958 int
01959 _gsasl_obsolete_callback (Gsasl * ctx, Gsasl_session * sctx,
01960 Gsasl_property prop)
01961 {
01962 char buf[BUFSIZ];
01963 size_t buflen = BUFSIZ - 1;
01964 int res;
01965
01966
01967
01968 switch (prop)
01969 {
01970 case GSASL_VALIDATE_ANONYMOUS:
01971 {
01972 Gsasl_server_callback_anonymous cb_anonymous;
01973 if (!sctx->anonymous_token)
01974 break;
01975 cb_anonymous = gsasl_server_callback_anonymous_get (sctx->ctx);
01976 if (!cb_anonymous)
01977 break;
01978 res = cb_anonymous (sctx, sctx->anonymous_token);
01979 return res;
01980 break;
01981 }
01982
01983 case GSASL_VALIDATE_EXTERNAL:
01984 {
01985 Gsasl_server_callback_external cb_external
01986 = gsasl_server_callback_external_get (sctx->ctx);
01987 if (!cb_external)
01988 break;
01989 res = cb_external (sctx);
01990 return res;
01991 break;
01992 }
01993
01994 case GSASL_VALIDATE_SECURID:
01995 {
01996 Gsasl_server_callback_securid cb_securid
01997 = gsasl_server_callback_securid_get (sctx->ctx);
01998 if (!cb_securid)
01999 break;
02000 res = cb_securid (sctx, sctx->authid, sctx->authzid, sctx->passcode,
02001 sctx->pin, buf, &buflen);
02002 if (buflen > 0 && buflen < BUFSIZ - 1)
02003 {
02004 buf[buflen] = '\0';
02005 gsasl_property_set (sctx, GSASL_SUGGESTED_PIN, buf);
02006 }
02007 return res;
02008 break;
02009 }
02010
02011 case GSASL_VALIDATE_GSSAPI:
02012 {
02013 Gsasl_server_callback_gssapi cb_gssapi
02014 = gsasl_server_callback_gssapi_get (sctx->ctx);
02015 if (!cb_gssapi)
02016 break;
02017 res = cb_gssapi (sctx, sctx->gssapi_display_name, sctx->authzid);
02018 return res;
02019 break;
02020 }
02021
02022 case GSASL_VALIDATE_SIMPLE:
02023 {
02024 Gsasl_server_callback_validate cb_validate
02025 = gsasl_server_callback_validate_get (sctx->ctx);
02026 if (!cb_validate)
02027 break;
02028 res = cb_validate (sctx, sctx->authzid, sctx->authid, sctx->password);
02029 return res;
02030 break;
02031 }
02032
02033 case GSASL_PASSWORD:
02034 {
02035 Gsasl_server_callback_retrieve cb_retrieve
02036 = gsasl_server_callback_retrieve_get (sctx->ctx);
02037 if (!cb_retrieve)
02038 break;
02039 res = cb_retrieve (sctx, sctx->authid, sctx->authzid,
02040 sctx->hostname, buf, &buflen);
02041 if (res == GSASL_OK)
02042 gsasl_property_set_raw (sctx, GSASL_PASSWORD, buf, buflen);
02043
02044 return res;
02045 break;
02046 }
02047
02048 default:
02049 break;
02050 }
02051
02052 return GSASL_NO_CALLBACK;
02053 }