summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2002-03-21 23:39:17 +0000
committerJeremy Allison <jra@samba.org>2002-03-21 23:39:17 +0000
commit67d21b5a4ba35244c4362130ce7c501c89839429 (patch)
tree09d8be71cd2f1c6fcf1b3c38fb94406f8671c99a
parent42955a4d8152ed583394db1954b307f965583265 (diff)
downloadsamba-67d21b5a4ba35244c4362130ce7c501c89839429.tar.gz
samba-67d21b5a4ba35244c4362130ce7c501c89839429.tar.bz2
samba-67d21b5a4ba35244c4362130ce7c501c89839429.zip
Make winbindd_idmap tdb endian independent. This is very important for
sharing between machines with rsync. Finally removed tdb_store_int/tdb_fetch_int. Now only tdb_store_int32/tdb_fetch_int32 which are endian independent are allowed. Jeremy. (This used to be commit 1c4a00dcc13f4a7c5876a5cf63ca730190d1132e)
-rw-r--r--source3/nmbd/nmbd_winsserver.c10
-rw-r--r--source3/nsswitch/winbindd_idmap.c57
-rw-r--r--source3/tdb/tdbutil.c93
-rw-r--r--source3/wrepld/process.c4
4 files changed, 53 insertions, 111 deletions
diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c
index 75f93eafde..3332e99e9d 100644
--- a/source3/nmbd/nmbd_winsserver.c
+++ b/source3/nmbd/nmbd_winsserver.c
@@ -240,7 +240,7 @@ BOOL initialise_wins(void)
return True;
}
- if (tdb_fetch_int(tdb, INFO_VERSION) != WINS_VERSION) {
+ if (tdb_fetch_int32(tdb, INFO_VERSION) != WINS_VERSION) {
DEBUG(0,("Discarding invalid wins.dat file\n"));
tdb_close(tdb);
return True;
@@ -1766,7 +1766,7 @@ void wins_write_database(BOOL background)
DEBUG(3,("wins_write_database: Dump of WINS name list.\n"));
- tdb_store_int(tdb, INFO_VERSION, WINS_VERSION);
+ tdb_store_int32(tdb, INFO_VERSION, WINS_VERSION);
for (namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist );
namerec;
@@ -1823,12 +1823,12 @@ void wins_write_database(BOOL background)
}
/* store the number of records */
- tdb_store_int(tdb, INFO_COUNT, num_record);
+ tdb_store_int32(tdb, INFO_COUNT, num_record);
/* get and store the last used ID */
get_global_id_and_update(&id, False);
- tdb_store_int(tdb, INFO_ID_HIGH, id>>32);
- tdb_store_int(tdb, INFO_ID_LOW, id&0xffffffff);
+ tdb_store_int32(tdb, INFO_ID_HIGH, id>>32);
+ tdb_store_int32(tdb, INFO_ID_LOW, id&0xffffffff);
tdb_close(tdb);
diff --git a/source3/nsswitch/winbindd_idmap.c b/source3/nsswitch/winbindd_idmap.c
index 6361cbc70a..fbecbe3252 100644
--- a/source3/nsswitch/winbindd_idmap.c
+++ b/source3/nsswitch/winbindd_idmap.c
@@ -259,7 +259,9 @@ static int convert_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, void *ignor
domain = find_domain_from_name(dom_name);
if (!domain) {
/* what do we do about this?? */
- return 0;
+ DEBUG(0,("winbindd: convert_fn : Unable to find domain %s\n", dom_name ));
+ DEBUG(0,("winbindd: convert_fn : conversion failed - idmap corrupt ?\n"));
+ return -1;
}
rid = atoi(p);
@@ -273,12 +275,16 @@ static int convert_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, void *ignor
if (tdb_store(idmap_tdb, key2, data, TDB_INSERT) != 0) {
/* not good! */
- return 0;
+ DEBUG(0,("winbindd: convert_fn : Unable to update record %s\n", key2.dptr ));
+ DEBUG(0,("winbindd: convert_fn : conversion failed - idmap corrupt ?\n"));
+ return -1;
}
if (tdb_store(idmap_tdb, data, key2, TDB_REPLACE) != 0) {
/* not good! */
- return 0;
+ DEBUG(0,("winbindd: convert_fn : Unable to update record %s\n", data.dptr ));
+ DEBUG(0,("winbindd: convert_fn : conversion failed - idmap corrupt ?\n"));
+ return -1;
}
tdb_delete(idmap_tdb, key);
@@ -289,14 +295,43 @@ static int convert_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, void *ignor
/* convert the idmap database from an older version */
static BOOL idmap_convert(void)
{
- if (tdb_fetch_int(idmap_tdb, "IDMAP_VERSION") == IDMAP_VERSION) {
+ int32 vers = tdb_fetch_int32(idmap_tdb, "IDMAP_VERSION");
+
+ if (vers == IDMAP_VERSION)
return True;
+
+ if (IREV(vers) == IDMAP_VERSION) {
+ /* Arrggghh ! Bytereversed - make order independent ! */
+ int32 wm;
+
+ wm = tdb_fetch_int32(idmap_tdb, HWM_USER);
+
+ if (wm != -1)
+ wm = IREV(wm);
+ else
+ wm = server_state.uid_low;
+
+ if (tdb_store_int32(idmap_tdb, HWM_USER, server_state.uid_low) == -1) {
+ DEBUG(0, ("idmap_convert: Unable to byteswap user hwm in idmap database\n"));
+ return False;
+ }
+
+ wm = tdb_fetch_int32(idmap_tdb, HWM_GROUP);
+ if (wm != -1)
+ wm = IREV(wm);
+ else
+ wm = server_state.gid_low;
+ if (tdb_store_int32(idmap_tdb, HWM_GROUP, server_state.gid_low) == -1) {
+ DEBUG(0, ("idmap_convert: Unable to byteswap group hwm in idmap database\n"));
+ return False;
+ }
}
/* the old format stored as DOMAIN/rid - now we store the SID direct */
tdb_traverse(idmap_tdb, convert_fn, NULL);
- if (tdb_store_int(idmap_tdb, "IDMAP_VERSION", IDMAP_VERSION) == -1) {
+ if (tdb_store_int32(idmap_tdb, "IDMAP_VERSION", IDMAP_VERSION) == -1) {
+ DEBUG(0, ("idmap_convert: Unable to byteswap group hwm in idmap database\n"));
return False;
}
@@ -323,16 +358,16 @@ BOOL winbindd_idmap_init(void)
/* Create high water marks for group and user id */
- if (tdb_fetch_int(idmap_tdb, HWM_USER) == -1) {
- if (tdb_store_int(idmap_tdb, HWM_USER, server_state.uid_low) == -1) {
- DEBUG(0, ("Unable to initialise user hwm in idmap database\n"));
+ if (tdb_fetch_int32(idmap_tdb, HWM_USER) == -1) {
+ if (tdb_store_int32(idmap_tdb, HWM_USER, server_state.uid_low) == -1) {
+ DEBUG(0, ("winbindd_idmap_init: Unable to initialise user hwm in idmap database\n"));
return False;
}
}
- if (tdb_fetch_int(idmap_tdb, HWM_GROUP) == -1) {
- if (tdb_store_int(idmap_tdb, HWM_GROUP, server_state.gid_low) == -1) {
- DEBUG(0, ("Unable to initialise group hwm in idmap database\n"));
+ if (tdb_fetch_int32(idmap_tdb, HWM_GROUP) == -1) {
+ if (tdb_store_int32(idmap_tdb, HWM_GROUP, server_state.gid_low) == -1) {
+ DEBUG(0, ("winbindd_idmap_init: Unable to initialise group hwm in idmap database\n"));
return False;
}
}
diff --git a/source3/tdb/tdbutil.c b/source3/tdb/tdbutil.c
index 0c816735b7..793b44d89d 100644
--- a/source3/tdb/tdbutil.c
+++ b/source3/tdb/tdbutil.c
@@ -52,64 +52,6 @@ void tdb_unlock_bystring(TDB_CONTEXT *tdb, char *keyval)
}
/****************************************************************************
- Fetch a value by a arbitrary blob key, return -1 if not found.
- JRA. DEPRECATED ! Use tdb_fetch_int32_byblob instead.
-****************************************************************************/
-
-int tdb_fetch_int_byblob(TDB_CONTEXT *tdb, char *keyval, size_t len)
-{
- TDB_DATA key, data;
- int ret;
-
- key.dptr = keyval;
- key.dsize = len;
- data = tdb_fetch(tdb, key);
- if (!data.dptr || data.dsize != sizeof(int))
- return -1;
-
- memcpy(&ret, data.dptr, sizeof(int));
- SAFE_FREE(data.dptr);
- return ret;
-}
-
-/****************************************************************************
- Fetch a value by string key, return -1 if not found.
- JRA. DEPRECATED ! Use tdb_fetch_int32 instead.
-****************************************************************************/
-
-int tdb_fetch_int(TDB_CONTEXT *tdb, char *keystr)
-{
- return tdb_fetch_int_byblob(tdb, keystr, strlen(keystr) + 1);
-}
-
-/****************************************************************************
- Store a value by an arbitary blob key, return 0 on success, -1 on failure.
- JRA. DEPRECATED ! Use tdb_store_int32_byblob instead.
-****************************************************************************/
-
-int tdb_store_int_byblob(TDB_CONTEXT *tdb, char *keystr, size_t len, int v)
-{
- TDB_DATA key, data;
-
- key.dptr = keystr;
- key.dsize = len;
- data.dptr = (void *)&v;
- data.dsize = sizeof(int);
-
- return tdb_store(tdb, key, data, TDB_REPLACE);
-}
-
-/****************************************************************************
- Store a value by string key, return 0 on success, -1 on failure.
- JRA. DEPRECATED ! Use tdb_store_int32 instead.
-****************************************************************************/
-
-int tdb_store_int(TDB_CONTEXT *tdb, char *keystr, int v)
-{
- return tdb_store_int_byblob(tdb, keystr, strlen(keystr) + 1, v);
-}
-
-/****************************************************************************
Fetch a int32 value by a arbitrary blob key, return -1 if not found.
Output is int32 in native byte order.
****************************************************************************/
@@ -204,41 +146,6 @@ TDB_DATA tdb_fetch_by_string(TDB_CONTEXT *tdb, char *keystr)
/****************************************************************************
Atomic integer change. Returns old value. To create, set initial value in *oldval.
- Deprecated. Use int32 version. JRA.
-****************************************************************************/
-
-int tdb_change_int_atomic(TDB_CONTEXT *tdb, char *keystr, int *oldval, int change_val)
-{
- int val;
- int ret = -1;
-
- if (tdb_lock_bystring(tdb, keystr) == -1)
- return -1;
-
- if ((val = tdb_fetch_int(tdb, keystr)) == -1) {
- if (tdb_error(tdb) != TDB_ERR_NOEXIST)
- goto err_out;
-
- val = *oldval;
-
- } else {
- *oldval = val;
- val += change_val;
- }
-
- if (tdb_store_int(tdb, keystr, val) == -1)
- goto err_out;
-
- ret = 0;
-
- err_out:
-
- tdb_unlock_bystring(tdb, keystr);
- return ret;
-}
-
-/****************************************************************************
- Atomic integer change. Returns old value. To create, set initial value in *oldval.
****************************************************************************/
int32 tdb_change_int32_atomic(TDB_CONTEXT *tdb, char *keystr, int32 *oldval, int32 change_val)
diff --git a/source3/wrepld/process.c b/source3/wrepld/process.c
index 1bd2ade043..e63b8a993c 100644
--- a/source3/wrepld/process.c
+++ b/source3/wrepld/process.c
@@ -197,8 +197,8 @@ static void get_our_last_id(WINS_OWNER *wins_owner)
return;
}
- wins_owner->max_version=((SMB_BIG_UINT)tdb_fetch_int(tdb, INFO_ID_HIGH))<<32 |
- (SMB_BIG_UINT)tdb_fetch_int(tdb, INFO_ID_LOW);
+ wins_owner->max_version=((SMB_BIG_UINT)tdb_fetch_int32(tdb, INFO_ID_HIGH))<<32 |
+ (SMB_BIG_UINT)tdb_fetch_int32(tdb, INFO_ID_LOW);
tdb_close(tdb);
}