static int vfswrap_ntimes(vfs_handle_struct *handle, const char *path, const struct timespec ts[2]) { int result; START_PROFILE(syscall_ntimes); #if defined(HAVE_UTIMES) { struct timeval tv[2]; tv[0] = convert_timespec_to_timeval(ts[0]); tv[1] = convert_timespec_to_timeval(ts[1]); result = utimes(path, tv); } #elif defined(HAVE_UTIME) { struct utimbuf times; times.actime = convert_timespec_to_time_t(ts[0]); times.modtime = convert_timespec_to_time_t(ts[1]); result = utime(path, times); } #else errno = ENOSYS; result = -1; #endif END_PROFILE(syscall_ntimes); return result; }
static int copy_reg(const char *source, const char *dest) { SMB_STRUCT_STAT source_stats; int saved_errno; int ifd = -1; int ofd = -1; if (sys_lstat(source, &source_stats, false) == -1) return -1; if (!S_ISREG (source_stats.st_ex_mode)) return -1; if (source_stats.st_ex_size > module_sizelimit) { DEBUG(5, ("%s: size of %s larger than sizelimit (%lld > %lld), rename prohititted\n", MODULE, source, (long long)source_stats.st_ex_size, (long long)module_sizelimit)); return -1; } if((ifd = open (source, O_RDONLY, 0)) < 0) return -1; if (unlink (dest) && errno != ENOENT) { close(ifd); return -1; } #ifdef O_NOFOLLOW if((ofd = open (dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600)) < 0 ) #else if((ofd = open (dest, O_WRONLY | O_CREAT | O_TRUNC , 0600)) < 0 ) #endif goto err; if (transfer_file(ifd, ofd, source_stats.st_ex_size) == -1) goto err; /* * Try to preserve ownership. For non-root it might fail, but that's ok. * But root probably wants to know, e.g. if NFS disallows it. */ #ifdef HAVE_FCHOWN if ((fchown(ofd, source_stats.st_ex_uid, source_stats.st_ex_gid) == -1) && (errno != EPERM)) #else if ((chown(dest, source_stats.st_ex_uid, source_stats.st_ex_gid) == -1) && (errno != EPERM)) #endif goto err; /* * fchown turns off set[ug]id bits for non-root, * so do the chmod last. */ #if defined(HAVE_FCHMOD) if ((fchmod (ofd, source_stats.st_ex_mode & 07777) == -1) && (errno != EPERM)) #else if ((chmod (dest, source_stats.st_ex_mode & 07777) == -1) && (errno != EPERM)) #endif goto err; if (close (ifd) == -1) goto err; if (close (ofd) == -1) return -1; /* Try to copy the old file's modtime and access time. */ #if defined(HAVE_UTIMENSAT) { struct timespec ts[2]; ts[0] = source_stats.st_ex_atime; ts[1] = source_stats.st_ex_mtime; utimensat(AT_FDCWD, dest, ts, AT_SYMLINK_NOFOLLOW); } #elif defined(HAVE_UTIMES) { struct timeval tv[2]; tv[0] = convert_timespec_to_timeval(source_stats.st_ex_atime); tv[1] = convert_timespec_to_timeval(source_stats.st_ex_mtime); #ifdef HAVE_LUTIMES lutimes(dest, tv); #else utimes(dest, tv); #endif } #elif defined(HAVE_UTIME) { struct utimbuf tv; tv.actime = convert_timespec_to_time_t(source_stats.st_ex_atime); tv.modtime = convert_timespec_to_time_t(source_stats.st_ex_mtime); utime(dest, &tv); } #endif if (unlink (source) == -1) return -1; return 0; err: saved_errno = errno; if (ifd != -1) close(ifd); if (ofd != -1) close(ofd); errno = saved_errno; return -1; }
/** * Check whether a cookie-stored struct info is the same * as a given SMB_STRUCT_STAT, as coming with the fsp. */ static bool vfs_default_durable_reconnect_check_stat( struct vfs_default_durable_stat *cookie_st, SMB_STRUCT_STAT *fsp_st, const char *name) { int ret; if (cookie_st->st_ex_dev != fsp_st->st_ex_dev) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_dev", (unsigned long long)cookie_st->st_ex_dev, (unsigned long long)fsp_st->st_ex_dev)); return false; } if (cookie_st->st_ex_ino != fsp_st->st_ex_ino) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_ino", (unsigned long long)cookie_st->st_ex_ino, (unsigned long long)fsp_st->st_ex_ino)); return false; } if (cookie_st->st_ex_mode != fsp_st->st_ex_mode) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_mode", (unsigned long long)cookie_st->st_ex_mode, (unsigned long long)fsp_st->st_ex_mode)); return false; } if (cookie_st->st_ex_nlink != fsp_st->st_ex_nlink) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_nlink", (unsigned long long)cookie_st->st_ex_nlink, (unsigned long long)fsp_st->st_ex_nlink)); return false; } if (cookie_st->st_ex_uid != fsp_st->st_ex_uid) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_uid", (unsigned long long)cookie_st->st_ex_uid, (unsigned long long)fsp_st->st_ex_uid)); return false; } if (cookie_st->st_ex_gid != fsp_st->st_ex_gid) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_gid", (unsigned long long)cookie_st->st_ex_gid, (unsigned long long)fsp_st->st_ex_gid)); return false; } if (cookie_st->st_ex_rdev != fsp_st->st_ex_rdev) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_rdev", (unsigned long long)cookie_st->st_ex_rdev, (unsigned long long)fsp_st->st_ex_rdev)); return false; } if (cookie_st->st_ex_size != fsp_st->st_ex_size) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_size", (unsigned long long)cookie_st->st_ex_size, (unsigned long long)fsp_st->st_ex_size)); return false; } ret = timespec_compare(&cookie_st->st_ex_atime, &fsp_st->st_ex_atime); if (ret != 0) { struct timeval tc, ts; tc = convert_timespec_to_timeval(cookie_st->st_ex_atime); ts = convert_timespec_to_timeval(fsp_st->st_ex_atime); DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:'%s' != stat:'%s', " "denying durable reconnect\n", name, "st_ex_atime", timeval_string(talloc_tos(), &tc, true), timeval_string(talloc_tos(), &ts, true))); return false; } ret = timespec_compare(&cookie_st->st_ex_mtime, &fsp_st->st_ex_mtime); if (ret != 0) { struct timeval tc, ts; tc = convert_timespec_to_timeval(cookie_st->st_ex_mtime); ts = convert_timespec_to_timeval(fsp_st->st_ex_mtime); DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:'%s' != stat:'%s', " "denying durable reconnect\n", name, "st_ex_mtime", timeval_string(talloc_tos(), &tc, true), timeval_string(talloc_tos(), &ts, true))); return false; } ret = timespec_compare(&cookie_st->st_ex_ctime, &fsp_st->st_ex_ctime); if (ret != 0) { struct timeval tc, ts; tc = convert_timespec_to_timeval(cookie_st->st_ex_ctime); ts = convert_timespec_to_timeval(fsp_st->st_ex_ctime); DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:'%s' != stat:'%s', " "denying durable reconnect\n", name, "st_ex_ctime", timeval_string(talloc_tos(), &tc, true), timeval_string(talloc_tos(), &ts, true))); return false; } ret = timespec_compare(&cookie_st->st_ex_btime, &fsp_st->st_ex_btime); if (ret != 0) { struct timeval tc, ts; tc = convert_timespec_to_timeval(cookie_st->st_ex_btime); ts = convert_timespec_to_timeval(fsp_st->st_ex_btime); DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:'%s' != stat:'%s', " "denying durable reconnect\n", name, "st_ex_btime", timeval_string(talloc_tos(), &tc, true), timeval_string(talloc_tos(), &ts, true))); return false; } if (cookie_st->st_ex_calculated_birthtime != fsp_st->st_ex_calculated_birthtime) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_calculated_birthtime", (unsigned long long)cookie_st->st_ex_calculated_birthtime, (unsigned long long)fsp_st->st_ex_calculated_birthtime)); return false; } if (cookie_st->st_ex_blksize != fsp_st->st_ex_blksize) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_blksize", (unsigned long long)cookie_st->st_ex_blksize, (unsigned long long)fsp_st->st_ex_blksize)); return false; } if (cookie_st->st_ex_blocks != fsp_st->st_ex_blocks) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_blocks", (unsigned long long)cookie_st->st_ex_blocks, (unsigned long long)fsp_st->st_ex_blocks)); return false; } if (cookie_st->st_ex_flags != fsp_st->st_ex_flags) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_flags", (unsigned long long)cookie_st->st_ex_flags, (unsigned long long)fsp_st->st_ex_flags)); return false; } if (cookie_st->st_ex_mask != fsp_st->st_ex_mask) { DEBUG(1, ("vfs_default_durable_reconnect (%s): " "stat_ex.%s differs: " "cookie:%llu != stat:%llu, " "denying durable reconnect\n", name, "st_ex_mask", (unsigned long long)cookie_st->st_ex_mask, (unsigned long long)fsp_st->st_ex_mask)); return false; } return true; }