From MAILER-DAEMON Wed Dec 03 06:34:00 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Xw8Bz-0008Ph-VM
	for mharc-commit-mailutils@gnu.org; Wed, 03 Dec 2014 06:33:59 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:45906)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xw8Bw-0008PF-94
	for commit-mailutils@gnu.org; Wed, 03 Dec 2014 06:33:57 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xw8Bv-0000ai-1H
	for commit-mailutils@gnu.org; Wed, 03 Dec 2014 06:33:56 -0500
Received: from vcs.savannah.gnu.org ([140.186.70.72]:59945)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xw8Bu-0000Zl-Uz
	for commit-mailutils@gnu.org; Wed, 03 Dec 2014 06:33:54 -0500
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xw8Bu-0003qT-2u
	for commit-mailutils@gnu.org; Wed, 03 Dec 2014 11:33:54 +0000
Date: Wed, 03 Dec 2014 11:33:54 +0000
Message-Id: <E1Xw8Bu-0003qT-2u@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-690-g6074d4d
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 25f14bddd6a2df8d0b85a40d6a179170f0f57311
X-Git-Newrev: 6074d4d856c861d0a5df9b39d7421bc186ce2056
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 03 Dec 2014 11:33:58 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=6074d4d856c861d0a5df9b39d7421bc186ce2056

The branch, master has been updated
       via  6074d4d856c861d0a5df9b39d7421bc186ce2056 (commit)
      from  25f14bddd6a2df8d0b85a40d6a179170f0f57311 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6074d4d856c861d0a5df9b39d7421bc186ce2056
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Dec 3 13:25:34 2014 +0200

    Fix eventual memory overrun
    
    * mail/mail.c (mail_mainloop): Check command length before
    trying to access its last byte.

-----------------------------------------------------------------------

Summary of changes:
 mail/mail.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/mail/mail.c b/mail/mail.c
