summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfsclient')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c62
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.h37
2 files changed, 96 insertions, 3 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index c36d9b4dbf8..e3447498253 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -4314,14 +4314,19 @@ out:
return op_ret;
}
+#define LIBGF_DO_CHOWN 1
+#define LIBGF_DO_LCHOWN 2
+
int
-glusterfs_glh_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
- gid_t group)
+__glusterfs_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
+ gid_t group, int whichop)
{
int op_ret = -1;
libglusterfs_client_ctx_t *ctx = handle;
loc_t loc = {0, };
char *name = NULL;
+ loc_t *oploc = NULL;
+ loc_t targetloc = {0, };
GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, ctx, out);
GF_VALIDATE_ABSOLUTE_PATH_OR_GOTO (LIBGF_XL_NAME, path, out);
@@ -4342,15 +4347,36 @@ glusterfs_glh_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
goto out;
}
- op_ret = libgf_client_chown (ctx, &loc, owner, group);
+ oploc = &loc;
+ if (whichop == LIBGF_DO_LCHOWN)
+ goto do_lchown;
+
+ if (!S_ISLNK (loc.inode->st_mode))
+ goto do_lchown;
+
+ op_ret = libgf_realpath_loc_fill (ctx, (char *)loc.path, &targetloc);
+ if (op_ret == -1)
+ goto out;
+
+ oploc = &targetloc;
+do_lchown:
+ op_ret = libgf_client_chown (ctx, oploc, owner, group);
out:
if (name)
FREE (name);
libgf_client_loc_wipe (&loc);
+ libgf_client_loc_wipe (&targetloc);
return op_ret;
}
int
+glusterfs_glh_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
+ gid_t group)
+{
+ return __glusterfs_chown (handle, path, owner, group, LIBGF_DO_CHOWN);
+}
+
+int
glusterfs_chown (const char *path, uid_t owner, gid_t group)
{
struct vmp_entry *entry = NULL;
@@ -4373,6 +4399,36 @@ out:
return op_ret;
}
+int
+glusterfs_glh_lchown (glusterfs_handle_t handle, const char *path, uid_t owner,
+ gid_t group)
+{
+ return __glusterfs_chown (handle, path, owner, group, LIBGF_DO_LCHOWN);
+}
+
+int
+glusterfs_lchown (const char *path, uid_t owner, gid_t group)
+{
+ struct vmp_entry *entry = NULL;
+ int op_ret = -1;
+ char *vpath = NULL;
+
+ GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, path, out);
+
+ entry = libgf_vmp_search_entry ((char *)path);
+ if (!entry) {
+ errno = ENODEV;
+ goto out;
+ }
+
+ vpath = libgf_vmp_virtual_path (entry, path);
+ op_ret = glusterfs_glh_lchown (entry->handle, vpath, owner, group);
+out:
+ if (vpath)
+ free (vpath);
+ return op_ret;
+}
+
glusterfs_dir_t
glusterfs_glh_opendir (glusterfs_handle_t handle, const char *path)
{
diff --git a/libglusterfsclient/src/libglusterfsclient.h b/libglusterfsclient/src/libglusterfsclient.h
index 37fcf04ddf5..ae0d86a0e64 100755
--- a/libglusterfsclient/src/libglusterfsclient.h
+++ b/libglusterfsclient/src/libglusterfsclient.h
@@ -732,6 +732,8 @@ glusterfs_chmod (const char *path, mode_t mode);
/* Change the owner of a path.
+ * If @path is a symlink, it is dereferenced and the ownership change
+ * happens on the target.
*
* @handle : Handle of the glusterfs context in which the path
* resides.
@@ -749,6 +751,8 @@ glusterfs_glh_chown (glusterfs_handle_t handle, const char *path, uid_t owner,
/* Change the owner of a path.
*
+ * If @path is a symlink, it is dereferenced and the ownership change
+ * happens on the target.
* @path : The path whose owner needs to be changed. Path must
* be pre-fixed with the VMP that identifies the
* glusterfs context in which the path resides.
@@ -1143,6 +1147,39 @@ glusterfs_glh_remove (glusterfs_handle_t handle, const char *path);
*/
int
glusterfs_remove (const char *path);
+
+
+
+/* Change the owner of the given path.
+ *
+ * If @path is a symlink, the ownership change happens on the symlink.
+ *
+ * @handle : Handle identifying the glusterfs client context.
+ * @path : Path whose owner needs to be changed.
+ * @owner : New owner ID
+ * @group : New Group ID
+ *
+ * Returns 0 on success and -1 on error with errno set appropriately.
+ */
+int
+glusterfs_glh_lchown (glusterfs_handle_t handle, const char *path, uid_t owner,
+ gid_t group);
+
+
+
+/* Change the owner of the given path.
+ *
+ * If @path is a symlink, the ownership change happens on the symlink.
+ *
+ * @path : Path whose owner needs to be changed.
+ * @owner : New owner ID
+ * @group : New Group ID
+ *
+ * Returns 0 on success and -1 on error with errno set appropriately.
+ */
+
+int
+glusterfs_lchown (const char *path, uid_t owner, gid_t group);
/* FIXME: review the need for these apis */
/* added for log related initialization in booster fork implementation */
void