Fix SharesContainer.__len__.
[samba.git] / source4 / libcli / util / nterr.c
index 08cd844b3aef51f55947d7bd8354b72bc53f239d..75bbbde92da7c015799d6e8fed178900323410f2 100644 (file)
@@ -5,7 +5,7 @@
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
  *  
  *  This program is distributed in the hope that it will be useful,
  *  GNU General Public License for more details.
  *  
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 /* NT error codes.  please read nterr.h */
 
 #include "includes.h"
-#include "pstring.h"
+#include "../libcli/ldap/ldap_errors.h"
+#undef strcasecmp
 
 typedef struct
 {
@@ -30,12 +30,16 @@ typedef struct
 } nt_err_code_struct;
 
 #define DOS_CODE(class, code) { #class ":" #code, NT_STATUS_DOS(class, code) }
+#define LDAP_CODE(code) { #code, NT_STATUS_LDAP(code) }
 
 static const nt_err_code_struct nt_errs[] =
 {
        { "NT_STATUS_OK", NT_STATUS_OK },
        { "STATUS_NO_MORE_FILES", STATUS_NO_MORE_FILES },
+       { "STATUS_NO_MORE_EAS", STATUS_NO_MORE_EAS },
+       { "STATUS_INVALID_EA_NAME", STATUS_INVALID_EA_NAME },
        { "STATUS_EA_LIST_INCONSISTENT", STATUS_EA_LIST_INCONSISTENT },
+       { "STATUS_INVALID_EA_FLAG", STATUS_INVALID_EA_FLAG },
        { "NT_STATUS_UNSUCCESSFUL", NT_STATUS_UNSUCCESSFUL },
        { "NT_STATUS_NOT_IMPLEMENTED", NT_STATUS_NOT_IMPLEMENTED },
        { "NT_STATUS_INVALID_INFO_CLASS", NT_STATUS_INVALID_INFO_CLASS },
@@ -538,11 +542,20 @@ static const nt_err_code_struct nt_errs[] =
        { "NT_STATUS_TOO_MANY_LINKS", NT_STATUS_TOO_MANY_LINKS },
        { "NT_STATUS_QUOTA_LIST_INCONSISTENT", NT_STATUS_QUOTA_LIST_INCONSISTENT },
        { "NT_STATUS_FILE_IS_OFFLINE", NT_STATUS_FILE_IS_OFFLINE },
+       { "NT_STATUS_DS_NO_MORE_RIDS", NT_STATUS_DS_NO_MORE_RIDS },
         { "NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES },
        { "NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED", NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED },
        { "NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX", NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX },
+       { "NT_STATUS_CURRENT_DOMAIN_NOT_ALLOWED", NT_STATUS_CURRENT_DOMAIN_NOT_ALLOWED },
+       { "NT_STATUS_OBJECTID_NOT_FOUND", NT_STATUS_OBJECTID_NOT_FOUND },
+       { "NT_STATUS_DOWNGRADE_DETECTED", NT_STATUS_DOWNGRADE_DETECTED },
+       { "NT_STATUS_INVALID_LOCK_RANGE", NT_STATUS_INVALID_LOCK_RANGE },
+       { "NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS", NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS },
+       { "NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION", NT_STATUS_ERROR_DS_INCOMPATIBLE_VERSION },
        { "STATUS_MORE_ENTRIES", STATUS_MORE_ENTRIES },
        { "STATUS_SOME_UNMAPPED", STATUS_SOME_UNMAPPED },
+       { "STATUS_NOTIFY_CLEANUP", STATUS_NOTIFY_CLEANUP },
+       { "STATUS_NOTIFY_ENUM_DIR", STATUS_NOTIFY_ENUM_DIR },
 
        DOS_CODE(ERRDOS, ERRsuccess),
        DOS_CODE(ERRDOS, ERRbadfunc),
@@ -665,6 +678,46 @@ static const nt_err_code_struct nt_errs[] =
        DOS_CODE(ERRHRD, ERRsharebufexc),
        DOS_CODE(ERRHRD, ERRdiskfull),
 
+       LDAP_CODE(LDAP_SUCCESS),
+       LDAP_CODE(LDAP_OPERATIONS_ERROR),
+       LDAP_CODE(LDAP_PROTOCOL_ERROR),
+       LDAP_CODE(LDAP_TIME_LIMIT_EXCEEDED),
+       LDAP_CODE(LDAP_SIZE_LIMIT_EXCEEDED),
+       LDAP_CODE(LDAP_COMPARE_FALSE),
+       LDAP_CODE(LDAP_COMPARE_TRUE),
+       LDAP_CODE(LDAP_AUTH_METHOD_NOT_SUPPORTED),
+       LDAP_CODE(LDAP_STRONG_AUTH_REQUIRED),
+       LDAP_CODE(LDAP_REFERRAL),
+       LDAP_CODE(LDAP_ADMIN_LIMIT_EXCEEDED),
+       LDAP_CODE(LDAP_UNAVAILABLE_CRITICAL_EXTENSION),
+       LDAP_CODE(LDAP_CONFIDENTIALITY_REQUIRED),
+       LDAP_CODE(LDAP_SASL_BIND_IN_PROGRESS),
+       LDAP_CODE(LDAP_NO_SUCH_ATTRIBUTE),
+       LDAP_CODE(LDAP_UNDEFINED_ATTRIBUTE_TYPE),
+       LDAP_CODE(LDAP_INAPPROPRIATE_MATCHING),
+       LDAP_CODE(LDAP_CONSTRAINT_VIOLATION),
+       LDAP_CODE(LDAP_ATTRIBUTE_OR_VALUE_EXISTS),
+       LDAP_CODE(LDAP_INVALID_ATTRIBUTE_SYNTAX),
+       LDAP_CODE(LDAP_NO_SUCH_OBJECT),
+       LDAP_CODE(LDAP_ALIAS_PROBLEM),
+       LDAP_CODE(LDAP_INVALID_DN_SYNTAX),
+       LDAP_CODE(LDAP_ALIAS_DEREFERENCING_PROBLEM),
+       LDAP_CODE(LDAP_INAPPROPRIATE_AUTHENTICATION),
+       LDAP_CODE(LDAP_INVALID_CREDENTIALS),
+       LDAP_CODE(LDAP_INSUFFICIENT_ACCESS_RIGHTS),
+       LDAP_CODE(LDAP_BUSY),
+       LDAP_CODE(LDAP_UNAVAILABLE),
+       LDAP_CODE(LDAP_UNWILLING_TO_PERFORM),
+       LDAP_CODE(LDAP_LOOP_DETECT),
+       LDAP_CODE(LDAP_NAMING_VIOLATION),
+       LDAP_CODE(LDAP_OBJECT_CLASS_VIOLATION),
+       LDAP_CODE(LDAP_NOT_ALLOWED_ON_NON_LEAF),
+       LDAP_CODE(LDAP_NOT_ALLOWED_ON_RDN),
+       LDAP_CODE(LDAP_ENTRY_ALREADY_EXISTS),
+       LDAP_CODE(LDAP_OBJECT_CLASS_MODS_PROHIBITED),
+       LDAP_CODE(LDAP_AFFECTS_MULTIPLE_DSAS),
+       LDAP_CODE(LDAP_OTHER),
+
        { NULL, NT_STATUS(0) }
 };
 
@@ -766,7 +819,6 @@ static const nt_err_code_struct nt_err_desc[] =
        { NULL, NT_STATUS(0) }
 };
 
