]> git.sur5r.net Git - openldap/commitdiff
ITS#3439 (NetBSD support for getpeereid())
authorLuke Howard <lukeh@openldap.org>
Thu, 3 Feb 2005 09:36:25 +0000 (09:36 +0000)
committerLuke Howard <lukeh@openldap.org>
Thu, 3 Feb 2005 09:36:25 +0000 (09:36 +0000)
libraries/liblutil/getpeereid.c
servers/slapd/daemon.c

index 1bbe4aa9fbdfc94b6755c723f4ad712113120d03..0b054a2b95c1e18b231529969da81b44ffa2e231 100644 (file)
@@ -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 @@ int getpeereid( int s, uid_t *euid, gid_t *egid )
                        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 */
 
index 147400ee844a1c3defa750c9f9d7db82ba95bc23..3438fe1df67769851993e3710a041b01193358ef 100644 (file)
@@ -978,8 +978,14 @@ static int slap_open_listener(
 #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
                }