1b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 2b89a8333Snatalie li - Sun Microsystems - Irvine United States * CDDL HEADER START 3b89a8333Snatalie li - Sun Microsystems - Irvine United States * 4b89a8333Snatalie li - Sun Microsystems - Irvine United States * The contents of this file are subject to the terms of the 5b89a8333Snatalie li - Sun Microsystems - Irvine United States * Common Development and Distribution License (the "License"). 6b89a8333Snatalie li - Sun Microsystems - Irvine United States * You may not use this file except in compliance with the License. 7b89a8333Snatalie li - Sun Microsystems - Irvine United States * 8b89a8333Snatalie li - Sun Microsystems - Irvine United States * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9b89a8333Snatalie li - Sun Microsystems - Irvine United States * or http://www.opensolaris.org/os/licensing. 10b89a8333Snatalie li - Sun Microsystems - Irvine United States * See the License for the specific language governing permissions 11b89a8333Snatalie li - Sun Microsystems - Irvine United States * and limitations under the License. 12b89a8333Snatalie li - Sun Microsystems - Irvine United States * 13b89a8333Snatalie li - Sun Microsystems - Irvine United States * When distributing Covered Code, include this CDDL HEADER in each 14b89a8333Snatalie li - Sun Microsystems - Irvine United States * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15b89a8333Snatalie li - Sun Microsystems - Irvine United States * If applicable, add the following below this CDDL HEADER, with the 16b89a8333Snatalie li - Sun Microsystems - Irvine United States * fields enclosed by brackets "[]" replaced with your own identifying 17b89a8333Snatalie li - Sun Microsystems - Irvine United States * information: Portions Copyright [yyyy] [name of copyright owner] 18b89a8333Snatalie li - Sun Microsystems - Irvine United States * 19b89a8333Snatalie li - Sun Microsystems - Irvine United States * CDDL HEADER END 20b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 21*148c5f43SAlan Wright 22b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 23*148c5f43SAlan Wright * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 24b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 25b89a8333Snatalie li - Sun Microsystems - Irvine United States 26b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 27b89a8333Snatalie li - Sun Microsystems - Irvine United States * Service Control Services (SVCCTL) RPC interface definition. 28b89a8333Snatalie li - Sun Microsystems - Irvine United States * This interface provides remote access to list SMF services 29b89a8333Snatalie li - Sun Microsystems - Irvine United States * from a Windows client. 30b89a8333Snatalie li - Sun Microsystems - Irvine United States * 31b89a8333Snatalie li - Sun Microsystems - Irvine United States * SVCCTL access is restricted to administrators: members of the 32b89a8333Snatalie li - Sun Microsystems - Irvine United States * Domain Admins or Administrators groups. 33b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 348d7e4166Sjose borrego 35b89a8333Snatalie li - Sun Microsystems - Irvine United States #include <stdio.h> 36b89a8333Snatalie li - Sun Microsystems - Irvine United States #include <strings.h> 37*148c5f43SAlan Wright 38*148c5f43SAlan Wright #include <smbsrv/libsmb.h> 39*148c5f43SAlan Wright #include <smbsrv/libmlsvc.h> 40b89a8333Snatalie li - Sun Microsystems - Irvine United States #include <smbsrv/nmpipes.h> 41037cac00Sjoyce mcintosh #include <smbsrv/ntifs.h> 421fcced4cSJordan Brown #include <smbsrv/winsvc.h> 431fcced4cSJordan Brown #include <smbsrv/ndl/svcctl.ndl> 441fcced4cSJordan Brown #include <smbsrv/libmlsvc.h> 45b89a8333Snatalie li - Sun Microsystems - Irvine United States 46037cac00Sjoyce mcintosh #define SVCCTL_SECURITY_BUFSIZE 256 47037cac00Sjoyce mcintosh #define SVCCTL_ENUMSERVICES_MINBUFSIZE 1024 48037cac00Sjoyce mcintosh 49b89a8333Snatalie li - Sun Microsystems - Irvine United States #define SVCCTL_OPENSVC_OP_UNIMPLEMENTED(S) \ 50b89a8333Snatalie li - Sun Microsystems - Irvine United States ((S) & SERVICE_CHANGE_CONFIG) || \ 51b89a8333Snatalie li - Sun Microsystems - Irvine United States ((S) & SERVICE_PAUSE_CONTINUE) || \ 52b89a8333Snatalie li - Sun Microsystems - Irvine United States ((S) & SERVICE_START) || \ 53b89a8333Snatalie li - Sun Microsystems - Irvine United States ((S) & SERVICE_STOP) || \ 54b89a8333Snatalie li - Sun Microsystems - Irvine United States ((S) & SERVICE_ENUMERATE_DEPENDENTS) 55b89a8333Snatalie li - Sun Microsystems - Irvine United States 56e3f2c991SKeyur Desai typedef union { 57e3f2c991SKeyur Desai uint8_t *svc_buf; 58e3f2c991SKeyur Desai svc_description_t *svc_desc; 59e3f2c991SKeyur Desai svc_failure_actions_t *svc_fac; 60e3f2c991SKeyur Desai svc_delayed_auto_start_t *svc_dstart; 61e3f2c991SKeyur Desai svc_config_failure_action_t *svc_cfa; 62e3f2c991SKeyur Desai } svc_config_rsp_t; 63e3f2c991SKeyur Desai 648d7e4166Sjose borrego static int svcctl_s_Close(void *, ndr_xa_t *); 65037cac00Sjoyce mcintosh static int svcctl_s_ControlService(void *, ndr_xa_t *); 66037cac00Sjoyce mcintosh static int svcctl_s_DeleteService(void *, ndr_xa_t *); 67037cac00Sjoyce mcintosh static int svcctl_s_QueryServiceSecurity(void *, ndr_xa_t *); 68037cac00Sjoyce mcintosh static int svcctl_s_SetServiceSecurity(void *, ndr_xa_t *); 698d7e4166Sjose borrego static int svcctl_s_OpenManager(void *, ndr_xa_t *); 708d7e4166Sjose borrego static int svcctl_s_OpenService(void *, ndr_xa_t *); 718d7e4166Sjose borrego static int svcctl_s_QueryServiceStatus(void *, ndr_xa_t *); 728d7e4166Sjose borrego static int svcctl_s_QueryServiceConfig(void *, ndr_xa_t *); 73037cac00Sjoyce mcintosh static int svcctl_s_StartService(void *, ndr_xa_t *); 74037cac00Sjoyce mcintosh static int svcctl_s_EnumDependentServices(void *, ndr_xa_t *); 758d7e4166Sjose borrego static int svcctl_s_EnumServicesStatus(void *, ndr_xa_t *); 768d7e4166Sjose borrego static int svcctl_s_GetServiceDisplayNameW(void *, ndr_xa_t *); 778d7e4166Sjose borrego static int svcctl_s_GetServiceKeyNameW(void *, ndr_xa_t *); 78037cac00Sjoyce mcintosh static int svcctl_s_OpenSCManagerA(void *, ndr_xa_t *); 79037cac00Sjoyce mcintosh static int svcctl_s_OpenServiceA(void *, ndr_xa_t *); 80037cac00Sjoyce mcintosh static int svcctl_s_EnumServicesStatusA(void *, ndr_xa_t *); 818d7e4166Sjose borrego static int svcctl_s_QueryServiceConfig2W(void *, ndr_xa_t *); 82037cac00Sjoyce mcintosh static int svcctl_s_QueryServiceStatusEx(void *, ndr_xa_t *); 83b89a8333Snatalie li - Sun Microsystems - Irvine United States 848d7e4166Sjose borrego static ndr_stub_table_t svcctl_stub_table[] = { 85b89a8333Snatalie li - Sun Microsystems - Irvine United States { svcctl_s_Close, SVCCTL_OPNUM_Close }, 86037cac00Sjoyce mcintosh { svcctl_s_ControlService, SVCCTL_OPNUM_ControlService }, 87037cac00Sjoyce mcintosh { svcctl_s_DeleteService, SVCCTL_OPNUM_DeleteService }, 88037cac00Sjoyce mcintosh { svcctl_s_QueryServiceSecurity, SVCCTL_OPNUM_QueryServiceSecurity }, 89037cac00Sjoyce mcintosh { svcctl_s_SetServiceSecurity, SVCCTL_OPNUM_SetServiceSecurity }, 90b89a8333Snatalie li - Sun Microsystems - Irvine United States { svcctl_s_OpenManager, SVCCTL_OPNUM_OpenManager }, 91b89a8333Snatalie li - Sun Microsystems - Irvine United States { svcctl_s_OpenService, SVCCTL_OPNUM_OpenService }, 92b89a8333Snatalie li - Sun Microsystems - Irvine United States { svcctl_s_QueryServiceStatus, SVCCTL_OPNUM_QueryServiceStatus }, 93b89a8333Snatalie li - Sun Microsystems - Irvine United States { svcctl_s_QueryServiceConfig, SVCCTL_OPNUM_QueryServiceConfig }, 94037cac00Sjoyce mcintosh { svcctl_s_StartService, SVCCTL_OPNUM_StartService }, 95037cac00Sjoyce mcintosh { svcctl_s_EnumDependentServices, 96037cac00Sjoyce mcintosh SVCCTL_OPNUM_EnumDependentServices }, 97b89a8333Snatalie li - Sun Microsystems - Irvine United States { svcctl_s_EnumServicesStatus, SVCCTL_OPNUM_EnumServicesStatus }, 98b89a8333Snatalie li - Sun Microsystems - Irvine United States { svcctl_s_GetServiceDisplayNameW, 99b89a8333Snatalie li - Sun Microsystems - Irvine United States SVCCTL_OPNUM_GetServiceDisplayNameW }, 100b89a8333Snatalie li - Sun Microsystems - Irvine United States { svcctl_s_GetServiceKeyNameW, SVCCTL_OPNUM_GetServiceKeyNameW }, 101037cac00Sjoyce mcintosh { svcctl_s_OpenSCManagerA, SVCCTL_OPNUM_OpenSCManagerA }, 102037cac00Sjoyce mcintosh { svcctl_s_OpenServiceA, SVCCTL_OPNUM_OpenServiceA }, 103037cac00Sjoyce mcintosh { svcctl_s_EnumServicesStatusA, SVCCTL_OPNUM_EnumServicesStatusA }, 104b89a8333Snatalie li - Sun Microsystems - Irvine United States { svcctl_s_QueryServiceConfig2W, SVCCTL_OPNUM_QueryServiceConfig2W }, 105037cac00Sjoyce mcintosh { svcctl_s_QueryServiceStatusEx, SVCCTL_OPNUM_QueryServiceStatusEx }, 106b89a8333Snatalie li - Sun Microsystems - Irvine United States {0} 107b89a8333Snatalie li - Sun Microsystems - Irvine United States }; 108b89a8333Snatalie li - Sun Microsystems - Irvine United States 1098d7e4166Sjose borrego static ndr_service_t svcctl_service = { 110b89a8333Snatalie li - Sun Microsystems - Irvine United States "SVCCTL", /* name */ 111b89a8333Snatalie li - Sun Microsystems - Irvine United States "Service Control Services", /* desc */ 112b89a8333Snatalie li - Sun Microsystems - Irvine United States "\\svcctl", /* endpoint */ 113b89a8333Snatalie li - Sun Microsystems - Irvine United States PIPE_NTSVCS, /* sec_addr_port */ 1148d7e4166Sjose borrego "367abb81-9844-35f1-ad32-98f038001003", 2, /* abstract */ 1158d7e4166Sjose borrego NDR_TRANSFER_SYNTAX_UUID, 2, /* transfer */ 116b89a8333Snatalie li - Sun Microsystems - Irvine United States 0, /* no bind_instance_size */ 117b89a8333Snatalie li - Sun Microsystems - Irvine United States 0, /* no bind_req() */ 118b89a8333Snatalie li - Sun Microsystems - Irvine United States 0, /* no unbind_and_close() */ 119b89a8333Snatalie li - Sun Microsystems - Irvine United States 0, /* use generic_call_stub() */ 120b89a8333Snatalie li - Sun Microsystems - Irvine United States &TYPEINFO(svcctl_interface), /* interface ti */ 121b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_stub_table /* stub_table */ 122b89a8333Snatalie li - Sun Microsystems - Irvine United States }; 123b89a8333Snatalie li - Sun Microsystems - Irvine United States 124b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 125b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_initialize 126b89a8333Snatalie li - Sun Microsystems - Irvine United States * 127b89a8333Snatalie li - Sun Microsystems - Irvine United States * This function registers the SVCCTL RPC interface with the RPC runtime 128b89a8333Snatalie li - Sun Microsystems - Irvine United States * library. It must be called in order to use either the client side 129b89a8333Snatalie li - Sun Microsystems - Irvine United States * or the server side functions. 130b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 131b89a8333Snatalie li - Sun Microsystems - Irvine United States void 132b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_initialize(void) 133b89a8333Snatalie li - Sun Microsystems - Irvine United States { 1348d7e4166Sjose borrego (void) ndr_svc_register(&svcctl_service); 1351fcced4cSJordan Brown svcctl_init(); 1361fcced4cSJordan Brown } 1371fcced4cSJordan Brown 1381fcced4cSJordan Brown void 1391fcced4cSJordan Brown svcctl_finalize(void) 1401fcced4cSJordan Brown { 1411fcced4cSJordan Brown svcctl_fini(); 142b89a8333Snatalie li - Sun Microsystems - Irvine United States } 143b89a8333Snatalie li - Sun Microsystems - Irvine United States 144b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 145b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_hdlookup 146b89a8333Snatalie li - Sun Microsystems - Irvine United States * 147b89a8333Snatalie li - Sun Microsystems - Irvine United States * Handle lookup wrapper to validate the local service and/or manager context. 148b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 149b89a8333Snatalie li - Sun Microsystems - Irvine United States static ndr_handle_t * 150b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_hdlookup(ndr_xa_t *mxa, ndr_hdid_t *id, svcctl_context_type_t type) 151b89a8333Snatalie li - Sun Microsystems - Irvine United States { 152b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 153b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_context_t *ctx; 154b89a8333Snatalie li - Sun Microsystems - Irvine United States 155b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((hd = ndr_hdlookup(mxa, id)) == NULL) 156b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 157b89a8333Snatalie li - Sun Microsystems - Irvine United States 158b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((ctx = (svcctl_context_t *)hd->nh_data) == NULL) 159b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 160b89a8333Snatalie li - Sun Microsystems - Irvine United States 161b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((ctx->c_type != type) || (ctx->c_ctx.uc_cp == NULL)) 162b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 163b89a8333Snatalie li - Sun Microsystems - Irvine United States 164b89a8333Snatalie li - Sun Microsystems - Irvine United States return (hd); 165b89a8333Snatalie li - Sun Microsystems - Irvine United States } 166b89a8333Snatalie li - Sun Microsystems - Irvine United States 167b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 168b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_hdfree 169b89a8333Snatalie li - Sun Microsystems - Irvine United States * 170b89a8333Snatalie li - Sun Microsystems - Irvine United States * Handle deallocation wrapper to free the local service and/or manager context. 171b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 172b89a8333Snatalie li - Sun Microsystems - Irvine United States static void 173b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_hdfree(ndr_xa_t *mxa, ndr_hdid_t *id) 174b89a8333Snatalie li - Sun Microsystems - Irvine United States { 175b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 176b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_context_t *ctx; 177b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 178b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_service_context_t *svc_ctx; 179b89a8333Snatalie li - Sun Microsystems - Irvine United States 180b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((hd = ndr_hdlookup(mxa, id)) != NULL) { 181b89a8333Snatalie li - Sun Microsystems - Irvine United States ctx = (svcctl_context_t *)hd->nh_data; 182b89a8333Snatalie li - Sun Microsystems - Irvine United States 183b89a8333Snatalie li - Sun Microsystems - Irvine United States switch (ctx->c_type) { 184b89a8333Snatalie li - Sun Microsystems - Irvine United States case SVCCTL_MANAGER_CONTEXT: 185b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = ctx->c_ctx.uc_mgr; 186b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_scm_fini(mgr_ctx); 187b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_scm_scf_handle_fini(mgr_ctx); 188b89a8333Snatalie li - Sun Microsystems - Irvine United States free(mgr_ctx); 189b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 190b89a8333Snatalie li - Sun Microsystems - Irvine United States 191b89a8333Snatalie li - Sun Microsystems - Irvine United States case SVCCTL_SERVICE_CONTEXT: 192b89a8333Snatalie li - Sun Microsystems - Irvine United States svc_ctx = ctx->c_ctx.uc_svc; 193b89a8333Snatalie li - Sun Microsystems - Irvine United States free(svc_ctx->sc_mgrid); 194b89a8333Snatalie li - Sun Microsystems - Irvine United States free(svc_ctx->sc_svcname); 195b89a8333Snatalie li - Sun Microsystems - Irvine United States free(svc_ctx); 196b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 197b89a8333Snatalie li - Sun Microsystems - Irvine United States 198b89a8333Snatalie li - Sun Microsystems - Irvine United States default: 199b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 200b89a8333Snatalie li - Sun Microsystems - Irvine United States } 201b89a8333Snatalie li - Sun Microsystems - Irvine United States 202b89a8333Snatalie li - Sun Microsystems - Irvine United States free(ctx); 203b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdfree(mxa, id); 204b89a8333Snatalie li - Sun Microsystems - Irvine United States } 205b89a8333Snatalie li - Sun Microsystems - Irvine United States } 206b89a8333Snatalie li - Sun Microsystems - Irvine United States 207b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 208b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_mgr_hdalloc 209b89a8333Snatalie li - Sun Microsystems - Irvine United States * 210b89a8333Snatalie li - Sun Microsystems - Irvine United States * Handle allocation wrapper to setup the local manager context. 211b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 212b89a8333Snatalie li - Sun Microsystems - Irvine United States static ndr_hdid_t * 213b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_mgr_hdalloc(ndr_xa_t *mxa) 214b89a8333Snatalie li - Sun Microsystems - Irvine United States { 215b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_context_t *ctx; 216b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 217b89a8333Snatalie li - Sun Microsystems - Irvine United States 218b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((ctx = malloc(sizeof (svcctl_context_t))) == NULL) 219b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 220b89a8333Snatalie li - Sun Microsystems - Irvine United States ctx->c_type = SVCCTL_MANAGER_CONTEXT; 221b89a8333Snatalie li - Sun Microsystems - Irvine United States 222b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((mgr_ctx = malloc(sizeof (svcctl_manager_context_t))) == NULL) { 223b89a8333Snatalie li - Sun Microsystems - Irvine United States free(ctx); 224b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 225b89a8333Snatalie li - Sun Microsystems - Irvine United States } 226b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(mgr_ctx, sizeof (svcctl_manager_context_t)); 227b89a8333Snatalie li - Sun Microsystems - Irvine United States 228b89a8333Snatalie li - Sun Microsystems - Irvine United States if (svcctl_scm_scf_handle_init(mgr_ctx) < 0) { 229b89a8333Snatalie li - Sun Microsystems - Irvine United States free(mgr_ctx); 230b89a8333Snatalie li - Sun Microsystems - Irvine United States free(ctx); 231b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 232b89a8333Snatalie li - Sun Microsystems - Irvine United States } 233b89a8333Snatalie li - Sun Microsystems - Irvine United States 234b89a8333Snatalie li - Sun Microsystems - Irvine United States if (svcctl_scm_init(mgr_ctx) < 0) { 235b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_scm_scf_handle_fini(mgr_ctx); 236b89a8333Snatalie li - Sun Microsystems - Irvine United States free(mgr_ctx); 237b89a8333Snatalie li - Sun Microsystems - Irvine United States free(ctx); 238b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 239b89a8333Snatalie li - Sun Microsystems - Irvine United States } 240b89a8333Snatalie li - Sun Microsystems - Irvine United States 241b89a8333Snatalie li - Sun Microsystems - Irvine United States ctx->c_ctx.uc_mgr = mgr_ctx; 242b89a8333Snatalie li - Sun Microsystems - Irvine United States 243b89a8333Snatalie li - Sun Microsystems - Irvine United States return (ndr_hdalloc(mxa, ctx)); 244b89a8333Snatalie li - Sun Microsystems - Irvine United States } 245b89a8333Snatalie li - Sun Microsystems - Irvine United States 246b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 247b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_get_mgr_ctx 248b89a8333Snatalie li - Sun Microsystems - Irvine United States * 249b89a8333Snatalie li - Sun Microsystems - Irvine United States * This function looks up a reference to local manager context. 250b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 251b89a8333Snatalie li - Sun Microsystems - Irvine United States static svcctl_manager_context_t * 252b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_get_mgr_ctx(ndr_xa_t *mxa, ndr_hdid_t *mgr_id) 253b89a8333Snatalie li - Sun Microsystems - Irvine United States { 254b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 255b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 256b89a8333Snatalie li - Sun Microsystems - Irvine United States 257b89a8333Snatalie li - Sun Microsystems - Irvine United States hd = svcctl_hdlookup(mxa, mgr_id, SVCCTL_MANAGER_CONTEXT); 258b89a8333Snatalie li - Sun Microsystems - Irvine United States if (hd == NULL) 259b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 260b89a8333Snatalie li - Sun Microsystems - Irvine United States 261b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_mgr; 262b89a8333Snatalie li - Sun Microsystems - Irvine United States 263b89a8333Snatalie li - Sun Microsystems - Irvine United States return (mgr_ctx); 264b89a8333Snatalie li - Sun Microsystems - Irvine United States } 265b89a8333Snatalie li - Sun Microsystems - Irvine United States 266b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 267b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_svc_hdalloc 268b89a8333Snatalie li - Sun Microsystems - Irvine United States * 269b89a8333Snatalie li - Sun Microsystems - Irvine United States * Handle allocation wrapper to setup the local service context. 270b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 271b89a8333Snatalie li - Sun Microsystems - Irvine United States static ndr_hdid_t * 272b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_svc_hdalloc(ndr_xa_t *mxa, ndr_hdid_t *mgr_id, char *svc_name) 273b89a8333Snatalie li - Sun Microsystems - Irvine United States { 274b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_context_t *ctx; 275b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_service_context_t *svc_ctx; 276b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 277b89a8333Snatalie li - Sun Microsystems - Irvine United States int max_name_sz = 0; 278b89a8333Snatalie li - Sun Microsystems - Irvine United States char *svcname; 279b89a8333Snatalie li - Sun Microsystems - Irvine United States 280b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = svcctl_get_mgr_ctx(mxa, mgr_id); 281b89a8333Snatalie li - Sun Microsystems - Irvine United States if (mgr_ctx == NULL) 282b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 283b89a8333Snatalie li - Sun Microsystems - Irvine United States max_name_sz = mgr_ctx->mc_scf_max_fmri_len; 284b89a8333Snatalie li - Sun Microsystems - Irvine United States 285b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((ctx = malloc(sizeof (svcctl_context_t))) == NULL) { 286b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_hdfree(mxa, mgr_id); 287b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 288b89a8333Snatalie li - Sun Microsystems - Irvine United States } 289b89a8333Snatalie li - Sun Microsystems - Irvine United States ctx->c_type = SVCCTL_SERVICE_CONTEXT; 290b89a8333Snatalie li - Sun Microsystems - Irvine United States 291b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((svc_ctx = malloc(sizeof (svcctl_service_context_t))) == NULL) { 292b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_hdfree(mxa, mgr_id); 293b89a8333Snatalie li - Sun Microsystems - Irvine United States free(ctx); 294b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 295b89a8333Snatalie li - Sun Microsystems - Irvine United States } 296b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(svc_ctx, sizeof (svcctl_service_context_t)); 297b89a8333Snatalie li - Sun Microsystems - Irvine United States 298b89a8333Snatalie li - Sun Microsystems - Irvine United States svc_ctx->sc_mgrid = malloc(sizeof (ndr_hdid_t)); 299b89a8333Snatalie li - Sun Microsystems - Irvine United States svcname = malloc(max_name_sz); 300b89a8333Snatalie li - Sun Microsystems - Irvine United States 301b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((svc_ctx->sc_mgrid == NULL) || (svcname == NULL)) { 302b89a8333Snatalie li - Sun Microsystems - Irvine United States free(svc_ctx->sc_mgrid); 303b89a8333Snatalie li - Sun Microsystems - Irvine United States free(svc_ctx); 304b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_hdfree(mxa, mgr_id); 305b89a8333Snatalie li - Sun Microsystems - Irvine United States free(ctx); 306b89a8333Snatalie li - Sun Microsystems - Irvine United States return (NULL); 307b89a8333Snatalie li - Sun Microsystems - Irvine United States } 308b89a8333Snatalie li - Sun Microsystems - Irvine United States 309b89a8333Snatalie li - Sun Microsystems - Irvine United States svc_ctx->sc_svcname = svcname; 310b89a8333Snatalie li - Sun Microsystems - Irvine United States 311b89a8333Snatalie li - Sun Microsystems - Irvine United States bcopy(mgr_id, svc_ctx->sc_mgrid, sizeof (ndr_hdid_t)); 312b89a8333Snatalie li - Sun Microsystems - Irvine United States (void) strlcpy(svc_ctx->sc_svcname, svc_name, max_name_sz); 313b89a8333Snatalie li - Sun Microsystems - Irvine United States 314b89a8333Snatalie li - Sun Microsystems - Irvine United States ctx->c_ctx.uc_svc = svc_ctx; 315b89a8333Snatalie li - Sun Microsystems - Irvine United States 316b89a8333Snatalie li - Sun Microsystems - Irvine United States return (ndr_hdalloc(mxa, ctx)); 317b89a8333Snatalie li - Sun Microsystems - Irvine United States } 318b89a8333Snatalie li - Sun Microsystems - Irvine United States 319b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 320b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_s_Close 321b89a8333Snatalie li - Sun Microsystems - Irvine United States * 322b89a8333Snatalie li - Sun Microsystems - Irvine United States * This is a request to close the SVCCTL interface specified by the 323b89a8333Snatalie li - Sun Microsystems - Irvine United States * handle. Free the handle and zero out the result handle for the 324b89a8333Snatalie li - Sun Microsystems - Irvine United States * client. 325b89a8333Snatalie li - Sun Microsystems - Irvine United States * 326b89a8333Snatalie li - Sun Microsystems - Irvine United States * Returns: 327b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SUCCESS 328b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_INVALID_HANDLE 329b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 330b89a8333Snatalie li - Sun Microsystems - Irvine United States static int 3318d7e4166Sjose borrego svcctl_s_Close(void *arg, ndr_xa_t *mxa) 332b89a8333Snatalie li - Sun Microsystems - Irvine United States { 333b89a8333Snatalie li - Sun Microsystems - Irvine United States struct svcctl_Close *param = arg; 334b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *id = (ndr_hdid_t *)¶m->handle; 335b89a8333Snatalie li - Sun Microsystems - Irvine United States 336b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_hdfree(mxa, id); 337b89a8333Snatalie li - Sun Microsystems - Irvine United States 338b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(¶m->result_handle, sizeof (svcctl_handle_t)); 339b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SUCCESS; 3408d7e4166Sjose borrego return (NDR_DRC_OK); 341b89a8333Snatalie li - Sun Microsystems - Irvine United States } 342b89a8333Snatalie li - Sun Microsystems - Irvine United States 343b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 344037cac00Sjoyce mcintosh * svcctl_s_ControlService 345037cac00Sjoyce mcintosh */ 346037cac00Sjoyce mcintosh static int 347037cac00Sjoyce mcintosh svcctl_s_ControlService(void *arg, ndr_xa_t *mxa) 348037cac00Sjoyce mcintosh { 349037cac00Sjoyce mcintosh struct svcctl_ControlService *param = arg; 350037cac00Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 351037cac00Sjoyce mcintosh ndr_handle_t *hd; 352037cac00Sjoyce mcintosh svcctl_manager_context_t *mgr_ctx; 353037cac00Sjoyce mcintosh svcctl_service_context_t *svc_ctx; 354037cac00Sjoyce mcintosh svcctl_svc_node_t *svc; 355037cac00Sjoyce mcintosh 356037cac00Sjoyce mcintosh hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 357037cac00Sjoyce mcintosh if (hd == NULL) { 358037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_ControlService)); 359037cac00Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 360037cac00Sjoyce mcintosh return (NDR_DRC_OK); 361037cac00Sjoyce mcintosh } 362037cac00Sjoyce mcintosh 363037cac00Sjoyce mcintosh svc_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_svc; 364037cac00Sjoyce mcintosh mgr_ctx = svcctl_get_mgr_ctx(mxa, svc_ctx->sc_mgrid); 365037cac00Sjoyce mcintosh if (mgr_ctx == NULL) { 366037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_ControlService)); 367037cac00Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 368037cac00Sjoyce mcintosh return (NDR_DRC_OK); 369037cac00Sjoyce mcintosh } 370037cac00Sjoyce mcintosh 371037cac00Sjoyce mcintosh switch (param->control) { 372037cac00Sjoyce mcintosh case SERVICE_CONTROL_STOP: 373037cac00Sjoyce mcintosh case SERVICE_CONTROL_PAUSE: 374037cac00Sjoyce mcintosh case SERVICE_CONTROL_CONTINUE: 375037cac00Sjoyce mcintosh case SERVICE_CONTROL_INTERROGATE: 376037cac00Sjoyce mcintosh case SERVICE_CONTROL_SHUTDOWN: 377037cac00Sjoyce mcintosh case SERVICE_CONTROL_PARAMCHANGE: 378037cac00Sjoyce mcintosh case SERVICE_CONTROL_NETBINDADD: 379037cac00Sjoyce mcintosh case SERVICE_CONTROL_NETBINDREMOVE: 380037cac00Sjoyce mcintosh case SERVICE_CONTROL_NETBINDENABLE: 381037cac00Sjoyce mcintosh case SERVICE_CONTROL_NETBINDDISABLE: 382037cac00Sjoyce mcintosh break; 383037cac00Sjoyce mcintosh default: 384037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_ControlService)); 385037cac00Sjoyce mcintosh param->status = ERROR_INVALID_PARAMETER; 386037cac00Sjoyce mcintosh return (NDR_DRC_OK); 387037cac00Sjoyce mcintosh } 388037cac00Sjoyce mcintosh 389037cac00Sjoyce mcintosh svc = svcctl_scm_find_service(mgr_ctx, svc_ctx->sc_svcname); 390037cac00Sjoyce mcintosh if (svc == NULL || svc->sn_state == NULL) { 391037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_ControlService)); 392037cac00Sjoyce mcintosh param->status = ERROR_SERVICE_DOES_NOT_EXIST; 393037cac00Sjoyce mcintosh return (NDR_DRC_OK); 394037cac00Sjoyce mcintosh } 395037cac00Sjoyce mcintosh 396037cac00Sjoyce mcintosh param->service_status.service_type = SERVICE_WIN32_SHARE_PROCESS; 397037cac00Sjoyce mcintosh param->service_status.cur_state = svcctl_scm_map_status(svc->sn_state); 398037cac00Sjoyce mcintosh param->service_status.ctrl_accepted = 0; 399037cac00Sjoyce mcintosh param->service_status.w32_exitcode = 0; 400037cac00Sjoyce mcintosh param->service_status.svc_specified_exitcode = 0; 401037cac00Sjoyce mcintosh param->service_status.check_point = 0; 402037cac00Sjoyce mcintosh param->service_status.wait_hint = 0; 403037cac00Sjoyce mcintosh 404037cac00Sjoyce mcintosh param->status = ERROR_SUCCESS; 405037cac00Sjoyce mcintosh return (NDR_DRC_OK); 406037cac00Sjoyce mcintosh } 407037cac00Sjoyce mcintosh 408037cac00Sjoyce mcintosh /* 409037cac00Sjoyce mcintosh * svcctl_s_DeleteService 410037cac00Sjoyce mcintosh */ 411037cac00Sjoyce mcintosh static int 412037cac00Sjoyce mcintosh svcctl_s_DeleteService(void *arg, ndr_xa_t *mxa) 413037cac00Sjoyce mcintosh { 414037cac00Sjoyce mcintosh struct svcctl_DeleteService *param = arg; 415037cac00Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 416037cac00Sjoyce mcintosh ndr_handle_t *hd; 417037cac00Sjoyce mcintosh 418037cac00Sjoyce mcintosh hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 419037cac00Sjoyce mcintosh if (hd == NULL) { 420037cac00Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 421037cac00Sjoyce mcintosh return (NDR_DRC_OK); 422037cac00Sjoyce mcintosh } 423037cac00Sjoyce mcintosh 424037cac00Sjoyce mcintosh param->status = ERROR_SUCCESS; 425037cac00Sjoyce mcintosh return (NDR_DRC_OK); 426037cac00Sjoyce mcintosh } 427037cac00Sjoyce mcintosh 428037cac00Sjoyce mcintosh /* 429037cac00Sjoyce mcintosh * svcctl_s_QueryServiceSecurity 430037cac00Sjoyce mcintosh */ 431037cac00Sjoyce mcintosh static int 432037cac00Sjoyce mcintosh svcctl_s_QueryServiceSecurity(void *arg, ndr_xa_t *mxa) 433037cac00Sjoyce mcintosh { 434037cac00Sjoyce mcintosh struct svcctl_QueryServiceSecurity *param = arg; 435037cac00Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 436037cac00Sjoyce mcintosh ndr_handle_t *hd; 437037cac00Sjoyce mcintosh uint32_t sec_info; 438037cac00Sjoyce mcintosh uint32_t bytes_needed = 0; 439037cac00Sjoyce mcintosh uint32_t status; 440037cac00Sjoyce mcintosh 441037cac00Sjoyce mcintosh hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 442037cac00Sjoyce mcintosh if (hd == NULL) { 443037cac00Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 444037cac00Sjoyce mcintosh goto query_service_security_error; 445037cac00Sjoyce mcintosh } 446037cac00Sjoyce mcintosh 447037cac00Sjoyce mcintosh sec_info = param->security_info & SMB_ALL_SECINFO; 448037cac00Sjoyce mcintosh if (sec_info == 0) { 449037cac00Sjoyce mcintosh status = ERROR_INVALID_PARAMETER; 450037cac00Sjoyce mcintosh goto query_service_security_error; 451037cac00Sjoyce mcintosh } 452037cac00Sjoyce mcintosh 453037cac00Sjoyce mcintosh if (param->buf_size < SVCCTL_SECURITY_BUFSIZE) { 454037cac00Sjoyce mcintosh bytes_needed = SVCCTL_SECURITY_BUFSIZE; 455037cac00Sjoyce mcintosh status = ERROR_INSUFFICIENT_BUFFER; 456037cac00Sjoyce mcintosh goto query_service_security_error; 457037cac00Sjoyce mcintosh } 458037cac00Sjoyce mcintosh 459037cac00Sjoyce mcintosh param->buffer = NDR_MALLOC(mxa, SVCCTL_SECURITY_BUFSIZE); 460037cac00Sjoyce mcintosh if (param->buffer == NULL) { 461037cac00Sjoyce mcintosh status = ERROR_NOT_ENOUGH_MEMORY; 462037cac00Sjoyce mcintosh goto query_service_security_error; 463037cac00Sjoyce mcintosh } 464037cac00Sjoyce mcintosh 465037cac00Sjoyce mcintosh bzero(param->buffer, sizeof (SVCCTL_SECURITY_BUFSIZE)); 466037cac00Sjoyce mcintosh param->buf_size = SVCCTL_SECURITY_BUFSIZE; 467037cac00Sjoyce mcintosh param->bytes_needed = 0; 468037cac00Sjoyce mcintosh param->status = ERROR_SUCCESS; 469037cac00Sjoyce mcintosh return (NDR_DRC_OK); 470037cac00Sjoyce mcintosh 471037cac00Sjoyce mcintosh query_service_security_error: 472037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_QueryServiceSecurity)); 473037cac00Sjoyce mcintosh param->buf_size = 0; 474037cac00Sjoyce mcintosh param->buffer = NDR_MALLOC(mxa, sizeof (uint32_t)); 475037cac00Sjoyce mcintosh param->bytes_needed = bytes_needed; 476037cac00Sjoyce mcintosh param->status = status; 477037cac00Sjoyce mcintosh return (NDR_DRC_OK); 478037cac00Sjoyce mcintosh } 479037cac00Sjoyce mcintosh 480037cac00Sjoyce mcintosh 481037cac00Sjoyce mcintosh /* 482037cac00Sjoyce mcintosh * svcctl_s_SetServiceSecurity 483037cac00Sjoyce mcintosh */ 484037cac00Sjoyce mcintosh static int 485037cac00Sjoyce mcintosh svcctl_s_SetServiceSecurity(void *arg, ndr_xa_t *mxa) 486037cac00Sjoyce mcintosh { 487037cac00Sjoyce mcintosh struct svcctl_SetServiceSecurity *param = arg; 488037cac00Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 489037cac00Sjoyce mcintosh ndr_handle_t *hd; 490037cac00Sjoyce mcintosh 491037cac00Sjoyce mcintosh hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 492037cac00Sjoyce mcintosh if (hd == NULL) { 493037cac00Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 494037cac00Sjoyce mcintosh return (NDR_DRC_OK); 495037cac00Sjoyce mcintosh } 496037cac00Sjoyce mcintosh 497037cac00Sjoyce mcintosh if ((param->security_info & SMB_ALL_SECINFO) == 0) { 498037cac00Sjoyce mcintosh param->status = ERROR_INVALID_PARAMETER; 499037cac00Sjoyce mcintosh return (NDR_DRC_OK); 500037cac00Sjoyce mcintosh } 501037cac00Sjoyce mcintosh 502037cac00Sjoyce mcintosh param->status = ERROR_ACCESS_DENIED; 503037cac00Sjoyce mcintosh return (NDR_DRC_OK); 504037cac00Sjoyce mcintosh } 505037cac00Sjoyce mcintosh 506037cac00Sjoyce mcintosh /* 507b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_s_OpenManager 508b89a8333Snatalie li - Sun Microsystems - Irvine United States * 509b89a8333Snatalie li - Sun Microsystems - Irvine United States * Request to open the service control manager. 510b89a8333Snatalie li - Sun Microsystems - Irvine United States * The caller must have administrator rights in order to open this 511b89a8333Snatalie li - Sun Microsystems - Irvine United States * interface. We don't support write (SC_MANAGER_LOCK) access. 512b89a8333Snatalie li - Sun Microsystems - Irvine United States * 513b89a8333Snatalie li - Sun Microsystems - Irvine United States * Returns: 514b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SUCCESS 515b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_ACCESS_DENIED 516b89a8333Snatalie li - Sun Microsystems - Irvine United States * 517b89a8333Snatalie li - Sun Microsystems - Irvine United States * On success, returns a handle for use with subsequent svcctl requests. 518b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 519b89a8333Snatalie li - Sun Microsystems - Irvine United States static int 5208d7e4166Sjose borrego svcctl_s_OpenManager(void *arg, ndr_xa_t *mxa) 521b89a8333Snatalie li - Sun Microsystems - Irvine United States { 522b89a8333Snatalie li - Sun Microsystems - Irvine United States struct svcctl_OpenManager *param = arg; 523b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *id = NULL; 524b89a8333Snatalie li - Sun Microsystems - Irvine United States int rc; 525b89a8333Snatalie li - Sun Microsystems - Irvine United States 526b89a8333Snatalie li - Sun Microsystems - Irvine United States rc = ndr_is_admin(mxa); 527b89a8333Snatalie li - Sun Microsystems - Irvine United States 528b89a8333Snatalie li - Sun Microsystems - Irvine United States if ((rc == 0) || (param->desired_access & SC_MANAGER_LOCK) != 0) { 529b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(¶m->handle, sizeof (svcctl_handle_t)); 530b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_ACCESS_DENIED; 5318d7e4166Sjose borrego return (NDR_DRC_OK); 532b89a8333Snatalie li - Sun Microsystems - Irvine United States } 533b89a8333Snatalie li - Sun Microsystems - Irvine United States 534b89a8333Snatalie li - Sun Microsystems - Irvine United States id = svcctl_mgr_hdalloc(mxa); 535b89a8333Snatalie li - Sun Microsystems - Irvine United States if (id) { 536b89a8333Snatalie li - Sun Microsystems - Irvine United States bcopy(id, ¶m->handle, sizeof (svcctl_handle_t)); 537b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SUCCESS; 538b89a8333Snatalie li - Sun Microsystems - Irvine United States } else { 539b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(¶m->handle, sizeof (svcctl_handle_t)); 540b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_ACCESS_DENIED; 541b89a8333Snatalie li - Sun Microsystems - Irvine United States } 542b89a8333Snatalie li - Sun Microsystems - Irvine United States 5438d7e4166Sjose borrego return (NDR_DRC_OK); 544b89a8333Snatalie li - Sun Microsystems - Irvine United States } 545b89a8333Snatalie li - Sun Microsystems - Irvine United States 546b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 547b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_s_OpenService 548b89a8333Snatalie li - Sun Microsystems - Irvine United States * 549b89a8333Snatalie li - Sun Microsystems - Irvine United States * Return a handle for use with subsequent svcctl requests. 550b89a8333Snatalie li - Sun Microsystems - Irvine United States * 551b89a8333Snatalie li - Sun Microsystems - Irvine United States * Returns: 552b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SUCCESS 553b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_INVALID_HANDLE 554b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SERVICE_DOES_NOT_EXIST 555b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_CALL_NOT_IMPLEMENTED 556b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 557b89a8333Snatalie li - Sun Microsystems - Irvine United States static int 5588d7e4166Sjose borrego svcctl_s_OpenService(void *arg, ndr_xa_t *mxa) 559b89a8333Snatalie li - Sun Microsystems - Irvine United States { 560b89a8333Snatalie li - Sun Microsystems - Irvine United States struct svcctl_OpenService *param = arg; 561b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *mgrid = (ndr_hdid_t *)¶m->manager_handle; 562b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *id = NULL; 563b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 564b89a8333Snatalie li - Sun Microsystems - Irvine United States DWORD status; 565b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 566b89a8333Snatalie li - Sun Microsystems - Irvine United States char *svc_name = (char *)param->service_name; 567b89a8333Snatalie li - Sun Microsystems - Irvine United States boolean_t unimplemented_operations = B_FALSE; 568b89a8333Snatalie li - Sun Microsystems - Irvine United States 569b89a8333Snatalie li - Sun Microsystems - Irvine United States /* Allow service handle allocations for only status & config queries */ 570b89a8333Snatalie li - Sun Microsystems - Irvine United States unimplemented_operations = 571b89a8333Snatalie li - Sun Microsystems - Irvine United States SVCCTL_OPENSVC_OP_UNIMPLEMENTED(param->desired_access); 572b89a8333Snatalie li - Sun Microsystems - Irvine United States 573b89a8333Snatalie li - Sun Microsystems - Irvine United States if (unimplemented_operations) { 574b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(¶m->service_handle, sizeof (svcctl_handle_t)); 575b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_CALL_NOT_IMPLEMENTED; 5768d7e4166Sjose borrego return (NDR_DRC_OK); 577b89a8333Snatalie li - Sun Microsystems - Irvine United States } 578b89a8333Snatalie li - Sun Microsystems - Irvine United States 579b89a8333Snatalie li - Sun Microsystems - Irvine United States hd = svcctl_hdlookup(mxa, mgrid, SVCCTL_MANAGER_CONTEXT); 580b89a8333Snatalie li - Sun Microsystems - Irvine United States if (hd == NULL) { 581b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(¶m->service_handle, sizeof (svcctl_handle_t)); 582b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_INVALID_HANDLE; 5838d7e4166Sjose borrego return (NDR_DRC_OK); 584b89a8333Snatalie li - Sun Microsystems - Irvine United States } 585b89a8333Snatalie li - Sun Microsystems - Irvine United States 586b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_mgr; 587b89a8333Snatalie li - Sun Microsystems - Irvine United States status = svcctl_scm_validate_service(mgr_ctx, svc_name); 588b89a8333Snatalie li - Sun Microsystems - Irvine United States if (status != ERROR_SUCCESS) { 589b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(¶m->service_handle, sizeof (svcctl_handle_t)); 590b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = status; 5918d7e4166Sjose borrego return (NDR_DRC_OK); 592b89a8333Snatalie li - Sun Microsystems - Irvine United States } 593b89a8333Snatalie li - Sun Microsystems - Irvine United States 594b89a8333Snatalie li - Sun Microsystems - Irvine United States id = svcctl_svc_hdalloc(mxa, mgrid, svc_name); 595b89a8333Snatalie li - Sun Microsystems - Irvine United States if (id) { 596b89a8333Snatalie li - Sun Microsystems - Irvine United States bcopy(id, ¶m->service_handle, sizeof (svcctl_handle_t)); 597b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SUCCESS; 598b89a8333Snatalie li - Sun Microsystems - Irvine United States } else { 599b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(¶m->service_handle, sizeof (svcctl_handle_t)); 600b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_ACCESS_DENIED; 601b89a8333Snatalie li - Sun Microsystems - Irvine United States } 602b89a8333Snatalie li - Sun Microsystems - Irvine United States 6038d7e4166Sjose borrego return (NDR_DRC_OK); 604b89a8333Snatalie li - Sun Microsystems - Irvine United States } 605b89a8333Snatalie li - Sun Microsystems - Irvine United States 606b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 607b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_s_QueryServiceStatus 608b89a8333Snatalie li - Sun Microsystems - Irvine United States * 609b89a8333Snatalie li - Sun Microsystems - Irvine United States * Returns: 610b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SUCCESS 611b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_INVALID_HANDLE 612b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 613b89a8333Snatalie li - Sun Microsystems - Irvine United States static int 6148d7e4166Sjose borrego svcctl_s_QueryServiceStatus(void *arg, ndr_xa_t *mxa) 615b89a8333Snatalie li - Sun Microsystems - Irvine United States { 616b89a8333Snatalie li - Sun Microsystems - Irvine United States struct svcctl_QueryServiceStatus *param = arg; 617b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 618b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 619b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 620b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_service_context_t *svc_ctx; 621b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_svc_node_t *svc; 622b89a8333Snatalie li - Sun Microsystems - Irvine United States 623b89a8333Snatalie li - Sun Microsystems - Irvine United States hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 624b89a8333Snatalie li - Sun Microsystems - Irvine United States if (hd == NULL) { 625b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_QueryServiceStatus)); 626b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_INVALID_HANDLE; 6278d7e4166Sjose borrego return (NDR_DRC_OK); 628b89a8333Snatalie li - Sun Microsystems - Irvine United States } 629b89a8333Snatalie li - Sun Microsystems - Irvine United States 630b89a8333Snatalie li - Sun Microsystems - Irvine United States svc_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_svc; 631b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = svcctl_get_mgr_ctx(mxa, svc_ctx->sc_mgrid); 632b89a8333Snatalie li - Sun Microsystems - Irvine United States if (mgr_ctx == NULL) { 633037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_QueryServiceStatus)); 634b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_INVALID_HANDLE; 6358d7e4166Sjose borrego return (NDR_DRC_OK); 636b89a8333Snatalie li - Sun Microsystems - Irvine United States } 637b89a8333Snatalie li - Sun Microsystems - Irvine United States 638b89a8333Snatalie li - Sun Microsystems - Irvine United States svc = svcctl_scm_find_service(mgr_ctx, svc_ctx->sc_svcname); 639b89a8333Snatalie li - Sun Microsystems - Irvine United States if (svc == NULL || svc->sn_state == NULL) { 640037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_QueryServiceStatus)); 641b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SERVICE_DOES_NOT_EXIST; 6428d7e4166Sjose borrego return (NDR_DRC_OK); 643b89a8333Snatalie li - Sun Microsystems - Irvine United States } 644b89a8333Snatalie li - Sun Microsystems - Irvine United States 645b89a8333Snatalie li - Sun Microsystems - Irvine United States param->service_status.service_type = SERVICE_WIN32_SHARE_PROCESS; 646b89a8333Snatalie li - Sun Microsystems - Irvine United States param->service_status.cur_state = svcctl_scm_map_status(svc->sn_state); 647b89a8333Snatalie li - Sun Microsystems - Irvine United States param->service_status.ctrl_accepted = 0; 648b89a8333Snatalie li - Sun Microsystems - Irvine United States param->service_status.w32_exitcode = 0; 649b89a8333Snatalie li - Sun Microsystems - Irvine United States param->service_status.svc_specified_exitcode = 0; 650b89a8333Snatalie li - Sun Microsystems - Irvine United States param->service_status.check_point = 0; 651b89a8333Snatalie li - Sun Microsystems - Irvine United States param->service_status.wait_hint = 0; 652b89a8333Snatalie li - Sun Microsystems - Irvine United States 653b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SUCCESS; 6548d7e4166Sjose borrego return (NDR_DRC_OK); 655b89a8333Snatalie li - Sun Microsystems - Irvine United States } 656b89a8333Snatalie li - Sun Microsystems - Irvine United States 657b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 658037cac00Sjoyce mcintosh * svcctl_s_EnumDependentServices 659037cac00Sjoyce mcintosh * 660037cac00Sjoyce mcintosh * Enumerate the list of services that depend on the specified service. 661037cac00Sjoyce mcintosh */ 662037cac00Sjoyce mcintosh static int 663037cac00Sjoyce mcintosh svcctl_s_EnumDependentServices(void *arg, ndr_xa_t *mxa) 664037cac00Sjoyce mcintosh { 665037cac00Sjoyce mcintosh struct svcctl_EnumDependentServices *param = arg; 666037cac00Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 667037cac00Sjoyce mcintosh ndr_handle_t *hd; 668037cac00Sjoyce mcintosh svcctl_manager_context_t *mgr_ctx; 669037cac00Sjoyce mcintosh svcctl_service_context_t *svc_ctx; 670037cac00Sjoyce mcintosh svcctl_svc_node_t *svc; 671037cac00Sjoyce mcintosh int input_bufsize = 0; 672037cac00Sjoyce mcintosh uint32_t status; 673037cac00Sjoyce mcintosh 674037cac00Sjoyce mcintosh hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 675037cac00Sjoyce mcintosh if (hd == NULL) { 676037cac00Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 677037cac00Sjoyce mcintosh goto enum_dependent_services_error; 678037cac00Sjoyce mcintosh } 679037cac00Sjoyce mcintosh 680037cac00Sjoyce mcintosh svc_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_svc; 681037cac00Sjoyce mcintosh mgr_ctx = svcctl_get_mgr_ctx(mxa, svc_ctx->sc_mgrid); 682037cac00Sjoyce mcintosh if (mgr_ctx == NULL) { 683037cac00Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 684037cac00Sjoyce mcintosh goto enum_dependent_services_error; 685037cac00Sjoyce mcintosh } 686037cac00Sjoyce mcintosh 687037cac00Sjoyce mcintosh svc = svcctl_scm_find_service(mgr_ctx, svc_ctx->sc_svcname); 688037cac00Sjoyce mcintosh if (svc == NULL || svc->sn_state == NULL) { 689037cac00Sjoyce mcintosh status = ERROR_SERVICE_DOES_NOT_EXIST; 690037cac00Sjoyce mcintosh goto enum_dependent_services_error; 691037cac00Sjoyce mcintosh } 692037cac00Sjoyce mcintosh 693037cac00Sjoyce mcintosh switch (param->svc_state) { 694037cac00Sjoyce mcintosh case SERVICE_STOPPED: 695037cac00Sjoyce mcintosh case SERVICE_START_PENDING: 696037cac00Sjoyce mcintosh case SERVICE_STOP_PENDING: 697037cac00Sjoyce mcintosh case SERVICE_RUNNING: 698037cac00Sjoyce mcintosh case SERVICE_CONTINUE_PENDING: 699037cac00Sjoyce mcintosh case SERVICE_PAUSE_PENDING: 700037cac00Sjoyce mcintosh case SERVICE_PAUSED: 701037cac00Sjoyce mcintosh break; 702037cac00Sjoyce mcintosh default: 703037cac00Sjoyce mcintosh status = ERROR_INVALID_PARAMETER; 704037cac00Sjoyce mcintosh goto enum_dependent_services_error; 705037cac00Sjoyce mcintosh } 706037cac00Sjoyce mcintosh 707037cac00Sjoyce mcintosh if ((input_bufsize = param->buf_size) == 0) { 708037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_EnumDependentServices)); 709037cac00Sjoyce mcintosh param->buf_size = input_bufsize; 710037cac00Sjoyce mcintosh param->services = NDR_STRDUP(mxa, ""); 711037cac00Sjoyce mcintosh param->bytes_needed = 1024; 712037cac00Sjoyce mcintosh param->svc_num = 0; 713037cac00Sjoyce mcintosh param->status = ERROR_MORE_DATA; 714037cac00Sjoyce mcintosh return (NDR_DRC_OK); 715037cac00Sjoyce mcintosh } 716037cac00Sjoyce mcintosh 717037cac00Sjoyce mcintosh param->services = NDR_MALLOC(mxa, input_bufsize); 718037cac00Sjoyce mcintosh if (param->services == NULL) { 719037cac00Sjoyce mcintosh status = ERROR_NOT_ENOUGH_MEMORY; 720037cac00Sjoyce mcintosh goto enum_dependent_services_error; 721037cac00Sjoyce mcintosh } 722037cac00Sjoyce mcintosh 723037cac00Sjoyce mcintosh bzero(param->services, input_bufsize); 724037cac00Sjoyce mcintosh param->buf_size = input_bufsize; 725037cac00Sjoyce mcintosh param->bytes_needed = 0; 726037cac00Sjoyce mcintosh param->svc_num = 0; 727037cac00Sjoyce mcintosh param->status = ERROR_SUCCESS; 728037cac00Sjoyce mcintosh return (NDR_DRC_OK); 729037cac00Sjoyce mcintosh 730037cac00Sjoyce mcintosh enum_dependent_services_error: 731037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_EnumDependentServices)); 732037cac00Sjoyce mcintosh param->services = NDR_STRDUP(mxa, ""); 733037cac00Sjoyce mcintosh param->status = status; 734037cac00Sjoyce mcintosh return (NDR_DRC_OK); 735037cac00Sjoyce mcintosh } 736037cac00Sjoyce mcintosh 737037cac00Sjoyce mcintosh /* 738b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_s_EnumServicesStatus 739b89a8333Snatalie li - Sun Microsystems - Irvine United States * 740037cac00Sjoyce mcintosh * Enumerate the list of services we support. 741b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 742b89a8333Snatalie li - Sun Microsystems - Irvine United States static int 7438d7e4166Sjose borrego svcctl_s_EnumServicesStatus(void *arg, ndr_xa_t *mxa) 744b89a8333Snatalie li - Sun Microsystems - Irvine United States { 745b89a8333Snatalie li - Sun Microsystems - Irvine United States struct svcctl_EnumServicesStatus *param = arg; 746b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *id = (ndr_hdid_t *)¶m->manager_handle; 747b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 748b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 749037cac00Sjoyce mcintosh uint32_t buf_size = 0; 750037cac00Sjoyce mcintosh uint32_t svc_num; 751037cac00Sjoyce mcintosh uint32_t resume_handle = 0; 752037cac00Sjoyce mcintosh uint32_t status; 753037cac00Sjoyce mcintosh 754037cac00Sjoyce mcintosh if (param->resume_handle != NULL) 755037cac00Sjoyce mcintosh resume_handle = *param->resume_handle; 756b89a8333Snatalie li - Sun Microsystems - Irvine United States 757b89a8333Snatalie li - Sun Microsystems - Irvine United States hd = svcctl_hdlookup(mxa, id, SVCCTL_MANAGER_CONTEXT); 758b89a8333Snatalie li - Sun Microsystems - Irvine United States if (hd == NULL) { 759037cac00Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 760037cac00Sjoyce mcintosh goto enum_services_status_error; 761b89a8333Snatalie li - Sun Microsystems - Irvine United States } 762b89a8333Snatalie li - Sun Microsystems - Irvine United States 763b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_mgr; 764b89a8333Snatalie li - Sun Microsystems - Irvine United States if (svcctl_scm_refresh(mgr_ctx) != 0) { 765037cac00Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 766037cac00Sjoyce mcintosh goto enum_services_status_error; 767b89a8333Snatalie li - Sun Microsystems - Irvine United States } 768b89a8333Snatalie li - Sun Microsystems - Irvine United States 769037cac00Sjoyce mcintosh buf_size = param->buf_size; 770037cac00Sjoyce mcintosh param->services = NDR_MALLOC(mxa, buf_size); 771b89a8333Snatalie li - Sun Microsystems - Irvine United States if (param->services == NULL) { 772037cac00Sjoyce mcintosh status = ERROR_NOT_ENOUGH_MEMORY; 773037cac00Sjoyce mcintosh goto enum_services_status_error; 774b89a8333Snatalie li - Sun Microsystems - Irvine United States } 775037cac00Sjoyce mcintosh bzero(param->services, buf_size); 776b89a8333Snatalie li - Sun Microsystems - Irvine United States 777037cac00Sjoyce mcintosh if (buf_size < SVCCTL_ENUMSERVICES_MINBUFSIZE) { 778b89a8333Snatalie li - Sun Microsystems - Irvine United States param->bytes_needed = mgr_ctx->mc_bytes_needed; 779b89a8333Snatalie li - Sun Microsystems - Irvine United States param->svc_num = 0; 780037cac00Sjoyce mcintosh if (param->resume_handle) 781037cac00Sjoyce mcintosh *param->resume_handle = 0; 782b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_MORE_DATA; 7838d7e4166Sjose borrego return (NDR_DRC_OK); 784b89a8333Snatalie li - Sun Microsystems - Irvine United States } 785b89a8333Snatalie li - Sun Microsystems - Irvine United States 786037cac00Sjoyce mcintosh svc_num = svcctl_scm_enum_services(mgr_ctx, param->services, 787037cac00Sjoyce mcintosh buf_size, &resume_handle, B_TRUE); 788b89a8333Snatalie li - Sun Microsystems - Irvine United States 789037cac00Sjoyce mcintosh param->buf_size = buf_size; 790037cac00Sjoyce mcintosh param->svc_num = svc_num; 791037cac00Sjoyce mcintosh 792037cac00Sjoyce mcintosh if (resume_handle != 0) { 793037cac00Sjoyce mcintosh if (param->resume_handle != NULL) 794037cac00Sjoyce mcintosh *param->resume_handle = resume_handle; 795037cac00Sjoyce mcintosh param->bytes_needed = mgr_ctx->mc_bytes_needed; 796037cac00Sjoyce mcintosh param->status = ERROR_MORE_DATA; 797037cac00Sjoyce mcintosh } else { 798037cac00Sjoyce mcintosh if (param->resume_handle) 799037cac00Sjoyce mcintosh *param->resume_handle = 0; 800b89a8333Snatalie li - Sun Microsystems - Irvine United States param->bytes_needed = 0; 801b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SUCCESS; 802037cac00Sjoyce mcintosh } 803037cac00Sjoyce mcintosh return (NDR_DRC_OK); 804037cac00Sjoyce mcintosh 805037cac00Sjoyce mcintosh enum_services_status_error: 806037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_EnumServicesStatus)); 807037cac00Sjoyce mcintosh param->services = NDR_STRDUP(mxa, ""); 808037cac00Sjoyce mcintosh param->status = status; 8098d7e4166Sjose borrego return (NDR_DRC_OK); 810b89a8333Snatalie li - Sun Microsystems - Irvine United States } 811b89a8333Snatalie li - Sun Microsystems - Irvine United States 812b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 813b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_s_QueryServiceConfig 814b89a8333Snatalie li - Sun Microsystems - Irvine United States * 815b89a8333Snatalie li - Sun Microsystems - Irvine United States * Returns: 816b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SUCCESS 817b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_INVALID_HANDLE 818b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 819b89a8333Snatalie li - Sun Microsystems - Irvine United States static int 8208d7e4166Sjose borrego svcctl_s_QueryServiceConfig(void *arg, ndr_xa_t *mxa) 821b89a8333Snatalie li - Sun Microsystems - Irvine United States { 822b89a8333Snatalie li - Sun Microsystems - Irvine United States struct svcctl_QueryServiceConfig *param = arg; 823b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 824b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 825b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 826b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_service_context_t *svc_ctx; 827b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_svc_node_t *svc; 828b89a8333Snatalie li - Sun Microsystems - Irvine United States int bytes_needed = 0; 829b89a8333Snatalie li - Sun Microsystems - Irvine United States svc_config_t *cfg; 830b89a8333Snatalie li - Sun Microsystems - Irvine United States 831b89a8333Snatalie li - Sun Microsystems - Irvine United States hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 832b89a8333Snatalie li - Sun Microsystems - Irvine United States if (hd == NULL) { 833b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_QueryServiceConfig)); 834b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_INVALID_HANDLE; 8358d7e4166Sjose borrego return (NDR_DRC_OK); 836b89a8333Snatalie li - Sun Microsystems - Irvine United States } 837b89a8333Snatalie li - Sun Microsystems - Irvine United States 838b89a8333Snatalie li - Sun Microsystems - Irvine United States svc_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_svc; 839b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = svcctl_get_mgr_ctx(mxa, svc_ctx->sc_mgrid); 840b89a8333Snatalie li - Sun Microsystems - Irvine United States if (mgr_ctx == NULL) { 841b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_QueryServiceConfig)); 842b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_INVALID_HANDLE; 8438d7e4166Sjose borrego return (NDR_DRC_OK); 844b89a8333Snatalie li - Sun Microsystems - Irvine United States } 845b89a8333Snatalie li - Sun Microsystems - Irvine United States 846b89a8333Snatalie li - Sun Microsystems - Irvine United States svc = svcctl_scm_find_service(mgr_ctx, svc_ctx->sc_svcname); 847b89a8333Snatalie li - Sun Microsystems - Irvine United States if (svc == NULL || svc->sn_fmri == NULL) { 848b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_QueryServiceConfig)); 849b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SERVICE_DOES_NOT_EXIST; 8508d7e4166Sjose borrego return (NDR_DRC_OK); 851b89a8333Snatalie li - Sun Microsystems - Irvine United States } 852b89a8333Snatalie li - Sun Microsystems - Irvine United States 853b89a8333Snatalie li - Sun Microsystems - Irvine United States cfg = ¶m->service_cfg; 854b89a8333Snatalie li - Sun Microsystems - Irvine United States cfg->service_type = SERVICE_WIN32_SHARE_PROCESS; 855b89a8333Snatalie li - Sun Microsystems - Irvine United States cfg->start_type = SERVICE_AUTO_START; 856e3f2c991SKeyur Desai cfg->error_control = SERVICE_ERROR_IGNORE; 8578d7e4166Sjose borrego cfg->binary_pathname = NDR_STRDUP(mxa, ""); 8588d7e4166Sjose borrego cfg->loadorder_group = NDR_STRDUP(mxa, ""); 859b89a8333Snatalie li - Sun Microsystems - Irvine United States cfg->tag_id = 0; 8608d7e4166Sjose borrego cfg->dependencies = NDR_STRDUP(mxa, ""); 8618d7e4166Sjose borrego cfg->service_startname = NDR_STRDUP(mxa, ""); 8628d7e4166Sjose borrego cfg->display_name = NDR_STRDUP(mxa, svc->sn_fmri); 863b89a8333Snatalie li - Sun Microsystems - Irvine United States 864b89a8333Snatalie li - Sun Microsystems - Irvine United States bytes_needed = sizeof (svc_config_t); 865b89a8333Snatalie li - Sun Microsystems - Irvine United States bytes_needed += SVCCTL_WNSTRLEN((const char *)cfg->binary_pathname); 866b89a8333Snatalie li - Sun Microsystems - Irvine United States bytes_needed += SVCCTL_WNSTRLEN((const char *)cfg->loadorder_group); 867b89a8333Snatalie li - Sun Microsystems - Irvine United States bytes_needed += SVCCTL_WNSTRLEN((const char *)cfg->dependencies); 868b89a8333Snatalie li - Sun Microsystems - Irvine United States bytes_needed += SVCCTL_WNSTRLEN((const char *)cfg->service_startname); 869b89a8333Snatalie li - Sun Microsystems - Irvine United States bytes_needed += SVCCTL_WNSTRLEN(svc->sn_fmri); 870b89a8333Snatalie li - Sun Microsystems - Irvine United States 871b89a8333Snatalie li - Sun Microsystems - Irvine United States if (param->buf_size < bytes_needed) { 872b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_QueryServiceConfig)); 873b89a8333Snatalie li - Sun Microsystems - Irvine United States param->cfg_bytes = bytes_needed; 874037cac00Sjoyce mcintosh param->status = ERROR_INSUFFICIENT_BUFFER; 8758d7e4166Sjose borrego return (NDR_DRC_OK); 876b89a8333Snatalie li - Sun Microsystems - Irvine United States } 877b89a8333Snatalie li - Sun Microsystems - Irvine United States 878b89a8333Snatalie li - Sun Microsystems - Irvine United States param->cfg_bytes = bytes_needed; 879b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SUCCESS; 8808d7e4166Sjose borrego return (NDR_DRC_OK); 881b89a8333Snatalie li - Sun Microsystems - Irvine United States } 882b89a8333Snatalie li - Sun Microsystems - Irvine United States 883b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 884037cac00Sjoyce mcintosh * svcctl_s_StartService 885037cac00Sjoyce mcintosh */ 886037cac00Sjoyce mcintosh static int 887037cac00Sjoyce mcintosh svcctl_s_StartService(void *arg, ndr_xa_t *mxa) 888037cac00Sjoyce mcintosh { 889037cac00Sjoyce mcintosh struct svcctl_StartService *param = arg; 890037cac00Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 891037cac00Sjoyce mcintosh ndr_handle_t *hd; 892037cac00Sjoyce mcintosh svcctl_manager_context_t *mgr_ctx; 893037cac00Sjoyce mcintosh svcctl_service_context_t *svc_ctx; 894037cac00Sjoyce mcintosh svcctl_svc_node_t *svc; 895037cac00Sjoyce mcintosh 896037cac00Sjoyce mcintosh hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 897037cac00Sjoyce mcintosh if (hd == NULL) { 898037cac00Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 899037cac00Sjoyce mcintosh return (NDR_DRC_OK); 900037cac00Sjoyce mcintosh } 901037cac00Sjoyce mcintosh 902037cac00Sjoyce mcintosh svc_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_svc; 903037cac00Sjoyce mcintosh mgr_ctx = svcctl_get_mgr_ctx(mxa, svc_ctx->sc_mgrid); 904037cac00Sjoyce mcintosh if (mgr_ctx == NULL) { 905037cac00Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 906037cac00Sjoyce mcintosh return (NDR_DRC_OK); 907037cac00Sjoyce mcintosh } 908037cac00Sjoyce mcintosh 909037cac00Sjoyce mcintosh svc = svcctl_scm_find_service(mgr_ctx, svc_ctx->sc_svcname); 910037cac00Sjoyce mcintosh if (svc == NULL || svc->sn_fmri == NULL) 911037cac00Sjoyce mcintosh param->status = ERROR_SERVICE_DOES_NOT_EXIST; 912037cac00Sjoyce mcintosh else 913037cac00Sjoyce mcintosh param->status = ERROR_SERVICE_ALREADY_RUNNING; 914037cac00Sjoyce mcintosh return (NDR_DRC_OK); 915037cac00Sjoyce mcintosh } 916037cac00Sjoyce mcintosh 917037cac00Sjoyce mcintosh 918037cac00Sjoyce mcintosh /* 919b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_s_GetServiceDisplayNameW 920b89a8333Snatalie li - Sun Microsystems - Irvine United States * 921b89a8333Snatalie li - Sun Microsystems - Irvine United States * Returns: 922b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SUCCESS 923b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_INVALID_HANDLE 924b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SERVICE_DOES_NOT_EXIST 925b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 926b89a8333Snatalie li - Sun Microsystems - Irvine United States static int 9278d7e4166Sjose borrego svcctl_s_GetServiceDisplayNameW(void *arg, ndr_xa_t *mxa) 928b89a8333Snatalie li - Sun Microsystems - Irvine United States { 929b89a8333Snatalie li - Sun Microsystems - Irvine United States struct svcctl_GetServiceDisplayNameW *param = arg; 930b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *id = (ndr_hdid_t *)¶m->manager_handle; 931b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 932b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_svc_node_t *svc; 933b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 934b89a8333Snatalie li - Sun Microsystems - Irvine United States 935b89a8333Snatalie li - Sun Microsystems - Irvine United States hd = svcctl_hdlookup(mxa, id, SVCCTL_MANAGER_CONTEXT); 936b89a8333Snatalie li - Sun Microsystems - Irvine United States if (hd == NULL) { 937b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_GetServiceDisplayNameW)); 9388d7e4166Sjose borrego param->display_name = NDR_STRDUP(mxa, ""); 939b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_INVALID_HANDLE; 9408d7e4166Sjose borrego return (NDR_DRC_OK); 941b89a8333Snatalie li - Sun Microsystems - Irvine United States } 942b89a8333Snatalie li - Sun Microsystems - Irvine United States 943b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_mgr; 944b89a8333Snatalie li - Sun Microsystems - Irvine United States svc = svcctl_scm_find_service(mgr_ctx, (char *)param->service_name); 945b89a8333Snatalie li - Sun Microsystems - Irvine United States if (svc == NULL || svc->sn_fmri == NULL) { 946b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_GetServiceDisplayNameW)); 9478d7e4166Sjose borrego param->display_name = NDR_STRDUP(mxa, ""); 948b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SERVICE_DOES_NOT_EXIST; 9498d7e4166Sjose borrego return (NDR_DRC_OK); 950b89a8333Snatalie li - Sun Microsystems - Irvine United States } 951b89a8333Snatalie li - Sun Microsystems - Irvine United States 9528d7e4166Sjose borrego param->display_name = NDR_STRDUP(mxa, svc->sn_fmri); 953b89a8333Snatalie li - Sun Microsystems - Irvine United States if (param->display_name == NULL) { 954b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_GetServiceDisplayNameW)); 9558d7e4166Sjose borrego param->display_name = NDR_STRDUP(mxa, ""); 956b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_NOT_ENOUGH_MEMORY; 9578d7e4166Sjose borrego return (NDR_DRC_OK); 958b89a8333Snatalie li - Sun Microsystems - Irvine United States } 959b89a8333Snatalie li - Sun Microsystems - Irvine United States 960b89a8333Snatalie li - Sun Microsystems - Irvine United States param->buf_size = strlen(svc->sn_fmri); 961b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SUCCESS; 9628d7e4166Sjose borrego return (NDR_DRC_OK); 963b89a8333Snatalie li - Sun Microsystems - Irvine United States } 964b89a8333Snatalie li - Sun Microsystems - Irvine United States 965b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 966b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_s_GetServiceKeyNameW 967b89a8333Snatalie li - Sun Microsystems - Irvine United States * 968b89a8333Snatalie li - Sun Microsystems - Irvine United States * Returns: 969b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SUCCESS 970b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_INVALID_HANDLE 971b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SERVICE_DOES_NOT_EXIST 972b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 973b89a8333Snatalie li - Sun Microsystems - Irvine United States static int 9748d7e4166Sjose borrego svcctl_s_GetServiceKeyNameW(void *arg, ndr_xa_t *mxa) 975b89a8333Snatalie li - Sun Microsystems - Irvine United States { 976b89a8333Snatalie li - Sun Microsystems - Irvine United States struct svcctl_GetServiceKeyNameW *param = arg; 977b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *id = (ndr_hdid_t *)¶m->manager_handle; 978b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 979b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_svc_node_t *svc; 980b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 981b89a8333Snatalie li - Sun Microsystems - Irvine United States 982b89a8333Snatalie li - Sun Microsystems - Irvine United States hd = svcctl_hdlookup(mxa, id, SVCCTL_MANAGER_CONTEXT); 983b89a8333Snatalie li - Sun Microsystems - Irvine United States if (hd == NULL) { 984b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_GetServiceKeyNameW)); 9858d7e4166Sjose borrego param->key_name = NDR_STRDUP(mxa, ""); 986b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_INVALID_HANDLE; 9878d7e4166Sjose borrego return (NDR_DRC_OK); 988b89a8333Snatalie li - Sun Microsystems - Irvine United States } 989b89a8333Snatalie li - Sun Microsystems - Irvine United States 990b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_mgr; 991b89a8333Snatalie li - Sun Microsystems - Irvine United States svc = svcctl_scm_find_service(mgr_ctx, (char *)param->service_name); 992b89a8333Snatalie li - Sun Microsystems - Irvine United States if (svc == NULL || svc->sn_name == NULL) { 993b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_GetServiceKeyNameW)); 9948d7e4166Sjose borrego param->key_name = NDR_STRDUP(mxa, ""); 995b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SERVICE_DOES_NOT_EXIST; 9968d7e4166Sjose borrego return (NDR_DRC_OK); 997b89a8333Snatalie li - Sun Microsystems - Irvine United States } 998b89a8333Snatalie li - Sun Microsystems - Irvine United States 9998d7e4166Sjose borrego param->key_name = NDR_STRDUP(mxa, svc->sn_name); 1000b89a8333Snatalie li - Sun Microsystems - Irvine United States if (param->key_name == NULL) { 1001b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_GetServiceKeyNameW)); 10028d7e4166Sjose borrego param->key_name = NDR_STRDUP(mxa, ""); 1003b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_NOT_ENOUGH_MEMORY; 10048d7e4166Sjose borrego return (NDR_DRC_OK); 1005b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1006b89a8333Snatalie li - Sun Microsystems - Irvine United States 1007b89a8333Snatalie li - Sun Microsystems - Irvine United States param->buf_size = strlen(svc->sn_name); 1008b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SUCCESS; 10098d7e4166Sjose borrego return (NDR_DRC_OK); 1010b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1011b89a8333Snatalie li - Sun Microsystems - Irvine United States 1012b89a8333Snatalie li - Sun Microsystems - Irvine United States /* 1013037cac00Sjoyce mcintosh * svcctl_s_OpenSCManagerA 1014037cac00Sjoyce mcintosh * 1015037cac00Sjoyce mcintosh * Request to open the service control manager. 1016037cac00Sjoyce mcintosh * The caller must have administrator rights in order to open this 1017037cac00Sjoyce mcintosh * interface. We don't support write (SC_MANAGER_LOCK) access. 1018037cac00Sjoyce mcintosh * 1019037cac00Sjoyce mcintosh * Returns: 1020037cac00Sjoyce mcintosh * ERROR_SUCCESS 1021037cac00Sjoyce mcintosh * ERROR_ACCESS_DENIED 1022037cac00Sjoyce mcintosh * 1023037cac00Sjoyce mcintosh * On success, returns a handle for use with subsequent svcctl requests. 1024037cac00Sjoyce mcintosh */ 1025037cac00Sjoyce mcintosh static int 1026037cac00Sjoyce mcintosh svcctl_s_OpenSCManagerA(void *arg, ndr_xa_t *mxa) 1027037cac00Sjoyce mcintosh { 1028037cac00Sjoyce mcintosh struct svcctl_OpenSCManagerA *param = arg; 1029037cac00Sjoyce mcintosh ndr_hdid_t *id = NULL; 1030037cac00Sjoyce mcintosh int rc; 1031037cac00Sjoyce mcintosh 1032037cac00Sjoyce mcintosh rc = ndr_is_admin(mxa); 1033037cac00Sjoyce mcintosh 1034037cac00Sjoyce mcintosh if ((rc == 0) || (param->desired_access & SC_MANAGER_LOCK) != 0) { 1035037cac00Sjoyce mcintosh bzero(¶m->handle, sizeof (svcctl_handle_t)); 1036037cac00Sjoyce mcintosh param->status = ERROR_ACCESS_DENIED; 1037037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1038037cac00Sjoyce mcintosh } 1039037cac00Sjoyce mcintosh 1040037cac00Sjoyce mcintosh id = svcctl_mgr_hdalloc(mxa); 1041037cac00Sjoyce mcintosh if (id) { 1042037cac00Sjoyce mcintosh bcopy(id, ¶m->handle, sizeof (svcctl_handle_t)); 1043037cac00Sjoyce mcintosh param->status = ERROR_SUCCESS; 1044037cac00Sjoyce mcintosh } else { 1045037cac00Sjoyce mcintosh bzero(¶m->handle, sizeof (svcctl_handle_t)); 1046037cac00Sjoyce mcintosh param->status = ERROR_ACCESS_DENIED; 1047037cac00Sjoyce mcintosh } 1048037cac00Sjoyce mcintosh 1049037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1050037cac00Sjoyce mcintosh } 1051037cac00Sjoyce mcintosh 1052037cac00Sjoyce mcintosh /* 1053037cac00Sjoyce mcintosh * svcctl_s_OpenServiceA 1054037cac00Sjoyce mcintosh * 1055037cac00Sjoyce mcintosh * Return a handle for use with subsequent svcctl requests. 1056037cac00Sjoyce mcintosh * 1057037cac00Sjoyce mcintosh * Returns: 1058037cac00Sjoyce mcintosh * ERROR_SUCCESS 1059037cac00Sjoyce mcintosh * ERROR_INVALID_HANDLE 1060037cac00Sjoyce mcintosh * ERROR_SERVICE_DOES_NOT_EXIST 1061037cac00Sjoyce mcintosh * ERROR_CALL_NOT_IMPLEMENTED 1062037cac00Sjoyce mcintosh */ 1063037cac00Sjoyce mcintosh static int 1064037cac00Sjoyce mcintosh svcctl_s_OpenServiceA(void *arg, ndr_xa_t *mxa) 1065037cac00Sjoyce mcintosh { 1066037cac00Sjoyce mcintosh struct svcctl_OpenServiceA *param = arg; 1067037cac00Sjoyce mcintosh ndr_hdid_t *mgrid = (ndr_hdid_t *)¶m->manager_handle; 1068037cac00Sjoyce mcintosh ndr_hdid_t *id = NULL; 1069037cac00Sjoyce mcintosh ndr_handle_t *hd; 1070037cac00Sjoyce mcintosh DWORD status; 1071037cac00Sjoyce mcintosh svcctl_manager_context_t *mgr_ctx; 1072037cac00Sjoyce mcintosh char *svc_name = (char *)param->service_name->value; 1073037cac00Sjoyce mcintosh boolean_t unimplemented_operations = B_FALSE; 1074037cac00Sjoyce mcintosh 1075037cac00Sjoyce mcintosh /* Allow service handle allocations for only status & config queries */ 1076037cac00Sjoyce mcintosh unimplemented_operations = 1077037cac00Sjoyce mcintosh SVCCTL_OPENSVC_OP_UNIMPLEMENTED(param->desired_access); 1078037cac00Sjoyce mcintosh 1079037cac00Sjoyce mcintosh if (unimplemented_operations) { 1080037cac00Sjoyce mcintosh bzero(¶m->service_handle, sizeof (svcctl_handle_t)); 1081037cac00Sjoyce mcintosh param->status = ERROR_CALL_NOT_IMPLEMENTED; 1082037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1083037cac00Sjoyce mcintosh } 1084037cac00Sjoyce mcintosh 1085037cac00Sjoyce mcintosh hd = svcctl_hdlookup(mxa, mgrid, SVCCTL_MANAGER_CONTEXT); 1086037cac00Sjoyce mcintosh if (hd == NULL) { 1087037cac00Sjoyce mcintosh bzero(¶m->service_handle, sizeof (svcctl_handle_t)); 1088037cac00Sjoyce mcintosh param->status = ERROR_INVALID_HANDLE; 1089037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1090037cac00Sjoyce mcintosh } 1091037cac00Sjoyce mcintosh 1092037cac00Sjoyce mcintosh mgr_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_mgr; 1093037cac00Sjoyce mcintosh status = svcctl_scm_validate_service(mgr_ctx, svc_name); 1094037cac00Sjoyce mcintosh if (status != ERROR_SUCCESS) { 1095037cac00Sjoyce mcintosh bzero(¶m->service_handle, sizeof (svcctl_handle_t)); 1096037cac00Sjoyce mcintosh param->status = status; 1097037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1098037cac00Sjoyce mcintosh } 1099037cac00Sjoyce mcintosh 1100037cac00Sjoyce mcintosh id = svcctl_svc_hdalloc(mxa, mgrid, svc_name); 1101037cac00Sjoyce mcintosh if (id) { 1102037cac00Sjoyce mcintosh bcopy(id, ¶m->service_handle, sizeof (svcctl_handle_t)); 1103037cac00Sjoyce mcintosh param->status = ERROR_SUCCESS; 1104037cac00Sjoyce mcintosh } else { 1105037cac00Sjoyce mcintosh bzero(¶m->service_handle, sizeof (svcctl_handle_t)); 1106037cac00Sjoyce mcintosh param->status = ERROR_ACCESS_DENIED; 1107037cac00Sjoyce mcintosh } 1108037cac00Sjoyce mcintosh 1109037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1110037cac00Sjoyce mcintosh } 1111037cac00Sjoyce mcintosh 1112037cac00Sjoyce mcintosh /* 1113037cac00Sjoyce mcintosh * svcctl_s_EnumServicesStatusA 1114037cac00Sjoyce mcintosh * 1115037cac00Sjoyce mcintosh * Enumerate the list of services we support as ASCII. 1116037cac00Sjoyce mcintosh */ 1117037cac00Sjoyce mcintosh static int 1118037cac00Sjoyce mcintosh svcctl_s_EnumServicesStatusA(void *arg, ndr_xa_t *mxa) 1119037cac00Sjoyce mcintosh { 1120037cac00Sjoyce mcintosh struct svcctl_EnumServicesStatusA *param = arg; 1121037cac00Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->manager_handle; 1122037cac00Sjoyce mcintosh ndr_handle_t *hd; 1123037cac00Sjoyce mcintosh svcctl_manager_context_t *mgr_ctx; 1124037cac00Sjoyce mcintosh uint32_t buf_size; 1125037cac00Sjoyce mcintosh uint32_t svc_num; 1126037cac00Sjoyce mcintosh uint32_t resume_handle = 0; 1127037cac00Sjoyce mcintosh uint32_t status; 1128037cac00Sjoyce mcintosh 1129037cac00Sjoyce mcintosh buf_size = param->buf_size; 1130037cac00Sjoyce mcintosh if (param->resume_handle != NULL) 1131037cac00Sjoyce mcintosh resume_handle = *param->resume_handle; 1132037cac00Sjoyce mcintosh 1133037cac00Sjoyce mcintosh hd = svcctl_hdlookup(mxa, id, SVCCTL_MANAGER_CONTEXT); 1134037cac00Sjoyce mcintosh if (hd == NULL) { 1135037cac00Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 1136037cac00Sjoyce mcintosh goto enum_services_status_error; 1137037cac00Sjoyce mcintosh } 1138037cac00Sjoyce mcintosh 1139037cac00Sjoyce mcintosh mgr_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_mgr; 1140037cac00Sjoyce mcintosh if (svcctl_scm_refresh(mgr_ctx) != 0) { 1141037cac00Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 1142037cac00Sjoyce mcintosh goto enum_services_status_error; 1143037cac00Sjoyce mcintosh } 1144037cac00Sjoyce mcintosh 1145037cac00Sjoyce mcintosh param->services = NDR_MALLOC(mxa, buf_size); 1146037cac00Sjoyce mcintosh if (param->services == NULL) { 1147037cac00Sjoyce mcintosh status = ERROR_NOT_ENOUGH_MEMORY; 1148037cac00Sjoyce mcintosh goto enum_services_status_error; 1149037cac00Sjoyce mcintosh } 1150037cac00Sjoyce mcintosh bzero(param->services, buf_size); 1151037cac00Sjoyce mcintosh 1152037cac00Sjoyce mcintosh svc_num = svcctl_scm_enum_services(mgr_ctx, param->services, 1153037cac00Sjoyce mcintosh buf_size, &resume_handle, B_FALSE); 1154037cac00Sjoyce mcintosh 1155037cac00Sjoyce mcintosh param->buf_size = buf_size; 1156037cac00Sjoyce mcintosh param->svc_num = svc_num; 1157037cac00Sjoyce mcintosh 1158037cac00Sjoyce mcintosh if (resume_handle != 0) { 1159037cac00Sjoyce mcintosh if (param->resume_handle != NULL) 1160037cac00Sjoyce mcintosh *param->resume_handle = resume_handle; 1161037cac00Sjoyce mcintosh param->bytes_needed = mgr_ctx->mc_bytes_needed; 1162037cac00Sjoyce mcintosh param->status = ERROR_MORE_DATA; 1163037cac00Sjoyce mcintosh } else { 1164037cac00Sjoyce mcintosh if (param->resume_handle) 1165037cac00Sjoyce mcintosh *param->resume_handle = 0; 1166037cac00Sjoyce mcintosh param->bytes_needed = 0; 1167037cac00Sjoyce mcintosh param->status = ERROR_SUCCESS; 1168037cac00Sjoyce mcintosh } 1169037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1170037cac00Sjoyce mcintosh 1171037cac00Sjoyce mcintosh enum_services_status_error: 1172037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_EnumServicesStatusA)); 1173037cac00Sjoyce mcintosh param->services = NDR_STRDUP(mxa, ""); 1174037cac00Sjoyce mcintosh param->status = status; 1175037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1176037cac00Sjoyce mcintosh } 1177037cac00Sjoyce mcintosh 1178037cac00Sjoyce mcintosh /* 1179b89a8333Snatalie li - Sun Microsystems - Irvine United States * svcctl_s_QueryServiceConfig2W 1180b89a8333Snatalie li - Sun Microsystems - Irvine United States * 1181b89a8333Snatalie li - Sun Microsystems - Irvine United States * Returns: 1182b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_SUCCESS 1183b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_INVALID_HANDLE 1184b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_INVALID_LEVEL 1185b89a8333Snatalie li - Sun Microsystems - Irvine United States * ERROR_NOT_ENOUGH_MEMORY 1186b89a8333Snatalie li - Sun Microsystems - Irvine United States */ 1187b89a8333Snatalie li - Sun Microsystems - Irvine United States static int 11888d7e4166Sjose borrego svcctl_s_QueryServiceConfig2W(void *arg, ndr_xa_t *mxa) 1189b89a8333Snatalie li - Sun Microsystems - Irvine United States { 1190b89a8333Snatalie li - Sun Microsystems - Irvine United States struct svcctl_QueryServiceConfig2W *param = arg; 1191b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 1192b89a8333Snatalie li - Sun Microsystems - Irvine United States ndr_handle_t *hd; 1193b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_manager_context_t *mgr_ctx; 1194b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_service_context_t *svc_ctx; 1195b89a8333Snatalie li - Sun Microsystems - Irvine United States svcctl_svc_node_t *svc; 1196e3f2c991SKeyur Desai svc_config_rsp_t svc_rsp; 1197b89a8333Snatalie li - Sun Microsystems - Irvine United States int offset, input_bufsize, bytes_needed = 0; 1198bbf6f00cSJordan Brown smb_wchar_t *wide_desc; 1199b89a8333Snatalie li - Sun Microsystems - Irvine United States char *desc; 1200b89a8333Snatalie li - Sun Microsystems - Irvine United States DWORD status; 1201b89a8333Snatalie li - Sun Microsystems - Irvine United States 1202b89a8333Snatalie li - Sun Microsystems - Irvine United States hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 1203b89a8333Snatalie li - Sun Microsystems - Irvine United States if (hd == NULL) { 1204b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_QueryServiceConfig2W)); 12058d7e4166Sjose borrego param->buffer = NDR_STRDUP(mxa, ""); 1206b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_INVALID_HANDLE; 12078d7e4166Sjose borrego return (NDR_DRC_OK); 1208b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1209b89a8333Snatalie li - Sun Microsystems - Irvine United States 1210b89a8333Snatalie li - Sun Microsystems - Irvine United States input_bufsize = param->buf_size; 12118d7e4166Sjose borrego param->buffer = NDR_MALLOC(mxa, input_bufsize); 1212b89a8333Snatalie li - Sun Microsystems - Irvine United States if (param->buffer == NULL) { 1213b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_QueryServiceConfig2W)); 12148d7e4166Sjose borrego param->buffer = NDR_STRDUP(mxa, ""); 1215b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_NOT_ENOUGH_MEMORY; 12168d7e4166Sjose borrego return (NDR_DRC_OK); 1217b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1218b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param->buffer, input_bufsize); 1219b89a8333Snatalie li - Sun Microsystems - Irvine United States 1220e3f2c991SKeyur Desai svc_rsp.svc_buf = param->buffer; 1221b89a8333Snatalie li - Sun Microsystems - Irvine United States status = ERROR_SUCCESS; 1222b89a8333Snatalie li - Sun Microsystems - Irvine United States switch (param->info_level) { 1223b89a8333Snatalie li - Sun Microsystems - Irvine United States case SERVICE_CONFIG_DESCRIPTION: 1224b89a8333Snatalie li - Sun Microsystems - Irvine United States svc_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_svc; 1225b89a8333Snatalie li - Sun Microsystems - Irvine United States mgr_ctx = svcctl_get_mgr_ctx(mxa, svc_ctx->sc_mgrid); 1226b89a8333Snatalie li - Sun Microsystems - Irvine United States if (mgr_ctx == NULL) { 1227b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_INVALID_HANDLE; 1228b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 1229b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1230b89a8333Snatalie li - Sun Microsystems - Irvine United States 1231b89a8333Snatalie li - Sun Microsystems - Irvine United States svc = svcctl_scm_find_service(mgr_ctx, svc_ctx->sc_svcname); 1232b89a8333Snatalie li - Sun Microsystems - Irvine United States if (svc == NULL || svc->sn_desc == NULL) { 1233b89a8333Snatalie li - Sun Microsystems - Irvine United States status = ERROR_SERVICE_DOES_NOT_EXIST; 1234b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 1235b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1236b89a8333Snatalie li - Sun Microsystems - Irvine United States 1237b89a8333Snatalie li - Sun Microsystems - Irvine United States desc = svc->sn_desc; 1238b89a8333Snatalie li - Sun Microsystems - Irvine United States bytes_needed = SVCCTL_WNSTRLEN(desc); 1239b89a8333Snatalie li - Sun Microsystems - Irvine United States 1240b89a8333Snatalie li - Sun Microsystems - Irvine United States if (input_bufsize <= bytes_needed) { 1241b89a8333Snatalie li - Sun Microsystems - Irvine United States param->bytes_needed = bytes_needed; 1242037cac00Sjoyce mcintosh param->status = ERROR_INSUFFICIENT_BUFFER; 12438d7e4166Sjose borrego return (NDR_DRC_OK); 1244b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1245b89a8333Snatalie li - Sun Microsystems - Irvine United States 1246b89a8333Snatalie li - Sun Microsystems - Irvine United States offset = sizeof (svc_description_t); 1247e3f2c991SKeyur Desai svc_rsp.svc_desc->desc = offset; 1248b89a8333Snatalie li - Sun Microsystems - Irvine United States /*LINTED E_BAD_PTR_CAST_ALIGN*/ 1249bbf6f00cSJordan Brown wide_desc = (smb_wchar_t *)¶m->buffer[offset]; 1250bbf6f00cSJordan Brown (void) smb_mbstowcs(wide_desc, desc, (strlen(desc) + 1)); 1251e3f2c991SKeyur Desai offset += SVCCTL_WNSTRLEN(desc); 1252b89a8333Snatalie li - Sun Microsystems - Irvine United States 1253b89a8333Snatalie li - Sun Microsystems - Irvine United States param->bytes_needed = offset; 1254b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 1255b89a8333Snatalie li - Sun Microsystems - Irvine United States 1256b89a8333Snatalie li - Sun Microsystems - Irvine United States case SERVICE_CONFIG_FAILURE_ACTIONS: 1257e3f2c991SKeyur Desai bzero(svc_rsp.svc_fac, sizeof (svc_failure_actions_t)); 1258e3f2c991SKeyur Desai bytes_needed = sizeof (svc_failure_actions_t); 1259e3f2c991SKeyur Desai if (input_bufsize <= bytes_needed) { 1260e3f2c991SKeyur Desai param->bytes_needed = bytes_needed; 1261e3f2c991SKeyur Desai param->status = ERROR_INSUFFICIENT_BUFFER; 1262e3f2c991SKeyur Desai return (NDR_DRC_OK); 1263e3f2c991SKeyur Desai } 1264e3f2c991SKeyur Desai param->bytes_needed = bytes_needed; 1265b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 1266b89a8333Snatalie li - Sun Microsystems - Irvine United States 1267e3f2c991SKeyur Desai case SERVICE_CONFIG_DELAYED_AUTO_START_INFO: 1268e3f2c991SKeyur Desai svc_rsp.svc_dstart->dstart = 0; 1269e3f2c991SKeyur Desai param->bytes_needed = sizeof (svc_delayed_auto_start_t); 1270e3f2c991SKeyur Desai break; 1271e3f2c991SKeyur Desai 1272e3f2c991SKeyur Desai case SERVICE_CONFIG_FAILURE_ACTIONS_FLAG: 1273e3f2c991SKeyur Desai svc_rsp.svc_cfa->cfa = 0; 1274e3f2c991SKeyur Desai param->bytes_needed = sizeof (svc_config_failure_action_t); 1275e3f2c991SKeyur Desai break; 1276e3f2c991SKeyur Desai 1277e3f2c991SKeyur Desai case SERVICE_CONFIG_SERVICE_SID_INFO: 1278e3f2c991SKeyur Desai case SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO: 1279e3f2c991SKeyur Desai case SERVICE_CONFIG_PRESHUTDOWN_INFO: 1280e3f2c991SKeyur Desai case SERVICE_CONFIG_TRIGGER_INFO: 1281e3f2c991SKeyur Desai case SERVICE_CONFIG_PREFERRED_NODE: 1282b89a8333Snatalie li - Sun Microsystems - Irvine United States default: 1283b89a8333Snatalie li - Sun Microsystems - Irvine United States status = ERROR_INVALID_LEVEL; 1284b89a8333Snatalie li - Sun Microsystems - Irvine United States break; 1285b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1286b89a8333Snatalie li - Sun Microsystems - Irvine United States 1287b89a8333Snatalie li - Sun Microsystems - Irvine United States if (status != ERROR_SUCCESS) { 1288b89a8333Snatalie li - Sun Microsystems - Irvine United States bzero(param, sizeof (struct svcctl_QueryServiceConfig2W)); 12898d7e4166Sjose borrego param->buffer = NDR_STRDUP(mxa, ""); 1290b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = status; 12918d7e4166Sjose borrego return (NDR_DRC_OK); 1292b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1293b89a8333Snatalie li - Sun Microsystems - Irvine United States 1294b89a8333Snatalie li - Sun Microsystems - Irvine United States param->status = ERROR_SUCCESS; 12958d7e4166Sjose borrego return (NDR_DRC_OK); 1296b89a8333Snatalie li - Sun Microsystems - Irvine United States } 1297037cac00Sjoyce mcintosh 1298037cac00Sjoyce mcintosh /* 1299037cac00Sjoyce mcintosh * svcctl_s_QueryServiceStatusEx 1300037cac00Sjoyce mcintosh */ 1301037cac00Sjoyce mcintosh static int 1302037cac00Sjoyce mcintosh svcctl_s_QueryServiceStatusEx(void *arg, ndr_xa_t *mxa) 1303037cac00Sjoyce mcintosh { 1304037cac00Sjoyce mcintosh struct svcctl_QueryServiceStatusEx *param = arg; 1305037cac00Sjoyce mcintosh ndr_hdid_t *id = (ndr_hdid_t *)¶m->service_handle; 1306037cac00Sjoyce mcintosh ndr_handle_t *hd; 1307037cac00Sjoyce mcintosh svcctl_manager_context_t *mgr_ctx; 1308037cac00Sjoyce mcintosh svcctl_service_context_t *svc_ctx; 1309037cac00Sjoyce mcintosh svcctl_svc_node_t *svc; 1310037cac00Sjoyce mcintosh svc_status_ex_t *svc_status_ex; 1311037cac00Sjoyce mcintosh uint32_t input_bufsize; 1312037cac00Sjoyce mcintosh uint32_t bytes_needed; 1313037cac00Sjoyce mcintosh DWORD status; 1314037cac00Sjoyce mcintosh 1315037cac00Sjoyce mcintosh hd = svcctl_hdlookup(mxa, id, SVCCTL_SERVICE_CONTEXT); 1316037cac00Sjoyce mcintosh if (hd == NULL) { 1317037cac00Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 1318037cac00Sjoyce mcintosh goto query_service_status_ex_error; 1319037cac00Sjoyce mcintosh } 1320037cac00Sjoyce mcintosh 1321037cac00Sjoyce mcintosh svc_ctx = ((svcctl_context_t *)hd->nh_data)->c_ctx.uc_svc; 1322037cac00Sjoyce mcintosh mgr_ctx = svcctl_get_mgr_ctx(mxa, svc_ctx->sc_mgrid); 1323037cac00Sjoyce mcintosh if (mgr_ctx == NULL) { 1324037cac00Sjoyce mcintosh status = ERROR_INVALID_HANDLE; 1325037cac00Sjoyce mcintosh goto query_service_status_ex_error; 1326037cac00Sjoyce mcintosh } 1327037cac00Sjoyce mcintosh 1328037cac00Sjoyce mcintosh if (param->info_level != SC_STATUS_PROCESS_INFO) { 1329037cac00Sjoyce mcintosh status = ERROR_INVALID_PARAMETER; 1330037cac00Sjoyce mcintosh goto query_service_status_ex_error; 1331037cac00Sjoyce mcintosh } 1332037cac00Sjoyce mcintosh 1333e3f2c991SKeyur Desai bytes_needed = sizeof (svc_status_ex_t); 1334037cac00Sjoyce mcintosh 1335037cac00Sjoyce mcintosh if ((input_bufsize = param->buf_size) < bytes_needed) { 1336037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_QueryServiceStatusEx)); 1337037cac00Sjoyce mcintosh param->buf_size = input_bufsize; 1338037cac00Sjoyce mcintosh param->buffer = NDR_STRDUP(mxa, ""); 1339037cac00Sjoyce mcintosh param->bytes_needed = bytes_needed; 1340037cac00Sjoyce mcintosh param->status = ERROR_INSUFFICIENT_BUFFER; 1341037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1342037cac00Sjoyce mcintosh } 1343037cac00Sjoyce mcintosh 1344037cac00Sjoyce mcintosh if ((svc_status_ex = NDR_MALLOC(mxa, bytes_needed)) == NULL) { 1345037cac00Sjoyce mcintosh status = ERROR_NOT_ENOUGH_MEMORY; 1346037cac00Sjoyce mcintosh goto query_service_status_ex_error; 1347037cac00Sjoyce mcintosh } 1348037cac00Sjoyce mcintosh 1349037cac00Sjoyce mcintosh svc = svcctl_scm_find_service(mgr_ctx, svc_ctx->sc_svcname); 1350037cac00Sjoyce mcintosh if (svc == NULL || svc->sn_state == NULL) { 1351037cac00Sjoyce mcintosh status = ERROR_SERVICE_DOES_NOT_EXIST; 1352037cac00Sjoyce mcintosh goto query_service_status_ex_error; 1353037cac00Sjoyce mcintosh } 1354037cac00Sjoyce mcintosh 1355037cac00Sjoyce mcintosh svc_status_ex->service_type = SERVICE_WIN32_SHARE_PROCESS; 1356037cac00Sjoyce mcintosh svc_status_ex->cur_state = svcctl_scm_map_status(svc->sn_state); 1357037cac00Sjoyce mcintosh svc_status_ex->ctrl_accepted = 0; 1358037cac00Sjoyce mcintosh svc_status_ex->w32_exitcode = 0; 1359037cac00Sjoyce mcintosh svc_status_ex->svc_specified_exitcode = 0; 1360037cac00Sjoyce mcintosh svc_status_ex->check_point = 0; 1361037cac00Sjoyce mcintosh svc_status_ex->wait_hint = 0; 1362037cac00Sjoyce mcintosh svc_status_ex->process_id = 1; 1363037cac00Sjoyce mcintosh svc_status_ex->service_flags = 1; 1364037cac00Sjoyce mcintosh 1365037cac00Sjoyce mcintosh param->buffer = (uint8_t *)svc_status_ex; 1366e3f2c991SKeyur Desai param->buf_size = input_bufsize; 1367e3f2c991SKeyur Desai param->bytes_needed = bytes_needed; 1368037cac00Sjoyce mcintosh param->status = ERROR_SUCCESS; 1369037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1370037cac00Sjoyce mcintosh 1371037cac00Sjoyce mcintosh query_service_status_ex_error: 1372037cac00Sjoyce mcintosh bzero(param, sizeof (struct svcctl_QueryServiceStatusEx)); 1373037cac00Sjoyce mcintosh param->buffer = NDR_STRDUP(mxa, ""); 1374037cac00Sjoyce mcintosh param->status = status; 1375037cac00Sjoyce mcintosh return (NDR_DRC_OK); 1376037cac00Sjoyce mcintosh } 1377