Proper support for IODriver::kInsecure.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 15 Oct 2013 11:17:00 +0000 (13:17 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 15 Oct 2013 11:17:00 +0000 (13:17 +0200)
src/VfsIO.cpp

index 4648a17..7cbb886 100644 (file)
@@ -52,23 +52,22 @@ IOHandler* VfsIODriver::createIOHandler(const std::string& pfn,
                                         mode_t mode) throw (DmException)
 {  
   if (!(flags & IODriver::kInsecure)) {
-    if (!extras.hasField("token"))
-      throw DmException(EACCES, "Missing token");
+      if (!extras.hasField("token"))
+        vfsThrow(EACCES, "Missing token");
+
+    std::string userId;
+    if (this->useIp_)
+      userId = this->secCtx_->credentials.remoteAddress;
+    else
+      userId = this->secCtx_->credentials.clientName;
+
+    if (dmlite::validateToken(extras.getString("token"),
+                              userId,
+                              pfn, this->passwd_,
+                              flags != O_RDONLY) != kTokenOK)
+      vfsThrow(EACCES, "Token does not validate for '%s' (using %s)", userId.c_str(), this->useIp_?"IP":"DN");
   }
-  
-  std::string userId;
-  if (this->useIp_)
-    userId = this->secCtx_->credentials.remoteAddress;
-  else
-    userId = this->secCtx_->credentials.clientName;
-  
-  if (dmlite::validateToken(extras.getString("token"),
-                            userId,
-                            pfn, this->passwd_,
-                            flags != O_RDONLY) != kTokenOK)
-    throw DmException(EACCES, "Token does not validate (using %s)",
-                      this->useIp_?"IP":"DN");
-  
+
   // Create
   return new VfsIOHandler(pfn, flags, mode);
 }