LCOV - code coverage report
Current view: top level - librpc/rpc - dcerpc_error.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 15 29 51.7 %
Date: 2024-04-21 15:09:00 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    dcerpc fault functions
       5             : 
       6             :    Copyright (C) Stefan Metzmacher 2004
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "librpc/rpc/dcerpc.h"
      24             : #include "rpc_common.h"
      25             : 
      26             : struct dcerpc_fault_table {
      27             :         const char *errstr;
      28             :         uint32_t faultcode;
      29             :         NTSTATUS nt_status;
      30             : };
      31             : 
      32             : static const struct dcerpc_fault_table dcerpc_faults[] =
      33             : {
      34             : #define _FAULT_STR(x, s) { .errstr = #x , .faultcode = x, .nt_status = s }
      35             : #define _FAULT_STR_NO_NT_MAPPING(x) _FAULT_STR(x, NT_STATUS_RPC_NOT_RPC_ERROR)
      36             :         _FAULT_STR(DCERPC_NCA_S_COMM_FAILURE, NT_STATUS_RPC_COMM_FAILURE),
      37             :         _FAULT_STR(DCERPC_NCA_S_OP_RNG_ERROR, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE),
      38             :         _FAULT_STR(DCERPC_NCA_S_UNKNOWN_IF, NT_STATUS_RPC_UNKNOWN_IF),
      39             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_WRONG_BOOT_TIME),
      40             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_YOU_CRASHED),
      41             :         _FAULT_STR(DCERPC_NCA_S_PROTO_ERROR, NT_STATUS_RPC_PROTOCOL_ERROR),
      42             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_OUT_ARGS_TOO_BIG),
      43             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_SERVER_TOO_BUSY),
      44             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_STRING_TOO_LARGE),
      45             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_UNSUPPORTED_TYPE),
      46             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_ADDR_ERROR),
      47             :         _FAULT_STR(DCERPC_NCA_S_FAULT_FP_DIV_BY_ZERO, NT_STATUS_RPC_FP_DIV_ZERO),
      48             :         _FAULT_STR(DCERPC_NCA_S_FAULT_FP_UNDERFLOW, NT_STATUS_RPC_FP_UNDERFLOW),
      49             :         _FAULT_STR(DCERPC_NCA_S_FAULT_FP_OVERRFLOW, NT_STATUS_RPC_FP_OVERFLOW),
      50             :         _FAULT_STR(DCERPC_NCA_S_FAULT_INT_DIV_BY_ZERO, NT_STATUS_RPC_FP_DIV_ZERO),
      51             :         _FAULT_STR(DCERPC_NCA_S_FAULT_INT_OVERFLOW, NT_STATUS_RPC_FP_OVERFLOW),
      52             :         /*
      53             :          * Our callers expect NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE
      54             :          * instead of NT_STATUS_RPC_INVALID_TAG.
      55             :          */
      56             :         _FAULT_STR(DCERPC_NCA_S_FAULT_INVALID_TAG, NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE),
      57             :         _FAULT_STR(DCERPC_NCA_S_FAULT_INVALID_TAG, NT_STATUS_RPC_INVALID_TAG),
      58             :         _FAULT_STR(DCERPC_NCA_S_FAULT_INVALID_BOUND, NT_STATUS_RPC_INVALID_BOUND),
      59             :         _FAULT_STR(DCERPC_NCA_S_FAULT_RPC_VERSION_MISMATCH, NT_STATUS_RPC_PROTOCOL_ERROR),
      60             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_UNSPEC_REJECT),
      61             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_BAD_ACTID),
      62             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_WHO_ARE_YOU_FAILED),
      63             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_MANAGER_NOT_ENTERED),
      64             :         _FAULT_STR(DCERPC_NCA_S_FAULT_CANCEL, NT_STATUS_RPC_CALL_CANCELLED),
      65             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_ILL_INST),
      66             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_FP_ERROR),
      67             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_UNUSED_1C000011),
      68             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_UNSPEC),
      69             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_REMOTE_COMM_FAILURE),
      70             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_PIPE_EMPTY),
      71             :         _FAULT_STR(DCERPC_NCA_S_FAULT_PIPE_CLOSED, NT_STATUS_RPC_PIPE_CLOSED),
      72             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_PIPE_ORDER),
      73             :         _FAULT_STR(DCERPC_NCA_S_FAULT_PIPE_DISCIPLINE, NT_STATUS_RPC_PIPE_DISCIPLINE_ERROR),
      74             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_PIPE_COMM_ERROR),
      75             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_PIPE_MEMORY),
      76             :         _FAULT_STR(DCERPC_NCA_S_FAULT_CONTEXT_MISMATCH, NT_STATUS_RPC_SS_CONTEXT_MISMATCH),
      77             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_REMOTE_NO_MEMORY),
      78             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_INVALID_PRES_CONTEXT_ID),
      79             :         _FAULT_STR(DCERPC_NCA_S_UNSUPPORTED_AUTHN_LEVEL, NT_STATUS_RPC_UNSUPPORTED_AUTHN_LEVEL),
      80             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_UNUSED_1C00001E),
      81             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_INVALID_CHECKSUM),
      82             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_INVALID_CRC),
      83             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_USER_DEFINED),
      84             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_TX_OPEN_FAILED),
      85             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_CODESET_CONV_ERROR),
      86             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_OBJECT_NOT_FOUND),
      87             :         _FAULT_STR_NO_NT_MAPPING(DCERPC_NCA_S_FAULT_NO_CLIENT_STUB),
      88             :         _FAULT_STR(DCERPC_FAULT_OTHER, NT_STATUS_RPC_CALL_FAILED),
      89             :         _FAULT_STR(DCERPC_FAULT_ACCESS_DENIED, NT_STATUS_ACCESS_DENIED),
      90             :         _FAULT_STR(DCERPC_FAULT_SERVER_UNAVAILABLE, NT_STATUS_RPC_SERVER_UNAVAILABLE),
      91             :         _FAULT_STR(DCERPC_FAULT_NO_CALL_ACTIVE, NT_STATUS_RPC_NO_CALL_ACTIVE),
      92             :         _FAULT_STR(DCERPC_FAULT_CANT_PERFORM, NT_STATUS_EPT_CANT_PERFORM_OP),
      93             :         _FAULT_STR(DCERPC_FAULT_OUT_OF_RESOURCES, NT_STATUS_RPC_OUT_OF_RESOURCES),
      94             :         _FAULT_STR(DCERPC_FAULT_BAD_STUB_DATA, NT_STATUS_RPC_BAD_STUB_DATA),
      95             :         _FAULT_STR(DCERPC_FAULT_SEC_PKG_ERROR, NT_STATUS_RPC_SEC_PKG_ERROR),
      96             :         { .faultcode = 0 }
      97             : #undef _FAULT_STR
      98             : };
      99             : 
     100         403 : _PUBLIC_ const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code)
     101             : {
     102         403 :         int idx = 0;
     103         403 :         WERROR werr = W_ERROR(fault_code);
     104             : 
     105        6840 :         while (dcerpc_faults[idx].errstr != NULL) {
     106        6840 :                 if (dcerpc_faults[idx].faultcode == fault_code) {
     107         403 :                         return dcerpc_faults[idx].errstr;
     108             :                 }
     109        6437 :                 idx++;
     110             :         }
     111             : 
     112           0 :         return win_errstr(werr);
     113             : }
     114             : 
     115        5359 : _PUBLIC_ NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code)
     116             : {
     117        5359 :         int idx = 0;
     118        5359 :         WERROR werr = W_ERROR(fault_code);
     119             : 
     120        5359 :         if (fault_code == 0) {
     121           0 :                 return NT_STATUS_RPC_PROTOCOL_ERROR;
     122             :         }
     123             : 
     124      109636 :         while (dcerpc_faults[idx].errstr != NULL) {
     125      109636 :                 if (dcerpc_faults[idx].faultcode == fault_code) {
     126        5359 :                         return dcerpc_faults[idx].nt_status;
     127             :                 }
     128      104277 :                 idx++;
     129             :         }
     130             : 
     131           0 :         return werror_to_ntstatus(werr);
     132             : }
     133             : 
     134           0 : _PUBLIC_ uint32_t dcerpc_fault_from_nt_status(NTSTATUS nt_status)
     135             : {
     136           0 :         int idx = 0;
     137           0 :         WERROR werr;
     138             : 
     139           0 :         if (NT_STATUS_IS_OK(nt_status)) {
     140           0 :                 return DCERPC_NCA_S_PROTO_ERROR;
     141             :         }
     142             : 
     143           0 :         while (dcerpc_faults[idx].errstr != NULL) {
     144           0 :                 if (NT_STATUS_EQUAL(dcerpc_faults[idx].nt_status, nt_status)) {
     145           0 :                         return dcerpc_faults[idx].faultcode;
     146             :                 }
     147           0 :                 idx++;
     148             :         }
     149             : 
     150           0 :         werr = ntstatus_to_werror(nt_status);
     151             : 
     152           0 :         return W_ERROR_V(werr);
     153             : }

Generated by: LCOV version 1.14