diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-10-27 12:35:07 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-10-27 12:39:01 +0300 |
commit | 2922690b716540b7e3971ffbdf506148503c7788 (patch) | |
tree | ccb6a4dbbffadf5f91ee47ca5ef5bd8347c02a1c /src/ckutil.c | |
parent | 1b09a70af6096d2f85cadff82f227e4e6850bfda (diff) | |
download | ck-2922690b716540b7e3971ffbdf506148503c7788.tar.gz ck-2922690b716540b7e3971ffbdf506148503c7788.tar.bz2 ck-2922690b716540b7e3971ffbdf506148503c7788.zip |
change own&grp when it should. version 0.8.1!
Diffstat (limited to 'src/ckutil.c')
-rw-r--r-- | src/ckutil.c | 27 |
1 files changed, 27 insertions, 0 deletions
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 <unistd.h> #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; +} |