summaryrefslogtreecommitdiff
path: root/source3/sam
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2003-04-06 09:35:16 +0000
committerSimo Sorce <idra@samba.org>2003-04-06 09:35:16 +0000
commit0ac2b380018bd50eaaf6d6bcfbb6e949b85a6601 (patch)
tree99d701957698c8c4e8f7c99e4c83424b5009e088 /source3/sam
parent588b1978a19f8bb468165740dc293ae1a4e28951 (diff)
downloadsamba-0ac2b380018bd50eaaf6d6bcfbb6e949b85a6601.tar.gz
samba-0ac2b380018bd50eaaf6d6bcfbb6e949b85a6601.tar.bz2
samba-0ac2b380018bd50eaaf6d6bcfbb6e949b85a6601.zip
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)
Diffstat (limited to 'source3/sam')
-rw-r--r--source3/sam/idmap_tdb.c160
-rw-r--r--source3/sam/idmap_winbind.c8
2 files changed, 18 insertions, 150 deletions
diff --git a/source3/sam/idmap_tdb.c b/source3/sam/idmap_tdb.c
index ec365b603d..8ecf4d6e7e 100644
--- a/source3/sam/idmap_tdb.c
+++ b/source3/sam/idmap_tdb.c
@@ -45,143 +45,6 @@ static struct idmap_state {
gid_t gid_low, gid_high; /* Range of gids to allocate */
} idmap_state;
-
-/* FIXME: let handle conversions when all things work ok.
- I think it is better to handle the conversion at
- upgrade time and leave the old db intact.
- That would also make easier to go back to 2.2 if needed
- ---SSS */
-#if 0
-
-/* convert one record to the new format */
-static int tdb_convert_fn(TDB_CONTEXT * tdb, TDB_DATA key, TDB_DATA data,
- void *ignored)
-{
- struct winbindd_domain *domain;
- char *p;
- DOM_SID sid;
- uint32 rid;
- fstring keystr;
- fstring dom_name;
- TDB_DATA key2;
-
- p = strchr(key.dptr, '/');
- if (!p)
- return 0;
-
- *p = 0;
- fstrcpy(dom_name, key.dptr);
- *p++ = '/';
-
- domain = find_domain_from_name(dom_name);
- if (!domain) {
- /* We must delete the old record. */
- DEBUG(0,
- ("winbindd: tdb_convert_fn : Unable to find domain %s\n",
- dom_name));
- DEBUG(0,
- ("winbindd: tdb_convert_fn : deleting record %s\n",
- key.dptr));
- tdb_delete(idmap_tdb, key);
- return 0;
- }
-
- rid = atoi(p);
-
- sid_copy(&sid, &domain->sid);
- sid_append_rid(&sid, rid);
-
- sid_to_string(keystr, &sid);
- key2.dptr = keystr;
- key2.dsize = strlen(keystr) + 1;
-
- if (tdb_store(idmap_tdb, key2, data, TDB_INSERT) != 0) {
- /* not good! */
- DEBUG(0,
- ("winbindd: tdb_convert_fn : Unable to update record %s\n",
- key2.dptr));
- DEBUG(0,
- ("winbindd: tdb_convert_fn : conversion failed - idmap corrupt ?\n"));
- return -1;
- }
-
- if (tdb_store(idmap_tdb, data, key2, TDB_REPLACE) != 0) {
- /* not good! */
- DEBUG(0,
- ("winbindd: tdb_convert_fn : Unable to update record %s\n",
- data.dptr));
- DEBUG(0,
- ("winbindd: tdb_convert_fn : conversion failed - idmap corrupt ?\n"));
- return -1;
- }
-
- tdb_delete(idmap_tdb, key);
-
- return 0;
-}
-
-/*****************************************************************************
- Convert the idmap database from an older version.
-*****************************************************************************/
-static BOOL tdb_idmap_convert(const char *idmap_name)
-{
- int32 vers = tdb_fetch_int32(idmap_tdb, "IDMAP_VERSION");
- BOOL bigendianheader =
- (idmap_tdb->flags & TDB_BIGENDIAN) ? True : False;
-
- if (vers == IDMAP_VERSION)
- return True;
-
- if (((vers == -1) && bigendianheader)
- || (IREV(vers) == IDMAP_VERSION)) {
- /* Arrggghh ! Bytereversed or old big-endian - make order independent ! */
- /*
- * high and low records were created on a
- * big endian machine and will need byte-reversing.
- */
-
- 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, wm) == -1) {
- DEBUG(0,
- ("tdb_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, wm) == -1) {
- DEBUG(0,
- ("tdb_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, tdb_convert_fn, NULL);
-
- if (tdb_store_int32(idmap_tdb, "IDMAP_VERSION", IDMAP_VERSION) ==
- -1) {
- DEBUG(0,
- ("tdb_idmap_convert: Unable to byteswap group hwm in idmap database\n"));
- return False;
- }
-
- return True;
-}
-#endif
-
/* Allocate either a user or group id from the pool */
static NTSTATUS db_allocate_id(unid_t *id, int id_type)
{
@@ -387,25 +250,26 @@ static NTSTATUS db_set_mapping(DOM_SID *sid, unid_t id, int id_type)
/*****************************************************************************
Initialise idmap database.
*****************************************************************************/
-static NTSTATUS db_idmap_init(const char *db_name)
+static NTSTATUS db_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)) {
+ DEBUG(0, ("idmap_init: winbindd_idmap.tdb is present and idmap.tdb is not!\nPlease RUN winbindd first to convert the db to the new format!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+ }
+
/* Open tdb cache */
- if (!(idmap_tdb = tdb_open_log(lock_path(db_name), 0,
+ if (!(idmap_tdb = tdb_open_log(lock_path("idmap.tdb"), 0,
TDB_DEFAULT, O_RDWR | O_CREAT,
0600))) {
DEBUG(0, ("idmap_init: Unable to open idmap database\n"));
return NT_STATUS_UNSUCCESSFUL;
}
-#if 0
- /* possibly convert from an earlier version */
- if (!tdb_idmap_convert(lock_path("winbind_idmap.tdb"))) {
- DEBUG(0,
- ("idmap_init: Unable to open old idmap database\n"));
- return False;
- }
-#endif
-
/* Create high water marks for group and user id */
if (tdb_fetch_int32(idmap_tdb, HWM_USER) == -1) {
if (tdb_store_int32(idmap_tdb, HWM_USER, idmap_state.uid_low) == -1) {
diff --git a/source3/sam/idmap_winbind.c b/source3/sam/idmap_winbind.c
index c2c46cfb57..d89c9e7bac 100644
--- a/source3/sam/idmap_winbind.c
+++ b/source3/sam/idmap_winbind.c
@@ -38,7 +38,6 @@ static NTSTATUS db_get_sid_from_id(DOM_SID *sid, unid_t id, int id_type)
struct winbindd_request request;
struct winbindd_response response;
int result, operation;
- fstring sid_str;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
@@ -82,6 +81,8 @@ static NTSTATUS db_get_id_from_sid(unid_t *id, int *id_type, const DOM_SID *sid)
return NT_STATUS_INVALID_PARAMETER;
}
+ /* setup request */
+
ZERO_STRUCT(request);
ZERO_STRUCT(response);
@@ -96,6 +97,9 @@ static NTSTATUS db_get_id_from_sid(unid_t *id, int *id_type, const DOM_SID *sid)
return NT_STATUS_INVALID_PARAMETER;
}
+ sid_to_string(sid_str, sid);
+ fstrcpy(request.data.sid, sid_str);
+
/* Make The Request */
result = winbindd_request(operation, &request, &response);
@@ -118,7 +122,7 @@ static NTSTATUS db_set_mapping(DOM_SID *sid, unid_t id, int id_type) {
/*****************************************************************************
Initialise idmap database.
*****************************************************************************/
-static NTSTATUS db_init(const char *db_name) {
+static NTSTATUS db_init(void) {
return NT_STATUS_OK;
}