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

[mpop-users] [PATCH] Add an option to disable hard-links usage



Hi everybody!


I'm writing to say I am a happy user of mpop, but I've always felt
bit bothered that I couldn't use it inside an EncFS (encrypted
filesystem) with maximum-security settings...

The thing is, when the "filename to IV header chaining" feature
is enabled in EncFS, the file data encoding depends on the
filename, and therefore hard-links are not supported.

This patch doesn't change anything in the way mpop works
by default. It just adds the --no-links option so that users on
filesystems that do not support hard-links can switch to
standard file renaming.

I hope the patch is ok; otherwise just tell me what to change :-)


Kind regards,

-- 
Sebastien Raveau
diff -c -r mpop-1.0.16.orig/doc/mpop.1 mpop-1.0.16/doc/mpop.1
*** mpop-1.0.16.orig/doc/mpop.1	2008-12-24 15:50:38.000000000 +0100
--- mpop-1.0.16/doc/mpop.1	2009-01-10 16:16:18.000000000 +0100
***************
*** 148,153 ****
--- 148,158 ----
  method from its arguments.
  .IP "--uidls-file=\fIfilename\fP"
  File to store UIDLs in. See the \fBuidls_file\fP command below.
+ .IP "--no-links"
+ Disable the usage of (hard) links, which are used by default in maildir
+ delivery mode. You will need this if your filesystem does not support them
+ (even in UNIX environments, for example if your maildir is in an EncFS with
+ maximum-security settings).
  .RE
  .SH USAGE
  mpop normally uses a configuration file (~/.mpoprc by default) that
diff -c -r mpop-1.0.16.orig/src/delivery.c mpop-1.0.16/src/delivery.c
*** mpop-1.0.16.orig/src/delivery.c	2007-07-16 22:34:44.000000000 +0200
--- mpop-1.0.16/src/delivery.c	2009-01-10 16:19:05.000000000 +0100
***************
*** 56,61 ****
--- 56,62 ----
  #include "tools.h"
  #include "delivery.h"
  
+ char no_links = 0;
  
  /*******************************************************************************
   *
***************
*** 421,445 ****
      newfilename = xstrdup(maildir_data->filename);
      strncpy(newfilename, "new", 3);
  #ifndef W32_NATIVE
!     if (link(maildir_data->filename, newfilename) != 0)
      {
! 	*errstr = xasprintf(_("%s: cannot link %s to %s: %s"), 
! 		maildir_data->maildir, maildir_data->filename, newfilename, 
! 		strerror(errno));
! 	free(newfilename);
! 	return DELIVERY_EIO;
!     }
!     (void)unlink(maildir_data->filename);
! #else /* W32_NATIVE */
!     if (rename(maildir_data->filename, newfilename) != 0)
!     {
! 	*errstr = xasprintf(_("%s: cannot move %s to %s: %s"), 
! 		maildir_data->maildir, maildir_data->filename, newfilename, 
! 		strerror(errno));
! 	free(newfilename);
! 	return DELIVERY_EIO;
      }
! #endif /* ! W32_NATIVE */	 
      free(newfilename);
      free(maildir_data->filename);
      maildir_data->filename = NULL;
--- 422,449 ----
      newfilename = xstrdup(maildir_data->filename);
      strncpy(newfilename, "new", 3);
  #ifndef W32_NATIVE
!     if (!no_links)
      {
! 	if (link(maildir_data->filename, newfilename) != 0)
! 	{
! 	    *errstr = xasprintf(_("%s: cannot link %s to %s: %s"), 
! 		    maildir_data->maildir, maildir_data->filename, newfilename, 
! 		    strerror(errno));
! 	    free(newfilename);
! 	    return DELIVERY_EIO;
! 	}
! 	(void)unlink(maildir_data->filename);
      }
!     else
! #endif /* W32_NATIVE */
! 	if (rename(maildir_data->filename, newfilename) != 0)
! 	{
! 	    *errstr = xasprintf(_("%s: cannot move %s to %s: %s"), 
! 		    maildir_data->maildir, maildir_data->filename, newfilename, 
! 		    strerror(errno));
! 	    free(newfilename);
! 	    return DELIVERY_EIO;
! 	}
      free(newfilename);
      free(maildir_data->filename);
      maildir_data->filename = NULL;
diff -c -r mpop-1.0.16.orig/src/delivery.h mpop-1.0.16/src/delivery.h
*** mpop-1.0.16.orig/src/delivery.h	2007-07-16 22:34:45.000000000 +0200
--- mpop-1.0.16/src/delivery.h	2009-01-10 16:16:18.000000000 +0100
***************
*** 138,141 ****
--- 138,149 ----
   */
  int delivery_method_free(delivery_method_t *dm, char **errstr);
  
+ /*
+  * --no-links disables the use of hardlinks
+  *
+  * Required because on some UNIX filesystems, such as EncFS with
+  * maximum-security settings, hardlinking is not permitted.
+  */
+ extern char no_links;
+ 
  #endif
diff -c -r mpop-1.0.16.orig/src/mpop.c mpop-1.0.16/src/mpop.c
*** mpop-1.0.16.orig/src/mpop.c	2008-12-24 15:54:01.000000000 +0100
--- mpop-1.0.16/src/mpop.c	2009-01-10 16:16:18.000000000 +0100
***************
*** 1644,1649 ****
--- 1644,1650 ----
  #define LONGONLYOPT_FILTER			20
  #define LONGONLYOPT_DELIVERY			21
  #define LONGONLYOPT_UIDLS_FILE			22
+ #define LONGONLYOPT_NO_LINKS			23
  
  int main(int argc, char *argv[])
  {
***************
*** 1743,1748 ****
--- 1744,1750 ----
  	    LONGONLYOPT_TLS_MIN_DH_PRIME_BITS },
  	{ "tls-priorities",        required_argument, 0, 
  	    LONGONLYOPT_TLS_PRIORITIES },
+ 	{ "no-links",              no_argument, 0, LONGONLYOPT_NO_LINKS },
  	{ 0, 0, 0, 0 }
      };
      
***************
*** 2172,2177 ****
--- 2174,2183 ----
  		cmdline_account->mask |= ACC_UIDLS_FILE;
  		break;
  
+ 	    case LONGONLYOPT_NO_LINKS:
+ 		no_links = 1;
+ 		break;
+ 
  	    default:
  		error_code = 1;
  		break;