[PATCH] winbindd_idmap.c [Re: idmap recovery tool}
Michael Steffens
michael_steffens at hp.com
Tue Feb 12 04:28:02 GMT 2002
Hi again,
this patch provides the idmap logging required to recover
winbindd_idmap.tdb any time. Rather than to the state of
the last dump/backup, with all new mappings since then being
lost.
It's not entirely what I had in mind, yet. The informational
third field with the plain text NT name is missing, as this
is not directly available inside get_id_from_rid().
I didn't want to change too much at once, so let's put up
without for now...
The log file winbindd_idmap.log is presently at the same
location as winbindd_idmap.tdb. Not ideal, it should be a
configurable parameter of its own, such that an administrator
can choose to keep this log in a different filesystem for
better redundancy. But again, let's put up... :-)
Cheers!
Michael
-------------- next part --------------
Index: source/nsswitch/winbindd_idmap.c
===================================================================
RCS file: /cvsroot/samba/source/nsswitch/winbindd_idmap.c,v
retrieving revision 1.3.4.7
diff -u -w -r1.3.4.7 winbindd_idmap.c
--- source/nsswitch/winbindd_idmap.c 19 Jan 2002 20:16:40 -0000 1.3.4.7
+++ source/nsswitch/winbindd_idmap.c 12 Feb 2002 12:01:44 -0000
@@ -66,6 +66,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_rid(char *domain_name, uint32 rid, uid_t *id,
@@ -121,10 +145,14 @@
data.dptr = keystr2;
data.dsize = strlen(keystr2) + 1;
+ /* have mapping depend on successful log in order to avoid
+ data loss for recovery */
+
+ 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