Source-Changes-HG archive

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

[src/trunk]: src/crypto/external/bsd/libsaslc/dist improve error handling, fr...



details:   https://anonhg.NetBSD.org/src/rev/348a1314b359
branches:  trunk
changeset: 762345:348a1314b359
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Feb 20 01:59:46 2011 +0000

description:
improve error handling, from Anon Ymous

diffstat:

 crypto/external/bsd/libsaslc/dist/man/libsaslc.3       |    8 +-
 crypto/external/bsd/libsaslc/dist/src/list.c           |   18 +-
 crypto/external/bsd/libsaslc/dist/src/list.h           |    4 +-
 crypto/external/bsd/libsaslc/dist/src/mech_digestmd5.c |  163 ++++++++++------
 crypto/external/bsd/libsaslc/dist/src/mech_gssapi.c    |   10 +-
 crypto/external/bsd/libsaslc/dist/src/xsess.c          |   62 +++---
 6 files changed, 157 insertions(+), 108 deletions(-)

diffs (truncated from 634 to 300 lines):

diff -r 84fb00028557 -r 348a1314b359 crypto/external/bsd/libsaslc/dist/man/libsaslc.3
--- a/crypto/external/bsd/libsaslc/dist/man/libsaslc.3  Sun Feb 20 01:26:22 2011 +0000
+++ b/crypto/external/bsd/libsaslc/dist/man/libsaslc.3  Sun Feb 20 01:59:46 2011 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: libsaslc.3,v 1.9 2011/02/16 02:14:22 christos Exp $
+.\"    $NetBSD: libsaslc.3,v 1.10 2011/02/20 01:59:46 christos Exp $
 .\"
 .\" Copyright (c) 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -34,7 +34,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd February 14, 2011
+.Dd February 18, 2011
 .Dt LIBSASLC 3
 .Os
 .Sh NAME
@@ -778,6 +778,10 @@
 authentication with a
 .Xr postfix 1
 SMTP server using the cyrus-sasl library.
+LOGIN, PLAIN, CRAM-MD5, and DIGEST-MD5 have also been tested and shown
+to work with a
+.Xr postfix 1
+SMTP server using a dovecot backend for authentication.
 The DIGEST-MD5 and GSSAPI specs also provide for integrity and
 confidentiality layers via the
 .Fn saslc_sess_encode
diff -r 84fb00028557 -r 348a1314b359 crypto/external/bsd/libsaslc/dist/src/list.c
--- a/crypto/external/bsd/libsaslc/dist/src/list.c      Sun Feb 20 01:26:22 2011 +0000
+++ b/crypto/external/bsd/libsaslc/dist/src/list.c      Sun Feb 20 01:59:46 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: list.c,v 1.2 2011/02/12 23:21:32 christos Exp $ */
+/* $NetBSD: list.c,v 1.3 2011/02/20 01:59:46 christos Exp $ */
 
 /* Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: list.c,v 1.2 2011/02/12 23:21:32 christos Exp $");
+__RCSID("$NetBSD: list.c,v 1.3 2011/02/20 01:59:46 christos Exp $");
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -164,11 +164,14 @@
 /**
  * @brief Parse a list of the following format:
  *   ( *LWS element *( *LWS "," *LWS element ))
+ * @param lp pointer to list_t type for returned list.  Cannot be NULL.
  * @param p string to parse
- * @return allocated list.
+ * @return 0 on success, -1 on error (no memory).
+ *
+ * Note: the list is allocated.  Use saslc__list_free() to free it.
  */
-list_t *
-saslc__list_parse(const char *p)
+int
+saslc__list_parse(list_t **lp, const char *p)
 {
        const char *e, *n;
        list_t *l, *t, **tp;
@@ -189,7 +192,7 @@
                t = alloc_list(p, (size_t)(e - p));
                if (t == NULL) {
                        saslc__list_free(l);
-                       return NULL;
+                       return -1;
                }
                if (tp != NULL)
                        *tp = t;
@@ -197,7 +200,8 @@
                        l = t;
                tp = &t->next;
        }
