s4:kdc: Implement KDC plugin hardware authentication policy
[samba.git] / source3 / modules / vfs_solarisacl.c
index 9b3c4f60a56858dba0fcf0481020a7786ffde75b..d31bda502333cdcfa6320aa9af383a7b0fc7414d 100644 (file)
@@ -62,13 +62,15 @@ static bool solaris_acl_check(SOLARIS_ACL_T solaris_acl, int count);
 
 /* public functions - the api */
 
-SMB_ACL_T solarisacl_sys_acl_get_file(vfs_handle_struct *handle,
-                                     const char *path_p,
-                                     SMB_ACL_TYPE_T type, TALLOC_CTX *mem_ctx)
+static SMB_ACL_T solarisacl_sys_acl_get_file(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               SMB_ACL_TYPE_T type,
+                               TALLOC_CTX *mem_ctx)
 {
        SMB_ACL_T result = NULL;
        int count;
        SOLARIS_ACL_T solaris_acl = NULL;
+       const char *path_p = smb_fname->base_name;
        
        DEBUG(10, ("solarisacl_sys_acl_get_file called for file '%s'.\n", 
                   path_p));
@@ -103,7 +105,9 @@ SMB_ACL_T solarisacl_sys_acl_get_file(vfs_handle_struct *handle,
  * get the access ACL of a file referred to by a fd
  */
 SMB_ACL_T solarisacl_sys_acl_get_fd(vfs_handle_struct *handle,
-                                   files_struct *fsp, TALLOC_CTX *mem_ctx)
+                                   files_struct *fsp,
+                                   SMB_ACL_TYPE_T type,
+                                   TALLOC_CTX *mem_ctx)
 {
        SMB_ACL_T result = NULL;
        int count;
@@ -111,7 +115,13 @@ SMB_ACL_T solarisacl_sys_acl_get_fd(vfs_handle_struct *handle,
 
        DEBUG(10, ("entering solarisacl_sys_acl_get_fd.\n"));
 
-       if (!solaris_acl_get_fd(fsp->fh->fd, &solaris_acl, &count)) {
+       if (!solaris_acl_get_fd(fsp_get_io_fd(fsp), &solaris_acl, &count)) {
+               goto done;
+       }
+
+       if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
+               DEBUG(10, ("invalid SMB_ACL_TYPE given (%d)\n", type));
+               errno = EINVAL;
                goto done;
        }
        /* 
@@ -120,7 +130,7 @@ SMB_ACL_T solarisacl_sys_acl_get_fd(vfs_handle_struct *handle,
         * access acl. So we need to filter this out here.  
         */
        result = solaris_acl_to_smb_acl(solaris_acl, count,
-                                       SMB_ACL_TYPE_ACCESS, mem_ctx);
+                                       type, mem_ctx);
        if (result == NULL) {
                DEBUG(10, ("conversion solaris_acl -> smb_acl failed (%s).\n",
                           strerror(errno)));
@@ -133,99 +143,19 @@ SMB_ACL_T solarisacl_sys_acl_get_fd(vfs_handle_struct *handle,
        return result;
 }
 
-int solarisacl_sys_acl_set_file(vfs_handle_struct *handle,
-                               const char *name,
-                               SMB_ACL_TYPE_T type,
-                               SMB_ACL_T theacl)
-{
-       int ret = -1;
-       struct stat_ex s;
-       SOLARIS_ACL_T solaris_acl = NULL;
-       int count;
-       
-       DEBUG(10, ("solarisacl_sys_acl_set_file called for file '%s'\n",
-                  name));
-
-       if ((type != SMB_ACL_TYPE_ACCESS) && (type != SMB_ACL_TYPE_DEFAULT)) {
-               errno = EINVAL;
-               DEBUG(10, ("invalid smb acl type given (%d).\n", type));
-               goto done;
-       }
-       DEBUGADD(10, ("setting %s acl\n", 
-                     ((type == SMB_ACL_TYPE_ACCESS) ? "access" : "default")));
-
-       if(!smb_acl_to_solaris_acl(theacl, &solaris_acl, &count, type)) {
-               DEBUG(10, ("conversion smb_acl -> solaris_acl failed (%s).\n",
-                          strerror(errno)));
-                goto done;
-       }
-
-       /*
-        * if the file is a directory, there is extra work to do:
-        * since the solaris acl call stores both the access acl and 
-        * the default acl as provided, we have to get the acl part 
-        * that has not been specified in "type" from the file first 
-        * and concatenate it with the acl provided.
-        */
-       if (vfs_stat_smb_fname(handle->conn, name, &s) != 0) {
-               DEBUG(10, ("Error in stat call: %s\n", strerror(errno)));
-               goto done;
-       }
-       if (S_ISDIR(s.st_ex_mode)) {
-               SOLARIS_ACL_T other_acl; 
-               int other_count;
-               SMB_ACL_TYPE_T other_type;
-
-               other_type = (type == SMB_ACL_TYPE_ACCESS) 
-                       ? SMB_ACL_TYPE_DEFAULT
-                       : SMB_ACL_TYPE_ACCESS;
-               DEBUGADD(10, ("getting acl from filesystem\n"));
-               if (!solaris_acl_get_file(name, &other_acl, &other_count)) {
-                       DEBUG(10, ("error getting acl from directory\n"));
-                       goto done;
-               }
-               DEBUG(10, ("adding %s part of fs acl to given acl\n",
-                          ((other_type == SMB_ACL_TYPE_ACCESS) 
-                           ? "access"
-                           : "default")));
-               if (!solaris_add_to_acl(&solaris_acl, &count, other_acl,
-                                       other_count, other_type)) 
-               {
-                       DEBUG(10, ("error adding other acl.\n"));
-                       SAFE_FREE(other_acl);
-                       goto done;
-               }
-               SAFE_FREE(other_acl);
-       }
-       else if (type != SMB_ACL_TYPE_ACCESS) {
-               errno = EINVAL;
-               goto done;
-       }
-
-       if (!solaris_acl_sort(solaris_acl, count)) {
-               DEBUG(10, ("resulting acl is not valid!\n"));
-               goto done;
-       }
-
-       ret = acl(name, SETACL, count, solaris_acl);
-       
- done:
-       DEBUG(10, ("solarisacl_sys_acl_set_file %s.\n",
-                  ((ret != 0) ? "failed" : "succeeded")));
-       SAFE_FREE(solaris_acl);
-       return ret;
-}
-
 /*
  * set the access ACL on the file referred to by a fd 
  */
 int solarisacl_sys_acl_set_fd(vfs_handle_struct *handle,
                              files_struct *fsp,
+                             SMB_ACL_TYPE_T type,
                              SMB_ACL_T theacl)
 {
        SOLARIS_ACL_T solaris_acl = NULL;
-       SOLARIS_ACL_T default_acl = NULL;
-       int count, default_count;
+       int count;
+       SOLARIS_ACL_T other_acl = NULL;
+       int other_count;
+       SMB_ACL_TYPE_T other_type;
        int ret = -1;
 
        DEBUG(10, ("entering solarisacl_sys_acl_set_fd\n"));
@@ -238,19 +168,24 @@ int solarisacl_sys_acl_set_fd(vfs_handle_struct *handle,
         * concatenate it with the access acl provided.
         */
        if (!smb_acl_to_solaris_acl(theacl, &solaris_acl, &count, 
-                                   SMB_ACL_TYPE_ACCESS))
+                                   type))
        {
                DEBUG(10, ("conversion smb_acl -> solaris_acl failed (%s).\n",
                           strerror(errno)));
                goto done;
        }
-       if (!solaris_acl_get_fd(fsp->fh->fd, &default_acl, &default_count)) {
+       if (!solaris_acl_get_fd(fsp_get_io_fd(fsp), &other_acl, &other_count)) {
                DEBUG(10, ("error getting (default) acl from fd\n"));
                goto done;
        }
+
+       other_type = (type == SMB_ACL_TYPE_ACCESS)
+               ? SMB_ACL_TYPE_DEFAULT
+               : SMB_ACL_TYPE_ACCESS;
+
        if (!solaris_add_to_acl(&solaris_acl, &count,
-                               default_acl, default_count,
-                               SMB_ACL_TYPE_DEFAULT))
+                               other_acl, other_count,
+                               other_type))
        {
                DEBUG(10, ("error adding default acl to solaris acl\n"));
                goto done;
@@ -260,7 +195,7 @@ int solarisacl_sys_acl_set_fd(vfs_handle_struct *handle,
                goto done;
        }
 
-       ret = facl(fsp->fh->fd, SETACL, count, solaris_acl);
+       ret = facl(fsp_get_io_fd(fsp), SETACL, count, solaris_acl);
        if (ret != 0) {
                DEBUG(10, ("call of facl failed (%s).\n", strerror(errno)));
        }
@@ -269,65 +204,64 @@ int solarisacl_sys_acl_set_fd(vfs_handle_struct *handle,
        DEBUG(10, ("solarisacl_sys_acl_set_fd %s.\n",
                   ((ret == 0) ? "succeeded" : "failed" )));
        SAFE_FREE(solaris_acl);
-       SAFE_FREE(default_acl);
+       SAFE_FREE(other_acl);
        return ret;
 }
 
 /*
  * delete the default ACL of a directory
  *
- * This is achieved by fetching the access ACL and rewriting it 
- * directly, via the solaris system call: the SETACL call on 
+ * This is achieved by fetching the access ACL and rewriting it
+ * directly, via the solaris system call: the SETACL call on
  * directories writes both the access and the default ACL as provided.
  *
  * XXX: posix acl_delete_def_file returns an error if
  * the file referred to by path is not a directory.
- * this function does not complain but the actions 
+ * this function does not complain but the actions
  * have no effect on a file other than a directory.
  * But sys_acl_delete_default_file is only called in
  * smbd/posixacls.c after having checked that the file
  * is a directory, anyways. So implementing the extra
  * check is considered unnecessary. --- Agreed? XXX
  */
-int solarisacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
-                                      const char *path)
+int solarisacl_sys_acl_delete_def_fd(vfs_handle_struct *handle,
+                               files_struct *fsp)
 {
        SMB_ACL_T smb_acl;
        int ret = -1;
        SOLARIS_ACL_T solaris_acl = NULL;
        int count;
 
-       DEBUG(10, ("entering solarisacl_sys_acl_delete_def_file.\n"));
-       
-       smb_acl = solarisacl_sys_acl_get_file(handle, path, 
+       DBG_DEBUG("entering solarisacl_sys_acl_delete_def_fd.\n");
+
+       smb_acl = solarisacl_sys_acl_get_file(handle, fsp->fsp_name->base_name,
                                              SMB_ACL_TYPE_ACCESS, talloc_tos());
        if (smb_acl == NULL) {
-               DEBUG(10, ("getting file acl failed!\n"));
+               DBG_DEBUG("getting file acl failed!\n");
                goto done;
        }
-       if (!smb_acl_to_solaris_acl(smb_acl, &solaris_acl, &count, 
+       if (!smb_acl_to_solaris_acl(smb_acl, &solaris_acl, &count,
                                    SMB_ACL_TYPE_ACCESS))
        {
-               DEBUG(10, ("conversion smb_acl -> solaris_acl failed.\n"));
+               DBG_DEBUG("conversion smb_acl -> solaris_acl failed.\n");
                goto done;
        }
        if (!solaris_acl_sort(solaris_acl, count)) {
-               DEBUG(10, ("resulting acl is not valid!\n"));
+               DBG_DEBUG("resulting acl is not valid!\n");
                goto done;
        }
-       ret = acl(path, SETACL, count, solaris_acl);
+       ret = acl(fsp->fsp_name->base_name, SETACL, count, solaris_acl);
        if (ret != 0) {
-               DEBUG(10, ("settinge file acl failed!\n"));
+               DBG_DEBG("settinge file acl failed!\n");
        }
-       
+
  done:
-       DEBUG(10, ("solarisacl_sys_acl_delete_def_file %s.\n",
-                  ((ret != 0) ? "failed" : "succeeded" )));
+       DBG_DEBUG("solarisacl_sys_acl_delete_def_fd %s.\n",
+                  ((ret != 0) ? "failed" : "succeeded" ));
        TALLOC_FREE(smb_acl);
        return ret;
 }
 
-
 /* private functions */
 
 static SOLARIS_ACL_T solaris_acl_init(int count)
@@ -749,17 +683,14 @@ static bool solaris_acl_check(SOLARIS_ACL_T solaris_acl, int count)
 #endif
 
 static struct vfs_fn_pointers solarisacl_fns = {
-       .sys_acl_get_file_fn = solarisacl_sys_acl_get_file,
        .sys_acl_get_fd_fn = solarisacl_sys_acl_get_fd,
-       .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
        .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
-       .sys_acl_set_file_fn = solarisacl_sys_acl_set_file,
        .sys_acl_set_fd_fn = solarisacl_sys_acl_set_fd,
-       .sys_acl_delete_def_file_fn = solarisacl_sys_acl_delete_def_file,
+       .sys_acl_delete_def_fd_fn = solarisacl_sys_acl_delete_def_fd,
 };
 
-NTSTATUS vfs_solarisacl_init(void);
-NTSTATUS vfs_solarisacl_init(void)
+static_decl_vfs;
+NTSTATUS vfs_solarisacl_init(TALLOC_CTX *ctx)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "solarisacl",
                                &solarisacl_fns);