Back to index

glibc  2.9
grp.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991,1992,1995-2001,2003,2004 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /*
00020  *     POSIX Standard: 9.2.1 Group Database Access      <grp.h>
00021  */
00022 
00023 #ifndef       _GRP_H
00024 #define       _GRP_H 1
00025 
00026 #include <features.h>
00027 
00028 __BEGIN_DECLS
00029 
00030 #include <bits/types.h>
00031 
00032 #define __need_size_t
00033 #include <stddef.h>
00034 
00035 
00036 /* For the Single Unix specification we must define this type here.  */
00037 #if (defined __USE_XOPEN || defined __USE_XOPEN2K) && !defined __gid_t_defined
00038 typedef __gid_t gid_t;
00039 # define __gid_t_defined
00040 #endif
00041 
00042 /* The group structure.      */
00043 struct group
00044   {
00045     char *gr_name;          /* Group name.       */
00046     char *gr_passwd;        /* Password.  */
00047     __gid_t gr_gid;         /* Group ID.  */
00048     char **gr_mem;          /* Member list.      */
00049   };
00050 
00051 
00052 #if defined __USE_SVID || defined __USE_GNU
00053 # define __need_FILE
00054 # include <stdio.h>
00055 #endif
00056 
00057 
00058 #if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
00059 /* Rewind the group-file stream.
00060 
00061    This function is a possible cancellation point and therefore not
00062    marked with __THROW.  */
00063 extern void setgrent (void);
00064 
00065 /* Close the group-file stream.
00066 
00067    This function is a possible cancellation point and therefore not
00068    marked with __THROW.  */
00069 extern void endgrent (void);
00070 
00071 /* Read an entry from the group-file stream, opening it if necessary.
00072 
00073    This function is a possible cancellation point and therefore not
00074    marked with __THROW.  */
00075 extern struct group *getgrent (void);
00076 #endif
00077 
00078 #ifdef __USE_SVID
00079 /* Read a group entry from STREAM.
00080 
00081    This function is not part of POSIX and therefore no official
00082    cancellation point.  But due to similarity with an POSIX interface
00083    or due to the implementation it is a cancellation point and
00084    therefore not marked with __THROW.  */
00085 extern struct group *fgetgrent (FILE *__stream);
00086 #endif
00087 
00088 #ifdef __USE_GNU
00089 /* Write the given entry onto the given stream.
00090 
00091    This function is not part of POSIX and therefore no official
00092    cancellation point.  But due to similarity with an POSIX interface
00093    or due to the implementation it is a cancellation point and
00094    therefore not marked with __THROW.  */
00095 extern int putgrent (__const struct group *__restrict __p,
00096                    FILE *__restrict __f);
00097 #endif
00098 
00099 /* Search for an entry with a matching group ID.
00100 
00101    This function is a possible cancellation point and therefore not
00102    marked with __THROW.  */
00103 extern struct group *getgrgid (__gid_t __gid);
00104 
00105 /* Search for an entry with a matching group name.
00106 
00107    This function is a possible cancellation point and therefore not
00108    marked with __THROW.  */
00109 extern struct group *getgrnam (__const char *__name);
00110 
00111 #if defined __USE_POSIX || defined __USE_MISC
00112 
00113 # ifdef __USE_MISC
00114 /* Reasonable value for the buffer sized used in the reentrant
00115    functions below.  But better use `sysconf'.  */
00116 #  define NSS_BUFLEN_GROUP  1024
00117 # endif
00118 
00119 /* Reentrant versions of some of the functions above.
00120 
00121    PLEASE NOTE: the `getgrent_r' function is not (yet) standardized.
00122    The interface may change in later versions of this library.  But
00123    the interface is designed following the principals used for the
00124    other reentrant functions so the chances are good this is what the
00125    POSIX people would choose.
00126 
00127    This function is not part of POSIX and therefore no official
00128    cancellation point.  But due to similarity with an POSIX interface
00129    or due to the implementation it is a cancellation point and
00130    therefore not marked with __THROW.  */
00131 
00132 # ifdef __USE_GNU
00133 extern int getgrent_r (struct group *__restrict __resultbuf,
00134                      char *__restrict __buffer, size_t __buflen,
00135                      struct group **__restrict __result);
00136 # endif
00137 
00138 /* Search for an entry with a matching group ID.
00139 
00140    This function is a possible cancellation point and therefore not
00141    marked with __THROW.  */
00142 extern int getgrgid_r (__gid_t __gid, struct group *__restrict __resultbuf,
00143                      char *__restrict __buffer, size_t __buflen,
00144                      struct group **__restrict __result);
00145 
00146 /* Search for an entry with a matching group name.
00147 
00148    This function is a possible cancellation point and therefore not
00149    marked with __THROW.  */
00150 extern int getgrnam_r (__const char *__restrict __name,
00151                      struct group *__restrict __resultbuf,
00152                      char *__restrict __buffer, size_t __buflen,
00153                      struct group **__restrict __result);
00154 
00155 # ifdef       __USE_SVID
00156 /* Read a group entry from STREAM.  This function is not standardized
00157    an probably never will.
00158 
00159    This function is not part of POSIX and therefore no official
00160    cancellation point.  But due to similarity with an POSIX interface
00161    or due to the implementation it is a cancellation point and
00162    therefore not marked with __THROW.  */
00163 extern int fgetgrent_r (FILE *__restrict __stream,
00164                      struct group *__restrict __resultbuf,
00165                      char *__restrict __buffer, size_t __buflen,
00166                      struct group **__restrict __result);
00167 # endif
00168 
00169 #endif /* POSIX or reentrant */
00170 
00171 
00172 #ifdef __USE_BSD
00173 
00174 # define __need_size_t
00175 # include <stddef.h>
00176 
00177 /* Set the group set for the current user to GROUPS (N of them).  */
00178 extern int setgroups (size_t __n, __const __gid_t *__groups) __THROW;
00179 
00180 /* Store at most *NGROUPS members of the group set for USER into
00181    *GROUPS.  Also include GROUP.  The actual number of groups found is
00182    returned in *NGROUPS.  Return -1 if the if *NGROUPS is too small.
00183 
00184    This function is not part of POSIX and therefore no official
00185    cancellation point.  But due to similarity with an POSIX interface
00186    or due to the implementation it is a cancellation point and
00187    therefore not marked with __THROW.  */
00188 extern int getgrouplist (__const char *__user, __gid_t __group,
00189                       __gid_t *__groups, int *__ngroups);
00190 
00191 /* Initialize the group set for the current user
00192    by reading the group database and using all groups
00193    of which USER is a member.  Also include GROUP.
00194 
00195    This function is not part of POSIX and therefore no official
00196    cancellation point.  But due to similarity with an POSIX interface
00197    or due to the implementation it is a cancellation point and
00198    therefore not marked with __THROW.  */
00199 extern int initgroups (__const char *__user, __gid_t __group);
00200 
00201 #endif /* Use BSD.  */
00202 
00203 __END_DECLS
00204 
00205 #endif /* grp.h  */