gsasl-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS gsasl/lib/src


From: gsasl-commit
Subject: CVS gsasl/lib/src
Date: Sat, 18 Sep 2004 02:58:36 +0200

Update of /home/cvs/gsasl/lib/src
In directory dopio:/tmp/cvs-serv26762/lib/src

Modified Files:
        Makefile.am callback.c common.c done.c error.c gsasl.h.in 
        internal.h xfinish.c 
Added Files:
        gsasl-compat.h property.c 
Log Message:
Add new callback/property interface, thereby deprecating old callback system.
Move obsolete APIs from gsasl.h.in to gsasl-compat.h.
Include gsasl-compat.h in gsasl.h.in.
Fix the ANONYMOUS mechanism to use the new interface, including
the new allocating mechanism interface.


--- /home/cvs/gsasl/lib/src/Makefile.am 2004/09/17 21:27:12     1.8
+++ /home/cvs/gsasl/lib/src/Makefile.am 2004/09/18 00:58:36     1.9
@@ -24,13 +24,13 @@
        -I$(srcdir)/../crypto -I../crypto
 DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@
 
-include_HEADERS = gsasl.h
+include_HEADERS = gsasl.h gsasl-compat.h
 
 libgsasl_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
 libgsasl_la_LIBADD = @LTLIBINTL@ ../crypto/libgc.la
 libgsasl_la_SOURCES = gsasl.h.in internal.h \
        init.c done.c register.c error.c version.c common.c \
-       callback.c callback-c.c callback-s.c \
+       callback.c property.c callback-c.c callback-s.c \
        supportp.c suggest.c listmech.c \
        xstart.c xstep.c xfinish.c xcode.c \
        base64.c md5pwd.c crypto.c obsolete.c