index f072e34..afdadd4 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -558,7 +558,7 @@ mail_mainloop (char *(*input) (void *, int),
   while ((command = (*input) (closure, 0)) != NULL)
     {
       int len = strlen (command);
-      while (command[len-1] == '\\')
+      while (len > 0 && command[len-1] == '\\')
 	{
 	  char *buf;
 	  char *command2 = (*input) (closure, 1);


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Dec 05 17:33:25 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Xx1RF-00052R-T9
	for mharc-commit-mailutils@gnu.org; Fri, 05 Dec 2014 17:33:25 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:35715)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xx1R8-00052I-09
	for commit-mailutils@gnu.org; Fri, 05 Dec 2014 17:33:24 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xx1R5-00073a-9t
	for commit-mailutils@gnu.org; Fri, 05 Dec 2014 17:33:17 -0500
Received: from vcs.savannah.gnu.org ([140.186.70.72]:35054)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xx1R5-00073W-56
	for commit-mailutils@gnu.org; Fri, 05 Dec 2014 17:33:15 -0500
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xx1R4-0003Wk-B3
	for commit-mailutils@gnu.org; Fri, 05 Dec 2014 22:33:14 +0000
Date: Fri, 05 Dec 2014 22:33:14 +0000
Message-Id: <E1Xx1R4-0003Wk-B3@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-691-g89d93a7
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 6074d4d856c861d0a5df9b39d7421bc186ce2056
X-Git-Newrev: 89d93a75c4abec10b9cfe0041eaf654d00f0a0ee
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 05 Dec 2014 22:33:24 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=89d93a75c4abec10b9cfe0041eaf654d00f0a0ee

The branch, master has been updated
       via  89d93a75c4abec10b9cfe0041eaf654d00f0a0ee (commit)
      from  6074d4d856c861d0a5df9b39d7421bc186ce2056 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 89d93a75c4abec10b9cfe0041eaf654d00f0a0ee
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Dec 6 00:15:41 2014 +0200

    Fix the use of erad-only maildir folders. Imap4d improvements.
    
    New imap4d statement "retain-groups" instructs it to retain the
    named supplementary user groups when switching to the user
    privileges (previously, imap4d just switched to <user>:mail).
    Read-only mailboxes are handled graciously: SELECT succeeds on
    such mailboxes, bug marks them explicitly as read-only.
    
    * imap4d/imap4d.c (user_retain_groups): New global.
    New config statement "retain-groups".
    (mu_get_user_groups): New function.
    (imap4d_session_setup0): Use mu_switch_to_privs instead of
    just setuid.
    * imap4d/list.c (imap4d_list): Fix handling of
      LIST "" "/path/to/mbox"
    * imap4d/select.c (imap4d_select0): Retry opening in read-only
    mode if failed to open for read-write.
    * libproto/maildir/mbox.c (maildir_mkfilename)
    (mk_info_filename): Change return value and signature. All uses
    changed.
    (maildir_scan0): Don't shuffle messages if mailbox is opened
    read-only.
    * libproto/maildir/folder.c: Update call to maildir_mkfilename.
    * libproto/maildir/maildir.h (maildir_mkfilename): Change
    prototype.

-----------------------------------------------------------------------

Summary of changes:
 imap4d/imap4d.c            |  115 +++++++++++++++++++++++++++++++++-
 imap4d/list.c              |   26 ++++++--
 imap4d/select.c            |    8 ++-
 libproto/maildir/folder.c  |    9 ++-
 libproto/maildir/maildir.h |    4 +-
 libproto/maildir/mbox.c    |  149 +++++++++++++++++++++++++++++--------------
 6 files changed, 249 insertions(+), 62 deletions(-)

diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index 6ce0864..156d407 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -35,6 +35,8 @@ enum tls_mode tls_mode;
 int login_disabled;             /* Disable LOGIN command */
 int create_home_dir;            /* Create home directory if it does not
 				   exist */
+mu_list_t user_retain_groups;
+
 int home_dir_mode = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
 
 int mailbox_mode[NS_MAX];
@@ -246,7 +248,32 @@ cb_mailbox_mode (void *data, mu_config_value_t *val)
     mu_error (_("invalid mode string near %s"), p);
   return 0;
 }
+
+static int
+cb2_group (const char *gname, void *data)
+{
+  mu_list_t list = data;
+  struct group *group;
+  
+  group = getgrnam (gname);
+  if (!group)
+    mu_error (_("unknown group: %s"), gname);
+  else
+    mu_list_append (list, (void*)group->gr_gid);
+  return 0;
+}
+  
+static int
+cb_group (void *data, mu_config_value_t *arg)
+{
+  mu_list_t *plist = data;
+
+  if (!*plist)
+    mu_list_create (plist);
+  return mu_cfg_string_value_cb (arg, cb2_group, *plist);
+}
 
+
 struct imap4d_srv_config
 {
   struct mu_srv_config m_cfg;
@@ -392,6 +419,9 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
   { "home-dir-mode", mu_cfg_callback, NULL, 0, cb_mode,
     N_("File mode for creating user home directories (octal)."),
     N_("mode") },
+  { "retain-groups", mu_cfg_callback, &user_retain_groups, 0, cb_group,
+    N_("Retain these supplementary groups when switching to user privileges"),
+    N_("groups: list of string") },
 #ifdef WITH_TLS
   { "tls", mu_cfg_callback, &tls_mode, 0, cb_tls,
     N_("Kind of TLS encryption to use") },
@@ -424,6 +454,48 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
 };
 
 int
+mu_get_user_groups (const char *user, mu_list_t retain, mu_list_t *pgrouplist)
+{
+  int rc;
+  struct group *gr;
+  mu_list_t list;
+	
+  if (!*pgrouplist)
+    {
+      rc = mu_list_create (pgrouplist);
+      if (rc)
+	{
+	  mu_error(_("%s: cannot create list: %s"),
+		   "mu_get_user_groups", mu_strerror (rc));
+	  return rc;
+	}
+    }
+
+  list = *pgrouplist;
+  setgrent ();
+  for (rc = 0; rc == 0 && (gr = getgrent ()); )
+    {
+      char **p;
+      for (p = gr->gr_mem; *p; p++)
+	if (strcmp (*p, user) == 0)
+	  {
+	    if (retain && mu_list_locate (retain, (void*)gr->gr_gid, NULL))
+	      continue;
+	      
+	    /* FIXME: Avoid duplicating gids */
+	    rc = mu_list_append (list, (void*)gr->gr_gid);
+	    if (rc) 
+	      mu_error(_("%s: cannot append to list: %s"),
+		       "mu_get_user_groups",
+		       mu_strerror (rc));
+	    break;
+	  }
+    }
+  endgrent ();
+  return rc;
+}
+
+int
 imap4d_session_setup0 ()
 {
   if (auth_deny_user_list &&
@@ -502,7 +574,48 @@ imap4d_session_setup0 ()
     }
   
   if (auth_data->change_uid)
-    setuid (auth_data->uid);
+    {
+      struct group *gr;
+      mu_list_t groups = NULL;
+      int rc;
+      uid_t uid;
+
+      uid = getuid ();
+      if (uid != auth_data->uid)
+	{
+	  rc = mu_list_create (&groups);
+	  if (rc)
+	    {
+	      mu_error(_("cannot create list: %s"), mu_strerror (rc));
+	      free (imap4d_homedir);
+	      free (real_homedir);
+	      return 1;
+	    }
+	  mu_list_append (groups, (void*)auth_data->gid);
+
+	  rc = mu_get_user_groups (auth_data->name, user_retain_groups,
+				   &groups);
+	  if (rc)
+	    {
+	      /* FIXME: When mu_get_user_groups goes to the library, add a
+		 diag message here */
+	      free (imap4d_homedir);
+	      free (real_homedir);
+	      return 1;
+	    }
+	  gr = getgrnam ("mail");
+	  rc = mu_switch_to_privs (auth_data->uid, gr->gr_gid, groups);
+	  mu_list_destroy (&groups);
+	  if (rc)
+	    {
+	      mu_error (_("can't switch to user %s privileges: %s"),
+			auth_data->name, mu_strerror (rc));
+	      free (imap4d_homedir);
+	      free (real_homedir);
+	      return 1;
+	    }
+	}
+    }
 
   util_chdir (imap4d_homedir);
   namespace_init_session (imap4d_homedir);
diff --git a/imap4d/list.c b/imap4d/list.c
index bbb7730..50c672d 100644
--- a/imap4d/list.c
+++ b/imap4d/list.c
@@ -157,9 +157,10 @@ imap4d_list (struct imap4d_session *session,
 			      "LIST (\\NoSelect) \"%c\" \"\"",
 			      MU_HIERARCHY_DELIMITER);
     }
+  
   /* There is only one mailbox in the "INBOX" hierarchy ... INBOX.  */
   else if (mu_c_strcasecmp (ref, "INBOX") == 0
-	   || (ref[0] == 0 && mu_c_strcasecmp (wcard, "INBOX") == 0))
+      || (ref[0] == 0 && mu_c_strcasecmp (wcard, "INBOX") == 0))
     {
       io_untagged_response (RESP_NONE, "LIST (\\NoInferiors) NIL INBOX");
     }
