2008-05-12 20:24:28 +02:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
gbc_chown.c
|
|
|
|
|
2018-02-12 02:53:46 +01:00
|
|
|
(c) 2000-2017 Benoît Minisini <g4mba5@gmail.com>
|
2008-05-12 20:24:28 +02:00
|
|
|
|
|
|
|
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
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2008-05-12 20:24:28 +02:00
|
|
|
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
|
2011-06-03 02:51:09 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
2011-12-31 03:39:20 +01:00
|
|
|
MA 02110-1301, USA.
|
2008-05-12 20:24:28 +02:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-08-14 21:42:27 +02:00
|
|
|
#define __GBC_CHOWN_C
|
|
|
|
|
2008-05-12 20:24:28 +02:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gbc_chown.h"
|
|
|
|
|
|
|
|
void FILE_set_owner(const char *path, const char *template)
|
|
|
|
{
|
|
|
|
struct stat info;
|
|
|
|
|
|
|
|
if (geteuid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (stat(template, &info))
|
|
|
|
goto __ERROR;
|
|
|
|
|
|
|
|
if (chown(path, info.st_uid, info.st_gid))
|
|
|
|
goto __ERROR;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
__ERROR:
|
|
|
|
unlink(path);
|
|
|
|
THROW("Cannot set file owner: &1: &2", path, strerror(errno));
|
|
|
|
}
|