--- /home/cvs/gsasl/lib/src/callback.c  2004/04/15 22:02:50     1.2
+++ /home/cvs/gsasl/lib/src/callback.c  2004/09/18 00:58:36     1.3
@@ -22,6 +22,153 @@
 #include "internal.h"
 
 /**
+ * gsasl_callback_set:
+ * @sctx: session handle.
+ * @cb: pointer to function implemented by application.
+ *
+ * Store the pointer to the application provided callback in the
+ * session specific handle.  The callback will be used, via
+ * gsasl_callback(), by mechanisms to discover various parameters
+ * (such as username and passwords).  The callback function will be
+ * called with a Gsasl_property value indicating the requested
+ * behaviour.  For example, for GSASL_CLIENT_ANONYMOUS, the function
+ * is expected to invoke gsasl_property_set(SCTX,
+ * GSASL_CLIENT_ANONYMOUS, "token") where "token" is the anonymous
+ * token the application wishes the SASL mechanism to use.  See the
+ * manual for the meaning of all parameters.
+ *
+ * It is valid, but may be confusing at first, to set different
+ * callbacks using gsasl_callback_set() and
+ * gsasl_callback_set_global().  Normally the session specific
+ * callback (i.e., the one set by gsasl_callback_set()) will be used
+ * by mechanisms, with a fall back to the global callback if a session
+ * specific callback has not been set.  You can use this to set a
+ * general global callback handler that apply to most sessions, but
+ * for some specific sessions you can override the callback with a
+ * different function.
+ **/
+void
+gsasl_callback_set (Gsasl_session * sctx, Gsasl_callback cb)
+{
+  sctx->cb = cb;
+}
+
+/**
+ * gsasl_callback_set_global:
+ * @ctx: handle received from gsasl_init().
+ * @cb: pointer to function implemented by application.
+ *
+ * Store the pointer to the application provided callback in the
+ * library handle.  The callback will be used, via gsasl_callback()
+ * and gsasl_callback_global(), by mechanisms to discover various
+ * parameters (such as username and passwords).  The callback function
+ * will be called with a Gsasl_property value indicating the requested
+ * behaviour.  For example, for GSASL_CLIENT_ANONYMOUS, the function
+ * is expected to invoke gsasl_property_set_global(CTX,
+ * GSASL_CLIENT_ANONYMOUS, "token") where "token" is the anonymous
+ * token the application wishes the SASL mechanism to use.  See the
+ * manual for the meaning of all parameters.
+ *
+ * It is valid, but may be confusing at first, to set different
+ * callbacks using gsasl_callback_set() and
+ * gsasl_callback_set_global().  Normally the session specific
+ * callback (i.e., the one set by gsasl_callback_set()) will be used
+ * by mechanisms, with a fall back to the global callback if a session
+ * specific callback has not been set.  You can use this to set a
+ * general global callback handler that apply to most sessions, but
+ * for some specific sessions you can override the callback with a
+ * different function.
+ **/
+void
+gsasl_callback_set_global (Gsasl * ctx, Gsasl_callback cb)
+{
+  ctx->cb = cb;
+}
+
+/**
+ * gsasl_callback:
+ * @sctx: session handle.
+ * @prop: enumerated value of Gsasl_property type.
+ *
+ * Invoke the session specific application callback, with a fall back
+ * to the global callback.  The @prop value indicate what the callback
+ * is expected to do.  For example, for GSASL_CLIENT_ANONYMOUS, the
+ * function is expected to invoke gsasl_property_set(SCTX,
+ * GSASL_CLIENT_ANONYMOUS, "token") where "token" is the anonymous
+ * token the application wishes the SASL mechanism to use.  See the
+ * manual for the meaning of all parameters.
+ *
+ * Note that if no callback has been set by the application, but the
+ * obsolete callback interface has been used, this function will
+ * translate the old callback interface into the new.  This interface
+ * should be sufficient to invoke all callbacks, both new and old.
+ *
+ * Return value: Returns whatever the application callback return, or
+ *   GSASL_NO_CALLBACK if no application was known.
+ **/
+int
+gsasl_callback (Gsasl_session * sctx, Gsasl_property prop)
+{
+  if (sctx->cb)
+    return sctx->cb (sctx->ctx, sctx, prop);
+
+  if (sctx->ctx->cb)
+    return gsasl_callback_global (sctx->ctx, prop);
+
+  {
+    /* Call obsolete callbacks.  Remove this when the obsolete
+     * callbacks are no longer supported.  This is done here, not in
+     * gsasl_callback_global, since all obsolete callbacks were
+     * session specific.  */
+    Gsasl_server_callback_anonymous cb_anonymous;
+    int res;
+
+    switch (prop)
+      {
+      case GSASL_SERVER_ANONYMOUS:
+       if (!sctx->anonymous_token)
+         break;
+       cb_anonymous = gsasl_server_callback_anonymous_get (sctx->ctx);
+       if (!cb_anonymous)
+         break;
+       res = cb_anonymous (sctx, sctx->anonymous_token);
+       return res;
+       break;
+
+      default:
+       break;
+      }
+  }
+
+  return GSASL_NO_CALLBACK;
+}
+
+/**
+ * gsasl_callback_global:
+ * @ctx: handle received from gsasl_init().
+ * @prop: enumerated value of Gsasl_property type.
+ *
+ * Invoke the handle global application callback.  The @prop value
+ * indicate what the callback is expected to do.  For example, for
+ * GSASL_CLIENT_ANONYMOUS, the function is expected to invoke
+ * gsasl_property_set(SCTX, GSASL_CLIENT_ANONYMOUS, "token") where
+ * "token" is the anonymous token the application wishes the SASL
+ * mechanism to use.  See the manual for the meaning of all
+ * parameters.
+ *
+ * Return value: Returns whatever the application callback return, or
+ *   GSASL_NO_CALLBACK if no application was known.
+ **/
+int
+gsasl_callback_global (Gsasl * ctx, Gsasl_property prop)
+{
+  if (ctx->cb)
+    return ctx->cb (ctx, NULL, prop);
+
+  return GSASL_NO_CALLBACK;
+}
+
+/**
  * gsasl_ctx_get:
  * @sctx: libgsasl session handle
  *
@@ -86,7 +233,7 @@
 
 /**
  * gsasl_appinfo_get:
- * @sctx: libgsasl client handle.
+ * @sctx: libgsasl session handle.
  *
  * Retrieve application specific data from libgsasl session
  * handle. The application data is set using
--- /home/cvs/gsasl/lib/src/common.c    2004/09/17 20:52:45     1.5
+++ /home/cvs/gsasl/lib/src/common.c    2004/09/18 00:58:36     1.6
@@ -42,10 +42,11 @@
     NULL,
     NULL,
     _gsasl_anonymous_client_start,
-    _gsasl_anonymous_client_step,
+    NULL,
     _gsasl_anonymous_client_finish,
     NULL,
-    NULL
+    NULL,
+    _gsasl_anonymous_client_step
 #endif
     },
    {
@@ -53,10 +54,11 @@
     NULL,
     NULL,
     _gsasl_anonymous_server_start,
-    _gsasl_anonymous_server_step,
+    NULL,
     _gsasl_anonymous_server_finish,
     NULL,
-    NULL
+    NULL,
+    _gsasl_anonymous_server_step
 #endif
     }
    },
--- /home/cvs/gsasl/lib/src/done.c      2004/09/17 20:44:43     1.3
+++ /home/cvs/gsasl/lib/src/done.c      2004/09/18 00:58:36     1.4
@@ -54,6 +54,9 @@
     free (ctx->server_mechs);
 #endif
 
+  if (ctx->anonymous_token)
+    free (ctx->anonymous_token);
+
   free (ctx);
 
   return;
--- /home/cvs/gsasl/lib/src/error.c     2004/04/15 22:02:50     1.2
+++ /home/cvs/gsasl/lib/src/error.c     2004/09/18 00:58:36     1.3
@@ -306,6 +306,14 @@
       p = _("The provided library handle was invalid (application error)");
       break;
 
+    case GSASL_NO_CALLBACK:
+      p = _("No callback specified by caller (application error).");
+      break;
+
+    case GSASL_NO_ANONYMOUS_TOKEN:
+      p = _("Authentication failed because no anonymous token was provided.");
+      break;
+
     default:
       p = _("Libgsasl unknown error");
       break;
--- /home/cvs/gsasl/lib/src/gsasl.h.in  2004/06/18 00:13:15     1.8
+++ /home/cvs/gsasl/lib/src/gsasl.h.in  2004/09/18 00:58:36     1.9
@@ -19,8 +19,8 @@
  *
  */
 
-#ifndef _GSASL_H
-#define _GSASL_H
+#ifndef GSASL_H
+#define GSASL_H
 
 #include <stdio.h>             /* FILE */
 #include <stddef.h>            /* size_t */
