ClientFile.cxx 1.64 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20
#include "config.h"
Max Kellermann's avatar
Max Kellermann committed
21
#include "Client.hxx"
22
#include "protocol/Ack.hxx"
23
#include "fs/Path.hxx"
24
#include "fs/FileInfo.hxx"
25
#include "util/Error.hxx"
26 27 28 29

#include <unistd.h>

bool
30
Client::AllowFile(Path path_fs, Error &error) const
31 32 33 34
{
#ifdef WIN32
	(void)path_fs;

35
	error.Set(ack_domain, ACK_ERROR_PERMISSION, "Access denied");
36 37
	return false;
#else
38 39 40 41 42
	if (uid >= 0 && (uid_t)uid == geteuid())
		/* always allow access if user runs his own MPD
		   instance */
		return true;

43
	if (uid < 0) {
44
		/* unauthenticated client */
45
		error.Set(ack_domain, ACK_ERROR_PERMISSION, "Access denied");
46 47 48
		return false;
	}

49 50
	FileInfo fi;
	if (!GetFileInfo(path_fs, fi, error))
51 52
		return false;

53
	if (fi.GetUid() != (uid_t)uid && (fi.GetMode() & 0444) != 0444) {
54
		/* client is not owner */
55
		error.Set(ack_domain, ACK_ERROR_PERMISSION, "Access denied");
56 57 58 59 60 61
		return false;
	}

	return true;
#endif
}