Commit Graph

43 Commits

Author SHA1 Message Date
Marc-André Lureau
95c3e28af5 gio: add G_CREDENTIALS_TYPE_WIN32_PID
Credentials are often used to check peer processes details.

With AF_UNIX sockets on Windows, SIO_AF_UNIX_GETPEERPID can
be used to retrive the peer PID.

We will probably introduce more advanced mechanisms later on, though,
but I am not a Windows API expert.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-01-26 18:19:44 +04:00
Ignacio Casal Quinteiro
1848905a99 credentials: support the local peerpid on macos
xucred does not provide the peer pid id, but this can be fetched
from the socket LOCAL_PEERPID option. Note that we only support
it when creating the credentials from a local socket, if
the credential comes from a message over a socket the peer
pid id will not be set and -1 will be returned when trying
to get the pid for the credential.
2022-01-20 10:52:01 +01:00
Emmanuel Fleury
6e3d30a105 Fix signedness warnings in gio/gcredentials.c
gio/gcredentials.c: In function ‘linux_ucred_check_valid’:
gio/gcredentials.c:317:22: error: comparison of integer expressions of different signedness: ‘uid_t’ {aka ‘unsigned int’} and ‘int’
  317 |       || native->uid == -1
      |                      ^~
gio/gcredentials.c:318:22: error: comparison of integer expressions of different signedness: ‘gid_t’ {aka ‘unsigned int’} and ‘int’
  318 |       || native->gid == -1)
      |                      ^~

gio/gcredentials.c: In function ‘g_credentials_set_unix_user’:
gio/gcredentials.c:639:29: error: comparison of integer expressions of different signedness: ‘uid_t’ {aka ‘unsigned int’} and ‘int’
  639 |   g_return_val_if_fail (uid != -1, FALSE);
      |                             ^~
2021-01-11 20:45:27 +01:00
Emmanuel Fleury
e90a79139f Fix signedness warnings in gio/gcredentials.c:g_credentials_to_string()
gio/gcredentials.c: In function ‘g_credentials_to_string’:
gio/gcredentials.c:238:31: error: comparison of integer expressions of different signedness: ‘uid_t’ {aka ‘unsigned int’} and ‘int’
  238 |   if (credentials->native.uid != -1)
      |                               ^~
gio/gcredentials.c:240:31: error: comparison of integer expressions of different signedness: ‘gid_t’ {aka ‘unsigned int’} and ‘int’
  240 |   if (credentials->native.gid != -1)
      |                               ^~
