2 * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #ifndef _COMPAT_SOCKET_H
19 #define _COMPAT_SOCKET_H
21 #include <sys/socket.h>
24 #include <common/macros.h>
28 #define LTTNG_SOCK_CREDS SCM_CREDENTIALS
30 typedef struct ucred lttng_sock_cred
;
32 #define LTTNG_SOCK_SET_UID_CRED(c, u) LTTNG_REF(c)->uid = u
33 #define LTTNG_SOCK_SET_GID_CRED(c, g) LTTNG_REF(c)->gid = g
34 #define LTTNG_SOCK_SET_PID_CRED(c, p) LTTNG_REF(c)->pid = p
36 #define LTTNG_SOCK_GET_UID_CRED(c) LTTNG_REF(c)->uid
37 #define LTTNG_SOCK_GET_GID_CRED(c) LTTNG_REF(c)->gid
38 #define LTTNG_SOCK_GET_PID_CRED(c) LTTNG_REF(c)->pid
40 #elif (defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__sun__))
42 struct lttng_sock_cred
{
47 typedef struct lttng_sock_cred lttng_sock_cred
;
49 #define LTTNG_SOCK_GET_UID_CRED(c) LTTNG_REF(c)->uid
50 #define LTTNG_SOCK_GET_GID_CRED(c) LTTNG_REF(c)->gid
51 #define LTTNG_SOCK_GET_PID_CRED(c) -1
54 #error "Please add support for your OS."
55 #endif /* __linux__ , __FreeBSD__ */
61 # ifdef _CMSG_DATA_ALIGN
62 # define CMSG_ALIGN(len) _CMSG_DATA_ALIGN(len)
64 /* aligning to sizeof (long) is assumed to be portable (fd.o#40235) */
65 # define CMSG_ALIGN(len) (((len) + sizeof (long) - 1) & ~(sizeof (long) - 1))
68 # define CMSG_SPACE(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + CMSG_ALIGN (len))
71 # define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
78 getpeereid(int s
, uid_t
*euid
, gid_t
*gid
)
81 ucred_t
*ucred
= NULL
;
83 ret
= getpeerucred(s
, &ucred
);
88 ret
= ucred_geteuid(ucred
);
94 ret
= ucred_getrgid(ucred
);
108 #endif /* _COMPAT_SOCKET_H */