Back to index

glibc  2.9
pwd.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.2 User Database Access       <pwd.h>
00021  */
00022 
00023 #ifndef       _PWD_H
00024 #define       _PWD_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 #if defined __USE_XOPEN || defined __USE_XOPEN2K
00036 /* The Single Unix specification says that some more types are
00037    available here.  */
00038 # ifndef __gid_t_defined
00039 typedef __gid_t gid_t;
00040 #  define __gid_t_defined
00041 # endif
00042 
00043 # ifndef __uid_t_defined
00044 typedef __uid_t uid_t;
00045 #  define __uid_t_defined
00046 # endif
00047 #endif
00048 
00049 /* The passwd structure.  */
00050 struct passwd
00051 {
00052   char *pw_name;            /* Username.  */
00053   char *pw_passwd;          /* Password.  */
00054   __uid_t pw_uid;           /* User ID.  */
00055   __gid_t pw_gid;           /* Group ID.  */
00056   char *pw_gecos;           /* Real name.  */
00057   char *pw_dir;                    /* Home directory.  */
00058   char *pw_shell;           /* Shell program.  */
00059 };
00060 
00061 
00062 #if defined __USE_SVID || defined __USE_GNU
00063 # define __need_FILE
00064 # include <stdio.h>
00065 #endif
00066 
00067 
00068 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN_EXTENDED
00069 /* Rewind the password-file stream.
00070 
00071    This function is a possible cancellation point and therefore not
00072    marked with __THROW.  */
00073 extern void setpwent (void);
00074 
00075 /* Close the password-file stream.
00076 
00077    This function is a possible cancellation point and therefore not
00078    marked with __THROW.  */
00079 extern void endpwent (void);
00080 
00081 /* Read an entry from the password-file stream, opening it if necessary.
00082 
00083    This function is a possible cancellation point and therefore not
00084    marked with __THROW.  */
00085 extern struct passwd *getpwent (void);
00086 #endif
00087 
00088 #ifdef __USE_SVID
00089 /* Read an entry from 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 struct passwd *fgetpwent (FILE *__stream);
00096 
00097 /* Write the given entry onto the given stream.
00098 
00099    This function is not part of POSIX and therefore no official
00100    cancellation point.  But due to similarity with an POSIX interface
00101    or due to the implementation it is a cancellation point and
00102    therefore not marked with __THROW.  */
00103 extern int putpwent (__const struct passwd *__restrict __p,
00104                    FILE *__restrict __f);
00105 #endif
00106 
00107 /* Search for an entry with a matching user ID.
00108 
00109    This function is a possible cancellation point and therefore not
00110    marked with __THROW.  */
00111 extern struct passwd *getpwuid (__uid_t __uid);
00112 
00113 /* Search for an entry with a matching username.
00114 
00115    This function is a possible cancellation point and therefore not
00116    marked with __THROW.  */
00117 extern struct passwd *getpwnam (__const char *__name);
00118 
00119 #if defined __USE_POSIX || defined __USE_MISC
00120 
00121 # ifdef __USE_MISC
00122 /* Reasonable value for the buffer sized used in the reentrant
00123    functions below.  But better use `sysconf'.  */
00124 #  define NSS_BUFLEN_PASSWD 1024
00125 # endif
00126 
00127 /* Reentrant versions of some of the functions above.
00128 
00129    PLEASE NOTE: the `getpwent_r' function is not (yet) standardized.
00130    The interface may change in later versions of this library.  But
00131    the interface is designed following the principals used for the
00132    other reentrant functions so the chances are good this is what the
00133    POSIX people would choose.  */
00134 
00135 # if defined __USE_SVID || defined __USE_MISC
00136 /* This function is not part of POSIX and therefore no official
00137    cancellation point.  But due to similarity with an POSIX interface
00138    or due to the implementation it is a cancellation point and
00139    therefore not marked with __THROW.  */
00140 extern int getpwent_r (struct passwd *__restrict __resultbuf,
00141                      char *__restrict __buffer, size_t __buflen,
00142                      struct passwd **__restrict __result);
00143 # endif
00144 
00145 extern int getpwuid_r (__uid_t __uid,
00146                      struct passwd *__restrict __resultbuf,
00147                      char *__restrict __buffer, size_t __buflen,
00148                      struct passwd **__restrict __result);
00149 
00150 extern int getpwnam_r (__const char *__restrict __name,
00151                      struct passwd *__restrict __resultbuf,
00152                      char *__restrict __buffer, size_t __buflen,
00153                      struct passwd **__restrict __result);
00154 
00155 
00156 # ifdef       __USE_SVID
00157 /* Read an entry from STREAM.  This function is not standardized and
00158    probably never will.
00159 
00160    This function is not part of POSIX and therefore no official
00161    cancellation point.  But due to similarity with an POSIX interface
00162    or due to the implementation it is a cancellation point and
00163    therefore not marked with __THROW.  */
00164 extern int fgetpwent_r (FILE *__restrict __stream,
00165                      struct passwd *__restrict __resultbuf,
00166                      char *__restrict __buffer, size_t __buflen,
00167                      struct passwd **__restrict __result);
00168 # endif
00169 
00170 #endif /* POSIX or reentrant */
00171 
00172 #ifdef __USE_GNU
00173 /* Re-construct the password-file line for the given uid
00174    in the given buffer.  This knows the format that the caller
00175    will expect, but this need not be the format of the password file.
00176 
00177    This function is not part of POSIX and therefore no official
00178    cancellation point.  But due to similarity with an POSIX interface
00179    or due to the implementation it is a cancellation point and
00180    therefore not marked with __THROW.  */
00181 extern int getpw (__uid_t __uid, char *__buffer);
00182 #endif
00183 
00184 __END_DECLS
00185 
00186 #endif /* pwd.h  */