summaryrefslogtreecommitdiffstats
path: root/api/src
diff options
context:
space:
mode:
authorPoornima Gurusiddaiah <pgurusid@redhat.com>2014-06-19 16:19:23 +0530
committerAnand Avati <avati@redhat.com>2014-06-23 08:44:00 -0700
commitb14a525554f1fce280874f0385fef6771ca93c89 (patch)
tree16467a2a1c216c150f5fa0525fbd1e38c3dc5da3 /api/src
parent83fa1cfe185f05319a0048a63c8c163e4e632cf7 (diff)
libgfapi: In glfs_*chown, if uid or gid is -1, do not set the corresponding flag.
Change-Id: I23d0caa36c37dd5372f6e1d6a27c7904f4df547b BUG: 1111563 Signed-off-by: Poornima Gurusiddaiah <pgurusid@redhat.com> Reviewed-on: http://review.gluster.org/8115 Reviewed-by: Raghavendra Talur <rtalur@redhat.com> Reviewed-by: Prashanth Pai <ppai@redhat.com> Reviewed-by: Niels de Vos <ndevos@redhat.com> Tested-by: Justin Clift <justin@gluster.org> Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'api/src')
-rw-r--r--api/src/glfs-fops.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c
index 4bf33b859b6..d5f65272c8b 100644
--- a/api/src/glfs-fops.c
+++ b/api/src/glfs-fops.c
@@ -2295,15 +2295,22 @@ glfs_fchmod (struct glfs_fd *glfd, mode_t mode)
int
glfs_chown (struct glfs *fs, const char *path, uid_t uid, gid_t gid)
{
- int ret = -1;
+ int ret = 0;
int valid = 0;
struct iatt iatt = {0, };
- iatt.ia_uid = uid;
- iatt.ia_gid = gid;
- valid = GF_SET_ATTR_UID|GF_SET_ATTR_GID;
+ if (uid != (uid_t) -1) {
+ iatt.ia_uid = uid;
+ valid = GF_SET_ATTR_UID;
+ }
- ret = glfs_setattr (fs, path, &iatt, valid, 1);
+ if (gid != (uid_t) -1) {
+ iatt.ia_gid = gid;
+ valid = valid | GF_SET_ATTR_GID;
+ }
+
+ if (valid)
+ ret = glfs_setattr (fs, path, &iatt, valid, 1);
return ret;
}
@@ -2312,15 +2319,22 @@ glfs_chown (struct glfs *fs, const char *path, uid_t uid, gid_t gid)
int
glfs_lchown (struct glfs *fs, const char *path, uid_t uid, gid_t gid)
{
- int ret = -1;
+ int ret = 0;
int valid = 0;
struct iatt iatt = {0, };
- iatt.ia_uid = uid;
- iatt.ia_gid = gid;
- valid = GF_SET_ATTR_UID|GF_SET_ATTR_GID;
+ if (uid != (uid_t) -1) {
+ iatt.ia_uid = uid;
+ valid = GF_SET_ATTR_UID;
+ }
+
+ if (gid != (uid_t) -1) {
+ iatt.ia_gid = gid;
+ valid = valid | GF_SET_ATTR_GID;
+ }
- ret = glfs_setattr (fs, path, &iatt, valid, 0);
+ if (valid)
+ ret = glfs_setattr (fs, path, &iatt, valid, 0);
return ret;
}
@@ -2329,15 +2343,22 @@ glfs_lchown (struct glfs *fs, const char *path, uid_t uid, gid_t gid)
int
glfs_fchown (struct glfs_fd *glfd, uid_t uid, gid_t gid)
{
- int ret = -1;
+ int ret = 0;
int valid = 0;
struct iatt iatt = {0, };
- iatt.ia_uid = uid;
- iatt.ia_gid = gid;
- valid = GF_SET_ATTR_UID|GF_SET_ATTR_GID;
+ if (uid != (uid_t) -1) {
+ iatt.ia_uid = uid;
+ valid = GF_SET_ATTR_UID;
+ }
- ret = glfs_fsetattr (glfd, &iatt, valid);
+ if (gid != (uid_t) -1) {
+ iatt.ia_gid = gid;
+ valid = valid | GF_SET_ATTR_GID;
+ }
+
+ if (valid)
+ ret = glfs_fsetattr (glfd, &iatt, valid);
return ret;
}