/* pull a string in a uint16_t ofs/ uint16_t length/blob format UTF-16 without termination */ NTSTATUS smb2_pull_o16s16_string(struct smb2_request_buffer *buf, TALLOC_CTX *mem_ctx, uint8_t *ptr, const char **str) { DATA_BLOB blob; NTSTATUS status; void *vstr; size_t converted_size = 0; bool ret; status = smb2_pull_o16s16_blob(buf, mem_ctx, ptr, &blob); NT_STATUS_NOT_OK_RETURN(status); if (blob.data == NULL) { *str = NULL; return NT_STATUS_OK; } if (blob.length == 0) { char *s; s = talloc_strdup(mem_ctx, ""); NT_STATUS_HAVE_NO_MEMORY(s); *str = s; return NT_STATUS_OK; } ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, blob.data, blob.length, &vstr, &converted_size); data_blob_free(&blob); (*str) = (char *)vstr; if (!ret) { return NT_STATUS_ILLEGAL_CHARACTER; } return NT_STATUS_OK; }
/** recv a session setup reply */ NTSTATUS smb2_session_setup_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx, struct smb2_session_setup *io) { NTSTATUS status; if (!smb2_request_receive(req) || (smb2_request_is_error(req) && !NT_STATUS_EQUAL(req->status, NT_STATUS_MORE_PROCESSING_REQUIRED))) { return smb2_request_destroy(req); } SMB2_CHECK_PACKET_RECV(req, 0x08, true); io->out.session_flags = SVAL(req->in.body, 0x02); io->out.uid = BVAL(req->in.hdr, SMB2_HDR_SESSION_ID); status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x04, &io->out.secblob); if (!NT_STATUS_IS_OK(status)) { smb2_request_destroy(req); return status; } return smb2_request_destroy(req); }