@@ -84,6 +84,8 @@
     GSASL_NO_MORE_REALMS,
     GSASL_NO_CLIENT_CODE,
     GSASL_NO_SERVER_CODE,
+    GSASL_NO_CALLBACK,
+    GSASL_NO_ANONYMOUS_TOKEN,
     /* Mechanism specific errors. */
     GSASL_GSSAPI_RELEASE_BUFFER_ERROR,
     GSASL_GSSAPI_IMPORT_NAME_ERROR,
@@ -125,6 +127,34 @@
   typedef struct Gsasl Gsasl;
   typedef struct Gsasl_session Gsasl_session;
 
+  /* Callback/property types. */
+  enum Gsasl_property
+  {
+    GSASL_CLIENT_ANONYMOUS,
+    GSASL_CLIENT_SIMPLE,
+    GSASL_CLIENT_PASSCODE,
+    GSASL_CLIENT_PIN,
+    GSASL_CLIENT_SERVICE,
+    GSASL_CLIENT_QOP,
+    GSASL_CLIENT_MAXBUF,
+    GSASL_SERVER_VALIDATE,
+    GSASL_SERVER_RETRIEVE,
+    GSASL_SERVER_USEROK,
+    GSASL_SERVER_SECURID,
+    GSASL_SERVER_CRAM_MD5,
+    GSASL_SERVER_DIGEST_MD5,
+    GSASL_SERVER_SERVICE,
+    GSASL_SERVER_EXTERNAL,
+    GSASL_SERVER_ANONYMOUS,
+    GSASL_SERVER_REALM,
+    GSASL_SERVER_QOP,
+    GSASL_SERVER_MAXBUF,
+    GSASL_SERVER_CIPHER
+  };
+  typedef enum Gsasl_property Gsasl_property;
+  typedef int (*Gsasl_callback) (Gsasl * ctx, Gsasl_session * sctx,
+                                Gsasl_property prop);
+
 /* Library entry and exit points: version.c, init.c, done.c */
   extern int gsasl_init (Gsasl ** ctx);
   extern void gsasl_done (Gsasl * ctx);
@@ -141,6 +171,24 @@
   extern void *gsasl_application_data_get (Gsasl * ctx);
   extern void gsasl_appinfo_set (Gsasl_session * sctx, void *appdata);
   extern void *gsasl_appinfo_get (Gsasl_session * sctx);
+  extern void gsasl_callback_set (Gsasl_session * sctx, Gsasl_callback cb);
+  extern void gsasl_callback_set_global (Gsasl * ctx, Gsasl_callback cb);
+  extern int gsasl_callback (Gsasl_session * sctx, Gsasl_property prop);
+  extern int gsasl_callback_global (Gsasl * ctx, Gsasl_property prop);
+
+  /* Property handling: property.c */
+  extern void gsasl_property_set (Gsasl_session * sctx, Gsasl_property prop,
+                                 const char *data);
+  extern void gsasl_property_set_global (Gsasl * ctx, Gsasl_property prop,
+                                        const char *data);
+  extern const char *gsasl_property_get (Gsasl_session * sctx,
+                                        Gsasl_property prop);
+  extern const char *gsasl_property_get_global (Gsasl * ctx,
+                                               Gsasl_property prop);
+  extern const char *gsasl_property_fast (Gsasl_session * sctx,
+                                         Gsasl_property prop);
+  extern const char *gsasl_property_fast_global (Gsasl * ctx,
+                                                Gsasl_property prop);
 
 /* Mechanism handling: listmech.c, supportp.c, suggest.c */
   extern int gsasl_client_mechlist (Gsasl * ctx, char **out);
@@ -177,8 +225,7 @@
   extern const char *gsasl_strerror (int err);
 
 /* Utilities: base64.c, md5pwd.c, crypto.c */
