lsar_lookup.c revision dc20a3024900c47dd2ee44b9707e6df38f7d62a5
/*
* 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"
/*
* Local Security Authority RPC (LSARPC) library interface functions for
* query, lookup and enumeration calls.
*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <smbsrv/ntaccess.h>
#include <smbsrv/ntstatus.h>
#include <smbsrv/ntlocale.h>
/*
* The maximum number of bytes we are prepared to deal with in a
* response.
*/
#define MLSVC_MAX_RESPONSE_LEN 1024
/*
* This structure is used when lookuping up names. We only lookup one
* name at a time but the structure will allow for more.
*/
typedef struct lookup_name_table {
/*
* lsar_query_security_desc
*
* Don't use this call yet. It is just a place holder for now.
*/
int
{
struct mslsa_QuerySecurityObject arg;
struct mlsvc_rpc_context *context;
int rc;
int opnum;
(void) mlsvc_rpc_init(&heap);
return (rc);
}
/*
* lsar_query_info_policy
*
* The general purpose of this function is to allow various pieces of
* information to be queried on the domain controller. The only
* information queries supported are MSLSA_POLICY_PRIMARY_DOMAIN_INFO
* and MSLSA_POLICY_ACCOUNT_DOMAIN_INFO.
*
* On success, the return code will be 0 and the user_info structure
* will be set up. The sid_name_use field will be set to SidTypeDomain
* indicating that the domain name and domain sid fields are vaild. If
* the infoClass returned from the server is not one of the supported
* values, the sid_name_use willbe set to SidTypeUnknown. If the RPC
* fails, a negative error code will be returned, in which case the
* user_info will not have been updated.
*/
{
struct mslsa_QueryInfoPolicy arg;
struct mlsvc_rpc_context *context;
struct mslsa_PrimaryDomainInfo *pd_info;
struct mslsa_AccountDomainInfo *ad_info;
int opnum;
if (lsa_handle == 0)
return (NT_STATUS_INVALID_PARAMETER);
(void) mlsvc_rpc_init(&heap);
} else {
switch (infoClass) {
(void) nt_domain_add(nt_new_dp);
break;
(void) nt_domain_add(nt_new_dp);
break;
default:
break;
}
}
return (status);
}
/*
* lsar_lookup_names
*
* Lookup a name and obtain the domain and user rid. The RPC call will
* actually support lookup of multiple names but we probably don't
* need to do that. On the final system the lookup level should be
* level 2 but for now we want to restrict it to level 1 so that we
* don't crash the PDC when we get things wrong.
*
* If the lookup fails, the status will typically be
* NT_STATUS_NONE_MAPPED.
*/
{
struct mlsvc_rpc_context *context;
int opnum;
int index;
struct mslsa_LookupNames arg;
struct mslsa_rid_entry *rid_entry;
struct mslsa_domain_entry *domain_entry;
char *p;
return (NT_STATUS_INVALID_PARAMETER);
/*
* Windows NT expects the name length to exclude the terminating
* wchar null but doesn't care whether the allosize includes or
* excludes the null char. Windows 2000 insists that both the
* length and the allosize include the wchar null.
*
* Note: NT returns an error if the mapped_count is non-zero
* when the RPC is called.
*/
/*
* Windows 2000 doesn't like an LSA lookup for
* DOMAIN\Administrator.
*/
++p;
if (strcasecmp(p, "administrator") == 0)
name = p;
}
} else {
}
(void) mlsvc_rpc_init(&heap);
} else if (arg.mapped_count == 0) {
} else {
user_info->domain_sid = 0;
user_info->domain_name = 0;
} else {
(const char *)
}
}
return (status);
}
/*
* lsar_lookup_sids
*
* Lookup a sid and obtain the domain sid and user name. The RPC call
* will actually support lookup of multiple sids but we probably don't
* need to do that. On the final system the lookup level should be
* level 2 but for now we want to restrict it to level 1 so that we
* don't crash the PDC when we get things wrong.
*/
{
struct mslsa_LookupSids arg;
struct mslsa_lup_sid_entry sid_entry;
struct mslsa_name_entry *name_entry;
struct mslsa_domain_entry *domain_entry;
struct mlsvc_rpc_context *context;
int opnum;
int index;
return (NT_STATUS_INVALID_PARAMETER);
(void) mlsvc_rpc_init(&heap);
} else if (arg.mapped_count == 0) {
} else {
}
user_info->domain_sid = 0;
user_info->domain_name = 0;
} else {
(const char *)
}
}
return (status);
}
/*
* lsar_enum_accounts
*
* Enumerate the list of accounts (i.e. SIDs). Use the handle returned
* from lsa_open_policy2. The enum_context is used to support multiple
* calls to this enumeration function. It should be set to 0 on the
* first call. It will be updated by the domain controller and should
* simply be passed unchanged to subsequent calls until there are no
* more accounts. A warning status of 0x1A indicates that no more data
* is available. The list of accounts will be returned in accounts.
* This list is dynamically allocated using malloc, it should be freed
* by the caller when it is no longer required.
*/
int
struct mslsa_EnumAccountBuf *accounts)
{
struct mslsa_EnumerateAccounts arg;
struct mslsa_AccountInfo *info;
struct mlsvc_rpc_context *context;
int opnum;
int rc;
DWORD i;
int nbytes;
return (-1);
accounts->entries_read = 0;
(void) mlsvc_rpc_init(&heap);
if (rc == 0) {
} else {
rc = -1;
}
nbytes);
return (-1);
}
for (i = 0; i < n_entries; ++i)
}
}
return (rc);
}
/*
* lsar_enum_trusted_domains
*
* Enumerate the list of trusted domains. Use the handle returned from
* lsa_open_policy2. The enum_context is used to support multiple calls
* to this enumeration function. It should be set to 0 on the first
* call. It will be updated by the domain controller and should simply
* be passed unchanged to subsequent calls until there are no more
* domains.
*
* The trusted domains aren't actually returned here. They are added
* to the NT domain database. After all of the trusted domains have
* been discovered, the database can be interrogated to find all of
* the trusted domains.
*/
{
struct mslsa_EnumTrustedDomain arg;
struct mlsvc_rpc_context *context;
int opnum;
DWORD i;
(void) mlsvc_rpc_init(&heap);
/*
* status 0x8000001A means NO_MORE_DATA,
* which is not an error.
*/
if (status != MLSVC_NO_MORE_DATA)
status = 0;
} else {
for (i = 0; i < n_entries; ++i) {
(void) nt_domain_add(nt_new_dp);
}
status = 0;
}
return (status);
}
/*
* lsar_enum_privs_account
*
* Privileges enum? Need an account handle.
*/
/*ARGSUSED*/
int
{
struct mslsa_EnumPrivsAccount arg;
struct mlsvc_rpc_context *context;
int opnum;
int rc;
sizeof (mslsa_handle_t));
(void) mlsvc_rpc_init(&heap);
rc = -1;
}
return (rc);
}
/*
* lsar_lookup_priv_value
*
* Map a privilege name to a local unique id (LUID). Privilege names
* are consistent across the network. LUIDs are machine specific.
* This function provides the means to map a privilege name to the
* LUID used by a remote server to represent it. The handle here is
* a policy handle.
*/
int
{
struct mslsa_LookupPrivValue arg;
struct mlsvc_rpc_context *context;
int opnum;
int rc;
return (-1);
length += sizeof (mts_wchar_t);
(void) mlsvc_rpc_init(&heap);
if (rc == 0) {
rc = -1;
else
}
return (rc);
}
/*
* lsar_lookup_priv_name
*
* Map a local unique id (LUID) to a privilege name. Privilege names
* are consistent across the network. LUIDs are machine specific.
* This function the means to map the LUID used by a remote server to
* the appropriate privilege name. The handle here is a policy handle.
*/
int
{
struct mslsa_LookupPrivName arg;
struct mlsvc_rpc_context *context;
int opnum;
int rc;
return (-1);
(void) mlsvc_rpc_init(&heap);
if (rc == 0) {
rc = -1;
else
namelen);
}
return (rc);
}
/*
* lsar_lookup_priv_display_name
*
* Map a privilege name to a privilege display name. The input handle
* should be an LSA policy handle and the name would normally be one
* of the privileges defined in smb_privilege.h
*
* There's something peculiar about the return status from NT servers,
* it's not always present. So for now, I'm ignoring the status in the
* RPC response.
*
* Returns NT status codes.
*/
char *display_name, int display_len)
{
struct mslsa_LookupPrivDisplayName arg;
struct mlsvc_rpc_context *context;
int opnum;
return (NT_STATUS_INVALID_PARAMETER);
(void) mlsvc_rpc_init(&heap);
#if 0
#endif
else {
(void) strlcpy(display_name,
}
return (status);
}
/*
* lsar_lookup_sids2
*/
{
struct lsar_lookup_sids2 arg;
struct lsar_name_entry2 *name_entry;
struct mslsa_lup_sid_entry sid_entry;
struct mslsa_domain_entry *domain_entry;
struct mlsvc_rpc_context *context;
int opnum;
int index;
return (NT_STATUS_INVALID_PARAMETER);
return (NT_STATUS_REVISION_MISMATCH);
(void) mlsvc_rpc_init(&heap);
} else if (arg.mapped_count == 0) {
} else {
}
user_info->domain_sid = 0;
user_info->domain_name = 0;
} else {
}
}
return (status);
}
/*
* lsar_lookup_names2
*
* Windows NT expects the name length to exclude the terminating
* wchar null but Windows 2000 insists that both the length and
* the allosize include the wchar null. Windows NT doesn't care
* whether or not the allosize includes or excludes the null char.
*
* As a precaution, I set the lookup level to 1 on Windows 2000
* until I can do some more testing.
*
* Note that NT returns an error if the mapped_count is non-zero
* when the RPC is called.
*
* It should be okay to lookup DOMAIN\Administrator in this function.
*/
{
struct mlsvc_rpc_context *context;
int opnum;
int index;
struct lsar_LookupNames2 arg;
struct lsar_rid_entry2 *rid_entry;
struct mslsa_domain_entry *domain_entry;
return (NT_STATUS_INVALID_PARAMETER);
return (NT_STATUS_REVISION_MISMATCH);
(void) mlsvc_rpc_init(&heap);
} else if (arg.mapped_count == 0) {
} else {
user_info->domain_sid = 0;
user_info->domain_name = 0;
} else {
}
}
return (status);
}
void
{
char *s = "unknown";
if (status == 0)
s = "success";
else if (NT_SC_IS_ERROR(status))
s = "error";
else if (NT_SC_IS_WARNING(status))
s = "warning";
else if (NT_SC_IS_INFO(status))
s = "info";
smb_tracef("mlrpc[0x%02x]: %s: %s (0x%08x)",
}