rpcclient/cmd_echo.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    RPC pipe client
00004 
00005    Copyright (C) Tim Potter 2003
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011    
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016    
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 */
00021 
00022 #include "includes.h"
00023 #include "rpcclient.h"
00024 
00025 static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
00026                                  int argc, const char **argv)
00027 {
00028         uint32 request = 1, response;
00029         NTSTATUS result;
00030 
00031         if (argc > 2) {
00032                 printf("Usage: %s [num]\n", argv[0]);
00033                 return NT_STATUS_OK;
00034         }
00035 
00036         if (argc == 2)
00037                 request = atoi(argv[1]);
00038 
00039         result = rpccli_echo_add_one(cli, mem_ctx, request, &response);
00040 
00041         if (!NT_STATUS_IS_OK(result))
00042                 goto done;
00043 
00044         printf("%d + 1 = %d\n", request, response);
00045 
00046 done:
00047         return result;
00048 }
00049 
00050 static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
00051                               int argc, const char **argv)
00052 {
00053         uint32 size, i;
00054         NTSTATUS result;
00055         char *in_data = NULL, *out_data = NULL;
00056 
00057         if (argc != 2) {
00058                 printf("Usage: %s num\n", argv[0]);
00059                 return NT_STATUS_OK;
00060         }
00061 
00062         size = atoi(argv[1]);
00063         in_data = SMB_MALLOC(size);
00064 
00065         for (i = 0; i < size; i++)
00066                 in_data[i] = i & 0xff;
00067 
00068         result = rpccli_echo_data(cli, mem_ctx, size, in_data, &out_data);
00069 
00070         if (!NT_STATUS_IS_OK(result))
00071                 goto done;
00072 
00073         for (i = 0; i < size; i++) {
00074                 if (in_data[i] != out_data[i]) {
00075                         printf("mismatch at offset %d, %d != %d\n",
00076                                i, in_data[i], out_data[i]);
00077                         result = NT_STATUS_UNSUCCESSFUL;
00078                 }
00079         }
00080 
00081 done:
00082         SAFE_FREE(in_data);
00083 
00084         return result;
00085 }
00086 
00087 static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli, 
00088                                      TALLOC_CTX *mem_ctx, int argc, 
00089                                      const char **argv)
00090 {
00091         uint32 size, i;
00092         NTSTATUS result;
00093         char *out_data = NULL;
00094 
00095         if (argc != 2) {
00096                 printf("Usage: %s num\n", argv[0]);
00097                 return NT_STATUS_OK;
00098         }
00099 
00100         size = atoi(argv[1]);
00101 
00102         result = rpccli_echo_source_data(cli, mem_ctx, size, &out_data);
00103 
00104         if (!NT_STATUS_IS_OK(result))
00105                 goto done;
00106 
00107         for (i = 0; i < size; i++) {
00108                 if (out_data && out_data[i] != (i & 0xff)) {
00109                         printf("mismatch at offset %d, %d != %d\n",
00110                                i, out_data[i], i & 0xff);
00111                         result = NT_STATUS_UNSUCCESSFUL;
00112                 }
00113         }
00114 
00115 done:
00116         return result;
00117 }
00118 
00119 static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
00120                                    int argc, const char **argv)
00121 {
00122         uint32 size, i;
00123         NTSTATUS result;
00124         char *in_data = NULL;
00125 
00126         if (argc != 2) {
00127                 printf("Usage: %s num\n", argv[0]);
00128                 return NT_STATUS_OK;
00129         }
00130 
00131         size = atoi(argv[1]);
00132         in_data = SMB_MALLOC(size);
00133 
00134         for (i = 0; i < size; i++)
00135                 in_data[i] = i & 0xff;
00136 
00137         result = rpccli_echo_sink_data(cli, mem_ctx, size, in_data);
00138 
00139         if (!NT_STATUS_IS_OK(result))
00140                 goto done;
00141 
00142 done:
00143         SAFE_FREE(in_data);
00144 
00145         return result;
00146 }
00147 
00148 /* List of commands exported by this module */
00149 
00150 struct cmd_set echo_commands[] = {
00151 
00152         { "ECHO" },
00153 
00154         { "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one,     NULL, PI_ECHO, NULL, "Add one to a number", "" },
00155         { "echodata",   RPC_RTYPE_NTSTATUS, cmd_echo_data,        NULL, PI_ECHO, NULL, "Echo data",           "" },
00156         { "sinkdata",   RPC_RTYPE_NTSTATUS, cmd_echo_sink_data,   NULL, PI_ECHO, NULL, "Sink data",           "" },
00157         { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, PI_ECHO, NULL, "Source data",         "" },
00158         { NULL }
00159 };

Sambaに対してSat Aug 29 21:23:22 2009に生成されました。  doxygen 1.4.7