-
 /*****************************************************************************
  returns an NT error message.  not amazingly helpful, but better than a number.
  *****************************************************************************/
@@ -775,11 +827,6 @@ const char *nt_errstr(NTSTATUS nt_code)
         static char msg[40];
         int idx = 0;
 
-       if (NT_STATUS_IS_LDAP(nt_code)) {
-               slprintf(msg, sizeof(msg), "LDAP code %u", NT_STATUS_LDAP_CODE(nt_code));
-               return msg;
-       }
-
        while (nt_errs[idx].nt_errstr != NULL) {
                if (NT_STATUS_V(nt_errs[idx].nt_errcode) == 
                     NT_STATUS_V(nt_code)) {
@@ -788,6 +835,11 @@ const char *nt_errstr(NTSTATUS nt_code)
                idx++;
        }
 
+       if (NT_STATUS_IS_LDAP(nt_code)) {
+               slprintf(msg, sizeof(msg), "LDAP code %u", NT_STATUS_LDAP_CODE(nt_code));
+               return msg;
+       }
+
        slprintf(msg, sizeof(msg), "NT code 0x%08x", NT_STATUS_V(nt_code));
 
         return msg;
@@ -816,7 +868,7 @@ const char *get_friendly_nt_error_msg(NTSTATUS nt_code)
  *****************************************************************************/
 const char *get_nt_error_c_code(NTSTATUS nt_code)
 {
-        static pstring out;
+        static char out[40];
         int idx = 0;
 
        while (nt_errs[idx].nt_errstr != NULL) {
@@ -835,7 +887,7 @@ const char *get_nt_error_c_code(NTSTATUS nt_code)
 /*****************************************************************************
  returns the NT_STATUS constant matching the string supplied (as an NTSTATUS)
  *****************************************************************************/
-NTSTATUS nt_status_string_to_code(char *nt_status_str)
+NTSTATUS nt_status_string_to_code(const char *nt_status_str)
 {
         int idx = 0;