I use the onchange functionality in vpopmail-5.5.0 but find it awkward that the script is only called once for "add_domain", instead of calling the script with "add_domain", "add_user" then "mod_user" so have written a patch to allow this. One side affect is that the order of calls in vadduser() has changed. Patch attached.

!DSPAM:55f7e1c341551875619181!
diff -uPr vpopmail-5.5.0.orig/backends/cdb/vcdb.c 
vpopmail-5.5.0/backends/cdb/vcdb.c
--- vpopmail-5.5.0.orig/backends/cdb/vcdb.c     2010-11-05 18:37:23.000000000 
+0000
+++ vpopmail-5.5.0/backends/cdb/vcdb.c  2015-09-04 12:42:00.306095822 +0100
@@ -664,12 +664,16 @@
 #endif
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s", inpw->pw_name, domain ) ;
        call_onchange ( "mod_user" ) ;
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
        if (!(strcasecmp(inpw->pw_shell, "NOQUOTA")))
           remove_maildirsize(inpw->pw_dir);
diff -uPr vpopmail-5.5.0.orig/backends/ldap/vldap.c 
vpopmail-5.5.0/backends/ldap/vldap.c
--- vpopmail-5.5.0.orig/backends/ldap/vldap.c   2010-11-05 18:37:24.000000000 
+0000
+++ vpopmail-5.5.0/backends/ldap/vldap.c        2015-09-04 12:42:00.307095769 
+0100
@@ -972,12 +972,16 @@
 #endif
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s", inpw->pw_name, domain );
        call_onchange ( "mod_user" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
        if (!(strcasecmp(inpw->pw_shell, "NOQUOTA")))
           remove_maildirsize(inpw->pw_dir);
@@ -1733,12 +1737,16 @@
     }
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s - %s", alias, domain, 
alias_line );
        call_onchange ( "alias_insert" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
     return(0);
 }
@@ -1756,12 +1764,16 @@
     if ( (err=ldap_connect()) != 0 ) return(err);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s - %s", alias, domain, 
