isync

mailbox synchronization program
git clone https://git.code.sf.net/p/isync/isync
Log | Files | Refs | README | LICENSE

commit 0f7823a4bfbee5161af6e4c53ec025ee9b10f9e3
parent 5eaa4e5512a2d1011dc22333acab28cd7dbe5572
Author: Michael Elkins <me@mutt.org>
Date:   Wed, 18 Jul 2001 18:49:55 +0000

fixed to not expand filenames until they are used inside of maildir_open(),
so that aliases are not required for simple filenames.
[re: http://bugs.debian.org/102255]

Diffstat:
Mconfig.c | 24++++++++++++++++--------
Misync.h | 1+
Mmaildir.c | 21+++++++++++++--------
3 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/config.c b/config.c @@ -18,6 +18,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#define _GNU_SOURCE 1 + #include <unistd.h> #include <limits.h> #include <errno.h> @@ -52,13 +54,12 @@ config_defaults (config_t * conf) #endif } -/* `s' is destroyed by this call */ -static char * -expand_strdup (char *s) +char * +expand_strdup (const char *s) { char path[_POSIX_PATH_MAX]; struct passwd *pw; - char *p; + const char *p; if (*s == '~') { @@ -71,10 +72,15 @@ expand_strdup (char *s) } else { + char *user; + p = strchr (s, '/'); if (p) - *p++ = 0; - pw = getpwnam (s); + user = strndup (s, (int)(p - s)); + else + user = strdup (s); + pw = getpwnam (user); + free (user); } if (!pw) return 0; @@ -83,7 +89,8 @@ expand_strdup (char *s) } else if (*s != '/') { - snprintf (path, sizeof (path), "%s/%s", global.maildir, s); + snprintf (path, sizeof (path), "%s/%s", + global.maildir ? global.maildir : "", s); s = path; } return strdup (s); @@ -131,7 +138,8 @@ load_config (const char *where) cur = &(*cur)->next; *cur = calloc (1, sizeof (config_t)); config_defaults (*cur); - (*cur)->path = expand_strdup (val); + /* not expanded at this point */ + (*cur)->path = strdup (val); } else if (!strncasecmp ("maildir", cmd, 7)) { diff --git a/isync.h b/isync.h @@ -167,6 +167,7 @@ int sync_mailbox (mailbox_t *, imap_t *, int, unsigned int); void config_defaults (config_t *); void load_config (const char *); +char * expand_strdup (const char *s); config_t *find_box (const char *); void imap_close (imap_t *); diff --git a/maildir.c b/maildir.c @@ -136,25 +136,30 @@ maildir_open (const char *path, int fast) char *s; int count = 0; + m = calloc (1, sizeof (mailbox_t)); + /* filename expansion happens here, not in the config parser */ + m->path = expand_strdup (path); + /* check to make sure this looks like a valid maildir box */ - snprintf (buf, sizeof (buf), "%s/new", path); + snprintf (buf, sizeof (buf), "%s/new", m->path); if (access (buf, F_OK)) { + free (m->path); + free (m); perror ("access"); return 0; } - snprintf (buf, sizeof (buf), "%s/cur", path); + snprintf (buf, sizeof (buf), "%s/cur", m->path); if (access (buf, F_OK)) { + free (m->path); + free (m); perror ("access"); return 0; } - m = calloc (1, sizeof (mailbox_t)); - m->path = strdup (path); - /* check for the uidvalidity value */ - m->uidvalidity = read_uid (path, "isyncuidvalidity"); + m->uidvalidity = read_uid (m->path, "isyncuidvalidity"); if (m->uidvalidity == (unsigned int) -1) { free (m->path); @@ -163,7 +168,7 @@ maildir_open (const char *path, int fast) } /* load the current maxuid */ - if ((m->maxuid = read_uid (path, "isyncmaxuid")) == (unsigned int) -1) + if ((m->maxuid = read_uid (m->path, "isyncmaxuid")) == (unsigned int) -1) { free (m->path); free (m); @@ -177,7 +182,7 @@ maildir_open (const char *path, int fast) for (; count < 2; count++) { /* read the msgs from the new subdir */ - snprintf (buf, sizeof (buf), "%s/%s", path, + snprintf (buf, sizeof (buf), "%s/%s", m->path, (count == 0) ? "new" : "cur"); d = opendir (buf); if (!d)