netr_logon.c revision 6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2e
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* NETR SamLogon and SamLogoff RPC client functions.
*/
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <time.h>
#include <alloca.h>
#include <unistd.h>
#include <netdb.h>
#include <smbsrv/libsmbrdr.h>
#include <smbsrv/mlsvc_util.h>
#include <smbsrv/netrauth.h>
#include <smbsrv/ntstatus.h>
#include <smbsrv/smb_token.h>
struct netr_authenticator *);
netr_client_t *, smb_userinfo_t *);
static void netr_invalidate_chain(void);
struct netr_logon_info1 *);
netr_logon_id_t *);
/*
* Shared with netr_auth.c
*/
extern netr_info_t netr_global_info;
/*
* netlogon_logon
*
* This is the entry point for authenticating a remote logon. The
* parameters here all refer to the remote user and workstation, i.e.
* the domain is the user's account domain, not our primary domain.
* In order to make it easy to track which domain is being used at
* each stage, and to reduce the number of things being pushed on the
* stack, the client information is bundled up in the clnt structure.
*
* If the user is successfully authenticated, an access token will be
* built and NT_STATUS_SUCCESS will be returned. Otherwise a non-zero
* NT status will be returned, in which case the token contents will
* be invalid.
*/
{
char resource_domain[SMB_PI_MAX_DOMAIN];
int retries = 0;
return (NT_STATUS_CANT_ACCESS_DOMAIN_INFO);
/*
* We had a session to the DC but it's not responding.
* So drop the credential chain.
*/
return (NT_STATUS_CANT_ACCESS_DOMAIN_INFO);
}
do {
if (status != 0)
return (status);
if (status != 0) {
(void) netr_close(&netr_handle);
return (NT_STATUS_LOGON_FAILURE);
}
}
(void) netr_close(&netr_handle);
if (retries >= 3)
return (status);
}
static DWORD
{
int i, nbytes;
return (NT_STATUS_NO_MEMORY);
return (NT_STATUS_NO_MEMORY);
return (NT_STATUS_NO_MEMORY);
if (username)
if (domain)
return (NT_STATUS_NO_MEMORY);
if (nbytes) {
} else {
return (NT_STATUS_NO_MEMORY);
}
}
if (nbytes) {
other_grps[i].attrs =
break;
}
user_info->n_other_grps = i;
} else {
return (NT_STATUS_NO_MEMORY);
}
}
return (NT_STATUS_SUCCESS);
}
/*
* netr_server_samlogon
*
* NetrServerSamLogon RPC: interactive or network. It is assumed that
* we have already authenticated with the PDC. If everything works,
* we build a user info structure and return it, where the caller will
* probably build an access token.
*
* Returns an NT status. There are numerous possibilities here.
* For example:
* NT_STATUS_INVALID_INFO_CLASS
* NT_STATUS_INVALID_PARAMETER
* NT_STATUS_ACCESS_DENIED
* NT_STATUS_PASSWORD_MUST_CHANGE
* NT_STATUS_NO_SUCH_USER
* NT_STATUS_WRONG_PASSWORD
* NT_STATUS_LOGON_FAILURE
* NT_STATUS_ACCOUNT_RESTRICTION
* NT_STATUS_INVALID_LOGON_HOURS
* NT_STATUS_INVALID_WORKSTATION
* NT_STATUS_INTERNAL_ERROR
* NT_STATUS_PASSWORD_EXPIRED
* NT_STATUS_ACCOUNT_DISABLED
*/
{
struct netr_SamLogon arg;
struct netr_authenticator auth;
struct netr_authenticator ret_auth;
struct netr_logon_info1 info1;
struct netr_logon_info2 info2;
struct netr_validation_info3 *info3;
int opnum;
(void) mlsvc_rpc_init(&heap);
/*
* Should we get the server and hostname from netr_info?
*/
if (rc != 0) {
return (NT_STATUS_INTERNAL_ERROR);
}
if (rc != SMBAUTH_SUCCESS) {
return (NT_STATUS_INTERNAL_ERROR);
}
switch (clnt->logon_level) {
case NETR_INTERACTIVE_LOGON:
break;
case NETR_NETWORK_LOGON:
&info2);
break;
default:
return (NT_STATUS_INVALID_PARAMETER);
}
if (rc != 0) {
/*
* We need to validate the chain even though we have
* a non-zero status. If the status is ACCESS_DENIED
* this will trigger a new credential chain. However,
* a valid credential is returned with some status
* codes; for example, WRONG_PASSWORD.
*/
} else {
if (status == NT_STATUS_INSUFFICIENT_LOGON_INFO) {
return (status);
}
}
return (status);
}
/*
* netr_interactive_samlogon
*
* Set things up for an interactive SamLogon. Copy the NT and LM
* passwords to the logon structure and hash them with the session
* key.
*/
static void
struct netr_logon_info1 *info1)
{
}
/*
* netr_network_samlogon
*
* Set things up for a network SamLogon. We provide a copy of the random
* challenge, that we sent to the client, to the domain controller. This
* is the key that the client will have used to encrypt the NT and LM
* passwords. Note that Windows 9x clients may not provide both passwords.
*/
/*ARGSUSED*/
static void
{
8);
} else {
}
} else {
}
}
/*
* netr_setup_authenticator
*
* Set up the request and return authenticators. A new credential is
* generated from the session key, the current client credential and
* the current time, i.e.
*
* NewCredential = Cred(SessionKey, OldCredential, time);
*
* The timestamp, which is used as a random seed, is stored in both
* the request and return authenticators.
*
* If any difficulties occur using the cryptographic framework, the
* function returns SMBAUTH_FAILURE. Otherwise SMBAUTH_SUCCESS is
* returned.
*/
int
{
return (SMBAUTH_FAILURE);
if (ret_auth) {
}
return (SMBAUTH_SUCCESS);
}
/*
* Validate the returned credentials and update the credential chain.
* The server returns an updated client credential rather than a new
* server credential. The server uses (timestamp + 1) when generating
* the credential.
*
* Generate the new seed for the credential chain. The new seed is
* formed by adding (timestamp + 1) to the current client credential.
* The only quirk is the DWORD style addition.
*
* Returns NT_STATUS_INSUFFICIENT_LOGON_INFO if auth->credential is a
* NULL pointer. The Authenticator field of the SamLogon response packet
* sent by the Samba 3 PDC always return NULL pointer if the received
* SamLogon request is not immediately followed by the ServerReqChallenge
* and ServerAuthenticate2 requests.
*
* Returns NT_STATUS_SUCCESS if the server returned a valid credential.
* Otherwise we retirm NT_STATUS_UNSUCCESSFUL.
*/
{
return (NT_STATUS_INTERNAL_ERROR);
if (&auth->credential == 0) {
/*
* If the validation fails, destroy the credential chain.
* This should trigger a new authentication chain.
*/
return (NT_STATUS_INSUFFICIENT_LOGON_INFO);
}
if (result != 0) {
/*
* If the validation fails, destroy the credential chain.
* This should trigger a new authentication chain.
*/
} else {
/*
* Otherwise generate the next step in the chain.
*/
/*LINTED E_BAD_PTR_CAST_ALIGN*/
}
return (result);
}
/*
* netr_invalidate_chain
*
* Mark the credential chain as invalid so that it will be recreated
* on the next attempt.
*/
static void
netr_invalidate_chain(void)
{
}
/*
* netr_setup_identity
*
* Set up the client identity information. All of this information is
* specifically related to the client user and workstation attempting
* to access this system. It may not be in our primary domain.
*
* I don't know what logon_id is, it seems to be a unique identifier.
* Increment it before each use.
*/
static void
{
if (logon_id == 0)
logon_id = 0xDCD0;
++logon_id;
identity->parameter_control = 0;
/*
* Some systems prefix the client workstation name with \\.
* It doesn't seem to make any difference whether it's there
* or not.
*/
}