A couple of minor things I noticed while trying the patch

2016-08-19 16:48 GMT-07:00 Aaron Conole <acon...@redhat.com>:

> It will be useful in the future to be able to set ownership and permissions
> on files which Open vSwitch creates. Allowing the specification of such
> ownership and permissions using the standard user:group, uog+-rwxs, and
> numerical forms commonly associated with those actions.
>
> This patch introduces a new chutil library, currently with a posix command
> implementation. WIN32 support does not exist at this time, but could be
> added
> in the future.
>
> As part of this, the daemon-unix.c was refactored to move the ownership
> parsing code to the chutil library. A new set of tests was added, and the
> fchmod and fchown calls are implemented.
>
> Signed-off-by: Aaron Conole <acon...@redhat.com>
> Acked-by: Ben Pfaff <b...@ovn.org>
> ---
>  lib/automake.mk     |   2 +
>  lib/chutil-unix.c   | 348 ++++++++++++++++++++++++++++++
> ++++++++++++++++++++++
>  lib/chutil.h        |  32 +++++
>  lib/daemon-unix.c   | 149 +---------------------
>  tests/automake.mk   |   2 +
>  tests/library.at    |   5 +
>  tests/test-chutil.c | 243 ++++++++++++++++++++++++++++++++++++
>  7 files changed, 637 insertions(+), 144 deletions(-)
>  create mode 100644 lib/chutil-unix.c
>  create mode 100644 lib/chutil.h
>  create mode 100644 tests/test-chutil.c
>
>
>
[...]


> +/* Changes the mode of a file to the mode specified.  Accepts chmod style
> + * comma-separated strings.  Returns 0 on success, otherwise a positive
> errno
> + * value. */
> +int
> +ovs_fchmod(int fd, const char *mode)
> +{
> +    mode_t new_mode;
> +    struct stat st;
> +    int err;
> +
> +    if (fstat(fd, &st)) {
> +        err = errno;
> +        VLOG_ERR("ovs_fchown: fstat (%s)", ovs_strerror(errno));
>

chmod


> +        return err;
> +    }
> +
> +    if (S_ISLNK(st.st_mode)) {
> +        errno = EINVAL;
> +        err = errno;
> +        VLOG_ERR("ovs_fchown: unable to change ownership of symlink");
>

chmod


> +        return err;
> +    }
> +
> +    errno = 0;
> +    new_mode = chmod_getmode(mode, st.st_mode);
> +    if (errno) {
> +        err = errno;
> +        VLOG_ERR("ovs_fchmod bad mode (%s) specified (%s)", mode,
> +                 ovs_strerror(errno));
> +        return err;
> +    }
> +
> +    if (fchmod(fd, new_mode)) {
> +        VLOG_ERR("ovs_fchmod: chmod error (%s) with mode %s",
> +                 ovs_strerror(errno), mode);
> +        return errno;
> +    }
> +    return 0;
> +}
> +
> +
> +/* Changes the ownership of a file to the mode specified.  Accepts chown
> style
> + * user:group strings.  Returns 0 on success.  Non-zero results contain
> + * errno. */
> +int
> +ovs_fchown(int fd, const char *owner)
> +{
> +    struct stat st;
> +    uid_t user;
> +    gid_t group;
> +    int err;
> +
> +    if (fstat(fd, &st)) {
> +        err = errno;
> +        VLOG_ERR("ovs_fchmod: lstat (%s)", ovs_strerror(errno));
>

chown


> +        return err;
> +    }
> +
> +    if (S_ISLNK(st.st_mode) || S_ISDIR(st.st_mode)) {
> +        errno = EINVAL;
> +        err = errno;
> +        VLOG_ERR("ovs_fchmod: changing symlink / directory modes is not "
> +                 "supported.");
>

chown


> +        return err;
> +    }
> +
> +    if (ovs_strtousr(owner, &user, NULL, &group, true)) {
> +        err = errno;
> +        VLOG_ERR("ovs_fchown: unknown user or group - bailing");
> +        return err;
> +    }
> +
> +    if (fchown(fd, user, group)) {
> +        err = errno;
> +        VLOG_ERR("ovs_fchown: chown error (%s)", ovs_strerror(errno));
> +        return err;
> +    }
> +
> +    return 0;
> +}
>

[...]
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to