189dc44ceSjose borrego /*
289dc44ceSjose borrego  * CDDL HEADER START
389dc44ceSjose borrego  *
489dc44ceSjose borrego  * The contents of this file are subject to the terms of the
589dc44ceSjose borrego  * Common Development and Distribution License (the "License").
689dc44ceSjose borrego  * You may not use this file except in compliance with the License.
789dc44ceSjose borrego  *
889dc44ceSjose borrego  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
989dc44ceSjose borrego  * or http://www.opensolaris.org/os/licensing.
1089dc44ceSjose borrego  * See the License for the specific language governing permissions
1189dc44ceSjose borrego  * and limitations under the License.
1289dc44ceSjose borrego  *
1389dc44ceSjose borrego  * When distributing Covered Code, include this CDDL HEADER in each
1489dc44ceSjose borrego  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1589dc44ceSjose borrego  * If applicable, add the following below this CDDL HEADER, with the
1689dc44ceSjose borrego  * fields enclosed by brackets "[]" replaced with your own identifying
1789dc44ceSjose borrego  * information: Portions Copyright [yyyy] [name of copyright owner]
1889dc44ceSjose borrego  *
1989dc44ceSjose borrego  * CDDL HEADER END
2089dc44ceSjose borrego  */
2189dc44ceSjose borrego /*
22f96bd5c8SAlan Wright  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
2389dc44ceSjose borrego  * Use is subject to license terms.
2489dc44ceSjose borrego  */
2589dc44ceSjose borrego 
2689dc44ceSjose borrego /*
2789dc44ceSjose borrego  * Windows Registry RPC (WINREG) server-side interface.
2889dc44ceSjose borrego  *
297f667e74Sjose borrego  * The registry is a database with a hierarchical structure similar to
307f667e74Sjose borrego  * a file system, with keys in place of directories and values in place
317f667e74Sjose borrego  * of files.  The top level keys are known as root keys and each key can
327f667e74Sjose borrego  * contain subkeys and values.  As with directories and sub-directories,
337f667e74Sjose borrego  * the terms key and subkey are used interchangeably.  Values, analogous
347f667e74Sjose borrego  * to files, contain data.
3589dc44ceSjose borrego  *
367f667e74Sjose borrego  * A specific subkey can be identifies by its fully qualified name (FQN),
377f667e74Sjose borrego  * which is analogous to a file system path.  In the registry, the key
387f667e74Sjose borrego  * separator is the '\' character, which is reserved and cannot appear
397f667e74Sjose borrego  * in key or value names.  Registry names are case-insensitive.
407f667e74Sjose borrego  *
417f667e74Sjose borrego  * For example:  HKEY_LOCAL_MACHINE\System\CurrentControlSet
427f667e74Sjose borrego  *
43b1352070SAlan Wright  * The HKEY_LOCAL_MACHINE root key contains a subkey called System, and
447f667e74Sjose borrego  * System contains a subkey called CurrentControlSet.
457f667e74Sjose borrego  *
467f667e74Sjose borrego  * The WINREG RPC interface returns Win32 error codes.
4789dc44ceSjose borrego  */
4889dc44ceSjose borrego 
4989dc44ceSjose borrego #include <sys/utsname.h>
5089dc44ceSjose borrego #include <strings.h>
5189dc44ceSjose borrego 
5289dc44ceSjose borrego #include <smbsrv/libsmb.h>
5389dc44ceSjose borrego #include <smbsrv/ntstatus.h>
5489dc44ceSjose borrego #include <smbsrv/nterror.h>
5589dc44ceSjose borrego #include <smbsrv/nmpipes.h>
5689dc44ceSjose borrego #include <smbsrv/libmlsvc.h>
5789dc44ceSjose borrego #include <smbsrv/ndl/winreg.ndl>
5889dc44ceSjose borrego 
5989dc44ceSjose borrego /*
6089dc44ceSjose borrego  * List of supported registry keys (case-insensitive).
6189dc44ceSjose borrego  */
6289dc44ceSjose borrego static char *winreg_keys[] = {
63b1352070SAlan Wright 	"HKLM",
64b1352070SAlan Wright 	"HKU",
65b1352070SAlan Wright 	"HKLM\\SOFTWARE",
66b1352070SAlan Wright 	"HKLM\\SYSTEM",
67e3f2c991SKeyur Desai 	"Application",
68e3f2c991SKeyur Desai 	"Security",
69b1352070SAlan Wright 	"System",
70b1352070SAlan Wright 	"CurrentControlSet",
71*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	"SunOS",
72*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	"Solaris",
7389dc44ceSjose borrego 	"System\\CurrentControlSet\\Services\\Eventlog",
747f667e74Sjose borrego 	"System\\CurrentControlSet\\Services\\Eventlog\\Application",
75*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	"System\\CurrentControlSet\\Services\\Eventlog\\"
76*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 						"Application\\Application",
777f667e74Sjose borrego 	"System\\CurrentControlSet\\Services\\Eventlog\\Security",
78*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	"System\\CurrentControlSet\\Services\\Eventlog\\Security\\Security",
7989dc44ceSjose borrego 	"System\\CurrentControlSet\\Services\\Eventlog\\System",
80*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	"System\\CurrentControlSet\\Services\\Eventlog\\System\\System",
8189dc44ceSjose borrego 	"System\\CurrentControlSet\\Control\\ProductOptions",
82b1352070SAlan Wright 	"SOFTWARE",
8389dc44ceSjose borrego 	"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
8489dc44ceSjose borrego };
8589dc44ceSjose borrego 
8689dc44ceSjose borrego typedef struct winreg_subkey {
8789dc44ceSjose borrego 	list_node_t sk_lnd;
8889dc44ceSjose borrego 	ndr_hdid_t sk_handle;
8989dc44ceSjose borrego 	char sk_name[MAXPATHLEN];
9089dc44ceSjose borrego 	boolean_t sk_predefined;
9189dc44ceSjose borrego } winreg_subkey_t;
9289dc44ceSjose borrego 
9389dc44ceSjose borrego typedef struct winreg_keylist {
9489dc44ceSjose borrego 	list_t kl_list;
9589dc44ceSjose borrego 	int kl_count;
9689dc44ceSjose borrego } winreg_keylist_t;
9789dc44ceSjose borrego 
9889dc44ceSjose borrego static winreg_keylist_t winreg_keylist;
99*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static mutex_t winreg_mutex;
10089dc44ceSjose borrego 
101*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static ndr_hdid_t *winreg_alloc_id(ndr_xa_t *, const char *);
102*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void winreg_dealloc_id(ndr_xa_t *, ndr_hdid_t *);
10389dc44ceSjose borrego static boolean_t winreg_key_has_subkey(const char *);
1047f667e74Sjose borrego static char *winreg_enum_subkey(ndr_xa_t *, const char *, uint32_t);
10589dc44ceSjose borrego static char *winreg_lookup_value(const char *);
106f96bd5c8SAlan Wright static uint32_t winreg_sd_format(smb_sd_t *);
107f96bd5c8SAlan Wright uint32_t srvsvc_sd_set_relative(smb_sd_t *, uint8_t *);
10889dc44ceSjose borrego 
1097f667e74Sjose borrego static int winreg_s_OpenHKCR(void *, ndr_xa_t *);
1107f667e74Sjose borrego static int winreg_s_OpenHKCU(void *, ndr_xa_t *);
11189dc44ceSjose borrego static int winreg_s_OpenHKLM(void *, ndr_xa_t *);
1127f667e74Sjose borrego static int winreg_s_OpenHKPD(void *, ndr_xa_t *);
1137f667e74Sjose borrego static int winreg_s_OpenHKU(void *, ndr_xa_t *);
1147f667e74Sjose borrego static int winreg_s_OpenHKCC(void *, ndr_xa_t *);
1157f667e74Sjose borrego static int winreg_s_OpenHKDD(void *, ndr_xa_t *);
1167f667e74Sjose borrego static int winreg_s_OpenHKPT(void *, ndr_xa_t *);
1177f667e74Sjose borrego static int winreg_s_OpenHKPN(void *, ndr_xa_t *);
1187f667e74Sjose borrego static int winreg_s_OpenHK(void *, ndr_xa_t *, const char *);
11989dc44ceSjose borrego static int winreg_s_Close(void *, ndr_xa_t *);
12089dc44ceSjose borrego static int winreg_s_CreateKey(void *, ndr_xa_t *);
12189dc44ceSjose borrego static int winreg_s_DeleteKey(void *, ndr_xa_t *);
12289dc44ceSjose borrego static int winreg_s_DeleteValue(void *, ndr_xa_t *);
12389dc44ceSjose borrego static int winreg_s_EnumKey(void *, ndr_xa_t *);
12489dc44ceSjose borrego static int winreg_s_EnumValue(void *, ndr_xa_t *);
12589dc44ceSjose borrego static int winreg_s_FlushKey(void *, ndr_xa_t *);
12689dc44ceSjose borrego static int winreg_s_GetKeySec(void *, ndr_xa_t *);
12789dc44ceSjose borrego static int winreg_s_NotifyChange(void *, ndr_xa_t *);
12889dc44ceSjose borrego static int winreg_s_OpenKey(void *, ndr_xa_t *);
12989dc44ceSjose borrego static int winreg_s_QueryKey(void *, ndr_xa_t *);
13089dc44ceSjose borrego static int winreg_s_QueryValue(void *, ndr_xa_t *);
13189dc44ceSjose borrego static int winreg_s_SetKeySec(void *, ndr_xa_t *);
13289dc44ceSjose borrego static int winreg_s_CreateValue(void *, ndr_xa_t *);
13389dc44ceSjose borrego static int winreg_s_Shutdown(void *, ndr_xa_t *);
13489dc44ceSjose borrego static int winreg_s_AbortShutdown(void *, ndr_xa_t *);
13589dc44ceSjose borrego static int winreg_s_GetVersion(void *, ndr_xa_t *);
13689dc44ceSjose borrego 
13789dc44ceSjose borrego static ndr_stub_table_t winreg_stub_table[] = {
1387f667e74Sjose borrego 	{ winreg_s_OpenHKCR,	WINREG_OPNUM_OpenHKCR },
1397f667e74Sjose borrego 	{ winreg_s_OpenHKCU,	WINREG_OPNUM_OpenHKCU },
14089dc44ceSjose borrego 	{ winreg_s_OpenHKLM,	WINREG_OPNUM_OpenHKLM },
1417f667e74Sjose borrego 	{ winreg_s_OpenHKPD,	WINREG_OPNUM_OpenHKPD },
1427f667e74Sjose borrego 	{ winreg_s_OpenHKU,	WINREG_OPNUM_OpenHKUsers },
14389dc44ceSjose borrego 	{ winreg_s_Close,	WINREG_OPNUM_Close },
14489dc44ceSjose borrego 	{ winreg_s_CreateKey,	WINREG_OPNUM_CreateKey },
14589dc44ceSjose borrego 	{ winreg_s_DeleteKey,	WINREG_OPNUM_DeleteKey },
14689dc44ceSjose borrego 	{ winreg_s_DeleteValue,	WINREG_OPNUM_DeleteValue },
14789dc44ceSjose borrego 	{ winreg_s_EnumKey,	WINREG_OPNUM_EnumKey },
14889dc44ceSjose borrego 	{ winreg_s_EnumValue,	WINREG_OPNUM_EnumValue },
14989dc44ceSjose borrego 	{ winreg_s_FlushKey,	WINREG_OPNUM_FlushKey },
15089dc44ceSjose borrego 	{ winreg_s_GetKeySec,	WINREG_OPNUM_GetKeySec },
15189dc44ceSjose borrego 	{ winreg_s_NotifyChange,	WINREG_OPNUM_NotifyChange },
15289dc44ceSjose borrego 	{ winreg_s_OpenKey,	WINREG_OPNUM_OpenKey },
15389dc44ceSjose borrego 	{ winreg_s_QueryKey,	WINREG_OPNUM_QueryKey },
15489dc44ceSjose borrego 	{ winreg_s_QueryValue,	WINREG_OPNUM_QueryValue },
15589dc44ceSjose borrego 	{ winreg_s_SetKeySec,	WINREG_OPNUM_SetKeySec },
15689dc44ceSjose borrego 	{ winreg_s_CreateValue,	WINREG_OPNUM_CreateValue },
15789dc44ceSjose borrego 	{ winreg_s_Shutdown,	WINREG_OPNUM_Shutdown },
15889dc44ceSjose borrego 	{ winreg_s_AbortShutdown,	WINREG_OPNUM_AbortShutdown },
15989dc44ceSjose borrego 	{ winreg_s_GetVersion,	WINREG_OPNUM_GetVersion },
1607f667e74Sjose borrego 	{ winreg_s_OpenHKCC,	WINREG_OPNUM_OpenHKCC },
1617f667e74Sjose borrego 	{ winreg_s_OpenHKDD,	WINREG_OPNUM_OpenHKDD },
1627f667e74Sjose borrego 	{ winreg_s_OpenHKPT,	WINREG_OPNUM_OpenHKPT },
1637f667e74Sjose borrego 	{ winreg_s_OpenHKPN,	WINREG_OPNUM_OpenHKPN },
16489dc44ceSjose borrego 	{0}
16589dc44ceSjose borrego };
16689dc44ceSjose borrego 
16789dc44ceSjose borrego static ndr_service_t winreg_service = {
16889dc44ceSjose borrego 	"Winreg",			/* name */
16989dc44ceSjose borrego 	"Windows Registry",		/* desc */
17089dc44ceSjose borrego 	"\\winreg",			/* endpoint */
17189dc44ceSjose borrego 	PIPE_WINREG,			/* sec_addr_port */
17289dc44ceSjose borrego 	"338cd001-2244-31f1-aaaa-900038001003", 1,	/* abstract */
17389dc44ceSjose borrego 	NDR_TRANSFER_SYNTAX_UUID,		2,	/* transfer */
17489dc44ceSjose borrego 	0,				/* no bind_instance_size */
17589dc44ceSjose borrego 	0,				/* no bind_req() */
17689dc44ceSjose borrego 	0,				/* no unbind_and_close() */
17789dc44ceSjose borrego 	0,				/* use generic_call_stub() */
17889dc44ceSjose borrego 	&TYPEINFO(winreg_interface),	/* interface ti */
17989dc44ceSjose borrego 	winreg_stub_table		/* stub_table */
18089dc44ceSjose borrego };
18189dc44ceSjose borrego 
18289dc44ceSjose borrego static char winreg_sysname[SYS_NMLN];
183*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static char winreg_sysver[SMB_VERSTR_LEN];
18489dc44ceSjose borrego 
18589dc44ceSjose borrego /*
18689dc44ceSjose borrego  * winreg_initialize
18789dc44ceSjose borrego  *
18889dc44ceSjose borrego  * Initialize and register the WINREG RPC interface with the RPC runtime
18989dc44ceSjose borrego  * library. It must be called in order to use either the client side
19089dc44ceSjose borrego  * or the server side functions.
19189dc44ceSjose borrego  */
19289dc44ceSjose borrego void
19389dc44ceSjose borrego winreg_initialize(void)
19489dc44ceSjose borrego {
19589dc44ceSjose borrego 	winreg_subkey_t *key;
196*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_version_t version;
19789dc44ceSjose borrego 	struct utsname name;
19889dc44ceSjose borrego 	char *sysname;
19989dc44ceSjose borrego 	int i;
20089dc44ceSjose borrego 
201*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_lock(&winreg_mutex);
202*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
20389dc44ceSjose borrego 	list_create(&winreg_keylist.kl_list, sizeof (winreg_subkey_t),
20489dc44ceSjose borrego 	    offsetof(winreg_subkey_t, sk_lnd));
20589dc44ceSjose borrego 	winreg_keylist.kl_count = 0;
20689dc44ceSjose borrego 
20789dc44ceSjose borrego 	for (i = 0; i < sizeof (winreg_keys)/sizeof (winreg_keys[0]); ++i) {
20889dc44ceSjose borrego 		if ((key = malloc(sizeof (winreg_subkey_t))) != NULL) {
20989dc44ceSjose borrego 			bzero(key, sizeof (winreg_subkey_t));
21089dc44ceSjose borrego 			(void) strlcpy(key->sk_name, winreg_keys[i],
21189dc44ceSjose borrego 			    MAXPATHLEN);
21289dc44ceSjose borrego 			key->sk_predefined = B_TRUE;
213*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
21489dc44ceSjose borrego 			list_insert_tail(&winreg_keylist.kl_list, key);
21589dc44ceSjose borrego 			++winreg_keylist.kl_count;
21689dc44ceSjose borrego 		}
21789dc44ceSjose borrego 	}
21889dc44ceSjose borrego 
219*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_unlock(&winreg_mutex);
220*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
22189dc44ceSjose borrego 	if (uname(&name) < 0)
22289dc44ceSjose borrego 		sysname = "Solaris";
22389dc44ceSjose borrego 	else
22489dc44ceSjose borrego 		sysname = name.sysname;
22589dc44ceSjose borrego 
22689dc44ceSjose borrego 	(void) strlcpy(winreg_sysname, sysname, SYS_NMLN);
227*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
228*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	smb_config_get_version(&version);
229*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) snprintf(winreg_sysver, SMB_VERSTR_LEN, "%d.%d",
230*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	    version.sv_major, version.sv_minor);
231*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
23289dc44ceSjose borrego 	(void) ndr_svc_register(&winreg_service);
23389dc44ceSjose borrego }
23489dc44ceSjose borrego 
23589dc44ceSjose borrego static int
2367f667e74Sjose borrego winreg_s_OpenHKCR(void *arg, ndr_xa_t *mxa)
23789dc44ceSjose borrego {
2387f667e74Sjose borrego 	return (winreg_s_OpenHK(arg, mxa, "HKCR"));
23989dc44ceSjose borrego }
24089dc44ceSjose borrego 
2417f667e74Sjose borrego static int
2427f667e74Sjose borrego winreg_s_OpenHKCU(void *arg, ndr_xa_t *mxa)
2437f667e74Sjose borrego {
2447f667e74Sjose borrego 	return (winreg_s_OpenHK(arg, mxa, "HKCU"));
24589dc44ceSjose borrego }
24689dc44ceSjose borrego 
24789dc44ceSjose borrego static int
24889dc44ceSjose borrego winreg_s_OpenHKLM(void *arg, ndr_xa_t *mxa)
24989dc44ceSjose borrego {
2507f667e74Sjose borrego 	return (winreg_s_OpenHK(arg, mxa, "HKLM"));
25189dc44ceSjose borrego }
25289dc44ceSjose borrego 
2537f667e74Sjose borrego static int
2547f667e74Sjose borrego winreg_s_OpenHKPD(void *arg, ndr_xa_t *mxa)
2557f667e74Sjose borrego {
2567f667e74Sjose borrego 	return (winreg_s_OpenHK(arg, mxa, "HKPD"));
2577f667e74Sjose borrego }
2587f667e74Sjose borrego 
2597f667e74Sjose borrego static int
2607f667e74Sjose borrego winreg_s_OpenHKU(void *arg, ndr_xa_t *mxa)
2617f667e74Sjose borrego {
2627f667e74Sjose borrego 	return (winreg_s_OpenHK(arg, mxa, "HKU"));
2637f667e74Sjose borrego }
2647f667e74Sjose borrego 
2657f667e74Sjose borrego static int
2667f667e74Sjose borrego winreg_s_OpenHKCC(void *arg, ndr_xa_t *mxa)
2677f667e74Sjose borrego {
2687f667e74Sjose borrego 	return (winreg_s_OpenHK(arg, mxa, "HKCC"));
2697f667e74Sjose borrego }
2707f667e74Sjose borrego 
2717f667e74Sjose borrego static int
2727f667e74Sjose borrego winreg_s_OpenHKDD(void *arg, ndr_xa_t *mxa)
2737f667e74Sjose borrego {
2747f667e74Sjose borrego 	return (winreg_s_OpenHK(arg, mxa, "HKDD"));
2757f667e74Sjose borrego }
2767f667e74Sjose borrego 
2777f667e74Sjose borrego static int
2787f667e74Sjose borrego winreg_s_OpenHKPT(void *arg, ndr_xa_t *mxa)
2797f667e74Sjose borrego {
2807f667e74Sjose borrego 	return (winreg_s_OpenHK(arg, mxa, "HKPT"));
2817f667e74Sjose borrego }
2827f667e74Sjose borrego 
2837f667e74Sjose borrego static int
2847f667e74Sjose borrego winreg_s_OpenHKPN(void *arg, ndr_xa_t *mxa)
2857f667e74Sjose borrego {
2867f667e74Sjose borrego 	return (winreg_s_OpenHK(arg, mxa, "HKPN"));
28789dc44ceSjose borrego }
28889dc44ceSjose borrego 
28989dc44ceSjose borrego /*
2907f667e74Sjose borrego  * winreg_s_OpenHK
29189dc44ceSjose borrego  *
2927f667e74Sjose borrego  * Common code to open root HKEYs.
29389dc44ceSjose borrego  */
29489dc44ceSjose borrego static int
2957f667e74Sjose borrego winreg_s_OpenHK(void *arg, ndr_xa_t *mxa, const char *hkey)
29689dc44ceSjose borrego {
2977f667e74Sjose borrego 	struct winreg_OpenHKCR *param = arg;
29889dc44ceSjose borrego 	ndr_hdid_t *id;
29989dc44ceSjose borrego 
300*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_lock(&winreg_mutex);
3017f667e74Sjose borrego 
302*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if ((id = winreg_alloc_id(mxa, hkey)) == NULL) {
30389dc44ceSjose borrego 		bzero(&param->handle, sizeof (winreg_handle_t));
30489dc44ceSjose borrego 		param->status = ERROR_ACCESS_DENIED;
30589dc44ceSjose borrego 	} else {
30689dc44ceSjose borrego 		bcopy(id, &param->handle, sizeof (winreg_handle_t));
30789dc44ceSjose borrego 		param->status = ERROR_SUCCESS;
30889dc44ceSjose borrego 	}
30989dc44ceSjose borrego 
310*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_unlock(&winreg_mutex);
31189dc44ceSjose borrego 	return (NDR_DRC_OK);
31289dc44ceSjose borrego }
31389dc44ceSjose borrego 
31489dc44ceSjose borrego /*
31589dc44ceSjose borrego  * winreg_s_Close
31689dc44ceSjose borrego  *
31789dc44ceSjose borrego  * This is a request to close the WINREG interface specified by the
31889dc44ceSjose borrego  * handle. We don't track handles (yet), so just zero out the handle
31989dc44ceSjose borrego  * and return NDR_DRC_OK. Setting the handle to zero appears to be
32089dc44ceSjose borrego  * standard behaviour.
32189dc44ceSjose borrego  */
32289dc44ceSjose borrego static int
32389dc44ceSjose borrego winreg_s_Close(void *arg, ndr_xa_t *mxa)
32489dc44ceSjose borrego {
32589dc44ceSjose borrego 	struct winreg_Close *param = arg;
32689dc44ceSjose borrego 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
327*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
328*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_lock(&winreg_mutex);
329*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	winreg_dealloc_id(mxa, id);
330*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_unlock(&winreg_mutex);
331*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
332*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	bzero(&param->result_handle, sizeof (winreg_handle_t));
333*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	param->status = ERROR_SUCCESS;
334*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	return (NDR_DRC_OK);
335*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
336*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
337*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static ndr_hdid_t *
338*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States winreg_alloc_id(ndr_xa_t *mxa, const char *key)
339*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
340*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	ndr_handle_t	*hd;
341*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	ndr_hdid_t	*id;
342*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	char		*data;
343*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
344*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if ((data = strdup(key)) == NULL)
345*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		return (NULL);
346*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
347*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if ((id = ndr_hdalloc(mxa, data)) == NULL) {
348*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		free(data);
349*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		return (NULL);
350*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	}
351*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
352*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if ((hd = ndr_hdlookup(mxa, id)) != NULL)
353*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		hd->nh_data_free = free;
354*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
355*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	return (id);
356*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States }
357*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
358*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States static void
359*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States winreg_dealloc_id(ndr_xa_t *mxa, ndr_hdid_t *id)
360*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States {
3617f667e74Sjose borrego 	ndr_handle_t *hd;
3627f667e74Sjose borrego 
3637f667e74Sjose borrego 	if ((hd = ndr_hdlookup(mxa, id)) != NULL) {
3647f667e74Sjose borrego 		free(hd->nh_data);
3657f667e74Sjose borrego 		hd->nh_data = NULL;
3667f667e74Sjose borrego 	}
36789dc44ceSjose borrego 
36889dc44ceSjose borrego 	ndr_hdfree(mxa, id);
36989dc44ceSjose borrego }
37089dc44ceSjose borrego 
37189dc44ceSjose borrego /*
37289dc44ceSjose borrego  * winreg_s_CreateKey
37389dc44ceSjose borrego  */
37489dc44ceSjose borrego static int
37589dc44ceSjose borrego winreg_s_CreateKey(void *arg, ndr_xa_t *mxa)
37689dc44ceSjose borrego {
37789dc44ceSjose borrego 	struct winreg_CreateKey *param = arg;
37889dc44ceSjose borrego 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
37989dc44ceSjose borrego 	ndr_handle_t *hd;
38089dc44ceSjose borrego 	winreg_subkey_t *key;
38189dc44ceSjose borrego 	char *subkey;
38289dc44ceSjose borrego 	DWORD *action;
38389dc44ceSjose borrego 
38489dc44ceSjose borrego 	subkey = (char *)param->subkey.str;
38589dc44ceSjose borrego 
38689dc44ceSjose borrego 	if (!ndr_is_admin(mxa) || (subkey == NULL)) {
38789dc44ceSjose borrego 		bzero(param, sizeof (struct winreg_CreateKey));
38889dc44ceSjose borrego 		param->status = ERROR_ACCESS_DENIED;
38989dc44ceSjose borrego 		return (NDR_DRC_OK);
39089dc44ceSjose borrego 	}
39189dc44ceSjose borrego 
392*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_lock(&winreg_mutex);
393*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
39489dc44ceSjose borrego 	hd = ndr_hdlookup(mxa, id);
39589dc44ceSjose borrego 	if (hd == NULL) {
396*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		(void) mutex_unlock(&winreg_mutex);
39789dc44ceSjose borrego 		bzero(param, sizeof (struct winreg_CreateKey));
39889dc44ceSjose borrego 		param->status = ERROR_INVALID_HANDLE;
39989dc44ceSjose borrego 		return (NDR_DRC_OK);
40089dc44ceSjose borrego 	}
40189dc44ceSjose borrego 
40289dc44ceSjose borrego 	if ((action = NDR_NEW(mxa, DWORD)) == NULL) {
403*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		(void) mutex_unlock(&winreg_mutex);
40489dc44ceSjose borrego 		bzero(param, sizeof (struct winreg_CreateKey));
40589dc44ceSjose borrego 		param->status = ERROR_NOT_ENOUGH_MEMORY;
40689dc44ceSjose borrego 		return (NDR_DRC_OK);
40789dc44ceSjose borrego 	}
40889dc44ceSjose borrego 
40989dc44ceSjose borrego 	if (list_is_empty(&winreg_keylist.kl_list))
41089dc44ceSjose borrego 		goto new_key;
41189dc44ceSjose borrego 
41289dc44ceSjose borrego 	/*
41389dc44ceSjose borrego 	 * Check for an existing key.
41489dc44ceSjose borrego 	 */
41589dc44ceSjose borrego 	key = list_head(&winreg_keylist.kl_list);
41689dc44ceSjose borrego 	do {
41789dc44ceSjose borrego 		if (strcasecmp(subkey, key->sk_name) == 0) {
41889dc44ceSjose borrego 			bcopy(&key->sk_handle, &param->result_handle,
41989dc44ceSjose borrego 			    sizeof (winreg_handle_t));
420*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
421*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 			(void) mutex_unlock(&winreg_mutex);
42289dc44ceSjose borrego 			*action = WINREG_ACTION_EXISTING_KEY;
42389dc44ceSjose borrego 			param->action = action;
42489dc44ceSjose borrego 			param->status = ERROR_SUCCESS;
42589dc44ceSjose borrego 			return (NDR_DRC_OK);
42689dc44ceSjose borrego 		}
42789dc44ceSjose borrego 	} while ((key = list_next(&winreg_keylist.kl_list, key)) != NULL);
42889dc44ceSjose borrego 
42989dc44ceSjose borrego new_key:
43089dc44ceSjose borrego 	/*
43189dc44ceSjose borrego 	 * Create a new key.
43289dc44ceSjose borrego 	 */
433*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if ((id = winreg_alloc_id(mxa, subkey)) == NULL)
434*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		goto no_memory;
4357f667e74Sjose borrego 
436*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	if ((key = malloc(sizeof (winreg_subkey_t))) == NULL) {
437*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		winreg_dealloc_id(mxa, id);
438*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		goto no_memory;
43989dc44ceSjose borrego 	}
44089dc44ceSjose borrego 
44189dc44ceSjose borrego 	bcopy(id, &key->sk_handle, sizeof (ndr_hdid_t));
44289dc44ceSjose borrego 	(void) strlcpy(key->sk_name, subkey, MAXPATHLEN);
44389dc44ceSjose borrego 	key->sk_predefined = B_FALSE;
44489dc44ceSjose borrego 	list_insert_tail(&winreg_keylist.kl_list, key);
44589dc44ceSjose borrego 	++winreg_keylist.kl_count;
44689dc44ceSjose borrego 
44789dc44ceSjose borrego 	bcopy(id, &param->result_handle, sizeof (winreg_handle_t));
448*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
449*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_unlock(&winreg_mutex);
45089dc44ceSjose borrego 	*action = WINREG_ACTION_NEW_KEY;
45189dc44ceSjose borrego 	param->action = action;
45289dc44ceSjose borrego 	param->status = ERROR_SUCCESS;
45389dc44ceSjose borrego 	return (NDR_DRC_OK);
454*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
455*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States no_memory:
456*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_unlock(&winreg_mutex);
457*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	bzero(param, sizeof (struct winreg_CreateKey));
458*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	param->status = ERROR_NOT_ENOUGH_MEMORY;
459*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	return (NDR_DRC_OK);
46089dc44ceSjose borrego }
46189dc44ceSjose borrego 
46289dc44ceSjose borrego /*
46389dc44ceSjose borrego  * winreg_s_DeleteKey
46489dc44ceSjose borrego  */
46589dc44ceSjose borrego static int
46689dc44ceSjose borrego winreg_s_DeleteKey(void *arg, ndr_xa_t *mxa)
46789dc44ceSjose borrego {
46889dc44ceSjose borrego 	struct winreg_DeleteKey *param = arg;
46989dc44ceSjose borrego 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
47089dc44ceSjose borrego 	winreg_subkey_t *key;
47189dc44ceSjose borrego 	char *subkey;
47289dc44ceSjose borrego 
47389dc44ceSjose borrego 	subkey = (char *)param->subkey.str;
47489dc44ceSjose borrego 
47589dc44ceSjose borrego 	if (!ndr_is_admin(mxa) || (subkey == NULL)) {
47689dc44ceSjose borrego 		param->status = ERROR_ACCESS_DENIED;
47789dc44ceSjose borrego 		return (NDR_DRC_OK);
47889dc44ceSjose borrego 	}
47989dc44ceSjose borrego 
480*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_lock(&winreg_mutex);
481*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
48289dc44ceSjose borrego 	if ((ndr_hdlookup(mxa, id) == NULL) ||
48389dc44ceSjose borrego 	    list_is_empty(&winreg_keylist.kl_list) ||
48489dc44ceSjose borrego 	    winreg_key_has_subkey(subkey)) {
485*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		(void) mutex_unlock(&winreg_mutex);
48689dc44ceSjose borrego 		param->status = ERROR_ACCESS_DENIED;
48789dc44ceSjose borrego 		return (NDR_DRC_OK);
48889dc44ceSjose borrego 	}
48989dc44ceSjose borrego 
49089dc44ceSjose borrego 	key = list_head(&winreg_keylist.kl_list);
49189dc44ceSjose borrego 	do {
49289dc44ceSjose borrego 		if (strcasecmp(subkey, key->sk_name) == 0) {
49389dc44ceSjose borrego 			if (key->sk_predefined == B_TRUE) {
49489dc44ceSjose borrego 				/* Predefined keys cannot be deleted */
49589dc44ceSjose borrego 				break;
49689dc44ceSjose borrego 			}
49789dc44ceSjose borrego 
49889dc44ceSjose borrego 			list_remove(&winreg_keylist.kl_list, key);
49989dc44ceSjose borrego 			--winreg_keylist.kl_count;
500*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 			winreg_dealloc_id(mxa, &key->sk_handle);
50189dc44ceSjose borrego 			free(key);
502*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
503*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 			(void) mutex_unlock(&winreg_mutex);
50489dc44ceSjose borrego 			param->status = ERROR_SUCCESS;
50589dc44ceSjose borrego 			return (NDR_DRC_OK);
50689dc44ceSjose borrego 		}
50789dc44ceSjose borrego 	} while ((key = list_next(&winreg_keylist.kl_list, key)) != NULL);
50889dc44ceSjose borrego 
509*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_unlock(&winreg_mutex);
51089dc44ceSjose borrego 	param->status = ERROR_ACCESS_DENIED;
51189dc44ceSjose borrego 	return (NDR_DRC_OK);
51289dc44ceSjose borrego }
51389dc44ceSjose borrego 
514*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
515*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Call with the winreg_mutex held.
516*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
51789dc44ceSjose borrego static boolean_t
51889dc44ceSjose borrego winreg_key_has_subkey(const char *subkey)
51989dc44ceSjose borrego {
52089dc44ceSjose borrego 	winreg_subkey_t *key;
52189dc44ceSjose borrego 	int keylen;
52289dc44ceSjose borrego 
52389dc44ceSjose borrego 	if (list_is_empty(&winreg_keylist.kl_list))
52489dc44ceSjose borrego 		return (B_FALSE);
52589dc44ceSjose borrego 
52689dc44ceSjose borrego 	keylen = strlen(subkey);
52789dc44ceSjose borrego 
52889dc44ceSjose borrego 	key = list_head(&winreg_keylist.kl_list);
52989dc44ceSjose borrego 	do {
53089dc44ceSjose borrego 		if (strncasecmp(subkey, key->sk_name, keylen) == 0) {
53189dc44ceSjose borrego 			/*
53289dc44ceSjose borrego 			 * Potential match.  If sk_name is longer than
53389dc44ceSjose borrego 			 * subkey, then sk_name is a subkey of our key.
53489dc44ceSjose borrego 			 */
53589dc44ceSjose borrego 			if (keylen < strlen(key->sk_name))
53689dc44ceSjose borrego 				return (B_TRUE);
53789dc44ceSjose borrego 		}
53889dc44ceSjose borrego 	} while ((key = list_next(&winreg_keylist.kl_list, key)) != NULL);
53989dc44ceSjose borrego 
54089dc44ceSjose borrego 	return (B_FALSE);
54189dc44ceSjose borrego }
54289dc44ceSjose borrego 
543*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /*
544*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Call with the winreg_mutex held.
545*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  */
54689dc44ceSjose borrego static char *
5477f667e74Sjose borrego winreg_enum_subkey(ndr_xa_t *mxa, const char *subkey, uint32_t index)
54889dc44ceSjose borrego {
54989dc44ceSjose borrego 	winreg_subkey_t *key;
5507f667e74Sjose borrego 	char *entry;
5517f667e74Sjose borrego 	char *p;
5527f667e74Sjose borrego 	int subkeylen;
5537f667e74Sjose borrego 	int count = 0;
55489dc44ceSjose borrego 
55589dc44ceSjose borrego 	if (subkey == NULL)
55689dc44ceSjose borrego 		return (NULL);
55789dc44ceSjose borrego 
55889dc44ceSjose borrego 	if (list_is_empty(&winreg_keylist.kl_list))
55989dc44ceSjose borrego 		return (NULL);
56089dc44ceSjose borrego 
5617f667e74Sjose borrego 	subkeylen = strlen(subkey);
5627f667e74Sjose borrego 
5637f667e74Sjose borrego 	for (key = list_head(&winreg_keylist.kl_list);
5647f667e74Sjose borrego 	    key != NULL; key = list_next(&winreg_keylist.kl_list, key)) {
5657f667e74Sjose borrego 		if (strncasecmp(subkey, key->sk_name, subkeylen) == 0) {
5667f667e74Sjose borrego 			p = key->sk_name + subkeylen;
5677f667e74Sjose borrego 
5687f667e74Sjose borrego 			if ((*p != '\\') || (*p == '\0')) {
5697f667e74Sjose borrego 				/*
5707f667e74Sjose borrego 				 * Not the same subkey or an exact match.
5717f667e74Sjose borrego 				 * We're looking for children of subkey.
5727f667e74Sjose borrego 				 */
5737f667e74Sjose borrego 				continue;
57489dc44ceSjose borrego 			}
5757f667e74Sjose borrego 
5767f667e74Sjose borrego 			++p;
5777f667e74Sjose borrego 
5787f667e74Sjose borrego 			if (count < index) {
5797f667e74Sjose borrego 				++count;
5807f667e74Sjose borrego 				continue;
5817f667e74Sjose borrego 			}
5827f667e74Sjose borrego 
5837f667e74Sjose borrego 			if ((entry = NDR_STRDUP(mxa, p)) == NULL)
5847f667e74Sjose borrego 				return (NULL);
5857f667e74Sjose borrego 
5867f667e74Sjose borrego 			if ((p = strchr(entry, '\\')) != NULL)
5877f667e74Sjose borrego 				*p = '\0';
5887f667e74Sjose borrego 
5897f667e74Sjose borrego 			return (entry);
5907f667e74Sjose borrego 		}
5917f667e74Sjose borrego 	}
59289dc44ceSjose borrego 
59389dc44ceSjose borrego 	return (NULL);
59489dc44ceSjose borrego }
59589dc44ceSjose borrego 
59689dc44ceSjose borrego /*
59789dc44ceSjose borrego  * winreg_s_DeleteValue
59889dc44ceSjose borrego  */
59989dc44ceSjose borrego /*ARGSUSED*/
60089dc44ceSjose borrego static int
60189dc44ceSjose borrego winreg_s_DeleteValue(void *arg, ndr_xa_t *mxa)
60289dc44ceSjose borrego {
60389dc44ceSjose borrego 	struct winreg_DeleteValue *param = arg;
60489dc44ceSjose borrego 
60589dc44ceSjose borrego 	param->status = ERROR_ACCESS_DENIED;
60689dc44ceSjose borrego 	return (NDR_DRC_OK);
60789dc44ceSjose borrego }
60889dc44ceSjose borrego 
60989dc44ceSjose borrego /*
61089dc44ceSjose borrego  * winreg_s_EnumKey
61189dc44ceSjose borrego  */
61289dc44ceSjose borrego static int
61389dc44ceSjose borrego winreg_s_EnumKey(void *arg, ndr_xa_t *mxa)
61489dc44ceSjose borrego {
61589dc44ceSjose borrego 	struct winreg_EnumKey *param = arg;
61689dc44ceSjose borrego 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
6177f667e74Sjose borrego 	ndr_handle_t *hd;
6187f667e74Sjose borrego 	char *subkey;
6197f667e74Sjose borrego 	char *name = NULL;
62089dc44ceSjose borrego 
621*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_lock(&winreg_mutex);
622*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
6237f667e74Sjose borrego 	if ((hd = ndr_hdlookup(mxa, id)) != NULL)
6247f667e74Sjose borrego 		name = hd->nh_data;
6257f667e74Sjose borrego 
6267f667e74Sjose borrego 	if (hd == NULL || name == NULL) {
627*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		(void) mutex_unlock(&winreg_mutex);
62889dc44ceSjose borrego 		bzero(param, sizeof (struct winreg_EnumKey));
62989dc44ceSjose borrego 		param->status = ERROR_NO_MORE_ITEMS;
63089dc44ceSjose borrego 		return (NDR_DRC_OK);
63189dc44ceSjose borrego 	}
63289dc44ceSjose borrego 
6337f667e74Sjose borrego 	subkey = winreg_enum_subkey(mxa, name, param->index);
6347f667e74Sjose borrego 	if (subkey == NULL) {
635*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		(void) mutex_unlock(&winreg_mutex);
63689dc44ceSjose borrego 		bzero(param, sizeof (struct winreg_EnumKey));
63789dc44ceSjose borrego 		param->status = ERROR_NO_MORE_ITEMS;
63889dc44ceSjose borrego 		return (NDR_DRC_OK);
63989dc44ceSjose borrego 	}
64089dc44ceSjose borrego 
6417f667e74Sjose borrego 	if (NDR_MSTRING(mxa, subkey, (ndr_mstring_t *)&param->name_out) == -1) {
642*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		(void) mutex_unlock(&winreg_mutex);
64389dc44ceSjose borrego 		bzero(param, sizeof (struct winreg_EnumKey));
64489dc44ceSjose borrego 		param->status = ERROR_NOT_ENOUGH_MEMORY;
64589dc44ceSjose borrego 		return (NDR_DRC_OK);
64689dc44ceSjose borrego 	}
647*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
648*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_unlock(&winreg_mutex);
649*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
6507f667e74Sjose borrego 	/*
6517f667e74Sjose borrego 	 * This request requires that the length includes the null.
6527f667e74Sjose borrego 	 */
6537f667e74Sjose borrego 	param->name_out.length = param->name_out.allosize;
65489dc44ceSjose borrego 	param->status = ERROR_SUCCESS;
65589dc44ceSjose borrego 	return (NDR_DRC_OK);
65689dc44ceSjose borrego }
65789dc44ceSjose borrego 
65889dc44ceSjose borrego /*
65989dc44ceSjose borrego  * winreg_s_EnumValue
66089dc44ceSjose borrego  */
66189dc44ceSjose borrego static int
66289dc44ceSjose borrego winreg_s_EnumValue(void *arg, ndr_xa_t *mxa)
66389dc44ceSjose borrego {
66489dc44ceSjose borrego 	struct winreg_EnumValue *param = arg;
66589dc44ceSjose borrego 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
66689dc44ceSjose borrego 
66789dc44ceSjose borrego 	if (ndr_hdlookup(mxa, id) == NULL) {
66889dc44ceSjose borrego 		bzero(param, sizeof (struct winreg_EnumValue));
66989dc44ceSjose borrego 		param->status = ERROR_NO_MORE_ITEMS;
67089dc44ceSjose borrego 		return (NDR_DRC_OK);
67189dc44ceSjose borrego 	}
67289dc44ceSjose borrego 
67389dc44ceSjose borrego 	bzero(param, sizeof (struct winreg_EnumValue));
67489dc44ceSjose borrego 	param->status = ERROR_NO_MORE_ITEMS;
67589dc44ceSjose borrego 	return (NDR_DRC_OK);
67689dc44ceSjose borrego }
67789dc44ceSjose borrego 
67889dc44ceSjose borrego /*
67989dc44ceSjose borrego  * winreg_s_FlushKey
68089dc44ceSjose borrego  *
68189dc44ceSjose borrego  * Flush the attributes associated with the specified open key to disk.
68289dc44ceSjose borrego  */
68389dc44ceSjose borrego static int
68489dc44ceSjose borrego winreg_s_FlushKey(void *arg, ndr_xa_t *mxa)
68589dc44ceSjose borrego {
68689dc44ceSjose borrego 	struct winreg_FlushKey *param = arg;
68789dc44ceSjose borrego 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
68889dc44ceSjose borrego 
68989dc44ceSjose borrego 	if (ndr_hdlookup(mxa, id) == NULL)
69089dc44ceSjose borrego 		param->status = ERROR_INVALID_HANDLE;
69189dc44ceSjose borrego 	else
69289dc44ceSjose borrego 		param->status = ERROR_SUCCESS;
69389dc44ceSjose borrego 
69489dc44ceSjose borrego 	return (NDR_DRC_OK);
69589dc44ceSjose borrego }
69689dc44ceSjose borrego 
69789dc44ceSjose borrego /*
69889dc44ceSjose borrego  * winreg_s_GetKeySec
69989dc44ceSjose borrego  */
70089dc44ceSjose borrego static int
70189dc44ceSjose borrego winreg_s_GetKeySec(void *arg, ndr_xa_t *mxa)
70289dc44ceSjose borrego {
70396a62adaSjoyce mcintosh 	static struct winreg_secdesc	error_sd;
70489dc44ceSjose borrego 	struct winreg_GetKeySec		*param = arg;
705f96bd5c8SAlan Wright 	struct winreg_value		*sd_buf;
706f96bd5c8SAlan Wright 	smb_sd_t			sd;
707f96bd5c8SAlan Wright 	uint32_t			sd_len;
708f96bd5c8SAlan Wright 	uint32_t			status;
70989dc44ceSjose borrego 
710f96bd5c8SAlan Wright 	bzero(&sd, sizeof (smb_sd_t));
711f96bd5c8SAlan Wright 
712f96bd5c8SAlan Wright 	if ((status = winreg_sd_format(&sd)) != ERROR_SUCCESS)
713f96bd5c8SAlan Wright 		goto winreg_getkeysec_error;
714f96bd5c8SAlan Wright 
715f96bd5c8SAlan Wright 	sd_len = smb_sd_len(&sd, SMB_ALL_SECINFO);
71696a62adaSjoyce mcintosh 	sd_buf = NDR_MALLOC(mxa, sd_len + sizeof (struct winreg_value));
717f96bd5c8SAlan Wright 
718f96bd5c8SAlan Wright 	param->sd = NDR_MALLOC(mxa, sizeof (struct winreg_secdesc));
71996a62adaSjoyce mcintosh 	if ((param->sd == NULL) || (sd_buf == NULL)) {
720f96bd5c8SAlan Wright 		status = ERROR_NOT_ENOUGH_MEMORY;
721f96bd5c8SAlan Wright 		goto winreg_getkeysec_error;
722f96bd5c8SAlan Wright 	}
723f96bd5c8SAlan Wright 
724f96bd5c8SAlan Wright 	param->sd->sd_len = sd_len;
725f96bd5c8SAlan Wright 	param->sd->sd_size = sd_len;
726f96bd5c8SAlan Wright 	param->sd->sd_buf = sd_buf;
727f96bd5c8SAlan Wright 
728f96bd5c8SAlan Wright 	sd_buf->vc_first_is = 0;
729f96bd5c8SAlan Wright 	sd_buf->vc_length_is = sd_len;
730f96bd5c8SAlan Wright 	param->status = srvsvc_sd_set_relative(&sd, sd_buf->value);
731f96bd5c8SAlan Wright 
732f96bd5c8SAlan Wright 	smb_sd_term(&sd);
73389dc44ceSjose borrego 	return (NDR_DRC_OK);
734f96bd5c8SAlan Wright 
735f96bd5c8SAlan Wright winreg_getkeysec_error:
736f96bd5c8SAlan Wright 	smb_sd_term(&sd);
737f96bd5c8SAlan Wright 	bzero(param, sizeof (struct winreg_GetKeySec));
73896a62adaSjoyce mcintosh 	param->sd = &error_sd;
739f96bd5c8SAlan Wright 	param->status = status;
740f96bd5c8SAlan Wright 	return (NDR_DRC_OK);
741f96bd5c8SAlan Wright }
742f96bd5c8SAlan Wright 
743f96bd5c8SAlan Wright static uint32_t
744f96bd5c8SAlan Wright winreg_sd_format(smb_sd_t *sd)
745f96bd5c8SAlan Wright {
746f96bd5c8SAlan Wright 	smb_fssd_t	fs_sd;
747f96bd5c8SAlan Wright 	acl_t		*acl;
748f96bd5c8SAlan Wright 	uint32_t	status = ERROR_SUCCESS;
749f96bd5c8SAlan Wright 
750f96bd5c8SAlan Wright 	if (acl_fromtext("owner@:rwxpdDaARWcCos::allow", &acl) != 0)
751f96bd5c8SAlan Wright 		return (ERROR_NOT_ENOUGH_MEMORY);
752f96bd5c8SAlan Wright 
753f96bd5c8SAlan Wright 	smb_fssd_init(&fs_sd, SMB_ALL_SECINFO, SMB_FSSD_FLAGS_DIR);
754f96bd5c8SAlan Wright 	fs_sd.sd_uid = 0;
755f96bd5c8SAlan Wright 	fs_sd.sd_gid = 0;
756f96bd5c8SAlan Wright 	fs_sd.sd_zdacl = acl;
757f96bd5c8SAlan Wright 	fs_sd.sd_zsacl = NULL;
758f96bd5c8SAlan Wright 
759f96bd5c8SAlan Wright 	if (smb_sd_fromfs(&fs_sd, sd) != NT_STATUS_SUCCESS)
760f96bd5c8SAlan Wright 		status = ERROR_ACCESS_DENIED;
761f96bd5c8SAlan Wright 	smb_fssd_term(&fs_sd);
762f96bd5c8SAlan Wright 	return (status);
76389dc44ceSjose borrego }
76489dc44ceSjose borrego 
76589dc44ceSjose borrego /*
76689dc44ceSjose borrego  * winreg_s_NotifyChange
76789dc44ceSjose borrego  */
76889dc44ceSjose borrego static int
76989dc44ceSjose borrego winreg_s_NotifyChange(void *arg, ndr_xa_t *mxa)
77089dc44ceSjose borrego {
77189dc44ceSjose borrego 	struct winreg_NotifyChange *param = arg;
77289dc44ceSjose borrego 
77389dc44ceSjose borrego 	if (ndr_is_admin(mxa))
77489dc44ceSjose borrego 		param->status = ERROR_SUCCESS;
77589dc44ceSjose borrego 	else
77689dc44ceSjose borrego 		param->status = ERROR_ACCESS_DENIED;
77789dc44ceSjose borrego 
77889dc44ceSjose borrego 	return (NDR_DRC_OK);
77989dc44ceSjose borrego }
78089dc44ceSjose borrego 
78189dc44ceSjose borrego /*
78289dc44ceSjose borrego  * winreg_s_OpenKey
78389dc44ceSjose borrego  *
78489dc44ceSjose borrego  * This is a request to open a windows registry key.
78589dc44ceSjose borrego  * If we recognize the key, we return a handle.
78689dc44ceSjose borrego  *
78789dc44ceSjose borrego  * Returns:
78889dc44ceSjose borrego  *	ERROR_SUCCESS		Valid handle returned.
78989dc44ceSjose borrego  *	ERROR_FILE_NOT_FOUND	No key or unable to allocate a handle.
79089dc44ceSjose borrego  */
79189dc44ceSjose borrego static int
79289dc44ceSjose borrego winreg_s_OpenKey(void *arg, ndr_xa_t *mxa)
79389dc44ceSjose borrego {
79489dc44ceSjose borrego 	struct winreg_OpenKey *param = arg;
795b1352070SAlan Wright 	ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
796b1352070SAlan Wright 	ndr_handle_t *hd;
79789dc44ceSjose borrego 	char *subkey = (char *)param->name.str;
79889dc44ceSjose borrego 	winreg_subkey_t *key;
799*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
800*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_lock(&winreg_mutex);
80189dc44ceSjose borrego 
802b1352070SAlan Wright 	if (subkey == NULL || *subkey == '\0') {
803b1352070SAlan Wright 		if ((hd = ndr_hdlookup(mxa, id)) != NULL)
804b1352070SAlan Wright 			subkey = hd->nh_data;
805b1352070SAlan Wright 	}
806b1352070SAlan Wright 
807b1352070SAlan Wright 	id = NULL;
808b1352070SAlan Wright 
8097f667e74Sjose borrego 	if (subkey == NULL || list_is_empty(&winreg_keylist.kl_list)) {
810*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		(void) mutex_unlock(&winreg_mutex);
81189dc44ceSjose borrego 		bzero(&param->result_handle, sizeof (winreg_handle_t));
81289dc44ceSjose borrego 		param->status = ERROR_FILE_NOT_FOUND;
81389dc44ceSjose borrego 		return (NDR_DRC_OK);
81489dc44ceSjose borrego 	}
81589dc44ceSjose borrego 
81689dc44ceSjose borrego 	key = list_head(&winreg_keylist.kl_list);
81789dc44ceSjose borrego 	do {
81889dc44ceSjose borrego 		if (strcasecmp(subkey, key->sk_name) == 0) {
819*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 			if (key->sk_predefined == B_TRUE)
820*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 				id = winreg_alloc_id(mxa, subkey);
821*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 			else
82289dc44ceSjose borrego 				id = &key->sk_handle;
82389dc44ceSjose borrego 
82489dc44ceSjose borrego 			if (id == NULL)
82589dc44ceSjose borrego 				break;
82689dc44ceSjose borrego 
82789dc44ceSjose borrego 			bcopy(id, &param->result_handle,
82889dc44ceSjose borrego 			    sizeof (winreg_handle_t));
829*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
830*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 			(void) mutex_unlock(&winreg_mutex);
83189dc44ceSjose borrego 			param->status = ERROR_SUCCESS;
83289dc44ceSjose borrego 			return (NDR_DRC_OK);
83389dc44ceSjose borrego 		}
83489dc44ceSjose borrego 	} while ((key = list_next(&winreg_keylist.kl_list, key)) != NULL);
83589dc44ceSjose borrego 
836*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	(void) mutex_unlock(&winreg_mutex);
83789dc44ceSjose borrego 	bzero(&param->result_handle, sizeof (winreg_handle_t));
83889dc44ceSjose borrego 	param->status = ERROR_FILE_NOT_FOUND;
83989dc44ceSjose borrego 	return (NDR_DRC_OK);
84089dc44ceSjose borrego }
84189dc44ceSjose borrego 
84289dc44ceSjose borrego /*
84389dc44ceSjose borrego  * winreg_s_QueryKey
84489dc44ceSjose borrego  */
84589dc44ceSjose borrego /*ARGSUSED*/
84689dc44ceSjose borrego static int
84789dc44ceSjose borrego winreg_s_QueryKey(void *arg, ndr_xa_t *mxa)
84889dc44ceSjose borrego {
84989dc44ceSjose borrego 	struct winreg_QueryKey *param = arg;
85089dc44ceSjose borrego 	int rc;
85189dc44ceSjose borrego 	winreg_string_t	*name;
85289dc44ceSjose borrego 
85389dc44ceSjose borrego 	name = (winreg_string_t	*)&param->name;
85489dc44ceSjose borrego 	bzero(param, sizeof (struct winreg_QueryKey));
855*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
85689dc44ceSjose borrego 	if ((name = NDR_NEW(mxa, winreg_string_t)) != NULL)
85789dc44ceSjose borrego 		rc = NDR_MSTRING(mxa, "", (ndr_mstring_t *)name);
85889dc44ceSjose borrego 
85989dc44ceSjose borrego 	if ((name == NULL) || (rc != 0)) {
86089dc44ceSjose borrego 		bzero(param, sizeof (struct winreg_QueryKey));
86189dc44ceSjose borrego 		param->status = ERROR_NOT_ENOUGH_MEMORY;
86289dc44ceSjose borrego 		return (NDR_DRC_OK);
86389dc44ceSjose borrego 	}
86489dc44ceSjose borrego 
86589dc44ceSjose borrego 	param->status = ERROR_SUCCESS;
86689dc44ceSjose borrego 	return (NDR_DRC_OK);
86789dc44ceSjose borrego }
86889dc44ceSjose borrego 
86989dc44ceSjose borrego /*
87089dc44ceSjose borrego  * winreg_s_QueryValue
87189dc44ceSjose borrego  *
87289dc44ceSjose borrego  * This is a request to get the value associated with a specified name.
87389dc44ceSjose borrego  *
87489dc44ceSjose borrego  * Returns:
87589dc44ceSjose borrego  *	ERROR_SUCCESS		Value returned.
87689dc44ceSjose borrego  *	ERROR_FILE_NOT_FOUND	PrimaryModule is not supported.
87789dc44ceSjose borrego  *	ERROR_CANTREAD          No such name or memory problem.
87889dc44ceSjose borrego  */
87989dc44ceSjose borrego static int
88089dc44ceSjose borrego winreg_s_QueryValue(void *arg, ndr_xa_t *mxa)
88189dc44ceSjose borrego {
88289dc44ceSjose borrego 	struct winreg_QueryValue *param = arg;
88389dc44ceSjose borrego 	struct winreg_value *pv;
88489dc44ceSjose borrego 	char *name;
88589dc44ceSjose borrego 	char *value;
88689dc44ceSjose borrego 	DWORD slen;
88789dc44ceSjose borrego 	DWORD msize;
88889dc44ceSjose borrego 
88989dc44ceSjose borrego 	name = (char *)param->value_name.str;
89089dc44ceSjose borrego 
89189dc44ceSjose borrego 	if (strcasecmp(name, "PrimaryModule") == 0) {
89289dc44ceSjose borrego 		param->status = ERROR_FILE_NOT_FOUND;
89389dc44ceSjose borrego 		return (NDR_DRC_OK);
89489dc44ceSjose borrego 	}
89589dc44ceSjose borrego 
89689dc44ceSjose borrego 	if ((value = winreg_lookup_value(name)) == NULL) {
89789dc44ceSjose borrego 		param->status = ERROR_CANTREAD;
89889dc44ceSjose borrego 		return (NDR_DRC_OK);
89989dc44ceSjose borrego 	}
90089dc44ceSjose borrego 
901bbf6f00cSJordan Brown 	slen = smb_wcequiv_strlen(value) + sizeof (smb_wchar_t);
90289dc44ceSjose borrego 	msize = sizeof (struct winreg_value) + slen;
90389dc44ceSjose borrego 
90489dc44ceSjose borrego 	param->value = (struct winreg_value *)NDR_MALLOC(mxa, msize);
90589dc44ceSjose borrego 	param->type = NDR_NEW(mxa, DWORD);
90689dc44ceSjose borrego 	param->value_size = NDR_NEW(mxa, DWORD);
90789dc44ceSjose borrego 	param->value_size_total = NDR_NEW(mxa, DWORD);
90889dc44ceSjose borrego 
90989dc44ceSjose borrego 	if (param->value == NULL || param->type == NULL ||
91089dc44ceSjose borrego 	    param->value_size == NULL || param->value_size_total == NULL) {
91189dc44ceSjose borrego 		param->status = ERROR_CANTREAD;
91289dc44ceSjose borrego 		return (NDR_DRC_OK);
91389dc44ceSjose borrego 	}
91489dc44ceSjose borrego 
91589dc44ceSjose borrego 	bzero(param->value, msize);
91689dc44ceSjose borrego 	pv = param->value;
91789dc44ceSjose borrego 	pv->vc_first_is = 0;
91889dc44ceSjose borrego 	pv->vc_length_is = slen;
91989dc44ceSjose borrego 	/*LINTED E_BAD_PTR_CAST_ALIGN*/
920bbf6f00cSJordan Brown 	(void) ndr_mbstowcs(NULL, (smb_wchar_t *)pv->value, value, slen);
92189dc44ceSjose borrego 
92289dc44ceSjose borrego 	*param->type = 1;
92389dc44ceSjose borrego 	*param->value_size = slen;
92489dc44ceSjose borrego 	*param->value_size_total = slen;
92589dc44ceSjose borrego 
92689dc44ceSjose borrego 	param->status = ERROR_SUCCESS;
92789dc44ceSjose borrego 	return (NDR_DRC_OK);
92889dc44ceSjose borrego }
92989dc44ceSjose borrego 
93089dc44ceSjose borrego /*
93189dc44ceSjose borrego  * Lookup a name in the registry and return the associated value.
93289dc44ceSjose borrego  * Our registry is a case-insensitive, name-value pair table.
93389dc44ceSjose borrego  *
93489dc44ceSjose borrego  * Windows ProductType: WinNT, ServerNT, LanmanNT.
93589dc44ceSjose borrego  *	Windows NT4.0 workstation: WinNT
93689dc44ceSjose borrego  *	Windows NT4.0 server:      ServerNT
93789dc44ceSjose borrego  *
93889dc44ceSjose borrego  * If LanmanNT is used here, Windows 2000 sends LsarQueryInfoPolicy
93989dc44ceSjose borrego  * with info level 6, which we don't support.  If we use ServerNT
94089dc44ceSjose borrego  * (as reported by NT4.0 Server) Windows 2000 send requests for
94189dc44ceSjose borrego  * levels 3 and 5, which are support.
94289dc44ceSjose borrego  *
94389dc44ceSjose borrego  * On success, returns a pointer to the value.  Otherwise returns
94489dc44ceSjose borrego  * a null pointer.
94589dc44ceSjose borrego  */
94689dc44ceSjose borrego static char *
94789dc44ceSjose borrego winreg_lookup_value(const char *name)
94889dc44ceSjose borrego {
94989dc44ceSjose borrego 	static struct registry {
95089dc44ceSjose borrego 		char *name;
95189dc44ceSjose borrego 		char *value;
95289dc44ceSjose borrego 	} registry[] = {
953*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		{ "SystemRoot",		"C:\\" },
954*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		{ "CurrentVersion",	winreg_sysver },
95589dc44ceSjose borrego 		{ "ProductType",	"ServerNT" },
956*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		{ "Sources",		winreg_sysname }, /* product name */
957*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		{ "EventMessageFile",	"C:\\windows\\system32\\eventlog.dll" }
95889dc44ceSjose borrego 	};
95989dc44ceSjose borrego 
96089dc44ceSjose borrego 	int i;
96189dc44ceSjose borrego 
96289dc44ceSjose borrego 	for (i = 0; i < sizeof (registry)/sizeof (registry[0]); ++i) {
963*9fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 		if (strcasecmp(registry[i].name, name) == 0)
96489dc44ceSjose borrego 			return (registry[i].value);
96589dc44ceSjose borrego 	}
96689dc44ceSjose borrego 
96789dc44ceSjose borrego 	return (NULL);
96889dc44ceSjose borrego }
96989dc44ceSjose borrego 
97089dc44ceSjose borrego /*
97189dc44ceSjose borrego  * winreg_s_SetKeySec
97289dc44ceSjose borrego  */
97389dc44ceSjose borrego /*ARGSUSED*/
97489dc44ceSjose borrego static int
97589dc44ceSjose borrego winreg_s_SetKeySec(void *arg, ndr_xa_t *mxa)
97689dc44ceSjose borrego {
97789dc44ceSjose borrego 	struct winreg_SetKeySec *param = arg;
97889dc44ceSjose borrego 
97989dc44ceSjose borrego 	param->status = ERROR_ACCESS_DENIED;
98089dc44ceSjose borrego 	return (NDR_DRC_OK);
98189dc44ceSjose borrego }
98289dc44ceSjose borrego 
98389dc44ceSjose borrego /*
98489dc44ceSjose borrego  * winreg_s_CreateValue
98589dc44ceSjose borrego  */
98689dc44ceSjose borrego /*ARGSUSED*/
98789dc44ceSjose borrego static int
98889dc44ceSjose borrego winreg_s_CreateValue(void *arg, ndr_xa_t *mxa)
98989dc44ceSjose borrego {
99089dc44ceSjose borrego 	struct winreg_CreateValue *param = arg;
99189dc44ceSjose borrego 
99289dc44ceSjose borrego 	param->status = ERROR_ACCESS_DENIED;
99389dc44ceSjose borrego 	return (NDR_DRC_OK);
99489dc44ceSjose borrego }
99589dc44ceSjose borrego 
99689dc44ceSjose borrego /*
99789dc44ceSjose borrego  * winreg_s_Shutdown
99889dc44ceSjose borrego  *
99989dc44ceSjose borrego  * Attempt to shutdown or reboot the system: access denied.
100089dc44ceSjose borrego  */
100189dc44ceSjose borrego /*ARGSUSED*/
100289dc44ceSjose borrego static int
100389dc44ceSjose borrego winreg_s_Shutdown(void *arg, ndr_xa_t *mxa)
100489dc44ceSjose borrego {
100589dc44ceSjose borrego 	struct winreg_Shutdown *param = arg;
100689dc44ceSjose borrego 
100789dc44ceSjose borrego 	param->status = ERROR_ACCESS_DENIED;
100889dc44ceSjose borrego 	return (NDR_DRC_OK);
100989dc44ceSjose borrego }
101089dc44ceSjose borrego 
101189dc44ceSjose borrego /*
101289dc44ceSjose borrego  * winreg_s_AbortShutdown
101389dc44ceSjose borrego  *
101489dc44ceSjose borrego  * Abort a shutdown request.
101589dc44ceSjose borrego  */
101689dc44ceSjose borrego static int
101789dc44ceSjose borrego winreg_s_AbortShutdown(void *arg, ndr_xa_t *mxa)
101889dc44ceSjose borrego {
101989dc44ceSjose borrego 	struct winreg_AbortShutdown *param = arg;
102089dc44ceSjose borrego 
102189dc44ceSjose borrego 	if (ndr_is_admin(mxa))
102289dc44ceSjose borrego 		param->status = ERROR_SUCCESS;
102389dc44ceSjose borrego 	else
102489dc44ceSjose borrego 		param->status = ERROR_ACCESS_DENIED;
102589dc44ceSjose borrego 
102689dc44ceSjose borrego 	return (NDR_DRC_OK);
102789dc44ceSjose borrego }
102889dc44ceSjose borrego 
102989dc44ceSjose borrego /*
103089dc44ceSjose borrego  * winreg_s_GetVersion
103189dc44ceSjose borrego  *
103289dc44ceSjose borrego  * Return the windows registry version.  The current version is 5.
103389dc44ceSjose borrego  * This call is usually made prior to enumerating or querying registry
103489dc44ceSjose borrego  * keys or values.
103589dc44ceSjose borrego  */
103689dc44ceSjose borrego /*ARGSUSED*/
103789dc44ceSjose borrego static int
103889dc44ceSjose borrego winreg_s_GetVersion(void *arg, ndr_xa_t *mxa)
103989dc44ceSjose borrego {
104089dc44ceSjose borrego 	struct winreg_GetVersion *param = arg;
104189dc44ceSjose borrego 
104289dc44ceSjose borrego 	param->version = 5;
104389dc44ceSjose borrego 	param->status = ERROR_SUCCESS;
104489dc44ceSjose borrego 	return (NDR_DRC_OK);
104589dc44ceSjose borrego }
1046