From 6638d1036688f7b0f15a1a18c9a251ab0a7ab626 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 7 Sep 2012 17:44:24 +1000 Subject: smbd: Remove pre-allocation of ACL array in sys_acl_init() 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 --- source3/include/smb_acls.h | 2 +- source3/lib/sysacls.c | 21 +++++++++------------ source3/modules/vfs_posixacl.c | 2 +- source3/smbd/posix_acls.c | 6 +++--- source3/smbd/pysmbd.c | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) (limited to 'source3') diff --git a/source3/include/smb_acls.h b/source3/include/smb_acls.h index 750bbc666a..dbcf3b7269 100644 --- a/source3/include/smb_acls.h +++ b/source3/include/smb_acls.h @@ -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); diff --git a/source3/lib/sysacls.c b/source3/lib/sysacls.c index 1b6eb9a35c..a5430d6a0d 100644 --- a/source3/lib/sysacls.c +++ b/source3/lib/sysacls.c @@ -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; } diff --git a/source3/modules/vfs_posixacl.c b/source3/modules/vfs_posixacl.c index c9f8bd5f2d..50487ff4de 100644 --- a/source3/modules/vfs_posixacl.c +++ b/source3/modules/vfs_posixacl.c @@ -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) { diff --git a/source3/smbd/posix_acls.c b/source3/smbd/posix_acls.c index c5dea9c141..016acf4b31 100644 --- a/source3/smbd/posix_acls.c +++ b/source3/smbd/posix_acls.c @@ -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; diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c index 74acc01a3a..9b9b358cd2 100644 --- a/source3/smbd/pysmbd.c +++ b/source3/smbd/pysmbd.c @@ -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; -- cgit