1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* 27 * Client side for the DSSETUP RPC service. 28 */ 29 30 #include <string.h> 31 #include <strings.h> 32 #include <smbsrv/libsmb.h> 33 #include <smbsrv/libsmbrdr.h> 34 #include <smbsrv/ndl/rpcpdu.ndl> 35 #include <smbsrv/ndl/dssetup.ndl> 36 #include <smbsrv/mlsvc_util.h> 37 38 /* 39 * Open the lsarpc pipe and bind to the dssetup service. 40 */ 41 static int 42 dssetup_open(mlsvc_handle_t *handle, mlrpc_heapref_t *heapref) 43 { 44 smb_ntdomain_t *di; 45 int fid; 46 int rc; 47 48 if ((di = smb_getdomaininfo(0)) == NULL) 49 return (-1); 50 51 if (mlsvc_logon(di->server, di->domain, MLSVC_ANON_USER) != 0) 52 return (-1); 53 54 fid = mlsvc_open_pipe(di->server, di->domain, MLSVC_ANON_USER, 55 "\\lsarpc"); 56 if (fid < 0) 57 return (-1); 58 59 if ((rc = mlsvc_rpc_bind(handle, fid, "DSSETUP")) < 0) { 60 (void) mlsvc_close_pipe(fid); 61 return (rc); 62 } 63 64 rc = mlsvc_rpc_init(heapref); 65 return (rc); 66 } 67 68 /* 69 * Close the dssetup pipe and free the associated context. 70 * This function should only be called if the open was successful. 71 */ 72 static void 73 dssetup_close(mlsvc_handle_t *handle, mlrpc_heapref_t *heapref) 74 { 75 mlsvc_rpc_free(handle->context, heapref); 76 (void) mlsvc_close_pipe(handle->context->fid); 77 free(handle->context); 78 } 79 80 int 81 dssetup_get_domain_info(ds_primary_domain_info_t *ds_info) 82 { 83 dssetup_DsRoleGetPrimaryDomainInfo_t arg; 84 struct dssetup_DsRolePrimaryDomInfo1 *info; 85 mlsvc_handle_t handle; 86 mlrpc_heapref_t heap; 87 int opnum; 88 int rc; 89 90 if (dssetup_open(&handle, &heap) != 0) 91 return (-1); 92 93 opnum = DSSETUP_OPNUM_DsRoleGetPrimaryDomainInfo; 94 bzero(&arg, sizeof (dssetup_DsRoleGetPrimaryDomainInfo_t)); 95 arg.level = DS_ROLE_BASIC_INFORMATION; 96 97 rc = mlsvc_rpc_call(handle.context, opnum, &arg, &heap); 98 if ((rc != 0) || (arg.status != 0) || arg.info == NULL) { 99 dssetup_close(&handle, &heap); 100 return (-1); 101 } 102 103 info = &arg.info->ru.info1; 104 105 if (info->nt_domain == NULL || 106 info->dns_domain == NULL || 107 info->forest == NULL) { 108 dssetup_close(&handle, &heap); 109 return (-1); 110 } 111 112 bcopy(info, ds_info, sizeof (ds_primary_domain_info_t)); 113 ds_info->nt_domain = (uint8_t *)strdup((char *)info->nt_domain); 114 ds_info->dns_domain = (uint8_t *)strdup((char *)info->dns_domain); 115 ds_info->forest = (uint8_t *)strdup((char *)info->forest); 116 117 dssetup_close(&handle, &heap); 118 return (0); 119 } 120