s3:lib: Factor read_ea_list_entry() and read_nttrans_ea_list() out so they can be...
authorJeremy Allison <jra@samba.org>
Wed, 7 Aug 2013 20:48:55 +0000 (13:48 -0700)
committerStefan Metzmacher <metze@samba.org>
Thu, 15 Aug 2013 07:07:06 +0000 (09:07 +0200)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/lib/util_ea.c [new file with mode: 0644]
source3/lib/util_ea.h [new file with mode: 0644]
source3/smbd/nttrans.c
source3/smbd/trans2.c
source3/wscript_build

diff --git a/source3/lib/util_ea.c b/source3/lib/util_ea.c
new file mode 100644 (file)
index 0000000..81684da
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+   Unix SMB/CIFS implementation.
+   SMB Extended attribute buffer handling
+   Copyright (C) Jeremy Allison                 2005-2013
+   Copyright (C) Tim Prouty                    2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "lib/util_ea.h"
+
+/****************************************************************************
+ Read one EA list entry from the buffer.
+****************************************************************************/
+
+struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t data_size, size_t *pbytes_used)
+{
+       struct ea_list *eal = talloc_zero(ctx, struct ea_list);
+       uint16 val_len;
+       unsigned int namelen;
+       size_t converted_size;
+
+       if (!eal) {
+               return NULL;
+       }
+
+       if (data_size < 6) {
+               return NULL;
+       }
+
+       eal->ea.flags = CVAL(pdata,0);
+       namelen = CVAL(pdata,1);
+       val_len = SVAL(pdata,2);
+
+       if (4 + namelen + 1 + val_len > data_size) {
+               return NULL;
+       }
+
+       /* Ensure the name is null terminated. */
+       if (pdata[namelen + 4] != '\0') {
+               return NULL;
+       }
+       if (!pull_ascii_talloc(ctx, &eal->ea.name, pdata + 4, &converted_size)) {
+               DEBUG(0,("read_ea_list_entry: pull_ascii_talloc failed: %s",
+                       strerror(errno)));
+       }
+       if (!eal->ea.name) {
+               return NULL;
+       }
+
+       eal->ea.value = data_blob_talloc(eal, NULL, (size_t)val_len + 1);
+       if (!eal->ea.value.data) {
+               return NULL;
+       }
+
+       memcpy(eal->ea.value.data, pdata + 4 + namelen + 1, val_len);
+
+       /* Ensure we're null terminated just in case we print the value. */
+       eal->ea.value.data[val_len] = '\0';
+       /* But don't count the null. */
+       eal->ea.value.length--;
+
+       if (pbytes_used) {
+               *pbytes_used = 4 + namelen + 1 + val_len;
+       }
+
+       DEBUG(10,("read_ea_list_entry: read ea name %s\n", eal->ea.name));
+       dump_data(10, eal->ea.value.data, eal->ea.value.length);
+
+       return eal;
+}
+
+/****************************************************************************
+ Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
+****************************************************************************/
+
+struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
+{
+       struct ea_list *ea_list_head = NULL;
+       size_t offset = 0;
+
+       if (data_size < 4) {
+               return NULL;
+       }
+
+       while (offset + 4 <= data_size) {
+               size_t next_offset = IVAL(pdata,offset);
+               struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
+
+               if (!eal) {
+                       return NULL;
+               }
+
+               DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
+               if (next_offset == 0) {
+                       break;
+               }
+
+               /* Integer wrap protection for the increment. */
+               if (offset + next_offset < offset) {
+                       break;
+               }
+
+               offset += next_offset;
+
+               /* Integer wrap protection for while loop. */
+               if (offset + 4 < offset) {
+                       break;
+               }
+
+       }
+
+       return ea_list_head;
+}
diff --git a/source3/lib/util_ea.h b/source3/lib/util_ea.h
new file mode 100644 (file)
index 0000000..54423ac
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+   Unix SMB/CIFS implementation.
+   SMB Extended attribute buffer handling
+   Copyright (C) Jeremy Allison                 2005-2013
+   Copyright (C) Tim Prouty                    2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __LIB_UTIL_EA_H__
+#define __LIB_UTIL_EA_H__
+
+/****************************************************************************
+ Read one EA list entry from a buffer.
+****************************************************************************/
+
+struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t data_size, size_t *pbytes_used);
+
+/****************************************************************************
+ Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
+****************************************************************************/
+
+struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size);
+
+#endif /* __LIB_UTIL_EA_H__ */
index bcba29a3e899c88bd0f301451ecbd9680e37fc9d..94be9f6d8d0df96bf33e5567f4cc8680d4c72e73 100644 (file)
@@ -29,6 +29,7 @@
 #include "auth.h"
 #include "smbprofile.h"
 #include "libsmb/libsmb.h"
