예제 #1
0
int file_utime(connection_struct *conn, const char *fname, struct utimbuf *times)
{
	SMB_STRUCT_STAT sbuf;
	int ret = -1;

	errno = 0;
	ZERO_STRUCT(sbuf);

	/* Don't update the time on read-only shares */
	/* We need this as set_filetime (which can be called on
	   close and other paths) can end up calling this function
	   without the NEED_WRITE protection. Found by : 
	   Leo Weppelman <*****@*****.**>
	*/

	if (!CAN_WRITE(conn)) {
		return 0;
	}

	if(SMB_VFS_UTIME(conn,fname, times) == 0)
		return 0;

	if((errno != EPERM) && (errno != EACCES))
		return -1;

	if(!lp_dos_filetimes(SNUM(conn)))
		return -1;

	/* We have permission (given by the Samba admin) to
	   break POSIX semantics and allow a user to change
	   the time on a file they don't own but can write to
	   (as DOS does).
	 */

	/* Check if we have write access. */
	if (can_write_to_file(conn, fname, &sbuf)) {
		/* We are allowed to become root and change the filetime. */
		become_root();
		ret = SMB_VFS_UTIME(conn,fname, times);
		unbecome_root();
	}

	return ret;
}
예제 #2
0
static NTSTATUS cmd_utime(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
{
	struct utimbuf times;
	if (argc != 4) {
		printf("Usage: utime <path> <access> <modify>\n");
		return NT_STATUS_OK;
	}
	times.actime = atoi(argv[2]);
	times.modtime = atoi(argv[3]);
	if (SMB_VFS_UTIME(vfs->conn, argv[1], &times) != 0) {
		printf("utime: error=%d (%s)\n", errno, strerror(errno));
		return NT_STATUS_UNSUCCESSFUL;
	}

	printf("utime: ok\n");
	return NT_STATUS_OK;
}