diff options
author | Günther Deschner <gd@samba.org> | 2011-01-12 19:00:16 +0100 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2011-01-13 12:17:30 +0100 |
commit | 3e2821acda1dd2197b82048e80ef190f46068832 (patch) | |
tree | bc91e41cecfa70b4f1e01becd365183a6ed4f863 | |
parent | 5ad7d6aaa8f0067e23ce5ef892026a0898fc1068 (diff) | |
download | samba-3e2821acda1dd2197b82048e80ef190f46068832.tar.gz samba-3e2821acda1dd2197b82048e80ef190f46068832.tar.bz2 samba-3e2821acda1dd2197b82048e80ef190f46068832.zip |
s3-net: restructure "net rpc service" and add open_service().
Guenther
Signed-off-by: Andreas Schneider <asn@samba.org>
-rw-r--r-- | source3/utils/net_rpc_service.c | 124 |
1 files changed, 49 insertions, 75 deletions
diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 8968c46b70..22394ca3a0 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -60,25 +60,21 @@ const char *svc_status_string( uint32 state ) /******************************************************************** ********************************************************************/ -static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, - struct policy_handle *hSCM, - const char *service, - uint32 *state ) +static WERROR open_service(struct dcerpc_binding_handle *b, + TALLOC_CTX *mem_ctx, + struct policy_handle *hSCM, + const char *service, + uint32_t access_mask, + struct policy_handle *hService) { - struct policy_handle hService; - struct SERVICE_STATUS service_status; - WERROR result = WERR_GENERAL_FAILURE; NTSTATUS status; - struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; - - /* now cycle until the status is actually 'watch_state' */ + WERROR result; status = dcerpc_svcctl_OpenServiceW(b, mem_ctx, hSCM, service, - SC_RIGHT_SVC_QUERY_STATUS, - &hService, + access_mask, + hService, &result); if (!NT_STATUS_IS_OK(status)) { result = ntstatus_to_werror(status); @@ -92,6 +88,33 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, return result; } + return WERR_OK; +} + +/******************************************************************** +********************************************************************/ + +static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + struct policy_handle *hSCM, + const char *service, + uint32 *state ) +{ + struct policy_handle hService; + struct SERVICE_STATUS service_status; + WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; + struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; + + /* now cycle until the status is actually 'watch_state' */ + + result = open_service(b, mem_ctx, hSCM, service, + SC_RIGHT_SVC_QUERY_STATUS, + &hService); + if (!W_ERROR_IS_OK(result) ) { + return result; + } + status = dcerpc_svcctl_QueryServiceStatus(b, mem_ctx, &hService, &service_status, @@ -169,23 +192,11 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, /* Open the Service */ - status = dcerpc_svcctl_OpenServiceW(b, mem_ctx, - hSCM, - service, - (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE), - &hService, - &result); - if (!NT_STATUS_IS_OK(status)) { - result = ntstatus_to_werror(status); - d_fprintf(stderr, _("Failed to open service. [%s]\n"), - nt_errstr(status)); - goto done; - } - + result = open_service(b, mem_ctx, hSCM, service, + (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE), + &hService); if (!W_ERROR_IS_OK(result) ) { - d_fprintf(stderr, _("Failed to open service. [%s]\n"), - win_errstr(result)); - goto done; + return result; } /* get the status */ @@ -402,22 +413,10 @@ static NTSTATUS rpc_service_status_internal(struct net_context *c, /* Open the Service */ - status = dcerpc_svcctl_OpenServiceW(b, mem_ctx, - &hSCM, - argv[0], - (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG), - &hService, - &result); - - if (!NT_STATUS_IS_OK(status)) { - result = ntstatus_to_werror(status); - d_fprintf(stderr, _("Failed to open service. [%s]\n"), - nt_errstr(status)); - goto done; - } + result = open_service(b, mem_ctx, &hSCM, argv[0], + (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG), + &hService); if (!W_ERROR_IS_OK(result) ) { - d_fprintf(stderr, _("Failed to open service. [%s]\n"), - win_errstr(result)); goto done; } @@ -741,22 +740,10 @@ static NTSTATUS rpc_service_start_internal(struct net_context *c, /* Open the Service */ - status = dcerpc_svcctl_OpenServiceW(b, mem_ctx, - &hSCM, - argv[0], - SC_RIGHT_SVC_START, - &hService, - &result); - if (!NT_STATUS_IS_OK(status)) { - result = ntstatus_to_werror(status); - d_fprintf(stderr, _("Failed to open service. [%s]\n"), - nt_errstr(status)); - goto done; - } - + result = open_service(b, mem_ctx, &hSCM, argv[0], + SC_RIGHT_SVC_START, + &hService); if (!W_ERROR_IS_OK(result) ) { - d_fprintf(stderr, _("Failed to open service. [%s]\n"), - win_errstr(result)); goto done; } @@ -849,23 +836,10 @@ static NTSTATUS rpc_service_delete_internal(struct net_context *c, /* Open the Service */ - status = dcerpc_svcctl_OpenServiceW(b, mem_ctx, - &hSCM, - argv[0], - SERVICE_ALL_ACCESS, - &hService, - &result); - - if (!NT_STATUS_IS_OK(status)) { - result = ntstatus_to_werror(status); - d_fprintf(stderr, _("Failed to open service. [%s]\n"), - nt_errstr(status)); - goto done; - } - + result = open_service(b, mem_ctx, &hSCM, argv[0], + SERVICE_ALL_ACCESS, + &hService); if (!W_ERROR_IS_OK(result) ) { - d_fprintf(stderr, _("Failed to open service. [%s]\n"), - win_errstr(result)); goto done; } |