callback.c

Go to the documentation of this file.
00001 /* callback.c --- Callback handling.
00002  * Copyright (C) 2002, 2003, 2004, 2005, 2006  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 
00043 void
00044 gsasl_callback_set (Gsasl * ctx, Gsasl_callback_function cb)
00045 {
00046   ctx->cb = cb;
00047 }
00048 
00074 int
00075 gsasl_callback (Gsasl * ctx, Gsasl_session * sctx, Gsasl_property prop)
00076 {
00077   if (ctx == NULL && sctx == NULL)
00078     return GSASL_NO_CALLBACK;
00079 
00080   if (ctx == NULL)
00081     ctx = sctx->ctx;
00082 
00083   if (ctx->cb)
00084     return ctx->cb (ctx, sctx, prop);
00085 
00086 #ifndef GSASL_NO_OBSOLETE
00087   {
00088     /* Call obsolete callbacks.  Remove this when the obsolete
00089      * callbacks are no longer supported.  */
00090     Gsasl_server_callback_anonymous cb_anonymous;
00091     Gsasl_server_callback_external cb_external;
00092     Gsasl_server_callback_securid cb_securid;
00093     Gsasl_server_callback_gssapi cb_gssapi;
00094     Gsasl_server_callback_validate cb_validate;
00095     Gsasl_server_callback_retrieve cb_retrieve;
00096     char buf[BUFSIZ];
00097     size_t buflen = BUFSIZ - 1;
00098     int res;
00099 
00100     switch (prop)
00101       {
00102       case GSASL_VALIDATE_ANONYMOUS:
00103         if (!sctx->anonymous_token)
00104           break;
00105         cb_anonymous = gsasl_server_callback_anonymous_get (sctx->ctx);
00106         if (!cb_anonymous)
00107           break;
00108         res = cb_anonymous (sctx, sctx->anonymous_token);
00109         return res;
00110         break;
00111 
00112       case GSASL_VALIDATE_EXTERNAL:
00113         cb_external = gsasl_server_callback_external_get (sctx->ctx);
00114         if (!cb_external)
00115           break;
00116         res = cb_external (sctx);
00117         return res;
00118         break;
00119 
00120       case GSASL_VALIDATE_SECURID:
00121         cb_securid = gsasl_server_callback_securid_get (sctx->ctx);
00122         if (!cb_securid)
00123           break;
00124         res = cb_securid (sctx, sctx->authid, sctx->authzid, sctx->passcode,
00125                           sctx->pin, buf, &buflen);
00126         if (buflen > 0 && buflen < BUFSIZ - 1)
00127           {
00128             buf[buflen] = '\0';
00129             gsasl_property_set (sctx, GSASL_SUGGESTED_PIN, buf);
00130           }
00131         return res;
00132         break;
00133 
00134       case GSASL_VALIDATE_GSSAPI:
00135         cb_gssapi = gsasl_server_callback_gssapi_get (sctx->ctx);
00136         if (!cb_gssapi)
00137           break;
00138         res = cb_gssapi (sctx, sctx->gssapi_display_name, sctx->authzid);
00139         return res;
00140         break;
00141 
00142       case GSASL_VALIDATE_SIMPLE:
00143         cb_validate = gsasl_server_callback_validate_get (sctx->ctx);
00144         if (!cb_validate)
00145           break;
00146         res = cb_validate (sctx, sctx->authzid, sctx->authid, sctx->password);
00147         return res;
00148         break;
00149 
00150       case GSASL_PASSWORD:
00151         cb_retrieve = gsasl_server_callback_retrieve_get (sctx->ctx);
00152         if (!cb_retrieve)
00153           break;
00154         res = cb_retrieve (sctx, sctx->authid, sctx->authzid,
00155                            sctx->hostname, buf, &buflen);
00156         if (res == GSASL_OK)
00157           gsasl_property_set_raw (sctx, GSASL_PASSWORD, buf, buflen);
00158         /* FIXME else if (res == GSASL_TOO_SMALL_BUFFER)... */
00159         return res;
00160         break;
00161 
00162       default:
00163         break;
00164       }
00165   }
00166 #endif
00167 
00168   return GSASL_NO_CALLBACK;
00169 }
00170 
00185 void
00186 gsasl_callback_hook_set (Gsasl * ctx, void *hook)
00187 {
00188   ctx->application_hook = hook;
00189 }
00190 
00205 void *
00206 gsasl_callback_hook_get (Gsasl * ctx)
00207 {
00208   return ctx->application_hook;
00209 }
00210 
00225 void
00226 gsasl_session_hook_set (Gsasl_session * sctx, void *hook)
00227 {
00228   sctx->application_hook = hook;
00229 }
00230 
00245 void *
00246 gsasl_session_hook_get (Gsasl_session * sctx)
00247 {
00248   return sctx->application_hook;
00249 }

Generated on Tue Aug 22 12:06:06 2006 for gsasl by  doxygen 1.4.7