Fix readLink() and namepsace local disk prefix, using class buffer instead of local...
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 16 Oct 2013 11:03:24 +0000 (13:03 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 17 Oct 2013 17:48:01 +0000 (19:48 +0200)
src/VfsNs.cpp
src/VfsNs.h

index ab06268..125b127 100644 (file)
@@ -318,14 +318,19 @@ void VfsCatalog::symlink(const std::string& oldPath, const std::string& newPath)
 
 std::string VfsCatalog::readLink(const std::string& path) throw (DmException)
 {
-  char buf[PATH_MAX];
   ExtendedStat meta = this->extendedStat(path, false);
+  char *buf;
 
   if (checkPermissions(this->secCtx_, meta.acl, meta.stat, S_IREAD) != 0)
     vfsThrow(EACCES, "not enough permissions for '%s' on '%s'", clientName.c_str(), path.c_str());
 
-  memset(buf, 0, sizeof(buf));
-  wrapCall(readlink(getLocalPath(path).c_str(), buf, sizeof(buf) - 1));
+  memset(this->buffer, 0, sizeof this->buffer);
+  wrapCall(readlink(getLocalPath(path).c_str(), this->buffer, sizeof(this->buffer) - 1));
+
+  // strip namespace local disk prefix, if target path is absolute and equals to the prefix
+  if (strncmp(this->buffer, this->prefix_.c_str(), this->prefix_.size()) == 0) buf = this->buffer + this->prefix_.size();
+  else buf = this->buffer;
+
   return buf;
 }
 
@@ -862,12 +867,12 @@ Extensible VfsCatalog::vfsGetXattrs(const std::string& path, const std::string&
   attrlist_t *list;
   attrlist_ent_t *entry;
 
-  list = (attrlist_t *)this->xattrBuffer;
+  list = (attrlist_t *)this->buffer;
   memset(&attr_cursor, 0, sizeof attr_cursor);
   do {
-    wrapCall(attr_list(lpath.c_str(), this->xattrBuffer, sizeof this->xattrBuffer, follow ? 0 : ATTR_DONTFOLLOW, &attr_cursor), "could not get list of extended attributes on '%s'", path.c_str());
+    wrapCall(attr_list(lpath.c_str(), this->buffer, sizeof this->buffer, follow ? 0 : ATTR_DONTFOLLOW, &attr_cursor), "could not get list of extended attributes on '%s'", path.c_str());
     for (int i = 0; i < list->al_count; i++) {
-      entry = ATTR_ENTRY(this->xattrBuffer, i);
+      entry = ATTR_ENTRY(this->buffer, i);
       // "selinux" is returned in the list, but failing to get the value
       if (strcmp(entry->a_name, "selinux") == 0) {
         //syslog(LOG_DEBUG, "%s: skipping attribute '%s'", __func__, entry->a_name);
index 13d0c48..626103e 100644 (file)
@@ -119,7 +119,7 @@ namespace dmlite {
     bool allowCurrent, allowWriteCurrent;
     std::string clientName;
 
-    char xattrBuffer[1024], xattrValue[1024];
+    char buffer[PATH_MAX > 1024 ? PATH_MAX : 1024], xattrValue[1024];
   };
 
 };