s3:netlookup: make use of cli_credentials_init_anon()
[bbaumbach/samba-autobuild/.git] / source3 / utils / net_rpc_service.c
index 523eafd6533a37381e708c93352f16619e552c0c..35111a7931f6b100c0fe3a7122bf32e0576645f0 100644 (file)
@@ -23,7 +23,7 @@
 #include "../librpc/gen_ndr/ndr_svcctl_c.h"
 
 struct svc_state_msg {
-       uint32 flag;
+       uint32_t flag;
        const char *message;
 };
 
@@ -41,7 +41,7 @@ static struct svc_state_msg state_msg_table[] = {
 
 /********************************************************************
 ********************************************************************/
-const char *svc_status_string( uint32 state )
+const char *svc_status_string( uint32_t state )
 {
        fstring msg;
        int i;
@@ -134,11 +134,11 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd,
                                TALLOC_CTX *mem_ctx,
                                struct policy_handle *hSCM,
                                const char *service,
-                               uint32 *state )
+                               uint32_t *state )
 {
        struct policy_handle hService;
        struct SERVICE_STATUS service_status;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        NTSTATUS status;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
@@ -181,12 +181,12 @@ static WERROR watch_service_state(struct rpc_pipe_client *pipe_hnd,
                                TALLOC_CTX *mem_ctx,
                                struct policy_handle *hSCM,
                                const char *service,
-                               uint32 watch_state,
-                               uint32 *final_state )
+                               uint32_t watch_state,
+                               uint32_t *final_state )
 {
-       uint32 i;
-       uint32 state = 0;
-       WERROR result = WERR_GENERAL_FAILURE;
+       uint32_t i;
+       uint32_t state = 0;
+       WERROR result = WERR_GEN_FAILURE;
 
 
        i = 0;
@@ -216,14 +216,14 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd,
                                TALLOC_CTX *mem_ctx,
                                struct policy_handle *hSCM,
                                const char *service,
-                               uint32 control,
-                               uint32 watch_state )
+                               uint32_t control,
+                               uint32_t watch_state )
 {
        struct policy_handle hService;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        NTSTATUS status;
        struct SERVICE_STATUS service_status;
-       uint32 state = 0;
+       uint32_t state = 0;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        /* Open the Service */
@@ -284,12 +284,12 @@ static NTSTATUS rpc_service_list_internal(struct net_context *c,
 {
        struct policy_handle hSCM;
        struct ENUM_SERVICE_STATUSW *services = NULL;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        NTSTATUS status;
        int i;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
-       uint8_t *buffer = NULL;
+       uint8_t *buffer;
        uint32_t buf_size = 0;
        uint32_t bytes_needed = 0;
        uint32_t num_services = 0;
@@ -307,6 +307,12 @@ static NTSTATUS rpc_service_list_internal(struct net_context *c,
                return werror_to_ntstatus(result);
        }
 
+       buffer = talloc_array(mem_ctx, uint8_t, buf_size);
+       if (buffer == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
        do {
                status = dcerpc_svcctl_EnumServicesStatusW(b, mem_ctx,
                                                           &hSCM,
@@ -327,8 +333,12 @@ static NTSTATUS rpc_service_list_internal(struct net_context *c,
                }
 
                if (W_ERROR_EQUAL(result, WERR_MORE_DATA) && bytes_needed > 0) {
-                       buffer = talloc_array(mem_ctx, uint8_t, bytes_needed);
                        buf_size = bytes_needed;
+                       buffer = talloc_realloc(mem_ctx, buffer, uint8_t, bytes_needed);
+                       if (buffer == NULL) {
+                               status = NT_STATUS_NO_MEMORY;
+                               break;
+                       }
                        continue;
                }
 
@@ -381,6 +391,7 @@ static NTSTATUS rpc_service_list_internal(struct net_context *c,
 
        } while (W_ERROR_EQUAL(result, WERR_MORE_DATA));
 
+done:
        if (is_valid_policy_hnd(&hSCM)) {
                WERROR _result;
                dcerpc_svcctl_CloseServiceHandle(b, mem_ctx, &hSCM, &_result);
@@ -402,7 +413,7 @@ static NTSTATUS rpc_service_status_internal(struct net_context *c,
                                                const char **argv )
 {
        struct policy_handle hSCM, hService;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        NTSTATUS status;
        struct SERVICE_STATUS service_status;
        struct QUERY_SERVICE_CONFIG config;
@@ -551,7 +562,7 @@ static NTSTATUS rpc_service_stop_internal(struct net_context *c,
                                        const char **argv )
 {
        struct policy_handle hSCM;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        if (argc != 1 ) {
@@ -591,7 +602,7 @@ static NTSTATUS rpc_service_pause_internal(struct net_context *c,
                                        const char **argv )
 {
        struct policy_handle hSCM;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        if (argc != 1 ) {
@@ -631,7 +642,7 @@ static NTSTATUS rpc_service_resume_internal(struct net_context *c,
                                        const char **argv )
 {
        struct policy_handle hSCM;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        if (argc != 1 ) {
@@ -671,9 +682,9 @@ static NTSTATUS rpc_service_start_internal(struct net_context *c,
                                        const char **argv )
 {
        struct policy_handle hSCM, hService;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        NTSTATUS status;
-       uint32 state = 0;
+       uint32_t state = 0;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        if (argc != 1 ) {
@@ -754,7 +765,7 @@ static NTSTATUS rpc_service_delete_internal(struct net_context *c,
                                            const char **argv)
 {
        struct policy_handle hSCM, hService;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        NTSTATUS status;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
@@ -829,7 +840,7 @@ static NTSTATUS rpc_service_create_internal(struct net_context *c,
                                            const char **argv)
 {
        struct policy_handle hSCM, hService;
-       WERROR result = WERR_GENERAL_FAILURE;
+       WERROR result = WERR_GEN_FAILURE;
        NTSTATUS status;
        const char *ServiceName;
        const char *DisplayName;