/*
* 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.
*/
/*
*/
/*
* SMB Session Setup, and related.
* Copied from the driver: smb_smb.c
*/
#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 <syslog.h>
#include <sys/byteorder.h>
#include "smbfs_lib.h"
#include "smbfs_nb_lib.h"
#include "smbfs_private.h"
#include "smbfs_charsets.h"
#include "smbfs_ntlm.h"
#include "smbfs_crypt.h"
static void smbfs_ssnsetup_lookup_os(char *, size_t);
/*
* 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 we negotiated signing, compute the MAC key
* and start signing messages, but only on the
* first non-null session login.
*/
char *p;
/*
* MAC_key = concat(session_key, nt_response)
*/
ctx->ct_mackeylen = 0;
goto out;
}
ctx->ct_hflags2 |=
}
/* 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 we negotiated signing, compute the MAC key
* and start signing messages, but only on the
* first non-null session login.
*/
char *p;
/*
* MAC_key = concat(session_key, nt_response)
*/
ctx->ct_mackeylen = 0;
goto out;
}
/* OK, start signing! */
ctx->ct_hflags2 |=
}
}
if (err)
goto out;
if (ntstatus != 0)
out:
return (err);
}
/*
* smbfs_ssnsetup_spnego
*
* Negotiate authentication mechanism with the SMB server and process
* SmbSessionSetupAndX request.
*
* SMBFS client uses GSS-API and a security provider glue (roughly modeled
* after Microsoft SSPI) to negotiate authentication mechanism with the SMB
* server.
*
* Solaris has Kerberos and Diffie Hellman authentication mechanisms
* which provide plugins into GSS-API. Solaris does not support
* NTLMSSP authentication plugin into GSS-API. Hence, for
* negotiating NTLMSSP authentication mechanism, SMBFS client will
* continue to use the security provider glue.
*
* If security context cannot be established using GSS-API, then this routine
* will try to establish security context using the security provider glue.
* If the return code from smbfs_gss_init_sec is EBADE, then NTLMSSP
* authentication cannot be attempted with the ctx structure.
*/
int
{
int err;
if (err != 0) {
return (err);
}
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. guest)
*/
int
{
struct mbuf *m;
/*
* Some of the "capability" bits we offer will be copied
* from those offered by the server, with a mask applied.
* This is the mask of capabilies copied from the server.
* Some others get special handling below.
*/
if (err)
goto out;
/*
* Build the SMB request.
*/
if (caps & CAP_EXTENDED_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 & CAP_EXTENDED_SECURITY) {
if (wc != 4)
goto out;
/*
* Get the security blob, after
* sanity-checking the length.
*/
goto out;
if (err)
goto out;
smbfs_mb_initm(mbc2, m);
} 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.
* The server may follow these strings but we don't need it.
*/
err = 0;
DPRINT("Server OS: %s, LM: %s",
}
/*
* Windows systems don't suport CAP_LARGE_READX,WRITEX
* when signing is enabled, so adjust sv_caps.
*/
DPRINT("Windows signing: disable CAP_LARGE_RW");
}
}
out:
if (rqp)
return (err);
}
static void
{
} else {
}
}