summaryrefslogtreecommitdiff
path: root/libcli
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2019-05-22 17:09:50 +0200
committerAndreas Schneider <asn@cryptomilk.org>2019-06-24 06:11:16 +0000
commitf54dfd97aaccd94241340f84936082dd3ea20c5d (patch)
treee28b35f6e607ad599649fa5b017120a4604b87e4 /libcli
parentaa2a3d95098231f48d7c308881bf66418164111e (diff)
downloadsamba-f54dfd97aaccd94241340f84936082dd3ea20c5d.tar.gz
libcli:util: Add gnutls_error
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'libcli')
-rw-r--r--libcli/util/gnutls_error.c69
-rw-r--r--libcli/util/gnutls_error.h31
-rw-r--r--libcli/util/wscript_build5
3 files changed, 103 insertions, 2 deletions
diff --git a/libcli/util/gnutls_error.c b/libcli/util/gnutls_error.c
new file mode 100644
index 00000000000..306977cd771
--- /dev/null
+++ b/libcli/util/gnutls_error.c
@@ -0,0 +1,69 @@
+/*
+ * 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_error.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;
+}
diff --git a/libcli/util/gnutls_error.h b/libcli/util/gnutls_error.h
new file mode 100644
index 00000000000..fa6420cea30
--- /dev/null
+++ b/libcli/util/gnutls_error.h
@@ -0,0 +1,31 @@
+/*
+ * 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/>.
+ */
+
+#ifndef _GNUTLS_ERROR_H
+#define _GNUTLS_ERROR_H
+
+#include "ntstatus.h"
+
+NTSTATUS _gnutls_error_to_ntstatus(int gnutls_rc,
+ NTSTATUS blocked_status,
+ const char *function,
+ const char *location);
+#define gnutls_error_to_ntstatus(gnutls_rc, blocked_status) \
+ _gnutls_error_to_ntstatus(gnutls_rc, blocked_status, \
+ __FUNCTION__, __location__)
+
+#endif /* _GNUTLS_ERROR_H */
diff --git a/libcli/util/wscript_build b/libcli/util/wscript_build
index 9713c9d5d70..56a70f888e9 100644
--- a/libcli/util/wscript_build
+++ b/libcli/util/wscript_build
@@ -2,11 +2,12 @@
bld.SAMBA_LIBRARY('samba-errors',
- public_headers='error.h ntstatus.h ntstatus_gen.h doserr.h werror.h werror_gen.h hresult.h',
+ public_headers='error.h ntstatus.h ntstatus_gen.h doserr.h werror.h werror_gen.h hresult.h gnutls_error.h',
private_headers='nterr_private.h',
header_path='core',
- source='doserr.c errormap.c nterr.c errmap_unix.c hresult.c',
+ source='doserr.c errormap.c nterr.c errmap_unix.c hresult.c gnutls_error.c',
public_deps='talloc samba-debug',
+ deps='gnutls',
# private_library=True,
pc_files=[],
vnum='1',