Fix the compile on systems without a full kerberos kit.
[amitay/samba.git] / source3 / libads / ads_status.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0
4    ads (active directory) utility library
5    Copyright (C) Andrew Tridgell 2001
6    Copyright (C) Remus Koos 2001
7    Copyright (C) Andrew Bartlett 2001
8    
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 #include "includes.h"
26
27 /*
28   build a ADS_STATUS structure
29 */
30 ADS_STATUS ads_build_error(enum ads_error_type etype, 
31                            int rc, int minor_status)
32 {
33         ADS_STATUS ret;
34         ret.error_type = etype;
35         ret.rc = rc;
36         ret.minor_status = minor_status;
37         return ret;
38 }
39
40 /*
41   do a rough conversion between ads error codes and NT status codes
42   we'll need to fill this in more
43 */
44 NTSTATUS ads_ntstatus(ADS_STATUS rc)
45 {
46         if (ADS_ERR_OK(rc)) return NT_STATUS_OK;
47         return NT_STATUS_UNSUCCESSFUL;
48 }
49
50 /*
51   return a string for an error from a ads routine
52 */
53 const char *ads_errstr(ADS_STATUS status)
54 {
55         uint32 minor;
56         int msg_ctx;
57         static char *ret;
58
59         SAFE_FREE(ret);
60         msg_ctx = 0;
61
62         switch (status.error_type) {
63         case ADS_ERROR_SYSTEM:
64                 return strerror(status.rc);
65 #ifdef HAVE_LDAP
66         case ADS_ERROR_LDAP:
67                 return ldap_err2string(status.rc);
68 #endif
69 #ifdef HAVE_KRB5
70         case ADS_ERROR_KRB5: 
71                 return error_message(status.rc);
72         case ADS_ERROR_GSS:
73         {
74                 gss_buffer_desc msg1, msg2;
75                 msg1.value = NULL;
76                 msg2.value = NULL;
77                 gss_display_status(&minor, status.rc, GSS_C_GSS_CODE,
78                                    GSS_C_NULL_OID, &msg_ctx, &msg1);
79                 gss_display_status(&minor, status.minor_status, GSS_C_MECH_CODE,
80                                    GSS_C_NULL_OID, &msg_ctx, &msg2);
81                 asprintf(&ret, "%s : %s", (char *)msg1.value, (char *)msg2.value);
82                 gss_release_buffer(&minor, &msg1);
83                 gss_release_buffer(&minor, &msg2);
84                 return ret;
85         }
86 #endif
87         default:
88                 return "Unknown ADS error type!? (not compiled in?)";
89         }
90
91 }
92
93