-  extern int gsasl_base64_encode (char const *src,
-                                 size_t srclength,
+  extern int gsasl_base64_encode (char const *src, size_t srclength,
                                  char *target, size_t targsize);
   extern int gsasl_base64_decode (char const *src,
                                  char *target, size_t targsize);
@@ -191,227 +238,11 @@
   extern int gsasl_hmac_md5 (const char *key, size_t keylen,
                             const char *in, size_t inlen, char *outhash[16]);
 
-/* Callback prototypes */
-  typedef int (*Gsasl_client_callback_anonymous) (Gsasl_session * sctx,
-                                                 char *out, size_t * outlen);
-  typedef int (*Gsasl_client_callback_authentication_id) (Gsasl_session *
-                                                         sctx, char *out,
-                                                         size_t * outlen);
-  typedef int (*Gsasl_client_callback_authorization_id) (Gsasl_session *
-                                                        sctx, char *out,
-                                                        size_t * outlen);
-  typedef int (*Gsasl_client_callback_password) (Gsasl_session * sctx,
-                                                char *out, size_t * outlen);
-  typedef int (*Gsasl_client_callback_passcode) (Gsasl_session * sctx,
-                                                char *out, size_t * outlen);
-  typedef int (*Gsasl_client_callback_pin) (Gsasl_session * sctx,
-                                           char *suggestion, char *out,
-                                           size_t * outlen);
-  typedef int (*Gsasl_client_callback_service) (Gsasl_session * sctx,
-                                               char *service,
-                                               size_t * servicelen,
-                                               char *hostname,
-                                               size_t * hostnamelen,
-                                               char *servicename,
-                                               size_t * servicenamelen);
-  typedef Gsasl_qop (*Gsasl_client_callback_qop) (Gsasl_session * sctx,
-                                                 Gsasl_qop serverqops);
-  typedef size_t (*Gsasl_client_callback_maxbuf) (Gsasl_session * sctx,
-                                                 size_t servermaxbuf);
-  typedef int (*Gsasl_client_callback_realm) (Gsasl_session * sctx,
-                                             char *out, size_t * outlen);
-  typedef int (*Gsasl_server_callback_retrieve) (Gsasl_session * sctx,
-                                                const char
-                                                *authentication_id,
-                                                const char *authorization_id,
-                                                const char *realm, char *key,
-                                                size_t * keylen);
-  typedef int (*Gsasl_server_callback_validate) (Gsasl_session * sctx,
-                                                const char *authorization_id,
-                                                const char
-                                                *authentication_id,
-                                                const char *password);
-  typedef int (*Gsasl_server_callback_gssapi) (Gsasl_session * sctx,
-                                              const char *clientname,
-                                              const char *authentication_id);
-  typedef int (*Gsasl_server_callback_securid) (Gsasl_session * sctx,
-                                               const char *authentication_id,
-                                               const char *authorization_id,
-                                               const char *passcode,
-                                               char *pin, char *suggestpin,
-                                               size_t * suggestpinlen);
-  typedef int (*Gsasl_server_callback_cram_md5) (Gsasl_session * sctx,
-                                                char *username,
-                                                char *challenge,
-                                                char *response);
-  typedef int (*Gsasl_server_callback_digest_md5) (Gsasl_session * sctx,
-                                                  char *username,
-                                                  char *realm,
-                                                  char *secrethash);
-  typedef int (*Gsasl_server_callback_service) (Gsasl_session * sctx,
-                                               char *service,
-                                               size_t * servicelen,
-                                               char *hostname,
-                                               size_t * hostnamelen);
-  typedef int (*Gsasl_server_callback_external) (Gsasl_session * sctx);
-  typedef int (*Gsasl_server_callback_anonymous) (Gsasl_session * sctx,
-                                                 const char *token);
-  typedef int (*Gsasl_server_callback_realm) (Gsasl_session * sctx,
-                                             char *out,
-                                             size_t * outlen, size_t nth);
-  typedef Gsasl_qop (*Gsasl_server_callback_qop) (Gsasl_session * sctx);
-  typedef size_t (*Gsasl_server_callback_maxbuf) (Gsasl_session * sctx);
-  typedef Gsasl_cipher (*Gsasl_server_callback_cipher) (Gsasl_session * sctx);
-
-/* Client callbacks: callback-c.c */
-  extern void gsasl_client_callback_authorization_id_set (Gsasl * ctx,
-                                                         
Gsasl_client_callback_authorization_id cb);
-  extern Gsasl_client_callback_authorization_id
-    gsasl_client_callback_authorization_id_get (Gsasl * ctx);
-
-  extern void gsasl_client_callback_authentication_id_set (Gsasl * ctx,
-                                                          
Gsasl_client_callback_authentication_id cb);
-  extern Gsasl_client_callback_authentication_id
-    gsasl_client_callback_authentication_id_get (Gsasl * ctx);
-
-  extern void gsasl_client_callback_anonymous_set (Gsasl * ctx,
-                                                  
Gsasl_client_callback_anonymous cb);
-  extern Gsasl_client_callback_anonymous
-    gsasl_client_callback_anonymous_get (Gsasl * ctx);
-
-  extern void gsasl_client_callback_password_set (Gsasl * ctx,
-                                                 
Gsasl_client_callback_password cb);
-  extern Gsasl_client_callback_password
-    gsasl_client_callback_password_get (Gsasl * ctx);
-
-  extern void gsasl_client_callback_passcode_set (Gsasl * ctx,
-                                                 
Gsasl_client_callback_passcode cb);
-  extern Gsasl_client_callback_passcode
-    gsasl_client_callback_passcode_get (Gsasl * ctx);
-
-  extern void gsasl_client_callback_pin_set (Gsasl * ctx,
-                                            Gsasl_client_callback_pin cb);
-  extern Gsasl_client_callback_pin
-    gsasl_client_callback_pin_get (Gsasl * ctx);
-
-  extern void gsasl_client_callback_service_set (Gsasl * ctx,
-                                                Gsasl_client_callback_service 
cb);
-  extern Gsasl_client_callback_service
-    gsasl_client_callback_service_get (Gsasl * ctx);
-
-  extern void gsasl_client_callback_qop_set (Gsasl * ctx,
-                                            Gsasl_client_callback_qop cb);
-  extern Gsasl_client_callback_qop
-    gsasl_client_callback_qop_get (Gsasl * ctx);
-
-  extern void gsasl_client_callback_maxbuf_set (Gsasl * ctx,
-                                               Gsasl_client_callback_maxbuf 
cb);
-  extern Gsasl_client_callback_maxbuf
-    gsasl_client_callback_maxbuf_get (Gsasl * ctx);
-  extern void gsasl_client_callback_realm_set (Gsasl * ctx,
-                                              Gsasl_client_callback_realm cb);
-  extern Gsasl_client_callback_realm
-    gsasl_client_callback_realm_get (Gsasl * ctx);
-
-/* Server callbacks: callback-s.c */
-  extern void gsasl_server_callback_validate_set (Gsasl * ctx,
-                                                 
Gsasl_server_callback_validate cb);
-  extern Gsasl_server_callback_validate
-    gsasl_server_callback_validate_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_retrieve_set (Gsasl * ctx,
-                                                 
Gsasl_server_callback_retrieve cb);
-  extern Gsasl_server_callback_retrieve
-    gsasl_server_callback_retrieve_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_cram_md5_set (Gsasl * ctx,
-                                                 
Gsasl_server_callback_cram_md5 cb);
-  extern Gsasl_server_callback_cram_md5
-    gsasl_server_callback_cram_md5_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_digest_md5_set (Gsasl * ctx,
-                                                   
Gsasl_server_callback_digest_md5 cb);
-  extern Gsasl_server_callback_digest_md5
-    gsasl_server_callback_digest_md5_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_external_set (Gsasl * ctx,
-                                                 
Gsasl_server_callback_external cb);
-  extern Gsasl_server_callback_external
-    gsasl_server_callback_external_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_anonymous_set (Gsasl * ctx,
-                                                  
Gsasl_server_callback_anonymous cb);
-  extern Gsasl_server_callback_anonymous
-    gsasl_server_callback_anonymous_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_realm_set (Gsasl * ctx,
-                                              Gsasl_server_callback_realm cb);
-  extern Gsasl_server_callback_realm
-    gsasl_server_callback_realm_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_qop_set (Gsasl * ctx,
-                                            Gsasl_server_callback_qop cb);
-  extern Gsasl_server_callback_qop
-    gsasl_server_callback_qop_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_maxbuf_set (Gsasl * ctx,
-                                               Gsasl_server_callback_maxbuf 
cb);
-  extern Gsasl_server_callback_maxbuf
-    gsasl_server_callback_maxbuf_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_cipher_set (Gsasl * ctx,
-                                               Gsasl_server_callback_cipher 
cb);
-  extern Gsasl_server_callback_cipher
-    gsasl_server_callback_cipher_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_securid_set (Gsasl * ctx,
-                                                Gsasl_server_callback_securid 
cb);
-  extern Gsasl_server_callback_securid
-    gsasl_server_callback_securid_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_gssapi_set (Gsasl * ctx,
-                                               Gsasl_server_callback_gssapi 
cb);
-  extern Gsasl_server_callback_gssapi
-    gsasl_server_callback_gssapi_get (Gsasl * ctx);
-
-  extern void gsasl_server_callback_service_set (Gsasl * ctx,
-                                                Gsasl_server_callback_service 
cb);
-  extern Gsasl_server_callback_service
-    gsasl_server_callback_service_get (Gsasl * ctx);
-
-  /* Obsolete functions. */
-#define Gsasl_ctx Gsasl
-#define Gsasl_session_ctx Gsasl_session
-  extern int gsasl_client_listmech (Gsasl_ctx * ctx, char *out,
-                                   size_t * outlen);
-  extern int gsasl_server_listmech (Gsasl_ctx * ctx, char *out,
-                                   size_t * outlen);
-  extern int gsasl_client_step (Gsasl_session_ctx * sctx,
-                               const char *input, size_t input_len,
-                               char *output, size_t * output_len);
-  extern int gsasl_client_step_base64 (Gsasl_session_ctx * sctx,
-                                      const char *b64input,
-                                      char *b64output, size_t b64output_len);
-  extern int gsasl_server_step (Gsasl_session_ctx * sctx,
-                               const char *input, size_t input_len,
-                               char *output, size_t * output_len);
-  extern int gsasl_server_step_base64 (Gsasl_session_ctx * sctx,
-                                      const char *b64input,
-                                      char *b64output, size_t b64output_len);
-  extern void gsasl_client_finish (Gsasl_session_ctx * sctx);
-  extern void gsasl_server_finish (Gsasl_session_ctx * sctx);
-  extern Gsasl_ctx *gsasl_client_ctx_get (Gsasl_session_ctx * sctx);
-  extern Gsasl_ctx *gsasl_server_ctx_get (Gsasl_session_ctx * sctx);
-  extern void gsasl_client_application_data_set (Gsasl_session_ctx * sctx,
-                                                void *application_data);
-  extern void *gsasl_client_application_data_get (Gsasl_session_ctx * sctx);
-  extern void gsasl_server_application_data_set (Gsasl_session_ctx * sctx,
-                                                void *application_data);
-  extern void *gsasl_server_application_data_get (Gsasl_session_ctx * sctx);
-  extern int gsasl_randomize (int strong, char *data, size_t datalen);
+  /* For compatibility with earlier versions. */
+#include <gsasl-compat.h>
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif                         /* _GSASL_H */
+#endif                         /* GSASL_H */
--- /home/cvs/gsasl/lib/src/internal.h  2004/09/17 21:27:12     1.4
+++ /home/cvs/gsasl/lib/src/internal.h  2004/09/18 00:58:36     1.5
@@ -91,6 +91,11 @@
   size_t n_server_mechs;
   _Gsasl_mechanism *server_mechs;
   void *application_data;
+  /* Global callback. */
+  Gsasl_callback cb;
+  /* Global properties. */
+  char *anonymous_token;
+  /* Obsolete callbacks. */
   Gsasl_client_callback_authorization_id cbc_authorization_id;
   Gsasl_client_callback_authentication_id cbc_authentication_id;
   Gsasl_client_callback_password cbc_password;
@@ -124,6 +129,12 @@
   _Gsasl_mechanism *mech;
   void *application_data;
   void *mech_data;
+  /* Session specific callback.  If NULL, use global callback in
+   * ctx->cb.  */
+  Gsasl_callback cb;
+  /* Session specific properties.  If NULL, use corresponding global
+   * property. */
+  char *anonymous_token;
 };
 
 #endif /* _INTERNAL_H */
