gsasl-commit
[Top][All Lists]
Advanced

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

CVS gsasl/src


From: gsasl-commit
Subject: CVS gsasl/src
Date: Tue, 30 Nov 2004 03:16:54 +0100

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

Modified Files:
        callbacks.c 
Log Message:
Use new API (server mode not ported yet).


--- /home/cvs/gsasl/src/callbacks.c     2004/10/31 20:58:12     1.31
+++ /home/cvs/gsasl/src/callbacks.c     2004/11/30 02:16:54     1.32
@@ -28,500 +28,109 @@
 extern char *readline (const char *prompt);
 #endif
 
-static int
-utf8cpy (char *dst, size_t * dstlen, char *src, size_t srclen)
+static char *
+locale_to_utf8 (char *str)
 {
-  int nonasciiflag = 0;
-  size_t i;
-  char *p = NULL;
-
-  if (srclen != strlen (src))
-    return !GSASL_OK;
-
-#if WITH_STRINGPREP
-  p = stringprep_locale_to_utf8 (src);
-#endif
-
-  if (p)
-    {
-      size_t len = strlen (p);
-
-      if (dst && *dstlen < len)
-       return GSASL_TOO_SMALL_BUFFER;
-      *dstlen = len;
-      if (dst)
-       strcpy (dst, p);
-      return GSASL_OK;
-    }
-
-#if WITH_STRINGPREP
-  fprintf (stderr, " ** failed to convert data from %s to UTF-8\n",
-          stringprep_locale_charset ());
-  fprintf (stderr, " ** check the system locale configuration\n");
-  fprintf (stderr, " ** treating input as ASCII\n");
-#endif
-
-  if (dst && *dstlen < srclen)
-    return GSASL_TOO_SMALL_BUFFER;
-
-  *dstlen = srclen;
-  for (i = 0; i < srclen; i++)
-    {
-      if (src[i] & 0x80)
-       nonasciiflag = 1;
-      if (dst)
-       dst[i] = src[i] & 0x7F;
-    }
-
-  if (nonasciiflag)
-    {
-      fprintf (stderr, " ** bit 8 stripped from string\n");
-      fprintf (stderr, " ** original string: `%s'\n", src);
-      fprintf (stderr, " ** stripped string: `%s'\n", dst);
-    }
-
-  return GSASL_OK;
-}
-
-/* Client callbacks */
-
-int
-client_callback_anonymous (Gsasl_session_ctx * ctx,
-                          char *out, size_t * outlen)
-{
-  int rc;
-
-  if (args_info.anonymous_token_arg == NULL)
-    args_info.anonymous_token_arg =
-      strdup (readline ("Enter anonymous token (e.g., email address): "));
-
-  if (args_info.anonymous_token_arg == NULL)
-    return GSASL_AUTHENTICATION_ERROR;
-
-  rc = utf8cpy (out, outlen, args_info.anonymous_token_arg,
-               strlen (args_info.anonymous_token_arg));
-  if (rc != GSASL_OK)
-    return rc;
-
-  return GSASL_OK;
-}
-
-int
-client_callback_authorization_id (Gsasl_session_ctx * ctx,
-                                 char *out, size_t * outlen)
-{
-  int rc;
-
-  if (args_info.authorization_id_arg == NULL)
-    {
-      if (outlen)
-       *outlen = 0;
-      return GSASL_OK;
-    }
-
-  rc = utf8cpy (out, outlen, args_info.authorization_id_arg,
-               strlen (args_info.authorization_id_arg));
-  if (rc != GSASL_OK)
-    return rc;
-
-  return GSASL_OK;
-}
-
-int
-client_callback_authentication_id (Gsasl_session_ctx * ctx,
-                                  char *out, size_t * outlen)
-{
-  int rc;
-
-  if (args_info.authentication_id_arg == NULL)
+  if (str)
     {
-      uid_t uid;
-      struct passwd *pw;
-
-      uid = getuid ();
-      pw = getpwuid (uid);
-
-      if (pw && pw->pw_name)
+      char *q = stringprep_locale_to_utf8 (str);
+      if (!q)
+       fprintf (stderr, "warning: Could not convert string to UTF-8...\n");
+      else
        {
-         printf ("Using system username `%s' as authentication identity.\n",
-                 pw->pw_name);
-         args_info.authentication_id_arg = strdup (pw->pw_name);
+         free (str);
+         str = q;
        }
-      else
-       args_info.authentication_id_arg =
-         strdup (readline ("Enter authentication ID: "));
     }
 
-  if (args_info.authentication_id_arg == NULL)
-    return GSASL_AUTHENTICATION_ERROR;
-
-  rc = utf8cpy (out, outlen, args_info.authentication_id_arg,
-               strlen (args_info.authentication_id_arg));
-  if (rc != GSASL_OK)
-    return rc;
-
-  return GSASL_OK;
+  return str;
 }
 
