summaryrefslogtreecommitdiff
path: root/gio/gcredentialsprivate.h
blob: 13d3bf327ab9c2a2228d5faff6f378a60ee4edf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* GIO - GLib Input, Output and Streaming Library
 *
 * Copyright 2013 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __G_CREDENTIALS_PRIVATE_H__
#define __G_CREDENTIALS_PRIVATE_H__

#include "gio/gcredentials.h"
#include "gio/gnetworking.h"

/*
 * G_CREDENTIALS_SUPPORTED:
 *
 * Defined to 1 if GCredentials works.
 */
#undef G_CREDENTIALS_SUPPORTED

/*
 * G_CREDENTIALS_USE_LINUX_UCRED, etc.:
 *
 * Defined to 1 if GCredentials uses Linux `struct ucred`, etc.
 */
#undef G_CREDENTIALS_USE_LINUX_UCRED
#undef G_CREDENTIALS_USE_FREEBSD_CMSGCRED
#undef G_CREDENTIALS_USE_NETBSD_UNPCBID
#undef G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED
#undef G_CREDENTIALS_USE_SOLARIS_UCRED
#undef G_CREDENTIALS_USE_APPLE_XUCRED

/*
 * G_CREDENTIALS_NATIVE_TYPE:
 *
 * Defined to one of G_CREDENTIALS_TYPE_LINUX_UCRED, etc.
 */
#undef G_CREDENTIALS_NATIVE_TYPE

/*
 * G_CREDENTIALS_NATIVE_SIZE:
 *
 * Defined to the size of the %G_CREDENTIALS_NATIVE_TYPE
 */
#undef G_CREDENTIALS_NATIVE_SIZE

/*
 * G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED:
 *
 * Defined to 1 if we have a message-passing API in which credentials
 * are attached to a particular message, such as `SCM_CREDENTIALS` on Linux
 * or `SCM_CREDS` on FreeBSD.
 */
#undef G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED

/*
 * G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED:
 *
 * Defined to 1 if we have a `getsockopt()`-style API in which one end of
 * a socket connection can directly query the credentials of the process
 * that initiated the other end, such as `getsockopt SO_PEERCRED` on Linux
 * or `getpeereid()` on multiple operating systems.
 */
#undef G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED

/*
 * G_CREDENTIALS_SPOOFING_SUPPORTED:
 *
 * Defined to 1 if privileged processes can spoof their credentials when
 * using the message-passing API.
 */
#undef G_CREDENTIALS_SPOOFING_SUPPORTED

/*
 * G_CREDENTIALS_PREFER_MESSAGE_PASSING:
 *
 * Defined to 1 if the data structure transferred by the message-passing
 * API is strictly more informative than the one transferred by the
 * `getsockopt()`-style API, and hence should be preferred, even for
 * protocols like D-Bus that are defined in terms of the credentials of
 * the (process that opened the) socket, as opposed to the credentials
 * of an individual message.
 */
#undef G_CREDENTIALS_PREFER_MESSAGE_PASSING

/*
 * G_CREDENTIALS_HAS_PID:
 *
 * Defined to 1 if the %G_CREDENTIALS_NATIVE_TYPE contains the process ID.
 */
#undef G_CREDENTIALS_HAS_PID

#ifdef __linux__
#define G_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_USE_LINUX_UCRED 1
#define G_CREDENTIALS_NATIVE_TYPE G_CREDENTIALS_TYPE_LINUX_UCRED
#define G_CREDENTIALS_NATIVE_SIZE (sizeof (struct ucred))
#define G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
#define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_SPOOFING_SUPPORTED 1
#define G_CREDENTIALS_HAS_PID 1

#elif defined(__FreeBSD__)                                  || \
      defined(__FreeBSD_kernel__) /* Debian GNU/kFreeBSD */ || \
      defined(__GNU__)            /* GNU Hurd */            || \
      defined(__DragonFly__)      /* DragonFly BSD */
#define G_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_USE_FREEBSD_CMSGCRED 1
#define G_CREDENTIALS_NATIVE_TYPE G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED
#define G_CREDENTIALS_NATIVE_SIZE (sizeof (struct cmsgcred))
#define G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
#define G_CREDENTIALS_SPOOFING_SUPPORTED 1
/* GLib doesn't implement it yet, but FreeBSD's getsockopt()-style API
 * is getpeereid(), which is not as informative as struct cmsgcred -
 * it does not tell us the PID. As a result, libdbus prefers to use
 * SCM_CREDS, and if we implement getpeereid() in future, we should
 * do the same. */
#define G_CREDENTIALS_PREFER_MESSAGE_PASSING 1
#define G_CREDENTIALS_HAS_PID 1

#elif defined(__NetBSD__)
#define G_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_USE_NETBSD_UNPCBID 1
#define G_CREDENTIALS_NATIVE_TYPE G_CREDENTIALS_TYPE_NETBSD_UNPCBID
#define G_CREDENTIALS_NATIVE_SIZE (sizeof (struct unpcbid))
/* #undef G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED */
#define G_CREDENTIALS_SPOOFING_SUPPORTED 1
#define G_CREDENTIALS_HAS_PID 1

#elif defined(__OpenBSD__)
#define G_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_USE_OPENBSD_SOCKPEERCRED 1
#define G_CREDENTIALS_NATIVE_TYPE G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED
#define G_CREDENTIALS_NATIVE_SIZE (sizeof (struct sockpeercred))
#define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_SPOOFING_SUPPORTED 1
#define G_CREDENTIALS_HAS_PID 1

#elif defined(__sun__) || defined(__illumos__) || defined (__OpenSolaris_kernel__)
#include <ucred.h>
#define G_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_USE_SOLARIS_UCRED 1
#define G_CREDENTIALS_NATIVE_TYPE G_CREDENTIALS_TYPE_SOLARIS_UCRED
#define G_CREDENTIALS_NATIVE_SIZE (ucred_size ())
#define G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
#define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_HAS_PID 1

#elif defined(__APPLE__)
#include <sys/ucred.h>
#define G_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_USE_APPLE_XUCRED 1
#define G_CREDENTIALS_NATIVE_TYPE G_CREDENTIALS_TYPE_APPLE_XUCRED
#define G_CREDENTIALS_NATIVE_SIZE (sizeof (struct xucred))
#undef G_CREDENTIALS_UNIX_CREDENTIALS_MESSAGE_SUPPORTED
#define G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED 1
#define G_CREDENTIALS_SPOOFING_SUPPORTED 1
#define G_CREDENTIALS_HAS_PID 0

#endif

#endif /* __G_CREDENTIALS_PRIVATE_H__ */