[vchkpw] Patch to create IMAPdir

2006-03-28 Thread Robin Bowes
Hi all,

After struggling for sometime to get skeldir functionality to work, I've
given up for now.

The primary reason for wanting skeldirs was so that new accounts could
be created with IMAPdir support for use with bincimap.

The following patch modifies vpopmail to create an IMAPdir directory.

It also modifies r_chown to work correctly with symlinks (required since
IMAPdir contains a symlink IMAPdir/INBOX - ../Maildir/)

R.

--- vpopmail-5.4.15/vpopmail.c  2006-01-17 11:30:52.0 -0800
+++ vpopmail-5.4.15-IMAPdir/vpopmail.c  2006-03-27 11:30:50.0 -0800
@@ -1298,11 +1298,16 @@
   while((mydirent=readdir(mydir))!=NULL){
 if ( strncmp(mydirent-d_name,., 2)!=0 
  strncmp(mydirent-d_name,.., 3)!=0 ) {
-  stat( mydirent-d_name, statbuf);
-  if ( S_ISDIR(statbuf.st_mode) ) {
-r_chown( mydirent-d_name, owner, group);
+  lstat( mydirent-d_name, statbuf);
+  // don't recurse into symlinks - just chown symlink to owner:group
+  if ( S_ISLNK(statbuf.st_mode) ) {
+lchown(mydirent-d_name,owner,group);
   } else {
-chown(mydirent-d_name,owner,group);
+if ( S_ISDIR(statbuf.st_mode) ) {
+  r_chown( mydirent-d_name, owner, group);
+} else {
+  chown(mydirent-d_name,owner,group);
+}
   }
 }
   }
@@ -2115,7 +2120,7 @@
  struct vqpasswd *mypw;
  char calling_dir[MAX_BUFF];
  char domain_dir[MAX_BUFF];
- const char *dirnames[] = {Maildir, Maildir/new, Maildir/cur,
+ const char *dirnames[] = {Maildir, IMAPdir, Maildir/new,
Maildir/cur,
Maildir/tmp};
  int i;

@@ -2175,6 +2180,16 @@
 }
   }

+  // Add the symlink IMAPdir/INBOX - ../Maildir/
+  if (symlink(../Maildir/, IMAPdir/INBOX) == -1) {
+fprintf(stderr, make_user_dir: failed to symlink %s\n,
IMAPdir/INBOX);
+/* back out of changes made above */
+chdir(..);
+vdelfiles(username);
+chdir(calling_dir);
+return(NULL);
+  }
+
   /* set permissions on the user's dir */
   r_chown(., uid, gid);



Re: [vchkpw] Patch to create IMAPdir

2006-03-28 Thread Michael Krieger
Did you see my post last night about the same issue and wrapping a  shell script and exec call around bincimap? It means you don't  have to deal with this problem for pop/smtp uses, but only imap.Why modify vpopmail to do something specific to another program?-MRobin Bowes [EMAIL PROTECTED] wrote:  Hi all,After struggling for sometime to get skeldir functionality to work, I'vegiven up for now.The primary reason for wanting skeldirs was so that new accounts couldbe created with IMAPdir support for use with bincimap.The following patch modifies vpopmail to create an IMAPdir directory.It also modifies r_chown to work correctly with symlinks (required sinceIMAPdir contains a symlink IMAPdir/INBOX - ../Maildir/)R.--- vpopmail-5.4.15/vpopmail.c 
 2006-01-17 11:30:52.0 -0800+++ vpopmail-5.4.15-IMAPdir/vpopmail.c  2006-03-27 11:30:50.0 -0800@@ -1298,11 +1298,16 @@   while((mydirent=readdir(mydir))!=NULL){ if ( strncmp(mydirent-d_name,".", 2)!=0   strncmp(mydirent-d_name,"..", 3)!=0 ) {-  stat( mydirent-d_name, statbuf);-  if ( S_ISDIR(statbuf.st_mode) ) {-r_chown( mydirent-d_name, owner, group);+  lstat( mydirent-d_name, statbuf);+  // don't recurse into symlinks - just chown symlink to owner:group+  if ( S_ISLNK(statbuf.st_mode) ) {+lchown(mydirent-d_name,owner,group);   } else {-chown(mydirent-d_name,owner,group);+if ( S_ISDIR(statbuf.st_mode) ) {+  r_chown( mydirent-d_name, owner, group);+} else {+  chown(mydirent-d_name,owner,group);+}   } }   }@@ -2115,7
 +2120,7 @@  struct vqpasswd *mypw;  char calling_dir[MAX_BUFF];  char domain_dir[MAX_BUFF];- const char *dirnames[] = {"Maildir", "Maildir/new", "Maildir/cur",+ const char *dirnames[] = {"Maildir", "IMAPdir", "Maildir/new","Maildir/cur","Maildir/tmp"};  int i;@@ -2175,6 +2180,16 @@ }   }+  // Add the symlink IMAPdir/INBOX - ../Maildir/+  if (symlink("../Maildir/", "IMAPdir/INBOX") == -1) {+fprintf(stderr, "make_user_dir: failed to symlink %s\n","IMAPdir/INBOX");+/* back out of changes made above */+chdir("..");+vdelfiles(username);+chdir(calling_dir);+return(NULL);+  }+   /* set permissions on the user's dir */   r_chown(".", uid, gid);