s3: Fix Coverity ID 242719 Uninitialized scalar variable
[sfrench/samba-autobuild/.git] / source3 / rpcclient / cmd_echo.c
index d9d14247f4d1b02156e1e90d5ac08a3ca56473a4..c1c97e339d7b5f162d6f7d1adbbbcae8a92e3ca6 100644 (file)
@@ -6,7 +6,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "rpcclient.h"
+#include "../librpc/gen_ndr/ndr_echo_c.h"
 
 static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                                 int argc, const char **argv)
 {
+       struct dcerpc_binding_handle *b = cli->binding_handle;
        uint32 request = 1, response;
-       NTSTATUS result;
+       NTSTATUS status;
 
        if (argc > 2) {
                printf("Usage: %s [num]\n", argv[0]);
                return NT_STATUS_OK;
        }
 
-       if (argc == 2)
+       if (argc == 2) {
                request = atoi(argv[1]);
+       }
 
-       result = rpccli_echo_AddOne(cli, mem_ctx, request, &response);
-
-       if (!NT_STATUS_IS_OK(result))
+       status = dcerpc_echo_AddOne(b, mem_ctx, request, &response);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
+       }
 
        printf("%d + 1 = %d\n", request, response);
 
 done:
-       return result;
+       return status;
 }
 
 static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                              int argc, const char **argv)
 {
+       struct dcerpc_binding_handle *b = cli->binding_handle;
        uint32 size, i;
-       NTSTATUS result;
+       NTSTATUS status;
        uint8_t *in_data = NULL, *out_data = NULL;
 
        if (argc != 2) {
@@ -63,27 +66,30 @@ static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
        if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
                printf("Failure to allocate buff of %d bytes\n",
                       size);
-               goto done;              
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
        }
        if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
                printf("Failure to allocate buff of %d bytes\n",
                       size);
-               goto done;              
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
        }
 
-       for (i = 0; i < size; i++)
+       for (i = 0; i < size; i++) {
                in_data[i] = i & 0xff;
+       }
 
-       result = rpccli_echo_EchoData(cli, mem_ctx, size, in_data, out_data);
-
-       if (!NT_STATUS_IS_OK(result))
+       status = dcerpc_echo_EchoData(b, mem_ctx, size, in_data, out_data);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
+       }
 
        for (i = 0; i < size; i++) {
                if (in_data[i] != out_data[i]) {
                        printf("mismatch at offset %d, %d != %d\n",
                               i, in_data[i], out_data[i]);
-                       result = NT_STATUS_UNSUCCESSFUL;
+                       status = NT_STATUS_UNSUCCESSFUL;
                }
        }
 
@@ -91,15 +97,16 @@ done:
        SAFE_FREE(in_data);
        SAFE_FREE(out_data);
 
-       return result;
+       return status;
 }
 
 static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli, 
                                     TALLOC_CTX *mem_ctx, int argc, 
                                     const char **argv)
 {
+       struct dcerpc_binding_handle *b = cli->binding_handle;
        uint32 size, i;
-       NTSTATUS result;
+       NTSTATUS status;
        uint8_t *out_data = NULL;
 
        if (argc != 2) {
@@ -111,32 +118,36 @@ static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
        if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
                printf("Failure to allocate buff of %d bytes\n",
                       size);
+               status = NT_STATUS_NO_MEMORY;
                goto done;              
        }
        
 
-       result = rpccli_echo_SourceData(cli, mem_ctx, size, out_data);
-
-       if (!NT_STATUS_IS_OK(result))
+       status = dcerpc_echo_SourceData(b, mem_ctx, size, out_data);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
+       }
 
        for (i = 0; i < size; i++) {
                if (out_data && out_data[i] != (i & 0xff)) {
                        printf("mismatch at offset %d, %d != %d\n",
                               i, out_data[i], i & 0xff);
-                       result = NT_STATUS_UNSUCCESSFUL;
+                       status = NT_STATUS_UNSUCCESSFUL;
                }
        }
 
 done:
-       return result;
+
+       SAFE_FREE(out_data);
+       return status;
 }
 
 static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                                   int argc, const char **argv)
 {
+       struct dcerpc_binding_handle *b = cli->binding_handle;
        uint32 size, i;
-       NTSTATUS result;
+       NTSTATUS status;
        uint8_t *in_data = NULL;
 
        if (argc != 2) {
@@ -148,21 +159,23 @@ static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_
        if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
                printf("Failure to allocate buff of %d bytes\n",
                       size);
+               status = NT_STATUS_NO_MEMORY;
                goto done;              
        }
 
-       for (i = 0; i < size; i++)
+       for (i = 0; i < size; i++) {
                in_data[i] = i & 0xff;
+       }
 
-       result = rpccli_echo_SinkData(cli, mem_ctx, size, in_data);
-
-       if (!NT_STATUS_IS_OK(result))
+       status = dcerpc_echo_SinkData(b, mem_ctx, size, in_data);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
+       }
 
 done:
        SAFE_FREE(in_data);
 
-       return result;
+       return status;
 }
 
 /* List of commands exported by this module */
@@ -171,9 +184,9 @@ struct cmd_set echo_commands[] = {
 
        { "ECHO" },
 
-       { "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one,     NULL, PI_RPCECHO, NULL, "Add one to a number", "" },
-       { "echodata",   RPC_RTYPE_NTSTATUS, cmd_echo_data,        NULL, PI_RPCECHO, NULL, "Echo data",           "" },
-       { "sinkdata",   RPC_RTYPE_NTSTATUS, cmd_echo_sink_data,   NULL, PI_RPCECHO, NULL, "Sink data",           "" },
-       { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, PI_RPCECHO, NULL, "Source data",         "" },
+       { "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one,     NULL, &ndr_table_rpcecho, NULL, "Add one to a number", "" },
+       { "echodata",   RPC_RTYPE_NTSTATUS, cmd_echo_data,        NULL, &ndr_table_rpcecho, NULL, "Echo data",           "" },
+       { "sinkdata",   RPC_RTYPE_NTSTATUS, cmd_echo_sink_data,   NULL, &ndr_table_rpcecho, NULL, "Sink data",           "" },
+       { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, &ndr_table_rpcecho, NULL, "Source data",         "" },
        { NULL }
 };