mlsvc_util.c revision 8d7e41661dc4633488e93b13363137523ce59977
/*
* 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.
*/
/*
* Utility functions to support the RPC interface library.
*/
#include <stdio.h>
#include <stdarg.h>
#include <strings.h>
#include <unistd.h>
#include <netdb.h>
#include <stdlib.h>
#include <smbsrv/libsmbrdr.h>
#include <smbsrv/libsmbns.h>
#include <smbsrv/libmlsvc.h>
#include <lsalib.h>
#include <samlib.h>
#include <smbsrv/netrauth.h>
/* Domain join support (using MS-RPC) */
extern int netr_open(char *, char *, mlsvc_handle_t *);
extern int netr_close(mlsvc_handle_t *);
extern int mlsvc_user_getauth(char *, char *, smb_auth_info_t *);
/*
* Compare the supplied domain name with the local hostname.
* We need to deal with both server names and fully-qualified
* domain names.
*
* Returns:
* 0 The specified domain is not the local domain,
* 1 The Specified domain is the local domain.
* -1 Invalid parameter or unable to get the local
* system information.
*/
int
mlsvc_is_local_domain(const char *domain)
{
char hostname[MAXHOSTNAMELEN];
int rc;
if (smb_config_get_secmode() == SMB_SECMODE_WORKGRP)
return (1);
else {
else
}
if (rc != 0)
return (-1);
return (1);
return (0);
}
/*
* mlsvc_lookup_name
*
* This is just a wrapper for lsa_lookup_name.
*
* The memory for the sid is allocated using malloc so the caller should
* call free when it is no longer required.
*/
{
return (NT_STATUS_NO_MEMORY);
if (status == NT_STATUS_SUCCESS) {
}
return (status);
}
/*
* mlsvc_lookup_sid
*
* This is just a wrapper for lsa_lookup_sid.
*
* The allocated memory for the returned name must be freed by caller upon
* successful return.
*/
{
int namelen;
return (NT_STATUS_NO_MEMORY);
if (status == NT_STATUS_SUCCESS) {
return (NT_STATUS_NO_MEMORY);
}
}
return (status);
}
/*
* mlsvc_alloc_user_info
*
* Allocate a user_info structure and set the contents to zero. A
* pointer to the user_info structure is returned.
*/
mlsvc_alloc_user_info(void)
{
return (NULL);
return (user_info);
}
/*
* mlsvc_free_user_info
*
* Free a user_info structure. This function ensures that the contents
* of the user_info are freed as well as the user_info itself.
*/
void
{
if (user_info) {
}
}
/*
* mlsvc_release_user_info
*
* Release the contents of a user_info structure and zero out the
* elements but do not free the user_info structure itself. This
* function cleans out the structure so that it can be reused without
* worrying about stale contents.
*/
void
{
int i;
return;
if (user_info->n_other_grps) {
for (i = 0; i < user_info->n_other_grps; i++)
}
}
/*
* mlsvc_setadmin_user_info
*
* Determines if the given user is the domain Administrator or a
* member of Domain Admins or Administrators group and set the
* user_info->flags accordingly.
*/
void
{
int rc, i;
return;
return;
else {
}
if (rc == SMB_LGRP_SUCCESS) {
smb_lgrp_free(&grp);
}
}
{
(void) netr_close(&netr_handle);
} else {
}
return (status);
}
/*
* mlsvc_join
*
* Returns NT status codes.
*/
{
int erc;
machine_passwd[0] = '\0';
/*
* Ensure that the domain name is uppercase.
*/
if (erc == AUTH_USER_GRANT) {
if (mlsvc_ntjoin_support == B_FALSE) {
machine_passwd, sizeof (machine_passwd))
else
} else {
!= 0) {
return (status);
}
if (status == NT_STATUS_SUCCESS) {
(void) smb_getnetbiosname(machine_passwd,
sizeof (machine_passwd));
(void) utf8_strlwr(machine_passwd);
}
}
if (status == NT_STATUS_SUCCESS) {
if (erc != 0)
return (NT_STATUS_UNSUCCESSFUL);
}
} else {
}
return (status);
}