/*
* 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 2015 Nexenta Systems, Inc. All rights reserved.
*/
/*
* This module provides the high level interface to the SAM RPC
* functions.
*/
#include <sys/isa_defs.h>
#include <sys/byteorder.h>
#include <alloca.h>
#include <smbsrv/libmlsvc.h>
#include <smbsrv/ntaccess.h>
#include <lsalib.h>
#include <samlib.h>
#ifdef _LITTLE_ENDIAN
/* little-endian values on little-endian */
#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
/* little-endian values on big-endian (swap) */
#endif /* (BYTE_ORDER == LITTLE_ENDIAN) */
/*
* Valid values for the OEM OWF password encryption.
*/
static void samr_fill_userpw(struct samr_user_password *, const char *);
static void samr_make_encrypted_password(
struct samr_encr_passwd *epw,
char *new_pw_clear,
/*
* Todo: Implement "unjoin" domain, which would use the
* sam_remove_trust_account code below.
*/
/*
* sam_remove_trust_account
*
* Attempt to remove the workstation trust account for this system.
* Administrator access is required to perform this operation.
*
* Returns NT status codes.
*/
{
return (NT_STATUS_INTERNAL_ERROR);
}
/*
* sam_delete_account
*
* Attempt to remove an account from the SAM database on the specified
* server.
*
* Returns NT status codes.
*/
{
int rc;
&samr_handle);
if (rc != 0)
return (NT_STATUS_CANT_ACCESS_DOMAIN_INFO);
goto out_samr_hdl;
}
if (status != NT_STATUS_SUCCESS)
goto out_sid_ptr;
if (status != NT_STATUS_SUCCESS)
goto out_dom_hdl;
if (status != NT_STATUS_SUCCESS)
goto out_dom_hdl;
(void) samr_close_handle(&user_handle);
(void) samr_close_handle(&domain_handle);
(void) samr_close_handle(&samr_handle);
return (status);
}
/*
* sam_lookup_name
*
* Lookup an account name in the SAM database on the specified domain
* controller. Provides the account RID on success.
*
* Returns NT status codes.
*/
{
int rc;
*rid_ret = 0;
&samr_handle);
if (rc != 0)
return (NT_STATUS_OPEN_FAILED);
if (domain_sid == NULL) {
(void) samr_close_handle(&samr_handle);
return (NT_STATUS_NO_SUCH_DOMAIN);
}
if (status == NT_STATUS_SUCCESS) {
account_name, &ainfo);
if (status == NT_STATUS_SUCCESS)
(void) samr_close_handle(&domain_handle);
}
(void) samr_close_handle(&samr_handle);
return (status);
}
/*
* sam_get_local_domains
*
* Query a remote server to get the list of local domains that it
* supports.
*
* Returns NT status codes.
*/
{
int rc;
&samr_handle);
if (rc != 0)
return (NT_STATUS_OPEN_FAILED);
(void) samr_close_handle(&samr_handle);
return (status);
}
/*
* Set the account control flags on some account for which we
* have already opened a SAM handle with appropriate rights,
* passed in here as sam_handle, along with the new flags.
*/
{
}
/*
* Set the password on some account, for which we have already
* opened a SAM handle with appropriate rights, passed in here
* as sam_handle, along with the new password as cleartext.
*
* This builds a struct SAMPR_USER_INTERNAL5_INFORMATION [MS-SAMR]
* containing the new password, encrypted with our session key.
*/
char *new_pw_clear)
{
return (NT_STATUS_INTERNAL_ERROR);
/* Rather not leave the session key around. */
}
/*
* Change a password like NetUserChangePassword(),
* but where we already know which AD server to use,
* so we don't request the domain name or search for
* an AD server for that domain here.
*/
char *server,
char *account,
char *old_pw_clear,
char *new_pw_clear)
{
/*
* Create an RPC handle to this server, bound to SAMR.
*/
if (status != NT_STATUS_SUCCESS)
return (status);
/*
* Encrypt the new p/w (plus random filler) with the
* old password, and send the old p/w encrypted with
* the new p/w hash to prove we know the old p/w.
* Details: [MS-SAMR 3.1.5.10.3]
*/
/*
* Finally, ready to try the OtW call.
*/
/* Avoid leaving cleartext (or equivalent) around. */
return (status);
}
/*
* Build an encrypted password, as used by samr_set_user_info
* and samr_change_password. Note: This builds the unencrypted
* form in one union arm, and encrypts it in the other union arm.
*/
void
struct samr_encr_passwd *epw,
char *new_pw_clear,
{
union {
struct samr_user_password u;
struct samr_encr_passwd e;
} pwu;
}
/*
* This fills in a samr_user_password (a.k.a. SAMPR_USER_PASSWORD
* in the MS Net API) which has the new password "right justified"
* in the buffer, and any space on the left filled with random junk
* to improve the quality of the encryption that is subsequently
* applied to this buffer before it goes over the wire.
*/
static void
{
/*
* First fill the whole buffer with the random junk.
* (Slightly less random when debugging:)
*/
#ifdef DEBUG
#else
#endif
/*
* Now overwrite the last pwlen characters of
* that buffer with the password, and set the
* length field so the receiving end knows where
* the junk ends and the real password starts.
*/
if (pwlen_wchars > SAMR_USER_PWLEN)
/* Yes, this is in Bytes, not wchars. */
}