Fix smbc_listxattr() and friends (bug #5189)
authorDerrell Lipman <derrell.lipman@unwireduniverse.com>
Sun, 13 Jan 2008 22:10:06 +0000 (17:10 -0500)
committerDerrell Lipman <derrell.lipman@unwireduniverse.com>
Sun, 13 Jan 2008 22:10:06 +0000 (17:10 -0500)
When the capability of using full names for DOS attributes was added, a bug
was introduced which caused the wrong number of bytes to be returned.  This
patch to smbc_listxattr_ctx() fixes the problem.

Thanks to Jack Schmidt for this patch.

Derrell
(This used to be commit 913c335d21c503d32b35bf65da7b2bddf0473875)

examples/libsmbclient/testacl.c
source3/include/libsmbclient.h
source3/libsmb/libsmbclient.c

index 4d327b39a7a11e0c7a0eea3768fd94ed66a50ced..51cc90f1015e34289aa4574930448ecade2cd2f7 100644 (file)
@@ -7,6 +7,7 @@
 
 enum acl_mode
 {
+    SMB_ACL_LIST,
     SMB_ACL_GET,
     SMB_ACL_SET,
     SMB_ACL_DELETE,
@@ -24,7 +25,7 @@ int main(int argc, const char *argv[])
     int debug = 0;
     int numeric = 0;
     int full_time_names = 0;
-    enum acl_mode mode = SMB_ACL_GET;
+    enum acl_mode mode = SMB_ACL_LIST;
     static char *the_acl = NULL;
     int ret;
     char *p;
@@ -149,6 +150,30 @@ int main(int argc, const char *argv[])
     
     switch(mode)
     {
+    case SMB_ACL_LIST:
+        ret = smbc_listxattr(path, value, sizeof(value)-2);
+        if (ret < 0)
+        {
+            printf("Could not get attribute list for [%s] %d: %s\n",
+                   path, errno, strerror(errno));
+            return 1;
+        }
+
+        /*
+         * The list of attributes has a series of null-terminated strings.
+         * The list of strings terminates with an extra null byte, thus two in
+         * a row.  Ensure that our buffer, which is conceivably shorter than
+         * the list of attributes, actually ends with two null bytes in a row.
+         */
+        value[sizeof(value) - 2] = '\0';
+        value[sizeof(value) - 1] = '\0';
+        printf("Supported attributes:\n");
+        for (p = value; *p; p += strlen(p) + 1)
+        {
+            printf("\t%s\n", p);
+        }
+        break;
+
     case SMB_ACL_GET:
         if (the_acl == NULL)
         {
index 9175b33d6023460df466462f58905286ab016042..07242f795675005bbd6eb86fc0f8f89266bdff08 100644 (file)
@@ -1961,7 +1961,7 @@ int smbc_fremovexattr(int fd,
  *                            extended attributes
  *
  * @note            This function always returns all attribute names supported
- *                  by NT file systems, regardless of wether the referenced
+ *                  by NT file systems, regardless of whether the referenced
  *                  file system supports extended attributes (e.g. a Windows
  *                  2000 machine supports extended attributes if NTFS is used,
  *                  but not if FAT is used, and Windows 98 doesn't support
index da8f1e332b44b39b7f2289933f91797fe97e940e..179f6eba5dd06400bc0b7eecf4405d60061b5fd3 100644 (file)
@@ -6241,6 +6241,7 @@ smbc_listxattr_ctx(SMBCCTX *context,
          * the complete set of attribute names, always, rather than only those
          * attribute names which actually exist for a file.  Hmmm...
          */
+        size_t retsize;
         const char supported_old[] =
                 "system.*\0"
                 "system.*+\0"
@@ -6284,22 +6285,24 @@ smbc_listxattr_ctx(SMBCCTX *context,
 
         if (context->internal->_full_time_names) {
                 supported = supported_new;
+                retsize = sizeof(supported_new);
         } else {
                 supported = supported_old;
+                retsize = sizeof(supported_old);
         }
 
         if (size == 0) {
-                return sizeof(supported);
+                return retsize;
         }
 
-        if (sizeof(supported) > size) {
+        if (retsize > size) {
                 errno = ERANGE;
                 return -1;
         }
 
         /* this can't be strcpy() because there are embedded null characters */
-        memcpy(list, supported, sizeof(supported));
-        return sizeof(supported);
+        memcpy(list, supported, retsize);
+        return retsize;
 }