2020-12-18 12:26:38 +01:00
Philip Withnall
f4766f2034 gcredentials: Improve documentation formatting slightly
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-15 09:10:19 +00:00
Philip Withnall
2a76f01698 gcredentials: Add missing (transfer) and (nullable) return annotations
This commit only looks at the `Returns:` lines in the documentation, and
has examined all of them in the file. Function arguments have not been
checked.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2227
2020-12-15 09:09:59 +00:00
Xavier Claessens
5b2bee3f53 Replace __typeof__ with glib_typeof macro
g_has_typeof macro is wrongly in the public g_ namespace, internaly
symbols are usually in the glib_ namespace. This will also allow to
define glib_typeof differently on non-GNUC compilers (e.g. c++11
decltype).
2020-10-14 14:48:36 -04:00
Dr. Michael Lauer
ec2f60a008 gio: add gcredential support for macOS
[smcv: Apply my review feedback from
<https://bugzilla.gnome.org/show_bug.cgi?id=668866>]

Co-authored-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.gnome.org/GNOME/glib/issues/507
2020-05-07 14:19:16 +01:00
Simon McVittie
3e61acddc5 GCredentials: Format C library type names as code
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-05-07 10:25:14 +01:00
Simon McVittie
1485a97d80 credentials: Invalid Linux struct ucred means "no information"
On Linux, if getsockopt SO_PEERCRED is used on a TCP socket, one
might expect it to fail with an appropriate error like ENOTSUP or
EPROTONOSUPPORT. However, it appears that in fact it succeeds, but
yields a credentials structure with pid 0, uid -1 and gid -1. These
are not real process, user and group IDs that can be allocated to a
real process (pid 0 needs to be reserved to give kill(0) its documented
special semantics, and similarly uid and gid -1 need to be reserved for
setresuid() and setresgid()) so it is not meaningful to signal them to
high-level API users.

An API user with Linux-specific knowledge can still inspect these fields
via g_credentials_get_native() if desired.

Similarly, if SO_PASSCRED is used to receive a SCM_CREDENTIALS message
on a receiving Unix socket, but the sending socket had not enabled
SO_PASSCRED at the time that the message was sent, it is possible
for it to succeed but yield a credentials structure with pid 0, uid
/proc/sys/kernel/overflowuid and gid /proc/sys/kernel/overflowgid. Even
if we were to read those pseudo-files, we cannot distinguish between
the overflow IDs and a real process that legitimately has the same IDs
(typically they are set to 'nobody' and 'nogroup', which can be used
by a real process), so we detect this situation by noticing that
pid == 0, and to save syscalls we do not read the overflow IDs from
/proc at all.

This results in a small API change: g_credentials_is_same_user() now
returns FALSE if we compare two credentials structures that are both
invalid. This seems like reasonable, conservative behaviour: if we cannot
prove that they are the same user, we should assume they are not.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-10-28 19:55:47 +00:00
Philip Withnall
18a232be89 glib: Various minor scan-build fixes
These squash various warnings from `scan-build`. None of them are
legitimate bugs, but some of them do improve code readability a bit.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1767
2019-09-05 13:51:27 +01:00
Дилян Палаузов
512655aa12 minor typos in the documentation (a/an) 2019-08-24 19:14:05 +00:00
Christoph Reiter
97c28f7fe1 ci: fix warnings and enable --werror for the mingw build
Fix various warnings regarding unused variables, duplicated
branches etc by adjusting the ifdeffery and some missing casts.

gnulib triggers -Wduplicated-branches in one of the copied files,
disable as that just makes updating the code harder.

The warning indicating missing features are made none fatal through
pragmas. They still show but don't abort the build.

https://bugzilla.gnome.org/show_bug.cgi?id=793729
2018-04-25 17:23:50 +02:00
Sébastien Wilmet
3bf4a720c3 gio/: LGPLv2+ -> LGPLv2.1+
Sub-directories inside gio/ already processed in a previous commit:
- fam/
- gdbus-2.0/ (which contains only codegen/)
- gvdb/
- inotify/
- tests/
- win32/
- xdgmime/

Other sub-directories inside gio/:
- completion/: no license headers
- kqueue/: not LGPL, BSD-style license

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-29 19:53:34 +02:00
Emmanuele Bassi
f952fdf3fc Drop trailing semi-colon from G_DEFINE_ macro
It's unnecessary, and only adds visual noise; we have been fairly
inconsistent in the past, but the semi-colon-less version clearly
dominates in the code base.

https://bugzilla.gnome.org/show_bug.cgi?id=669355
2017-04-10 10:38:31 +01:00
Philip Withnall
25a7c817d3 glib: Add missing (nullable) and (optional) annotations
Add various (nullable) and (optional) annotations which were missing
from a variety of functions. Also port a couple of existing (allow-none)
annotations in the same files to use (nullable) and (optional) as
appropriate instead.

Secondly, add various (not nullable) annotations as needed by the new
default in gobject-introspection of marking gpointers as (nullable). See
https://bugzilla.gnome.org/show_bug.cgi?id=729660.

This includes adding some stub documentation comments for the
assertion macro error functions, which weren’t previously documented.
The new comments are purely to allow for annotations, and hence are
marked as (skip) to prevent the symbols appearing in the GIR file.

https://bugzilla.gnome.org/show_bug.cgi?id=719966
2015-11-07 10:48:32 +01:00
Colin Walters
91821974e1 gcredentials: Add assertion to pacify static analysis
This should always be true.

https://bugzilla.gnome.org/show_bug.cgi?id=733576
2014-07-23 07:43:41 -04:00
Patrick Welche
afce39c228 gcredentials: add NetBSD support
https://bugzilla.gnome.org/show_bug.cgi?id=728256
2014-06-28 14:06:36 -04:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Matthias Clasen
fc04275a00 Docs: don't use the type tag
Just avoid explicit docbook markup.
2014-01-31 05:58:17 -05:00
Dan Winship
5a269e5a90 gcredentials: add Solaris support
Based on patches from Igor Pashev.

https://bugzilla.gnome.org/show_bug.cgi?id=705029
2013-10-04 09:51:31 -04:00
Dan Winship
66edac7fb9 gcredentials: add Hurd support
It uses the same system as FreeBSD.

https://bugzilla.gnome.org/show_bug.cgi?id=708265
2013-10-04 09:51:31 -04:00
Dan Winship
cedd697bf8 gcredentials: add internal macros to simplify all the #ifdefs
Rather than having lots of obscure platform-based #ifdefs all over
gio, define some macros in gcredentialsprivate.h, and use those to
simplify the rest of the code.

https://bugzilla.gnome.org/show_bug.cgi?id=701482
2013-10-04 09:51:31 -04:00
Simon McVittie
8f65536504 GCredentials: add getter/setter for the Unix process ID
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=687920
2012-12-19 15:08:09 -05:00
Dan Winship
b377e69685 Add gnetworking.h
Install a public "gnetworking.h" header that can be used to include
the relevant OS-dependent networking headers. This does not really
abstract away unix-vs-windows however; error codes, in particular,
are incompatible.

gnetworkingprivate.h now contains just a few internal URI-related
functions

Also add a g_networking_init() function to gnetworking.h, which can be
used to explicitly initialize OS-level networking, rather than having
that happen as a side-effect of registering GInetAddress.

https://bugzilla.gnome.org/show_bug.cgi?id=623187
2012-12-12 15:20:22 +01:00
Simon McVittie
1afaea333b Use the FreeBSD credentials-passing code on Debian GNU/kFreeBSD
The __FreeBSD__ macro means we have both a FreeBSD kernel and FreeBSD
libc, which isn't the case on GNU/kFreeBSD (GNU libc and userland on
the FreeBSD kernel), so it predefines a different macro. The kernel
is what actually matters for credentials-passing, though.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Tested-by: Steven Chamberlain <steven@pyro.eu.org>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=649302
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=581750
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=631968
Reviewed-by: Dan Winship <danw@gnome.org>
2012-11-02 13:55:40 +00:00
Antoine Jacoutot
77f4f5aa02 Add glib credentials support to OpenBSD.
https://bugzilla.gnome.org/show_bug.cgi?id=650885
2011-05-27 14:22:56 -04:00
Johan Dahlin
30132c44c1 Add a lot of missing annotations 2010-09-24 18:24:41 -03:00
Joe Marcus Clarke
964eb62343 Bug 628904 – Add credential support for FreeBSD and fix a socket issue
Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-09-09 14:10:01 -04:00
David Zeuthen
173977a701 GCredentials: use effective uid/gid
Otherwise e.g. setuid root processes can't connect to the system
bus. This was discovered when porting PolicyKit's pkexec(1) command to
a PolicyKit library using GDBus.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-30 11:26:43 -04:00
David Zeuthen
7eba41346e Bug 617483 – Credentials passing
- Make GCredentials instance and class structures private so it can't
   be subclassed and we don't have to worry about ABI compat
   issues. This also allows us to get rid of the GCredentialsPrivate
   struct.

 - Add a GCredentialsType enumeration that is used whenever exchanging
   pointers with the user. This allows us to support OSes with
   multiple native credential types. In particular, it allows
   supporting OSes where the native credential evolves or even changes
   over time.

 - Add g_socket_get_credentials() method.

 - Add tests for g_socket_get_credentials(). Right now this is in the
   GDBus peer-to-peer test case but we can change that later.

 - Move GTcpConnection into a separate gtk-doc page as was already
   half-done with GUnixConnection. Also finish the GUnixConnection
   move and ensure send_credentials() and receive_credentials()
   methods are in the docs. Also nuke comment about GTcpConnection
   being empty compared to its superclass.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-20 16:34:18 -04:00
