Lines Matching refs:sr

151 smb2_invalid_cmd(smb_request_t *sr)
155 sr->session->ip_addr_str);
157 sr->smb2_status = NT_STATUS_INVALID_PARAMETER;
176 smb2sr_newrq(smb_request_t *sr)
182 magic = LE_IN32(sr->sr_request_buf);
184 smb_request_free(sr);
197 command = LE_IN16((uint8_t *)sr->sr_request_buf + 12);
199 rc = smb2sr_newrq_cancel(sr);
200 smb_request_free(sr);
208 sr->sr_time_submitted = gethrtime();
209 sr->sr_state = SMB_REQ_STATE_SUBMITTED;
210 smb_srqueue_waitq_enter(sr->session->s_srqueue);
211 (void) taskq_dispatch(sr->sr_server->sv_worker_pool,
212 smb2_tq_work, sr, TQ_SLEEP);
220 smb_request_t *sr;
223 sr = (smb_request_t *)arg;
224 SMB_REQ_VALID(sr);
226 srq = sr->session->s_srqueue;
228 sr->sr_worker = curthread;
229 sr->sr_time_active = gethrtime();
236 smb2sr_work(sr);
260 * sr->reply chain starting at smb2_reply_hdr.
265 smb2sr_work(struct smb_request *sr)
276 session = sr->session;
278 ASSERT(sr->tid_tree == 0);
279 ASSERT(sr->uid_user == 0);
280 ASSERT(sr->fid_ofile == 0);
281 sr->smb_fid = (uint16_t)-1;
282 sr->smb2_status = 0;
285 sr->user_cr = zone_kcred();
287 mutex_enter(&sr->sr_mutex);
288 switch (sr->sr_state) {
291 sr->sr_state = SMB_REQ_STATE_ACTIVE;
297 sr->smb2_status = NT_STATUS_CANCELLED;
300 mutex_exit(&sr->sr_mutex);
319 if (sr->smb2_status != NT_STATUS_CANCELLED &&
320 sr->smb2_status != NT_STATUS_INSUFFICIENT_RESOURCES)
321 sr->smb2_status = 0;
323 sr->smb2_cmd_hdr = sr->command.chain_offset;
324 if ((rc = smb2_decode_header(sr)) != 0) {
335 if ((sr->smb2_hdr_flags & SMB2_FLAGS_SERVER_TO_REDIR) != 0) {
341 related = (sr->smb2_hdr_flags & SMB2_FLAGS_RELATED_OPERATIONS);
349 if (sr->smb2_credit_charge == 0)
350 sr->smb2_credit_charge = 1;
351 sr->smb2_credit_response = sr->smb2_credit_charge;
359 sr->smb2_reply_hdr = sr->reply.chain_offset;
360 if ((rc = smb2_encode_header(sr, B_FALSE)) != 0) {
372 if (sr->smb2_next_command != 0) {
374 msg_len = sr->smb2_next_command;
376 ((sr->smb2_cmd_hdr + msg_len) > sr->command.max_bytes)) {
383 msg_len = sr->command.max_bytes - sr->smb2_cmd_hdr;
394 (void) MBC_SHADOW_CHAIN(&sr->smb_data, &sr->command,
395 sr->smb2_cmd_hdr, msg_len);
404 if (sr->smb2_cmd_code < SMB2_INVALID_CMD)
405 cmd_idx = sr->smb2_cmd_code;
425 if (sr->fid_ofile != NULL) {
426 smb_ofile_request_complete(sr->fid_ofile);
427 smb_ofile_release(sr->fid_ofile);
428 sr->fid_ofile = NULL;
430 if (sr->tid_tree != NULL) {
431 smb_tree_release(sr->tid_tree);
432 sr->tid_tree = NULL;
434 if (sr->uid_user != NULL) {
435 smb_user_release(sr->uid_user);
436 sr->uid_user = NULL;
437 sr->user_cr = zone_kcred();
455 if (sr->uid_user == NULL) {
456 smb2sr_put_error(sr,
460 sr->smb_uid = sr->uid_user->u_uid;
466 ASSERT(sr->uid_user == NULL);
467 sr->uid_user = smb_session_lookup_uid(session,
468 sr->smb_uid);
469 if (sr->uid_user == NULL) {
470 smb2sr_put_error(sr,
474 sr->user_cr = smb_user_getcred(sr->uid_user);
476 ASSERT(sr->uid_user != NULL);
488 if (sr->tid_tree == NULL) {
489 smb2sr_put_error(sr,
493 sr->smb_tid = sr->tid_tree->t_tid;
499 ASSERT(sr->tid_tree == NULL);
500 sr->tid_tree = smb_session_lookup_tree(session,
501 sr->smb_tid);
502 if (sr->tid_tree == NULL) {
503 smb2sr_put_error(sr,
508 ASSERT(sr->tid_tree != NULL);
523 if (sr->uid_user == NULL)
524 sr->smb2_hdr_flags &= ~SMB2_FLAGS_SIGNED;
532 sr->uid_user != NULL &&
533 (sr->uid_user->u_sign_flags & SMB_SIGNING_CHECK) != 0) {
538 if ((sr->smb2_hdr_flags & SMB2_FLAGS_SIGNED) == 0) {
539 smb2sr_put_error(sr, NT_STATUS_ACCESS_DENIED);
542 rc = smb2_sign_check_request(sr);
544 DTRACE_PROBE1(smb2__sign__check, smb_request_t, sr);
545 smb2sr_put_error(sr, NT_STATUS_ACCESS_DENIED);
553 * This leaves sr->smb_data correctly positioned
557 sr->smb_data.chain_offset = sr->smb2_cmd_hdr + SMB2_HDR_SIZE;
589 sr->smb2_credit_response = sr->smb2_credit_request;
590 if (sr->smb2_credit_request < sr->smb2_credit_charge) {
597 d = sr->smb2_credit_charge - sr->smb2_credit_request;
605 sr->smb2_credit_response = sr->smb2_credit_charge;
606 DTRACE_PROBE1(smb2__credit__neg, smb_request_t, sr);
616 sr->smb2_credit_response += 1;
617 DTRACE_PROBE1(smb2__credit__min, smb_request_t, sr);
621 smb_request_t, sr, int, (int)cur,
632 sr->sr_time_start = gethrtime();
634 if (sr->smb2_status == 0) {
636 rc = (*sdd->sdt_function)(sr);
640 MBC_FLUSH(&sr->raw_data);
645 if (sr->smb2_credit_request > sr->smb2_credit_charge) {
652 d = sr->smb2_credit_request - sr->smb2_credit_charge;
662 sr->smb2_credit_response -= d;
663 DTRACE_PROBE1(smb2__credit__max, smb_request_t, sr);
667 smb_request_t, sr, int, (int)cur,
678 if (sr->reply.chain_offset & 7) {
679 int padsz = 8 - (sr->reply.chain_offset & 7);
680 (void) smb_mbc_encodef(&sr->reply, "#.", padsz);
682 ASSERT((sr->reply.chain_offset & 7) == 0);
688 gethrtime() - sr->sr_time_start);
690 (int64_t)(sr->command.chain_offset - sr->smb2_cmd_hdr));
692 (int64_t)(sr->reply.chain_offset - sr->smb2_reply_hdr));
707 sr->smb2_cmd_code, rc);
711 if (sr->smb2_status == 0)
712 sr->smb2_status = NT_STATUS_INTERNAL_ERROR;
726 if (sr->smb2_next_command != 0) {
727 sr->command.chain_offset =
728 sr->smb2_cmd_hdr + sr->smb2_next_command;
729 sr->smb2_next_reply =
730 sr->reply.chain_offset - sr->smb2_reply_hdr;
732 sr->smb2_next_reply = 0;
740 (void) smb2_encode_header(sr, B_TRUE);
742 if (sr->smb2_hdr_flags & SMB2_FLAGS_SIGNED)
743 smb2_sign_reply(sr);
745 if (sr->smb2_next_command != 0)
752 smb2_send_reply(sr);
756 * The async. function "keeps" this sr, changing its state
759 if (sr->sr_async_req != NULL) {
760 smb2sr_do_async(sr);
779 mutex_enter(&sr->sr_mutex);
780 sr->sr_state = SMB_REQ_STATE_COMPLETED;
781 mutex_exit(&sr->sr_mutex);
783 smb_request_free(sr);
794 * of the response. Finally, send the response and free the sr.
797 smb2sr_do_async(smb_request_t *sr)
808 ar = sr->sr_async_req;
809 sr->smb2_cmd_hdr = ar->ar_cmd_hdr;
810 sr->smb2_cmd_code = ar->ar_cmd_code;
811 sr->smb2_hdr_flags = ar->ar_hdr_flags;
812 sr->smb2_async_id = (uintptr_t)ar;
813 sr->smb2_messageid = ar->ar_messageid;
814 sr->smb_pid = ar->ar_pid;
815 sr->smb_tid = ar->ar_tid;
816 sr->smb_uid = ar->ar_uid;
817 sr->smb2_status = 0;
824 sr->smb2_credit_response = 0;
825 sr->smb2_next_reply = 0;
831 (void) MBC_SHADOW_CHAIN(&sr->smb_data, &sr->command,
832 sr->smb2_cmd_hdr + SMB2_HDR_SIZE,
838 MBC_FLUSH(&sr->reply);
839 sr->smb2_reply_hdr = sr->reply.chain_offset;
840 (void) smb2_encode_header(sr, B_FALSE);
842 VERIFY3U(sr->smb2_cmd_code, <, SMB2_INVALID_CMD);
843 sdd = &smb2_disp_table[sr->smb2_cmd_code];
844 sds = sr->session->s_server->sv_disp_stats2;
845 sds = &sds[sr->smb2_cmd_code];
851 sr->uid_user == NULL) {
852 smb2sr_put_error(sr, NT_STATUS_USER_SESSION_DELETED);
856 sr->tid_tree == NULL) {
857 smb2sr_put_error(sr, NT_STATUS_NETWORK_NAME_DELETED);
867 rc = ar->ar_func(sr);
868 if (rc != 0 && sr->smb2_status == 0)
869 sr->smb2_status = NT_STATUS_INTERNAL_ERROR;
875 if (sr->reply.chain_offset & 7) {
876 int padsz = 8 - (sr->reply.chain_offset & 7);
877 (void) smb_mbc_encodef(&sr->reply, "#.", padsz);
879 ASSERT((sr->reply.chain_offset & 7) == 0);
885 (int64_t)(sr->reply.chain_offset - sr->smb2_reply_hdr));
892 (void) smb2_encode_header(sr, B_TRUE);
894 if (sr->smb2_hdr_flags & SMB2_FLAGS_SIGNED)
895 smb2_sign_reply(sr);
897 smb2_send_reply(sr);
902 sr->sr_async_req = NULL;
905 mutex_enter(&sr->sr_mutex);
906 sr->sr_state = SMB_REQ_STATE_COMPLETED;
907 mutex_exit(&sr->sr_mutex);
909 smb_request_free(sr);
944 smb2sr_go_async(smb_request_t *sr,
949 if (sr->smb2_next_command != 0)
952 ASSERT(sr->sr_async_req == NULL);
966 sr->smb2_hdr_flags |= SMB2_FLAGS_ASYNC_COMMAND;
967 sr->smb2_async_id = (uintptr_t)ar;
970 ar->ar_cmd_hdr = sr->smb2_cmd_hdr;
971 ar->ar_cmd_len = sr->smb_data.max_bytes - sr->smb2_cmd_hdr;
973 ar->ar_cmd_code = sr->smb2_cmd_code;
974 ar->ar_hdr_flags = sr->smb2_hdr_flags &
976 ar->ar_messageid = sr->smb2_messageid;
977 ar->ar_pid = sr->smb_pid;
978 ar->ar_tid = sr->smb_tid;
979 ar->ar_uid = sr->smb_uid;
981 sr->sr_async_req = ar;
984 sr->smb2_hdr_flags &= ~SMB2_FLAGS_SIGNED;
990 smb2_decode_header(smb_request_t *sr)
998 &sr->command, "Nwww..wwllqllq16c",
1000 &sr->smb2_credit_charge, /* w */
1001 &sr->smb2_chan_seq, /* w */
1003 &sr->smb2_cmd_code, /* w */
1004 &sr->smb2_credit_request, /* w */
1005 &sr->smb2_hdr_flags, /* l */
1006 &sr->smb2_next_command, /* l */
1007 &sr->smb2_messageid, /* q */
1011 sr->smb2_sig); /* 16c */
1018 sr->smb_uid = (uint16_t)ssnid; /* XXX wide UIDs */
1020 if (sr->smb2_hdr_flags & SMB2_FLAGS_ASYNC_COMMAND) {
1021 sr->smb2_async_id = pid |
1024 sr->smb_pid = pid;
1025 sr->smb_tid = (uint16_t)tid; /* XXX wide TIDs */
1032 smb2_encode_header(smb_request_t *sr, boolean_t overwrite)
1034 uint64_t ssnid = sr->smb_uid;
1039 if (sr->smb2_hdr_flags & SMB2_FLAGS_ASYNC_COMMAND) {
1040 pid_tid_aid = sr->smb2_async_id;
1042 pid_tid_aid = sr->smb_pid |
1043 ((uint64_t)sr->smb_tid) << 32;
1045 reply_hdr_flags = sr->smb2_hdr_flags | SMB2_FLAGS_SERVER_TO_REDIR;
1048 rc = smb_mbc_poke(&sr->reply,
1049 sr->smb2_reply_hdr,
1052 sr->smb2_credit_charge, /* w */
1053 sr->smb2_status, /* l */
1054 sr->smb2_cmd_code, /* w */
1055 sr->smb2_credit_response, /* w */
1057 sr->smb2_next_reply, /* l */
1058 sr->smb2_messageid, /* q */
1061 sr->smb2_sig); /* 16c */
1063 rc = smb_mbc_encodef(&sr->reply,
1066 sr->smb2_credit_charge, /* w */
1067 sr->smb2_status, /* l */
1068 sr->smb2_cmd_code, /* w */
1069 sr->smb2_credit_response, /* w */
1071 sr->smb2_next_reply, /* l */
1072 sr->smb2_messageid, /* q */
1075 sr->smb2_sig); /* 16c */
1082 smb2_send_reply(smb_request_t *sr)
1085 if (smb_session_send(sr->session, 0, &sr->reply) == 0)
1086 sr->reply.chain = 0;
1097 smbsr_status_smb2(smb_request_t *sr, DWORD status)
1101 if (sr->smb2_cmd_code < SMB2__NCMDS)
1102 name = smb2_disp_table[sr->smb2_cmd_code].sdt_name;
1109 smb2sr_put_error_data(sr, status, NULL);
1113 smb2sr_put_errno(struct smb_request *sr, int errnum)
1116 smb2sr_put_error_data(sr, status, NULL);
1120 smb2sr_put_error(smb_request_t *sr, uint32_t status)
1122 smb2sr_put_error_data(sr, status, NULL);
1129 smb2sr_put_error_data(smb_request_t *sr, uint32_t status, mbuf_chain_t *mbc)
1137 sr->smb2_status = status;
1140 sr->reply.chain_offset = sr->smb2_reply_hdr + SMB2_HDR_SIZE;
1148 &sr->reply,
1156 &sr->reply,
1167 * Setup sr->fid_ofile, either inherited from a related command,
1172 smb2sr_lookup_fid(smb_request_t *sr, smb2fid_t *fid)
1174 boolean_t related = sr->smb2_hdr_flags &
1178 if (sr->fid_ofile == NULL)
1180 sr->smb_fid = sr->fid_ofile->f_fid;
1186 * we could simply ASSERT(sr->fid_ofile == NULL) here.
1190 if (sr->fid_ofile == NULL) {
1191 sr->smb_fid = (uint16_t)fid->temporal;
1192 sr->fid_ofile = smb_ofile_lookup_by_fid(sr, sr->smb_fid);
1194 if (sr->fid_ofile == NULL)