getpwuid.h

Go to the documentation of this file.
00001 ///
00002 /// \file       getpwuid.h
00003 ///             Header for getpwduid*() calls, for systems that don't have an equivalent.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2007-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008     Portions Copyright (C) 2011, RealVNC Ltd.
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019     See the GNU General Public License in the COPYING file at the
00020     root directory of this project for more details.
00021 */
00022 
00023 #ifndef __BARRY_GETPWUID_H__
00024 #define __BARRY_GETPWUID_H__
00025 
00026 #include "config.h"             // getpwuid.h is not installed, so this is safe
00027 #include <sys/types.h>
00028 
00029 #ifdef HAVE_GETPWUID
00030 // System supports pwd so just include the system headers
00031 #include <pwd.h>
00032 
00033 #else
00034 
00035 // so define our own version...
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 struct barry_passwd {
00040         char   *pw_name;       /* username */
00041         char   *pw_passwd;     /* user password */
00042         uid_t   pw_uid;        /* user ID */
00043         gid_t   pw_gid;        /* group ID */
00044         char   *pw_gecos;      /* real name */
00045         char   *pw_dir;        /* home directory */
00046         char   *pw_shell;      /* shell program */
00047 };
00048 
00049 struct barry_passwd *barry_getpwuid(uid_t uid);
00050 int barry_getpwuid_r(uid_t uid, struct barry_passwd *pwd,
00051                    char *buf, size_t buflen, struct barry_passwd **result);
00052 
00053 #ifdef __cplusplus
00054 }
00055 #endif
00056 
00057 // and override the system's names so we call our own
00058 #define passwd barry_passwd
00059 #define getpwuid(u) barry_getpwuid(u)
00060 #define getpwuid_r(u, p, b, l, r) barry_getpwuid_r(u, p, b, l, r)
00061 
00062 #endif // !HAVE_GETPWDUID
00063 
00064 #endif  // __BARRY_GETPWUID_H__
00065