Per-Domain-Quota in 2.2 with virtual domains turned on ?

Christian Schulte cs at schulte.it
Thu Jan 30 16:54:21 EST 2003


Ken Murchison wrote:

>I just committed support for per-domain quotas which works for all
>domains except for the default domain (the code to make it work for the
>default domain would be particularly crufty).  To set a domain quota, do
>something like the following in cyradm:
>
>sq @domain.tld 1024
>
>To try this out, either do an update from CVS or apply the following
>(relatively small) patches:
>
>http://bugzilla.andrew.cmu.edu/cvsweb/src/cyrus/imap/mailbox.c.diff?r1=1.134.4.14&r2=1.134.4.15
>http://bugzilla.andrew.cmu.edu/cvsweb/src/cyrus/imap/mboxlist.c.diff?r1=1.198.2.29&r2=1.198.2.30
>
Sorry for not answering a longer time. I did not have the time to 
concentrate on cyrus the last  days.  I just updated from cvs and 
started looking at the domain quota. Could it be that the quota binary 
does not support the -f option for virtdomains correctly ? For me quota 
does not report anything for mailboxes for which cyradm displays data 
and so I think quota cannot fix also ?!

Actually I wrote a patch last night to get rid of mkimap -d! I added a 
new switch to imap/imapoptions which is called virtdomains_autoconfig 
and defaults to disabled. If enabled the function mailbox_create() in 
mailbox.c creates the configdirectory/domain/d/domain/...  and the 
sievedir/domain/d/domain/.... directories if compiled with USE_SIEVE and 
if the domain does not already exist.

For me this patch compiles without warnings and seems to work but 
because I am a java programmer and are used to thinking in an 
objectoriented manner I do not have *the* 100% C knowledge. Mainly I do 
not know if the pointers buffers etc I used are used and initialized 
correctly or whatever. So this here needs definetley review and it would 
be great if someone could point out some errors I did or write some 
comments to this.

--Christian--

schulte-22:31:03:~/cyrus-cvs/cyrus-imapd-2_2/imap >diff -c 
imapoptions.original imapoptions
*** imapoptions.original        Do Jan 30 22:28:27 2003
--- imapoptions Do Jan 30 22:30:20 2003
***************
*** 546,551 ****
--- 546,557 ----
  { "virtdomains", 0, SWITCH }
  /* Enable virtual domain support */

+ { "virtdomains_autoconfig", 0, SWITCH }
+ /* Automatically configure the configdirectory tree. The default is
+    to run tools/mkimap -d for every new domain. Enabling this causes
+    automatic configuration of the configdirectory tree without the need of
+    tools/mkimap -d */
+
  /*
  .SH SEE ALSO
  .PP


schulte-22:48:49:~/cyrus-cvs/cyrus-imapd-2_2/imap >diff -c 
mailbox.c.original mailbox.c
*** mailbox.c.original  Do Jan 30 22:23:22 2003
--- mailbox.c   Do Jan 30 22:18:18 2003
***************
*** 1938,1944 ****
--- 1938,1977 ----
      return (stat(quota_path, &sbuf) != -1);
  }

+ /* creates directories a..z within a given path */
+ int mailbox_virtdomains_createaz(char *path){

+     char *a="XX";
+     char alpha[60]="a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z";
+     char *p;
+     int save_errno;
+     struct stat sbuf;
+
+     p=path+strlen(path);
+     a=strtok(strdup(alpha), ":");
+     strcpy(p,a);
+     if (mkdir(path, 0755) == -1 && errno != EEXIST) {
+        save_errno = errno;
+         if (stat(path, &sbuf) == -1) {
+             errno = save_errno;
+             syslog(LOG_ERR, "IOERROR: creating directory %s: %m", path);
+             return IMAP_IOERROR;
+         }
+     }
+     while((a=strtok(NULL, ":"))){
+         strcpy(p,a);
+         if (mkdir(path, 0755) == -1 && errno != EEXIST) {
+             save_errno = errno;
+             if (stat(path, &sbuf) == -1) {
+                 errno = save_errno;
+                 syslog(LOG_ERR, "IOERROR: creating directory %s: %m", 
path);
+                 return IMAP_IOERROR;
+             }
+         }
+   }
+   return 0;
+ }
+
  int mailbox_create(const char *name,
                   char *path,
                   const char *acl,
***************
*** 1948,1953 ****
--- 1981,1994 ----
  {
      int r;
      char *p=path;
+     char cfgdir[MAX_MAILBOX_PATH];
+ #ifdef USE_SIEVE
+     char sievedir[MAX_MAILBOX_PATH];
+ #endif /* USE_SIEVE */
+     char *myname=strdup(name);
+     char *myp=myname;
+     char *my2p;
+     char letter[2];
      char quota_root[MAX_MAILBOX_PATH];
      int hasquota;
      char fnamebuf[MAX_MAILBOX_PATH];
***************
*** 1977,1983 ****
            return IMAP_IOERROR;
        }
      }
