Convert all uses of uint8/16/32 to uint8/16/32_t in the libads code.
[samba.git] / source3 / libads / ads_status.c
index 017d38c6001b021c0b0d56ef9f47078c53babbe8..70569949aeb2fa1dcfa0d448f6b9ab83fae44d3d 100644 (file)
@@ -8,7 +8,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/>.
 */
 
 #include "includes.h"
+#include "smb_krb5.h"
+#include "system/gssapi.h"
+#include "smb_ldap.h"
+#include "libads/ads_status.h"
 
 /*
   build a ADS_STATUS structure
@@ -79,6 +82,9 @@ NTSTATUS ads_ntstatus(ADS_STATUS status)
                if (status.err.rc == LDAP_SUCCESS) {
                        return NT_STATUS_OK;
                }
+               if (status.err.rc == LDAP_TIMELIMIT_EXCEEDED) {
+                       return NT_STATUS_IO_TIMEOUT;
+               }
                return NT_STATUS_LDAP(status.err.rc);
 #endif
 #ifdef HAVE_KRB5
@@ -100,10 +106,6 @@ NTSTATUS ads_ntstatus(ADS_STATUS status)
 */
 const char *ads_errstr(ADS_STATUS status)
 {
-       static char *ret;
-
-       SAFE_FREE(ret);
-
        switch (status.error_type) {
        case ENUM_ADS_ERROR_SYSTEM:
                return strerror(status.err.rc);
@@ -114,12 +116,11 @@ const char *ads_errstr(ADS_STATUS status)
 #ifdef HAVE_KRB5
        case ENUM_ADS_ERROR_KRB5: 
                return error_message(status.err.rc);
-#endif
-#ifdef HAVE_GSSAPI
        case ENUM_ADS_ERROR_GSS:
        {
-               uint32 msg_ctx;
-               uint32 minor;
+               char *ret;
+               uint32_t msg_ctx;
+               uint32_t minor;
                gss_buffer_desc msg1, msg2;
 
                msg_ctx = 0;
@@ -130,7 +131,9 @@ const char *ads_errstr(ADS_STATUS status)
                                   GSS_C_NULL_OID, &msg_ctx, &msg1);
                gss_display_status(&minor, status.minor_status, GSS_C_MECH_CODE,
                                   GSS_C_NULL_OID, &msg_ctx, &msg2);
-               asprintf(&ret, "%s : %s", (char *)msg1.value, (char *)msg2.value);
+               ret = talloc_asprintf(talloc_tos(), "%s : %s",
+                                     (char *)msg1.value, (char *)msg2.value);
+               SMB_ASSERT(ret != NULL);
                gss_release_buffer(&minor, &msg1);
                gss_release_buffer(&minor, &msg2);
                return ret;
@@ -141,7 +144,14 @@ const char *ads_errstr(ADS_STATUS status)
        default:
                return "Unknown ADS error type!? (not compiled in?)";
        }
-
 }
 
-
+#ifdef HAVE_KRB5
+NTSTATUS gss_err_to_ntstatus(uint32_t maj, uint32_t min)
+{
+        ADS_STATUS adss = ADS_ERROR_GSS(maj, min);
+        DEBUG(10,("gss_err_to_ntstatus: Error %s\n",
+                ads_errstr(adss) ));
+        return ads_ntstatus(adss);
+}
+#endif