/*
* Copyright (c) 2000-2001 Boris Popov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Boris Popov.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
/*
* SMB Session Setup, and related.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <netdb.h>
#include <libintl.h>
#include <xti.h>
#include <assert.h>
#include <sys/byteorder.h>
#include "private.h"
#include "charsets.h"
#include "ntlm.h"
#include "smb_crypt.h"
static int
/*
* Session Setup: NULL session (anonymous)
*/
int
{
int err;
/* Should not get here with... */
goto out;
}
if (err)
goto out;
if (ntstatus != 0)
out:
return (err);
}
/*
* SMB Session Setup, using NTLMv1 (and maybe LMv1)
*/
int
{
int err;
/* Should not get here with... */
goto out;
}
/* Make mb_done calls at out safe. */
/* Put the LM,NTLM responses (as mbdata). */
if (err)
goto out;
if (err)
goto out;
/* OK, start signing! */
}
if (err)
goto out;
if (ntstatus != 0)
out:
return (err);
}
/*
* SMB Session Setup, using NTLMv2 (and LMv2)
*/
int
{
int err;
/* Should not get here with... */
goto out;
}
/* Make mb_done calls at out safe. */
/* Build the NTLMv2 "target info" blob (as mbdata) */
if (err)
goto out;
/* Put the LMv2, NTLMv2 responses (as mbdata). */
if (err)
goto out;
if (err)
goto out;
/* OK, start signing! */
}
if (err)
goto out;
if (ntstatus != 0)
out:
return (err);
}
int
{
int err;
if (err)
goto out;
/* NULL input indicates first call. */
if (err)
goto out;
for (;;) {
if (err)
goto out;
if (ntstatus == 0)
break; /* normal loop termination */
if (ntstatus != NT_STATUS_MORE_PROCESSING_REQUIRED) {
goto out;
}
/* middle calls get both in, out */
if (err)
goto out;
}
/* NULL output indicates last call. */
out:
return (err);
}
/*
* Session Setup function used for all the forms we support.
* To allow this sharing, the crypto stuff is computed by
* callers and passed in as mbdata chains. Also, the args
* have different meanings for extended security vs. old.
* Some may be used as either IN or OUT parameters.
*
* For NTLM (v1, v2), all parameters are inputs
* mbc1: [in] LM password hash
* mbc2: [in] NT password hash
* For Extended security (spnego)
* mbc1: [in] outgoing blob data
* mbc2: [out] received blob data
* For both forms, these are optional:
* statusp: [out] NT status
* actionp: [out] Logon Action (i.e. SMB_ACT_GUEST)
*/
static int
{
struct mbuf *m;
if (err)
goto out;
/*
* Build the SMB request.
*/
if (caps & SMB_CAP_EXT_SECURITY) {
}
/* mbc2 is required below */
goto out;
}
} else {
}
}
}
if (err)
goto out;
if (statusp)
/*
* If we have a real error, the response probably has
* no more data, so don't try to parse any more.
* Note: err=0, means rq_status is valid.
*/
goto out;
}
/*
* Parse the reply
*/
if (err)
goto out;
if (caps & SMB_CAP_EXT_SECURITY) {
if (wc != 4)
goto out;
/*
* Get the security blob, after
* sanity-checking the length.
*/
goto out;
if (err)
goto out;
} else {
if (wc != 3)
goto out;
if (err)
goto out;
}
/*
* Native OS, LANMGR, & Domain follow here.
* Parse these strings and store for later.
* If unicode, they should be aligned.
*
* Note that with Extended security, we may use
* multiple calls to this function. Only parse
* these strings on the last one (status == 0).
* Ditto for the CAP_LARGE work-around.
*/
goto out;
/* Ignore any parsing errors for these strings. */
/*
* There's sometimes a server domain folloing
* at this point, but we don't need it.
*/
/* Success! (See Ignore any ... above) */
err = 0;
/*
* Windows systems don't suport CAP_LARGE_READX,WRITEX
* when signing is enabled, so adjust sv_caps.
*/
DPRINT("Server is Windows");
DPRINT("disable CAP_LARGE_(r/w)");
}
}
out:
if (rqp)
return (err);
}