mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-20 22:59:34 -05:00
Use getpeereid(3) where available else use *_PEERCRED replacment function
This commit is contained in:
parent
6865806190
commit
eb41333e4c
7 changed files with 726 additions and 654 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
55
libraries/liblutil/getpeereid.c
Normal file
55
libraries/liblutil/getpeereid.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* 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
|
||||
|
|
@ -1555,19 +1555,18 @@ slapd_daemon_task(
|
|||
case AF_LOCAL:
|
||||
sprintf( peername, "PATH=%s", from.sa_un_addr.sun_path );
|
||||
ssf = LDAP_PVT_SASL_LOCAL_SSF;
|
||||
# ifdef SO_PEERCRED
|
||||
{
|
||||
struct ucred peercred;
|
||||
size_t peercred_len = sizeof(peercred);
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
|
||||
if (getsockopt( s, SOL_SOCKET, SO_PEERCRED,
|
||||
(void *)&peercred, &peercred_len ) == 0 &&
|
||||
peercred_len == sizeof(peercred) ) {
|
||||
authid = ch_malloc(sizeof("uidNumber=+gidNumber=+,cn=peercred,cn=external,cn=auth") + 32);
|
||||
sprintf(authid, "uidNumber=%d+gidNumber=%d,cn=peercred,cn=external,cn=auth", peercred.uid, peercred.gid);
|
||||
if( getpeereid( s, &uid, &gid ) == 0 ) {
|
||||
authid = ch_malloc( sizeof("uidNumber=+gidNumber=+,"
|
||||
"cn=peercred,cn=external,cn=auth") + 32);
|
||||
sprintf(authid, "uidNumber=%d+gidNumber=%d,"
|
||||
"cn=peercred,cn=external,cn=auth",
|
||||
uid, gid);
|
||||
}
|
||||
}
|
||||
# endif /* SO_PEERCRED */
|
||||
dnsname = "local";
|
||||
break;
|
||||
#endif /* LDAP_PF_LOCAL */
|
||||
|
|
|
|||
Loading…
Reference in a new issue