!
      zeromailbox(mailbox);
      mailbox.quota.fd = -1;

--- 2018,2109 ----
            return IMAP_IOERROR;
        }
      }
!
!     /* Create the domain also under the configdirectory if 
virtdomains_autoconfig. */
!     if(config_getswitch(IMAPOPT_VIRTDOMAINS_AUTOCONFIG)){
!         strcpy(cfgdir, config_getstring(IMAPOPT_CONFIGDIRECTORY));
!         myp=strchr(myp, '!');
!         // Only do something if there is an '!' character in the 
mailbox name
!         if(myp){
!             *myp='\0';
!             strcat(cfgdir,"/domain/");
!             strncpy(letter, myname, 1);
!             strcat(cfgdir,letter);
!             strcat(cfgdir,"/");
!             strcat(cfgdir,myname);
!             strcat(cfgdir,"/");
!             // Check if the domain already exists
!             if(stat(cfgdir, &sbuf) != -1) goto sieve;
!             syslog(LOG_INFO, "virtdomains_autoconfig: configuring %s", 
cfgdir);
!             myp=cfgdir;
!             while ((myp = strchr(myp+1, '/'))) {
!                 *myp = '\0';
!                 if (mkdir(cfgdir, 0755) == -1 && errno != EEXIST) {
!                     save_errno = errno;
!                     if (stat(cfgdir, &sbuf) == -1) {
!                         errno = save_errno;
!                         syslog(LOG_ERR, "IOERROR: creating directory 
%s: %m", cfgdir);
!                         return IMAP_IOERROR;
!                     }
!                 }
!                 *myp = '/';
!             }
!             myp=cfgdir+strlen(cfgdir);
!             strcpy(myp,"user");
!             if (mkdir(cfgdir, 0755) == -1 && errno != EEXIST) {
!                 save_errno = errno;
!                 if (stat(cfgdir, &sbuf) == -1) {
!                     errno = save_errno;
!                     syslog(LOG_ERR, "IOERROR: creating directory %s: 
%m", cfgdir);
!                     return IMAP_IOERROR;
!                 }
!             }
!             strcat(cfgdir, "/");
!             my2p=cfgdir+strlen(cfgdir);
!             r=mailbox_virtdomains_createaz(cfgdir);
!             if(r!=0) return r;
!             strcpy(myp,"quota");
!             if (mkdir(cfgdir, 0755) == -1 && errno != EEXIST) {
!                 save_errno = errno;
!                 if (stat(cfgdir, &sbuf) == -1) {
!                     errno = save_errno;
!                     syslog(LOG_ERR, "IOERROR: creating directory %s: 
%m", cfgdir);
!                     return IMAP_IOERROR;
!                 }
!             }
!             strcat(cfgdir, "/");
!             r=mailbox_virtdomains_createaz(cfgdir);
!             if(r!=0) return r;
! sieve:
! #ifdef USE_SIEVE
!             strcpy(sievedir, config_getstring(IMAPOPT_SIEVEDIR));
!             strcat(sievedir,"/domain/");
!             strcat(sievedir,letter);
!             strcat(sievedir,"/");
!             strcat(sievedir,myname);
!             strcat(sievedir,"/");
!             // Check if the domain already exists
!             if(stat(sievedir, &sbuf) != -1) goto configured;
!             syslog(LOG_INFO, "virtdomains_autoconfig: configuring %s", 
sievedir);
!             myp=sievedir;
!             while ((myp = strchr(myp+1, '/'))) {
!                 *myp = '\0';
!                 if (mkdir(sievedir, 0755) == -1 && errno != EEXIST) {
!                     save_errno = errno;
!                     if (stat(sievedir, &sbuf) == -1) {
!                         errno = save_errno;
!                         syslog(LOG_ERR, "IOERROR: creating directory 
%s: %m", sievedir);
!                         return IMAP_IOERROR;
!                     }
!                 }
!                 *myp = '/';
!             }
!             r=mailbox_virtdomains_createaz(sievedir);
!             if(r!=0) return r;
! #endif /* USE_SIEVE */
! configured:
!         }
!     }
      zeromailbox(mailbox);
      mailbox.quota.fd = -1;









More information about the Info-cyrus mailing list