--- /home/cvs/gsasl/lib/src/xfinish.c   2004/04/15 22:02:50     1.2
+++ /home/cvs/gsasl/lib/src/xfinish.c   2004/09/18 00:58:36     1.3
@@ -37,5 +37,8 @@
     sctx->mech->server.finish (sctx, sctx->mech_data);
   /* XXX return value? */
 
+  if (sctx->anonymous_token)
+    free (sctx->anonymous_token);
+
   free (sctx);
 }

--- /home/cvs/gsasl/lib/src/gsasl-compat.h      2004/09/18 00:58:36     NONE
+++ /home/cvs/gsasl/lib/src/gsasl-compat.h      2004/09/18 00:58:36     1.1
/* gsasl-compat.h --- Header file for obsoleted features in GNU SASL Library.
 * Copyright (C) 2002, 2003, 2004  Simon Josefsson
 *
 * This file is part of GNU SASL Library.
 *
 * GNU SASL Library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * GNU SASL Library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * License along with GNU SASL Library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef GSASL_COMPAT_H
# define GSASL_COMPAT_H

/* Callback prototypes */
typedef int (*Gsasl_client_callback_anonymous) (Gsasl_session * sctx,
                                                char *out, size_t * outlen);
typedef int (*Gsasl_client_callback_authentication_id) (Gsasl_session *
                                                        sctx, char *out,
                                                        size_t * outlen);
