From 2922690b716540b7e3971ffbdf506148503c7788 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 27 Oct 2018 12:35:07 +0300 Subject: change own&grp when it should. version 0.8.1! --- src/ckutil.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/ckutil.c') diff --git a/src/ckutil.c b/src/ckutil.c index 84eb43d..f292e8e 100644 --- a/src/ckutil.c +++ b/src/ckutil.c @@ -17,6 +17,9 @@ #include #include "ckutil.h" +#include "ckerrlog.h" + +ERRLOG(utility); int util_is_dir(const char *path) { if (!path) { @@ -153,3 +156,27 @@ int str_is_empty(const char *s) { } return 1; } + +int util_own_grp_copy(const char *dest, const char *original) { + if (!dest || !original) { + return -1; + } + struct stat destbuf, origbuf; + if (lstat(dest, &destbuf)) { + sERR("error stating %s", dest) + return -1; + } + if (stat(original, &origbuf)) { + sERR("error stating %s", original) + return -1; + } + if (destbuf.st_uid != origbuf.st_uid + || destbuf.st_gid != origbuf.st_gid) { + hLOG("Copying uid & gid: %s -> %s", original, dest); + if (lchown(dest, origbuf.st_uid, origbuf.st_gid)) { + sERR("Cannot change owner and group of %s", dest); + return -1; + } + } + return 0; +} -- cgit v1.2.3