aboutsummaryrefslogtreecommitdiffstats
path: root/src/ckutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ckutil.c')
-rw-r--r--src/ckutil.c27
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;
+}