typedef int (*Gsasl_client_callback_authorization_id) (Gsasl_session *
                                                       sctx, char *out,
                                                       size_t * outlen);
typedef int (*Gsasl_client_callback_password) (Gsasl_session * sctx,
                                               char *out, size_t * outlen);
typedef int (*Gsasl_client_callback_passcode) (Gsasl_session * sctx,
                                               char *out, size_t * outlen);
typedef int (*Gsasl_client_callback_pin) (Gsasl_session * sctx,
                                          char *suggestion, char *out,
                                          size_t * outlen);
typedef int (*Gsasl_client_callback_service) (Gsasl_session * sctx,
                                              char *service,
                                              size_t * servicelen,
                                              char *hostname,
                                              size_t * hostnamelen,
                                              char *servicename,
                                              size_t * servicenamelen);
typedef Gsasl_qop (*Gsasl_client_callback_qop) (Gsasl_session * sctx,
                                                Gsasl_qop serverqops);
typedef size_t (*Gsasl_client_callback_maxbuf) (Gsasl_session * sctx,
                                                size_t servermaxbuf);
typedef int (*Gsasl_client_callback_realm) (Gsasl_session * sctx,
                                            char *out, size_t * outlen);
typedef int (*Gsasl_server_callback_retrieve) (Gsasl_session * sctx,
                                               const char *authentication_id,
                                               const char *authorization_id,
                                               const char *realm, char *key,
                                               size_t * keylen);
typedef int (*Gsasl_server_callback_validate) (Gsasl_session * sctx,
                                               const char *authorization_id,
                                               const char *authentication_id,
                                               const char *password);
typedef int (*Gsasl_server_callback_gssapi) (Gsasl_session * sctx,
                                             const char *clientname,
                                             const char *authentication_id);
typedef int (*Gsasl_server_callback_securid) (Gsasl_session * sctx,
                                              const char *authentication_id,
                                              const char *authorization_id,
                                              const char *passcode,
                                              char *pin, char *suggestpin,
                                              size_t * suggestpinlen);
typedef int (*Gsasl_server_callback_cram_md5) (Gsasl_session * sctx,
                                               char *username,
                                               char *challenge,
                                               char *response);
typedef int (*Gsasl_server_callback_digest_md5) (Gsasl_session * sctx,
                                                 char *username,
                                                 char *realm,
                                                 char *secrethash);
typedef int (*Gsasl_server_callback_service) (Gsasl_session * sctx,
                                              char *service,
                                              size_t * servicelen,
                                              char *hostname,
                                              size_t * hostnamelen);
typedef int (*Gsasl_server_callback_external) (Gsasl_session * sctx);
typedef int (*Gsasl_server_callback_anonymous) (Gsasl_session * sctx,
                                                const char *token);
typedef int (*Gsasl_server_callback_realm) (Gsasl_session * sctx,
                                            char *out,
                                            size_t * outlen, size_t nth);
typedef Gsasl_qop (*Gsasl_server_callback_qop) (Gsasl_session * sctx);
typedef size_t (*Gsasl_server_callback_maxbuf) (Gsasl_session * sctx);
typedef Gsasl_cipher (*Gsasl_server_callback_cipher) (Gsasl_session * sctx);

