From 0ac2b380018bd50eaaf6d6bcfbb6e949b85a6601 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 6 Apr 2003 09:35:16 +0000 Subject: This commit make winbindd copy winbindd_idmap.tdb into idmap.tdb on the first run if idmap.tdb is not found, and then eventually convert it to the new format. This is done to unify winbind and idmap databases and to make a backup of winbindd_idmap.tdb in case you want to downgrade (of course it will not be updated). This is needed because idmap.tdb contains also local mappings, not only foreign domains mappings. Added some other fixes/improvements Simo. (This used to be commit cf17261519fd8775500f9b9d6caa2bc462e04633) --- source3/nsswitch/winbindd_idmap_tdb.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'source3/nsswitch') diff --git a/source3/nsswitch/winbindd_idmap_tdb.c b/source3/nsswitch/winbindd_idmap_tdb.c index b47b7ed07d..12d6972bae 100644 --- a/source3/nsswitch/winbindd_idmap_tdb.c +++ b/source3/nsswitch/winbindd_idmap_tdb.c @@ -106,7 +106,7 @@ static int tdb_convert_fn(TDB_CONTEXT * tdb, TDB_DATA key, TDB_DATA data, /***************************************************************************** Convert the idmap database from an older version. *****************************************************************************/ -static BOOL tdb_idmap_convert(const char *idmap_name) +static BOOL tdb_idmap_convert(void) { int32 vers = tdb_fetch_int32(idmap_tdb, "IDMAP_VERSION"); BOOL bigendianheader = @@ -280,8 +280,27 @@ static BOOL tdb_get_id_from_sid(DOM_SID * sid, uid_t * id, BOOL isgroup) *****************************************************************************/ static BOOL tdb_idmap_init(void) { + SMB_STRUCT_STAT stbuf; + + /* move to the new database on first startup */ + if (!file_exist(lock_path("idmap.tdb"), &stbuf)) { + if (file_exist(lock_path("winbindd_idmap.tdb"), &stbuf)) { + char *cmd = NULL; + + /* lazy file copy */ + if (asprintf(&cmd, "cp -p %s/winbindd_idmap.tdb %s/idmap.tdb", lp_lockdir(), lp_lockdir()) != -1) { + system(cmd); + free(cmd); + } + if (!file_exist(lock_path("idmap.tdb"), &stbuf)) { + DEBUG(0, ("idmap_init: Unable to make a new database copy\n")); + return False; + } + } + } + /* Open tdb cache */ - if (!(idmap_tdb = tdb_open_log(lock_path("winbindd_idmap.tdb"), 0, + if (!(idmap_tdb = tdb_open_log(lock_path("idmap.tdb"), 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0600))) { DEBUG(0, @@ -290,9 +309,8 @@ static BOOL tdb_idmap_init(void) } /* possibly convert from an earlier version */ - if (!tdb_idmap_convert(lock_path("winbindd_idmap.tdb"))) { - DEBUG(0, - ("winbindd_idmap_init: Unable to open idmap database\n")); + if (!tdb_idmap_convert()) { + DEBUG(0, ("winbindd_idmap_init: Unable to open idmap database\n")); return False; } -- cgit