[WebSVN] [patch] better support for (long) X.509 certificated based usernames

View: New views
1 Messages — Rating Filter:   Alert me  

[WebSVN] [patch] better support for (long) X.509 certificated based usernames

by Udo Rader :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

as written previously, I've patched WebSVN to better deal with X.509
certificated based usernames (that is typically the subjects of
certificates), such as:

/C=AT/ST=Austria/L=Innsbruck/O=The Foo Bar Company/OU=Testing
Dept./CN=Mr. Foo Bar/emailAddress=foo.bar@...

Up to now, those usernames rendered the GUI quite "ugly" and the "blame"
functionality simply cut off the usernames after the first username.

The patch attached solves those issues by testing the author names
against an email address matching pattern and if an email address is
found, it is used instead.

BTW: the information how to subscribe to this ML could be a lot better.
Not everybody is familiar with majordomo and its secrets ...

--
Udo Rader, CTO
http://www.bestsolution.at
http://riaschissl.blogspot.com

------------------------------------------------------
http://websvn.tigris.org/ds/viewMessage.do?dsForumId=1547&dsMessageId=2393678

To unsubscribe from this discussion, e-mail: [dev-unsubscribe@...].
diff -x '*.svn' -Naur trunk/blame.php changed/blame.php
--- trunk/blame.php 2009-09-11 19:26:45.000000000 +0200
+++ changed/blame.php 2009-09-11 19:44:05.000000000 +0200
@@ -1,6 +1,7 @@
 <?php
 // WebSVN - Subversion repository viewing via the web using PHP
 // Copyright (C) 2004-2006 Tim Armes
+// (c) 2009 BestSolution.at EDV Systemhaus GmbH
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -16,6 +17,8 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 //
+// 2009-09-11: udo.rader@...
+//    * changed from plain text "svn blame" to xml style "svn blame --xml"
 // --
 //
 // blame.php
@@ -107,7 +110,7 @@
 
     $svnrep->getBlameDetails($path, $tbname, $rev, $peg);
     
-    if ($blame = fopen($tbname, 'r')) {
+    if ($blame = simplexml_load_file($tbname)) {
       // Create an array of version/author/line
   
       $index = 0;
@@ -115,12 +118,10 @@
       $last_rev = "";
       $row_class = '';
   
-      while (!feof($blame) && !feof($file)) {
-        $blameline = fgets($blame);
-  
-        if ($blameline != '') {
-          list($revision, $author, $remainder) = sscanf($blameline, '%d %s %s');
-          $empty = !$remainder;
+      foreach($blame->target[0]->entry as $oneEntry) {
+        if (!feof($file)) {
+          $revision = (int)$oneEntry->commit['revision'];
+          $author = demystifyAuthor( $oneEntry->commit->author );
   
           $listing[$index]['lineno'] = $index + 1;
   
@@ -141,11 +142,10 @@
           $line = rtrim(fgets($file));
           if (!$highlighted)
             $line = replaceEntities($line, $rep);
-          $listing[$index]['line'] = ($empty) ? ' ' : wrapInCodeTagIfNecessary($line);
+          $listing[$index]['line'] = (empty($line)) ? ' ' : wrapInCodeTagIfNecessary($line);
           $index++;
         }
       }
-      fclose($blame);
     }
     fclose($file);
     @unlink($tbname);
diff -x '*.svn' -Naur trunk/include/svnlook.php changed/include/svnlook.php
--- trunk/include/svnlook.php 2009-09-11 19:16:59.000000000 +0200
+++ changed/include/svnlook.php 2009-09-11 19:49:23.000000000 +0200
@@ -195,7 +195,7 @@
     case "AUTHOR":
       if ($debugxml) print "Author: $data\n";
       if (empty($data)) return;
-      $curList->curEntry->author .= htmlentities($data, ENT_COMPAT, "UTF-8");
+      $curList->curEntry->author .= demystifyAuthor( htmlentities($data, ENT_COMPAT, "UTF-8") );
       break;
 
     case "DATE":
@@ -334,7 +334,7 @@
     case "AUTHOR":
       if ($debugxml) print "Author: $data\n";
       if (empty($data)) return;
-      $curLog->curEntry->author .= htmlentities($data, ENT_COMPAT, "UTF-8");
+      $curLog->curEntry->author .= demystifyAuthor( htmlentities($data, ENT_COMPAT, "UTF-8") );
       break;
 
     case "DATE":
@@ -787,7 +787,7 @@
     $pegrev = ($peg) ? '@'.$peg : '';
     
     $path = encodepath($this->getSvnpath($path));
-    $cmd = $config->svn." blame -r $rev ".$this->repConfig->svnParams().quote($path.$pegrev).' > '.quote($filename);
+    $cmd = $config->svn." blame --xml -r $rev ".$this->repConfig->svnParams().quote($path.$pegrev).' > '.quote($filename);
 
     $descriptorspec = array(2 => array('pipe', 'w')); // stderr
     $resource = proc_open($cmd, $descriptorspec, $pipes);
diff -x '*.svn' -Naur trunk/include/utils.php changed/include/utils.php
--- trunk/include/utils.php 2009-09-11 19:16:59.000000000 +0200
+++ changed/include/utils.php 2009-09-11 19:48:43.000000000 +0200
@@ -1,6 +1,7 @@
 <?php
 // WebSVN - Subversion repository viewing via the web using PHP
 // Copyright (C) 2004-2006 Tim Armes
+// (c) 2009 BestSolution.at EDV Systemhaus GmbH
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -16,6 +17,9 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 //
+// 2009-09-11: udo.rader@...
+//   * added demystifyAuthor() to better support usernames from X.509
+//     certificates
 // --
 //
 // utils.php
@@ -341,4 +345,22 @@
   return $default;
 }
 
+/**
+ * Retrieves a possible email address for an author name. This is typically the
+ * case when X.509 based client authentication is in place and the username used
+ * to commit are the certificates' subjects.
+ * @param string $author
+ * @return string
+ */
+function demystifyAuthor( $author ) {
+  $rv = $author;
+  // note: this email address pattern is not 100% accurate
+  $emailPattern = '/emailAddress=(([a-z0-9])(([-a-z0-9._+])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$)/i';
+   if ( preg_match( $emailPattern, $author, $matches ) ) {
+        $rv = $matches[1];
+   }
+
+   return $rv;
+}
+
 // }}}