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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 24 */ 25 26 /* 27 * Client side for the DSSETUP RPC service. 28 */ 29 30 #include <string.h> 31 #include <strings.h> 32 #include <smbsrv/wintypes.h> 33 #include <smbsrv/libsmb.h> 34 #include <smbsrv/libsmbrdr.h> 35 #include <smbsrv/ndl/dssetup.ndl> 36 #include <smbsrv/libmlsvc.h> 37 38 int 39 dssetup_get_domain_info(ds_primary_domain_info_t *ds_info) 40 { 41 dssetup_DsRoleGetPrimaryDomainInfo_t arg; 42 struct dssetup_DsRolePrimaryDomInfo1 *info; 43 smb_domainex_t di; 44 mlsvc_handle_t handle; 45 int opnum; 46 int rc; 47 48 if (!smb_domain_getinfo(&di)) 49 return (-1); 50 51 if (ndr_rpc_bind(&handle, di.d_dc, di.d_primary.di_nbname, 52 MLSVC_ANON_USER, "DSSETUP") != 0) 53 return (-1); 54 55 opnum = DSSETUP_OPNUM_DsRoleGetPrimaryDomainInfo; 56 bzero(&arg, sizeof (dssetup_DsRoleGetPrimaryDomainInfo_t)); 57 arg.level = DS_ROLE_BASIC_INFORMATION; 58 59 rc = ndr_rpc_call(&handle, opnum, &arg); 60 if ((rc != 0) || (arg.status != 0) || arg.info == NULL) { 61 ndr_rpc_unbind(&handle); 62 return (-1); 63 } 64 65 info = &arg.info->ru.info1; 66 67 if (info->nt_domain == NULL || 68 info->dns_domain == NULL || 69 info->forest == NULL) { 70 ndr_rpc_unbind(&handle); 71 return (-1); 72 } 73 74 bcopy(info, ds_info, sizeof (ds_primary_domain_info_t)); 75 ds_info->nt_domain = (uint8_t *)strdup((char *)info->nt_domain); 76 ds_info->dns_domain = (uint8_t *)strdup((char *)info->dns_domain); 77 ds_info->forest = (uint8_t *)strdup((char *)info->forest); 78 79 ndr_rpc_unbind(&handle); 80 return (0); 81 } 82 83 /* 84 * Check whether our connection to the DC is working. 85 * Note: Do NOT want to block opening a connection, 86 * as that would interfere with smbd_dc_monitor 87 * getting to smbd_dc_update, smb_locate_dc. 88 */ 89 int 90 dssetup_check_service(void) 91 { 92 char cur_dc[MAXHOSTNAMELEN]; 93 94 bzero(cur_dc, sizeof (cur_dc)); 95 smb_domain_current_dc(cur_dc, sizeof (cur_dc)); 96 97 if (smbrdr_echo(cur_dc) < 0) 98 return (-1); 99 100 return (0); 101 } 102