lib-network
[apps/madmutt.git] / mutt_sasl.c
index c93413d..d5738b6 100644 (file)
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "account.h"
 #include "mutt_sasl.h"
-#include "mutt_socket.h"
+#include <lib-network/mutt_socket.h>
 
-#include "lib/mem.h"
 #include "lib/debug.h"
 
 #include <errno.h>
@@ -69,7 +70,6 @@ static int getnameinfo_err (int ret)
   }
   return err;
 }
-#endif
 
 /* arbitrary. SASL will probably use a smaller buffer anyway. OTOH it's
  * been a while since I've had access to an SASL server which negotiated
@@ -116,14 +116,13 @@ static int iptostring (const struct sockaddr *addr, socklen_t addrlen,
   if (ret)
     return getnameinfo_err (ret);
 
-  if (outlen < str_len (hbuf) + str_len (pbuf) + 2)
+  if (outlen < m_strlen(hbuf) + m_strlen(pbuf) + 2)
     return SASL_BUFOVER;
 
   snprintf (out, outlen, "%s;%s", hbuf, pbuf);
 
   return SASL_OK;
 }
-#endif
 
 /* mutt_sasl_start: called before doing a SASL exchange - initialises library
  *   (if necessary). */
@@ -258,7 +257,7 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn)
    * just fall back to LOGIN in the IMAP case anyway. If that doesn't
    * work for POP, we can make it a flag or move this code into
    * imap/auth_sasl.c */
-  memset (&secprops, 0, sizeof (secprops));
+  p_clear(&secprops, 1);
   /* Work around a casting bug in the SASL krb4 module */
   secprops.max_ssf = 0x7fff;
   secprops.maxbufsize = M_SASL_MAXBUF;
@@ -332,10 +331,8 @@ int mutt_sasl_interact (sasl_interact_t * interaction)
     if (mutt_get_field (prompt, resp, sizeof (resp), 0))
       return SASL_FAIL;
 
-    interaction->len = str_len (resp) + 1;
-    interaction->result = mem_malloc (interaction->len);
-    memcpy ((char*) interaction->result, resp, interaction->len);
-
+    interaction->len = m_strlen(resp) + 1;
+    interaction->result = p_dupstr(resp, interaction->len - 1);
     interaction++;
   }
 
@@ -360,16 +357,16 @@ int mutt_sasl_interact (sasl_interact_t * interaction)
  *   for the read/write methods. */
 void mutt_sasl_setup_conn (CONNECTION * conn, sasl_conn_t * saslconn)
 {
-  SASL_DATA *sasldata = (SASL_DATA *) mem_malloc (sizeof (SASL_DATA));
+  SASL_DATA *sasldata = p_new(SASL_DATA, 1);
 
   sasldata->saslconn = saslconn;
   /* get ssf so we know whether we have to (en|de)code read/write */
-  sasl_getprop (saslconn, SASL_SSF, (const void **) &sasldata->ssf);
+  sasl_getprop (saslconn, SASL_SSF, (const void **)(void *)&sasldata->ssf);
   debug_print (3, ("SASL protection strength: %u\n", *sasldata->ssf));
   /* Add SASL SSF to transport SSF */
   conn->ssf += *sasldata->ssf;
   sasl_getprop (saslconn, SASL_MAXOUTBUF,
-                (const void **) &sasldata->pbufsize);
+                (const void **)(void *)&sasldata->pbufsize);
   debug_print (3, ("SASL protection buffer size: %u\n", *sasldata->pbufsize));
 
   /* clear input buffer */
@@ -432,7 +429,7 @@ static int mutt_sasl_cb_authname (void *context, int id, const char **result,
   }
 
   if (len)
-    *len = str_len (*result);
+    *len = m_strlen(*result);
 
   return SASL_OK;
 }
@@ -452,9 +449,9 @@ static int mutt_sasl_cb_pass (sasl_conn_t * conn, void *context, int id,
   if (mutt_account_getpass (account))
     return SASL_FAIL;
 
-  len = str_len (account->pass);
+  len = m_strlen(account->pass);
 
-  *psecret = (sasl_secret_t *) mem_malloc (sizeof (sasl_secret_t) + len);
+  *psecret = xmalloc(sizeof(sasl_secret_t) + len);
   (*psecret)->len = len;
   strcpy ((char*) (*psecret)->data, account->pass);     /* __STRCPY_CHECKED__ */
 
@@ -496,8 +493,8 @@ static int mutt_sasl_conn_close (CONNECTION * conn)
 
   /* release sasl resources */
   sasl_dispose (&sasldata->saslconn);
-  mem_free (&sasldata->buf);
-  mem_free (&sasldata);
+  p_delete(&sasldata->buf);
+  p_delete(&sasldata);
 
   /* call underlying close */
   rc = (conn->conn_close) (conn);
@@ -527,7 +524,7 @@ static int mutt_sasl_conn_read (CONNECTION * conn, char *buf, size_t len)
 
   conn->sockdata = sasldata->sockdata;
 
-  mem_free (&sasldata->buf);
+  p_delete(&sasldata->buf);
   sasldata->bpos = 0;
   sasldata->blen = 0;
 
@@ -592,7 +589,7 @@ static int mutt_sasl_conn_write (CONNECTION * conn, const char *buf,
       }
 
       rc = (sasldata->msasl_write) (conn, pbuf, plen);
-      mem_free (&pbuf);
+      p_delete(&pbuf);
       if (rc != plen)
         goto fail;