Samba 3: added Samba 3.0.24 sources
[tomato.git] / release / src / router / samba3 / source / libads / ads_status.c
blob536ef766e374a6ece9e47c2d2b4abe370337c029
1 /*
2 Unix SMB/CIFS implementation.
3 ads (active directory) utility library
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Remus Koos 2001
6 Copyright (C) Andrew Bartlett 2001
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 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "includes.h"
27 build a ADS_STATUS structure
29 ADS_STATUS ads_build_error(enum ads_error_type etype,
30 int rc, int minor_status)
32 ADS_STATUS ret;
34 if (etype == ENUM_ADS_ERROR_NT) {
35 DEBUG(0,("don't use ads_build_error with ENUM_ADS_ERROR_NT!\n"));
36 ret.err.rc = -1;
37 ret.error_type = ENUM_ADS_ERROR_SYSTEM;
38 ret.minor_status = 0;
39 return ret;
42 ret.err.rc = rc;
43 ret.error_type = etype;
44 ret.minor_status = minor_status;
45 return ret;
48 ADS_STATUS ads_build_nt_error(enum ads_error_type etype,
49 NTSTATUS nt_status)
51 ADS_STATUS ret;
53 if (etype != ENUM_ADS_ERROR_NT) {
54 DEBUG(0,("don't use ads_build_nt_error without ENUM_ADS_ERROR_NT!\n"));
55 ret.err.rc = -1;
56 ret.error_type = ENUM_ADS_ERROR_SYSTEM;
57 ret.minor_status = 0;
58 return ret;
60 ret.err.nt_status = nt_status;
61 ret.error_type = etype;
62 ret.minor_status = 0;
63 return ret;
67 do a rough conversion between ads error codes and NT status codes
68 we'll need to fill this in more
70 NTSTATUS ads_ntstatus(ADS_STATUS status)
72 if (status.error_type == ENUM_ADS_ERROR_NT){
73 return status.err.nt_status;
75 #ifdef HAVE_LDAP
76 if ((status.error_type == ENUM_ADS_ERROR_LDAP)
77 && (status.err.rc == LDAP_NO_MEMORY)) {
78 return NT_STATUS_NO_MEMORY;
80 #endif
81 #ifdef HAVE_KRB5
82 if (status.error_type == ENUM_ADS_ERROR_KRB5) {
83 if (status.err.rc == KRB5KDC_ERR_PREAUTH_FAILED) {
84 return NT_STATUS_LOGON_FAILURE;
85 } else if (status.err.rc == KRB5_KDC_UNREACH) {
86 return NT_STATUS_NO_LOGON_SERVERS;
89 #endif
90 if (ADS_ERR_OK(status)) return NT_STATUS_OK;
91 return NT_STATUS_UNSUCCESSFUL;
95 return a string for an error from a ads routine
97 const char *ads_errstr(ADS_STATUS status)
99 static char *ret;
101 SAFE_FREE(ret);
103 switch (status.error_type) {
104 case ENUM_ADS_ERROR_SYSTEM:
105 return strerror(status.err.rc);
106 #ifdef HAVE_LDAP
107 case ENUM_ADS_ERROR_LDAP:
108 return ldap_err2string(status.err.rc);
109 #endif
110 #ifdef HAVE_KRB5
111 case ENUM_ADS_ERROR_KRB5:
112 return error_message(status.err.rc);
113 #endif
114 #ifdef HAVE_GSSAPI
115 case ENUM_ADS_ERROR_GSS:
117 uint32 msg_ctx;
118 uint32 minor;
119 gss_buffer_desc msg1, msg2;
121 msg_ctx = 0;
123 msg1.value = NULL;
124 msg2.value = NULL;
125 gss_display_status(&minor, status.err.rc, GSS_C_GSS_CODE,
126 GSS_C_NULL_OID, &msg_ctx, &msg1);
127 gss_display_status(&minor, status.minor_status, GSS_C_MECH_CODE,
128 GSS_C_NULL_OID, &msg_ctx, &msg2);
129 asprintf(&ret, "%s : %s", (char *)msg1.value, (char *)msg2.value);
130 gss_release_buffer(&minor, &msg1);
131 gss_release_buffer(&minor, &msg2);
132 return ret;
134 #endif
135 case ENUM_ADS_ERROR_NT:
136 return get_friendly_nt_error_msg(ads_ntstatus(status));
137 default:
138 return "Unknown ADS error type!? (not compiled in?)";