@@ -168,8 +169,8 @@ imap4d_list (struct imap4d_session *session,
       int status;
       mu_folder_t folder;
       char *cwd;
-      char *p, *q;
       struct refinfo refinfo;
+      size_t seglen;
       
       switch (*wcard)
 	{
@@ -209,12 +210,10 @@ imap4d_list (struct imap4d_session *session,
       /* Move any directory not containing a wildcard into the reference
 	 So (ref = ~guest, wcard = Mail/folder1/%.vf) -->
 	 (ref = ~guest/Mail/folder1, wcard = %.vf).  */
-      for (p = wcard; (q = strpbrk (p, "/%*")) && *q == '/'; p = q + 1)
-	;
+      seglen = strcspn (wcard, "%*");
 
-      if (p > wcard)
+      if (seglen)
 	{
-	  size_t seglen = p - wcard;
 	  size_t reflen = strlen (ref);
 	  int addslash = (reflen > 0 && ref[reflen-1] != '/'); 
 	  size_t len = seglen + reflen + addslash + 1;
@@ -235,6 +234,21 @@ imap4d_list (struct imap4d_session *session,
 	  return io_completion_response (command, RESP_NO,
 			              "The requested item could not be found.");
 	}
+
+      /* FIXME */
+      if (wcard[0] == 0)
+	{
+	  char *p = strrchr (ref, '/');
+	  if (p && p[1])
+	    {
+	      *p++ = 0;
+	      wcard = p;
+
+	      p = strrchr (cwd, '/');
+	      *p = 0;
+	    }
+	}
+
       status = mu_folder_create (&folder, cwd);
       if (status)
 	{
diff --git a/imap4d/select.c b/imap4d/select.c
index 1283d4f..0d68dd2 100644
--- a/imap4d/select.c
+++ b/imap4d/select.c
@@ -64,13 +64,17 @@ imap4d_select0 (struct imap4d_command *command, const char *mboxname,
   if (!mailbox_name)
     return io_completion_response (command, RESP_NO, "Couldn't open mailbox");
 
-  if (flags & MU_STREAM_RDWR)
+  if (flags & MU_STREAM_WRITE)
     {
       status = manlock_open_mailbox (&mbox, mailbox_name, 1, flags);
+      if (status)
+	flags &= ~MU_STREAM_WRITE;
     }
-  else
+
+  if (!(flags & MU_STREAM_WRITE))
     {
       status = mu_mailbox_create_default (&mbox, mailbox_name);
+
       if (status)
 	mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_create_default",
 			 mailbox_name,
diff --git a/libproto/maildir/folder.c b/libproto/maildir/folder.c
index 4fd96d8..6471a02 100644
--- a/libproto/maildir/folder.c
+++ b/libproto/maildir/folder.c
@@ -40,8 +40,13 @@ static int
 dir_exists (const char *name, const char *suf)
 {
   struct stat st;
-  char *s = maildir_mkfilename (name, suf, NULL);
-      
+  int rc;
+  char *s;
+
+  rc = maildir_mkfilename (name, suf, NULL, &s);
+  if (rc)
+    return 0;/* FIXME: error message */
+  
   if (stat (s, &st) < 0)
     return 0;
 
diff --git a/libproto/maildir/maildir.h b/libproto/maildir/maildir.h
index db22049..d338d44 100644
--- a/libproto/maildir/maildir.h
+++ b/libproto/maildir/maildir.h
@@ -21,5 +21,5 @@
 #define CURSUF "cur"
 #define NEWSUF "new"
 
-extern char *maildir_mkfilename (const char *dir, const char *suffix,
-				 const char *name);
+int maildir_mkfilename (const char *dir, const char *suffix,
+			const char *name, char **retname);
diff --git a/libproto/maildir/mbox.c b/libproto/maildir/mbox.c
index 9773143..58ab3a4 100644
--- a/libproto/maildir/mbox.c
+++ b/libproto/maildir/mbox.c
@@ -68,6 +68,7 @@
 #include <mailutils/sys/mailbox.h>
 #include <mailutils/sys/registrar.h>
 #include <mailutils/sys/amd.h>
+#include <mailutils/io.h>
 #include <maildir.h>
 
 #ifndef PATH_MAX 
@@ -237,8 +238,9 @@ read_random (void *buf, size_t size)
   return rc != size;
 }
 
-char *
-maildir_mkfilename (const char *directory, const char *suffix, const char *name)
+int
+maildir_mkfilename (const char *directory, const char *suffix, const char *name,
+		    char **ret_name)
 {
   size_t size = strlen (directory) + 1 + strlen (suffix) + 1;
   char *tmp;
@@ -247,22 +249,25 @@ maildir_mkfilename (const char *directory, const char *suffix, const char *name)
     size += 1 + strlen (name);
   
   tmp = malloc (size);
+  if (!tmp)
+    return errno;
   sprintf (tmp, "%s/%s", directory, suffix);
   if (name)
     {
       strcat (tmp, "/");
       strcat (tmp, name);
     }
-  return tmp;
+  *ret_name = tmp;
+  return 0;
 }
 
-static char *
-mk_info_filename (char *directory, char *suffix, char *name, int flags)
+static int
+mk_info_filename (char *directory, char *suffix, char *name, int flags,
+		  char **ret_name)
 {
   char fbuf[info_map_size + 1];
   char *tmp;
   int namelen;
-  size_t size;
 
   tmp = strchr (name, ':');
   if (!tmp)
@@ -270,16 +275,10 @@ mk_info_filename (char *directory, char *suffix, char *name, int flags)
   else
     namelen = tmp - name;
 
-  size = strlen (directory)
-          + 1 + strlen (suffix)
-          + 1 + namelen + 1;
-
   flags_to_info (flags, fbuf);
-  size += 3 + strlen (fbuf);
 
-  tmp = malloc (size);
-  sprintf (tmp, "%s/%s/%*.*s:2,%s", directory, suffix, namelen, namelen, name, fbuf);
-  return tmp;
+  return mu_asprintf (ret_name, "%s/%s/%*.*s:2,%s",
+		      directory, suffix, namelen, namelen, name, fbuf);
 }
 
 char *
@@ -335,8 +334,7 @@ static int
 maildir_cur_message_name (struct _amd_message *amsg, char **pname)
 {
   struct _maildir_message *msg = (struct _maildir_message *) amsg;
-  *pname = maildir_mkfilename (amsg->amd->name, msg->dir, msg->file_name);
-  return 0;
+  return maildir_mkfilename (amsg->amd->name, msg->dir, msg->file_name, pname);
 }
 
 static int
@@ -350,9 +348,11 @@ maildir_new_message_name (struct _amd_message *amsg, int flags, int expunge,
       *pname = NULL;
     }
   else if (strcmp (msg->dir, CURSUF) == 0)
-    *pname = mk_info_filename (amsg->amd->name, CURSUF, msg->file_name, flags);
+    return mk_info_filename (amsg->amd->name, CURSUF, msg->file_name, flags,
+			     pname);
   else
-    *pname = maildir_mkfilename (amsg->amd->name, msg->dir, msg->file_name);
+    return maildir_mkfilename (amsg->amd->name, msg->dir, msg->file_name,
+			       pname);
   return 0;
 }
 
@@ -388,7 +388,16 @@ static void
 maildir_delete_file (char *dirname, char *filename)
 {
   struct stat st;
-  char *name = maildir_mkfilename (dirname, filename, NULL);
+  char *name;
+  int rc;
+  
+  rc = maildir_mkfilename (dirname, filename, NULL, &name);
+  if (rc)
+    {
+      mu_error ("maildir: failed to create file name: %s",
+		mu_strerror (errno));
+      return;
+    }
 
   if (stat (name, &st) == 0)
     {
@@ -429,15 +438,21 @@ maildir_create (struct _amd_data *amd, int flags)
   for (i = 0; i < 3; i++)
     {
       DIR *dir;
-      char *tmpname = maildir_mkfilename (amd->name, dirs[i], NULL);
-      int rc = maildir_opendir (&dir, tmpname,
-				PERMS |
-				mu_stream_flags_to_mode (amd->mailbox->flags,
-							 1));
+      int rc;
+      char *tmpname;
+
+      rc = maildir_mkfilename (amd->name, dirs[i], NULL, &tmpname);
       if (rc)
 	return rc;
-      closedir (dir);
+      
+      rc = maildir_opendir (&dir, tmpname,
+			    PERMS |
+			    mu_stream_flags_to_mode (amd->mailbox->flags,
+						     1));
       free (tmpname);
+      if (rc)
+	return rc;
+      closedir (dir);
     }
   return 0;
 }
@@ -454,10 +469,16 @@ maildir_msg_init (struct _amd_data *amd, struct _amd_message *amm)
   char *name, *fname;
   struct stat st;
   int i;
+  int rc;
   
   name = maildir_uniq (amd, -1);
-  fname = maildir_mkfilename (amd->name, NEWSUF, name);
-
+  rc = maildir_mkfilename (amd->name, NEWSUF, name, &fname);
+  if (rc)
+    {
+      free (name);
+      return rc;
+    }
+  
   msg->dir = TMPSUF;
   
   for (i = 0; i < NTRIES; i++)
@@ -483,35 +504,41 @@ maildir_msg_finish_delivery (struct _amd_data *amd, struct _amd_message *amm,
 			     const mu_message_t orig_msg)
 {
   struct _maildir_message *msg = (struct _maildir_message *) amm;
-  char *oldname = maildir_mkfilename (amd->name, TMPSUF, msg->file_name);
-  char *newname;
+  char *oldname, *newname;
   mu_attribute_t attr;
   int flags;
+  int rc;
+  
+  rc = maildir_mkfilename (amd->name, TMPSUF, msg->file_name, &oldname);
+  if (rc)
+    return rc;
   
   if (mu_message_get_attribute (orig_msg, &attr) == 0
       && mu_attribute_is_read (attr)
       && mu_attribute_get_flags (attr, &flags) == 0)
     {
       msg->dir = CURSUF;
-      newname = mk_info_filename (amd->name, CURSUF, msg->file_name, flags);
+      rc = mk_info_filename (amd->name, CURSUF, msg->file_name, flags,
+			     &newname);
     }
   else
     {
       msg->dir = NEWSUF;
-      newname = maildir_mkfilename (amd->name, NEWSUF, msg->file_name);
+      rc = maildir_mkfilename (amd->name, NEWSUF, msg->file_name, &newname);
     }
-    
-  unlink (newname);
-  if (link (oldname, newname) == 0)
-    unlink (oldname);
-  else
+
+  if (rc == 0)
     {
-      return errno; /* FIXME? */
+      unlink (newname);
+      if (link (oldname, newname) == 0)
+	unlink (oldname);
+      else
+	rc = errno; /* FIXME? */
     }
-
+  
   free (oldname);
   free (newname);
-  return 0;
+  return rc;
 }
 
 
@@ -523,7 +550,11 @@ maildir_flush (struct _amd_data *amd)
   int rc;
   DIR *dir;
   struct dirent *entry;
-  char *tmpname = maildir_mkfilename (amd->name, TMPSUF, NULL);
+  char *tmpname;
+
+  rc = maildir_mkfilename (amd->name, TMPSUF, NULL, &tmpname);
+  if (rc)
+    return rc;
 
   rc = maildir_opendir (&dir, tmpname,
 			PERMS |
@@ -561,16 +592,24 @@ maildir_deliver_new (struct _amd_data *amd, DIR *dir)
   while ((entry = readdir (dir)))
     {
       char *oldname, *newname;
-	
+      int rc;
+      
       switch (entry->d_name[0])
 	{
 	case '.':
 	  break;
 
 	default:
-	  oldname = maildir_mkfilename (amd->name, NEWSUF, entry->d_name);
-	  newname = mk_info_filename (amd->name, CURSUF, entry->d_name, 0);
-	  rename (oldname, newname);
+	  rc = maildir_mkfilename (amd->name, NEWSUF, entry->d_name, &oldname);
+	  if (rc)
+	    return rc;
+	  rc = mk_info_filename (amd->name, CURSUF, entry->d_name, 0, &newname);
+	  if (rc)
+	    {
+	      free (oldname);
+	      return rc;
+	    }
+	  rename (oldname, newname); /* FIXME: Error code? */
 	  free (oldname);
 	  free (newname);
 	}
@@ -654,19 +693,27 @@ maildir_scan0 (mu_mailbox_t mailbox, size_t msgno MU_ARG_UNUSED,
   maildir_flush (amd);
 
   /* 2nd phase: Scan and deliver messages from new */
-  name = maildir_mkfilename (amd->name, NEWSUF, NULL);
-
+  status = maildir_mkfilename (amd->name, NEWSUF, NULL, &name);
+  if (status)
+    return status;
+  
   status = maildir_opendir (&dir, name,
 			    PERMS |
 			    mu_stream_flags_to_mode (mailbox->flags, 1));
   if (status == 0)
     {
-      maildir_deliver_new (amd, dir);
+      if (mailbox->flags & MU_STREAM_WRITE)
+	maildir_deliver_new (amd, dir);
+      else
+	status = maildir_scan_dir (amd, dir, NEWSUF);
       closedir (dir);
     }
   free (name);
 
-  name = maildir_mkfilename (amd->name, CURSUF, NULL);
+  status = maildir_mkfilename (amd->name, CURSUF, NULL, &name);
+  if (status)
+    return status;
+  
   /* 3rd phase: Scan cur/ */
   status = maildir_opendir (&dir, name,
 			    PERMS |
@@ -746,7 +793,11 @@ maildir_remove (struct _amd_data *amd)
 
   for (i = 0; rc == 0 && i < 3; i++)
     {
-      char *name = maildir_mkfilename (amd->name, suf[i], NULL);
+      char *name;
+
+      rc = maildir_mkfilename (amd->name, suf[i], NULL, &name);
+      if (rc)
+	return rc;
       rc = amd_remove_dir (name);
       if (rc)
 	mu_diag_output (MU_DIAG_WARNING,


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Dec 06 02:51:22 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1XxA9C-0003p4-E5
	for mharc-commit-mailutils@gnu.org; Sat, 06 Dec 2014 02:51:22 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39957)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XxA99-0003ob-KZ
	for commit-mailutils@gnu.org; Sat, 06 Dec 2014 02:51:20 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XxA98-0004Hx-8s
	for commit-mailutils@gnu.org; Sat, 06 Dec 2014 02:51:19 -0500
Received: from vcs.savannah.gnu.org ([140.186.70.72]:39622)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XxA98-0004Ht-4n
	for commit-mailutils@gnu.org; Sat, 06 Dec 2014 02:51:18 -0500
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XxA92-0003eI-LR
	for commit-mailutils@gnu.org; Sat, 06 Dec 2014 07:51:16 +0000
Date: Sat, 06 Dec 2014 07:51:13 +0000
Message-Id: <E1XxA92-0003eI-LR@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-692-g751aad9
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 89d93a75c4abec10b9cfe0041eaf654d00f0a0ee
X-Git-Newrev: 751aad904e7d642240de2106de95429f8c248ea7
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 06 Dec 2014 07:51:21 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=751aad904e7d642240de2106de95429f8c248ea7

The branch, master has been updated
       via  751aad904e7d642240de2106de95429f8c248ea7 (commit)
      from  89d93a75c4abec10b9cfe0041eaf654d00f0a0ee (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 751aad904e7d642240de2106de95429f8c248ea7
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Dec 6 09:46:49 2014 +0200

    Improve diagnostics in maildir
    
    * libmailutils/mailbox/fsfolder.c: Fix debugging categories
    * libproto/maildir/mbox.c (maildir_opendir)
    (maildir_msg_finish_delivery)
    (maildir_scan0): Log errors.
    (maildir_flush,maildir_deliver_new): Return EACCES if the mailbox is read-only.

-----------------------------------------------------------------------

Summary of changes:
 libmailutils/mailbox/fsfolder.c |    6 +-
 libproto/maildir/mbox.c         |   81 +++++++++++++++++++++++++++++---------
 2 files changed, 65 insertions(+), 22 deletions(-)

diff --git a/libmailutils/mailbox/fsfolder.c b/libmailutils/mailbox/fsfolder.c
index 7620bf0..ba92a40 100644
--- a/libmailutils/mailbox/fsfolder.c
+++ b/libmailutils/mailbox/fsfolder.c
@@ -222,7 +222,7 @@ list_helper (struct search_data *data, mu_record_t record,
   dirp = opendir (dirname);
   if (dirp == NULL)
     {
-      mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
+      mu_debug (MU_DEBCAT_FOLDER, MU_DEBUG_ERROR,
 		("list_helper cannot open directory %s: %s",
 		 dirname, mu_strerror (errno)));
       data->errcnt++;
@@ -276,7 +276,7 @@ list_helper (struct search_data *data, mu_record_t record,
 		  resp = malloc (sizeof (*resp));
 		  if (resp == NULL)
 		    {
-		      mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
+		      mu_debug (MU_DEBCAT_FOLDER, MU_DEBUG_ERROR,
 				("list_helper: %s", mu_strerror (ENOMEM)));
 		      data->errcnt++;
 		      free (fname);
@@ -343,7 +343,7 @@ list_helper (struct search_data *data, mu_record_t record,
 	}
       else
 	{
-	  mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR,
+	  mu_debug (MU_DEBCAT_FOLDER, MU_DEBUG_ERROR,
 		    ("list_helper cannot stat %s: %s",
 		     fname, mu_strerror (errno)));
 	}
diff --git a/libproto/maildir/mbox.c b/libproto/maildir/mbox.c
index 58ab3a4..a11201e 100644
--- a/libproto/maildir/mbox.c
+++ b/libproto/maildir/mbox.c
@@ -390,7 +390,7 @@ maildir_delete_file (char *dirname, char *filename)
   struct stat st;
   char *name;
   int rc;
-  
+
   rc = maildir_mkfilename (dirname, filename, NULL, &name);
   if (rc)
     {
@@ -412,21 +412,32 @@ maildir_delete_file (char *dirname, char *filename)
 static int
 maildir_opendir (DIR **dir, char *name, int permissions)
 {
+  int rc = 0;
+      
   *dir = opendir (name);
   if (!*dir)
     {
       if (errno == ENOENT)
 	{
 	  if (mkdir (name, permissions))
-	    return errno;
+	    {
+	      rc = errno;
+	      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+			("can't create directory %s: %s",
+			 name, mu_strerror (rc)));
+	      return rc;
+	    }
+	  
 	  *dir = opendir (name);
-	  if (!*dir)
-	    return errno;
+	  if (*dir)
+	    return 0;
 	}
-      else
-	return errno;
+      rc = errno;
+      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		("can't open directory %s: %s",
+		 name, mu_strerror (rc)));
     }
-  return 0;
+  return rc;
 }
 
 static int
@@ -529,11 +540,28 @@ maildir_msg_finish_delivery (struct _amd_data *amd, struct _amd_message *amm,
 
   if (rc == 0)
     {
-      unlink (newname);
-      if (link (oldname, newname) == 0)
-	unlink (oldname);
+      if (unlink (newname))
+	{
+	  rc = errno;
+	  mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		    ("can't unlink %s: %s",
+		     newname, mu_strerror (errno)));
+	}
+      else if (link (oldname, newname) == 0)
+	{
+	  if (unlink (oldname))
+	    mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		      ("can't unlink %s: %s",
+		       oldname, mu_strerror (errno)));
+	}
       else
-	rc = errno; /* FIXME? */
+	{
+	  rc = errno;
+	  mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		    ("renaming %s to %s failed: %s",
+		     oldname, newname, mu_strerror (rc)));
+	}
+
     }
   
   free (oldname);
@@ -552,6 +580,9 @@ maildir_flush (struct _amd_data *amd)
   struct dirent *entry;
   char *tmpname;
 
+  if (!(amd->mailbox->flags & MU_STREAM_WRITE))
+    return EACCES;
+
   rc = maildir_mkfilename (amd->name, TMPSUF, NULL, &tmpname);
   if (rc)
     return rc;
@@ -588,7 +619,10 @@ int
 maildir_deliver_new (struct _amd_data *amd, DIR *dir)
 {
   struct dirent *entry;
+  int err = 0;
 
+  if (!(amd->mailbox->flags & MU_STREAM_WRITE))
+    return EACCES;
   while ((entry = readdir (dir)))
     {
       char *oldname, *newname;
@@ -609,12 +643,18 @@ maildir_deliver_new (struct _amd_data *amd, DIR *dir)
 	      free (oldname);
 	      return rc;
 	    }
-	  rename (oldname, newname); /* FIXME: Error code? */
+	  if (rename (oldname, newname))
+	    {
+	      err = MU_ERR_FAILURE;
+	      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+			("renaming %s to %s failed: %s",
+			 oldname, newname, mu_strerror (errno)));
+	    }
 	  free (oldname);
 	  free (newname);
 	}
     }
-  return 0;
+  return err;
 }
 
 static int
@@ -635,8 +675,8 @@ maildir_scan_dir (struct _amd_data *amd, DIR *dir, char *dirname)
 	  break;
 
 	default:
-	      /* Message not found. Index pointd to the array cell where it
-		 would be placed */
+	  /* Message not found. Index points to the array cell where it
+	     would be placed */
 	  msg = calloc (1, sizeof (*msg));
 	  if (!msg)
 	    {
@@ -702,9 +742,7 @@ maildir_scan0 (mu_mailbox_t mailbox, size_t msgno MU_ARG_UNUSED,
 			    mu_stream_flags_to_mode (mailbox->flags, 1));
   if (status == 0)
     {
-      if (mailbox->flags & MU_STREAM_WRITE)
-	maildir_deliver_new (amd, dir);
-      else
+      if (maildir_deliver_new (amd, dir))
 	status = maildir_scan_dir (amd, dir, NEWSUF);
       closedir (dir);
     }
@@ -824,7 +862,12 @@ maildir_chattr_msg (struct _amd_message *amsg, int expunge)
   if (!new_name)
     {
       if (unlink (mp->file_name))
-	rc = errno;
+	{
+	  rc = errno;
+	  mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		    ("can't unlink %s: %s",
+		     mp->file_name, mu_strerror (rc)));
+	}
     }
   else
     {


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Dec 07 08:26:34 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Xxbr8-0003R3-G3
	for mharc-commit-mailutils@gnu.org; Sun, 07 Dec 2014 08:26:34 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:46749)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xxbr5-0003QD-2a
	for commit-mailutils@gnu.org; Sun, 07 Dec 2014 08:26:32 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xxbr3-0003MQ-Cs
	for commit-mailutils@gnu.org; Sun, 07 Dec 2014 08:26:31 -0500
Received: from vcs.savannah.gnu.org ([140.186.70.72]:55434)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xxbr3-0003MM-8W
	for commit-mailutils@gnu.org; Sun, 07 Dec 2014 08:26:29 -0500
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Xxbr1-0008Ha-Uz
	for commit-mailutils@gnu.org; Sun, 07 Dec 2014 13:26:28 +0000
Date: Sun, 07 Dec 2014 13:26:28 +0000
Message-Id: <E1Xxbr1-0008Ha-Uz@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-693-gd059030
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 751aad904e7d642240de2106de95429f8c248ea7
X-Git-Newrev: d0590302f3bde188c5548c06538df7b172f12521
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 07 Dec 2014 13:26:32 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=d0590302f3bde188c5548c06538df7b172f12521

The branch, master has been updated
       via  d0590302f3bde188c5548c06538df7b172f12521 (commit)
      from  751aad904e7d642240de2106de95429f8c248ea7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d0590302f3bde188c5548c06538df7b172f12521
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sun Dec 7 15:22:57 2014 +0200

    New function mu_fgetpwent_r.
    
    * libmailutils/base/fgetpwent.c: Rewrite from scratch.
    * ChangeLog.amend: Update.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog.amend               |    3 +
 libmailutils/base/fgetpwent.c |  236 ++++++++++++++++++++++++-----------------
 2 files changed, 142 insertions(+), 97 deletions(-)

diff --git a/ChangeLog.amend b/ChangeLog.amend
index 6b35ac9..0418451 100644
--- a/ChangeLog.amend
+++ b/ChangeLog.amend
@@ -1,5 +1,8 @@
 # Spelling corrections for GNU Mailutils ChangeLog
 
+89d93a75c4abec10b9cfe0041eaf654d00f0a0ee
+s/erad-only/read-only/
+
 1cbbd572d56b7a77362992181ef008db8a11688f
 s/consisten/consistent/
 
diff --git a/libmailutils/base/fgetpwent.c b/libmailutils/base/fgetpwent.c
index 5e43aea..6b32744 100644
--- a/libmailutils/base/fgetpwent.c
+++ b/libmailutils/base/fgetpwent.c
@@ -24,126 +24,165 @@
 #include <pwd.h>
 #include <string.h>
 #include <stdlib.h>
-
-/*
-  Written by Alain Magloire.
-  Simple replacement for fgetpwent(), it is not :
-  - thread safe;
-  - static buffer was not use since it will limit the size
-    of the entry.  But rather memory is allocated and __never__
-    release.  The memory will grow if need be.
-  - no support for shadow
-  - no support for NIS(+)
+#include <errno.h>
+
+/* Assuming FP refers to an open file in format of /etc/passwd, read the next
+   line and store a pointer to a structure containing the broken-out
+   fields of the record in the location pointed to by RESULT.  Use *BUFP
+   (of size *BUFS) to store the data, reallocating it if necessary.  If
+   *BUFP is NULL or *BUFS is 0, allocate new memory.  The caller should
+   free *BUFP when no longer needed.  Do not try to free *RESULT!
+
+   Input lines not conforming to the /etc/passwd format are silently
+   ignored.
+   
+   Return value:
+    0      - success
+    ENOMEM - not enough memory
+    ENOENT - no more entries.
 */
 
-static char *buffer;
-static size_t buflen;
-static struct passwd pw;
-
-static char *
-parse_line (char *s, char **p)
+int
+mu_fgetpwent_r (FILE *fp, char **bufp, size_t *bufs, struct passwd **result)
 {
-  if (*s)
+  char *buffer = *bufp;
+  size_t buflen = *bufs;
+  struct passwd *pwbuf;
+  size_t pos = 0;
+  int c;
+  size_t off[6];
+  int i = 0;
+
+  if (!buffer)
+    buflen = 0;
+  
+  while ((c = fgetc(fp)) != EOF)
     {
-      char *sep = strchr (s, ':');
-      if (sep)
+      if (pos == buflen)
+	{
+	  char *nb;
+	  size_t ns;
+	  
+	  if (buflen == 0)
+	    ns = 128;
+	  else
+	    {
+	      ns = ns * 2;
+	      if (ns < buflen)
+		return ENOMEM;
+	    }
+	  nb = realloc(buffer, ns);
+	  if (!nb)
+	    return ENOMEM;
+	  buffer = nb;
+	  buflen = ns;
+	}
+      if (c == '\n')
+	{
+	  buffer[pos++] = 0;
+	  if (i != sizeof(off)/sizeof(off[0]))
+	    continue;
+	  break;
+	}
+      if (c == ':')
 	{
-	  *sep++ = '\0';
-	  *p = sep;
+	  buffer[pos++] = 0;
+	  if (i < sizeof(off)/sizeof(off[0]))
+	    off[i++] = pos;
 	}
       else
-	*p = s + strlen (s);
+	buffer[pos++] = c;
     }
-  else
-    *p = s;
-  return s;
-}
 
-static struct passwd *
-getentry (char *s)
-{
-  char *p;
-  pw.pw_name = parse_line (s, &p);
-  s = p;
-  pw.pw_passwd = parse_line (s, &p);
-  s = p;
-  pw.pw_uid = strtoul (parse_line (s, &p), NULL, 10);
-  s = p;
-  pw.pw_gid = strtoul (parse_line (s, &p), NULL, 10);
-  s = p;
-  pw.pw_gecos = parse_line (s, &p);
-  s = p;
-  pw.pw_dir = parse_line (s, &p);
-  s = p;
-  pw.pw_shell = parse_line (s, &p);
-  return &pw;
+  if (pos == 0)
+    return ENOENT;
+
+  if (pos + sizeof(struct passwd) > buflen)
+    {
+      char *nb;
+      size_t ns;
+	  
+      ns = pos + sizeof(struct passwd);
+      if (ns < buflen)
+	return ENOMEM;
+    
+      nb = realloc(buffer, ns);
+      if (!nb)
+	return ENOMEM;
+      buffer = nb;
+      buflen = ns;
+    }
+  pwbuf = (struct passwd*)((char*) buffer + pos);
+  
+  pwbuf->pw_name   = buffer;
+  pwbuf->pw_passwd = buffer + off[0];
+  pwbuf->pw_uid    = strtoul(buffer + off[1], NULL, 10);
+  pwbuf->pw_gid    = strtoul(buffer + off[2], NULL, 10);
+  pwbuf->pw_gecos  = buffer + off[3];
+  pwbuf->pw_dir    = buffer + off[4];
+  pwbuf->pw_shell  = buffer + off[5];
+
+  *bufp   = buffer;
+  *bufs   = buflen;
+  *result = pwbuf;
+  return 0;
 }
 
+/* A simple replacement for fgetpwent().
+   Note:
+    - it is not thread safe (neither is the original fgetpwent)
+    - uses dynamically allocated buffer that is __never__ freed.
+    - no support for shadow nor BSD-style pwddb (neither has the original
+    fgetpwent).
+    - no support for NIS(+).
+
+   Initial implementation by Alain Magloire.
+   Rewritten from scratch by Sergey Poznyakoff.
+*/
 struct passwd *
 mu_fgetpwent (FILE *fp)
 {
-  size_t pos = 0;
-  int done = 0;
-  struct passwd *pw = NULL;
-
-  /* Allocate buffer if not yet available.  */
-  /* This buffer will be never free().  */
-  if (buffer == NULL)
+  static char *buffer;
+  static size_t bufsize;
+  static struct passwd *pwbuf;
+  int rc = mu_fgetpwent_r (fp, &buffer, &bufsize, &pwbuf);
+  if (rc)
     {
-      buflen = 1024;
-      buffer = malloc (buflen);
-      if (buffer == NULL)
-	return NULL;
+      errno = rc;
+      return NULL;
     }
-
-  do
-    {
-      if (fgets (buffer + pos, buflen, fp) != NULL)
-	{
-	  /* Need a full line.  */
-	  if (buffer[strlen (buffer) - 1] == '\n')
-	    {
-	      /* reset marker position.  */
-	      pos = 0;
-	      /* Nuke trailing newline.  */
-	      buffer[strlen (buffer) - 1] = '\0';
-
-	      /* Skip comments.  */
-	      if (buffer[0] != '#')
-		{
-		  done = 1;
-		  pw = getentry (buffer);
-		}
-	    }
-	  else
-	    {
-	      /* Line is too long reallocate the buffer.  */
-	      char *tmp;
-	      pos = strlen (buffer);
-	      buflen *= 2;
-	      tmp = realloc (buffer, buflen);
-	      if (tmp)
-		buffer = tmp;
-	      else
-		done = 1;
-	    }
-	}
-      else
-	done = 1;
-    } while (!done);
-
-  return pw;
-
+  return pwbuf;
 }
 
 #ifdef STANDALONE
+# include <assert.h>
+
 int
-main ()
+main (int argc, char **argv)
 {
-  FILE *fp = fopen ("/etc/passwd", "r");
-  if (fp)
+  FILE *fp;
+  
+  if (argc == 1)
+    {
+      char *a[3];
+      a[0] = argv[0];
+      a[1] = "/etc/passwd";
+      a[2] = NULL;
+      argv = a;
+      argc = 2;
+    }
+  while (--argc)
     {
       struct passwd *pwd;
+      char *file = *++argv;
+
+      fp = fopen (file, "r");
+      if (!fp)
+	{
+	  perror (file);
+	  continue;
+	}
+      printf ("Reading %s\n", file);
       while ((pwd = fgetpwent (fp)))
         {
           printf ("--------------------------------------\n");
@@ -155,6 +194,9 @@ main ()
           printf ("dir %s\n", pwd->pw_dir);
           printf ("shell %s\n", pwd->pw_shell);
         }
+      printf ("======================================\n");
+      printf ("End of %s\n", file);
+      close (fp);
     }
   return 0;
 }


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Dec 08 06:45:56 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1XxwlI-00021B-Fk
	for mharc-commit-mailutils@gnu.org; Mon, 08 Dec 2014 06:45:56 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:38576)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XxwlG-00020z-7d
	for commit-mailutils@gnu.org; Mon, 08 Dec 2014 06:45:55 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XxwlE-0003vc-Oe
	for commit-mailutils@gnu.org; Mon, 08 Dec 2014 06:45:54 -0500
Received: from vcs.savannah.gnu.org ([140.186.70.72]:38917)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XxwlE-0003vY-I0
	for commit-mailutils@gnu.org; Mon, 08 Dec 2014 06:45:52 -0500
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XxwlD-00010w-PD
	for commit-mailutils@gnu.org; Mon, 08 Dec 2014 11:45:51 +0000
Date: Mon, 08 Dec 2014 11:45:51 +0000
Message-Id: <E1XxwlD-00010w-PD@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-694-g84c7934
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: d0590302f3bde188c5548c06538df7b172f12521
X-Git-Newrev: 84c79341d577d5574d3eb450007219322e87fd7d
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Dec 2014 11:45:55 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=84c79341d577d5574d3eb450007219322e87fd7d

The branch, master has been updated
       via  84c79341d577d5574d3eb450007219322e87fd7d (commit)
      from  d0590302f3bde188c5548c06538df7b172f12521 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 84c79341d577d5574d3eb450007219322e87fd7d
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Dec 8 12:59:36 2014 +0200

    Fix alignment issues in fgetpwent_r
    
    * libmailutils/base/fgetpwent.c: Place struct passwd at the
    beginning of the buffer.  Account for eventual missing newline
    at the end of file.

-----------------------------------------------------------------------

Summary of changes:
 libmailutils/base/fgetpwent.c |   63 +++++++++++++++++++++-------------------
 1 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/libmailutils/base/fgetpwent.c b/libmailutils/base/fgetpwent.c
index 6b32744..78f2b73 100644
--- a/libmailutils/base/fgetpwent.c
+++ b/libmailutils/base/fgetpwent.c
@@ -41,14 +41,17 @@
     ENOMEM - not enough memory
     ENOENT - no more entries.
 */
+#define SPWDSIZ (sizeof (struct passwd))
 
 int
 mu_fgetpwent_r (FILE *fp, char **bufp, size_t *bufs, struct passwd **result)
 {
   char *buffer = *bufp;
   size_t buflen = *bufs;
+  char *nb;
+  size_t ns;
   struct passwd *pwbuf;
-  size_t pos = 0;
+  size_t pos = SPWDSIZ;
   int c;
   size_t off[6];
   int i = 0;
@@ -56,22 +59,19 @@ mu_fgetpwent_r (FILE *fp, char **bufp, size_t *bufs, struct passwd **result)
   if (!buffer)
     buflen = 0;
   
-  while ((c = fgetc(fp)) != EOF)
+  while ((c = fgetc (fp)) != EOF)
     {
-      if (pos == buflen)
+      if (pos >= buflen)
 	{
-	  char *nb;
-	  size_t ns;
-	  
 	  if (buflen == 0)
-	    ns = 128;
+	    ns = SPWDSIZ + 128;
 	  else
 	    {
 	      ns = ns * 2;
 	      if (ns < buflen)
 		return ENOMEM;
 	    }
-	  nb = realloc(buffer, ns);
+	  nb = realloc (buffer, ns);
 	  if (!nb)
 	    return ENOMEM;
 	  buffer = nb;
@@ -80,44 +80,47 @@ mu_fgetpwent_r (FILE *fp, char **bufp, size_t *bufs, struct passwd **result)
       if (c == '\n')
 	{
 	  buffer[pos++] = 0;
-	  if (i != sizeof(off)/sizeof(off[0]))
-	    continue;
+	  if (i != sizeof (off) / sizeof (off[0]))
+	    {
+	      pos = SPWDSIZ;
+	      continue;
+	    }
 	  break;
 	}
       if (c == ':')
 	{
 	  buffer[pos++] = 0;
-	  if (i < sizeof(off)/sizeof(off[0]))
+	  if (i < sizeof (off) / sizeof (off[0]))
 	    off[i++] = pos;
 	}
       else
 	buffer[pos++] = c;
     }
 
-  if (pos == 0)
+  if (pos == SPWDSIZ)
     return ENOENT;
 
-  if (pos + sizeof(struct passwd) > buflen)
+  if (c == EOF)
     {
-      char *nb;
-      size_t ns;
-	  
-      ns = pos + sizeof(struct passwd);
-      if (ns < buflen)
-	return ENOMEM;
-    
-      nb = realloc(buffer, ns);
-      if (!nb)
-	return ENOMEM;
-      buffer = nb;
-      buflen = ns;
+      if (i != sizeof (off) / sizeof (off[0]))
+	return ENOENT;
+      if (pos == buflen)
+	{
+	  nb = realloc (buffer, buflen + 1);
+	  if (!nb)
+	    return ENOMEM;
+	  buffer = nb;
+	  buflen = ns;
+	}
+      buffer[pos++] = 0;
     }
-  pwbuf = (struct passwd*)((char*) buffer + pos);
   
-  pwbuf->pw_name   = buffer;
+  pwbuf = (struct passwd*) buffer;
+  
+  pwbuf->pw_name   = buffer + SPWDSIZ;
   pwbuf->pw_passwd = buffer + off[0];
-  pwbuf->pw_uid    = strtoul(buffer + off[1], NULL, 10);
-  pwbuf->pw_gid    = strtoul(buffer + off[2], NULL, 10);
+  pwbuf->pw_uid    = strtoul (buffer + off[1], NULL, 10);
+  pwbuf->pw_gid    = strtoul (buffer + off[2], NULL, 10);
   pwbuf->pw_gecos  = buffer + off[3];
   pwbuf->pw_dir    = buffer + off[4];
   pwbuf->pw_shell  = buffer + off[5];
@@ -196,7 +199,7 @@ main (int argc, char **argv)
         }
       printf ("======================================\n");
       printf ("End of %s\n", file);
-      close (fp);
+      fclose (fp);
     }
   return 0;
 }


hooks/post-receive
-- 
GNU Mailutils


