myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [2925] Added support for regex in the security file CO


From: Giuseppe Scrivano
Subject: [myserver-commit] [2925] Added support for regex in the security file CONDITION.
Date: Thu, 30 Oct 2008 20:39:50 +0000

Revision: 2925
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2925
Author:   gscrivano
Date:     2008-10-30 20:39:49 +0000 (Thu, 30 Oct 2008)

Log Message:
-----------
Added support for regex in the security file CONDITION.

Modified Paths:
--------------
    trunk/myserver/documentation/security.texi
    trunk/myserver/src/conf/security/xml_validator.cpp

Modified: trunk/myserver/documentation/security.texi
===================================================================
--- trunk/myserver/documentation/security.texi  2008-10-29 22:28:23 UTC (rev 
2924)
+++ trunk/myserver/documentation/security.texi  2008-10-30 20:39:49 UTC (rev 
2925)
@@ -128,6 +128,16 @@
 In this case, the inner block is evaluated every time the
 @code{auth.user} is different than "Guest".
 
+It is possible to match a value against a regular expression, in this
+case you will need to declare it explicitly.
+
address@hidden
+<CONDITION name="auth.user" value="admin.*" regex="yes" not="yes">
+...
+</CONDITION>
address@hidden example
+
+
 @subsubsection DEFINE element
 The @code{DEFINE} block is used to specify a value for a variable that
 later can be accessed by the server.

Modified: trunk/myserver/src/conf/security/xml_validator.cpp
===================================================================
--- trunk/myserver/src/conf/security/xml_validator.cpp  2008-10-29 22:28:23 UTC 
(rev 2924)
+++ trunk/myserver/src/conf/security/xml_validator.cpp  2008-10-30 20:39:49 UTC 
(rev 2925)
@@ -19,6 +19,7 @@
 #include <include/conf/security/xml_validator.h>
 #include <include/conf/security/auth_domain.h>
 #include <include/conf/security/security_cache.h>
+#include <include/base/regex/myserver_regex.h>
 
 XmlValidator::XmlValidator ()
 {
@@ -281,21 +282,26 @@
   string name;
   const xmlChar *isNot = (const xmlChar*)"";
   const xmlChar *value = (const xmlChar*)"";
+  const xmlChar *regex = (const xmlChar*)"";
   xmlAttr *attrs = node->properties;
   
   while (attrs)
   {
-    if(!xmlStrcmp (attrs->name, (const xmlChar *)"name") &&
+    if (!xmlStrcmp (attrs->name, (const xmlChar *)"name") &&
        attrs->children && attrs->children->content)
       name.assign ((const char*)attrs->children->content);
     
-    if(!xmlStrcmp (attrs->name, (const xmlChar *)"value") &&
+    if (!xmlStrcmp (attrs->name, (const xmlChar *)"value") &&
        attrs->children && attrs->children->content)
       value = attrs->children->content;
 
-    if(!xmlStrcmp (attrs->name, (const xmlChar *)"not") &&
+    if (!xmlStrcmp (attrs->name, (const xmlChar *)"not") &&
        attrs->children && attrs->children->content)
       isNot = attrs->children->content;
+
+    if (!xmlStrcmp (attrs->name, (const xmlChar *)"regex") &&
+       attrs->children && attrs->children->content)
+      regex = attrs->children->content;
     
     attrs = attrs->next;
   }
@@ -305,7 +311,21 @@
   if (!storedValue)
     return false;
 
-  bool eq = storedValue->compare ((const char*)value) == 0;
+  bool eq;
+
+  if (!xmlStrcmp (regex, (const xmlChar *) "yes"))
+  {
+    Regex regex;
+
+    if (regex.compile ((const char*)value, REG_EXTENDED))
+      return false;
+
+    regmatch_t pm;
+
+    eq = regex.exec (storedValue->c_str (), 1, &pm, 0) == 0;
+  }
+  else
+    eq = storedValue->compare ((const char*)value) == 0;
   
   if (!xmlStrcmp (isNot, (const xmlChar *) "yes"))
     return !eq;






reply via email to

[Prev in Thread] Current Thread [Next in Thread]