-       return l;
+       *lp = l;
+       return 0;
 }
 
 /**
diff -r 84fb00028557 -r 348a1314b359 crypto/external/bsd/libsaslc/dist/src/list.h
--- a/crypto/external/bsd/libsaslc/dist/src/list.h      Sun Feb 20 01:26:22 2011 +0000
+++ b/crypto/external/bsd/libsaslc/dist/src/list.h      Sun Feb 20 01:59:46 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: list.h,v 1.1 2011/02/11 23:44:43 christos Exp $ */
+/* $NetBSD: list.h,v 1.2 2011/02/20 01:59:46 christos Exp $ */
 
 /* Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -49,6 +49,6 @@
 uint32_t saslc__list_flags(list_t *, const named_flag_t *);
 void     saslc__list_free(list_t *);
 void     saslc__list_log(list_t *, const char *);
-list_t * saslc__list_parse(const char *);
+int      saslc__list_parse(list_t **, const char *);
 
 #endif /* ! _LIST_H_ */
diff -r 84fb00028557 -r 348a1314b359 crypto/external/bsd/libsaslc/dist/src/mech_digestmd5.c
--- a/crypto/external/bsd/libsaslc/dist/src/mech_digestmd5.c    Sun Feb 20 01:26:22 2011 +0000
+++ b/crypto/external/bsd/libsaslc/dist/src/mech_digestmd5.c    Sun Feb 20 01:59:46 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mech_digestmd5.c,v 1.9 2011/02/16 02:14:22 christos Exp $ */
+/* $NetBSD: mech_digestmd5.c,v 1.10 2011/02/20 01:59:46 christos Exp $ */
 
 /* Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: mech_digestmd5.c,v 1.9 2011/02/16 02:14:22 christos Exp $");
+__RCSID("$NetBSD: mech_digestmd5.c,v 1.10 2011/02/20 01:59:46 christos Exp $");
 
 #include <sys/param.h>
 
@@ -651,22 +651,23 @@
  * @param hqlist a comma delimited list with entries of the form
  * "[hostname:]string".
  * @param hostname the hostname to use in the selection.
- * @return the best matching string or NULL if none found.
+ * @param rval pointer to location for returned string.  Set to NULL
+ * if none found, otherwise set to strdup(3) of the string found.
+ * @return 0 on success, -1 on failure (no memory).
  *
- * NOTE: hqlist must not be NULL.
+ * NOTE: hqlist and rval must not be NULL.
  * NOTE: this allocates memory for its output and the caller is
  * responsible for freeing it.
  */
