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.
23b3700b07SGordon Ross  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
24*15f5f761SMatt Barden  * Copyright 2023 RackTop Systems, Inc.
252c1b14e5Sjose borrego  */
262c1b14e5Sjose borrego 
272c1b14e5Sjose borrego /*
282c1b14e5Sjose borrego  * Client side for the DSSETUP RPC service.
292c1b14e5Sjose borrego  */
302c1b14e5Sjose borrego 
312c1b14e5Sjose borrego #include <string.h>
322c1b14e5Sjose borrego #include <strings.h>
333299f39fSGordon Ross #include <smb/wintypes.h>
342c1b14e5Sjose borrego #include <smbsrv/libsmb.h>
352c1b14e5Sjose borrego #include <smbsrv/ndl/dssetup.ndl>
368d7e4166Sjose borrego #include <smbsrv/libmlsvc.h>
372c1b14e5Sjose borrego 
382c1b14e5Sjose borrego int
dssetup_get_domain_info(ds_primary_domain_info_t * ds_info)392c1b14e5Sjose borrego dssetup_get_domain_info(ds_primary_domain_info_t *ds_info)
402c1b14e5Sjose borrego {
412c1b14e5Sjose borrego 	dssetup_DsRoleGetPrimaryDomainInfo_t arg;
42*15f5f761SMatt Barden 	char user[SMB_USERNAME_MAXLEN];
432c1b14e5Sjose borrego 	struct dssetup_DsRolePrimaryDomInfo1 *info;
44a0aa776eSAlan Wright 	smb_domainex_t di;
452c1b14e5Sjose borrego 	mlsvc_handle_t handle;
462c1b14e5Sjose borrego 	int opnum;
472c1b14e5Sjose borrego 	int rc;
482c1b14e5Sjose borrego 
498d7e4166Sjose borrego 	if (!smb_domain_getinfo(&di))
508d7e4166Sjose borrego 		return (-1);
518d7e4166Sjose borrego 
52*15f5f761SMatt Barden 	smb_ipc_get_user(user, sizeof (user));
53b3700b07SGordon Ross 	if (ndr_rpc_bind(&handle, di.d_dci.dc_name, di.d_primary.di_nbname,
54*15f5f761SMatt Barden 	    user, "DSSETUP") != 0)
552c1b14e5Sjose borrego 		return (-1);
562c1b14e5Sjose borrego 
572c1b14e5Sjose borrego 	opnum = DSSETUP_OPNUM_DsRoleGetPrimaryDomainInfo;
582c1b14e5Sjose borrego 	bzero(&arg, sizeof (dssetup_DsRoleGetPrimaryDomainInfo_t));
592c1b14e5Sjose borrego 	arg.level = DS_ROLE_BASIC_INFORMATION;
602c1b14e5Sjose borrego 
618d7e4166Sjose borrego 	rc = ndr_rpc_call(&handle, opnum, &arg);
622c1b14e5Sjose borrego 	if ((rc != 0) || (arg.status != 0) || arg.info == NULL) {
638d7e4166Sjose borrego 		ndr_rpc_unbind(&handle);
642c1b14e5Sjose borrego 		return (-1);
652c1b14e5Sjose borrego 	}
662c1b14e5Sjose borrego 
672c1b14e5Sjose borrego 	info = &arg.info->ru.info1;
682c1b14e5Sjose borrego 
692c1b14e5Sjose borrego 	if (info->nt_domain == NULL ||
702c1b14e5Sjose borrego 	    info->dns_domain == NULL ||
712c1b14e5Sjose borrego 	    info->forest == NULL) {
728d7e4166Sjose borrego 		ndr_rpc_unbind(&handle);
732c1b14e5Sjose borrego 		return (-1);
742c1b14e5Sjose borrego 	}
752c1b14e5Sjose borrego 
762c1b14e5Sjose borrego 	bcopy(info, ds_info, sizeof (ds_primary_domain_info_t));
772c1b14e5Sjose borrego 	ds_info->nt_domain = (uint8_t *)strdup((char *)info->nt_domain);
782c1b14e5Sjose borrego 	ds_info->dns_domain = (uint8_t *)strdup((char *)info->dns_domain);
792c1b14e5Sjose borrego 	ds_info->forest = (uint8_t *)strdup((char *)info->forest);
802c1b14e5Sjose borrego 
818d7e4166Sjose borrego 	ndr_rpc_unbind(&handle);
822c1b14e5Sjose borrego 	return (0);
832c1b14e5Sjose borrego }
841fdeec65Sjoyce mcintosh 
85380acbbeSGordon Ross /*
86380acbbeSGordon Ross  * Check whether our connection to the DC is working.
87380acbbeSGordon Ross  */
881fdeec65Sjoyce mcintosh int
dssetup_check_service(void)891fdeec65Sjoyce mcintosh dssetup_check_service(void)
901fdeec65Sjoyce mcintosh {
91ed9aabc7SGordon Ross 	ds_primary_domain_info_t	ds_info;
92ed9aabc7SGordon Ross 	int				rc;
931fdeec65Sjoyce mcintosh 
94ed9aabc7SGordon Ross 	bzero(&ds_info, sizeof (ds_info));
951fdeec65Sjoyce mcintosh 
96ed9aabc7SGordon Ross 	if ((rc = dssetup_get_domain_info(&ds_info)) == 0) {
97ed9aabc7SGordon Ross 		free(ds_info.nt_domain);
98ed9aabc7SGordon Ross 		free(ds_info.dns_domain);
99ed9aabc7SGordon Ross 		free(ds_info.forest);
100ed9aabc7SGordon Ross 	}
1011fdeec65Sjoyce mcintosh 
102ed9aabc7SGordon Ross 	return (rc);
1031fdeec65Sjoyce mcintosh }
104