Author: vlendec Date: 2007-05-28 11:08:58 +0000 (Mon, 28 May 2007) New Revision: 23170
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23170 Log: Add map_nt_error_from_tdb() Modified: branches/SAMBA_3_0/source/lib/dbwrap_tdb.c branches/SAMBA_3_0/source/lib/util_tdb.c branches/SAMBA_3_0_26/source/lib/dbwrap_tdb.c branches/SAMBA_3_0_26/source/lib/util_tdb.c Changeset: Modified: branches/SAMBA_3_0/source/lib/dbwrap_tdb.c =================================================================== --- branches/SAMBA_3_0/source/lib/dbwrap_tdb.c 2007-05-27 17:12:08 UTC (rev 23169) +++ branches/SAMBA_3_0/source/lib/dbwrap_tdb.c 2007-05-28 11:08:58 UTC (rev 23170) @@ -127,9 +127,15 @@ { struct db_tdb_ctx *ctx = talloc_get_type_abort(rec->private_data, struct db_tdb_ctx); + int res; + + res = tdb_delete(ctx->tdb, rec->key); - return (tdb_delete(ctx->tdb, rec->key) == 0) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; + if (res == 0) { + return NT_STATUS_OK; + } + + return map_nt_error_from_tdb(tdb_error(ctx->tdb)); } struct db_tdb_traverse_ctx { Modified: branches/SAMBA_3_0/source/lib/util_tdb.c =================================================================== --- branches/SAMBA_3_0/source/lib/util_tdb.c 2007-05-27 17:12:08 UTC (rev 23169) +++ branches/SAMBA_3_0/source/lib/util_tdb.c 2007-05-28 11:08:58 UTC (rev 23170) @@ -940,3 +940,40 @@ return w; } + +NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err) +{ + struct { enum TDB_ERROR err; NTSTATUS status; } map[] = + { { TDB_SUCCESS, NT_STATUS_OK }, + { TDB_ERR_CORRUPT, NT_STATUS_INTERNAL_DB_CORRUPTION }, + { TDB_ERR_IO, NT_STATUS_UNEXPECTED_IO_ERROR }, + { TDB_ERR_OOM, NT_STATUS_NO_MEMORY }, + { TDB_ERR_EXISTS, NT_STATUS_OBJECT_NAME_COLLISION }, + + /* + * 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. + */ + { TDB_ERR_LOCK, NT_STATUS_FILE_LOCK_CONFLICT }, + /* + * The next two ones in the enum are not actually used + */ + { TDB_ERR_NOLOCK, NT_STATUS_FILE_LOCK_CONFLICT }, + { TDB_ERR_LOCK_TIMEOUT, NT_STATUS_FILE_LOCK_CONFLICT }, + { TDB_ERR_NOEXIST, NT_STATUS_NOT_FOUND }, + { TDB_ERR_EINVAL, NT_STATUS_INVALID_PARAMETER }, + { TDB_ERR_RDONLY, NT_STATUS_ACCESS_DENIED } + }; + + int i; + + for (i=0; i < sizeof(map) / sizeof(map[0]); i++) { + if (err == map[i].err) { + return map[i].status; + } + } + + return NT_STATUS_INTERNAL_ERROR; +} Modified: branches/SAMBA_3_0_26/source/lib/dbwrap_tdb.c =================================================================== --- branches/SAMBA_3_0_26/source/lib/dbwrap_tdb.c 2007-05-27 17:12:08 UTC (rev 23169) +++ branches/SAMBA_3_0_26/source/lib/dbwrap_tdb.c 2007-05-28 11:08:58 UTC (rev 23170) @@ -125,9 +125,15 @@ { struct db_tdb_ctx *ctx = talloc_get_type_abort(rec->private_data, struct db_tdb_ctx); + int res; + + res = tdb_delete(ctx->tdb, rec->key); - return (tdb_delete(ctx->tdb, rec->key) == 0) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; + if (res == 0) { + return NT_STATUS_OK; + } + + return map_nt_error_from_tdb(tdb_error(ctx->tdb)); } struct db_tdb_traverse_ctx { Modified: branches/SAMBA_3_0_26/source/lib/util_tdb.c =================================================================== --- branches/SAMBA_3_0_26/source/lib/util_tdb.c 2007-05-27 17:12:08 UTC (rev 23169) +++ branches/SAMBA_3_0_26/source/lib/util_tdb.c 2007-05-28 11:08:58 UTC (rev 23170) @@ -940,3 +940,40 @@ return w; } + +NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err) +{ + struct { enum TDB_ERROR err; NTSTATUS status; } map[] = + { { TDB_SUCCESS, NT_STATUS_OK }, + { TDB_ERR_CORRUPT, NT_STATUS_INTERNAL_DB_CORRUPTION }, + { TDB_ERR_IO, NT_STATUS_UNEXPECTED_IO_ERROR }, + { TDB_ERR_OOM, NT_STATUS_NO_MEMORY }, + { TDB_ERR_EXISTS, NT_STATUS_OBJECT_NAME_COLLISION }, + + /* + * 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. + */ + { TDB_ERR_LOCK, NT_STATUS_FILE_LOCK_CONFLICT }, + /* + * The next two ones in the enum are not actually used + */ + { TDB_ERR_NOLOCK, NT_STATUS_FILE_LOCK_CONFLICT }, + { TDB_ERR_LOCK_TIMEOUT, NT_STATUS_FILE_LOCK_CONFLICT }, + { TDB_ERR_NOEXIST, NT_STATUS_NOT_FOUND }, + { TDB_ERR_EINVAL, NT_STATUS_INVALID_PARAMETER }, + { TDB_ERR_RDONLY, NT_STATUS_ACCESS_DENIED } + }; + + int i; + + for (i=0; i < sizeof(map) / sizeof(map[0]); i++) { + if (err == map[i].err) { + return map[i].status; + } + } + + return NT_STATUS_INTERNAL_ERROR; +}