This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[samba.git] / source3 / libads / ads_status.c
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
7    
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 2 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, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25
26 /*
27   build a ADS_STATUS structure
28 */
29 ADS_STATUS ads_build_error(enum ads_error_type etype, 
30                            int rc, int minor_status)
31 {
32         ADS_STATUS ret;
33         ret.error_type = etype;
34         ret.rc = rc;
35         ret.minor_status = minor_status;
36         return ret;
37 }
38
39 /*
40   do a rough conversion between ads error codes and NT status codes
41   we'll need to fill this in more
42 */
43 NTSTATUS ads_ntstatus(ADS_STATUS rc)
44 {
45         if (ADS_ERR_OK(rc)) return NT_STATUS_OK;
46         return NT_STATUS_UNSUCCESSFUL;
47 }
48
49 /*
50   return a string for an error from a ads routine
51 */
52 const char *ads_errstr(ADS_STATUS status)
53 {
54         int msg_ctx;
55         static char *ret;
56
57         SAFE_FREE(ret);
58         msg_ctx = 0;
59
60         switch (status.error_type) {
61         case ADS_ERROR_SYSTEM:
62                 return strerror(status.rc);
63 #ifdef HAVE_LDAP
64         case ADS_ERROR_LDAP:
65                 return ldap_err2string(status.rc);
66 #endif
67 #ifdef HAVE_KRB5
68         case ADS_ERROR_KRB5: 
69                 return error_message(status.rc);
70 #endif
71 #ifdef HAVE_GSSAPI
72         case ADS_ERROR_GSS:
73         {
74                 uint32 minor;
75                 
76                 gss_buffer_desc msg1, msg2;
77                 msg1.value = NULL;
78                 msg2.value = NULL;
79                 gss_display_status(&minor, status.rc, GSS_C_GSS_CODE,
80                                    GSS_C_NULL_OID, &msg_ctx, &msg1);
81                 gss_display_status(&minor, status.minor_status, GSS_C_MECH_CODE,
82                                    GSS_C_NULL_OID, &msg_ctx, &msg2);
83                 asprintf(&ret, "%s : %s", (char *)msg1.value, (char *)msg2.value);
84                 gss_release_buffer(&minor, &msg1);
85                 gss_release_buffer(&minor, &msg2);
86                 return ret;
87         }
88 #endif
89         default:
90                 return "Unknown ADS error type!? (not compiled in?)";
91         }
92
93 }
94
95