gsasl  1.8.0
obsolete.c
Go to the documentation of this file.
00001 /* obsolete.c --- Obsolete functions kept around for backwards compatibility.
00002  * Copyright (C) 2002-2012 Simon Josefsson
00003  *
00004  * This file is part of GNU SASL Library.
00005  *
00006  * GNU SASL Library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License
00008  * as published by the Free Software Foundation; either version 2.1 of
00009  * the License, or (at your option) any later version.
00010  *
00011  * GNU SASL Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License License along with GNU SASL Library; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "internal.h"
00024 
00025 #if USE_DIGEST_MD5
00026 #include "qop.h"
00027 #endif
00028 
00045 int
00046 gsasl_client_listmech (Gsasl * ctx, char *out, size_t * outlen)
00047 {
00048   char *tmp;
00049   int rc;
00050 
00051   rc = gsasl_client_mechlist (ctx, &tmp);
00052 
00053   if (rc == GSASL_OK)
00054     {
00055       size_t tmplen = strlen (tmp);
00056 
00057       if (tmplen >= *outlen)
00058         {
00059           free (tmp);
00060           return GSASL_TOO_SMALL_BUFFER;
00061         }
00062 
00063       if (out)
00064         strcpy (out, tmp);
00065       *outlen = tmplen + 1;
00066       free (tmp);
00067     }
00068 
00069   return rc;
00070 }
00071 
00088 int
00089 gsasl_server_listmech (Gsasl * ctx, char *out, size_t * outlen)
00090 {
00091   char *tmp;
00092   int rc;
00093 
00094   rc = gsasl_server_mechlist (ctx, &tmp);
00095 
00096   if (rc == GSASL_OK)
00097     {
00098       size_t tmplen = strlen (tmp);
00099 
00100       if (tmplen >= *outlen)
00101         {
00102           free (tmp);
00103           return GSASL_TOO_SMALL_BUFFER;
00104         }
00105 
00106       if (out)
00107         strcpy (out, tmp);
00108       *outlen = tmplen + 1;
00109       free (tmp);
00110     }
00111 
00112   return rc;
00113 }
00114 
00115 static int
00116 _gsasl_step (Gsasl_session * sctx,
00117              const char *input, size_t input_len,
00118              char *output, size_t * output_len)
00119 {
00120   char *tmp;
00121   size_t tmplen;
00122   int rc;
00123 
00124   rc = gsasl_step (sctx, input, input_len, &tmp, &tmplen);
00125 
00126   if (rc == GSASL_OK || rc == GSASL_NEEDS_MORE)
00127     {
00128       if (tmplen >= *output_len)
00129         {
00130           free (tmp);
00131           /* XXX We lose the step token here, don't we? */
00132           return GSASL_TOO_SMALL_BUFFER;
00133         }
00134 
00135       if (output)
00136         memcpy (output, tmp, tmplen);
00137       *output_len = tmplen;
00138       free (tmp);
00139     }
00140 
00141   return rc;
00142 }
00143 
00166 int
00167 gsasl_client_step (Gsasl_session * sctx,
00168                    const char *input,
00169                    size_t input_len, char *output, size_t * output_len)
00170 {
00171   return _gsasl_step (sctx, input, input_len, output, output_len);
00172 }
00173 
00196 int
00197 gsasl_server_step (Gsasl_session * sctx,
00198                    const char *input,
00199                    size_t input_len, char *output, size_t * output_len)
00200 {
00201   return _gsasl_step (sctx, input, input_len, output, output_len);
00202 }
00203 
00204 static int
00205 _gsasl_step64 (Gsasl_session * sctx,
00206                const char *b64input, char *b64output, size_t b64output_len)
00207 {
00208   char *tmp;
00209   int rc;
00210 
00211   rc = gsasl_step64 (sctx, b64input, &tmp);
00212 
00213   if (rc == GSASL_OK || rc == GSASL_NEEDS_MORE)
00214     {
00215       if (b64output_len <= strlen (tmp))
00216         {
00217           free (tmp);
00218           /* XXX We lose the step token here, don't we? */
00219           return GSASL_TOO_SMALL_BUFFER;
00220         }
00221 
00222       if (b64output)
00223         strcpy (b64output, tmp);
00224       free (tmp);
00225     }
00226 
00227   return rc;
00228 }
00229 
00244 int
00245 gsasl_client_step_base64 (Gsasl_session * sctx,
00246                           const char *b64input,
00247                           char *b64output, size_t b64output_len)
00248 {
00249   return _gsasl_step64 (sctx, b64input, b64output, b64output_len);
00250 }
00251 
00266 int
00267 gsasl_server_step_base64 (Gsasl_session * sctx,
00268                           const char *b64input,
00269                           char *b64output, size_t b64output_len)
00270 {
00271   return _gsasl_step64 (sctx, b64input, b64output, b64output_len);
00272 }
00273 
00283 void
00284 gsasl_client_finish (Gsasl_session * sctx)
00285 {
00286   gsasl_finish (sctx);
00287 }
00288 
00298 void
00299 gsasl_server_finish (Gsasl_session * sctx)
00300 {
00301   gsasl_finish (sctx);
00302 }
00303 
00314 Gsasl *
00315 gsasl_client_ctx_get (Gsasl_session * sctx)
00316 {
00317   return sctx->ctx;
00318 }
00319 
00334 void
00335 gsasl_client_application_data_set (Gsasl_session * sctx,
00336                                    void *application_data)
00337 {
00338   gsasl_appinfo_set (sctx, application_data);
00339 }
00340 
00355 void *
00356 gsasl_client_application_data_get (Gsasl_session * sctx)
00357 {
00358   return gsasl_appinfo_get (sctx);
00359 }
00360 
00371 Gsasl *
00372 gsasl_server_ctx_get (Gsasl_session * sctx)
00373 {
00374   return sctx->ctx;
00375 }
00376 
00391 void
00392 gsasl_server_application_data_set (Gsasl_session * sctx,
00393                                    void *application_data)
00394 {
00395   gsasl_appinfo_set (sctx, application_data);
00396 }
00397 
00412 void *
00413 gsasl_server_application_data_get (Gsasl_session * sctx)
00414 {
00415   return gsasl_appinfo_get (sctx);
00416 }
00417 
00431 int
00432 gsasl_randomize (int strong, char *data, size_t datalen)
00433 {
00434   if (strong)
00435     return gsasl_random (data, datalen);
00436   return gsasl_nonce (data, datalen);
00437 }
00438 
00449 Gsasl *
00450 gsasl_ctx_get (Gsasl_session * sctx)
00451 {
00452   return sctx->ctx;
00453 }
00454 
00473 int
00474 gsasl_encode_inline (Gsasl_session * sctx,
00475                      const char *input, size_t input_len,
00476                      char *output, size_t * output_len)
00477 {
00478   char *tmp;
00479   size_t tmplen;
00480   int res;
00481 
00482   res = gsasl_encode (sctx, input, input_len, &tmp, &tmplen);
00483   if (res == GSASL_OK)
00484     {
00485       if (*output_len < tmplen)
00486         return GSASL_TOO_SMALL_BUFFER;
00487       *output_len = tmplen;
00488       memcpy (output, tmp, tmplen);
00489       free (output);
00490     }
00491 
00492   return res;
00493 }
00494 
00513 int
00514 gsasl_decode_inline (Gsasl_session * sctx,
00515                      const char *input, size_t input_len,
00516                      char *output, size_t * output_len)
00517 {
00518   char *tmp;
00519   size_t tmplen;
00520   int res;
00521 
00522   res = gsasl_decode (sctx, input, input_len, &tmp, &tmplen);
00523   if (res == GSASL_OK)
00524     {
00525       if (*output_len < tmplen)
00526         return GSASL_TOO_SMALL_BUFFER;
00527       *output_len = tmplen;
00528       memcpy (output, tmp, tmplen);
00529       free (output);
00530     }
00531 
00532   return res;
00533 }
00534 
00548 void
00549 gsasl_application_data_set (Gsasl * ctx, void *appdata)
00550 {
00551   ctx->application_hook = appdata;
00552 }
00553 
00567 void *
00568 gsasl_application_data_get (Gsasl * ctx)
00569 {
00570   return ctx->application_hook;
00571 }
00572 
00586 void
00587 gsasl_appinfo_set (Gsasl_session * sctx, void *appdata)
00588 {
00589   sctx->application_data = appdata;
00590 }
00591 
00605 void *
00606 gsasl_appinfo_get (Gsasl_session * sctx)
00607 {
00608   return sctx->application_data;
00609 }
00610 
00626 const char *
00627 gsasl_server_suggest_mechanism (Gsasl * ctx, const char *mechlist)
00628 {
00629   return NULL;                  /* This function is just silly. */
00630 }
00631 
00646 void
00647 gsasl_client_callback_authentication_id_set (Gsasl * ctx,
00648                                              Gsasl_client_callback_authentication_id
00649                                              cb)
00650 {
00651   ctx->cbc_authentication_id = cb;
00652 }
00653 
00669 Gsasl_client_callback_authentication_id
00670 gsasl_client_callback_authentication_id_get (Gsasl * ctx)
00671 {
00672   return ctx ? ctx->cbc_authentication_id : NULL;
00673 }
00674 
00689 void
00690 gsasl_client_callback_authorization_id_set (Gsasl * ctx,
00691                                             Gsasl_client_callback_authorization_id
00692                                             cb)
00693 {
00694   ctx->cbc_authorization_id = cb;
00695 }
00696 
00712 Gsasl_client_callback_authorization_id
00713 gsasl_client_callback_authorization_id_get (Gsasl * ctx)
00714 {
00715   return ctx ? ctx->cbc_authorization_id : NULL;
00716 }
00717 
00732 void
00733 gsasl_client_callback_password_set (Gsasl * ctx,
00734                                     Gsasl_client_callback_password cb)
00735 {
00736   ctx->cbc_password = cb;
00737 }
00738 
00739 
00755 Gsasl_client_callback_password
00756 gsasl_client_callback_password_get (Gsasl * ctx)
00757 {
00758   return ctx ? ctx->cbc_password : NULL;
00759 }
00760 
00775 void
00776 gsasl_client_callback_passcode_set (Gsasl * ctx,
00777                                     Gsasl_client_callback_passcode cb)
00778 {
00779   ctx->cbc_passcode = cb;
00780 }
00781 
00782 
00798 Gsasl_client_callback_passcode
00799 gsasl_client_callback_passcode_get (Gsasl * ctx)
00800 {
00801   return ctx ? ctx->cbc_passcode : NULL;
00802 }
00803 
00820 void
00821 gsasl_client_callback_pin_set (Gsasl * ctx, Gsasl_client_callback_pin cb)
00822 {
00823   ctx->cbc_pin = cb;
00824 }
00825 
00826 
00842 Gsasl_client_callback_pin
00843 gsasl_client_callback_pin_get (Gsasl * ctx)
00844 {
00845   return ctx ? ctx->cbc_pin : NULL;
00846 }
00847 
00865 void
00866 gsasl_client_callback_service_set (Gsasl * ctx,
00867                                    Gsasl_client_callback_service cb)
00868 {
00869   ctx->cbc_service = cb;
00870 }
00871 
00887 Gsasl_client_callback_service
00888 gsasl_client_callback_service_get (Gsasl * ctx)
00889 {
00890   return ctx ? ctx->cbc_service : NULL;
00891 }
00892 
00908 void
00909 gsasl_client_callback_anonymous_set (Gsasl * ctx,
00910                                      Gsasl_client_callback_anonymous cb)
00911 {
00912   ctx->cbc_anonymous = cb;
00913 }
00914 
00930 Gsasl_client_callback_anonymous
00931 gsasl_client_callback_anonymous_get (Gsasl * ctx)
00932 {
00933   return ctx ? ctx->cbc_anonymous : NULL;
00934 }
00935 
00950 void
00951 gsasl_client_callback_qop_set (Gsasl * ctx, Gsasl_client_callback_qop cb)
00952 {
00953   ctx->cbc_qop = cb;
00954 }
00955 
00971 Gsasl_client_callback_qop
00972 gsasl_client_callback_qop_get (Gsasl * ctx)
00973 {
00974   return ctx ? ctx->cbc_qop : NULL;
00975 }
00976 
00994 void
00995 gsasl_client_callback_maxbuf_set (Gsasl * ctx,
00996                                   Gsasl_client_callback_maxbuf cb)
00997 {
00998   ctx->cbc_maxbuf = cb;
00999 }
01000 
01016 Gsasl_client_callback_maxbuf
01017 gsasl_client_callback_maxbuf_get (Gsasl * ctx)
01018 {
01019   return ctx ? ctx->cbc_maxbuf : NULL;
01020 }
01021 
01037 void
01038 gsasl_client_callback_realm_set (Gsasl * ctx, Gsasl_client_callback_realm cb)
01039 {
01040   ctx->cbc_realm = cb;
01041 }
01042 
01058 Gsasl_client_callback_realm
01059 gsasl_client_callback_realm_get (Gsasl * ctx)
01060 {
01061   return ctx ? ctx->cbc_realm : NULL;
01062 }
01063 
01079 void
01080 gsasl_server_callback_validate_set (Gsasl * ctx,
01081                                     Gsasl_server_callback_validate cb)
01082 {
01083   ctx->cbs_validate = cb;
01084 }
01085 
01101 Gsasl_server_callback_validate
01102 gsasl_server_callback_validate_get (Gsasl * ctx)
01103 {
01104   return ctx ? ctx->cbs_validate : NULL;
01105 }
01106 
01122 void
01123 gsasl_server_callback_retrieve_set (Gsasl * ctx,
01124                                     Gsasl_server_callback_retrieve cb)
01125 {
01126   ctx->cbs_retrieve = cb;
01127 }
01128 
01144 Gsasl_server_callback_retrieve
01145 gsasl_server_callback_retrieve_get (Gsasl * ctx)
01146 {
01147   return ctx ? ctx->cbs_retrieve : NULL;
01148 }
01149 
01165 void
01166 gsasl_server_callback_cram_md5_set (Gsasl * ctx,
01167                                     Gsasl_server_callback_cram_md5 cb)
01168 {
01169   ctx->cbs_cram_md5 = cb;
01170 }
01171 
01187 Gsasl_server_callback_cram_md5
01188 gsasl_server_callback_cram_md5_get (Gsasl * ctx)
01189 {
01190   return ctx ? ctx->cbs_cram_md5 : NULL;
01191 }
01192 
01208 void
01209 gsasl_server_callback_digest_md5_set (Gsasl * ctx,
01210                                       Gsasl_server_callback_digest_md5 cb)
01211 {
01212   ctx->cbs_digest_md5 = cb;
01213 }
01214 
01230 Gsasl_server_callback_digest_md5
01231 gsasl_server_callback_digest_md5_get (Gsasl * ctx)
01232 {
01233   return ctx->cbs_digest_md5;
01234 }
01235 
01250 void
01251 gsasl_server_callback_external_set (Gsasl * ctx,
01252                                     Gsasl_server_callback_external cb)
01253 {
01254   ctx->cbs_external = cb;
01255 }
01256 
01272 Gsasl_server_callback_external
01273 gsasl_server_callback_external_get (Gsasl * ctx)
01274 {
01275   return ctx ? ctx->cbs_external : NULL;
01276 }
01277 
01292 void
01293 gsasl_server_callback_anonymous_set (Gsasl * ctx,
01294                                      Gsasl_server_callback_anonymous cb)
01295 {
01296   ctx->cbs_anonymous = cb;
01297 }
01298 
01314 Gsasl_server_callback_anonymous
01315 gsasl_server_callback_anonymous_get (Gsasl * ctx)
01316 {
01317   return ctx ? ctx->cbs_anonymous : NULL;
01318 }
01319 
01335 void
01336 gsasl_server_callback_realm_set (Gsasl * ctx, Gsasl_server_callback_realm cb)
01337 {
01338   ctx->cbs_realm = cb;
01339 }
01340 
01356 Gsasl_server_callback_realm
01357 gsasl_server_callback_realm_get (Gsasl * ctx)
01358 {
01359   return ctx ? ctx->cbs_realm : NULL;
01360 }
01361 
01378 void
01379 gsasl_server_callback_qop_set (Gsasl * ctx, Gsasl_server_callback_qop cb)
01380 {
01381   ctx->cbs_qop = cb;
01382 }
01383 
01399 Gsasl_server_callback_qop
01400 gsasl_server_callback_qop_get (Gsasl * ctx)
01401 {
01402   return ctx ? ctx->cbs_qop : NULL;
01403 }
01404 
01422 void
01423 gsasl_server_callback_maxbuf_set (Gsasl * ctx,
01424                                   Gsasl_server_callback_maxbuf cb)
01425 {
01426   ctx->cbs_maxbuf = cb;
01427 }
01428 
01444 Gsasl_server_callback_maxbuf
01445 gsasl_server_callback_maxbuf_get (Gsasl * ctx)
01446 {
01447   return ctx ? ctx->cbs_maxbuf : NULL;
01448 }
01449 
01466 void
01467 gsasl_server_callback_cipher_set (Gsasl * ctx,
01468                                   Gsasl_server_callback_cipher cb)
01469 {
01470   ctx->cbs_cipher = cb;
01471 }
01472 
01488 Gsasl_server_callback_cipher
01489 gsasl_server_callback_cipher_get (Gsasl * ctx)
01490 {
01491   return ctx ? ctx->cbs_cipher : NULL;
01492 }
01493 
01515 void
01516 gsasl_server_callback_securid_set (Gsasl * ctx,
01517                                    Gsasl_server_callback_securid cb)
01518 {
01519   ctx->cbs_securid = cb;
01520 }
01521 
01537 Gsasl_server_callback_securid
01538 gsasl_server_callback_securid_get (Gsasl * ctx)
01539 {
01540   return ctx ? ctx->cbs_securid : NULL;
01541 }
01542 
01560 void
01561 gsasl_server_callback_gssapi_set (Gsasl * ctx,
01562                                   Gsasl_server_callback_gssapi cb)
01563 {
01564   ctx->cbs_gssapi = cb;
01565 }
01566 
01582 Gsasl_server_callback_gssapi
01583 gsasl_server_callback_gssapi_get (Gsasl * ctx)
01584 {
01585   return ctx ? ctx->cbs_gssapi : NULL;
01586 }
01587 
01604 void
01605 gsasl_server_callback_service_set (Gsasl * ctx,
01606                                    Gsasl_server_callback_service cb)
01607 {
01608   ctx->cbs_service = cb;
01609 }
01610 
01626 Gsasl_server_callback_service
01627 gsasl_server_callback_service_get (Gsasl * ctx)
01628 {
01629   return ctx ? ctx->cbs_service : NULL;
01630 }
01631 
01632 #if HAVE_LIBIDN
01633 #include <stringprep.h>
01634 #endif
01635 
01662 char *
01663 gsasl_stringprep_nfkc (const char *in, ssize_t len)
01664 {
01665   char *out = NULL;
01666 
01667 #if HAVE_LIBIDN
01668   out = stringprep_utf8_nfkc_normalize (in, len);
01669 #endif
01670 
01671   return out;
01672 }
01673 
01693 char *
01694 gsasl_stringprep_saslprep (const char *in, int *stringprep_rc)
01695 {
01696   char *out = NULL;
01697 #if HAVE_LIBIDN
01698   int rc;
01699 
01700   rc = stringprep_profile (in, &out, "SASLprep", 0);
01701   if (stringprep_rc)
01702     *stringprep_rc = rc;
01703   if (rc != STRINGPREP_OK)
01704     out = NULL;
01705 #endif
01706 
01707   return out;
01708 }
01709 
01727 char *
01728 gsasl_stringprep_trace (const char *in, int *stringprep_rc)
01729 {
01730   char *out = NULL;
01731 #if HAVE_LIBIDN
01732   int rc;
01733 
01734   rc = stringprep_profile (in, &out, "trace", 0);
01735   if (stringprep_rc)
01736     *stringprep_rc = rc;
01737   if (rc != STRINGPREP_OK)
01738     out = NULL;
01739 #endif
01740 
01741   return out;
01742 }
01743 
01768 int
01769 gsasl_md5pwd_get_password (const char *filename,
01770                            const char *username, char *key, size_t * keylen)
01771 {
01772   char *tmp;
01773   size_t tmplen;
01774   int res;
01775   FILE *fh;
01776 
01777   fh = fopen (filename, "r");
01778   if (fh == NULL)
01779     return GSASL_FOPEN_ERROR;
01780   fclose (fh);
01781 
01782   res = gsasl_simple_getpass (filename, username, &tmp);
01783   if (res != GSASL_OK)
01784     return res;
01785 
01786   tmplen = strlen (tmp);
01787 
01788   if (*keylen < tmplen + 1)
01789     {
01790       free (tmp);
01791       return GSASL_TOO_SMALL_BUFFER;
01792     }
01793 
01794   *keylen = tmplen;
01795 
01796   if (key)
01797     memcpy (key, tmp, tmplen);
01798 
01799   free (tmp);
01800 
01801   return GSASL_OK;
01802 }
01803 
01804 #include <minmax.h>
01805 
01822 int
01823 gsasl_base64_encode (char const *src,
01824                      size_t srclength, char *target, size_t targsize)
01825 {
01826   int rc;
01827   char *out;
01828   size_t outlen;
01829   int copied;
01830 
01831   rc = gsasl_base64_to (src, srclength, &out, &outlen);
01832   if (rc)
01833     return -1;
01834 
01835   copied = MIN (outlen, targsize);
01836   memcpy (target, out, copied);
01837   free (out);
01838 
01839   return copied;
01840 }
01841 
01857 int
01858 gsasl_base64_decode (char const *src, char *target, size_t targsize)
01859 {
01860   int rc;
01861   char *out;
01862   size_t outlen;
01863   int copied;
01864 
01865   rc = gsasl_base64_from (src, strlen (src), &out, &outlen);
01866   if (rc)
01867     return -1;
01868 
01869   copied = MIN (outlen, targsize);
01870   memcpy (target, out, copied);
01871   free (out);
01872 
01873   return copied;
01874 }
01875 
01876 static const char *
01877 pmap (Gsasl_session * sctx, Gsasl_property prop, char *buf, size_t buflen)
01878 {
01879   int res;
01880 
01881   buf[0] = '\0';
01882 
01883   /* Translate obsolete callbacks to modern properties. */
01884 
01885   switch (prop)
01886     {
01887     case GSASL_SERVICE:
01888       {
01889         Gsasl_client_callback_service cb_service
01890           = gsasl_client_callback_service_get (sctx->ctx);
01891         if (!cb_service)
01892           break;
01893         res = cb_service (sctx, buf, &buflen, NULL, 0, NULL, 0);
01894         if (res != GSASL_OK)
01895           break;
01896         buf[buflen] = '\0';
01897         gsasl_property_set (sctx, prop, buf);
01898         break;
01899       }
01900 
01901     case GSASL_HOSTNAME:
01902       {
01903         Gsasl_client_callback_service cb_service
01904           = gsasl_client_callback_service_get (sctx->ctx);
01905         if (!cb_service)
01906           break;
01907         res = cb_service (sctx, NULL, 0, buf, &buflen, NULL, 0);
01908         if (res != GSASL_OK)
01909           break;
01910         buf[buflen] = '\0';
01911         gsasl_property_set (sctx, prop, buf);
01912         break;
01913       }
01914 
01915     case GSASL_ANONYMOUS_TOKEN:
01916       {
01917         Gsasl_client_callback_anonymous cb_anonymous
01918           = gsasl_client_callback_anonymous_get (sctx->ctx);
01919         if (!cb_anonymous)
01920           break;
01921         res = cb_anonymous (sctx, buf, &buflen);
01922         if (res != GSASL_OK)
01923           break;
01924         buf[buflen] = '\0';
01925         gsasl_property_set (sctx, prop, buf);
01926         break;
01927       }
01928 
01929     case GSASL_AUTHID:
01930       {
01931         Gsasl_client_callback_authentication_id cb_authentication_id
01932           = gsasl_client_callback_authentication_id_get (sctx->ctx);
01933         if (!cb_authentication_id)
01934           break;
01935         res = cb_authentication_id (sctx, buf, &buflen);
01936         if (res != GSASL_OK)
01937           break;
01938         buf[buflen] = '\0';
01939         gsasl_property_set (sctx, prop, buf);
01940         break;
01941       }
01942 
01943     case GSASL_AUTHZID:
01944       {
01945         Gsasl_client_callback_authorization_id cb_authorization_id
01946           = gsasl_client_callback_authorization_id_get (sctx->ctx);
01947         if (!cb_authorization_id)
01948           break;
01949         res = cb_authorization_id (sctx, buf, &buflen);
01950         if (res != GSASL_OK)
01951           break;
01952         buf[buflen] = '\0';
01953         gsasl_property_set (sctx, prop, buf);
01954         break;
01955       }
01956 
01957     case GSASL_PASSWORD:
01958       {
01959         Gsasl_client_callback_password cb_password
01960           = gsasl_client_callback_password_get (sctx->ctx);
01961         if (!cb_password)
01962           break;
01963         res = cb_password (sctx, buf, &buflen);
01964         if (res != GSASL_OK)
01965           break;
01966         buf[buflen] = '\0';
01967         gsasl_property_set (sctx, prop, buf);
01968         break;
01969       }
01970 
01971     case GSASL_PASSCODE:
01972       {
01973         Gsasl_client_callback_passcode cb_passcode
01974           = gsasl_client_callback_passcode_get (sctx->ctx);
01975         if (!cb_passcode)
01976           break;
01977         res = cb_passcode (sctx, buf, &buflen);
01978         if (res != GSASL_OK)
01979           break;
01980         buf[buflen] = '\0';
01981         gsasl_property_set (sctx, prop, buf);
01982         break;
01983       }
01984 
01985     case GSASL_PIN:
01986       {
01987         Gsasl_client_callback_pin cb_pin
01988           = gsasl_client_callback_pin_get (sctx->ctx);
01989         if (!cb_pin)
01990           break;
01991         res = cb_pin (sctx, sctx->suggestedpin, buf, &buflen);
01992         if (res != GSASL_OK)
01993           break;
01994         buf[buflen] = '\0';
01995         gsasl_property_set (sctx, prop, buf);
01996         break;
01997       }
01998 
01999     case GSASL_REALM:
02000       {
02001         Gsasl_client_callback_realm cb_realm
02002           = gsasl_client_callback_realm_get (sctx->ctx);
02003         if (!cb_realm)
02004           break;
02005         res = cb_realm (sctx, buf, &buflen);
02006         if (res != GSASL_OK)
02007           break;
02008         buf[buflen] = '\0';
02009         gsasl_property_set (sctx, prop, buf);
02010         break;
02011       }
02012 
02013 #if USE_DIGEST_MD5
02014     case GSASL_QOP:
02015       {
02016         Gsasl_client_callback_qop cb_qop
02017           = gsasl_client_callback_qop_get (sctx->ctx);
02018         int serverqops;
02019         Gsasl_qop qop;
02020         if (!cb_qop)
02021           break;
02022         serverqops = digest_md5_qopstr2qops (sctx->qops);
02023         if (serverqops == -1)
02024           return NULL;
02025         qop = cb_qop (sctx, serverqops);
02026         if (qop & 0x07)
02027           gsasl_property_set (sctx, prop, digest_md5_qops2qopstr (qop));
02028         break;
02029       }
02030       break;
02031 #endif
02032 
02033     default:
02034       break;
02035     }
02036 
02037   return gsasl_property_fast (sctx, prop);
02038 }
02039 
02040 const char *
02041 _gsasl_obsolete_property_map (Gsasl_session * sctx, Gsasl_property prop)
02042 {
02043   const char *ret;
02044   char *buf;
02045 
02046   buf = malloc (BUFSIZ);
02047   if (!buf)
02048     return NULL;
02049 
02050   ret = pmap (sctx, prop, buf, BUFSIZ - 1);
02051 
02052   free (buf);
02053 
02054   return ret;
02055 }
02056 
02057 int
02058 _gsasl_obsolete_callback (Gsasl * ctx, Gsasl_session * sctx,
02059                           Gsasl_property prop)
02060 {
02061   int res;
02062 
02063   /* Call obsolete callbacks. */
02064 
02065   switch (prop)
02066     {
02067     case GSASL_VALIDATE_ANONYMOUS:
02068       {
02069         Gsasl_server_callback_anonymous cb_anonymous;
02070         if (!sctx->anonymous_token)
02071           break;
02072         cb_anonymous = gsasl_server_callback_anonymous_get (sctx->ctx);
02073         if (!cb_anonymous)
02074           break;
02075         res = cb_anonymous (sctx, sctx->anonymous_token);
02076         return res;
02077         break;
02078       }
02079 
02080     case GSASL_VALIDATE_EXTERNAL:
02081       {
02082         Gsasl_server_callback_external cb_external
02083           = gsasl_server_callback_external_get (sctx->ctx);
02084         if (!cb_external)
02085           break;
02086         res = cb_external (sctx);
02087         return res;
02088         break;
02089       }
02090 
02091     case GSASL_VALIDATE_SECURID:
02092       {
02093         Gsasl_server_callback_securid cb_securid
02094           = gsasl_server_callback_securid_get (sctx->ctx);
02095 #define MAX_SECURID 32          /* See RFC 2808. */
02096         char buf[MAX_SECURID + 1];
02097         size_t buflen = MAX_SECURID;
02098         if (!cb_securid)
02099           break;
02100         res = cb_securid (sctx, sctx->authid, sctx->authzid, sctx->passcode,
02101                           sctx->pin, buf, &buflen);
02102         if (buflen > 0 && buflen < MAX_SECURID)
02103           {
02104             buf[buflen] = '\0';
02105             gsasl_property_set (sctx, GSASL_SUGGESTED_PIN, buf);
02106           }
02107         return res;
02108         break;
02109       }
02110 
02111     case GSASL_VALIDATE_GSSAPI:
02112       {
02113         Gsasl_server_callback_gssapi cb_gssapi
02114           = gsasl_server_callback_gssapi_get (sctx->ctx);
02115         if (!cb_gssapi)
02116           break;
02117         res = cb_gssapi (sctx, sctx->gssapi_display_name, sctx->authzid);
02118         return res;
02119         break;
02120       }
02121 
02122     case GSASL_VALIDATE_SIMPLE:
02123       {
02124         Gsasl_server_callback_validate cb_validate
02125           = gsasl_server_callback_validate_get (sctx->ctx);
02126         if (!cb_validate)
02127           break;
02128         res = cb_validate (sctx, sctx->authzid, sctx->authid, sctx->password);
02129         return res;
02130         break;
02131       }
02132 
02133     case GSASL_PASSWORD:
02134       {
02135         Gsasl_server_callback_retrieve cb_retrieve
02136           = gsasl_server_callback_retrieve_get (sctx->ctx);
02137         char *buf;
02138         size_t buflen = BUFSIZ - 1;
02139         if (!cb_retrieve)
02140           break;
02141         buf = malloc (BUFSIZ);
02142         if (!buf)
02143           return GSASL_MALLOC_ERROR;
02144         res = cb_retrieve (sctx, sctx->authid, sctx->authzid,
02145                            sctx->hostname, buf, &buflen);
02146         if (res == GSASL_OK)
02147           gsasl_property_set_raw (sctx, GSASL_PASSWORD, buf, buflen);
02148         /* FIXME else if (res == GSASL_TOO_SMALL_BUFFER)... */
02149         free (buf);
02150         return res;
02151         break;
02152       }
02153 
02154 #if USE_DIGEST_MD5
02155     case GSASL_QOPS:
02156       {
02157         Gsasl_server_callback_qop cb_qop
02158           = gsasl_server_callback_qop_get (sctx->ctx);
02159         Gsasl_qop qops;
02160         if (!cb_qop)
02161           break;
02162         qops = cb_qop (sctx);
02163         if (qops & 0x07)
02164           gsasl_property_set (sctx, GSASL_QOPS,
02165                               digest_md5_qops2qopstr (qops));
02166         return GSASL_OK;
02167         break;
02168       }
02169 #endif
02170 
02171     default:
02172       break;
02173     }
02174 
02175   return GSASL_NO_CALLBACK;
02176 }