lib/util: Move map_nt_error_from_tdb to the top level
authorAndrew Bartlett <abartlet@samba.org>
Mon, 16 Apr 2012 04:18:49 +0000 (14:18 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 18 Apr 2012 02:04:59 +0000 (12:04 +1000)
This will help with making dbwrap available as a top level library.

Andrew Bartlett

lib/util/util_tdb.c
lib/util/util_tdb.h
source3/lib/util_tdb.c

index f239797c470fa471e357786bb5c336275da50515..2096769e57a7621bd47f54353c041f5fbbae046e 100644 (file)
@@ -4,7 +4,8 @@
    tdb utility functions
 
    Copyright (C) Andrew Tridgell 1992-2006
-   
+   Copyright (C) Volker Lendecke 2007-2011
+
    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
@@ -351,3 +352,65 @@ int tdb_traverse_delete_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA d
 {
     return tdb_delete(the_tdb, key);
 }
+
+/****************************************************************************
+ Return an NTSTATUS from a TDB_ERROR
+****************************************************************************/
+
+NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err)
+{
+       NTSTATUS result = NT_STATUS_INTERNAL_ERROR;
+
+       switch (err) {
+       case TDB_SUCCESS:
+               result = NT_STATUS_OK;
+               break;
+       case TDB_ERR_CORRUPT:
+               result = NT_STATUS_INTERNAL_DB_CORRUPTION;
+               break;
+       case TDB_ERR_IO:
+               result = NT_STATUS_UNEXPECTED_IO_ERROR;
+               break;
+       case TDB_ERR_OOM:
+               result = NT_STATUS_NO_MEMORY;
+               break;
+       case TDB_ERR_EXISTS:
+               result = NT_STATUS_OBJECT_NAME_COLLISION;
+               break;
+
+       case TDB_ERR_LOCK:
+               /*
+                * TDB_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;
+
+#ifndef BUILD_TDB2
+       case TDB_ERR_NOLOCK:
+       case TDB_ERR_LOCK_TIMEOUT:
+               /*
+                * These two ones in the enum are not actually used
+                */
+               result = NT_STATUS_FILE_LOCK_CONFLICT;
+               break;
+#endif
+       case TDB_ERR_NOEXIST:
+               result = NT_STATUS_NOT_FOUND;
+               break;
+       case TDB_ERR_EINVAL:
+               result = NT_STATUS_INVALID_PARAMETER;
+               break;
+       case TDB_ERR_RDONLY:
+               result = NT_STATUS_ACCESS_DENIED;
+               break;
+#ifndef BUILD_TDB2
+       case TDB_ERR_NESTING:
+               result = NT_STATUS_INTERNAL_ERROR;
+               break;
+#endif
+       };
+       return result;
+}
index 3d03b990c2ce38d54f92cd693e11f53e81da9838..0b6f3f18a42debd2e673a0624b0f7cc098ace837 100644 (file)
@@ -132,5 +132,11 @@ bool tdb_change_uint32_atomic(struct tdb_context *tdb, const char *keystr, uint3
 int tdb_traverse_delete_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf,
                      void *state);
 
+/****************************************************************************
+ Return an NTSTATUS from a TDB_ERROR
+****************************************************************************/
+
+NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err);
+
 #endif /* _____LIB_UTIL_UTIL_TDB_H__ */
 
index aea5c746509be19eba5bf6b73a84c8145080a85c..e9965ed838d484b377076c147337a089c825c5c4 100644 (file)
@@ -584,64 +584,6 @@ int tdb_trans_delete(struct tdb_context *tdb, TDB_DATA key)
        return res;
 }
 
-NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err)
-{
-       NTSTATUS result = NT_STATUS_INTERNAL_ERROR;
-
-       switch (err) {
-       case TDB_SUCCESS:
-               result = NT_STATUS_OK;
-               break;
-       case TDB_ERR_CORRUPT:
-               result = NT_STATUS_INTERNAL_DB_CORRUPTION;
-               break;
-       case TDB_ERR_IO:
-               result = NT_STATUS_UNEXPECTED_IO_ERROR;
-               break;
-       case TDB_ERR_OOM:
-               result = NT_STATUS_NO_MEMORY;
-               break;
-       case TDB_ERR_EXISTS:
-               result = NT_STATUS_OBJECT_NAME_COLLISION;
-               break;
-
-       case TDB_ERR_LOCK:
-               /*
-                * TDB_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;
-
-#ifndef BUILD_TDB2
-       case TDB_ERR_NOLOCK:
-       case TDB_ERR_LOCK_TIMEOUT:
-               /*
-                * These two ones in the enum are not actually used
-                */
-               result = NT_STATUS_FILE_LOCK_CONFLICT;
-               break;
-#endif
-       case TDB_ERR_NOEXIST:
-               result = NT_STATUS_NOT_FOUND;
-               break;
-       case TDB_ERR_EINVAL:
-               result = NT_STATUS_INVALID_PARAMETER;
-               break;
-       case TDB_ERR_RDONLY:
-               result = NT_STATUS_ACCESS_DENIED;
-               break;
-#ifndef BUILD_TDB2
-       case TDB_ERR_NESTING:
-               result = NT_STATUS_INTERNAL_ERROR;
-               break;
-#endif
-       };
-       return result;
-}
-
 int tdb_data_cmp(TDB_DATA t1, TDB_DATA t2)
 {
        int ret;