+#include "lib/util_ea.h"
 
 extern const struct generic_mapping file_generic_mapping;
 
@@ -965,49 +966,6 @@ NTSTATUS set_sd_blob(files_struct *fsp, uint8_t *data, uint32_t sd_len,
        return set_sd(fsp, psd, security_info_sent);
 }
 
-/****************************************************************************
- Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
-****************************************************************************/
-
-struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
-{
-       struct ea_list *ea_list_head = NULL;
-       size_t offset = 0;
-
-       if (data_size < 4) {
-               return NULL;
-       }
-
-       while (offset + 4 <= data_size) {
-               size_t next_offset = IVAL(pdata,offset);
-               struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
-
-               if (!eal) {
-                       return NULL;
-               }
-
-               DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
-               if (next_offset == 0) {
-                       break;
-               }
-
-               /* Integer wrap protection for the increment. */
-               if (offset + next_offset < offset) {
-                       break;
-               }
-
-               offset += next_offset;
-
-               /* Integer wrap protection for while loop. */
-               if (offset + 4 < offset) {
-                       break;
-               }
-
-       }
-
-       return ea_list_head;
-}
-
 /****************************************************************************
  Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
 ****************************************************************************/
index da0b1ea92cba5a5b3b308f46fcb022e3abfc640a..2bff483d7063a85b9efb111d760fa3cde92336cb 100644 (file)
@@ -38,6 +38,7 @@
 #include "smbprofile.h"
 #include "rpc_server/srv_pipe_hnd.h"
 #include "printing.h"
+#include "lib/util_ea.h"
 
 #define DIR_ENTRY_SAFETY_MARGIN 4096
 
@@ -748,67 +749,6 @@ static struct ea_list *read_ea_name_list(TALLOC_CTX *ctx, const char *pdata, siz
        return ea_list_head;
 }
 
-/****************************************************************************
- Read one EA list entry from the buffer.
-****************************************************************************/
-
-struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t data_size, size_t *pbytes_used)
-{
-       struct ea_list *eal = talloc_zero(ctx, struct ea_list);
-       uint16 val_len;
-       unsigned int namelen;
-       size_t converted_size;
-
-       if (!eal) {
-               return NULL;
-       }
-
-       if (data_size < 6) {
-               return NULL;
-       }
-
-       eal->ea.flags = CVAL(pdata,0);
-       namelen = CVAL(pdata,1);
-       val_len = SVAL(pdata,2);
-
-       if (4 + namelen + 1 + val_len > data_size) {
-               return NULL;
-       }
-
-       /* Ensure the name is null terminated. */
-       if (pdata[namelen + 4] != '\0') {
-               return NULL;
-       }
-       if (!pull_ascii_talloc(ctx, &eal->ea.name, pdata + 4, &converted_size)) {
-               DEBUG(0,("read_ea_list_entry: pull_ascii_talloc failed: %s",
-                        strerror(errno)));
-       }
-       if (!eal->ea.name) {
-               return NULL;
-       }
-
-       eal->ea.value = data_blob_talloc(eal, NULL, (size_t)val_len + 1);
-       if (!eal->ea.value.data) {
-               return NULL;
-       }
-
-       memcpy(eal->ea.value.data, pdata + 4 + namelen + 1, val_len);
-
-       /* Ensure we're null terminated just in case we print the value. */
-       eal->ea.value.data[val_len] = '\0';
-       /* But don't count the null. */
-       eal->ea.value.length--;
-
-       if (pbytes_used) {
-               *pbytes_used = 4 + namelen + 1 + val_len;
-       }
-
-       DEBUG(10,("read_ea_list_entry: read ea name %s\n", eal->ea.name));
-       dump_data(10, eal->ea.value.data, eal->ea.value.length);
-
-       return eal;
-}
-
 /****************************************************************************
  Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
 ****************************************************************************/
index f52197a1a31adca8cb1e44512fdd06b68779d965..569c63250edbdd8c6e562d5b4f26fcadba0855c7 100755 (executable)
@@ -67,7 +67,8 @@ LIB_SRC = '''
           lib/fncall.c
           libads/krb5_errs.c lib/system_smbd.c lib/audit.c
          lib/tevent_wait.c
-          lib/idmap_cache.c'''
+          lib/idmap_cache.c
+          lib/util_ea.c'''
 
 LIB_UTIL_SRC = '''
                lib/system.c