mbr_check_membership.3   [plain text]


.\" Copyright (c) 2005-2007 Apple Inc
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 4. Neither the name of Apple Computer nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"
.Dd February 3, 2005
.Dt MBR_CHECK_MEMBERSHIP 3
.Os "Mac OS X"
.Sh NAME
.Nm mbr_check_membership
.Nd check whether a user is a member of a group
.Sh SYNOPSIS
.In membership.h
.Ft int
.Fn mbr_check_membership "uuid_t user" "uuid_t group" "int *ismember"
.Sh DESCRIPTION
.Fn mbr_check_membership
tests if a given user is a member of a group, individually or as a member of a nested group.
.Fa ismember
is set to 1 if the user is a member of the group, and 0 otherwise.  
.Pp
Users may belong to any number of groups.
.Fn mbr_check_membership
should be always be used to check group membership, rather than
calling
.Xr getgroups 2 ,
and checking the returned list of gids.
The
.Xr setgroups 2
and
.Xr getgroups 2
routines are limited to a fixed number of gids,
and so may not include all of a user's groups.
.Pp
There are two special cases.
If the two uuids are equal, then 
.Fa ismember
is set to 1.
If the
.Fa group
uuid is equal to the reserved "everyone" uuid (ABCDEFAB-CDEF-ABCD-EFAB-CDEF0000000C), then
.Fa ismember
will be set to 1 for any valid user.
.Pp
Group membership information is managed by the
.Xr DirectoryService 8
daemon.
.Sh RETURN VALUES
.Fn mbr_check_membership
returns 0 on success.
It returns EIO if it is unable to communicate with the
.Xr DirectoryService 8
daemon.
ENOENT is returned if
.Fa user
cannot be found.
.Pp
Note that 
.Fn mbr_check_membership
does not test whether
.Fa group
exists or not.
Querying membership for a nonexistent group will result in
.Fa ismember
being to 0 and a return value of 0.
.Sh SEE ALSO
.Xr setgroups 2 ,
.Xr getgroups 2 ,
.Xr mbr_uid_to_uuid 3 ,
.Xr DirectoryService 8