s3-talloc Change TALLOC_ARRAY() to talloc_array()
[samba.git] / source3 / modules / vfs_afsacl.c
index 1c310c7185983dc6bb3db02125ddccaf4b731181..658f3be179914b8ba2e7f25e8355348b5b62c395 100644 (file)
@@ -18,6 +18,8 @@
  */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
 #include <afs/venus.h>
 #include <afs/prs_fs.h>
 
-#define MAXSIZE 2048
+#define MAXSIZE 2049
 
-extern const DOM_SID global_sid_World;
-extern const DOM_SID global_sid_Builtin_Administrators;
-extern const DOM_SID global_sid_Builtin_Backup_Operators;
-extern const DOM_SID global_sid_Authenticated_Users;
-extern const DOM_SID global_sid_NULL;
+extern const struct dom_sid global_sid_World;
+extern const struct dom_sid global_sid_Builtin_Administrators;
+extern const struct dom_sid global_sid_Builtin_Backup_Operators;
+extern const struct dom_sid global_sid_Authenticated_Users;
+extern const struct dom_sid global_sid_NULL;
 
 static char space_replacement = '%';
 
@@ -46,7 +48,7 @@ extern int afs_syscall(int, char *, int, char *, int);
 struct afs_ace {
        bool positive;
        char *name;
-       DOM_SID sid;
+       struct dom_sid sid;
        enum lsa_SidType type;
        uint32 rights;
        struct afs_ace *next;
@@ -108,7 +110,7 @@ static struct afs_ace *new_afs_ace(TALLOC_CTX *mem_ctx,
                                   bool positive,
                                   const char *name, uint32 rights)
 {
-       DOM_SID sid;
+       struct dom_sid sid;
        enum lsa_SidType type;
        struct afs_ace *result;
 
@@ -232,10 +234,10 @@ static bool parse_afs_acl(struct afs_acl *acl, const char *acl_str)
        int nplus, nminus;
        int aces;
 
-       char str[MAXSIZE+1];
+       char str[MAXSIZE];
        char *p = str;
 
-       strncpy(str, acl_str, MAXSIZE);
+       strlcpy(str, acl_str, MAXSIZE);
 
        if (sscanf(p, "%d", &nplus) != 1)
                return False;
@@ -311,16 +313,16 @@ static bool unparse_afs_acl(struct afs_acl *acl, char *acl_str)
        }
 
        fstr_sprintf(line, "%d\n", positives);
-       safe_strcat(acl_str, line, MAXSIZE);
+       strlcat(acl_str, line, MAXSIZE);
 
        fstr_sprintf(line, "%d\n", negatives);
-       safe_strcat(acl_str, line, MAXSIZE);
+       strlcat(acl_str, line, MAXSIZE);
 
        ace = acl->acelist;
 
        while (ace != NULL) {
                fstr_sprintf(line, "%s\t%d\n", ace->name, ace->rights);
-               safe_strcat(acl_str, line, MAXSIZE);
+               strlcat(acl_str, line, MAXSIZE);
                ace = ace->next;
        }
        return True;
@@ -417,7 +419,7 @@ static void split_afs_acl(struct afs_acl *acl,
 static bool same_principal(struct afs_ace *x, struct afs_ace *y)
 {
        return ( (x->positive == y->positive) &&
-                (sid_compare(&x->sid, &y->sid) == 0) );
+                (dom_sid_compare(&x->sid, &y->sid) == 0) );
 }
 
 static void merge_afs_acls(struct afs_acl *dir_acl,
@@ -514,7 +516,7 @@ static struct static_dir_ace_mapping {
 
        /* FULL inherit only -- counterpart to previous one */
        { 0, SEC_ACE_FLAG_OBJECT_INHERIT|SEC_ACE_FLAG_CONTAINER_INHERIT|SEC_ACE_FLAG_INHERIT_ONLY,
-         PERMS_FULL | GENERIC_RIGHT_WRITE_ACCESS, 127 /* rlidwka */ },
+         PERMS_FULL | SEC_GENERIC_WRITE, 127 /* rlidwka */ },
 
        /* CHANGE without inheritance -- in all cases here we also get
           the corresponding INHERIT_ONLY ACE in the same ACL */
@@ -522,13 +524,13 @@ static struct static_dir_ace_mapping {
 
        /* CHANGE inherit only -- counterpart to previous one */
        { 0, SEC_ACE_FLAG_OBJECT_INHERIT|SEC_ACE_FLAG_CONTAINER_INHERIT|SEC_ACE_FLAG_INHERIT_ONLY,
-         PERMS_CHANGE | GENERIC_RIGHT_WRITE_ACCESS, 63 /* rlidwk */ },
+         PERMS_CHANGE | SEC_GENERIC_WRITE, 63 /* rlidwk */ },
 
        /* End marker, hopefully there's no afs right 9999 :-) */
        { 0, 0, 0, 9999 }
 };
 
-static uint32 nt_to_afs_dir_rights(const char *filename, const SEC_ACE *ace)
+static uint32 nt_to_afs_dir_rights(const char *filename, const struct security_ace *ace)
 {
        uint32 result = 0;
        uint32 rights = ace->access_mask;
@@ -569,7 +571,7 @@ static uint32 nt_to_afs_dir_rights(const char *filename, const SEC_ACE *ace)
        return result;
 }
 
-static uint32 nt_to_afs_file_rights(const char *filename, const SEC_ACE *ace)
+static uint32 nt_to_afs_file_rights(const char *filename, const struct security_ace *ace)
 {
        uint32 result = 0;
        uint32 rights = ace->access_mask;
@@ -590,9 +592,9 @@ static size_t afs_to_nt_acl_common(struct afs_acl *afs_acl,
                                   uint32 security_info,
                                   struct security_descriptor **ppdesc)
 {
-       SEC_ACE *nt_ace_list;
-       DOM_SID owner_sid, group_sid;
-       SEC_ACL *psa = NULL;
+       struct security_ace *nt_ace_list;
+       struct dom_sid owner_sid, group_sid;
+       struct security_acl *psa = NULL;
        int good_aces;
        size_t sd_size;
        TALLOC_CTX *mem_ctx = talloc_tos();
@@ -603,7 +605,7 @@ static size_t afs_to_nt_acl_common(struct afs_acl *afs_acl,
        gid_to_sid(&group_sid, psbuf->st_ex_gid);
 
        if (afs_acl->num_aces) {
-               nt_ace_list = TALLOC_ARRAY(mem_ctx, SEC_ACE, afs_acl->num_aces);
+               nt_ace_list = talloc_array(mem_ctx, struct security_ace, afs_acl->num_aces);
 
                if (nt_ace_list == NULL)
                        return 0;
@@ -642,11 +644,11 @@ static size_t afs_to_nt_acl_common(struct afs_acl *afs_acl,
        if (psa == NULL)
                return 0;
 
-       *ppdesc = make_sec_desc(mem_ctx, SEC_DESC_REVISION,
+       *ppdesc = make_sec_desc(mem_ctx, SD_REVISION,
                                SEC_DESC_SELF_RELATIVE,
-                               (security_info & OWNER_SECURITY_INFORMATION)
+                               (security_info & SECINFO_OWNER)
                                ? &owner_sid : NULL,
-                               (security_info & GROUP_SECURITY_INFORMATION)
+                               (security_info & SECINFO_GROUP)
                                ? &group_sid : NULL,
                                NULL, psa, &sd_size);
 
@@ -659,8 +661,15 @@ static size_t afs_to_nt_acl(struct afs_acl *afs_acl,
                            uint32 security_info,
                            struct security_descriptor **ppdesc)
 {
+       int ret;
+
        /* Get the stat struct for the owner info. */
-       if(SMB_VFS_STAT(conn, smb_fname) != 0) {
+       if (lp_posix_pathnames()) {
+               ret = SMB_VFS_LSTAT(conn, smb_fname);
+       } else {
+               ret = SMB_VFS_STAT(conn, smb_fname);
+       }
+       if (ret == -1) {
                return 0;
        }
 
@@ -675,7 +684,7 @@ static size_t afs_fto_nt_acl(struct afs_acl *afs_acl,
 {
        SMB_STRUCT_STAT sbuf;
 
-       if (fsp->is_directory || fsp->fh->fd == -1) {
+       if (fsp->fh->fd == -1) {
                /* Get the stat struct for the owner info. */
                return afs_to_nt_acl(afs_acl, fsp->conn, fsp->fsp_name,
                                     security_info, ppdesc);
@@ -688,20 +697,20 @@ static size_t afs_fto_nt_acl(struct afs_acl *afs_acl,
        return afs_to_nt_acl_common(afs_acl, &sbuf, security_info, ppdesc);
 }
 
-static bool mappable_sid(const DOM_SID *sid)
+static bool mappable_sid(const struct dom_sid *sid)
 {
-       DOM_SID domain_sid;
+       struct dom_sid domain_sid;
        
-       if (sid_compare(sid, &global_sid_Builtin_Administrators) == 0)
+       if (dom_sid_compare(sid, &global_sid_Builtin_Administrators) == 0)
                return True;
 
-       if (sid_compare(sid, &global_sid_World) == 0)
+       if (dom_sid_compare(sid, &global_sid_World) == 0)
                return True;
 
-       if (sid_compare(sid, &global_sid_Authenticated_Users) == 0)
+       if (dom_sid_compare(sid, &global_sid_Authenticated_Users) == 0)
                return True;
 
-       if (sid_compare(sid, &global_sid_Builtin_Backup_Operators) == 0)
+       if (dom_sid_compare(sid, &global_sid_Builtin_Backup_Operators) == 0)
                return True;
 
        string_to_sid(&domain_sid, "S-1-5-21");
@@ -716,15 +725,15 @@ static bool nt_to_afs_acl(const char *filename,
                          uint32 security_info_sent,
                          const struct security_descriptor *psd,
                          uint32 (*nt_to_afs_rights)(const char *filename,
-                                                    const SEC_ACE *ace),
+                                                    const struct security_ace *ace),
                          struct afs_acl *afs_acl)
 {
-       const SEC_ACL *dacl;
+       const struct security_acl *dacl;
        int i;
 
        /* Currently we *only* look at the dacl */
 
-       if (((security_info_sent & DACL_SECURITY_INFORMATION) == 0) ||
+       if (((security_info_sent & SECINFO_DACL) == 0) ||
            (psd->dacl == NULL))
                return True;
 
@@ -734,7 +743,7 @@ static bool nt_to_afs_acl(const char *filename,
        dacl = psd->dacl;
 
        for (i = 0; i < dacl->num_aces; i++) {
-               const SEC_ACE *ace = &(dacl->aces[i]);
+               const struct security_ace *ace = &(dacl->aces[i]);
                const char *dom_name, *name;
                enum lsa_SidType name_type;
                char *p;
@@ -750,22 +759,22 @@ static bool nt_to_afs_acl(const char *filename,
                        continue;
                }
 
-               if (sid_compare(&ace->trustee,
+               if (dom_sid_compare(&ace->trustee,
                                &global_sid_Builtin_Administrators) == 0) {
 
                        name = "system:administrators";
 
-               } else if (sid_compare(&ace->trustee,
+               } else if (dom_sid_compare(&ace->trustee,
                                       &global_sid_World) == 0) {
 
                        name = "system:anyuser";
 
-               } else if (sid_compare(&ace->trustee,
+               } else if (dom_sid_compare(&ace->trustee,
                                       &global_sid_Authenticated_Users) == 0) {
 
                        name = "system:authuser";
 
-               } else if (sid_compare(&ace->trustee,
+               } else if (dom_sid_compare(&ace->trustee,
                                       &global_sid_Builtin_Backup_Operators)
                           == 0) {
 
@@ -888,7 +897,7 @@ static NTSTATUS afs_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
 {
        struct afs_acl old_afs_acl, new_afs_acl;
        struct afs_acl dir_acl, file_acl;
-       char acl_string[2049];
+       char acl_string[MAXSIZE];
        struct afs_iob iob;
        int ret = -1;
        char *name = NULL;
@@ -1049,7 +1058,7 @@ static NTSTATUS afsacl_get_nt_acl(struct vfs_handle_struct *handle,
 NTSTATUS afsacl_fset_nt_acl(vfs_handle_struct *handle,
                         files_struct *fsp,
                         uint32 security_info_sent,
-                        const SEC_DESC *psd)
+                        const struct security_descriptor *psd)
 {
        return afs_set_nt_acl(handle, fsp, security_info_sent, psd);
 }
@@ -1058,14 +1067,19 @@ static int afsacl_connect(vfs_handle_struct *handle,
                          const char *service, 
                          const char *user)
 {
-                       const char *spc;
+       const char *spc;
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
 
        spc = lp_parm_const_string(SNUM(handle->conn), "afsacl", "space", "%");
 
        if (spc != NULL)
                space_replacement = spc[0];
-       
-       return SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       return 0;
 }
 
 static struct vfs_fn_pointers vfs_afsacl_fns = {