int io_error;
int checksum_len;
dev_t filesystem_dev; /* used to implement -x */
+unsigned int file_struct_len;
static char empty_sum[MD4_SUM_LENGTH];
static int flist_count_offset;
-static unsigned int file_struct_len;
static void clean_flist(struct file_list *flist, int strip_root, int no_dups);
static void output_flist(struct file_list *flist);
flags |= XMIT_RDEV_MINOR_IS_SMALL;
}
}
- if (file->uid == uid)
+ if (file->ids->uid == uid)
flags |= XMIT_SAME_UID;
else
- uid = file->uid;
- if (file->gid == gid)
+ uid = file->ids->uid;
+ if (file->ids->gid == gid)
flags |= XMIT_SAME_GID;
else
- gid = file->gid;
+ gid = file->ids->gid;
if (file->modtime == modtime)
flags |= XMIT_SAME_TIME;
else
memset(bp, 0, file_struct_len);
bp += file_struct_len;
- file->flags = 0;
file->modtime = modtime;
file->length = file_length;
file->mode = mode;
- file->uid = uid;
- file->gid = gid;
+ file->ids = id_pair(uid, gid);
if (dirname_len) {
file->dirname = lastdir = bp;
file->modtime = st.st_mtime;
file->length = st.st_size;
file->mode = st.st_mode;
- file->uid = st.st_uid;
- file->gid = st.st_gid;
+ file->ids = id_pair(st.st_uid, st.st_gid);
#ifdef SUPPORT_HARD_LINKS
if (flist && flist->hlink_pool) {
file->modtime = st2.st_mtime;
file->length = st2.st_size;
file->mode = st2.st_mode;
- file->uid = st2.st_uid;
- file->gid = st2.st_gid;
+ file->ids = id_pair(st2.st_uid, st2.st_gid);
file->u.link = NULL;
} else
file->mode = save_mode;
* without causing a compatibility problem with older versions. */
clean_flist(flist, 0, 0);
- /* Now send the uid/gid list. This was introduced in
- * protocol version 15 */
send_uid_list(f);
/* send the io_error flag */
clean_flist(flist, relative_paths, 1);
if (f >= 0) {
- /* Now send the uid/gid list. This was introduced in
- * protocol version 15 */
- recv_uid_list(f, flist);
+ recv_uid_list(f);
/* Recv the io_error flag */
if (lp_ignore_errors(module_id) || ignore_errors)
for (i = 0; i < flist->count; i++) {
file = flist->files[i];
if ((am_root || am_sender) && preserve_uid)
- sprintf(uidbuf, " uid=%ld", (long)file->uid);
+ sprintf(uidbuf, " uid=%ld", (long)file->ids->uid);
else
*uidbuf = '\0';
- if (preserve_gid && file->gid != GID_NONE)
- sprintf(gidbuf, " gid=%ld", (long)file->gid);
+ if (preserve_gid && file->ids->gid != GID_NONE)
+ sprintf(gidbuf, " gid=%ld", (long)file->ids->gid);
else
*gidbuf = '\0';
if (!am_sender)
&& (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
return 0;
- if (am_root && preserve_uid && st->st_uid != file->uid)
+ if (am_root && preserve_uid && st->st_uid != file->ids->uid)
return 0;
- if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
+ if (preserve_gid && file->ids->gid != GID_NONE && st->st_gid != file->ids->gid)
return 0;
return 1;
if (preserve_perms
&& (file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
iflags |= ITEM_REPORT_PERMS;
- if (preserve_uid && am_root && file->uid != st->st_uid)
+ if (preserve_uid && am_root && file->ids->uid != st->st_uid)
iflags |= ITEM_REPORT_OWNER;
- if (preserve_gid && file->gid != GID_NONE
- && st->st_gid != file->gid)
+ if (preserve_gid && file->ids->gid != GID_NONE
+ && st->st_gid != file->ids->gid)
iflags |= ITEM_REPORT_GROUP;
} else
iflags |= ITEM_IS_NEW;
updated = 1;
}
- change_uid = am_root && preserve_uid && st->st_uid != file->uid;
- change_gid = preserve_gid && file->gid != GID_NONE
- && st->st_gid != file->gid;
+ change_uid = am_root && preserve_uid && st->st_uid != file->ids->uid;
+ change_gid = preserve_gid && file->ids->gid != GID_NONE
+ && st->st_gid != file->ids->gid;
#if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
if (S_ISLNK(st->st_mode))
;
rprintf(FINFO,
"set uid of %s from %ld to %ld\n",
fname,
- (long)st->st_uid, (long)file->uid);
+ (long)st->st_uid, (long)file->ids->uid);
}
if (change_gid) {
rprintf(FINFO,
"set gid of %s from %ld to %ld\n",
fname,
- (long)st->st_gid, (long)file->gid);
+ (long)st->st_gid, (long)file->ids->gid);
}
}
if (do_lchown(fname,
- change_uid ? file->uid : st->st_uid,
- change_gid ? file->gid : st->st_gid) != 0) {
+ change_uid ? file->ids->uid : st->st_uid,
+ change_gid ? file->ids->gid : st->st_gid) != 0) {
/* shouldn't have attempted to change uid or gid
* unless have the privilege */
rsyserr(FERROR, errno, "%s %s failed",
int hlindex;
};
+struct id_pair {
+ uid_t uid;
+ gid_t gid;
+};
+
#define F_DEV link_u.idev->dev
#define F_INODE link_u.idev->inode
struct idev *idev;
struct hlink *links;
} link_u;
+ struct id_pair *ids;
time_t modtime;
- uid_t uid;
- gid_t gid;
mode_t mode;
uchar flags; /* this item MUST remain last */
};
static struct idlist *uidlist;
static struct idlist *gidlist;
+static struct id_pair *pair_list;
+static int pair_cnt = 0, pair_alloc = 0;
+
static struct idlist *add_to_list(struct idlist **root, int id, char *name,
int id2)
{
/* recv a complete uid/gid mapping from the peer and map the uid/gid
* in the file list to local names */
-void recv_uid_list(int f, struct file_list *flist)
+void recv_uid_list(int f)
{
int id, i;
char *name;
}
}
- /* now convert the uid/gid of all files in the list to the mapped
- * uid/gid */
+ /* Now convert the id_pair array over to mapped uid/gid values. */
if (am_root && preserve_uid && !numeric_ids) {
- for (i = 0; i < flist->count; i++)
- flist->files[i]->uid = match_uid(flist->files[i]->uid);
+ for (i = 0; i < pair_cnt; i++)
+ pair_list[i].uid = match_uid(pair_list[i].uid);
}
if (preserve_gid && (!am_root || !numeric_ids)) {
- for (i = 0; i < flist->count; i++)
- flist->files[i]->gid = match_gid(flist->files[i]->gid);
+ for (i = 0; i < pair_cnt; i++)
+ pair_list[i].gid = match_gid(pair_list[i].gid);
+ }
+}
+
+struct id_pair *id_pair(uid_t uid, gid_t gid)
+{
+ int i;
+
+ for (i = 0; i < pair_cnt; i++) {
+ if (uid == pair_list[i].uid && gid == pair_list[i].gid)
+ return pair_list + i;
+ }
+
+ if (pair_cnt == pair_alloc) {
+ pair_alloc += 128;
+ pair_list = realloc_array(pair_list, struct id_pair,
+ pair_alloc);
}
+ pair_list[pair_cnt].uid = uid;
+ pair_list[pair_cnt].gid = gid;
+ return pair_list + pair_cnt++;
}