Commit eb41333e authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Use getpeereid(3) where available else use *_PEERCRED replacment function

parent 68658061
This diff is collapsed.
......@@ -834,6 +834,7 @@ AC_CHECK_HEADERS( \
sys/syslog.h \
sys/time.h \
sys/types.h \
sys/ucred.h \
syslog.h \
termios.h \
unistd.h \
......@@ -2478,11 +2479,14 @@ AC_CHECK_FUNCS( \
)
dnl We actually may need to replace more than this.
AC_REPLACE_FUNCS(getopt)
AC_REPLACE_FUNCS(getopt getpeereid)
if test "$ac_cv_func_getopt" != yes; then
LIBSRCS="$LIBSRCS getopt.c"
fi
if test "$ac_cv_func_getpeereid" != yes; then
LIBSRCS="$LIBSRCS getpeereid.c"
fi
if test "$ac_cv_func_snprintf" != yes -o "$ac_cv_func_vsnprintf" != yes; then
if test "$ac_cv_func_snprintf" != yes; then
AC_DEFINE(snprintf, ber_pvt_snprintf, [define to snprintf routine])
......
......@@ -32,7 +32,7 @@
* create a replacement and hope it works
*/
LIBLBER_F (void) ber_pvt_assert LDAP_P(( const char *file, int line,
LBER_F (void) ber_pvt_assert LDAP_P(( const char *file, int line,
const char *test ));
/* Can't use LDAP_STRING(test), that'd expand to "test" */
......
......@@ -197,8 +197,12 @@ LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
# define AC_GAI_STRERROR(x) (gai_strerror((x)))
# else
# define AC_GAI_STRERROR(x) (ldap_pvt_gai_strerror((x)))
char * ldap_pvt_gai_strerror( int );
LDAP_F (char *) ldap_pvt_gai_strerror( int );
# endif
#endif
#ifndef HAVE_GETPEEREID
LDAP_LUTIL_F( int ) getpeereid( int s, uid_t *, gid_t * );
#endif
#endif /* _AC_SOCKET_H_ */
......@@ -164,6 +164,9 @@
/* Define if you have the getpassphrase function. */
#undef HAVE_GETPASSPHRASE
/* Define if you have the getpeereid function. */
#undef HAVE_GETPEEREID
/* Define if you have the getpwnam function. */
#undef HAVE_GETPWNAM
......@@ -542,6 +545,9 @@
/* Define if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define if you have the <sys/ucred.h> header file. */
#undef HAVE_SYS_UCRED_H
/* Define if you have the <sys/un.h> header file. */
#undef HAVE_SYS_UN_H
......
/* getpeereid.c */
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "portable.h"
#ifndef HAVE_GETPEEREID
#include <sys/types.h>
#include <ac/unistd.h>
#include <ac/socket.h>
#if HAVE_SYS_UCRED_H
#include <sys/ucred.h>
#endif
int getpeereid( int s, uid_t *euid, gid_t *egid )
{
#ifdef LDAP_PF_LOCAL
#if defined( SO_PEERCRED )
struct ucred peercred;
size_t peercredlen = sizeof peercred;
if(( getsockopt( s, SOL_SOCKET, SO_PEERCRED,
(void *)&peercred, &peercredlen ) == 0 )
&& ( peercredlen == sizeof peercred ))
{
*euid = peercred.uid;
*egid = peercred.gid;
return 0;
}
#elif defined( LOCAL_PEERCRED )
struct xucred peercred;
socklen_t peercredlen = sizeof peercred;
if(( getsockopt( s, LOCAL_PEERCRED, 1,
(void *)&peercred, &peercredlen ) == 0 )
&& ( peercred.cr_version == XUCRED_VERSION ))
{
*euid = peercred.cr_uid;
*egid = peercred.cr_gid;
return 0;
}
#endif
#endif
return -1;
}
#endif
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment