LCOV - code coverage report
Current view: top level - source3/rpcclient - cmd_wkssvc.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 0 79 0.0 %
Date: 2024-04-21 15:09:00 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    RPC pipe client
       4             : 
       5             :    Copyright (C) Günther Deschner 2007
       6             : 
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "rpcclient.h"
      23             : #include "../librpc/gen_ndr/ndr_wkssvc_c.h"
      24             : 
      25           0 : static WERROR cmd_wkssvc_wkstagetinfo(struct rpc_pipe_client *cli,
      26             :                                       TALLOC_CTX *mem_ctx,
      27             :                                       int argc,
      28             :                                       const char **argv)
      29             : {
      30             :         NTSTATUS status;
      31             :         WERROR werr;
      32           0 :         uint32_t level = 100;
      33             :         union wkssvc_NetWkstaInfo info;
      34             :         const char *server_name;
      35           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
      36             : 
      37           0 :         if (argc > 2) {
      38           0 :                 printf("usage: %s <level>\n", argv[0]);
      39           0 :                 return WERR_OK;
      40             :         }
      41             : 
      42           0 :         if (argc > 1) {
      43           0 :                 level = atoi(argv[1]);
      44             :         }
      45             : 
      46           0 :         server_name = cli->desthost;
      47             : 
      48           0 :         status = dcerpc_wkssvc_NetWkstaGetInfo(b, mem_ctx,
      49             :                                                server_name,
      50             :                                                level,
      51             :                                                &info,
      52             :                                                &werr);
      53           0 :         if (!NT_STATUS_IS_OK(status)) {
      54           0 :                 return ntstatus_to_werror(status);
      55             :         }
      56             : 
      57           0 :         return werr;
      58             : }
      59             : 
      60           0 : static WERROR cmd_wkssvc_getjoininformation(struct rpc_pipe_client *cli,
      61             :                                             TALLOC_CTX *mem_ctx,
      62             :                                             int argc,
      63             :                                             const char **argv)
      64             : {
      65             :         const char *server_name;
      66             :         const char *name_buffer;
      67             :         enum wkssvc_NetJoinStatus name_type;
      68             :         NTSTATUS status;
      69             :         WERROR werr;
      70           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
      71             : 
      72           0 :         server_name = cli->desthost;
      73           0 :         name_buffer = "";
      74             : 
      75           0 :         status = dcerpc_wkssvc_NetrGetJoinInformation(b, mem_ctx,
      76             :                                                       server_name,
      77             :                                                       &name_buffer,
      78             :                                                       &name_type,
      79             :                                                       &werr);
      80           0 :         if (!NT_STATUS_IS_OK(status)) {
      81           0 :                 return ntstatus_to_werror(status);
      82             :         }
      83             : 
      84           0 :         if (W_ERROR_IS_OK(werr)) {
      85           0 :                 printf("%s (%d)\n", name_buffer, name_type);
      86             :         }
      87             : 
      88           0 :         return werr;
      89             : }
      90             : 
      91           0 : static WERROR cmd_wkssvc_messagebuffersend(struct rpc_pipe_client *cli,
      92             :                                            TALLOC_CTX *mem_ctx,
      93             :                                            int argc,
      94             :                                            const char **argv)
      95             : {
      96           0 :         const char *server_name = cli->desthost;
      97           0 :         const char *message_name = cli->desthost;
      98           0 :         const char *message_sender_name = cli->desthost;
      99           0 :         smb_ucs2_t *message_buffer = NULL;
     100           0 :         size_t message_size = 0;
     101           0 :         const char *message = "my message";
     102             :         NTSTATUS status;
     103             :         WERROR werr;
     104           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     105             : 
     106           0 :         if (argc > 1) {
     107           0 :                 message = argv[1];
     108             :         }
     109             : 
     110           0 :         if (!push_ucs2_talloc(mem_ctx, &message_buffer, message,
     111             :                               &message_size))
     112             :         {
     113           0 :                 return WERR_NOT_ENOUGH_MEMORY;
     114             :         }
     115             : 
     116           0 :         status = dcerpc_wkssvc_NetrMessageBufferSend(b, mem_ctx,
     117             :                                                      server_name,
     118             :                                                      message_name,
     119             :                                                      message_sender_name,
     120             :                                                      (uint8_t *)message_buffer,
     121             :                                                      message_size,
     122             :                                                      &werr);
     123           0 :         if (!NT_STATUS_IS_OK(status)) {
     124           0 :                 return ntstatus_to_werror(status);
     125             :         }
     126             : 
     127           0 :         return werr;
     128             : }
     129             : 
     130           0 : static WERROR cmd_wkssvc_enumeratecomputernames(struct rpc_pipe_client *cli,
     131             :                                                 TALLOC_CTX *mem_ctx,
     132             :                                                 int argc,
     133             :                                                 const char **argv)
     134             : {
     135             :         const char *server_name;
     136           0 :         enum wkssvc_ComputerNameType name_type = NetAllComputerNames;
     137             :         NTSTATUS status;
     138           0 :         struct wkssvc_ComputerNamesCtr *ctr = NULL;
     139             :         WERROR werr;
     140           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     141             : 
     142           0 :         server_name = cli->desthost;
     143             : 
     144           0 :         if (argc >= 2) {
     145           0 :                 name_type = atoi(argv[1]);
     146             :         }
     147             : 
     148           0 :         status = dcerpc_wkssvc_NetrEnumerateComputerNames(b, mem_ctx,
     149             :                                                           server_name,
     150             :                                                           name_type, 0,
     151             :                                                           &ctr,
     152             :                                                           &werr);
     153           0 :         if (!NT_STATUS_IS_OK(status)) {
     154           0 :                 return ntstatus_to_werror(status);
     155             :         }
     156             : 
     157           0 :         if (W_ERROR_IS_OK(werr)) {
     158           0 :                 int i=0;
     159           0 :                 for (i = 0; i < ctr->count; i++) {
     160           0 :                         printf("name: %d %s\n", i, ctr->computer_name->string);
     161             :                 }
     162             :         }
     163             : 
     164           0 :         return werr;
     165             : }
     166             : 
     167           0 : static WERROR cmd_wkssvc_enumerateusers(struct rpc_pipe_client *cli,
     168             :                                         TALLOC_CTX *mem_ctx,
     169             :                                         int argc,
     170             :                                         const char **argv)
     171             : {
     172             :         const char *server_name;
     173             :         NTSTATUS status;
     174             :         struct wkssvc_NetWkstaEnumUsersInfo info;
     175             :         WERROR werr;
     176             :         uint32_t i, num_entries, resume_handle;
     177           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     178             : 
     179           0 :         server_name = cli->desthost;
     180             : 
     181           0 :         ZERO_STRUCT(info);
     182             : 
     183           0 :         if (argc >= 2) {
     184           0 :                 info.level = atoi(argv[1]);
     185             :         }
     186             : 
     187           0 :         status = dcerpc_wkssvc_NetWkstaEnumUsers(b, mem_ctx, server_name,
     188             :                                                  &info, 1000, &num_entries,
     189             :                                                  &resume_handle, &werr);
     190           0 :         if (!NT_STATUS_IS_OK(status)) {
     191           0 :                 return ntstatus_to_werror(status);
     192             :         }
     193           0 :         if (!W_ERROR_IS_OK(werr)) {
     194           0 :                 return werr;
     195             :         }
     196             : 
     197           0 :         for (i=0; i<num_entries; i++) {
     198           0 :                 const char *user = NULL;
     199           0 :                 switch (info.level) {
     200           0 :                 case 0:
     201           0 :                         user = info.ctr.user0->user0[i].user_name;
     202           0 :                         break;
     203           0 :                 case 1:
     204           0 :                         user = talloc_asprintf(
     205           0 :                                 talloc_tos(), "%s\\%s",
     206           0 :                                 info.ctr.user1->user1[i].logon_domain,
     207           0 :                                 info.ctr.user1->user1[i].user_name);
     208           0 :                         break;
     209             :                 }
     210           0 :                 printf("%s\n", user ? user : "(null)");
     211             :         }
     212             : 
     213           0 :         return werr;
     214             : }
     215             : 
     216             : struct cmd_set wkssvc_commands[] = {
     217             : 
     218             :         {
     219             :                 .name = "WKSSVC",
     220             :         },
     221             :         {
     222             :                 .name               = "wkssvc_wkstagetinfo",
     223             :                 .returntype         = RPC_RTYPE_WERROR,
     224             :                 .ntfn               = NULL,
     225             :                 .wfn                = cmd_wkssvc_wkstagetinfo,
     226             :                 .table              = &ndr_table_wkssvc,
     227             :                 .rpc_pipe           = NULL,
     228             :                 .description        = "Query WKSSVC Workstation Information",
     229             :                 .usage              = "",
     230             :         },
     231             :         {
     232             :                 .name               = "wkssvc_getjoininformation",
     233             :                 .returntype         = RPC_RTYPE_WERROR,
     234             :                 .ntfn               = NULL,
     235             :                 .wfn                = cmd_wkssvc_getjoininformation,
     236             :                 .table              = &ndr_table_wkssvc,
     237             :                 .rpc_pipe           = NULL,
     238             :                 .description        = "Query WKSSVC Join Information",
     239             :                 .usage              = "",
     240             :         },
     241             :         {
     242             :                 .name               = "wkssvc_messagebuffersend",
     243             :                 .returntype         = RPC_RTYPE_WERROR,
     244             :                 .ntfn               = NULL,
     245             :                 .wfn                = cmd_wkssvc_messagebuffersend,
     246             :                 .table              = &ndr_table_wkssvc,
     247             :                 .rpc_pipe           = NULL,
     248             :                 .description        = "Send WKSSVC message",
     249             :                 .usage              = "",
     250             :         },
     251             :         {
     252             :                 .name               = "wkssvc_enumeratecomputernames",
     253             :                 .returntype         = RPC_RTYPE_WERROR,
     254             :                 .ntfn               = NULL,
     255             :                 .wfn                = cmd_wkssvc_enumeratecomputernames,
     256             :                 .table              = &ndr_table_wkssvc,
     257             :                 .rpc_pipe           = NULL,
     258             :                 .description        = "Enumerate WKSSVC computer names",
     259             :                 .usage              = "",
     260             :         },
     261             :         {
     262             :                 .name               = "wkssvc_enumerateusers",
     263             :                 .returntype         = RPC_RTYPE_WERROR,
     264             :                 .ntfn               = NULL,
     265             :                 .wfn                = cmd_wkssvc_enumerateusers,
     266             :                 .table              = &ndr_table_wkssvc,
     267             :                 .rpc_pipe           = NULL,
     268             :                 .description        = "Enumerate WKSSVC users",
     269             :                 .usage              = "",
     270             :         },
     271             :         {
     272             :                 .name =NULL,
     273             :         },
     274             : };

Generated by: LCOV version 1.14