From 9199721eba64b7808471f6f0811dfd20e85938ca Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 26 Apr 2002 23:11:26 +0000 Subject: Attempt to fix big-endian upgrade problem (Herb, Jerry, please check). Jeremy. (This used to be commit 54261460b35cc531e033a99596d5596e94bebe24) --- source3/nsswitch/winbindd_idmap.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'source3/nsswitch/winbindd_idmap.c') diff --git a/source3/nsswitch/winbindd_idmap.c b/source3/nsswitch/winbindd_idmap.c index 6528efea43..3649b8ff7a 100644 --- a/source3/nsswitch/winbindd_idmap.c +++ b/source3/nsswitch/winbindd_idmap.c @@ -363,6 +363,7 @@ fail: static BOOL idmap_convert(const char *idmap_name) { + BOOL bytereversed = False; int32 vers = tdb_fetch_int32(idmap_tdb, "IDMAP_VERSION"); if (vers == IDMAP_VERSION) @@ -374,15 +375,18 @@ static BOOL idmap_convert(const char *idmap_name) return False; #endif - if ((vers == -1) || (IREV(vers) == IDMAP_VERSION)) { + bytereversed = (IREV(vers) == IDMAP_VERSION) ? True : False; + + if ((vers == -1) || bytereversed) { /* Arrggghh ! Bytereversed or missing - make order independent ! */ int32 wm; wm = tdb_fetch_int32(idmap_tdb, HWM_USER); - if (wm != -1) + if (wm != -1 && bytereversed) { + /* A record existed and it was from a big endian machine. */ wm = IREV(wm); - else + } else if (wm == -1) wm = server_state.uid_low; if (tdb_store_int32(idmap_tdb, HWM_USER, wm) == -1) { @@ -391,10 +395,12 @@ static BOOL idmap_convert(const char *idmap_name) } wm = tdb_fetch_int32(idmap_tdb, HWM_GROUP); - if (wm != -1) + if (wm != -1 && bytereversed) { + /* A record existed and it was from a big endian machine. */ wm = IREV(wm); - else + } else if (wm == -1) wm = server_state.gid_low; + if (tdb_store_int32(idmap_tdb, HWM_GROUP, wm) == -1) { DEBUG(0, ("idmap_convert: Unable to byteswap group hwm in idmap database\n")); return False; @@ -404,7 +410,7 @@ static BOOL idmap_convert(const char *idmap_name) /* the old format stored as DOMAIN/rid - now we store the SID direct */ tdb_traverse(idmap_tdb, convert_fn, NULL); - if (tdb_store_int32(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; } -- cgit