smbd: Remove pre-allocation of ACL array in sys_acl_init()
authorAndrew Bartlett <abartlet@samba.org>
Fri, 7 Sep 2012 07:44:24 +0000 (17:44 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 12 Sep 2012 03:26:16 +0000 (05:26 +0200)
Instead, this is just handled with realloc in sys_acl_create_entry()

This allows us to remove the size element from the SMB_ACL_T.

Andrew Bartlett

librpc/idl/smb_acl.idl
source3/include/smb_acls.h
source3/lib/sysacls.c
source3/modules/vfs_posixacl.c
source3/smbd/posix_acls.c
source3/smbd/pysmbd.c

index 2904c3afa487825091808111c60a0f77d609cb49..f7332d9ac71292f6ed7b7a93bb5df118a7596e87 100644 (file)
@@ -65,7 +65,6 @@ interface smb_acl
        } smb_acl_entry;
        
        [public] typedef struct {
-               [value(0)] int  size;
                int     count;
                [value(0)] int  next;
                [size_is(count)] smb_acl_entry acl[*];
index 750bbc666ae7fb76ece82455647ffddf77a802d2..dbcf3b7269c930c9960caf84c7cf9d49f4849819 100644 (file)
@@ -44,7 +44,7 @@ int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d);
 int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
 int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
 char *sys_acl_to_text(const struct smb_acl_t *acl_d, ssize_t *len_p);
-SMB_ACL_T sys_acl_init(int count);
+SMB_ACL_T sys_acl_init(void);
 int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p);
 int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type);
 int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p);
index 1b6eb9a35c5bd3dab4492c541c875f764414a8df..a5430d6a0db805f72ce14040299a5d2471d08d37 100644 (file)
@@ -249,25 +249,19 @@ char *sys_acl_to_text(const struct smb_acl_t *acl_d, ssize_t *len_p)
        return text;
 }
 
-SMB_ACL_T sys_acl_init(int count)
+SMB_ACL_T sys_acl_init(void)
 {
        SMB_ACL_T       a;
 
-       if (count < 0) {
-               errno = EINVAL;
-               return NULL;
-       }
-
        if ((a = talloc(NULL, struct smb_acl_t)) == NULL) {
                errno = ENOMEM;
                return NULL;
        }
  
-       a->size = count + 1;
        a->count = 0;
        a->next = -1;
 
-       a->acl = talloc_array(a, struct smb_acl_entry, count+1);
+       a->acl = talloc_array(a, struct smb_acl_entry, 0);
        if (!a->acl) {
                TALLOC_FREE(a);
                errno = ENOMEM;
@@ -281,22 +275,25 @@ int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
 {
        SMB_ACL_T       acl_d;
        SMB_ACL_ENTRY_T entry_d;
+       struct smb_acl_entry *acl;
 
        if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
                errno = EINVAL;
                return -1;
        }
 
-       if (acl_d->count >= acl_d->size) {
-               errno = ENOSPC;
+       acl = talloc_realloc(acl_d, acl_d->acl, struct smb_acl_entry, acl_d->count+1);
+       if (!acl) {
+               errno = ENOMEM;
                return -1;
        }
-
-       entry_d         = &acl_d->acl[acl_d->count++];
+       acl_d->acl = acl;
+       entry_d         = &acl_d->acl[acl_d->count];
        entry_d->a_type = SMB_ACL_TAG_INVALID;
        entry_d->a_perm = 0;
        *entry_p        = entry_d;
 
+       acl_d->count++;
        return 0;
 }
 
index c9f8bd5f2d17440de307766e2b681193e3a85be8..50487ff4dedcdb17346e2343886a165d47e28ddd 100644 (file)
@@ -214,7 +214,7 @@ static bool smb_ace_to_internal(acl_entry_t posix_ace,
 
 static struct smb_acl_t *smb_acl_to_internal(acl_t acl)
 {
-       struct smb_acl_t *result = sys_acl_init(0);
+       struct smb_acl_t *result = sys_acl_init();
        int entry_id = ACL_FIRST_ENTRY;
        acl_entry_t e;
        if (result == NULL) {
index c5dea9c141e32efa492b2aed3c583ff6022ff922..016acf4b31fc73fad303a336aba3a733cfe0a244 100644 (file)
@@ -2823,7 +2823,7 @@ static bool set_canon_ace_list(files_struct *fsp,
 {
        connection_struct *conn = fsp->conn;
        bool ret = False;
-       SMB_ACL_T the_acl = sys_acl_init(count_canon_ace_list(the_ace) + 1);
+       SMB_ACL_T the_acl = sys_acl_init();
        canon_ace *p_ace;
        int i;
        SMB_ACL_ENTRY_T mask_entry;
@@ -4524,7 +4524,7 @@ static bool unix_ex_wire_to_tagtype(unsigned char wire_tt, SMB_ACL_TAG_T *p_tt)
 static SMB_ACL_T create_posix_acl_from_wire(connection_struct *conn, uint16 num_acls, const char *pdata)
 {
        unsigned int i;
-       SMB_ACL_T the_acl = sys_acl_init(num_acls);
+       SMB_ACL_T the_acl = sys_acl_init();
 
        if (the_acl == NULL) {
                return NULL;
@@ -4668,7 +4668,7 @@ static bool remove_posix_acl(connection_struct *conn, files_struct *fsp, const c
        SMB_ACL_ENTRY_T entry;
        bool ret = False;
        /* Create a new ACL with only 3 entries, u/g/w. */
-       SMB_ACL_T new_file_acl = sys_acl_init(3);
+       SMB_ACL_T new_file_acl = sys_acl_init();
        SMB_ACL_ENTRY_T user_ent = NULL;
        SMB_ACL_ENTRY_T group_ent = NULL;
        SMB_ACL_ENTRY_T other_ent = NULL;
index 74acc01a3ae7cc4249d55fa0570a703151d64dc2..9b9b358cd253cb939720954835aa43f57e40e264 100644 (file)
@@ -160,7 +160,7 @@ static SMB_ACL_T make_simple_acl(gid_t gid, mode_t chmod_mode)
        mode_t mode_other = chmod_mode &  07;
 
        SMB_ACL_ENTRY_T entry;
-       SMB_ACL_T acl = sys_acl_init(4);
+       SMB_ACL_T acl = sys_acl_init();
 
        if (!acl) {
                return NULL;