1 /* Copyright (C) 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <sys/socket.h>
23 #include <asm/posix_types.h>
25 /* The kernel expects this structure in SCM_CREDS messages.
26 * Note: sizeof(struct __kernel_ucred) <= sizeof(struct cmsgcred) must hold.
35 extern int __recvmsg (int, struct msghdr *, int);
38 recvmsg (fd, message, flags)
40 struct msghdr *message;
47 /* Must check for space first. */
48 cm = CMSG_FIRSTHDR (message);
51 if (cm->cmsg_type == SCM_CREDS)
53 if (cm->cmsg_len < CMSG_SPACE (sizeof (struct cmsgcred)))
60 cm = CMSG_NXTHDR (message, cm);
64 ret = __recvmsg (fd, message, flags);
69 /* Postprocess the message control block for SCM_CREDS. */
70 cm = CMSG_FIRSTHDR (message);
74 if (cm->cmsg_type == SCM_CREDS)
76 struct cmsgcred *c = (struct cmsgcred *) CMSG_DATA (cm);
77 struct __kernel_ucred u;
79 memcpy (&u, CMSG_DATA (cm), sizeof (struct __kernel_ucred));
81 c->cmcred_pid = u.pid;
82 c->cmcred_uid = u.uid;
83 c->cmcred_gid = u.gid;
86 c->cmcred_ngroups = 0;
87 for (i = 0; i < CMGROUP_MAX; i++)
88 c->cmcred_groups[i] = -1;
90 cm = CMSG_NXTHDR (message, cm);