/* Obsolete client callbacks: callback-c.c */
extern void
  gsasl_client_callback_authorization_id_set
  (Gsasl * ctx, Gsasl_client_callback_authorization_id cb);
extern Gsasl_client_callback_authorization_id
gsasl_client_callback_authorization_id_get (Gsasl * ctx);

extern void
  gsasl_client_callback_authentication_id_set
  (Gsasl * ctx, Gsasl_client_callback_authentication_id cb);
extern Gsasl_client_callback_authentication_id
gsasl_client_callback_authentication_id_get (Gsasl * ctx);

extern void
gsasl_client_callback_anonymous_set (Gsasl * ctx,
                                     Gsasl_client_callback_anonymous cb);
extern Gsasl_client_callback_anonymous
gsasl_client_callback_anonymous_get (Gsasl * ctx);

extern void
gsasl_client_callback_password_set (Gsasl * ctx,
                                    Gsasl_client_callback_password cb);
extern Gsasl_client_callback_password
gsasl_client_callback_password_get (Gsasl * ctx);

extern void
gsasl_client_callback_passcode_set (Gsasl * ctx,
                                    Gsasl_client_callback_passcode cb);
extern Gsasl_client_callback_passcode
gsasl_client_callback_passcode_get (Gsasl * ctx);

extern void
gsasl_client_callback_pin_set (Gsasl * ctx, Gsasl_client_callback_pin cb);
extern Gsasl_client_callback_pin gsasl_client_callback_pin_get (Gsasl * ctx);

extern void
gsasl_client_callback_service_set (Gsasl * ctx,
                                   Gsasl_client_callback_service cb);
extern Gsasl_client_callback_service
gsasl_client_callback_service_get (Gsasl * ctx);

extern void
gsasl_client_callback_qop_set (Gsasl * ctx, Gsasl_client_callback_qop cb);
extern Gsasl_client_callback_qop gsasl_client_callback_qop_get (Gsasl * ctx);

extern void
gsasl_client_callback_maxbuf_set (Gsasl * ctx,
                                  Gsasl_client_callback_maxbuf cb);
extern Gsasl_client_callback_maxbuf
gsasl_client_callback_maxbuf_get (Gsasl * ctx);
extern void
gsasl_client_callback_realm_set (Gsasl * ctx, Gsasl_client_callback_realm cb);
extern Gsasl_client_callback_realm
gsasl_client_callback_realm_get (Gsasl * ctx);

/* Obsolete server callbacks: callback-s.c */
extern void
gsasl_server_callback_validate_set (Gsasl * ctx,
                                    Gsasl_server_callback_validate cb);
extern Gsasl_server_callback_validate
gsasl_server_callback_validate_get (Gsasl * ctx);

extern void
gsasl_server_callback_retrieve_set (Gsasl * ctx,
                                    Gsasl_server_callback_retrieve cb);
extern Gsasl_server_callback_retrieve
gsasl_server_callback_retrieve_get (Gsasl * ctx);

extern void
gsasl_server_callback_cram_md5_set (Gsasl * ctx,
                                    Gsasl_server_callback_cram_md5 cb);
extern Gsasl_server_callback_cram_md5
gsasl_server_callback_cram_md5_get (Gsasl * ctx);

extern void
gsasl_server_callback_digest_md5_set (Gsasl * ctx,
                                      Gsasl_server_callback_digest_md5 cb);
extern Gsasl_server_callback_digest_md5
gsasl_server_callback_digest_md5_get (Gsasl * ctx);

extern void
gsasl_server_callback_external_set (Gsasl * ctx,
                                    Gsasl_server_callback_external cb);
extern Gsasl_server_callback_external
gsasl_server_callback_external_get (Gsasl * ctx);

extern void
gsasl_server_callback_anonymous_set (Gsasl * ctx,
                                     Gsasl_server_callback_anonymous cb);
extern Gsasl_server_callback_anonymous
gsasl_server_callback_anonymous_get (Gsasl * ctx);

extern void
gsasl_server_callback_realm_set (Gsasl * ctx, Gsasl_server_callback_realm cb);
extern Gsasl_server_callback_realm
gsasl_server_callback_realm_get (Gsasl * ctx);

extern void
gsasl_server_callback_qop_set (Gsasl * ctx, Gsasl_server_callback_qop cb);
extern Gsasl_server_callback_qop gsasl_server_callback_qop_get (Gsasl * ctx);

extern void
gsasl_server_callback_maxbuf_set (Gsasl * ctx,
                                  Gsasl_server_callback_maxbuf cb);
extern Gsasl_server_callback_maxbuf
gsasl_server_callback_maxbuf_get (Gsasl * ctx);

extern void
gsasl_server_callback_cipher_set (Gsasl * ctx,
                                  Gsasl_server_callback_cipher cb);
extern Gsasl_server_callback_cipher
gsasl_server_callback_cipher_get (Gsasl * ctx);

extern void
gsasl_server_callback_securid_set (Gsasl * ctx,
                                   Gsasl_server_callback_securid cb);
extern Gsasl_server_callback_securid
gsasl_server_callback_securid_get (Gsasl * ctx);

extern void
gsasl_server_callback_gssapi_set (Gsasl * ctx,
                                  Gsasl_server_callback_gssapi cb);
extern Gsasl_server_callback_gssapi
gsasl_server_callback_gssapi_get (Gsasl * ctx);

