summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-22 09:44:41 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-22 07:35:17 +0200
commit348159d1e4c11c330a75600269b1d45be70d8bb2 (patch)
tree17cd28d364421d4eccdebefe579e77e7fe7af93b /lib/util
parent88ad365caf7811772b754bc00e5ca3d0b92812ea (diff)
downloadsamba-348159d1e4c11c330a75600269b1d45be70d8bb2.tar.gz
samba-348159d1e4c11c330a75600269b1d45be70d8bb2.tar.bz2
samba-348159d1e4c11c330a75600269b1d45be70d8bb2.zip
util: util_ntdb.c gets NTDB_ERROR => NTSTATUS map.
Very similar to the tdb version. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/util_ntdb.c43
-rw-r--r--lib/util/util_ntdb.h6
2 files changed, 49 insertions, 0 deletions
diff --git a/lib/util/util_ntdb.c b/lib/util/util_ntdb.c
index f0fc158651..ad9e0a73d2 100644
--- a/lib/util/util_ntdb.c
+++ b/lib/util/util_ntdb.c
@@ -236,3 +236,46 @@ enum NTDB_ERROR ntdb_fetch_bystring(struct ntdb_context *ntdb,
return ntdb_fetch(ntdb, key, data);
}
+
+NTSTATUS map_nt_error_from_ntdb(enum NTDB_ERROR err)
+{
+ NTSTATUS result = NT_STATUS_INTERNAL_ERROR;
+
+ switch (err) {
+ case NTDB_SUCCESS:
+ result = NT_STATUS_OK;
+ break;
+ case NTDB_ERR_CORRUPT:
+ result = NT_STATUS_INTERNAL_DB_CORRUPTION;
+ break;
+ case NTDB_ERR_IO:
+ result = NT_STATUS_UNEXPECTED_IO_ERROR;
+ break;
+ case NTDB_ERR_OOM:
+ result = NT_STATUS_NO_MEMORY;
+ break;
+ case NTDB_ERR_EXISTS:
+ result = NT_STATUS_OBJECT_NAME_COLLISION;
+ break;
+
+ case NTDB_ERR_LOCK:
+ /*
+ * NTDB_ERR_LOCK is very broad, we could for example
+ * distinguish between fcntl locks and invalid lock
+ * sequences. So NT_STATUS_FILE_LOCK_CONFLICT is a
+ * compromise.
+ */
+ result = NT_STATUS_FILE_LOCK_CONFLICT;
+ break;
+ case NTDB_ERR_NOEXIST:
+ result = NT_STATUS_NOT_FOUND;
+ break;
+ case NTDB_ERR_EINVAL:
+ result = NT_STATUS_INVALID_PARAMETER;
+ break;
+ case NTDB_ERR_RDONLY:
+ result = NT_STATUS_ACCESS_DENIED;
+ break;
+ };
+ return result;
+}
diff --git a/lib/util/util_ntdb.h b/lib/util/util_ntdb.h
index 41531791e1..eac0db4f02 100644
--- a/lib/util/util_ntdb.h
+++ b/lib/util/util_ntdb.h
@@ -23,6 +23,7 @@
#define _____LIB_UTIL_UTIL_NTDB_H__
#include <ntdb.h>
#include <talloc.h>
+#include "libcli/util/ntstatus.h"
struct loadparm_context;
union ntdb_attribute;
@@ -102,4 +103,9 @@ static inline NTDB_DATA string_term_ntdb_data(const char *string)
return ntdb_mkdata(string, string ? strlen(string) + 1 : 0);
}
+
+/****************************************************************************
+ Return an NTSTATUS from a NTDB_ERROR
+****************************************************************************/
+NTSTATUS map_nt_error_from_ntdb(enum NTDB_ERROR err);
#endif /* _____LIB_UTIL_UTIL_NTDB_H__ */