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

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/CIFS implementation.
       3             :  *
       4             :  * This program is free software; you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation; either version 3 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * This program is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "includes.h"
      19             : #include "rpcclient.h"
      20             : #include "../librpc/gen_ndr/ndr_unixinfo_c.h"
      21             : #include "libcli/security/dom_sid.h"
      22             : 
      23           0 : static NTSTATUS cmd_unixinfo_uidtosid(
      24             :         struct rpc_pipe_client *cli,
      25             :         TALLOC_CTX *mem_ctx,
      26             :         int argc,
      27             :         const char **argv)
      28             : {
      29           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
      30           0 :         uint64_t uid = 0;
      31           0 :         struct dom_sid sid = { .sid_rev_num = 0, };
      32             :         struct dom_sid_buf buf;
      33             :         NTSTATUS status, result;
      34             : 
      35           0 :         if (argc != 2) {
      36           0 :                 printf("Usage: %s [uid]\n", argv[0]);
      37           0 :                 return NT_STATUS_OK;
      38             :         }
      39           0 :         uid = atoi(argv[1]);
      40             : 
      41           0 :         status = dcerpc_unixinfo_UidToSid(b, mem_ctx, uid, &sid, &result);
      42           0 :         if (!NT_STATUS_IS_OK(status)) {
      43           0 :                 fprintf(stderr,
      44             :                         "dcerpc_unixinfo_UidToSid failed: %s\n",
      45             :                         nt_errstr(status));
      46           0 :                 goto done;
      47             :         }
      48           0 :         if (!NT_STATUS_IS_OK(result)) {
      49           0 :                 fprintf(stderr,
      50             :                         "dcerpc_unixinfo_UidToSid returned: %s\n",
      51             :                         nt_errstr(result));
      52           0 :                 status = result;
      53           0 :                 goto done;
      54             :         }
      55             : 
      56           0 :         printf("UidToSid(%"PRIu64")=%s\n",
      57             :                uid,
      58             :                dom_sid_str_buf(&sid, &buf));
      59             : 
      60           0 : done:
      61           0 :         return status;
      62             : }
      63             : 
      64           0 : static NTSTATUS cmd_unixinfo_getpwuid(
      65             :         struct rpc_pipe_client *cli,
      66             :         TALLOC_CTX *mem_ctx,
      67             :         int argc,
      68             :         const char **argv)
      69             : {
      70           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
      71           0 :         uint32_t count = 1;
      72           0 :         uint64_t uids = 0;
      73           0 :         struct unixinfo_GetPWUidInfo infos = { .homedir = NULL, };
      74             :         NTSTATUS status, result;
      75             : 
      76           0 :         if (argc != 2) {
      77           0 :                 printf("Usage: %s [uid]\n", argv[0]);
      78           0 :                 return NT_STATUS_OK;
      79             :         }
      80           0 :         uids = atoi(argv[1]);
      81             : 
      82           0 :         status = dcerpc_unixinfo_GetPWUid(
      83             :                 b, mem_ctx, &count, &uids, &infos, &result);
      84           0 :         if (!NT_STATUS_IS_OK(status)) {
      85           0 :                 goto done;
      86             :         }
      87             : 
      88           0 :         if (!NT_STATUS_IS_OK(status)) {
      89           0 :                 fprintf(stderr,
      90             :                         "dcerpc_unixinfo_GetPWUid failed: %s\n",
      91             :                         nt_errstr(status));
      92           0 :                 return status;
      93             :         }
      94           0 :         if (!NT_STATUS_IS_OK(result)) {
      95           0 :                 fprintf(stderr,
      96             :                         "dcerpc_unixinfo_GetPWUid returned: %s\n",
      97             :                         nt_errstr(result));
      98           0 :                 return result;
      99             :         }
     100             : 
     101           0 :         printf("status=%s, homedir=%s, shell=%s\n",
     102             :                nt_errstr(infos.status),
     103             :                infos.homedir,
     104             :                infos.shell);
     105             : 
     106           0 : done:
     107           0 :         return status;
     108             : }
     109             : 
     110             : /* List of commands exported by this module */
     111             : 
     112             : struct cmd_set unixinfo_commands[] = {
     113             : 
     114             :         {
     115             :                 .name = "UNIXINFO",
     116             :         },
     117             : 
     118             :         {
     119             :                 .name               = "getpwuid",
     120             :                 .returntype         = RPC_RTYPE_NTSTATUS,
     121             :                 .ntfn               = cmd_unixinfo_getpwuid,
     122             :                 .wfn                = NULL,
     123             :                 .table              = &ndr_table_unixinfo,
     124             :                 .rpc_pipe           = NULL,
     125             :                 .description        = "Get shell and homedir",
     126             :                 .usage              = "",
     127             :         },
     128             :         {
     129             :                 .name               = "uidtosid",
     130             :                 .returntype         = RPC_RTYPE_NTSTATUS,
     131             :                 .ntfn               = cmd_unixinfo_uidtosid,
     132             :                 .wfn                = NULL,
     133             :                 .table              = &ndr_table_unixinfo,
     134             :                 .rpc_pipe           = NULL,
     135             :                 .description        = "Convert uid to sid",
     136             :                 .usage              = "",
     137             :         },
     138             :         {
     139             :                 .name = NULL
     140             :         },
     141             : };

Generated by: LCOV version 1.14