extern void
gsasl_server_callback_service_set (Gsasl * ctx,
                                   Gsasl_server_callback_service cb);
extern Gsasl_server_callback_service
gsasl_server_callback_service_get (Gsasl * ctx);

  /* Obsolete functions. */
#define Gsasl_ctx Gsasl
#define Gsasl_session_ctx Gsasl_session
extern int gsasl_client_listmech (Gsasl_ctx * ctx, char *out,
                                  size_t * outlen);
extern int gsasl_server_listmech (Gsasl_ctx * ctx, char *out,
                                  size_t * outlen);
extern int gsasl_client_step (Gsasl_session_ctx * sctx,
                              const char *input, size_t input_len,
                              char *output, size_t * output_len);
extern int gsasl_client_step_base64 (Gsasl_session_ctx * sctx,
                                     const char *b64input,
                                     char *b64output, size_t b64output_len);
extern int gsasl_server_step (Gsasl_session_ctx * sctx,
                              const char *input, size_t input_len,
                              char *output, size_t * output_len);
extern int gsasl_server_step_base64 (Gsasl_session_ctx * sctx,
                                     const char *b64input,
                                     char *b64output, size_t b64output_len);
extern void gsasl_client_finish (Gsasl_session_ctx * sctx);
extern void gsasl_server_finish (Gsasl_session_ctx * sctx);
extern Gsasl_ctx *gsasl_client_ctx_get (Gsasl_session_ctx * sctx);
extern Gsasl_ctx *gsasl_server_ctx_get (Gsasl_session_ctx * sctx);
extern void gsasl_client_application_data_set (Gsasl_session_ctx * sctx,
                                               void *application_data);
extern void *gsasl_client_application_data_get (Gsasl_session_ctx * sctx);
extern void gsasl_server_application_data_set (Gsasl_session_ctx * sctx,
                                               void *application_data);
extern void *gsasl_server_application_data_get (Gsasl_session_ctx * sctx);
extern int gsasl_randomize (int strong, char *data, size_t datalen);

#endif /* GSASL_COMPAT_H */
--- /home/cvs/gsasl/lib/src/property.c  2004/09/18 00:58:36     NONE
+++ /home/cvs/gsasl/lib/src/property.c  2004/09/18 00:58:36     1.1
/* property.c --- Callback property handling.
 * Copyright (C) 2004  Simon Josefsson
 *
 * This file is part of GNU SASL Library.
 *
 * GNU SASL Library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * GNU SASL Library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * License along with GNU SASL Library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include "internal.h"

static char **
map (Gsasl_session * sctx, Gsasl_property prop)
{
  char **p = NULL;

  switch (prop)
    {
    case GSASL_CLIENT_ANONYMOUS:
    case GSASL_SERVER_ANONYMOUS:
      p = &sctx->anonymous_token;
      break;

    default:
      break;
    }

  return p;
}

static char **
map_global (Gsasl * ctx, Gsasl_property prop)
{
  char **p = NULL;

  switch (prop)
    {
    case GSASL_CLIENT_ANONYMOUS:
    case GSASL_SERVER_ANONYMOUS:
      p = &ctx->anonymous_token;
      break;

    default:
      break;
    }

  return p;
}

/**
 * gsasl_property_set:
 * @sctx: session handle.
 * @prop: enumerated value of Gsasl_property type, indicating the
 *        type of data in @data.
 * @data: zero terminated character string to store.
 *
 * Make a copy of @data and store it in the session handle for the
 * indicated property @prop.  You can immediately deallocate @data
 * after calling this function, without affecting the data stored in
 * the session handle.
 *
 * It is valid, but may be confusing at first, to store both session
 * specific properties, using gsasl_property_set(), and more global
 * library handle properties using gsasl_property_set_global(), at the
 * same time.  The functions gsasl_property_get() and
 * gsasl_property_fast() will fall back to the global variables if no
 * session specific data is present.
 **/
void
gsasl_property_set (Gsasl_session * sctx, Gsasl_property prop,
                    const char *data)
{
  char **p = map (sctx, prop);

  if (p)
    {
      if (*p)
        free (*p);
      *p = strdup (data);
    }
}

/**
 * gsasl_property_set_global:
 * @ctx: library handle.
 * @prop: enumerated value of Gsasl_property type, indicating the
 *        type of data in @data.
 * @data: zero terminated character string to store.
 *
 * Make a copy of @data and store it in the library handle for the
 * indicated property @prop.  You can immediately deallocate @data
 * after calling this function, without affecting the data stored in
 * the session handle.
 *
 * It is valid, but may be confusing at first, to store both session
 * specific properties, using gsasl_property_set(), and more global
 * library handle properties using gsasl_property_set_global(), at the
 * same time.  The functions gsasl_property_get() and
 * gsasl_property_fast() will fall back to the global variables if no
 * session specific data is present.
 **/
void
gsasl_property_set_global (Gsasl * ctx, Gsasl_property prop,
                           const char *data)
{
  char **p = map_global (ctx, prop);

  if (p)
    {
      if (*p)
        free (*p);
      *p = strdup (data);
    }
}

/**
 * gsasl_property_fast_global:
 * @ctx: library handle.
 * @prop: enumerated value of Gsasl_property type, indicating the
 *        type of data in @data.

[142 lines skipped]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]