From: Volker Lendecke Date: Thu, 16 Feb 2023 12:41:44 +0000 (+0100) Subject: libsmb: Add SMB1 posix cli_mknod X-Git-Tag: talloc-2.4.1~342 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca99d6a6ff4b39bfa73e2b2efd1e8140424bb4e8;p=thirdparty%2Fsamba.git libsmb: Add SMB1 posix cli_mknod This is a dead horse, but in the future it will make it easier to test the smb311 unix extension code. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index ecc652c81e6..6acca11211e 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -1178,6 +1178,140 @@ NTSTATUS cli_posix_chown(struct cli_state *cli, return status; } +struct cli_smb1_posix_mknod_state { + uint8_t data[100]; +}; + +static void cli_smb1_posix_mknod_done(struct tevent_req *subreq); + +static struct tevent_req *cli_smb1_posix_mknod_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct cli_state *cli, + const char *fname, + mode_t mode, + dev_t dev) +{ + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_smb1_posix_mknod_state *state = NULL; + mode_t type = mode & S_IFMT; + uint32_t smb_unix_type = 0xFFFFFFFF; + + req = tevent_req_create( + mem_ctx, &state, struct cli_smb1_posix_mknod_state); + if (req == NULL) { + return NULL; + } + /* + * Set all sizes/times/ids to no change. + */ + memset(state->data, 0xff, 56); + + switch (type) { + case S_IFREG: + smb_unix_type = UNIX_TYPE_FILE; + break; + case S_IFDIR: + smb_unix_type = UNIX_TYPE_DIR; + break; + case S_IFLNK: + smb_unix_type = UNIX_TYPE_SYMLINK; + break; + case S_IFCHR: + smb_unix_type = UNIX_TYPE_CHARDEV; + break; + case S_IFBLK: + smb_unix_type = UNIX_TYPE_BLKDEV; + break; + case S_IFIFO: + smb_unix_type = UNIX_TYPE_FIFO; + break; + case S_IFSOCK: + smb_unix_type = UNIX_TYPE_SOCKET; + break; + } + PUSH_LE_U32(state->data, 56, smb_unix_type); + + if ((type == S_IFCHR) || (type == S_IFBLK)) { + PUSH_LE_U64(state->data, 60, unix_dev_major(dev)); + PUSH_LE_U64(state->data, 68, unix_dev_minor(dev)); + } + + PUSH_LE_U32(state->data, 84, unix_perms_to_wire(mode)); + + subreq = cli_setpathinfo_send( + state, + ev, + cli, + SMB_SET_FILE_UNIX_BASIC, + fname, + state->data, + sizeof(state->data)); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_smb1_posix_mknod_done, req); + return req; +} + +static void cli_smb1_posix_mknod_done(struct tevent_req *subreq) +{ + NTSTATUS status = cli_setpathinfo_recv(subreq); + tevent_req_simple_finish_ntstatus(subreq, status); +} + +static NTSTATUS cli_smb1_posix_mknod_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} + +struct cli_mknod_state { + uint8_t dummy; +}; + +static void cli_mknod_done1(struct tevent_req *subreq); + +struct tevent_req *cli_mknod_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct cli_state *cli, + const char *fname, + mode_t mode, + dev_t dev) +{ + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_mknod_state *state = NULL; + + req = tevent_req_create(mem_ctx, &state, struct cli_mknod_state); + if (req == NULL) { + return NULL; + } + + if (cli->requested_posix_capabilities != 0) { + subreq = cli_smb1_posix_mknod_send( + state, ev, cli, fname, mode, dev); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_mknod_done1, req); + return req; + } + + tevent_req_nterror(req, NT_STATUS_NOT_IMPLEMENTED); + return tevent_req_post(req, ev); +} + +static void cli_mknod_done1(struct tevent_req *subreq) +{ + NTSTATUS status = cli_smb1_posix_mknod_recv(subreq); + tevent_req_simple_finish_ntstatus(subreq, status); +} + +NTSTATUS cli_mknod_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} + /**************************************************************************** Rename a file. ****************************************************************************/ diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index 3bac88c2ee4..4905702c0dc 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -327,6 +327,14 @@ NTSTATUS cli_posix_chown(struct cli_state *cli, const char *fname, uid_t uid, gid_t gid); +struct tevent_req *cli_mknod_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct cli_state *cli, + const char *fname, + mode_t mode, + dev_t dev); +NTSTATUS cli_mknod_recv(struct tevent_req *req); struct tevent_req *cli_rename_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct cli_state *cli,