LCOV - code coverage report
Current view: top level - libcli/util - nterr.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 27 59 45.8 %
Date: 2024-06-13 04:01:37 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /*
       2             :  *  Unix SMB/CIFS implementation.
       3             :  *  RPC Pipe client / server routines
       4             :  *
       5             :  *  Copyright (C) Luke Kenneth Casson Leighton 1997-2001.
       6             :  *  Copyright (C) Andrew Bartlett
       7             :  *  Copyright (C) Andrew Tridgell
       8             :  *
       9             :  *  This program is free software; you can redistribute it and/or modify
      10             :  *  it under the terms of the GNU General Public License as published by
      11             :  *  the Free Software Foundation; either version 3 of the License, or
      12             :  *  (at your option) any later version.
      13             :  *
      14             :  *  This program is distributed in the hope that it will be useful,
      15             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :  *  GNU General Public License for more details.
      18             :  *
      19             :  *  You should have received a copy of the GNU General Public License
      20             :  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
      21             :  */
      22             : 
      23             : /* NT error codes.  please read nterr.h */
      24             : 
      25             : #include "includes.h"
      26             : #include "../libcli/ldap/ldap_errors.h"
      27             : #undef strcasecmp
      28             : 
      29             : #if !defined(N_)
      30             : #define N_(string) string
      31             : #endif
      32             : 
      33             : #define DOS_CODE(class, code) { #class ":" #code, NT_STATUS_DOS(class, code) }
      34             : #define LDAP_CODE(code) { #code, NT_STATUS_LDAP(code) }
      35             : 
      36             : typedef struct
      37             : {
      38             :         const char *nt_errstr;
      39             :         NTSTATUS nt_errcode;
      40             : } nt_err_code_struct;
      41             : 
      42             : #include "nterr_gen.c"
      43             : 
      44             : /* Errors which aren't in the generated code because they're not in the
      45             :  * same table as the other ones. */
      46             : static const nt_err_code_struct special_errs[] =
      47             : {
      48             :         { "NT_STATUS_OK", NT_STATUS_OK },
      49             :         { "STATUS_NO_MORE_FILES", STATUS_NO_MORE_FILES },
      50             :         { "STATUS_INVALID_EA_NAME", STATUS_INVALID_EA_NAME },
      51             :         { "STATUS_BUFFER_OVERFLOW", STATUS_BUFFER_OVERFLOW },
      52             :         { "STATUS_MORE_ENTRIES", STATUS_MORE_ENTRIES },
      53             :         { "STATUS_SOME_UNMAPPED", STATUS_SOME_UNMAPPED },
      54             :         { "NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS", NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS },
      55             :         { "NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION", NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION },
      56             :         { "NT_STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP", NT_STATUS_SMB_NO_PREAUTH_INTEGRITY_HASH_OVERLAP },
      57             :         { "NT_STATUS_ABIOS_NOT_PRESENT", NT_STATUS_ABIOS_NOT_PRESENT },
      58             :         { "NT_STATUS_ABIOS_LID_NOT_EXIST", NT_STATUS_ABIOS_LID_NOT_EXIST },
      59             :         { "NT_STATUS_ABIOS_LID_ALREADY_OWNED", NT_STATUS_ABIOS_LID_ALREADY_OWNED },
      60             :         { "NT_STATUS_ABIOS_NOT_LID_OWNER", NT_STATUS_ABIOS_NOT_LID_OWNER },
      61             :         { "NT_STATUS_ABIOS_INVALID_COMMAND", NT_STATUS_ABIOS_INVALID_COMMAND },
      62             :         { "NT_STATUS_ABIOS_INVALID_LID", NT_STATUS_ABIOS_INVALID_LID },
      63             :         { "NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE", NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE },
      64             :         { "NT_STATUS_ABIOS_INVALID_SELECTOR", NT_STATUS_ABIOS_INVALID_SELECTOR },
      65             :         { "NT_STATUS_HANDLE_NOT_WAITABLE", NT_STATUS_HANDLE_NOT_WAITABLE },
      66             :         { "NT_STATUS_DEVICE_POWER_FAILURE", NT_STATUS_DEVICE_POWER_FAILURE },
      67             :         { "NT_STATUS_VHD_SHARED", NT_STATUS_VHD_SHARED },
      68             :         { "NT_STATUS_SMB_BAD_CLUSTER_DIALECT", NT_STATUS_SMB_BAD_CLUSTER_DIALECT },
      69             :         { "NT_STATUS_NO_SUCH_JOB", NT_STATUS_NO_SUCH_JOB },
      70             : 
      71             :         DOS_CODE(ERRDOS, ERRsuccess),
      72             :         DOS_CODE(ERRDOS, ERRbadfunc),
      73             :         DOS_CODE(ERRDOS, ERRbadfile),
      74             :         DOS_CODE(ERRDOS, ERRbadpath),
      75             :         DOS_CODE(ERRDOS, ERRnofids),
      76             :         DOS_CODE(ERRDOS, ERRnoaccess),
      77             :         DOS_CODE(ERRDOS, ERRbadfid),
      78             :         DOS_CODE(ERRDOS, ERRbadmcb),
      79             :         DOS_CODE(ERRDOS, ERRnomem),
      80             :         DOS_CODE(ERRDOS, ERRbadmem),
      81             :         DOS_CODE(ERRDOS, ERRbadenv),
      82             :         DOS_CODE(ERRDOS, ERRbadaccess),
      83             :         DOS_CODE(ERRDOS, ERRbaddata),
      84             :         DOS_CODE(ERRDOS, ERRres),
      85             :         DOS_CODE(ERRDOS, ERRbaddrive),
      86             :         DOS_CODE(ERRDOS, ERRremcd),
      87             :         DOS_CODE(ERRDOS, ERRdiffdevice),
      88             :         DOS_CODE(ERRDOS, ERRnofiles),
      89             :         DOS_CODE(ERRDOS, ERRgeneral),
      90             :         DOS_CODE(ERRDOS, ERRbadshare),
      91             :         DOS_CODE(ERRDOS, ERRlock),
      92             :         DOS_CODE(ERRDOS, ERRunsup),
      93             :         DOS_CODE(ERRDOS, ERRnetnamedel),
      94             :         DOS_CODE(ERRDOS, ERRnosuchshare),
      95             :         DOS_CODE(ERRDOS, ERRfilexists),
      96             :         DOS_CODE(ERRDOS, ERRinvalidparam),
      97             :         DOS_CODE(ERRDOS, ERRcannotopen),
      98             :         DOS_CODE(ERRDOS, ERRinsufficientbuffer),
      99             :         DOS_CODE(ERRDOS, ERRinvalidname),
     100             :         DOS_CODE(ERRDOS, ERRunknownlevel),
     101             :         DOS_CODE(ERRDOS, ERRnotlocked),
     102             :         DOS_CODE(ERRDOS, ERRinvalidpath),
     103             :         DOS_CODE(ERRDOS, ERRcancelviolation),
     104             :         DOS_CODE(ERRDOS, ERRnoatomiclocks),
     105             :         DOS_CODE(ERRDOS, ERRrename),
     106             :         DOS_CODE(ERRDOS, ERRbadpipe),
     107             :         DOS_CODE(ERRDOS, ERRpipebusy),
     108             :         DOS_CODE(ERRDOS, ERRpipeclosing),
     109             :         DOS_CODE(ERRDOS, ERRnotconnected),
     110             :         DOS_CODE(ERRDOS, ERRmoredata),
     111             :         DOS_CODE(ERRDOS, ERRnomoreitems),
     112             :         DOS_CODE(ERRDOS, ERRbaddirectory),
     113             :         DOS_CODE(ERRDOS, ERReasnotsupported),
     114             :         DOS_CODE(ERRDOS, ERRlogonfailure),
     115             :         DOS_CODE(ERRDOS, ERRbuftoosmall),
     116             :         DOS_CODE(ERRDOS, ERRunknownipc),
     117             :         DOS_CODE(ERRDOS, ERRnosuchprintjob),
     118             :         DOS_CODE(ERRDOS, ERRinvgroup),
     119             :         DOS_CODE(ERRDOS, ERRnoipc),
     120             :         DOS_CODE(ERRDOS, ERRdriveralreadyinstalled),
     121             :         DOS_CODE(ERRDOS, ERRunknownprinterport),
     122             :         DOS_CODE(ERRDOS, ERRunknownprinterdriver),
     123             :         DOS_CODE(ERRDOS, ERRunknownprintprocessor),
     124             :         DOS_CODE(ERRDOS, ERRinvalidseparatorfile),
     125             :         DOS_CODE(ERRDOS, ERRinvalidjobpriority),
     126             :         DOS_CODE(ERRDOS, ERRinvalidprintername),
     127             :         DOS_CODE(ERRDOS, ERRprinteralreadyexists),
     128             :         DOS_CODE(ERRDOS, ERRinvalidprintercommand),
     129             :         DOS_CODE(ERRDOS, ERRinvaliddatatype),
     130             :         DOS_CODE(ERRDOS, ERRinvalidenvironment),
     131             :         DOS_CODE(ERRDOS, ERRunknownprintmonitor),
     132             :         DOS_CODE(ERRDOS, ERRprinterdriverinuse),
     133             :         DOS_CODE(ERRDOS, ERRspoolfilenotfound),
     134             :         DOS_CODE(ERRDOS, ERRnostartdoc),
     135             :         DOS_CODE(ERRDOS, ERRnoaddjob),
     136             :         DOS_CODE(ERRDOS, ERRprintprocessoralreadyinstalled),
     137             :         DOS_CODE(ERRDOS, ERRprintmonitoralreadyinstalled),
     138             :         DOS_CODE(ERRDOS, ERRinvalidprintmonitor),
     139             :         DOS_CODE(ERRDOS, ERRprintmonitorinuse),
     140             :         DOS_CODE(ERRDOS, ERRprinterhasjobsqueued),
     141             :         DOS_CODE(ERRDOS, ERReainconsistent),
     142             : 
     143             :         DOS_CODE(ERRSRV, ERRerror),
     144             :         DOS_CODE(ERRSRV, ERRbadpw),
     145             :         DOS_CODE(ERRSRV, ERRbadtype),
     146             :         DOS_CODE(ERRSRV, ERRaccess),
     147             :         DOS_CODE(ERRSRV, ERRinvnid),
     148             :         DOS_CODE(ERRSRV, ERRinvnetname),
     149             :         DOS_CODE(ERRSRV, ERRinvdevice),
     150             :         DOS_CODE(ERRSRV, ERRqfull),
     151             :         DOS_CODE(ERRSRV, ERRqtoobig),
     152             :         DOS_CODE(ERRSRV, ERRinvpfid),
     153             :         DOS_CODE(ERRSRV, ERRsmbcmd),
     154             :         DOS_CODE(ERRSRV, ERRsrverror),
     155             :         DOS_CODE(ERRSRV, ERRfilespecs),
     156             :         DOS_CODE(ERRSRV, ERRbadlink),
     157             :         DOS_CODE(ERRSRV, ERRbadpermits),
     158             :         DOS_CODE(ERRSRV, ERRbadpid),
     159             :         DOS_CODE(ERRSRV, ERRsetattrmode),
     160             :         DOS_CODE(ERRSRV, ERRpaused),
     161             :         DOS_CODE(ERRSRV, ERRmsgoff),
     162             :         DOS_CODE(ERRSRV, ERRnoroom),
     163             :         DOS_CODE(ERRSRV, ERRrmuns),
     164             :         DOS_CODE(ERRSRV, ERRtimeout),
     165             :         DOS_CODE(ERRSRV, ERRnoresource),
     166             :         DOS_CODE(ERRSRV, ERRtoomanyuids),
     167             :         DOS_CODE(ERRSRV, ERRbaduid),
     168             :         DOS_CODE(ERRSRV, ERRuseMPX),
     169             :         DOS_CODE(ERRSRV, ERRuseSTD),
     170             :         DOS_CODE(ERRSRV, ERRcontMPX),
     171             :         DOS_CODE(ERRSRV, ERRnosupport),
     172             :         DOS_CODE(ERRSRV, ERRunknownsmb),
     173             : 
     174             :         DOS_CODE(ERRHRD, ERRnowrite),
     175             :         DOS_CODE(ERRHRD, ERRbadunit),
     176             :         DOS_CODE(ERRHRD, ERRnotready),
     177             :         DOS_CODE(ERRHRD, ERRbadcmd),
     178             :         DOS_CODE(ERRHRD, ERRdata),
     179             :         DOS_CODE(ERRHRD, ERRbadreq),
     180             :         DOS_CODE(ERRHRD, ERRseek),
     181             :         DOS_CODE(ERRHRD, ERRbadmedia),
     182             :         DOS_CODE(ERRHRD, ERRbadsector),
     183             :         DOS_CODE(ERRHRD, ERRnopaper),
     184             :         DOS_CODE(ERRHRD, ERRwrite),
     185             :         DOS_CODE(ERRHRD, ERRread),
     186             :         DOS_CODE(ERRHRD, ERRgeneral),
     187             :         DOS_CODE(ERRHRD, ERRwrongdisk),
     188             :         DOS_CODE(ERRHRD, ERRFCBunavail),
     189             :         DOS_CODE(ERRHRD, ERRsharebufexc),
     190             :         DOS_CODE(ERRHRD, ERRdiskfull),
     191             : 
     192             :         LDAP_CODE(LDAP_SUCCESS),
     193             :         LDAP_CODE(LDAP_OPERATIONS_ERROR),
     194             :         LDAP_CODE(LDAP_PROTOCOL_ERROR),
     195             :         LDAP_CODE(LDAP_TIME_LIMIT_EXCEEDED),
     196             :         LDAP_CODE(LDAP_SIZE_LIMIT_EXCEEDED),
     197             :         LDAP_CODE(LDAP_COMPARE_FALSE),
     198             :         LDAP_CODE(LDAP_COMPARE_TRUE),
     199             :         LDAP_CODE(LDAP_AUTH_METHOD_NOT_SUPPORTED),
     200             :         LDAP_CODE(LDAP_STRONG_AUTH_REQUIRED),
     201             :         LDAP_CODE(LDAP_REFERRAL),
     202             :         LDAP_CODE(LDAP_ADMIN_LIMIT_EXCEEDED),
     203             :         LDAP_CODE(LDAP_UNAVAILABLE_CRITICAL_EXTENSION),
     204             :         LDAP_CODE(LDAP_CONFIDENTIALITY_REQUIRED),
     205             :         LDAP_CODE(LDAP_SASL_BIND_IN_PROGRESS),
     206             :         LDAP_CODE(LDAP_NO_SUCH_ATTRIBUTE),
     207             :         LDAP_CODE(LDAP_UNDEFINED_ATTRIBUTE_TYPE),
     208             :         LDAP_CODE(LDAP_INAPPROPRIATE_MATCHING),
     209             :         LDAP_CODE(LDAP_CONSTRAINT_VIOLATION),
     210             :         LDAP_CODE(LDAP_ATTRIBUTE_OR_VALUE_EXISTS),
     211             :         LDAP_CODE(LDAP_INVALID_ATTRIBUTE_SYNTAX),
     212             :         LDAP_CODE(LDAP_NO_SUCH_OBJECT),
     213             :         LDAP_CODE(LDAP_ALIAS_PROBLEM),
     214             :         LDAP_CODE(LDAP_INVALID_DN_SYNTAX),
     215             :         LDAP_CODE(LDAP_ALIAS_DEREFERENCING_PROBLEM),
     216             :         LDAP_CODE(LDAP_INAPPROPRIATE_AUTHENTICATION),
     217             :         LDAP_CODE(LDAP_INVALID_CREDENTIALS),
     218             :         LDAP_CODE(LDAP_INSUFFICIENT_ACCESS_RIGHTS),
     219             :         LDAP_CODE(LDAP_BUSY),
     220             :         LDAP_CODE(LDAP_UNAVAILABLE),
     221             :         LDAP_CODE(LDAP_UNWILLING_TO_PERFORM),
     222             :         LDAP_CODE(LDAP_LOOP_DETECT),
     223             :         LDAP_CODE(LDAP_NAMING_VIOLATION),
     224             :         LDAP_CODE(LDAP_OBJECT_CLASS_VIOLATION),
     225             :         LDAP_CODE(LDAP_NOT_ALLOWED_ON_NON_LEAF),
     226             :         LDAP_CODE(LDAP_NOT_ALLOWED_ON_RDN),
     227             :         LDAP_CODE(LDAP_ENTRY_ALREADY_EXISTS),
     228             :         LDAP_CODE(LDAP_OBJECT_CLASS_MODS_PROHIBITED),
     229             :         LDAP_CODE(LDAP_AFFECTS_MULTIPLE_DSAS),
     230             :         LDAP_CODE(LDAP_OTHER),
     231             : 
     232             :         { NULL, NT_STATUS(0) }
     233             : };
     234             : 
     235             : /*****************************************************************************
     236             :  Returns an NT_STATUS constant as a string for inclusion in autogen C code.
     237             :  *****************************************************************************/
     238             : 
     239           0 : const char *get_nt_error_c_code(TALLOC_CTX *mem_ctx, NTSTATUS nt_code)
     240             : {
     241             :         char *result;
     242           0 :         int idx = 0;
     243             : 
     244           0 :         while (special_errs[idx].nt_errstr != NULL) {
     245           0 :                 if (NT_STATUS_V(special_errs[idx].nt_errcode) ==
     246           0 :                     NT_STATUS_V(nt_code)) {
     247           0 :                         result = talloc_strdup(mem_ctx, special_errs[idx].nt_errstr);
     248           0 :                         return result;
     249             :                 }
     250           0 :                 idx++;
     251             :         }
     252             : 
     253           0 :         idx = 0;
     254             : 
     255           0 :         while (nt_errs[idx].nt_errstr != NULL) {
     256           0 :                 if (NT_STATUS_V(nt_errs[idx].nt_errcode) ==
     257           0 :                     NT_STATUS_V(nt_code)) {
     258           0 :                         result = talloc_strdup(mem_ctx, nt_errs[idx].nt_errstr);
     259           0 :                         return result;
     260             :                 }
     261           0 :                 idx++;
     262             :         }
     263             : 
     264           0 :         result = talloc_asprintf(mem_ctx, "NT_STATUS(0x%08x)",
     265             :                                  NT_STATUS_V(nt_code));
     266           0 :         return result;
     267             : }
     268             : 
     269             : /*****************************************************************************
     270             :  Returns the NT_STATUS constant matching the string supplied (as an NTSTATUS)
     271             :  *****************************************************************************/
     272             : 
     273           0 : NTSTATUS nt_status_string_to_code(const char *nt_status_str)
     274             : {
     275           0 :         int idx = 0;
     276             : 
     277           0 :         while (special_errs[idx].nt_errstr != NULL) {
     278           0 :                 if (strcasecmp(special_errs[idx].nt_errstr, nt_status_str) == 0) {
     279           0 :                         return special_errs[idx].nt_errcode;
     280             :                 }
     281           0 :                 idx++;
     282             :         }
     283             : 
     284           0 :         idx = 0;
     285             : 
     286           0 :         while (nt_errs[idx].nt_errstr != NULL) {
     287           0 :                 if (strcasecmp(nt_errs[idx].nt_errstr, nt_status_str) == 0) {
     288           0 :                         return nt_errs[idx].nt_errcode;
     289             :                 }
     290           0 :                 idx++;
     291             :         }
     292             : 
     293           0 :         return NT_STATUS_UNSUCCESSFUL;
     294             : }
     295             : 
     296             : /**
     297             :  * Squash an NT_STATUS in line with security requirements.
     298             :  * In an attempt to avoid giving the whole game away when users
     299             :  * are authenticating, NT replaces both NT_STATUS_NO_SUCH_USER and
     300             :  * NT_STATUS_WRONG_PASSWORD with NT_STATUS_LOGON_FAILURE in certain situations
     301             :  * (session setups in particular).
     302             :  *
     303             :  * @param nt_status NTSTATUS input for squashing.
     304             :  * @return the 'squashed' nt_status
     305             :  **/
     306             : 
     307        5158 : NTSTATUS nt_status_squash(NTSTATUS nt_status)
     308             : {
     309        5158 :         if NT_STATUS_IS_OK(nt_status) {
     310        2712 :                 return nt_status;
     311        2446 :         } else if NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_SUCH_USER) {
     312             :                 /* Match WinXP and don't give the game away */
     313         184 :                 return NT_STATUS_LOGON_FAILURE;
     314             : 
     315        2262 :         } else if NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD) {
     316             :                 /* Match WinXP and don't give the game away */
     317         284 :                 return NT_STATUS_LOGON_FAILURE;
     318             :         } else {
     319        1978 :                 return nt_status;
     320             :         }
     321             : }
     322             : 
     323             : /*****************************************************************************
     324             :  Returns an NT error message.  not amazingly helpful, but better than a number.
     325             :  *****************************************************************************/
     326             : 
     327      164941 : const char *nt_errstr(NTSTATUS nt_code)
     328             : {
     329             :         static char msg[20];
     330      164941 :         int idx = 0;
     331             : 
     332    22276077 :         while (special_errs[idx].nt_errstr != NULL) {
     333    41794374 :                 if (NT_STATUS_V(special_errs[idx].nt_errcode) ==
     334    22003006 :                     NT_STATUS_V(nt_code)) {
     335       42301 :                         return special_errs[idx].nt_errstr;
     336             :                 }
     337    21960705 :                 idx++;
     338             :         }
     339             : 
     340      122640 :         idx = 0;
     341             : 
     342    67365303 :         while (nt_errs[idx].nt_errstr != NULL) {
     343   128191924 :                 if (NT_STATUS_V(nt_errs[idx].nt_errcode) ==
     344    67255006 :                     NT_STATUS_V(nt_code)) {
     345      122640 :                         return nt_errs[idx].nt_errstr;
     346             :                 }
     347    67132366 :                 idx++;
     348             :         }
     349             : 
     350             :         /*
     351             :          * This should not really happen, we should have all error codes
     352             :          * available. We have a problem that this might get wrongly
     353             :          * overwritten by later calls in the same DEBUG statement.
     354             :          */
     355             : 
     356           0 :         snprintf(msg, sizeof(msg), "NT code 0x%08x", NT_STATUS_V(nt_code));
     357           0 :         return msg;
     358             : }
     359             : 
     360             : /************************************************************************
     361             :  Print friendler version fo NT error code
     362             :  ***********************************************************************/
     363             : 
     364       39347 : const char *get_friendly_nt_error_msg(NTSTATUS nt_code)
     365             : {
     366       39347 :         int idx = 0;
     367             : 
     368     9693089 :         while (nt_err_desc[idx].nt_errstr != NULL) {
     369     9660987 :                 if (NT_STATUS_V(nt_err_desc[idx].nt_errcode) == NT_STATUS_V(nt_code)) {
     370       39347 :                         return nt_err_desc[idx].nt_errstr;
     371             :                 }
     372     9621640 :                 idx++;
     373             :         }
     374             : 
     375             :         /* fall back to NT_STATUS_XXX string */
     376             : 
     377           0 :         return nt_errstr(nt_code);
     378             : }

Generated by: LCOV version 1.13