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