-int
-client_callback_password (Gsasl_session_ctx * ctx, char *out, size_t * outlen)
+static char *
+readutf8line (const char *prompt)
 {
-  int rc;
-
-  if (args_info.password_arg == NULL)
-    args_info.password_arg = getpass ("Enter password: ");
-
-  if (args_info.password_arg == NULL)
-    return GSASL_AUTHENTICATION_ERROR;
+  char *p = readline (prompt);
 
-  rc = utf8cpy (out, outlen, args_info.password_arg,
-               strlen (args_info.password_arg));
-  if (rc != GSASL_OK)
-    return rc;
-
-  return GSASL_OK;
+  return locale_to_utf8 (p);
 }
 
-int
-client_callback_service (Gsasl_session_ctx * ctx,
-                        char *srv,
-                        size_t * srvlen,
-                        char *host,
-                        size_t * hostlen, char *srvname, size_t * srvnamelen)
+static char *
+readutf8pass (const char *prompt)
 {
-  int rc;
-
-  if (args_info.service_arg == NULL)
-    args_info.service_arg =
-      strdup (readline ("Enter GSSAPI service name (e.g. \"imap\"): "));
-
-  if (args_info.hostname_arg == NULL)
-    args_info.hostname_arg = strdup (readline ("Enter hostname of server: "));
+  char *p = getpass (prompt);
 
-  if (srvnamelen && args_info.service_name_arg == NULL)
-    args_info.service_name_arg =
-      strdup (readline ("Enter generic server name (optional): "));
-
-  if (args_info.service_arg == NULL)
-    return GSASL_AUTHENTICATION_ERROR;
-
-  if (args_info.hostname_arg == NULL)
-    return GSASL_AUTHENTICATION_ERROR;
-
-  if (srvnamelen && args_info.service_name_arg == NULL)
-    return GSASL_AUTHENTICATION_ERROR;
-
-  rc = utf8cpy (srv, srvlen, args_info.service_arg,
-               strlen (args_info.service_arg));
-  if (rc != GSASL_OK)
-    return rc;
-
-  rc =
-    utf8cpy (host, hostlen, args_info.hostname_arg,
-            strlen (args_info.hostname_arg));
-  if (rc != GSASL_OK)
-    return rc;
-
-  if (srvnamelen)
-    {
-      rc =
-       utf8cpy (srvname, srvnamelen, args_info.service_name_arg,
-                strlen (args_info.service_name_arg));
-      if (rc != GSASL_OK)
-       return rc;
-    }
-
-  return GSASL_OK;
+  return locale_to_utf8 (p);
 }
 
 int
-client_callback_passcode (Gsasl_session_ctx * ctx, char *out, size_t * outlen)
+callback (Gsasl * ctx, Gsasl_session * sctx, Gsasl_property prop)
 {
-  int rc;
+  int rc = GSASL_NO_CALLBACK;
 
-  if (args_info.passcode_arg == NULL)
-    args_info.passcode_arg = getpass ("Enter passcode: ");
-
-  rc = utf8cpy (out, outlen, args_info.passcode_arg,
-               strlen (args_info.passcode_arg));
-  if (rc != GSASL_OK)
-    return rc;
-
-  return GSASL_OK;
-}
-
-Gsasl_qop
-client_callback_qop (Gsasl_session_ctx * ctx, Gsasl_qop serverqops)
-{
-  int qop = GSASL_QOP_AUTH;
-
-  if (args_info.quality_of_protection_given)
+  switch (prop)
     {
-      if (strcmp (args_info.quality_of_protection_arg, "auth") == 0)
-       qop = GSASL_QOP_AUTH;
-      else if (strcmp (args_info.quality_of_protection_arg, "auth-int") == 0)
-       qop = GSASL_QOP_AUTH_INT;
-      else if (strcmp (args_info.quality_of_protection_arg, "auth-conf") == 0)
-       qop = GSASL_QOP_AUTH_CONF;
-    }
+    case GSASL_ANONYMOUS_TOKEN:
+      if (args_info.anonymous_token_arg == NULL)
+       args_info.anonymous_token_arg =
+         readutf8line ("Enter anonymous token (e.g., email address): ");
 
-  if (!(serverqops & qop))
-    fprintf (stderr,
-            "Warning: Server QOPs %d does not include client QOP %d.\n",
-            serverqops, qop);
-  return qop;
-}
+      gsasl_property_set (sctx, GSASL_ANONYMOUS_TOKEN,
+                         args_info.anonymous_token_arg);
 
