LCOV - code coverage report
Current view: top level - libcli/util - doserr.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 19 22 86.4 %
Date: 2024-05-31 13:13:24 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Unix SMB/CIFS implementation.
       3             :  *  DOS error routines
       4             :  *  Copyright (C) Tim Potter 2002.
       5             :  *
       6             :  *  This program is free software; you can redistribute it and/or modify
       7             :  *  it under the terms of the GNU General Public License as published by
       8             :  *  the Free Software Foundation; either version 3 of the License, or
       9             :  *  (at your option) any later version.
      10             :  *
      11             :  *  This program is distributed in the hope that it will be useful,
      12             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  *  GNU General Public License for more details.
      15             :  *
      16             :  *  You should have received a copy of the GNU General Public License
      17             :  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : /* DOS error codes.  please read doserr.h */
      21             : 
      22             : #include "replace.h"
      23             : #include "libcli/util/werror.h"
      24             : #include "libcli/util/hresult.h"
      25             : 
      26             : struct werror_code_struct {
      27             :         const char *dos_errstr;
      28             :         WERROR werror;
      29             : };
      30             : 
      31             : struct werror_str_struct {
      32             :         WERROR werror;
      33             :         const char *friendly_errstr;
      34             : };
      35             : 
      36             : static const struct werror_code_struct special_errs[] =
      37             : {
      38             :         { "WERR_DNS_ERROR_NOT_ALLOWED_ON_ACTIVE_SKD", WERR_DNS_ERROR_NOT_ALLOWED_ON_ACTIVE_SKD },
      39             :         { "WERR_DNS_ERROR_INVALID_NSEC3_PARAMETERS", WERR_DNS_ERROR_INVALID_NSEC3_PARAMETERS },
      40             :         { "WERR_DNS_ERROR_DNSSEC_IS_DISABLED", WERR_DNS_ERROR_DNSSEC_IS_DISABLED },
      41             :         { "WERR_DNS_ERROR_NOT_ALLOWED_ON_UNSIGNED_ZONE", WERR_DNS_ERROR_NOT_ALLOWED_ON_UNSIGNED_ZONE },
      42             :         { "WERR_DNS_ERROR_KSP_DOES_NOT_SUPPORT_PROTECTION", WERR_DNS_ERROR_KSP_DOES_NOT_SUPPORT_PROTECTION },
      43             :         { "WERR_DNS_ERROR_BAD_KEYMASTER", WERR_DNS_ERROR_BAD_KEYMASTER },
      44             :         { "WERR_USER_APC", WERR_USER_APC },
      45             :         { "WERR_DNS_ERROR_UNEXPECTED_DATA_PROTECTION_ERROR", WERR_DNS_ERROR_UNEXPECTED_DATA_PROTECTION_ERROR },
      46             :         { "WERR_WAIT_2", WERR_WAIT_2 },
      47             :         { "WERR_WAIT_3", WERR_WAIT_3 },
      48             :         { "WERR_WAIT_1", WERR_WAIT_1 },
      49             :         { "WERR_DNS_ERROR_NSEC3_NAME_COLLISION", WERR_DNS_ERROR_NSEC3_NAME_COLLISION },
      50             :         { "WERR_DNS_ERROR_KSP_NOT_ACCESSIBLE", WERR_DNS_ERROR_KSP_NOT_ACCESSIBLE },
      51             :         { "WERR_DNS_ERROR_ROLLOVER_NOT_POKEABLE", WERR_DNS_ERROR_ROLLOVER_NOT_POKEABLE },
      52             :         { "WERR_DNS_ERROR_INVALID_KEY_SIZE", WERR_DNS_ERROR_INVALID_KEY_SIZE },
      53             :         { "WERR_DNS_ERROR_ROLLOVER_ALREADY_QUEUED", WERR_DNS_ERROR_ROLLOVER_ALREADY_QUEUED },
      54             :         { "WERR_DNS_ERROR_UNKNOWN_SIGNING_PARAMETER_VERSION", WERR_DNS_ERROR_UNKNOWN_SIGNING_PARAMETER_VERSION },
      55             :         { "WERR_DNS_ERROR_INVALID_INITIAL_ROLLOVER_OFFSET", WERR_DNS_ERROR_INVALID_INITIAL_ROLLOVER_OFFSET },
      56             :         { "WERR_DNS_ERROR_SIGNING_KEY_NOT_ACCESSIBLE", WERR_DNS_ERROR_SIGNING_KEY_NOT_ACCESSIBLE },
      57             :         { "WERR_DNS_REQUEST_PENDING", WERR_DNS_REQUEST_PENDING },
      58             :         { "WERR_LOG_HARD_ERROR", WERR_LOG_HARD_ERROR },
      59             :         { "WERR_DNS_ERROR_NOT_ALLOWED_ON_ZSK", WERR_DNS_ERROR_NOT_ALLOWED_ON_ZSK },
      60             :         { "WERR_OK", WERR_OK },
      61             :         { "WERR_DNS_ERROR_KEYMASTER_REQUIRED", WERR_DNS_ERROR_KEYMASTER_REQUIRED },
      62             :         { "WERR_STATUS_MORE_ENTRIES", WERR_STATUS_MORE_ENTRIES },
      63             :         { "WERR_DS_INVALID_ATTRIBUTE_SYNTAX", WERR_DS_INVALID_ATTRIBUTE_SYNTAX },
      64             :         { "WERR_ALERTED", WERR_ALERTED },
      65             :         { "WERR_DNS_ERROR_UNSUPPORTED_ALGORITHM", WERR_DNS_ERROR_UNSUPPORTED_ALGORITHM },
      66             :         { "WERR_DNS_ERROR_INVALID_NSEC3_ITERATION_COUNT", WERR_DNS_ERROR_INVALID_NSEC3_ITERATION_COUNT },
      67             :         { "WERR_DNS_ERROR_INVALID_XML", WERR_DNS_ERROR_INVALID_XML },
      68             :         { "WERR_DNS_ERROR_DELEGATION_REQUIRED", WERR_DNS_ERROR_DELEGATION_REQUIRED },
      69             :         { "WERR_ABANDONED_WAIT_63", WERR_ABANDONED_WAIT_63 },
      70             :         { "WERR_DNS_ERROR_UNEXPECTED_CNG_ERROR", WERR_DNS_ERROR_UNEXPECTED_CNG_ERROR },
      71             :         { "WERR_DNS_ERROR_DNAME_COLLISION", WERR_DNS_ERROR_DNAME_COLLISION },
      72             :         { "WERR_DNS_ERROR_INVALID_POLICY_TABLE", WERR_DNS_ERROR_INVALID_POLICY_TABLE },
      73             :         { "WERR_DNS_ERROR_NO_VALID_TRUST_ANCHORS", WERR_DNS_ERROR_NO_VALID_TRUST_ANCHORS },
      74             :         { "WERR_MULTIPLE_FAULT_VIOLATION", WERR_MULTIPLE_FAULT_VIOLATION },
      75             :         { "WERR_DNS_ERROR_INVALID_ROLLOVER_PERIOD", WERR_DNS_ERROR_INVALID_ROLLOVER_PERIOD },
      76             :         { "WERR_DNS_ERROR_INVALID_SIGNATURE_VALIDITY_PERIOD", WERR_DNS_ERROR_INVALID_SIGNATURE_VALIDITY_PERIOD },
      77             :         { "WERR_DNS_ERROR_NOT_ENOUGH_SIGNING_KEY_DESCRIPTORS", WERR_DNS_ERROR_NOT_ENOUGH_SIGNING_KEY_DESCRIPTORS },
      78             :         { "WERR_INVALID_PRIMARY_GROUP", WERR_INVALID_PRIMARY_GROUP },
      79             :         { "WERR_KERNEL_APC", WERR_KERNEL_APC },
      80             :         { "WERR_DNS_ERROR_NOT_ALLOWED_UNDER_DNAME", WERR_DNS_ERROR_NOT_ALLOWED_UNDER_DNAME },
      81             :         { "WERR_DNS_ERROR_TOO_MANY_SKDS", WERR_DNS_ERROR_TOO_MANY_SKDS },
      82             :         { "WERR_DNS_ERROR_NODE_IS_DNMAE", WERR_DNS_ERROR_NODE_IS_DNAME },
      83             :         { "WERR_DNS_ERROR_NODE_IS_DNAME", WERR_DNS_ERROR_NODE_IS_DNAME },
      84             :         { "WERR_SERVICE_NOTIFICATION", WERR_SERVICE_NOTIFICATION },
      85             :         { "WERR_WAIT_63", WERR_WAIT_63 },
      86             :         { "WERR_DNS_ERROR_STANDBY_KEY_NOT_PRESENT", WERR_DNS_ERROR_STANDBY_KEY_NOT_PRESENT },
      87             :         { "WERR_DNS_ERROR_ALIAS_LOOP", WERR_DNS_ERROR_ALIAS_LOOP },
      88             :         { "WERR_DNS_ERROR_ROLLOVER_IN_PROGRESS", WERR_DNS_ERROR_ROLLOVER_IN_PROGRESS },
      89             :         { "WERR_DNS_ERROR_NOT_ALLOWED_ON_SIGNED_ZONE", WERR_DNS_ERROR_NOT_ALLOWED_ON_SIGNED_ZONE },
      90             :         { 0, W_ERROR(0) }
      91             : };
      92             : 
      93             : /*****************************************************************************
      94             :  returns a windows error message.  not amazingly helpful, but better than a number.
      95             :  *****************************************************************************/
      96       27693 : const char *win_errstr(WERROR werror)
      97             : {
      98         863 :         static char msg[40];
      99       27693 :         int idx = 0;
     100             : 
     101     1294149 :         while (special_errs[idx].dos_errstr != NULL) {
     102     1272242 :                 if (W_ERROR_V(special_errs[idx].werror) ==
     103     1235167 :                     W_ERROR_V(werror))
     104        5786 :                         return special_errs[idx].dos_errstr;
     105     1266456 :                 idx++;
     106             :         }
     107             : 
     108       21907 :         idx = 0;
     109             : 
     110       21907 :         switch W_ERROR_V(werror) {
     111             : #include "werror_gen.c"
     112          11 :         default:
     113          13 :                 break;
     114             :         }
     115             : 
     116             :         /*
     117             :          * WERROR codes are 16-bit only, if the
     118             :          * upper 16-bit are not 0, it's likely
     119             :          * an HRESULT.
     120             :          *
     121             :          * E.g. we should display HRES_SEC_E_WRONG_PRINCIPAL instead of
     122             :          * 'DOS code 0x80090322'
     123             :          */
     124          13 :         if ((W_ERROR_V(werror) & 0xFFFF0000) != 0) {
     125           1 :                 HRESULT hres = HRES_ERROR(W_ERROR_V(werror));
     126           1 :                 return hresult_errstr(hres);
     127             :         }
     128             : 
     129          12 :         slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));
     130             : 
     131          12 :         return msg;
     132             : }
     133             : 
     134             : /*****************************************************************************
     135             :  Get friendly error string for WERRORs
     136             :  *****************************************************************************/
     137             : 
     138           9 : const char *get_friendly_werror_msg(WERROR werror)
     139             : {
     140           9 :         switch W_ERROR_V(werror) {
     141             : #include "werror_friendly_gen.c"
     142           0 :         default:
     143           0 :                 break;
     144             :         }
     145             : 
     146           0 :         return win_errstr(werror);
     147             : }

Generated by: LCOV version 1.14