s4:kdc: also provide cross-realm keys via samba_kdc_seq()
[Samba.git] / lib / crypto / gnutls_error.c
blob764e217532859173dbd29ccff47537523ea6d24c
1 /*
2 * Copyright (c) 2019 Andreas Schneider <asn@samba.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "includes.h"
19 #include "gnutls_helpers.h"
21 #include <gnutls/gnutls.h>
23 NTSTATUS _gnutls_error_to_ntstatus(int gnutls_rc,
24 NTSTATUS blocked_status,
25 const char *function,
26 const char *location)
28 NTSTATUS status;
30 if (gnutls_rc == GNUTLS_E_SUCCESS) {
31 return NT_STATUS_OK;
34 switch (gnutls_rc) {
35 case GNUTLS_E_UNWANTED_ALGORITHM:
36 status = blocked_status;
37 break;
38 case GNUTLS_E_MEMORY_ERROR:
39 status = NT_STATUS_NO_MEMORY;
40 break;
41 case GNUTLS_E_INVALID_REQUEST:
42 status = NT_STATUS_INVALID_VARIANT;
43 break;
44 case GNUTLS_E_DECRYPTION_FAILED:
45 status = NT_STATUS_DECRYPTION_FAILED;
46 break;
47 case GNUTLS_E_ENCRYPTION_FAILED:
48 status = NT_STATUS_ENCRYPTION_FAILED;
49 break;
50 case GNUTLS_E_SHORT_MEMORY_BUFFER:
51 status = NT_STATUS_INVALID_PARAMETER;
52 break;
53 case GNUTLS_E_BASE64_DECODING_ERROR:
54 case GNUTLS_E_HASH_FAILED:
55 case GNUTLS_E_LIB_IN_ERROR_STATE:
56 case GNUTLS_E_INTERNAL_ERROR:
57 default:
58 status = NT_STATUS_INTERNAL_ERROR;
59 break;
62 D_WARNING("%s: GNUTLS ERROR: %s, NTSTATUS: %s at %s\n",
63 function,
64 gnutls_strerror_name(gnutls_rc),
65 nt_errstr(status),
66 location);
68 return status;
71 WERROR _gnutls_error_to_werror(int gnutls_rc,
72 WERROR blocked_werr,
73 const char *function,
74 const char *location)
76 WERROR werr;
78 if (gnutls_rc == GNUTLS_E_SUCCESS) {
79 return WERR_OK;
82 switch (gnutls_rc) {
83 case GNUTLS_E_UNWANTED_ALGORITHM:
84 werr = blocked_werr;
85 break;
86 case GNUTLS_E_MEMORY_ERROR:
87 werr = WERR_NOT_ENOUGH_MEMORY;
88 break;
89 case GNUTLS_E_INVALID_REQUEST:
90 werr = WERR_INVALID_VARIANT;
91 break;
92 case GNUTLS_E_DECRYPTION_FAILED:
93 werr = WERR_DECRYPTION_FAILED;
94 break;
95 case GNUTLS_E_ENCRYPTION_FAILED:
96 werr = WERR_ENCRYPTION_FAILED;
97 break;
98 case GNUTLS_E_SHORT_MEMORY_BUFFER:
99 werr = WERR_INVALID_PARAMETER;
100 break;
101 case GNUTLS_E_BASE64_DECODING_ERROR:
102 case GNUTLS_E_HASH_FAILED:
103 case GNUTLS_E_LIB_IN_ERROR_STATE:
104 case GNUTLS_E_INTERNAL_ERROR:
105 default:
106 werr = WERR_INTERNAL_ERROR;
107 break;
110 D_WARNING("%s: GNUTLS ERROR: %s, WERROR: %s at %s\n",
111 function,
112 gnutls_strerror_name(gnutls_rc),
113 win_errstr(werr),
114 location);
116 return werr;