| 487 | } |
| 488 | |
| 489 | int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, |
| 490 | const char *fnamecmp, int flags) |
| 491 | { |
| 492 | int updated = 0; |
| 493 | stat_x sx2; |
| 494 | int change_uid, change_gid; |
| 495 | mode_t new_mode = file->mode; |
| 496 | int inherit; |
| 497 | |
| 498 | if (!sxp) { |
| 499 | if (dry_run) |
| 500 | return 1; |
| 501 | if (link_stat(fname, &sx2.st, 0) < 0) { |
| 502 | rsyserr(FERROR_XFER, errno, "stat %s failed", |
| 503 | full_fname(fname)); |
| 504 | return 0; |
| 505 | } |
| 506 | init_stat_x(&sx2); |
| 507 | sxp = &sx2; |
| 508 | inherit = !preserve_perms; |
| 509 | } else |
| 510 | inherit = !preserve_perms && file->flags & FLAG_DIR_CREATED; |
| 511 | |
| 512 | if (inherit && S_ISDIR(new_mode) && sxp->st.st_mode & S_ISGID) { |
| 513 | /* We just created this directory and its setgid |
| 514 | * bit is on, so make sure it stays on. */ |
| 515 | new_mode |= S_ISGID; |
| 516 | } |
| 517 | |
| 518 | if (daemon_chmod_modes && !S_ISLNK(new_mode)) |
| 519 | new_mode = tweak_mode(new_mode, daemon_chmod_modes); |
| 520 | |
| 521 | #ifdef SUPPORT_ACLS |
| 522 | if (preserve_acls && !S_ISLNK(file->mode) && !ACL_READY(*sxp)) |
| 523 | get_acl(fname, sxp); |
| 524 | #endif |
| 525 | |
| 526 | change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file); |
| 527 | change_gid = gid_ndx && !(file->flags & FLAG_SKIP_GROUP) |
| 528 | && sxp->st.st_gid != (gid_t)F_GROUP(file); |
| 529 | #ifndef CAN_CHOWN_SYMLINK |
| 530 | if (S_ISLNK(sxp->st.st_mode)) { |
| 531 | ; |
| 532 | } else |
| 533 | #endif |
| 534 | if (change_uid || change_gid) { |
| 535 | if (DEBUG_GTE(OWN, 1)) { |
| 536 | if (change_uid) { |
| 537 | rprintf(FINFO, |
| 538 | "set uid of %s from %u to %u\n", |
| 539 | fname, (unsigned)sxp->st.st_uid, F_OWNER(file)); |
| 540 | } |
| 541 | if (change_gid) { |
| 542 | rprintf(FINFO, |
| 543 | "set gid of %s from %u to %u\n", |
| 544 | fname, (unsigned)sxp->st.st_gid, F_GROUP(file)); |
| 545 | } |
| 546 | } |
no test coverage detected