diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-11-17 18:04:52 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-11-17 18:04:52 +0000 |
commit | c2db1deb321eb2c2cd9bfe0262ef1013ce7f617e (patch) | |
tree | 3fced821344b5f620e32e9bf60595ae8da20a0c0 | |
parent | 42a7cc48c7398707710bed6f6dd8bebe755690b2 (diff) | |
download | mailutils-c2db1deb321eb2c2cd9bfe0262ef1013ce7f617e.tar.gz mailutils-c2db1deb321eb2c2cd9bfe0262ef1013ce7f617e.tar.bz2 |
* mailbox/sha1.h: Remove.
* include/mailutils/sha1.h: Add.
* mailbox/md5.h: Remove.
* include/mailutils/md5.h: Add.
* include/mailutils/Makefile.am: Update.
* mailbox/Makefile.am: Update.
* libproto/pop/mbox.c, libproto/pop/pop3_apop.c,
libproto/pop/pop3_stls.c, mailbox/md5.c, mailbox/message.c,
mailbox/sha1.c, pop3d/apop.c, pop3d/pop3d.h, sql/mysql.c: Fix
usage of sha1_ and md5_.
* mailbox/mu_auth.c, mailbox/mutil.c, mailbox/rfc2047.c: Eliminate
strtok_r.
-rw-r--r-- | include/mailutils/Makefile.am | 2 | ||||
-rw-r--r-- | include/mailutils/md5.h (renamed from mailbox/md5.h) | 22 | ||||
-rw-r--r-- | include/mailutils/sha1.h (renamed from mailbox/sha1.h) | 13 | ||||
-rw-r--r-- | libproto/pop/mbox.c | 13 | ||||
-rw-r--r-- | libproto/pop/pop3_apop.c | 12 | ||||
-rw-r--r-- | libproto/pop/pop3_stls.c | 2 | ||||
-rw-r--r-- | mailbox/Makefile.am | 3 | ||||
-rw-r--r-- | mailbox/md5.c | 5 | ||||
-rw-r--r-- | mailbox/message.c | 11 | ||||
-rw-r--r-- | mailbox/mu_auth.c | 24 | ||||
-rw-r--r-- | mailbox/mutil.c | 16 | ||||
-rw-r--r-- | mailbox/rfc2047.c | 59 | ||||
-rw-r--r-- | mailbox/sha1.c | 2 | ||||
-rw-r--r-- | pop3d/apop.c | 10 | ||||
-rw-r--r-- | pop3d/pop3d.h | 2 | ||||
-rw-r--r-- | sql/mysql.c | 16 |
16 files changed, 125 insertions, 87 deletions
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am index feb1205ea..d068d8e93 100644 --- a/include/mailutils/Makefile.am +++ b/include/mailutils/Makefile.am @@ -56,6 +56,7 @@ pkginclude_HEADERS = \ mailcap.h\ mailer.h\ mailutils.h\ + md5.h\ message.h\ mime.h\ monitor.h\ @@ -71,6 +72,7 @@ pkginclude_HEADERS = \ radius.h\ refcount.h\ registrar.h\ + sha1.h\ stream.h\ syslog.h\ sql.h\ diff --git a/mailbox/md5.h b/include/mailutils/md5.h index c737040e1..efc4711ea 100644 --- a/mailbox/md5.h +++ b/include/mailutils/md5.h @@ -18,8 +18,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef _MD5_H -#define _MD5_H 1 +#ifndef _MAILUTILS_MD5_H +#define _MAILUTILS_MD5_H 1 #include <stdio.h> #include <stdint.h> @@ -44,15 +44,15 @@ # endif #endif -#ifndef _LIBC -# define __md5_buffer md5_buffer -# define __md5_finish_ctx md5_finish_ctx -# define __md5_init_ctx md5_init_ctx -# define __md5_process_block md5_process_block -# define __md5_process_bytes md5_process_bytes -# define __md5_read_ctx md5_read_ctx -# define __md5_stream md5_stream -#endif +#define __md5_buffer mu_md5_buffer +#define __md5_finish_ctx mu_md5_finish_ctx +#define __md5_init_ctx mu_md5_init_ctx +#define __md5_process_block mu_md5_process_block +#define __md5_process_bytes mu_md5_process_bytes +#define __md5_read_ctx mu_md5_read_ctx +#define __md5_stream mu_md5_stream + +#define md5_ctx mu_md5_ctx /* Structure to save state of computation between the single steps. */ struct md5_ctx diff --git a/mailbox/sha1.h b/include/mailutils/sha1.h index 9545f0b2b..f717acf8a 100644 --- a/mailbox/sha1.h +++ b/include/mailutils/sha1.h @@ -16,12 +16,21 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef SHA1_H -# define SHA1_H 1 +#ifndef _MAILUTILS_SHA1_H +# define _MAILUTILS_SHA1_H 1 # include <stdio.h> # include <stdint.h> +# define sha1_ctx mu_sha1_ctx +# define sha1_init_ctx mu_sha1_init_ctx +# define sha1_process_block mu_sha1_process_block +# define sha1_process_bytes mu_sha1_process_bytes +# define sha1_finish_ctx mu_sha1_finish_ctx +# define sha1_read_ctx mu_sha1_read_ctx +# define sha1_stream mu_sha1_stream +# define sha1_buffer mu_sha1_buffer + /* Structure to save state of computation between the single steps. */ struct sha1_ctx { diff --git a/libproto/pop/mbox.c b/libproto/pop/mbox.c index 5352dac1a..46eb9aacd 100644 --- a/libproto/pop/mbox.c +++ b/libproto/pop/mbox.c @@ -42,8 +42,6 @@ # include <strings.h> #endif -#include <md5.h> - #include <mu_umaxtostr.h> #include <mailutils/attribute.h> #include <mailutils/auth.h> @@ -58,6 +56,7 @@ #include <mailutils/stream.h> #include <mailutils/url.h> #include <mailutils/tls.h> +#include <mailutils/md5.h> #include <folder0.h> #include <mailbox0.h> @@ -2176,7 +2175,7 @@ pop_get_timestamp (pop_data_t mpd) static int pop_get_md5 (pop_data_t mpd) { - struct md5_ctx md5context; + struct mu_md5_ctx md5context; unsigned char md5digest[16]; char digest[64]; /* Really it just has to be 32 + 1(null). */ char *tmp; @@ -2187,10 +2186,10 @@ pop_get_md5 (pop_data_t mpd) if (timestamp == NULL) return EINVAL; - md5_init_ctx (&md5context); - md5_process_bytes (timestamp, strlen (timestamp), &md5context); - md5_process_bytes (mpd->passwd, strlen (mpd->passwd), &md5context); - md5_finish_ctx (&md5context, md5digest); + mu_md5_init_ctx (&md5context); + mu_md5_process_bytes (timestamp, strlen (timestamp), &md5context); + mu_md5_process_bytes (mpd->passwd, strlen (mpd->passwd), &md5context); + mu_md5_finish_ctx (&md5context, md5digest); for (tmp = digest, n = 0; n < 16; n++, tmp += 2) sprintf (tmp, "%02x", md5digest[n]); diff --git a/libproto/pop/pop3_apop.c b/libproto/pop/pop3_apop.c index 8c5ceeb26..1978dc613 100644 --- a/libproto/pop/pop3_apop.c +++ b/libproto/pop/pop3_apop.c @@ -21,12 +21,12 @@ # include <config.h> #endif -#include <md5.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <mailutils/sys/pop3.h> +#include <mailutils/md5.h> /* * APOP name digest @@ -54,16 +54,16 @@ mu_pop3_apop (mu_pop3_t pop3, const char *user, const char *secret) /* Generate the md5 from the secret and timestamp. */ case MU_POP3_NO_STATE: { - struct md5_ctx md5context; + struct mu_md5_ctx md5context; unsigned char md5digest[16]; char digest[64]; /* Really it just has to be 32 + 1(null). */ char *tmp; size_t n; - md5_init_ctx (&md5context); - md5_process_bytes (pop3->timestamp, strlen (pop3->timestamp), &md5context); - md5_process_bytes (secret, strlen (secret), &md5context); - md5_finish_ctx (&md5context, md5digest); + mu_md5_init_ctx (&md5context); + mu_md5_process_bytes (pop3->timestamp, strlen (pop3->timestamp), &md5context); + mu_md5_process_bytes (secret, strlen (secret), &md5context); + mu_md5_finish_ctx (&md5context, md5digest); for (tmp = digest, n = 0; n < 16; n++, tmp += 2) { sprintf (tmp, "%02x", md5digest[n]); diff --git a/libproto/pop/pop3_stls.c b/libproto/pop/pop3_stls.c index 547c6c0d4..5e619759a 100644 --- a/libproto/pop/pop3_stls.c +++ b/libproto/pop/pop3_stls.c @@ -20,13 +20,13 @@ # include <config.h> #endif -#include <md5.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <mailutils/sys/pop3.h> #include <mailutils/tls.h> +#include <mailutils/md5.h> /* * STLS diff --git a/mailbox/Makefile.am b/mailbox/Makefile.am index 1e70cd398..84c5319fd 100644 --- a/mailbox/Makefile.am +++ b/mailbox/Makefile.am @@ -140,8 +140,6 @@ EXTRA_DIST += regcomp.c regex.h regex_internal.c regex_internal.h regexec.c libmailutils_la_SOURCES += strtok_r.h -libmailutils_la_SOURCES += md5.h - BUILT_SOURCES += $(GLOB_H) EXTRA_DIST += glob_.h glob-libc.h @@ -154,7 +152,6 @@ MOSTLYCLEANFILES += glob.h glob.h-t EXTRA_DIST += inttostr.c inttostr.h -EXTRA_DIST += sha1.h diff --git a/mailbox/md5.c b/mailbox/md5.c index 043a741d5..41016b549 100644 --- a/mailbox/md5.c +++ b/mailbox/md5.c @@ -24,7 +24,7 @@ # include <config.h> #endif -#include "md5.h" +#include "mailutils/md5.h" #include <stddef.h> #include <stdlib.h> @@ -40,6 +40,8 @@ # if __BYTE_ORDER == __BIG_ENDIAN # define WORDS_BIGENDIAN 1 # endif +#endif + /* We need to keep the namespace clean so define the MD5 function protected using leading __ . */ # define md5_init_ctx __md5_init_ctx @@ -49,7 +51,6 @@ # define md5_read_ctx __md5_read_ctx # define md5_stream __md5_stream # define md5_buffer __md5_buffer -#endif #ifdef WORDS_BIGENDIAN # define SWAP(n) \ diff --git a/mailbox/message.c b/mailbox/message.c index eb23c5bdd..50a1af0a6 100644 --- a/mailbox/message.c +++ b/mailbox/message.c @@ -32,8 +32,6 @@ #include <ctype.h> #include <pwd.h> -#include "md5.h" - #include <message0.h> #include <mailutils/address.h> @@ -51,6 +49,7 @@ #include <mailutils/stream.h> #include <mailutils/mu_auth.h> #include <mailutils/nls.h> +#include <mailutils/md5.h> #include <mu_umaxtostr.h> #define MESSAGE_MODIFIED 0x10000; @@ -617,7 +616,7 @@ mu_message_get_uidl (mu_message_t msg, char *buffer, size_t buflen, size_t *pwri else { size_t uid = 0; - struct md5_ctx md5context; + struct mu_md5_ctx md5context; mu_stream_t stream = NULL; char buf[1024]; mu_off_t offset = 0; @@ -626,14 +625,14 @@ mu_message_get_uidl (mu_message_t msg, char *buffer, size_t buflen, size_t *pwri n = 0; mu_message_get_uid (msg, &uid); mu_message_get_stream (msg, &stream); - md5_init_ctx (&md5context); + mu_md5_init_ctx (&md5context); while (mu_stream_read (stream, buf, sizeof (buf), offset, &n) == 0 && n > 0) { - md5_process_bytes (buf, n, &md5context); + mu_md5_process_bytes (buf, n, &md5context); offset += n; } - md5_finish_ctx (&md5context, md5digest); + mu_md5_finish_ctx (&md5context, md5digest); tmp = buf; for (n = 0; n < 16; n++, tmp += 2) sprintf (tmp, "%02x", md5digest[n]); diff --git a/mailbox/mu_auth.c b/mailbox/mu_auth.c index 8ab1a7599..8b3f2c051 100644 --- a/mailbox/mu_auth.c +++ b/mailbox/mu_auth.c @@ -307,21 +307,31 @@ _locate (const char *name) static void _add_module_list (const char *modlist, int (*fun)(const char *name)) { - char *sp, *name; + int argc; + char **argv; + char *name; + int rc, i; - for (name = strtok_r ((char *)modlist, ":", &sp); name; - name = strtok_r (NULL, ":", &sp)) + rc = mu_argcv_get (modlist, ":", NULL, &argc, &argv); + if (rc) { - if (fun (name)) + mu_error (_("cannot split line `%s': %s"), modlist, mu_strerror (rc)); + exit (1); + } + + for (i = 0; i < argc; i++) + { + if (fun (argv[i])) { if (errno == ENOENT) - mu_error ("no such module: %s", name); + mu_error (_("no such module: %s"), argv[i]); else - mu_error ("failed to add module %s: %s", - name, strerror (errno)); + mu_error (_("failed to add module %s: %s"), + argv[i], strerror (errno)); exit (1); } } + mu_argcv_free (argc, argv); } diff --git a/mailbox/mutil.c b/mailbox/mutil.c index ec40028fe..bfa1bc1d2 100644 --- a/mailbox/mutil.c +++ b/mailbox/mutil.c @@ -1438,12 +1438,20 @@ mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) { int rc; int i; - char *copy = strdup (map); - char *sp, *tok; + int argc; + char **argv; mu_assoc_t assoc_tab = NULL; - for (tok = strtok_r (copy, ",", &sp); tok; tok = strtok_r (NULL, ",", &sp)) + rc = mu_argcv_get (map, ":", NULL, &argc, &argv); + if (rc) + { + mu_error (_("cannot split line `%s': %s"), map, mu_strerror (rc)); + return rc; + } + + for (i = 0; i < argc; i++) { + char *tok = argv[i]; char *p = strchr (tok, '='); char *pptr; @@ -1475,7 +1483,7 @@ mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) } } - free (copy); + mu_argcv_free (argc, argv); if (rc && perr) *perr = i; return rc; diff --git a/mailbox/rfc2047.c b/mailbox/rfc2047.c index ff37494ed..094a0a803 100644 --- a/mailbox/rfc2047.c +++ b/mailbox/rfc2047.c @@ -41,16 +41,37 @@ realloc_buffer (char **bufp, size_t *bufsizep, size_t incr) return 0; } +static char * +getword (const char **pstr, int delim) +{ + size_t len; + char *ret; + const char *start = *pstr; + const char *end = strchr (start, delim); + if (!end) + return NULL; + len = end - start; + ret = malloc (len + 1); + if (!ret) + return NULL; + memcpy (ret, start, len); + ret[len] = 0; + *pstr = end + 1; + return ret; +} + int mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr) { int status = 0; - char *tmpcopy, *fromstr; - char *start_position = NULL; + const char *fromstr; char *buffer; size_t bufsize; size_t bufpos; size_t run_count = 0; + char *fromcode = NULL; + char *encoding_type = NULL; + char *encoded_text = NULL; #define BUFINC 128 #define CHKBUF(count) do { \ @@ -61,8 +82,10 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr) s = BUFINC; \ if (realloc_buffer (&buffer, &bufsize, s)) \ { \ - free (tmpcopy); \ free (buffer); \ + free (fromcode); \ + free (encoding_type); \ + free (encoded_text); \ return ENOMEM; \ } \ } \ @@ -73,12 +96,7 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr) if (!ptostr) return MU_ERR_OUT_PTR_NULL; - /* Prepare a temporary copy of the input string (strtok_r is - going to modify it. */ - tmpcopy = strdup (input); - if (!tmpcopy) - return ENOMEM; - fromstr = tmpcopy; + fromstr = input; /* Allocate the buffer. It is assumed that encoded string is always longer than it's decoded variant, so it's safe to use its length @@ -86,30 +104,22 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr) bufsize = strlen (fromstr) + 1; buffer = malloc (bufsize); if (buffer == NULL) - { - free (tmpcopy); - return ENOMEM; - } + return ENOMEM; bufpos = 0; while (*fromstr) { if (strncmp (fromstr, "=?", 2) == 0) { - char *fromcode = NULL; - char *encoding_type = NULL; - char *encoded_text = NULL; mu_stream_t filter = NULL; mu_stream_t in_stream = NULL; const char *filter_type = NULL; size_t nbytes = 0, size; - char *sp = NULL; + const char *sp = fromstr + 2; - start_position = fromstr; - - fromcode = strtok_r (start_position + 2, "?", &sp); - encoding_type = strtok_r (NULL, "?", &sp); - encoded_text = strtok_r (NULL, "?", &sp); + fromcode = getword (&sp, '?'); + encoding_type = getword (&sp, '?'); + encoded_text = getword (&sp, '?'); if (sp == NULL || sp[0] != '=') { status = MU_ERR_BAD_2047_INPUT; @@ -202,7 +212,10 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr) CHKBUF(1); buffer[bufpos++] = 0; - free (tmpcopy); + free (fromcode); + free (encoding_type); + free (encoded_text); + *ptostr = realloc (buffer, bufpos); return status; } diff --git a/mailbox/sha1.c b/mailbox/sha1.c index dadf97361..e4cf16fa5 100644 --- a/mailbox/sha1.c +++ b/mailbox/sha1.c @@ -27,7 +27,7 @@ # include <config.h> #endif -#include "sha1.h" +#include <mailutils/sha1.h> #include <stddef.h> #include <string.h> diff --git a/pop3d/apop.c b/pop3d/apop.c index c73445d04..b610c1314 100644 --- a/pop3d/apop.c +++ b/pop3d/apop.c @@ -148,7 +148,7 @@ pop3d_apop (const char *arg) { char *tmp, *user_digest, *user, *password; char buf[POP_MAXCMDLEN]; - struct md5_ctx md5context; + struct mu_md5_ctx md5context; unsigned char md5digest[16]; if (state != AUTHORIZATION) @@ -176,11 +176,11 @@ pop3d_apop (const char *arg) return ERR_BAD_LOGIN; } - md5_init_ctx (&md5context); - md5_process_bytes (md5shared, strlen (md5shared), &md5context); - md5_process_bytes (password, strlen (password), &md5context); + mu_md5_init_ctx (&md5context); + mu_md5_process_bytes (md5shared, strlen (md5shared), &md5context); + mu_md5_process_bytes (password, strlen (password), &md5context); free (password); - md5_finish_ctx (&md5context, md5digest); + mu_md5_finish_ctx (&md5context, md5digest); { int i; diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h index 9674fe4ad..fe60abf23 100644 --- a/pop3d/pop3d.h +++ b/pop3d/pop3d.h @@ -134,7 +134,6 @@ extern int expire_on_exit; #include <grp.h> #include <syslog.h> #include <ctype.h> -#include <md5.h> #ifdef HAVE_STRINGS_H # include <strings.h> #endif @@ -155,6 +154,7 @@ extern int expire_on_exit; #include <mailutils/registrar.h> #include <mailutils/tls.h> #include <mailutils/url.h> +#include <mailutils/md5.h> /* For Berkley DB2 APOP password file */ #ifdef HAVE_DB_H diff --git a/sql/mysql.c b/sql/mysql.c index b635f53a8..ad0abd189 100644 --- a/sql/mysql.c +++ b/sql/mysql.c @@ -25,7 +25,7 @@ #include <mysql/mysql.h> #include <mysql/errmsg.h> -#include <sha1.h> +#include <mailutils/sha1.h> struct mu_mysql_data { @@ -293,19 +293,19 @@ mu_octet_to_hex (char *to, const unsigned char *str, unsigned len) static int mu_check_mysql_4x_password (const char *scrambled, const char *message) { - struct sha1_ctx sha1_context; + struct mu_sha1_ctx sha1_context; unsigned char hash_stage2[SHA1_HASH_SIZE]; char to[2*SHA1_HASH_SIZE + 2]; /* stage 1: hash password */ - sha1_init_ctx (&sha1_context); - sha1_process_bytes (message, strlen (message), &sha1_context); - sha1_finish_ctx (&sha1_context, to); + mu_sha1_init_ctx (&sha1_context); + mu_sha1_process_bytes (message, strlen (message), &sha1_context); + mu_sha1_finish_ctx (&sha1_context, to); /* stage 2: hash stage1 output */ - sha1_init_ctx (&sha1_context); - sha1_process_bytes (to, SHA1_HASH_SIZE, &sha1_context); - sha1_finish_ctx (&sha1_context, hash_stage2); + mu_sha1_init_ctx (&sha1_context); + mu_sha1_process_bytes (to, SHA1_HASH_SIZE, &sha1_context); + mu_sha1_finish_ctx (&sha1_context, hash_stage2); /* convert hash_stage2 to hex string */ to[0] = '*'; |