mirror of
https://github.com/samba-team/samba.git
synced 2025-03-09 08:58:35 +03:00
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)
This commit is contained in:
parent
42955a4d81
commit
67d21b5a4b
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -51,64 +51,6 @@ void tdb_unlock_bystring(TDB_CONTEXT *tdb, char *keyval)
|
||||
tdb_chainunlock(tdb, key);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
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.
|
||||
@ -202,41 +144,6 @@ TDB_DATA tdb_fetch_by_string(TDB_CONTEXT *tdb, char *keystr)
|
||||
return tdb_fetch(tdb, key);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user