📄 vfs_ipc.c
字号:
if (!NT_STATUS_IS_OK(status)) { return status; } wr->writex.out.nwritten = data.length; wr->writex.out.remaining = 0; return NT_STATUS_OK;}/* seek in a file*/static NTSTATUS ipc_seek(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_seek *io){ return NT_STATUS_ACCESS_DENIED;}/* flush a file*/static NTSTATUS ipc_flush(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_flush *io){ return NT_STATUS_ACCESS_DENIED;}/* close a file*/static NTSTATUS ipc_close(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_close *io){ struct ipc_private *private = ntvfs->private_data; struct pipe_state *p; if (io->generic.level != RAW_CLOSE_CLOSE) { return ntvfs_map_close(ntvfs, req, io); } p = pipe_state_find(private, io->close.in.file.ntvfs); if (!p) { return NT_STATUS_INVALID_HANDLE; } talloc_free(p); return NT_STATUS_OK;}/* exit - closing files*/static NTSTATUS ipc_exit(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req){ struct ipc_private *private = ntvfs->private_data; struct pipe_state *p, *next; for (p=private->pipe_list; p; p=next) { next = p->next; if (p->handle->session_info == req->session_info && p->handle->smbpid == req->smbpid) { talloc_free(p); } } return NT_STATUS_OK;}/* logoff - closing files open by the user*/static NTSTATUS ipc_logoff(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req){ struct ipc_private *private = ntvfs->private_data; struct pipe_state *p, *next; for (p=private->pipe_list; p; p=next) { next = p->next; if (p->handle->session_info == req->session_info) { talloc_free(p); } } return NT_STATUS_OK;}/* setup for an async call*/static NTSTATUS ipc_async_setup(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, void *private){ return NT_STATUS_OK;}/* cancel an async call*/static NTSTATUS ipc_cancel(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req){ return NT_STATUS_UNSUCCESSFUL;}/* lock a byte range*/static NTSTATUS ipc_lock(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_lock *lck){ return NT_STATUS_ACCESS_DENIED;}/* set info on a open file*/static NTSTATUS ipc_setfileinfo(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_setfileinfo *info){ return NT_STATUS_ACCESS_DENIED;}/* query info on a open file*/static NTSTATUS ipc_qfileinfo(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_fileinfo *info){ struct ipc_private *private = ntvfs->private_data; struct pipe_state *p = pipe_state_find(private, info->generic.in.file.ntvfs); if (!p) { return NT_STATUS_INVALID_HANDLE; } switch (info->generic.level) { case RAW_FILEINFO_GENERIC: { ZERO_STRUCT(info->generic.out); info->generic.out.attrib = FILE_ATTRIBUTE_NORMAL; info->generic.out.fname.s = strrchr(p->pipe_name, '\\'); info->generic.out.alloc_size = 4096; info->generic.out.nlink = 1; /* What the heck? Match Win2k3: IPC$ pipes are delete pending */ info->generic.out.delete_pending = 1; return NT_STATUS_OK; } case RAW_FILEINFO_ALT_NAME_INFO: case RAW_FILEINFO_ALT_NAME_INFORMATION: case RAW_FILEINFO_STREAM_INFO: case RAW_FILEINFO_STREAM_INFORMATION: case RAW_FILEINFO_COMPRESSION_INFO: case RAW_FILEINFO_COMPRESSION_INFORMATION: case RAW_FILEINFO_NETWORK_OPEN_INFORMATION: case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION: return NT_STATUS_INVALID_PARAMETER; case RAW_FILEINFO_ALL_EAS: return NT_STATUS_ACCESS_DENIED; default: return ntvfs_map_qfileinfo(ntvfs, req, info); } return NT_STATUS_ACCESS_DENIED;}/* return filesystem info*/static NTSTATUS ipc_fsinfo(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_fsinfo *fs){ return NT_STATUS_ACCESS_DENIED;}/* return print queue info*/static NTSTATUS ipc_lpq(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_lpq *lpq){ return NT_STATUS_ACCESS_DENIED;}/* list files in a directory matching a wildcard pattern*/static NTSTATUS ipc_search_first(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_search_first *io, void *search_private, bool (*callback)(void *, const union smb_search_data *)){ return NT_STATUS_ACCESS_DENIED;}/* continue listing files in a directory */static NTSTATUS ipc_search_next(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_search_next *io, void *search_private, bool (*callback)(void *, const union smb_search_data *)){ return NT_STATUS_ACCESS_DENIED;}/* end listing files in a directory */static NTSTATUS ipc_search_close(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_search_close *io){ return NT_STATUS_ACCESS_DENIED;}static NTSTATUS ipc_trans_dcesrv_output(void *private_data, DATA_BLOB *out, size_t *nwritten){ NTSTATUS status = NT_STATUS_OK; DATA_BLOB *blob = private_data; if (out->length > blob->length) { status = STATUS_BUFFER_OVERFLOW; } if (out->length < blob->length) { blob->length = out->length; } memcpy(blob->data, out->data, blob->length); *nwritten = blob->length; return status;}/* SMBtrans - handle a DCERPC command */static NTSTATUS ipc_dcerpc_cmd(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, struct smb_trans2 *trans){ struct pipe_state *p; struct ipc_private *private = ntvfs->private_data; NTSTATUS status; DATA_BLOB fnum_key; uint16_t fnum; /* * the fnum is in setup[1], a 16 bit value * the setup[*] values are already in host byteorder * but ntvfs_handle_search_by_wire_key() expects * network byteorder */ SSVAL(&fnum, 0, trans->in.setup[1]); fnum_key = data_blob_const(&fnum, 2); p = pipe_state_find_key(private, req, &fnum_key); if (!p) { return NT_STATUS_INVALID_HANDLE; } trans->out.data = data_blob_talloc(req, NULL, trans->in.max_data); if (!trans->out.data.data) { return NT_STATUS_NO_MEMORY; } /* pass the data to the dcerpc server. Note that we don't expect this to fail, and things like NDR faults are not reported at this stage. Those sorts of errors happen in the dcesrv_output stage */ status = dcesrv_input(p->dce_conn, &trans->in.data); if (!NT_STATUS_IS_OK(status)) { return status; } /* now ask the dcerpc system for some output. This doesn't yet handle async calls. Again, we only expect NT_STATUS_OK. If the call fails then the error is encoded at the dcerpc level */ status = dcesrv_output(p->dce_conn, &trans->out.data, ipc_trans_dcesrv_output); if (NT_STATUS_IS_ERR(status)) { return status; } trans->out.setup_count = 0; trans->out.setup = NULL; trans->out.params = data_blob(NULL, 0); return status;}/* SMBtrans - set named pipe state */static NTSTATUS ipc_set_nm_pipe_state(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, struct smb_trans2 *trans){ struct ipc_private *private = ntvfs->private_data; struct pipe_state *p; DATA_BLOB fnum_key; /* the fnum is in setup[1] */ fnum_key = data_blob_const(&trans->in.setup[1], sizeof(trans->in.setup[1])); p = pipe_state_find_key(private, req, &fnum_key); if (!p) { return NT_STATUS_INVALID_HANDLE; } if (trans->in.params.length != 2) { return NT_STATUS_INVALID_PARAMETER; } p->ipc_state = SVAL(trans->in.params.data, 0); trans->out.setup_count = 0; trans->out.setup = NULL; trans->out.params = data_blob(NULL, 0); trans->out.data = data_blob(NULL, 0); return NT_STATUS_OK;}/* SMBtrans - used to provide access to SMB pipes */static NTSTATUS ipc_trans(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, struct smb_trans2 *trans){ NTSTATUS status; if (strequal(trans->in.trans_name, "\\PIPE\\LANMAN")) return ipc_rap_call(req, ntvfs->ctx->event_ctx, ntvfs->ctx->lp_ctx, trans); if (trans->in.setup_count != 2) { return NT_STATUS_INVALID_PARAMETER; } switch (trans->in.setup[0]) { case TRANSACT_SETNAMEDPIPEHANDLESTATE: status = ipc_set_nm_pipe_state(ntvfs, req, trans); break; case TRANSACT_DCERPCCMD: status = ipc_dcerpc_cmd(ntvfs, req, trans); break; default: status = NT_STATUS_INVALID_PARAMETER; break; } return status;}static NTSTATUS ipc_ioctl_smb2(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_ioctl *io){ struct pipe_state *p; struct ipc_private *private = ntvfs->private_data; NTSTATUS status; switch (io->smb2.in.function) { case FSCTL_NAMED_PIPE_READ_WRITE: break; default: return NT_STATUS_FS_DRIVER_REQUIRED; } p = pipe_state_find(private, io->smb2.in.file.ntvfs); if (!p) { return NT_STATUS_INVALID_HANDLE; } io->smb2.out.out = data_blob_talloc(req, NULL, io->smb2.in.max_response_size); NT_STATUS_HAVE_NO_MEMORY(io->smb2.out.out.data); /* pass the data to the dcerpc server. Note that we don't expect this to fail, and things like NDR faults are not reported at this stage. Those sorts of errors happen in the dcesrv_output stage */ status = dcesrv_input(p->dce_conn, &io->smb2.in.out); NT_STATUS_NOT_OK_RETURN(status); /* now ask the dcerpc system for some output. This doesn't yet handle async calls. Again, we only expect NT_STATUS_OK. If the call fails then the error is encoded at the dcerpc level */ status = dcesrv_output(p->dce_conn, &io->smb2.out.out, ipc_trans_dcesrv_output); NT_STATUS_IS_ERR_RETURN(status); io->smb2.out._pad = 0; io->smb2.out.function = io->smb2.in.function; io->smb2.out.unknown2 = 0; io->smb2.out.unknown3 = 0; io->smb2.out.in = io->smb2.in.out; return status;}/* ioctl interface*/static NTSTATUS ipc_ioctl(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_ioctl *io){ switch (io->generic.level) { case RAW_IOCTL_SMB2: return ipc_ioctl_smb2(ntvfs, req, io); case RAW_IOCTL_SMB2_NO_HANDLE: return NT_STATUS_FS_DRIVER_REQUIRED; default: return NT_STATUS_ACCESS_DENIED; } return NT_STATUS_ACCESS_DENIED;}/* initialialise the IPC backend, registering ourselves with the ntvfs subsystem */NTSTATUS ntvfs_ipc_init(void){ NTSTATUS ret; struct ntvfs_ops ops; NTVFS_CURRENT_CRITICAL_SIZES(vers); ZERO_STRUCT(ops); /* fill in the name and type */ ops.name = "default"; ops.type = NTVFS_IPC; /* fill in all the operations */ ops.connect = ipc_connect; ops.disconnect = ipc_disconnect; ops.unlink = ipc_unlink; ops.chkpath = ipc_chkpath; ops.qpathinfo = ipc_qpathinfo; ops.setpathinfo = ipc_setpathinfo; ops.open = ipc_open; ops.mkdir = ipc_mkdir; ops.rmdir = ipc_rmdir; ops.rename = ipc_rename; ops.copy = ipc_copy; ops.ioctl = ipc_ioctl; ops.read = ipc_read; ops.write = ipc_write; ops.seek = ipc_seek; ops.flush = ipc_flush; ops.close = ipc_close; ops.exit = ipc_exit; ops.lock = ipc_lock; ops.setfileinfo = ipc_setfileinfo; ops.qfileinfo = ipc_qfileinfo; ops.fsinfo = ipc_fsinfo; ops.lpq = ipc_lpq; ops.search_first = ipc_search_first; ops.search_next = ipc_search_next; ops.search_close = ipc_search_close; ops.trans = ipc_trans; ops.logoff = ipc_logoff; ops.async_setup = ipc_async_setup; ops.cancel = ipc_cancel; /* register ourselves with the NTVFS subsystem. */ ret = ntvfs_register(&ops, &vers); if (!NT_STATUS_IS_OK(ret)) { DEBUG(0,("Failed to register IPC backend!\n")); return ret; } return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -