[libvirt] [PATCH v4 2/5] util: Create virFileAccessibleAs function
Eric Blake
eblake at redhat.com
Thu Oct 20 16:48:18 UTC 2011
On 10/20/2011 08:52 AM, Michal Privoznik wrote:
> This function checks if a given path is accessible under
> given uid and gid.
> ---
> src/util/util.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> src/util/util.h | 3 ++
> 2 files changed, 81 insertions(+), 0 deletions(-)
>
> diff --git a/src/util/util.c b/src/util/util.c
> index 01146f5..2020415 100644
> --- a/src/util/util.c
> +++ b/src/util/util.c
> @@ -671,6 +671,72 @@ virFileIsExecutable(const char *file)
> }
>
> #ifndef WIN32
> +/* Check that a file is accessible under certain
> + * user& gid.
> + * @mode can be R_OK, W_OK, X_OK or F_OK.
More accurately:
@mode can be F_OK, or a bitwise combination of R_OK, W_OK, and X_OK.
> + * see 'man accesss' for more details.
s/accesss/access/
> + * Returns 0 on success, -errno on fail,
> + *>0 on signaled child.
> + */
> +int
> +virFileAccessibleAs(const char *path, int mode,
> + uid_t uid, gid_t gid)
> +{
> + pid_t pid;
> + int waitret, status, ret = 0;
> + int forkRet;
> +
> + forkRet = virFork(&pid);
Should you take a shortcut that if uid and gid match
geteuid()/getegid(), then we avoid the fork()?
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
More information about the libvir-list
mailing list