
    This patch file is derived from OpenLDAP Software. All of the
modifications to OpenLDAP Software represented in the following
patch(es) were developed by Love <lha@it.su.se>. These modifications
are not subject to any license of Stockholm University.


    I, Love, hereby place the following modifications to OpenLDAP
Software (and only these modifications) into the public domain. Hence,
these modifications may be freely used and/or redistributed for any
purpose with or without attribution and/or other notice.

note, this is a license, not copyright.


--- work3/openldap-2.2.18/servers/slapd/daemon.c	2004-08-30 17:44:19.000000000 +0200
+++ work/openldap-2.2.18/servers/slapd/daemon.c	2004-12-12 21:38:35.000000000 +0100
@@ -864,8 +864,14 @@
 #endif
 #ifdef LDAP_PF_LOCAL
 		case AF_LOCAL:
-			addrlen = sizeof(struct sockaddr_un);
-			break;
+#ifdef LOCAL_CREDS
+		{
+		    int one = 1;
+		    setsockopt(l.sl_sd, 0, LOCAL_CREDS, &one, sizeof one);
+		}
+#endif
+		addrlen = sizeof(struct sockaddr_un);
+		break;
 #endif
 		}
 
--- work3/openldap-2.2.18/libraries/liblutil/getpeereid.c	2004-01-01 19:16:31.000000000 +0100
+++ work/openldap-2.2.18/libraries/liblutil/getpeereid.c	2004-12-27 15:28:57.000000000 +0100
@@ -40,6 +40,9 @@
 #include <sys/stat.h>
 #endif
 
+#include <stdlib.h>
+
+
 int getpeereid( int s, uid_t *euid, gid_t *egid )
 {
 #ifdef LDAP_PF_LOCAL
@@ -95,6 +98,49 @@
 			return 0;
 		}
 	}
+#elif defined(SOCKCREDSIZE)
+        struct msghdr msg;
+        socklen_t crmsgsize;
+        void *crmsg;
+        struct cmsghdr *cmp;
+        struct sockcred *sc;
+
+	memset(&msg, 0, sizeof msg);
+	crmsgsize = CMSG_SPACE(SOCKCREDSIZE(NGROUPS));
+	if (crmsgsize == 0)
+	    goto sc_err;
+	crmsg = malloc(crmsgsize);
+	if (crmsg == NULL)
+	    goto sc_err;
+	memset(crmsg, 0, crmsgsize);
+	
+	msg.msg_control = crmsg;
+	msg.msg_controllen = crmsgsize;
+	
+	if (recvmsg(s, &msg, 0) < 0) {
+	    free(crmsg);
+	    goto sc_err;
+	}	
+
+	if (msg.msg_controllen == 0 || (msg.msg_flags & MSG_CTRUNC) != 0) {
+	    free(crmsg);
+	    goto sc_err;
+	}	
+	
+	cmp = CMSG_FIRSTHDR(&msg);
+	if (cmp->cmsg_level != SOL_SOCKET || cmp->cmsg_type != SCM_CREDS) {
+	    printf("nocreds\n");
+	    goto sc_err;
+	}	
+	
+	sc = (struct sockcred *)(void *)CMSG_DATA(cmp);
+	
+	*euid = sc->sc_euid;
+	*egid = sc->sc_egid;
+
+	free(crmsg);
+	return 0;
+ sc_err:	
 #endif
 #endif /* LDAP_PF_LOCAL */
 
