move to SAFE_FREE()
[tprouty/samba.git] / source / smbd / posix_acls.c
index b87605ee07c12ad4a92ea11ff5f223447ca275dd..18a635336cbc75dffb0312a514cd21d080903a86 100644 (file)
@@ -74,7 +74,7 @@ static void free_canon_ace_list( canon_ace *list_head )
        while (list_head) {
                canon_ace *old_head = list_head;
                DLIST_REMOVE(list_head, list_head);
-               free(old_head);
+               SAFE_FREE(old_head);
        }
 }
 
@@ -256,7 +256,7 @@ static void merge_aces( canon_ace **pp_list_head )
 
                                curr_ace_outer->perms |= curr_ace->perms;
                                DLIST_REMOVE(list_head, curr_ace);
-                               free(curr_ace);
+                               SAFE_FREE(curr_ace);
                                curr_ace_outer_next = curr_ace_outer->next; /* We may have deleted the link. */
                        }
                }
@@ -301,7 +301,7 @@ static void merge_aces( canon_ace **pp_list_head )
                                         */
 
                                        DLIST_REMOVE(list_head, curr_ace);
-                                       free(curr_ace);
+                                       SAFE_FREE(curr_ace);
                                        curr_ace_outer_next = curr_ace_outer->next; /* We may have deleted the link. */
 
                                } else {
@@ -317,7 +317,7 @@ static void merge_aces( canon_ace **pp_list_head )
                                         */
 
                                        DLIST_REMOVE(list_head, curr_ace_outer);
-                                       free(curr_ace_outer);
+                                       SAFE_FREE(curr_ace_outer);
                                }
                        }
 
@@ -419,7 +419,7 @@ static BOOL unpack_nt_owners(SMB_STRUCT_STAT *psbuf, uid_t *puser, gid_t *pgrp,
 
        if(security_info_sent == 0) {
                DEBUG(0,("unpack_nt_owners: no security info sent !\n"));
-               return False;
+               return True;
        }
 
        /*
@@ -438,8 +438,10 @@ static BOOL unpack_nt_owners(SMB_STRUCT_STAT *psbuf, uid_t *puser, gid_t *pgrp,
 
        if (security_info_sent & OWNER_SECURITY_INFORMATION) {
                sid_copy(&owner_sid, psd->owner_sid);
-               if (!sid_to_uid( &owner_sid, puser, &sid_type))
+               if (!sid_to_uid( &owner_sid, puser, &sid_type)) {
                        DEBUG(3,("unpack_nt_owners: unable to validate owner sid.\n"));
+                       return False;
+               }
        }
 
        /*
@@ -449,8 +451,10 @@ static BOOL unpack_nt_owners(SMB_STRUCT_STAT *psbuf, uid_t *puser, gid_t *pgrp,
 
        if (security_info_sent & GROUP_SECURITY_INFORMATION) {
                sid_copy(&grp_sid, psd->grp_sid);
-               if (!sid_to_gid( &grp_sid, pgrp, &sid_type))
+               if (!sid_to_gid( &grp_sid, pgrp, &sid_type)) {
                        DEBUG(3,("unpack_nt_owners: unable to validate group sid.\n"));
+                       return False;
+               }
        }
 
        DEBUG(5,("unpack_nt_owners: owner_sids validated.\n"));
@@ -742,7 +746,7 @@ static BOOL create_canon_ace_lists(files_struct *fsp,
 
                        free_canon_ace_list(file_ace);
                        free_canon_ace_list(dir_ace);
-                       free(current_ace);
+                       SAFE_FREE(current_ace);
                        DEBUG(0,("create_canon_ace_lists: unable to map SID %s to uid or gid.\n",
                                sid_to_string(str, &current_ace->sid) ));
                        return False;
@@ -812,7 +816,7 @@ static BOOL create_canon_ace_lists(files_struct *fsp,
 Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name ));
                                        free_canon_ace_list(file_ace);
                                        free_canon_ace_list(dir_ace);
-                                       free(current_ace);
+                                       SAFE_FREE(current_ace);
                                        return False;
                                }       
 
@@ -863,7 +867,7 @@ Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name ));
 Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name ));
                                free_canon_ace_list(file_ace);
                                free_canon_ace_list(dir_ace);
-                               free(current_ace);
+                               SAFE_FREE(current_ace);
                                return False;
                        }       
 
@@ -879,8 +883,7 @@ Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name ));
                 * Free if ACE was not added.
                 */
 
-               if (current_ace)
-                       free(current_ace);
+               SAFE_FREE(current_ace);
        }
 
        if (fsp->is_directory && all_aces_are_inherit_only) {
@@ -1964,8 +1967,7 @@ size_t get_nt_acl(files_struct *fsp, SEC_DESC **ppdesc)
                sys_acl_free_acl(dir_acl);
        free_canon_ace_list(file_ace);
        free_canon_ace_list(dir_ace);
-       if (nt_ace_list)
-               free(nt_ace_list);
+       SAFE_FREE(nt_ace_list);
 
        return sd_size;
 }
@@ -2213,11 +2215,11 @@ static int chmod_acl_internals( SMB_ACL_T posix_acl, mode_t mode)
        }
 
        /*
-        * If this is a simple 3 element ACL then it's a standard
+        * If this is a simple 3 element ACL or no elements then it's a standard
         * UNIX permission set. Just use chmod...       
         */
 
-       if (num_entries == 3)
+       if ((num_entries == 3) || (num_entries == 0))
                return -1;
 
        return 0;