]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/recvmsg.c
52a0abcf675ecae8e2a2b96f3a9f9c142ead7483
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / recvmsg.c
1 /* Copyright (C) 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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. */
18
19 #include <sys/socket.h>
20 #include <errno.h>
21 #include <string.h>
22
23 #include <asm/posix_types.h>
24
25 /* The kernel expects this structure in SCM_CREDS messages.
26 * Note: sizeof(struct __kernel_ucred) <= sizeof(struct cmsgcred) must hold.
27 */
28 struct __kernel_ucred
29 {
30 __kernel_pid_t pid;
31 __kernel_uid_t uid;
32 __kernel_gid_t gid;
33 };
34
35 extern int __syscall_recvmsg (int, struct msghdr *, int);
36
37 int
38 __libc_recvmsg (int fd, struct msghdr *message, int flags)
39 {
40 struct cmsghdr *cm;
41 int ret;
42
43 ret = __syscall_recvmsg (fd, message, flags);
44
45 if (ret == -1)
46 return ret;
47
48 /* Postprocess the message control block for SCM_CREDS. */
49 cm = CMSG_FIRSTHDR (message);
50 while (cm)
51 {
52 if (cm->cmsg_type == SCM_CREDS)
53 {
54 struct cmsgcred *c = (struct cmsgcred *) CMSG_DATA (cm);
55 struct __kernel_ucred u;
56 int i;
57 memcpy (&u, CMSG_DATA (cm), sizeof (struct __kernel_ucred));
58
59 c->cmcred_pid = u.pid;
60 c->cmcred_uid = u.uid;
61 c->cmcred_gid = u.gid;
62
63 c->cmcred_euid = -1;
64 c->cmcred_ngroups = 0;
65 for (i = 0; i < CMGROUP_MAX; i++)
66 c->cmcred_groups[i] = -1;
67 }
68 cm = CMSG_NXTHDR (message, cm);
69 }
70
71 return ret;
72 }
73
74 weak_alias (__libc_recvmsg, recvmsg)