- if (!am_root && !is_in_group(id2))
- id2 = GID_NONE;
-@@ -195,9 +246,6 @@ uid_t match_uid(uid_t uid)
- static uid_t last_in, last_out;
+- return node;
+-}
+-
+-/* Add a gid to the list of gids. Only called on receiving side. */
+-static struct idlist *recv_add_gid(gid_t id, char *name)
+-{
+- gid_t id2 = name ? map_gid(id, name) : id;
+- struct idlist *node;
+-
+- node = add_to_list(&gidlist, id, name, id2,
+- !am_root && !is_in_group(id2) ? FLAG_SKIP_GROUP : 0);
++ node = add_to_list(idmap_ptr, id, *name ? name : NULL, id2,
++ !am_root && idmap_ptr == &gidmap
++ && !is_in_group(id2) ? FLAG_SKIP_GROUP : 0);
+
+ if (verbose > 3) {
+- rprintf(FINFO, "gid %u(%s) maps to %u\n",
+- (unsigned)id, name ? name : "", (unsigned)id2);
++ rprintf(FINFO, "%sid %u(%s) maps to %u\n",
++ idmap_ptr == &uidmap ? "u" : "g",
++ (unsigned)id, name, (unsigned)id2);
+ }
+
+ return node;
+@@ -195,12 +200,9 @@ static struct idlist *recv_add_gid(gid_t id, char *name)
+ /* this function is a definate candidate for a faster algorithm */
+ uid_t match_uid(uid_t uid)
+ {
+- static uid_t last_in, last_out;
++ static uid_t last_in = -1, last_out = -1;