You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kp...@apache.org on 2008/08/01 23:07:21 UTC

svn commit: r681824 - in /incubator/qpid/trunk/qpid/cpp/src: acl.mk qpid/acl/Acl.cpp qpid/acl/Acl.h qpid/acl/AclPlugin.cpp qpid/acl/AclReader.cpp qpid/acl/AclReader.h

Author: kpvdr
Date: Fri Aug  1 14:07:20 2008
New Revision: 681824

URL: http://svn.apache.org/viewvc?rev=681824&view=rev
Log:
Initial framework for ACL reader

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.h
Modified:
    incubator/qpid/trunk/qpid/cpp/src/acl.mk
    incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclPlugin.cpp

Modified: incubator/qpid/trunk/qpid/cpp/src/acl.mk
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/acl.mk?rev=681824&r1=681823&r2=681824&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/acl.mk (original)
+++ incubator/qpid/trunk/qpid/cpp/src/acl.mk Fri Aug  1 14:07:20 2008
@@ -6,6 +6,8 @@
 libqpidacl_la_SOURCES = \
   qpid/acl/Acl.cpp \
   qpid/acl/Acl.h \
+  qpid/acl/AclReader.cpp \
+  qpid/acl/AclReader.h \
   qpid/acl/AclPlugin.cpp 
 
 libqpidacl_la_LIBADD= -lacl libqpidbroker.la

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp?rev=681824&r1=681823&r2=681824&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp Fri Aug  1 14:07:20 2008
@@ -72,6 +72,9 @@
    /*params*/)
    {
       if (aclValues.noEnforce) return true;
+      boost::shared_ptr<AclData> dataLocal = data;  //rcu copy
+      
+      // only use dataLocal here...
    
       // add real ACL check here... 
       AclResult aclreslt = ALLOWLOG;  // hack to test, set based on real decision.
@@ -83,6 +86,9 @@
    bool Acl::authorise(std::string id, acl::Action action, acl::ObjectType objType, std::string ExchangeName, std::string /*RoutingKey*/)
    {
       if (aclValues.noEnforce) return true;
+      boost::shared_ptr<AclData> dataLocal = data;  //rcu copy
+      
+      // only use dataLocal here...
    
       // add real ACL check here... 
       AclResult aclreslt = ALLOWLOG;  // hack to test, set based on real decision.
@@ -113,8 +119,15 @@
    bool Acl::readAclFile()
    {
       // only set transferAcl = true if a rule implies the use of ACL on transfer, else keep false for permormance reasons.
-   
-   
+      return readAclFile(aclValues.aclFile);
+   }
+
+   bool Acl::readAclFile(std::string aclFile) {
+      boost::shared_ptr<AclData> d(new AclData);
+      if (AclReader::read(aclFile, d))
+          return false;
+ 
+      data = d;
       return true;
    }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.h?rev=681824&r1=681823&r2=681824&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.h Fri Aug  1 14:07:20 2008
@@ -22,6 +22,7 @@
 
 
 
+#include "qpid/acl/AclReader.h"
 #include "qpid/shared_ptr.h"
 #include "qpid/RefCounted.h"
 #include "qpid/broker/AclModule.h"
@@ -37,7 +38,6 @@
 namespace acl {
 
 struct AclValues {
-    public:
 	bool noEnforce;
     std::string aclFile;
 
@@ -52,6 +52,7 @@
    acl::AclValues aclValues;
    broker::Broker* broker;
    bool transferAcl;
+   boost::shared_ptr<AclData> data;
 
 
 public:
@@ -71,7 +72,7 @@
    std::string printObjType(acl::ObjectType objType);
    bool result(AclResult aclreslt, std::string id, acl::Action action, acl::ObjectType objType, std::string name);
    bool readAclFile();
-      
+   bool readAclFile(std::string aclFile);      
 };
 
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclPlugin.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclPlugin.cpp?rev=681824&r1=681823&r2=681824&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclPlugin.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclPlugin.cpp Fri Aug  1 14:07:20 2008
@@ -16,6 +16,7 @@
  *
  */
 
+#include <sstream>
 #include "qpid/acl/Acl.h"
 #include "qpid/broker/Broker.h"
 #include "qpid/Plugin.h"
@@ -61,6 +62,9 @@
 			return;  
 		}
         if (acl) throw Exception("ACL plugin cannot be initialized twice in one process.");
+        std::ostringstream oss;
+        oss << b.getDataDir().getPath() << "/" << values.aclFile;
+        values.aclFile = oss.str();
         acl = new Acl(values, b);
 		b.setAcl(acl.get());
         b.addFinalizer(boost::bind(&AclPlugin::shutdown, this));

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.cpp?rev=681824&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.cpp Fri Aug  1 14:07:20 2008
@@ -0,0 +1,73 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "qpid/acl/AclReader.h"
+
+#include <cstring>
+//#include <iostream> // debug
+#include <fstream>
+
+namespace qpid {
+namespace acl {
+
+int AclReader::read(const std::string& fn, boost::shared_ptr<AclData> d) {
+//std::cout << "AclReader::read(" << fn << ")" << std::endl << std::flush;
+    char buff[1024];
+    std::ifstream ifs(fn.c_str(), std::ios_base::in);
+    if (!ifs.good()) {
+        // error/exception - file open error
+        return -1;
+    }
+    try {
+        while (ifs.good()) {
+            ifs.getline(buff, 1024);
+            processLine(buff, d);
+        }
+        ifs.close();
+    } catch (...) {
+        // error/exception - file read/processing error
+        ifs.close();
+        return -2;
+    }
+    return 0;
+}
+
+
+void AclReader::processLine(char* line, boost::shared_ptr<AclData> /*d*/) {
+   std::vector<std::string> toks;
+   int numToks = tokenizeLine(line, toks);
+   for (int i=0; i<numToks; i++) {
+// DO MAGIC STUFF HERE
+//std::cout << "tok " << i << ": " << toks[i] << std::endl << std::flush;
+   }
+}
+
+int  AclReader::tokenizeLine(char* line, std::vector<std::string>& toks) {
+    const char* tokChars = " \t\n";
+    int cnt = 0;
+    char* cp = std::strtok(line, tokChars);
+    while (cp != 0) {
+        toks.push_back(std::string(cp));
+        cnt++;
+        cp = std::strtok(0, tokChars);
+    }
+    return cnt;
+}
+
+
+}} // namespace qpid::acl

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.h?rev=681824&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/acl/AclReader.h Fri Aug  1 14:07:20 2008
@@ -0,0 +1,45 @@
+#ifndef QPID_ACL_ACLREADER_H
+#define QPID_ACL_ACLREADER_H
+
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <boost/shared_ptr.hpp>
+#include <string>
+#include <vector>
+
+namespace qpid {
+namespace acl {
+
+struct AclData {
+    bool lc; // Line continue flag
+    AclData() : lc(false) {}
+};
+
+class AclReader {
+public:
+    static int read(const std::string& fn, boost::shared_ptr<AclData> d);
+private:
+    static void processLine(char* line, boost::shared_ptr<AclData> d);
+    static int tokenizeLine(char* line, std::vector<std::string>& toks);
+};
+    
+}} // namespace qpid::acl
+
+#endif // QPID_ACL_ACLREADER_H