alias_line );
        call_onchange ( "alias_remove" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
        memset(ud, 0, sizeof(ud));
        snprintf(ud, sizeof(ud), "%s@%s", alias, domain);
@@ -1863,12 +1875,16 @@
     if ( (err=ldap_connect()) != 0 ) return(err);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s", alias, domain );
        call_onchange ( "alias_delete" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
        memset(ud, 0, sizeof(ud));
        snprintf(ud, sizeof(ud), "%s@%s", alias, domain);
diff -uPr vpopmail-5.5.0.orig/backends/mysql/vmysql.c 
vpopmail-5.5.0/backends/mysql/vmysql.c
--- vpopmail-5.5.0.orig/backends/mysql/vmysql.c 2010-11-05 18:37:23.000000000 
+0000
+++ vpopmail-5.5.0/backends/mysql/vmysql.c      2015-09-04 12:42:00.308095716 
+0100
@@ -875,12 +875,16 @@
 #endif
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s", inpw->pw_name, domain );
        call_onchange ( "mod_user" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
        if (!(strcasecmp(inpw->pw_shell, "NOQUOTA")))
           remove_maildirsize(inpw->pw_dir);
@@ -1459,12 +1463,16 @@
     }
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s - %s", alias, domain, 
alias_line );
        call_onchange ( "valias_insert" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
     return(0);
 }
@@ -1478,12 +1486,16 @@
     if ( (err=vauth_open_update()) != 0 ) return(err);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s - %s", alias, domain, 
alias_line );
        call_onchange ( "valias_remove" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
     qnprintf( SqlBufUpdate, SQL_BUF_SIZE, 
         "DELETE FROM valias WHERE alias = '%s' \
@@ -1508,12 +1520,16 @@
     if ( (err=vauth_open_update()) != 0 ) return(err);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s", alias, domain );
        call_onchange ( "valias_delete" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
     qnprintf( SqlBufUpdate, SQL_BUF_SIZE, 
         "DELETE FROM valias WHERE alias = '%s' \
@@ -1539,12 +1555,16 @@
     if ( (err=vauth_open_update()) != 0 ) return(err);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s", domain );
        call_onchange ( "valias_delete_domain" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
     qnprintf( SqlBufUpdate, SQL_BUF_SIZE, 
         "DELETE FROM valias WHERE domain = '%s'", 
diff -uPr vpopmail-5.5.0.orig/backends/postgres/vpgsql.c 
vpopmail-5.5.0/backends/postgres/vpgsql.c
--- vpopmail-5.5.0.orig/backends/postgres/vpgsql.c      2010-11-05 
18:37:23.000000000 +0000
+++ vpopmail-5.5.0/backends/postgres/vpgsql.c   2015-09-04 12:42:00.309095667 
+0100
@@ -687,12 +687,16 @@
 #endif
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s", inpw->pw_name, domain );
        call_onchange ( "mod_user" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
        if (!(strcasecmp(inpw->pw_shell, "NOQUOTA")))
           remove_maildirsize(inpw->pw_dir);
@@ -1396,12 +1400,16 @@
     if(pgres) PQclear(pgres);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s - %s", alias, domain, 
alias_line );
        call_onchange ( "valias_add" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
     return(0);
   }
@@ -1416,12 +1424,16 @@
   if ( (err=vauth_open(1)) != 0 ) return(err);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
   if( allow_onchange ) {
+#endif
      /* tell other programs that data has changed */
      snprintf ( onchange_buf, MAX_BUFF, "%s@%s", alias, domain );
      call_onchange ( "valias_delete" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
      }
 #endif
+#endif
 
   qnprintf( SqlBufUpdate, SQL_BUF_SIZE, 
            "delete from valias where alias='%s' and domain='%s'", 
@@ -1452,12 +1464,16 @@
   if ( (err=vauth_open(1)) != 0 ) return(err);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
   if( allow_onchange ) {
+#endif
      /* tell other programs that data has changed */
      snprintf ( onchange_buf, MAX_BUFF, "%s@%s - %s", alias, domain, 
alias_line);
      call_onchange ( "valias_remove" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
      }
 #endif
+#endif
 
   qnprintf( SqlBufUpdate, SQL_BUF_SIZE, 
            "delete from valias where alias='%s' and valias_line='%s' and 
domain='%s'", 
@@ -1485,12 +1501,16 @@
   if ( (err=vauth_open(1)) != 0 ) return(err);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
   if( allow_onchange ) {
+#endif
      /* tell other programs that data has changed */
      snprintf ( onchange_buf, MAX_BUFF, "%s@%s - %s", alias, domain, 
alias_line);
      call_onchange ( "valias_delete_domain" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
      }
 #endif
+#endif
 
   qnprintf( SqlBufUpdate, SQL_BUF_SIZE, 
            "delete from valias where domain='%s'", domain );
diff -uPr vpopmail-5.5.0.orig/vpalias.c vpopmail-5.5.0/vpalias.c
--- vpopmail-5.5.0.orig/vpalias.c       2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vpalias.c    2015-09-04 12:42:00.310095624 +0100
@@ -151,12 +151,16 @@
     fclose(fs);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s - %s", alias, domain, 
alias_line );
        call_onchange ( "valias_insert" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
     return(0);
 }
@@ -218,12 +222,16 @@
     free(DirNew);
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s - %s", alias, domain, 
alias_line );
        call_onchange ( "valias_remove" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
 #endif
+#endif
 
     return(0);
 }
@@ -248,13 +256,15 @@
     }
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
     if( allow_onchange ) {
+#endif
        /* tell other programs that data has changed */
        snprintf ( onchange_buf, MAX_BUFF, "%s@%s", alias, domain );
        call_onchange ( "valias_delete" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
        }
-
-
+#endif
 #endif
 
     strncat(Dir, "/.qmail-", sizeof(Dir)-strlen(Dir)-1);
diff -uPr vpopmail-5.5.0.orig/vpopmail.c vpopmail-5.5.0/vpopmail.c
--- vpopmail-5.5.0.orig/vpopmail.c      2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vpopmail.c   2015-09-04 12:42:00.312095542 +0100
@@ -111,9 +111,11 @@
  int aliascount=0;
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
   /*  Don't execute any implied onchange in called functions  */
   allow_onchange = 0;
 #endif
+#endif
 
   /*
    * In case we need to use delete_line, build an array and count 
@@ -319,12 +321,16 @@
 
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
   allow_onchange = 1;
+#endif
   /* tell other programs that data has changed */
   snprintf ( onchange_buf, MAX_BUFF, "%s", domain );
   call_onchange ( "add_domain" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
   allow_onchange = 0;
 #endif
+#endif
 
   /* return back to the callers directory and return success */
   chdir(calling_dir);
@@ -651,10 +657,12 @@
        
 
 #ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
  int temp_onchange;
     temp_onchange = allow_onchange;
     allow_onchange = 0;
 #endif
+#endif
 
   /* check gecos for : characters - bad */
   if ( strchr(gecos,':')!=0) return(VA_BAD_CHAR);
@@ -722,6 +730,18 @@
     return(VA_NO_AUTH_CONNECTION);
   }
 
+#ifdef ONCHANGE_SCRIPT
+#ifdef ONCHANGE_SCRIPT_ALLOW
+  allow_onchange = temp_onchange;
+#endif
+  /* tell other programs that data has changed */
+  snprintf ( onchange_buf, MAX_BUFF, "%s@%s", username, domain );
+  call_onchange ( "add_user" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
+  allow_onchange = 0;
+#endif
+#endif
+
   if (limits.defaultquota > 0) {
     if (limits.defaultmaxmsgcount > 0)
       snprintf (quota, sizeof(quota), "%dS,%dC", limits.defaultquota,
@@ -767,12 +787,10 @@
   chdir(calling_dir);
 
 #ifdef ONCHANGE_SCRIPT
-  allow_onchange = temp_onchange;
-  /* tell other programs that data has changed */
-  snprintf ( onchange_buf, MAX_BUFF, "%s@%s", username, domain );
-  call_onchange ( "add_user" );
+#ifdef ONCHANGE_SCRIPT_ALLOW
   allow_onchange = 1;
 #endif
+#endif
 
   return(VA_SUCCESS);
 }
@@ -4356,15 +4374,19 @@
  * 2007-07-14 jms1 - suppressing "ONCHANGE script not found" message.
  */
 char onchange_buf[MAX_BUFF];
+#ifdef ONCHANGE_SCRIPT_ALLOW
 int allow_onchange=1;
+#endif
 int call_onchange ( const char *cmd )
 {
        char path[MAX_BUFF];
        int pid, rv;
 
+#ifdef ONCHANGE_SCRIPT_ALLOW
         if( !allow_onchange )  {
            return(0);
            }
+#endif
 
        /* build the name */
        snprintf ( path, sizeof(path), "%s/onchange", VPOPMAIL_DIR_ETC );
diff -uPr vpopmail-5.5.0.orig/vpopmail.h vpopmail-5.5.0/vpopmail.h
--- vpopmail-5.5.0.orig/vpopmail.h      2010-11-05 18:37:24.000000000 +0000
+++ vpopmail-5.5.0/vpopmail.h   2015-09-04 12:42:00.313095506 +0100
@@ -367,7 +367,9 @@
 #ifdef ONCHANGE_SCRIPT
 /* onchange function */
 extern char onchange_buf[MAX_BUFF];
+#ifdef ONCHANGE_SCRIPT_ALLOW
 extern int allow_onchange;
+#endif
 int call_onchange();
 #endif
 

Reply via email to