613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Copyright (c) 2000-2001 Boris Popov
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * All rights reserved.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Redistribution and use in source and binary forms, with or without
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * modification, are permitted provided that the following conditions
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * 1. Redistributions of source code must retain the above copyright
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * notice, this list of conditions and the following disclaimer.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * 2. Redistributions in binary form must reproduce the above copyright
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * notice, this list of conditions and the following disclaimer in the
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * documentation and/or other materials provided with the distribution.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * 3. All advertising materials mentioning features or use of this software
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * must display the following acknowledgement:
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * This product includes software developed by Boris Popov.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * 4. Neither the name of the author nor the names of any co-contributors
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * may be used to endorse or promote products derived from this software
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * without specific prior written permission.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * SUCH DAMAGE.
15359501f7d4b9abebd7b7bf6efd5982a8e7eb27Gordon Ross * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
85e6b6747d07050e01ec91acef2453655821f9abGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * SMB Session Setup, and related.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Session Setup: NULL session (anonymous)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Should not get here with... */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross err = smb__ssnsetup(ctx, NULL, NULL, &ntstatus, &action);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross DPRINT("status 0x%x action 0x%x", ntstatus, (int)action);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * SMB Session Setup, using NTLMv1 (and maybe LMv1)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Should not get here with... */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Make mb_done calls at out safe. */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Put the LM,NTLM responses (as mbdata). */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross err = ntlm_put_v1_responses(ctx, &lm_mbc, &nt_mbc);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross (ctx->ct_hflags2 & SMB_FLAGS2_SECURITY_SIGNATURE) == 0) {
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* OK, start signing! */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross ctx->ct_hflags2 |= SMB_FLAGS2_SECURITY_SIGNATURE;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross err = smb__ssnsetup(ctx, &lm_mbc, &nt_mbc, &ntstatus, &action);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross DPRINT("status 0x%x action 0x%x", ntstatus, (int)action);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * SMB Session Setup, using NTLMv2 (and LMv2)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Should not get here with... */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Make mb_done calls at out safe. */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Build the NTLMv2 "target info" blob (as mbdata) */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross err = ntlm_build_target_info(ctx, NULL, &ti_mbc);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Put the LMv2, NTLMv2 responses (as mbdata). */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross err = ntlm_put_v2_responses(ctx, &ti_mbc, &lm_mbc, &nt_mbc);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross (ctx->ct_hflags2 & SMB_FLAGS2_SECURITY_SIGNATURE) == 0) {
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* OK, start signing! */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross ctx->ct_hflags2 |= SMB_FLAGS2_SECURITY_SIGNATURE;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross err = smb__ssnsetup(ctx, &lm_mbc, &nt_mbc, &ntstatus, &action);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross DPRINT("status 0x%x action 0x%x", ntstatus, (int)action);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rosssmb_ssnsetup_spnego(struct smb_ctx *ctx, struct mbdata *hint_mb)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* NULL input indicates first call. */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross break; /* normal loop termination */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (ntstatus != NT_STATUS_MORE_PROCESSING_REQUIRED) {
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* middle calls get both in, out */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross err = ssp_ctx_next_token(ctx, &recv_mb, &send_mb);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross DPRINT("status 0x%x action 0x%x", ntstatus, (int)action);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* NULL output indicates last call. */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Session Setup function used for all the forms we support.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * To allow this sharing, the crypto stuff is computed by
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * callers and passed in as mbdata chains. Also, the args
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * have different meanings for extended security vs. old.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Some may be used as either IN or OUT parameters.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * For NTLM (v1, v2), all parameters are inputs
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * mbc1: [in] LM password hash
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * mbc2: [in] NT password hash
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * For Extended security (spnego)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * mbc1: [in] outgoing blob data
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * mbc2: [out] received blob data
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * For both forms, these are optional:
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * statusp: [out] NT status
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * actionp: [out] Logon Action (i.e. SMB_ACT_GUEST)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross err = smb_rq_init(ctx, SMB_COM_SESSION_SETUP_ANDX, &rqp);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Build the SMB request.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_uint16le(mbp, 0xff); /* 0: AndXCommand */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_uint16le(mbp, sv->sv_maxtx); /* 2: MaxBufferSize */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_uint16le(mbp, sv->sv_maxmux); /* 3: MaxMpxCount */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_uint32le(mbp, sv->sv_skey); /* 5,6: Session Key */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_uint16le(mbp, len1); /* 7: Sec. Blob Len */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_uint32le(mbp, caps); /* 10,11: Capabilities */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* mbc2 is required below */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_uint16le(mbp, len1); /* 7: LM pass. len */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_uint16le(mbp, len2); /* 8: NT pass. len */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_uint32le(mbp, caps); /* 11,12: Capabilities */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_mbuf(mbp, mbc1->mb_top); /* LM password */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross mb_put_mbuf(mbp, mbc2->mb_top); /* NT password */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * If we have a real error, the response probably has
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * no more data, so don't try to parse any more.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Note: err=0, means rq_status is valid.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright rqp->rq_status != NT_STATUS_MORE_PROCESSING_REQUIRED) {
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Parse the reply
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross err = EBADRPC; /* for any problems in this section */
02d09e03eb27f3a2dc299de704e45dae5173f43fGordon Ross md_get_uint16le(mbp, &sblen); /* sec. blob len */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Get the security blob, after
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * sanity-checking the length.
02d09e03eb27f3a2dc299de704e45dae5173f43fGordon Ross err = md_get_uint16le(mbp, &bc); /* byte count */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Native OS, LANMGR, & Domain follow here.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Parse these strings and store for later.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * If unicode, they should be aligned.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Note that with Extended security, we may use
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * multiple calls to this function. Only parse
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * these strings on the last one (status == 0).
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Ditto for the CAP_LARGE work-around.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Ignore any parsing errors for these strings. */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross DPRINT("server OS: %s", err ? "?" : ctx->ct_srv_OS);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross DPRINT("server LM: %s", err ? "?" : ctx->ct_srv_LM);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * There's sometimes a server domain folloing
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * at this point, but we don't need it.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* Success! (See Ignore any ... above) */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Windows systems don't suport CAP_LARGE_READX,WRITEX
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * when signing is enabled, so adjust sv_caps.