+/* Add a uid to the list of uids. Only called on receiving side. */
+static uid_t recv_add_uid(uid_t id, char *name)
+{
+ uid_t id2 = name ? map_uid(id, name) : id;
+ struct idlist *node;
+
+ node = add_to_list(&uidlist, (int)id, name, (int)id2);
+
+ if (verbose > 3) {
+ rprintf(FINFO, "uid %d(%s) maps to %d\n",
+ (int)id, name ? name : "", (int)id2);
+ }
+
+ return id2;
+}
+
+/* Add a gid to the list of gids. Only called on receiving side. */
+static gid_t recv_add_gid(gid_t id, char *name)
+{
+ gid_t id2 = name ? map_gid(id, name) : id;
+ struct idlist *node;
+
+ if (!am_root && !is_in_group(id2))
+ id2 = GID_NONE;
+ node = add_to_list(&gidlist, (int)id, name, (int)id2);
+
+ if (verbose > 3) {
+ rprintf(FINFO, "gid %d(%s) maps to %d\n",
+ (int)id, name ? name : "", (int)id2);
+ }
+
+ return id2;
+}
+
+/* this function is a definate candidate for a faster algorithm */
+static uid_t match_uid(uid_t uid)
+{
+ static uid_t last_in, last_out;
+ struct idlist *list;
+
+ if (uid == 0)
+ return 0;
+
+ if (uid == last_in)
+ return last_out;
+
+ last_in = uid;
+
+ for (list = uidlist; list; list = list->next) {
+ if (list->id == (int)uid)
+ return last_out = (uid_t)list->id2;
+ }
+
+ return last_out = uid;
+}
+