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 3 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.
27 build a ADS_STATUS structure
29 ADS_STATUS ads_build_error(enum ads_error_type etype,
30 int rc, int minor_status)
34 if (etype == ENUM_ADS_ERROR_NT) {
35 DEBUG(0,("don't use ads_build_error with ENUM_ADS_ERROR_NT!\n"));
37 ret.error_type = ENUM_ADS_ERROR_SYSTEM;
43 ret.error_type = etype;
44 ret.minor_status = minor_status;
48 ADS_STATUS ads_build_nt_error(enum ads_error_type etype,
53 if (etype != ENUM_ADS_ERROR_NT) {
54 DEBUG(0,("don't use ads_build_nt_error without ENUM_ADS_ERROR_NT!\n"));
56 ret.error_type = ENUM_ADS_ERROR_SYSTEM;
60 ret.err.nt_status = nt_status;
61 ret.error_type = etype;
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 switch (status.error_type) {
73 case ENUM_ADS_ERROR_NT:
74 return status.err.nt_status;
75 case ENUM_ADS_ERROR_SYSTEM:
76 return map_nt_error_from_unix(status.err.rc);
78 case ENUM_ADS_ERROR_LDAP:
79 if (status.err.rc == LDAP_SUCCESS) {
82 return NT_STATUS_LDAP(status.err.rc);
85 case ENUM_ADS_ERROR_KRB5:
86 return krb5_to_nt_status(status.err.rc);
89 case ENUM_ADS_ERROR_GSS:
90 return map_nt_error_from_gss(status.err.rc, status.minor_status);
96 if (ADS_ERR_OK(status)) {
99 return NT_STATUS_UNSUCCESSFUL;
103 return a string for an error from a ads routine
105 const char *ads_errstr(ADS_STATUS status)
111 switch (status.error_type) {
112 case ENUM_ADS_ERROR_SYSTEM:
113 return strerror(status.err.rc);
115 case ENUM_ADS_ERROR_LDAP:
116 return ldap_err2string(status.err.rc);
119 case ENUM_ADS_ERROR_KRB5:
120 return error_message(status.err.rc);
123 case ENUM_ADS_ERROR_GSS:
127 gss_buffer_desc msg1, msg2;
133 gss_display_status(&minor, status.err.rc, GSS_C_GSS_CODE,
134 GSS_C_NULL_OID, &msg_ctx, &msg1);
135 gss_display_status(&minor, status.minor_status, GSS_C_MECH_CODE,
136 GSS_C_NULL_OID, &msg_ctx, &msg2);
137 asprintf(&ret, "%s : %s", (char *)msg1.value, (char *)msg2.value);
138 gss_release_buffer(&minor, &msg1);
139 gss_release_buffer(&minor, &msg2);
143 case ENUM_ADS_ERROR_NT:
144 return get_friendly_nt_error_msg(ads_ntstatus(status));
146 return "Unknown ADS error type!? (not compiled in?)";
151 NTSTATUS gss_err_to_ntstatus(uint32 maj, uint32 min)
153 ADS_STATUS adss = ADS_ERROR_GSS(maj, min);
154 DEBUG(10,("gss_err_to_ntstatus: Error %s\n",
156 return ads_ntstatus(adss);