lib: Make sid_parse return the parsed length
[samba.git] / source3 / modules / vfs_default.c
index f54f87dc5c93e98ca76e48313f79de20655b4a24..7ce3775e54f0aa7b841a4f6e9a7cd89e398f2b6f 100644 (file)
@@ -686,7 +686,7 @@ static struct tevent_req *vfswrap_pread_send(struct vfs_handle_struct *handle,
        SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
 
        subreq = pthreadpool_tevent_job_send(
-               state, ev, handle->conn->sconn->raw_thread_pool,
+               state, ev, handle->conn->sconn->pool,
                vfs_pread_do, state);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
@@ -742,8 +742,18 @@ static void vfs_pread_done(struct tevent_req *subreq)
        TALLOC_FREE(subreq);
        SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
        talloc_set_destructor(state, NULL);
-       if (tevent_req_error(req, ret)) {
-               return;
+       if (ret != 0) {
+               if (ret != EAGAIN) {
+                       tevent_req_error(req, ret);
+                       return;
+               }
+               /*
+                * If we get EAGAIN from pthreadpool_tevent_job_recv() this
+                * means the lower level pthreadpool failed to create a new
+                * thread. Fallback to sync processing in that case to allow
+                * some progress for the client.
+                */
+               vfs_pread_do(state);
        }
 
        tevent_req_done(req);
@@ -804,7 +814,7 @@ static struct tevent_req *vfswrap_pwrite_send(struct vfs_handle_struct *handle,
        SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
 
        subreq = pthreadpool_tevent_job_send(
-               state, ev, handle->conn->sconn->raw_thread_pool,
+               state, ev, handle->conn->sconn->pool,
                vfs_pwrite_do, state);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
@@ -860,8 +870,18 @@ static void vfs_pwrite_done(struct tevent_req *subreq)
        TALLOC_FREE(subreq);
        SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
        talloc_set_destructor(state, NULL);
-       if (tevent_req_error(req, ret)) {
-               return;
+       if (ret != 0) {
+               if (ret != EAGAIN) {
+                       tevent_req_error(req, ret);
+                       return;
+               }
+               /*
+                * If we get EAGAIN from pthreadpool_tevent_job_recv() this
+                * means the lower level pthreadpool failed to create a new
+                * thread. Fallback to sync processing in that case to allow
+                * some progress for the client.
+                */
+               vfs_pwrite_do(state);
        }
 
        tevent_req_done(req);
@@ -914,8 +934,7 @@ static struct tevent_req *vfswrap_fsync_send(struct vfs_handle_struct *handle,
        SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
 
        subreq = pthreadpool_tevent_job_send(
-               state, ev, handle->conn->sconn->raw_thread_pool,
-               vfs_fsync_do, state);
+               state, ev, handle->conn->sconn->pool, vfs_fsync_do, state);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -969,8 +988,18 @@ static void vfs_fsync_done(struct tevent_req *subreq)
        TALLOC_FREE(subreq);
        SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
        talloc_set_destructor(state, NULL);
-       if (tevent_req_error(req, ret)) {
-               return;
+       if (ret != 0) {
+               if (ret != EAGAIN) {
+                       tevent_req_error(req, ret);
+                       return;
+               }
+               /*
+                * If we get EAGAIN from pthreadpool_tevent_job_recv() this
+                * means the lower level pthreadpool failed to create a new
+                * thread. Fallback to sync processing in that case to allow
+                * some progress for the client.
+                */
+               vfs_fsync_do(state);
        }
 
        tevent_req_done(req);
@@ -996,10 +1025,7 @@ static off_t vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, off_t o
 
        START_PROFILE(syscall_lseek);
 
-       /* Cope with 'stat' file opens. */
-       if (fsp->fh->fd != -1)
-               result = lseek(fsp->fh->fd, offset, whence);
-
+       result = lseek(fsp->fh->fd, offset, whence);
        /*
         * We want to maintain the fiction that we can seek
         * on a fifo for file system purposes. This allows
@@ -1329,6 +1355,7 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                 *
                 * but I have to check that --metze
                 */
+               struct sid_parse_ret ret;
                struct dom_sid sid;
                struct dom_sid_buf buf;
                uid_t uid;
@@ -1347,7 +1374,8 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                /* unknown 4 bytes: this is not the length of the sid :-(  */
                /*unknown = IVAL(pdata,0);*/
 
-               if (!sid_parse(_in_data + 4, sid_len, &sid)) {
+               ret = sid_parse(_in_data + 4, sid_len, &sid);
+               if (ret.len == -1) {
                        return NT_STATUS_INVALID_PARAMETER;
                }
                DEBUGADD(10, ("for SID: %s\n",
@@ -1504,12 +1532,11 @@ static void vfswrap_get_dos_attributes_getxattr_done(struct tevent_req *subreq);
 
 static struct tevent_req *vfswrap_get_dos_attributes_send(
                        TALLOC_CTX *mem_ctx,
-                       const struct smb_vfs_ev_glue *evg,
+                       struct tevent_context *ev,
                        struct vfs_handle_struct *handle,
                        files_struct *dir_fsp,
                        struct smb_filename *smb_fname)
 {
-       struct tevent_context *ev = dir_fsp->conn->sconn->raw_ev_ctx;
        struct tevent_req *req = NULL;
        struct tevent_req *subreq = NULL;
        struct vfswrap_get_dos_attributes_state *state = NULL;
@@ -1846,7 +1873,7 @@ static struct tevent_req *vfswrap_offload_write_send(
                return tevent_req_post(req, ev);
        }
 
-       state->src_ev = src_fsp->conn->user_ev_ctx;
+       state->src_ev = src_fsp->conn->sconn->ev_ctx;
        state->src_fsp = src_fsp;
 
        state->buf = talloc_array(state, uint8_t, num);
@@ -2525,11 +2552,8 @@ static bool vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int op, o
 
        START_PROFILE(syscall_fcntl_lock);
 
-       if (fsp->use_ofd_locks || !lp_parm_bool(SNUM(fsp->conn),
-                                               "smbd",
-                                               "force process locks",
-                                               false)) {
-               op = map_process_lock_to_ofd_lock(op, &fsp->use_ofd_locks);
+       if (fsp->use_ofd_locks) {
+               op = map_process_lock_to_ofd_lock(op);
        }
 
        result =  fcntl_lock(fsp->fh->fd, op, offset, count, type);
@@ -2553,11 +2577,8 @@ static bool vfswrap_getlock(vfs_handle_struct *handle, files_struct *fsp, off_t
 
        START_PROFILE(syscall_fcntl_getlock);
 
-       if (fsp->use_ofd_locks || !lp_parm_bool(SNUM(fsp->conn),
-                                               "smbd",
-                                               "force process locks",
-                                               false)) {
-               op = map_process_lock_to_ofd_lock(op, &fsp->use_ofd_locks);
+       if (fsp->use_ofd_locks) {
+               op = map_process_lock_to_ofd_lock(op);
        }
 
        result = fcntl_getlock(fsp->fh->fd, op, poffset, pcount, ptype, ppid);
@@ -3038,7 +3059,7 @@ static struct tevent_req *vfswrap_getxattrat_send(
        subreq = pthreadpool_tevent_job_send(
                        state,
                        ev,
-                       dir_fsp->conn->sconn->raw_thread_pool,
+                       dir_fsp->conn->sconn->pool,
                        vfswrap_getxattrat_do_async,
                        state);
        if (tevent_req_nomem(subreq, req)) {
@@ -3149,12 +3170,8 @@ static void vfswrap_getxattrat_done(struct tevent_req *subreq)
        /*
         * Make sure we run as the user again
         */
-       ok = change_to_user(state->dir_fsp->conn,
-                           state->dir_fsp->vuid);
-       if (!ok) {
-               smb_panic("Can't change to user");
-               return;
-       }
+       ok = change_to_user_by_fsp(state->dir_fsp);
+       SMB_ASSERT(ok);
 
        ret = pthreadpool_tevent_job_recv(subreq);
        TALLOC_FREE(subreq);