Ryan Lortie
5b946e0504 gio/: fully remove gioalias hacks 2010-07-07 19:53:22 -04:00
Tor Lillqvist
efb1a054b0 Fix build with the Microsoft compiler
Correct a few gccisms and C99isms. Ensure the Windows-specific gio
source files are listed in the generated gio VS project file.
2010-06-22 12:22:46 +03:00
Javier Jardón
257c519ba2 Fix trivial typo in GCredentials code
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=618839
2010-05-18 23:45:54 +02:00
Ryan Lortie
6067f9f794 Bug 618839 - Typo at translation message
Fix trivial typo in GCredentials code
2010-05-18 16:43:36 -04:00
Matthias Clasen
1d22b64843 Cleanups
Sort #includes a bit better, and don't include platform-specific
headers in gio.h.
2010-05-14 08:38:07 -04:00
Matthias Clasen
0cf467c2ca Update copyright years to include 2010 2010-05-09 13:14:55 -04:00
David Zeuthen
c148cafdd1 GDBus: Rework GCredentials type
These changes are is related to

 https://bugzilla.gnome.org/show_bug.cgi?id=617483

and IRC discussions with danw.
2010-05-09 10:03:56 -04:00
David Zeuthen
46ce134d51 GDBus: Add new symbols to gio.symbols 2010-05-06 17:31:51 -04:00
David Zeuthen
fb1b4599a0 GDBus: Fix up i18n 2010-05-06 16:34:23 -04:00
David Zeuthen
0fd6498cd8 Add "Since: 2.26" to all new GDBus API 2010-05-06 16:02:08 -04:00
David Zeuthen
c490c14f4e Set up gtk-doc for GDBus
Also move send_credentials() and receive_credentials() to
GUnixConnection. This code might change, discussion is still ongoing
in

 https://bugzilla.gnome.org/show_bug.cgi?id=617483.
2010-05-06 15:31:45 -04:00
David Zeuthen
d0a14469d0 Initial GDBus code-drop from GDBus-standalone repo
Things compile and the test-suite passes. Still need to hook up
gio.symbols and docs. There are still a bunch of TODOs left in the
sources that needs to be addressed.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-05-06 14:21:32 -04:00