s3-spoolss: fix rpcclient after setprinter IDL fixes.
[ira/wip.git] / source3 / rpcclient / cmd_echo.c
index 81028dfb73922a53edbf567dc5f3cf2e63fecb03..cf5f9e00ef504e172782a6fd74e9a735a7160b14 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/cli_echo.h"
 
 static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                                 int argc, const char **argv)
@@ -52,7 +52,7 @@ static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
 {
        uint32 size, i;
        NTSTATUS result;
-       uint8 *in_data = NULL, *out_data = NULL;
+       uint8_t *in_data = NULL, *out_data = NULL;
 
        if (argc != 2) {
                printf("Usage: %s num\n", argv[0]);
@@ -60,8 +60,18 @@ static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
        }
 
        size = atoi(argv[1]);
-       in_data = (uint8 *)SMB_MALLOC(size);
-       out_data = (uint8 *)SMB_MALLOC(size);
+       if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
+               printf("Failure to allocate buff of %d bytes\n",
+                      size);
+               result = 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);
+               result = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
 
        for (i = 0; i < size; i++)
                in_data[i] = i & 0xff;
@@ -81,7 +91,7 @@ static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
 
 done:
        SAFE_FREE(in_data);
-       TALLOC_FREE(out_data);
+       SAFE_FREE(out_data);
 
        return result;
 }
@@ -92,7 +102,7 @@ static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
 {
        uint32 size, i;
        NTSTATUS result;
-       uint8 *out_data;
+       uint8_t *out_data = NULL;
 
        if (argc != 2) {
                printf("Usage: %s num\n", argv[0]);
@@ -100,15 +110,21 @@ static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
        }
 
        size = atoi(argv[1]);
+       if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
+               printf("Failure to allocate buff of %d bytes\n",
+                      size);
+               result = NT_STATUS_NO_MEMORY;
+               goto done;              
+       }
+       
 
-       out_data = SMB_MALLOC_ARRAY(uint8, size);
        result = rpccli_echo_SourceData(cli, mem_ctx, size, out_data);
 
        if (!NT_STATUS_IS_OK(result))
                goto done;
 
        for (i = 0; i < size; i++) {
-               if (out_data[i] != (i & 0xff)) {
+               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;
@@ -116,8 +132,8 @@ static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
        }
 
 done:
-       TALLOC_FREE(out_data);
 
+       SAFE_FREE(out_data);
        return result;
 }
 
@@ -126,7 +142,7 @@ static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_
 {
        uint32 size, i;
        NTSTATUS result;
-       uint8 *in_data = NULL;
+       uint8_t *in_data = NULL;
 
        if (argc != 2) {
                printf("Usage: %s num\n", argv[0]);
@@ -134,7 +150,12 @@ static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_
        }
 
        size = atoi(argv[1]);
-       in_data = (uint8 *)SMB_MALLOC(size);
+       if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
+               printf("Failure to allocate buff of %d bytes\n",
+                      size);
+               result = NT_STATUS_NO_MEMORY;
+               goto done;              
+       }
 
        for (i = 0; i < size; i++)
                in_data[i] = i & 0xff;
@@ -156,9 +177,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.syntax_id, NULL, "Add one to a number", "" },
+       { "echodata",   RPC_RTYPE_NTSTATUS, cmd_echo_data,        NULL, &ndr_table_rpcecho.syntax_id, NULL, "Echo data",           "" },
+       { "sinkdata",   RPC_RTYPE_NTSTATUS, cmd_echo_sink_data,   NULL, &ndr_table_rpcecho.syntax_id, NULL, "Sink data",           "" },
+       { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, &ndr_table_rpcecho.syntax_id, NULL, "Source data",         "" },
        { NULL }
 };