-static char *
-choose_from_hqlist(const char *hqlist, const char *hostname)
+static int
+choose_from_hqlist(const char *hqlist, const char *hostname, char **rval)
 {
        list_t *l, *list;
        size_t len;
        char *p;
 
-       list = saslc__list_parse(hqlist);
-       if (list == NULL)
-               return NULL;
+       if (saslc__list_parse(&list, hqlist) == -1)
+               return -1;      /* no memory */
 
        /*
         * If the user provided a list and the caller provided a
@@ -677,14 +678,14 @@
                len = strlen(hostname);
                for (l = list; l != NULL; l = l->next) {
                        p = l->value + len;
-                       if (strncasecmp(l->value, hostname, len) != 0 ||
-                           *p != ':')
+                       if (*p != ':' ||
+                           strncasecmp(l->value, hostname, len) != 0)
                                continue;
 
                        if (*(++p) != '\0' && isalnum((unsigned char)*p)) {
-                               p = strdup(p);
-                               saslc__list_free(list);
-                               return p;
+                               if ((p = strdup(p)) == NULL)
+                                       goto nomem;
+                               goto done;
                        }
                }
        }
@@ -695,12 +696,18 @@
        p = NULL;
        for (l = list; l != NULL; l = l->next) {
                if (strchr(l->value, ':') == NULL) {
-                       p = strdup(l->value);
-                       break;
+                       if ((p = strdup(l->value)) == NULL)
+                               goto nomem;
+                       goto done;
                }
        }
+ done:
        saslc__list_free(list);
-       return p;
+       *rval = p;
+       return 0;
+ nomem:
+       saslc__list_free(list);
+       return -1;
 }
 
 /**
@@ -714,15 +721,12 @@
 static char *
 saslc__mech_digestmd5_digesturi(saslc_sess_t *sess, const char *serv_host)
 {
-       saslc__mech_digestmd5_sess_t *ms;
        const char *serv_list;
        char *serv_name;
        const char *serv_type;
        char *r;
        int rv;
 
-       ms = sess->mech_sess;
-
        serv_type = saslc_sess_getprop(sess, SASLC_DIGESTMD5_SERVICE);
        if (serv_type == NULL) {
                saslc__error_set(ERR(sess), ERROR_MECH,
@@ -730,10 +734,13 @@
                return NULL;
        }
        serv_list = saslc_sess_getprop(sess, SASLC_DIGESTMD5_SERVNAME);
-       serv_name = serv_list != NULL
-           ? choose_from_hqlist(serv_list, serv_host) : NULL;
+       if (serv_list == NULL)
+               serv_name = NULL;
+       else if (choose_from_hqlist(serv_list, serv_host, &serv_name) == -1)
+               goto nomem;
 
-       saslc__msg_dbg("%s: serv_name='%s'", __func__, serv_name);
+       saslc__msg_dbg("%s: serv_name='%s'", __func__,
+           serv_name ? serv_name : "<null>");
 
        /****************************************************************/
        /* digest-uri       = "digest-uri" "=" <"> digest-uri-value <"> */
@@ -753,12 +760,14 @@
            : asprintf(&r, "%s/%s/%s", serv_type, serv_host, serv_name);
        if (serv_name != NULL)
                free(serv_name);
-       if (rv == -1) {
-               saslc__error_set_errno(ERR(sess), ERROR_NOMEM);
-               return NULL;
-       }
+       if (rv == -1)
+               goto nomem;
+
        saslc__msg_dbg("%s: digest-uri='%s'", __func__, r);
        return r;
+ nomem:
+       saslc__error_set_errno(ERR(sess), ERROR_NOMEM);
+       return NULL;
 }
 
 /**
@@ -871,15 +880,21 @@
         */
        if (realms == NULL) {
                /*
-                * No realm was supplied.  Figure out a plausable
-                * default.
+                * No realm was supplied in challenge.  Figure out a
+                * plausable default.
                 */
-               if (user_realms != NULL) {
-                       p = choose_from_hqlist(user_realms, hostname);
-                       if (p != NULL)
-                               return p;
+               if (user_realms == NULL) {
+                       saslc__error_set(ERR(sess), ERROR_MECH,
+                           "cannot determine the realm");
+                       return NULL;
                }
-               return NULL;
+               if (choose_from_hqlist(user_realms, hostname, &p) == -1)
+                       goto nomem;
+
+               if (p == NULL)
+                       saslc__error_set(ERR(sess), ERROR_MECH,
+                           "cannot choose a realm");
+               return p;
        }
 
        /************************************************************/
@@ -892,9 +907,14 @@
         * one from the user provided list, just take the first realm
         * from the challenge.
         */
-       if (user_realms == NULL ||
-           (p = choose_from_hqlist(user_realms, hostname)) == NULL)
-               return strdup(realms->value);
+       if (user_realms == NULL)
+               goto use_1st_realm;
+
+       if (choose_from_hqlist(user_realms, hostname, &p) == -1)
+               goto nomem;
+
+       if (p == NULL)
+               goto use_1st_realm;
 
        /*
         * If we found a matching user provide realm, make sure it is
@@ -905,7 +925,13 @@
                if (strcasecmp(p, l->value) == 0)
                        return p;
        }
-       return strdup(realms->value);
+ use_1st_realm:
+       if ((p = strdup(realms->value)) == NULL)
+               goto nomem;
+       return p;



Home | Main Index | Thread Index | Old Index