smbd: split out public parse_dos_attribute_blob() from get_ea_dos_attribute()
authorRalph Boehme <slow@samba.org>
Thu, 15 Mar 2018 09:56:28 +0000 (10:56 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 26 Jul 2018 13:10:29 +0000 (15:10 +0200)
In preperation of adding an async version of get_ea_dos_attribute() that
will then call parse_dos_attribute_blob() too.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/smbd/dosmode.c
source3/smbd/proto.h

index 7ac876a47bf66eeb9efd9d6e59c1a794d224bedc..ed5ecc9120c50bc968f9604c8082e0cb7a3c8dcf 100644 (file)
@@ -260,16 +260,96 @@ static uint32_t dos_mode_from_sbuf(connection_struct *conn,
  This can also pull the create time into the stat struct inside smb_fname.
 ****************************************************************************/
 
+NTSTATUS parse_dos_attribute_blob(struct smb_filename *smb_fname,
+                                 DATA_BLOB blob,
+                                 uint32_t *pattr)
+{
+       struct xattr_DOSATTRIB dosattrib;
+       enum ndr_err_code ndr_err;
+       uint32_t dosattr;
+
+       ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
+                       (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
+
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               DBG_WARNING("bad ndr decode "
+                           "from EA on file %s: Error = %s\n",
+                           smb_fname_str_dbg(smb_fname),
+                           ndr_errstr(ndr_err));
+               return ndr_map_error2ntstatus(ndr_err);
+       }
+
+       DBG_DEBUG("%s attr = %s\n",
+                 smb_fname_str_dbg(smb_fname), dosattrib.attrib_hex);
+
+       switch (dosattrib.version) {
+       case 0xFFFF:
+               dosattr = dosattrib.info.compatinfoFFFF.attrib;
+               break;
+       case 1:
+               dosattr = dosattrib.info.info1.attrib;
+               if (!null_nttime(dosattrib.info.info1.create_time)) {
+                       struct timespec create_time =
+                               nt_time_to_unix_timespec(
+                                       dosattrib.info.info1.create_time);
+
+                       update_stat_ex_create_time(&smb_fname->st,
+                                                  create_time);
+
+                       DBG_DEBUG("file %s case 1 set btime %s\n",
+                                 smb_fname_str_dbg(smb_fname),
+                                 time_to_asc(convert_timespec_to_time_t(
+                                                     create_time)));
+               }
+               break;
+       case 2:
+               dosattr = dosattrib.info.oldinfo2.attrib;
+               /* Don't know what flags to check for this case. */
+               break;
+       case 3:
+               dosattr = dosattrib.info.info3.attrib;
+               if ((dosattrib.info.info3.valid_flags & XATTR_DOSINFO_CREATE_TIME) &&
+                   !null_nttime(dosattrib.info.info3.create_time)) {
+                       struct timespec create_time =
+                               nt_time_to_unix_timespec(
+                                       dosattrib.info.info3.create_time);
+
+                       update_stat_ex_create_time(&smb_fname->st,
+                                                  create_time);
+
+                       DBG_DEBUG("file %s case 3 set btime %s\n",
+                                 smb_fname_str_dbg(smb_fname),
+                                 time_to_asc(convert_timespec_to_time_t(
+                                                     create_time)));
+               }
+               break;
+       default:
+               DBG_WARNING("Badly formed DOSATTRIB on file %s - %s\n",
+                           smb_fname_str_dbg(smb_fname), blob.data);
+               /* Should this be INTERNAL_ERROR? */
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       if (S_ISDIR(smb_fname->st.st_ex_mode)) {
+               dosattr |= FILE_ATTRIBUTE_DIRECTORY;
+       }
+
+       /* FILE_ATTRIBUTE_SPARSE is valid on get but not on set. */
+       *pattr |= (uint32_t)(dosattr & (SAMBA_ATTRIBUTES_MASK|FILE_ATTRIBUTE_SPARSE));
+
+       dos_mode_debug_print(__func__, *pattr);
+
+       return NT_STATUS_OK;
+}
+
 NTSTATUS get_ea_dos_attribute(connection_struct *conn,
                              struct smb_filename *smb_fname,
                              uint32_t *pattr)
 {
-       struct xattr_DOSATTRIB dosattrib;
-       enum ndr_err_code ndr_err;
        DATA_BLOB blob;
        ssize_t sizeret;
        fstring attrstr;
-       uint32_t dosattr;
+       NTSTATUS status;
 
        if (!lp_store_dos_attributes(SNUM(conn))) {
                return NT_STATUS_NOT_IMPLEMENTED;
@@ -327,78 +407,10 @@ NTSTATUS get_ea_dos_attribute(connection_struct *conn,
        blob.data = (uint8_t *)attrstr;
        blob.length = sizeret;
 
-       ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
-                       (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
-
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               DEBUG(1,("get_ea_dos_attribute: bad ndr decode "
-                        "from EA on file %s: Error = %s\n",
-                        smb_fname_str_dbg(smb_fname),
-                        ndr_errstr(ndr_err)));
-               return ndr_map_error2ntstatus(ndr_err);
-       }
-
-       DEBUG(10,("get_ea_dos_attribute: %s attr = %s\n",
-                 smb_fname_str_dbg(smb_fname), dosattrib.attrib_hex));
-
-       switch (dosattrib.version) {
-               case 0xFFFF:
-                       dosattr = dosattrib.info.compatinfoFFFF.attrib;
-                       break;
-               case 1:
-                       dosattr = dosattrib.info.info1.attrib;
-                       if (!null_nttime(dosattrib.info.info1.create_time)) {
-                               struct timespec create_time =
-                                       nt_time_to_unix_timespec(
-                                               dosattrib.info.info1.create_time);
-
-                               update_stat_ex_create_time(&smb_fname->st,
-                                                       create_time);
-
-                               DEBUG(10,("get_ea_dos_attribute: file %s case 1 "
-                                       "set btime %s\n",
-                                       smb_fname_str_dbg(smb_fname),
-                                       time_to_asc(convert_timespec_to_time_t(
-                                               create_time)) ));
-                       }
-                       break;
-               case 2:
-                       dosattr = dosattrib.info.oldinfo2.attrib;
-                       /* Don't know what flags to check for this case. */
-                       break;
-               case 3:
-                       dosattr = dosattrib.info.info3.attrib;
-                       if ((dosattrib.info.info3.valid_flags & XATTR_DOSINFO_CREATE_TIME) &&
-                                       !null_nttime(dosattrib.info.info3.create_time)) {
-                               struct timespec create_time =
-                                       nt_time_to_unix_timespec(
-                                               dosattrib.info.info3.create_time);
-
-                               update_stat_ex_create_time(&smb_fname->st,
-                                                       create_time);
-
-                               DEBUG(10,("get_ea_dos_attribute: file %s case 3 "
-                                       "set btime %s\n",
-                                       smb_fname_str_dbg(smb_fname),
-                                       time_to_asc(convert_timespec_to_time_t(
-                                               create_time)) ));
-                       }
-                       break;
-               default:
-                       DEBUG(1,("get_ea_dos_attribute: Badly formed DOSATTRIB on "
-                                "file %s - %s\n", smb_fname_str_dbg(smb_fname),
-                                attrstr));
-                       /* Should this be INTERNAL_ERROR? */
-                       return NT_STATUS_INVALID_PARAMETER;
-       }
-
-       if (S_ISDIR(smb_fname->st.st_ex_mode)) {
-               dosattr |= FILE_ATTRIBUTE_DIRECTORY;
+       status = parse_dos_attribute_blob(smb_fname, blob, pattr);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
        }
-       /* FILE_ATTRIBUTE_SPARSE is valid on get but not on set. */
-       *pattr |= (uint32_t)(dosattr & (SAMBA_ATTRIBUTES_MASK|FILE_ATTRIBUTE_SPARSE));
-
-       dos_mode_debug_print(__func__, *pattr);
 
        return NT_STATUS_OK;
 }
index 0697c1b9c56d94756ab3e69bfe54f0c2eacb5dc3..7c426fdf5e349d8504371ae22044d9f927f92566 100644 (file)
@@ -290,6 +290,10 @@ struct timespec get_change_timespec(connection_struct *conn,
                                struct files_struct *fsp,
                                const struct smb_filename *smb_fname);
 
+NTSTATUS parse_dos_attribute_blob(struct smb_filename *smb_fname,
+                                 DATA_BLOB blob,
+                                 uint32_t *pattr);
+
 /* The following definitions come from smbd/error.c  */
 
 bool use_nt_status(void);