--- a\HTPasswdSync.module	2011-06-18 19:00:43.000000000 -0000
+++ b\HTPasswdSync.module	2011-11-25 17:54:58.000000000 -0000
@@ -65,12 +65,22 @@
   */
  function _htpasswdsync_grpfilename() {
     return variable_get('htpasswdsync_htgroup', "/etc/httpd/htgroup");
  }
  
  /**
+  * return SVN authz file name
+  *     
+  * @return
+  *   full filename of the SVN authz file
+  */
+ function _htpasswdsync_authzfilename() {
+    return variable_get('htpasswdsync_authz', "");
+ }
+ 
+ /**
   * return role to put in htgroup
   * 
   * return the roles selectionned in the admin page to put into
   * the htgroup file.
   *       
   * @return
@@ -188,12 +198,40 @@
       fputs($f, $u .":". $p ."\n");
     }
   }
   fclose($f);
  }
  
+ /**
+ * write to an SVN authz file
+ *     
+ * loop through an array of groups/users and write to an SVN authz file
+ * 
+ * @param &$arr
+ *   an array of groups/users to read
+ * @param $file
+ *   an SVN authz file to write to
+ * @return
+ *   none 
+ */
+ function _htpasswdsync_write_authzfile(&$arr, $file) {
+  $content = file_get_contents($file); // get the existing contents of the authz file
+  
+  $authz_groups = "[groups]\r\n"; // string to contain the updated groups/users data
+  // loop through the array of groups/users and build the [groups] string for the authz file
+  foreach ($arr as $group => $users) {
+    if ($group != "" && $users != "") {
+      $authz_groups .= str_replace(' ', '', $group) . " = " . str_replace(' ', ',', trim($users)) . "\r\n"; // remove any spaces in the group name
+    }
+  }
+  
+  $pattern = '/\[groups\]\n([\w][\w\s,-]*?[=]{1}[\w\s,-]*?\n)*/'; // regex pattern for the [groups] information 
+  $content = preg_replace($pattern, $authz_groups, $content); // replace the existing authz [groups] section with the new one
+  file_put_contents($file, $content); // write the updated file
+ }
+ 
 /* generate the htgroup content
  *
  * for each role configured (htpasswdsync_roles array), list users
  * and update the htgroup accordingly
  * 
  * @param
@@ -221,12 +259,18 @@
     while ($r = db_fetch_object($res)) {
       $groups[$name] .= " ". $r->name;
     }
 
   }
   _htpasswdsync_write_htfile($groups, $file);
+  
+  // check if we need to update the SVN authz file
+  $file = _htpasswdsync_authzfilename();
+  if (!empty($file)) {
+	_htpasswdsync_write_authzfile($groups, $file);
+  }
  }
 
 /* generate the htpasswd content from the database
  *
  * update the htpasswd file from the table htpasswdsync_passwd
  * 
@@ -423,12 +467,22 @@
     '#size' => 100,
     '#maxlength' => 200,
     '#description' => t("Where is stored the !file file we want to synchronize with.",
           array('!file' => 'htgroup')),
     '#required' => TRUE,
   );
+  $form['htpasswdsync_authz'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Subversion authz file'),
+    '#default_value' => _htpasswdsync_authzfilename(),
+    '#size' => 100,
+    '#maxlength' => 200,
+    '#description' => t("Where is the !file file stored that we want to synchronize with?",
+          array('!file' => 'Subversion authz')),
+    '#required' => FALSE,
+  );
   $form['htpasswdsync_hash'] = array(
     '#type' => 'radios',
     '#title' => t('password hashing algorythm'),
     '#description' => t("How shall the password be hashed (crypt for unix, SHA1 for all)"),
     '#options' => _htpasswdsync_hashes(),    
     '#default_value' => _htpasswdsync_hash(),
@@ -481,13 +535,18 @@
   if ($msg = _htpasswdsync_check_file($file)) {
     form_set_error('htpasswdsync_htpasswd', $msg);
   }
 
   $file = $form_state['values']['htpasswdsync_htgroup'];
   if ($msg = _htpasswdsync_check_file($file)) {
-    form_set_error('htpasswdsync_htpasswd', $msg);
+    form_set_error('htpasswdsync_htgroup', $msg);
+  }
+
+  $file = $form_state['values']['htpasswdsync_authz'];
+  if (!empty($file) && $msg = _htpasswdsync_check_file($file)) {
+    form_set_error('htpasswdsync_authz', $msg);
   }
 }
 
 function htpasswdsync_menu() {
 
   $items = array();
@@ -523,20 +582,27 @@
   $htgroup_status_msg = _htpasswdsync_check_file(_htpasswdsync_grpfilename());
   $htgroup_status_val = REQUIREMENT_ERROR;
   if (!$htgroup_status_msg) {
     $htgroup_status_msg = t('!file file is available', array('!file' => 'htgroup'));
     $htgroup_status_val = REQUIREMENT_OK;
   }
+
+  $authz_status_msg = _htpasswdsync_check_file(_htpasswdsync_authzfilename());
+  $authz_status_val = REQUIREMENT_ERROR;
+  if (!$authz_status_msg) {
+    $authz_status_msg = t('!file file is available', array('!file' => 'authz'));
+    $authz_status_val = REQUIREMENT_OK;
+  }
   
-  $status = $htpasswd_status_val > $htgroup_status_val ?
-    $htpasswd_status_val : $htgroup_status_val;
+  $status = max($htpasswd_status_val, $htgroup_status_val, $authz_status_val);
 
   $requirements['htpasswdsync_status'] = array(
     'title'       => t('HTPasswd Sync Status'),
     'value'       => $htpasswd_status_msg ."<br>". 
                      $htgroup_status_msg ."<br>".
+                     $authz_status_msg ."<br>".
                      t('last update !time ago.', array(
                         '!time' => format_interval(time()-variable_get('htpasswdsync_cron_time', 0)))),
     'severity'    => $status,
     );
   if ($status != REQUIREMENT_OK) {
     $requirements['htpasswdsync_status']['description'] =
