Winbind idmap recovery (wbidmap)
Michael Steffens
michael_steffens at hp.com
Tue Apr 30 05:58:01 GMT 2002
Hello Tim, hello everyone,
in February I have posted a winbind idmap recovery tool ("wbidmap")
for dumping and restoring the id mapping tdb, plus a patch for
winbindd_idmap.c to enable logging of newly created mappings in
a way that can be replayed by wbidmap.
Has this approach been considered in the meanwhile?
No, I won't ask for getting it into 2.2.4 at this point :)
But in any case, for everyone who found it useful, I have updated
it for 2.2.4 (int32 instead of int value byte order, the
IDMAP_VERSION key, and the modified SID format).
Attached is the source file wbidmap.c, a patch for Makefile.in
such that it can be built using "make bin/wbidmap", and the logging
patch against current winbindd_idmap.c.
Cheers!
Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wbidmap.c
Type: text/x-csrc
Size: 21719 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20020430/18f40b2e/wbidmap.bin
-------------- next part --------------
Index: source/Makefile.in
===================================================================
RCS file: /cvsroot/samba/source/Makefile.in,v
retrieving revision 1.227.2.133
diff -u -r1.227.2.133 Makefile.in
--- source/Makefile.in 30 Apr 2002 07:59:05 -0000 1.227.2.133
+++ source/Makefile.in 30 Apr 2002 12:28:48 -0000
@@ -405,6 +405,8 @@
WBINFO_OBJ = nsswitch/wbinfo.o libsmb/smbencrypt.o libsmb/smbdes.o \
passdb/secrets.o
+WBIDMAP_OBJ = nsswitch/wbidmap.o
+
WINBIND_NSS_OBJ = nsswitch/winbind_nss.o nsswitch/wb_common.o @WINBIND_NSS_EXTRA_OBJS@
WINBIND_NSS_PICOBJS = $(WINBIND_NSS_OBJ:.o=.po)
@@ -690,6 +692,12 @@
$(UBIQX_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
@$(LINK) -o $@ $(WBINFO_OBJ) $(PARAM_OBJ) $(LIB_OBJ) $(NOPROTO_OBJ) \
+ $(UBIQX_OBJ) $(LIBS) @BUILD_POPT@
+
+bin/wbidmap: $(WBIDMAP_OBJ) $(PARAM_OBJ) $(LIB_OBJ) $(NOPROTO_OBJ) \
+ $(UBIQX_OBJ) @BUILD_POPT@ bin/.dummy
+ @echo Linking $@
+ @$(LINK) -o $@ $(WBIDMAP_OBJ) $(PARAM_OBJ) $(LIB_OBJ) $(NOPROTO_OBJ) \
$(UBIQX_OBJ) $(LIBS) @BUILD_POPT@
bin/tdbbackup: $(TDBBACKUP_OBJ) bin/.dummy
-------------- next part --------------
Index: source/nsswitch/winbindd_idmap.c
===================================================================
RCS file: /cvsroot/samba/source/nsswitch/winbindd_idmap.c,v
retrieving revision 1.3.4.13
diff -u -r1.3.4.13 winbindd_idmap.c
--- source/nsswitch/winbindd_idmap.c 27 Apr 2002 03:04:08 -0000 1.3.4.13
+++ source/nsswitch/winbindd_idmap.c 30 Apr 2002 12:26:34 -0000
@@ -68,6 +68,30 @@
return True;
}
+/* Log id mapping. Reopen log file for every entry, because information
+ would be lost when someone unlinks the file while winbindd has it open */
+
+static BOOL log_idmap(TDB_DATA id, TDB_DATA sid)
+{
+ FILE *logfile;
+
+ if ((logfile = fopen(lock_path("winbindd_idmap.log"), "a")) == NULL) {
+ DEBUG(1, ("cannot open %s : %s\n",
+ lock_path("winbindd_idmap.log"), strerror(errno)));
+ return False;
+ }
+
+ if (fprintf(logfile, "%s:%s\n", id.dptr, sid.dptr) < 0) {
+ DEBUG(1, ("cannot write %s:%s to %s : %s\n", id.dptr, sid.dptr,
+ lock_path("winbindd_idmap.log"), strerror(errno)));
+ fclose(logfile);
+ return False;
+ }
+
+ fclose(logfile);
+ return True;
+}
+
/* Get an id from a rid */
static BOOL get_id_from_sid(DOM_SID *sid, uid_t *id, BOOL isgroup)
{
@@ -115,10 +139,14 @@
data.dptr = keystr2;
data.dsize = strlen(keystr2) + 1;
- tdb_store(idmap_tdb, key, data, TDB_REPLACE);
- tdb_store(idmap_tdb, data, key, TDB_REPLACE);
+ /* have mapping depend on successful log in order to avoid
+ data loss for recovery */
- result = True;
+ if (log_idmap(data, key)) {
+ tdb_store(idmap_tdb, key, data, TDB_REPLACE);
+ tdb_store(idmap_tdb, data, key, TDB_REPLACE);
+ result = True;
+ }
}
}
More information about the samba-technical
mailing list