xref: /titanic_50/usr/src/lib/smbsrv/libmlsvc/common/dssetup_clnt.c (revision b3700b074e637f8c6991b70754c88a2cfffb246b)
12c1b14e5Sjose borrego /*
22c1b14e5Sjose borrego  * CDDL HEADER START
32c1b14e5Sjose borrego  *
42c1b14e5Sjose borrego  * The contents of this file are subject to the terms of the
52c1b14e5Sjose borrego  * Common Development and Distribution License (the "License").
62c1b14e5Sjose borrego  * You may not use this file except in compliance with the License.
72c1b14e5Sjose borrego  *
82c1b14e5Sjose borrego  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92c1b14e5Sjose borrego  * or http://www.opensolaris.org/os/licensing.
102c1b14e5Sjose borrego  * See the License for the specific language governing permissions
112c1b14e5Sjose borrego  * and limitations under the License.
122c1b14e5Sjose borrego  *
132c1b14e5Sjose borrego  * When distributing Covered Code, include this CDDL HEADER in each
142c1b14e5Sjose borrego  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152c1b14e5Sjose borrego  * If applicable, add the following below this CDDL HEADER, with the
162c1b14e5Sjose borrego  * fields enclosed by brackets "[]" replaced with your own identifying
172c1b14e5Sjose borrego  * information: Portions Copyright [yyyy] [name of copyright owner]
182c1b14e5Sjose borrego  *
192c1b14e5Sjose borrego  * CDDL HEADER END
202c1b14e5Sjose borrego  */
212c1b14e5Sjose borrego /*
22ed9aabc7SGordon Ross  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23*b3700b07SGordon Ross  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
242c1b14e5Sjose borrego  */
252c1b14e5Sjose borrego 
262c1b14e5Sjose borrego /*
272c1b14e5Sjose borrego  * Client side for the DSSETUP RPC service.
282c1b14e5Sjose borrego  */
292c1b14e5Sjose borrego 
302c1b14e5Sjose borrego #include <string.h>
312c1b14e5Sjose borrego #include <strings.h>
328d7e4166Sjose borrego #include <smbsrv/wintypes.h>
332c1b14e5Sjose borrego #include <smbsrv/libsmb.h>
342c1b14e5Sjose borrego #include <smbsrv/ndl/dssetup.ndl>
358d7e4166Sjose borrego #include <smbsrv/libmlsvc.h>
362c1b14e5Sjose borrego 
372c1b14e5Sjose borrego int
dssetup_get_domain_info(ds_primary_domain_info_t * ds_info)382c1b14e5Sjose borrego dssetup_get_domain_info(ds_primary_domain_info_t *ds_info)
392c1b14e5Sjose borrego {
402c1b14e5Sjose borrego 	dssetup_DsRoleGetPrimaryDomainInfo_t arg;
412c1b14e5Sjose borrego 	struct dssetup_DsRolePrimaryDomInfo1 *info;
42a0aa776eSAlan Wright 	smb_domainex_t di;
432c1b14e5Sjose borrego 	mlsvc_handle_t handle;
442c1b14e5Sjose borrego 	int opnum;
452c1b14e5Sjose borrego 	int rc;
462c1b14e5Sjose borrego 
478d7e4166Sjose borrego 	if (!smb_domain_getinfo(&di))
488d7e4166Sjose borrego 		return (-1);
498d7e4166Sjose borrego 
50*b3700b07SGordon Ross 	if (ndr_rpc_bind(&handle, di.d_dci.dc_name, di.d_primary.di_nbname,
518d7e4166Sjose borrego 	    MLSVC_ANON_USER, "DSSETUP") != 0)
522c1b14e5Sjose borrego 		return (-1);
532c1b14e5Sjose borrego 
542c1b14e5Sjose borrego 	opnum = DSSETUP_OPNUM_DsRoleGetPrimaryDomainInfo;
552c1b14e5Sjose borrego 	bzero(&arg, sizeof (dssetup_DsRoleGetPrimaryDomainInfo_t));
562c1b14e5Sjose borrego 	arg.level = DS_ROLE_BASIC_INFORMATION;
572c1b14e5Sjose borrego 
588d7e4166Sjose borrego 	rc = ndr_rpc_call(&handle, opnum, &arg);
592c1b14e5Sjose borrego 	if ((rc != 0) || (arg.status != 0) || arg.info == NULL) {
608d7e4166Sjose borrego 		ndr_rpc_unbind(&handle);
612c1b14e5Sjose borrego 		return (-1);
622c1b14e5Sjose borrego 	}
632c1b14e5Sjose borrego 
642c1b14e5Sjose borrego 	info = &arg.info->ru.info1;
652c1b14e5Sjose borrego 
662c1b14e5Sjose borrego 	if (info->nt_domain == NULL ||
672c1b14e5Sjose borrego 	    info->dns_domain == NULL ||
682c1b14e5Sjose borrego 	    info->forest == NULL) {
698d7e4166Sjose borrego 		ndr_rpc_unbind(&handle);
702c1b14e5Sjose borrego 		return (-1);
712c1b14e5Sjose borrego 	}
722c1b14e5Sjose borrego 
732c1b14e5Sjose borrego 	bcopy(info, ds_info, sizeof (ds_primary_domain_info_t));
742c1b14e5Sjose borrego 	ds_info->nt_domain = (uint8_t *)strdup((char *)info->nt_domain);
752c1b14e5Sjose borrego 	ds_info->dns_domain = (uint8_t *)strdup((char *)info->dns_domain);
762c1b14e5Sjose borrego 	ds_info->forest = (uint8_t *)strdup((char *)info->forest);
772c1b14e5Sjose borrego 
788d7e4166Sjose borrego 	ndr_rpc_unbind(&handle);
792c1b14e5Sjose borrego 	return (0);
802c1b14e5Sjose borrego }
811fdeec65Sjoyce mcintosh 
82380acbbeSGordon Ross /*
83380acbbeSGordon Ross  * Check whether our connection to the DC is working.
84380acbbeSGordon Ross  */
851fdeec65Sjoyce mcintosh int
dssetup_check_service(void)861fdeec65Sjoyce mcintosh dssetup_check_service(void)
871fdeec65Sjoyce mcintosh {
88ed9aabc7SGordon Ross 	ds_primary_domain_info_t	ds_info;
89ed9aabc7SGordon Ross 	int				rc;
901fdeec65Sjoyce mcintosh 
91ed9aabc7SGordon Ross 	bzero(&ds_info, sizeof (ds_info));
921fdeec65Sjoyce mcintosh 
93ed9aabc7SGordon Ross 	if ((rc = dssetup_get_domain_info(&ds_info)) == 0) {
94ed9aabc7SGordon Ross 		free(ds_info.nt_domain);
95ed9aabc7SGordon Ross 		free(ds_info.dns_domain);
96ed9aabc7SGordon Ross 		free(ds_info.forest);
97ed9aabc7SGordon Ross 	}
981fdeec65Sjoyce mcintosh 
99ed9aabc7SGordon Ross 	return (rc);
1001fdeec65Sjoyce mcintosh }
101