-size_t
-client_callback_maxbuf (Gsasl_session_ctx * ctx, size_t servermaxbuf)
-{
-  return args_info.maxbuf_arg;
-}
-
-int
-client_callback_realm (Gsasl_session_ctx * ctx, char *out, size_t * outlen)
-{
-  int rc;
-
-  if (args_info.realm_given == 0)
-    {
-      args_info.realm_arg = malloc (sizeof (*args_info.realm_arg));
-      memset (args_info.realm_arg, 0, sizeof (*args_info.realm_arg));
-    }
-
-  if (args_info.realm_arg[0] == NULL)
-    args_info.realm_arg[0] = strdup (readline ("Enter client realm: "));
+      rc = GSASL_OK;
+      break;
 
-  if (args_info.realm_arg[0] == NULL)
-    return GSASL_AUTHENTICATION_ERROR;
+    case GSASL_PASSWORD:
+      if (args_info.password_arg == NULL)
+       args_info.password_arg = readutf8pass ("Enter password: ");
 
-  rc =
-    utf8cpy (out, outlen, args_info.realm_arg[0],
-            strlen (args_info.realm_arg[0]));
-  if (rc != GSASL_OK)
-    return rc;
+      gsasl_property_set (sctx, GSASL_PASSWORD, args_info.password_arg);
 
-  return GSASL_OK;
-}
-
-/* Server callbacks */
-
-int
-server_callback_cram_md5 (Gsasl_session_ctx * ctx,
-                         char *username, char *challenge, char *response)
-{
-  char *data;
+      rc = GSASL_OK;
+      break;
 
-  printf ("User: `%s'\nChallenge: `%s'\nResponse: `%s'\n",
-         username, challenge, response);
+    case GSASL_PASSCODE:
+      if (args_info.passcode_arg == NULL)
+       args_info.passcode_arg = readutf8pass ("Enter passcode: ");
 
-  data = readline ("Admit user? (y/n) ");
+      gsasl_property_set (sctx, GSASL_PASSCODE, args_info.passcode_arg);
 
-  if (*data == 'y' || *data == 'Y')
-    return GSASL_OK;
-  else
-    return GSASL_AUTHENTICATION_ERROR;
-}
-
-int
-server_callback_anonymous (Gsasl_session_ctx * ctx, const char *message)
-{
-  char *data;
+      rc = GSASL_OK;
+      break;
 
-  printf ("Anonymous user: `%s'\n", message);
+    case GSASL_AUTHID:
+      if (args_info.authentication_id_arg == NULL)
+       {
+         uid_t uid;
+         struct passwd *pw;
 
-  data = readline ("Admit user? (y/n) ");
+         uid = getuid ();
+         pw = getpwuid (uid);
 
-  if (*data == 'y' || *data == 'Y')
-    return GSASL_OK;
-  else
-    return GSASL_AUTHENTICATION_ERROR;
-}
+         if (pw && pw->pw_name)
+           {
+             printf ("Using system username `%s' as "
+                     "authentication identity.\n", pw->pw_name);
+             args_info.authentication_id_arg = strdup (pw->pw_name);
+           }
+         else
+           args_info.authentication_id_arg =
+             readutf8line ("Enter authentication ID: ");
+       }
 
-Gsasl_qop
-server_callback_qop (Gsasl_session_ctx * ctx)
-{
-  return GSASL_QOP_AUTH | GSASL_QOP_AUTH_INT | GSASL_QOP_AUTH_CONF;
-}
+      gsasl_property_set (sctx, GSASL_AUTHID, args_info.authentication_id_arg);
+      rc = GSASL_OK;
+      break;
 
-size_t
-server_callback_maxbuf (Gsasl_session_ctx * ctx)
-{
-  return args_info.maxbuf_arg;
-}
+    case GSASL_AUTHZID:
+      gsasl_property_set (sctx, GSASL_AUTHZID, args_info.authorization_id_arg);
+      rc = GSASL_OK;
+      break;
 
-int
-server_callback_realm (Gsasl_session_ctx * ctx,
-                      char *out, size_t * outlen, size_t nth)
-{
-  int rc;
-
-  if (args_info.realm_given == 0)

[172 lines skipped]





reply via email to

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