gunixconnection.c 22.9 KB
Newer Older
1 2 3 4
/* GIO - GLib Input, Output and Streaming Library
 *
 * Copyright © 2009 Codethink Limited
 *
5 6 7 8
 * 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.
9 10 11 12 13 14 15
 *
 * See the included COPYING file for more information.
 *
 * Authors: Ryan Lortie <desrt@desrt.ca>
 */

#include "config.h"
16

17
#include "gunixconnection.h"
18 19 20
#include "gnetworking.h"
#include "gsocket.h"
#include "gsocketcontrolmessage.h"
21
#include "gunixcredentialsmessage.h"
22
#include "gunixfdmessage.h"
23 24
#include "glibintl.h"

25 26 27 28
#include <errno.h>
#include <string.h>
#include <unistd.h>

29
/**
30
 * SECTION:gunixconnection
31
 * @title: GUnixConnection
Matthias Clasen's avatar
Matthias Clasen committed
32 33
 * @short_description: A UNIX domain GSocketConnection
 * @include: gio/gunixconnection.h
34 35 36 37 38
 * @see_also: #GSocketConnection.
 *
 * This is the subclass of #GSocketConnection that is created
 * for UNIX domain sockets.
 *
Matthias Clasen's avatar
Matthias Clasen committed
39 40 41
 * It contains functions to do some of the UNIX socket specific
 * functionality like passing file descriptors.
 *
42
 * Note that `<gio/gunixconnection.h>` belongs to the UNIX-specific
43 44
 * GIO interfaces, thus you have to use the `gio-unix-2.0.pc`
 * pkg-config file when using it.
45 46
 *
 * Since: 2.22
47
 */
48

49 50 51 52 53 54 55
/**
 * GUnixConnection:
 *
 * #GUnixConnection is an opaque data structure and can only be accessed
 * using the following functions.
 **/

56 57 58 59 60
G_DEFINE_TYPE_WITH_CODE (GUnixConnection, g_unix_connection,
			 G_TYPE_SOCKET_CONNECTION,
  g_socket_connection_factory_register_type (g_define_type_id,
					     G_SOCKET_FAMILY_UNIX,
					     G_SOCKET_TYPE_STREAM,
61
					     G_SOCKET_PROTOCOL_DEFAULT);
62 63 64 65
			 );

/**
 * g_unix_connection_send_fd:
66
 * @connection: a #GUnixConnection
67
 * @fd: a file descriptor
68 69
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
 * @error: (nullable): #GError for error reporting, or %NULL to ignore.
70
 *
71 72
 * Passes a file descriptor to the receiving side of the
 * connection. The receiving end has to call g_unix_connection_receive_fd()
73 74 75 76 77 78 79 80 81
 * to accept the file descriptor.
 *
 * As well as sending the fd this also writes a single byte to the
 * stream, as this is required for fd passing to work on some
 * implementations.
 *
 * Returns: a %TRUE on success, %NULL on error.
 *
 * Since: 2.22
82
 */
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
gboolean
g_unix_connection_send_fd (GUnixConnection  *connection,
                           gint              fd,
                           GCancellable     *cancellable,
                           GError          **error)
{
  GSocketControlMessage *scm;
  GSocket *socket;

  g_return_val_if_fail (G_IS_UNIX_CONNECTION (connection), FALSE);
  g_return_val_if_fail (fd >= 0, FALSE);

  scm = g_unix_fd_message_new ();

  if (!g_unix_fd_message_append_fd (G_UNIX_FD_MESSAGE (scm), fd, error))
    {
      g_object_unref (scm);
      return FALSE;
    }

  g_object_get (connection, "socket", &socket, NULL);
104
  if (g_socket_send_message (socket, NULL, NULL, 0, &scm, 1, 0, cancellable, error) != 1)
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    /* XXX could it 'fail' with zero? */
    {
      g_object_unref (socket);
      g_object_unref (scm);

      return FALSE;
    }

  g_object_unref (socket);
  g_object_unref (scm);

  return TRUE;
}

/**
 * g_unix_connection_receive_fd:
121
 * @connection: a #GUnixConnection
122 123
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
 * @error: (nullable): #GError for error reporting, or %NULL to ignore
124
 *
125 126 127
 * Receives a file descriptor from the sending end of the connection.
 * The sending end has to call g_unix_connection_send_fd() for this
 * to work.
128 129 130 131 132 133 134 135
 *
 * As well as reading the fd this also reads a single byte from the
 * stream, as this is required for fd passing to work on some
 * implementations.
 *
 * Returns: a file descriptor on success, -1 on error.
 *
 * Since: 2.22
Allison Karlitskaya's avatar
Allison Karlitskaya committed
136
 **/
137 138 139 140 141 142 143 144 145 146 147 148 149
gint
g_unix_connection_receive_fd (GUnixConnection  *connection,
                              GCancellable     *cancellable,
                              GError          **error)
{
  GSocketControlMessage **scms;
  gint *fds, nfd, fd, nscm;
  GUnixFDMessage *fdmsg;
  GSocket *socket;

  g_return_val_if_fail (G_IS_UNIX_CONNECTION (connection), -1);

  g_object_get (connection, "socket", &socket, NULL);
150 151
  if (g_socket_receive_message (socket, NULL, NULL, 0,
                                &scms, &nscm, NULL, cancellable, error) != 1)
152 153 154 155 156 157 158 159 160 161 162 163 164 165
    /* XXX it _could_ 'fail' with zero. */
    {
      g_object_unref (socket);

      return -1;
    }

  g_object_unref (socket);

  if (nscm != 1)
    {
      gint i;

      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
166 167 168 169
        ngettext("Expecting 1 control message, got %d",
                 "Expecting 1 control message, got %d",
                 nscm),
        nscm);
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

      for (i = 0; i < nscm; i++)
        g_object_unref (scms[i]);

      g_free (scms);

      return -1;
    }

  if (!G_IS_UNIX_FD_MESSAGE (scms[0]))
    {
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
			   _("Unexpected type of ancillary data"));
      g_object_unref (scms[0]);
      g_free (scms);

      return -1;
    }

  fdmsg = G_UNIX_FD_MESSAGE (scms[0]);
  g_free (scms);

  fds = g_unix_fd_message_steal_fds (fdmsg, &nfd);
  g_object_unref (fdmsg);

  if (nfd != 1)
    {
      gint i;

      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
200 201 202 203
                   ngettext("Expecting one fd, but got %d\n",
                            "Expecting one fd, but got %d\n",
                            nfd),
                   nfd);
204 205 206 207 208 209 210 211 212 213 214 215 216 217

      for (i = 0; i < nfd; i++)
        close (fds[i]);

      g_free (fds);

      return -1;
    }

  fd = *fds;
  g_free (fds);

  if (fd < 0)
    {
218 219
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           _("Received invalid fd"));
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
      fd = -1;
    }

  return fd;
}

static void
g_unix_connection_init (GUnixConnection *connection)
{
}

static void
g_unix_connection_class_init (GUnixConnectionClass *class)
{
}

/* TODO: Other stuff we might want to add are:
void                    g_unix_connection_send_fd_async                 (GUnixConnection      *connection,
                                                                         gint                  fd,
                                                                         gboolean              close,
                                                                         gint                  io_priority,
                                                                         GAsyncReadyCallback   callback,
                                                                         gpointer              user_data);
gboolean                g_unix_connection_send_fd_finish                (GUnixConnection      *connection,
                                                                         GError              **error);

gboolean                g_unix_connection_send_fds                      (GUnixConnection      *connection,
                                                                         gint                 *fds,
                                                                         gint                  nfds,
                                                                         GError              **error);
void                    g_unix_connection_send_fds_async                (GUnixConnection      *connection,
                                                                         gint                 *fds,
                                                                         gint                  nfds,
                                                                         gint                  io_priority,
                                                                         GAsyncReadyCallback   callback,
                                                                         gpointer              user_data);
gboolean                g_unix_connection_send_fds_finish               (GUnixConnection      *connection,
                                                                         GError              **error);

void                    g_unix_connection_receive_fd_async              (GUnixConnection      *connection,
                                                                         gint                  io_priority,
                                                                         GAsyncReadyCallback   callback,
                                                                         gpointer              user_data);
gint                    g_unix_connection_receive_fd_finish             (GUnixConnection      *connection,
                                                                         GError              **error);


gboolean                g_unix_connection_send_fake_credentials         (GUnixConnection      *connection,
                                                                         guint64               pid,
                                                                         guint64               uid,
                                                                         guint64               gid,
                                                                         GError              **error);
void                    g_unix_connection_send_fake_credentials_async   (GUnixConnection      *connection,
                                                                         guint64               pid,
                                                                         guint64               uid,
                                                                         guint64               gid,
                                                                         gint                  io_priority,
                                                                         GAsyncReadyCallback   callback,
                                                                         gpointer              user_data);
gboolean                g_unix_connection_send_fake_credentials_finish  (GUnixConnection      *connection,
                                                                         GError              **error);

gboolean                g_unix_connection_create_pair                   (GUnixConnection     **one,
                                                                         GUnixConnection     **two,
                                                                         GError              **error);
*/

David Zeuthen's avatar
David Zeuthen committed
287 288 289 290

/**
 * g_unix_connection_send_credentials:
 * @connection: A #GUnixConnection.
291
 * @cancellable: (nullable): A #GCancellable or %NULL.
David Zeuthen's avatar
David Zeuthen committed
292 293
 * @error: Return location for error or %NULL.
 *
294
 * Passes the credentials of the current user the receiving side
295
 * of the connection. The receiving end has to call
David Zeuthen's avatar
David Zeuthen committed
296 297 298 299 300 301 302
 * g_unix_connection_receive_credentials() (or similar) to accept the
 * credentials.
 *
 * As well as sending the credentials this also writes a single NUL
 * byte to the stream, as this is required for credentials passing to
 * work on some implementations.
 *
303 304 305
 * Other ways to exchange credentials with a foreign peer includes the
 * #GUnixCredentialsMessage type and g_socket_get_credentials() function.
 *
David Zeuthen's avatar
David Zeuthen committed
306 307 308 309 310 311 312 313 314
 * Returns: %TRUE on success, %FALSE if @error is set.
 *
 * Since: 2.26
 */
gboolean
g_unix_connection_send_credentials (GUnixConnection      *connection,
                                    GCancellable         *cancellable,
                                    GError              **error)
{
315
  GCredentials *credentials;
David Zeuthen's avatar
David Zeuthen committed
316 317 318 319 320
  GSocketControlMessage *scm;
  GSocket *socket;
  gboolean ret;
  GOutputVector vector;
  guchar nul_byte[1] = {'\0'};
321
  gint num_messages;
David Zeuthen's avatar
David Zeuthen committed
322 323 324 325 326 327

  g_return_val_if_fail (G_IS_UNIX_CONNECTION (connection), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  ret = FALSE;

328 329
  credentials = g_credentials_new ();

David Zeuthen's avatar
David Zeuthen committed
330 331
  vector.buffer = &nul_byte;
  vector.size = 1;
332 333 334 335 336 337 338 339 340 341 342 343

  if (g_unix_credentials_message_is_supported ())
    {
      scm = g_unix_credentials_message_new_with_credentials (credentials);
      num_messages = 1;
    }
  else
    {
      scm = NULL;
      num_messages = 0;
    }

David Zeuthen's avatar
David Zeuthen committed
344 345 346 347 348 349
  g_object_get (connection, "socket", &socket, NULL);
  if (g_socket_send_message (socket,
                             NULL, /* address */
                             &vector,
                             1,
                             &scm,
350
                             num_messages,
David Zeuthen's avatar
David Zeuthen committed
351 352 353 354 355 356 357 358 359 360 361 362
                             G_SOCKET_MSG_NONE,
                             cancellable,
                             error) != 1)
    {
      g_prefix_error (error, _("Error sending credentials: "));
      goto out;
    }

  ret = TRUE;

 out:
  g_object_unref (socket);
363 364
  if (scm != NULL)
    g_object_unref (scm);
365
  g_object_unref (credentials);
David Zeuthen's avatar
David Zeuthen committed
366 367 368
  return ret;
}

369
static void
370 371 372 373
send_credentials_async_thread (GTask         *task,
			       gpointer       source_object,
			       gpointer       task_data,
			       GCancellable  *cancellable)
374 375 376
{
  GError *error = NULL;

377 378 379 380 381 382 383
  if (g_unix_connection_send_credentials (G_UNIX_CONNECTION (source_object),
					  cancellable,
					  &error))
    g_task_return_boolean (task, TRUE);
  else
    g_task_return_error (task, error);
  g_object_unref (task);
384 385 386 387 388
}

/**
 * g_unix_connection_send_credentials_async:
 * @connection: A #GUnixConnection.
389
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
 * @user_data: (closure): the data to pass to callback function
 *
 * Asynchronously send credentials.
 *
 * For more details, see g_unix_connection_send_credentials() which is
 * the synchronous version of this call.
 *
 * When the operation is finished, @callback will be called. You can then call
 * g_unix_connection_send_credentials_finish() to get the result of the operation.
 *
 * Since: 2.32
 **/
void
g_unix_connection_send_credentials_async (GUnixConnection      *connection,
                                          GCancellable         *cancellable,
                                          GAsyncReadyCallback   callback,
                                          gpointer              user_data)
{
409
  GTask *task;
410

411
  task = g_task_new (connection, cancellable, callback, user_data);
412
  g_task_set_source_tag (task, g_unix_connection_send_credentials_async);
413
  g_task_run_in_thread (task, send_credentials_async_thread);
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
}

/**
 * g_unix_connection_send_credentials_finish:
 * @connection: A #GUnixConnection.
 * @result: a #GAsyncResult.
 * @error: a #GError, or %NULL
 *
 * Finishes an asynchronous send credentials operation started with
 * g_unix_connection_send_credentials_async().
 *
 * Returns: %TRUE if the operation was successful, otherwise %FALSE.
 *
 * Since: 2.32
 **/
gboolean
g_unix_connection_send_credentials_finish (GUnixConnection *connection,
                                           GAsyncResult    *result,
                                           GError         **error)
{
434
  g_return_val_if_fail (g_task_is_valid (result, connection), FALSE);
435

436
  return g_task_propagate_boolean (G_TASK (result), error);
437 438
}

David Zeuthen's avatar
David Zeuthen committed
439 440 441
/**
 * g_unix_connection_receive_credentials:
 * @connection: A #GUnixConnection.
442
 * @cancellable: (nullable): A #GCancellable or %NULL.
David Zeuthen's avatar
David Zeuthen committed
443 444 445 446 447 448 449 450 451 452
 * @error: Return location for error or %NULL.
 *
 * Receives credentials from the sending end of the connection.  The
 * sending end has to call g_unix_connection_send_credentials() (or
 * similar) for this to work.
 *
 * As well as reading the credentials this also reads (and discards) a
 * single byte from the stream, as this is required for credentials
 * passing to work on some implementations.
 *
453 454 455
 * Other ways to exchange credentials with a foreign peer includes the
 * #GUnixCredentialsMessage type and g_socket_get_credentials() function.
 *
456
 * Returns: (transfer full): Received credentials on success (free with
David Zeuthen's avatar
David Zeuthen committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
 * g_object_unref()), %NULL if @error is set.
 *
 * Since: 2.26
 */
GCredentials *
g_unix_connection_receive_credentials (GUnixConnection      *connection,
                                       GCancellable         *cancellable,
                                       GError              **error)
{
  GCredentials *ret;
  GSocketControlMessage **scms;
  gint nscm;
  GSocket *socket;
  gint n;
  gssize num_bytes_read;
#ifdef __linux__
  gboolean turn_off_so_passcreds;
#endif

  g_return_val_if_fail (G_IS_UNIX_CONNECTION (connection), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  ret = NULL;
  scms = NULL;

  g_object_get (connection, "socket", &socket, NULL);

  /* On Linux, we need to turn on SO_PASSCRED if it isn't enabled
   * already. We also need to turn it off when we're done.  See
   * #617483 for more discussion.
   */
#ifdef __linux__
  {
    gint opt_val;

    turn_off_so_passcreds = FALSE;
    opt_val = 0;
494 495 496 497 498
    if (!g_socket_get_option (socket,
			      SOL_SOCKET,
			      SO_PASSCRED,
			      &opt_val,
			      NULL))
David Zeuthen's avatar
David Zeuthen committed
499
      {
500
        int errsv = errno;
David Zeuthen's avatar
David Zeuthen committed
501 502
        g_set_error (error,
                     G_IO_ERROR,
503
                     g_io_error_from_errno (errsv),
David Zeuthen's avatar
David Zeuthen committed
504
                     _("Error checking if SO_PASSCRED is enabled for socket: %s"),
505
                     g_strerror (errsv));
David Zeuthen's avatar
David Zeuthen committed
506 507 508 509
        goto out;
      }
    if (opt_val == 0)
      {
510 511 512 513 514
        if (!g_socket_set_option (socket,
				  SOL_SOCKET,
				  SO_PASSCRED,
				  TRUE,
				  NULL))
David Zeuthen's avatar
David Zeuthen committed
515
          {
516
            int errsv = errno;
David Zeuthen's avatar
David Zeuthen committed
517 518
            g_set_error (error,
                         G_IO_ERROR,
519
                         g_io_error_from_errno (errsv),
David Zeuthen's avatar
David Zeuthen committed
520
                         _("Error enabling SO_PASSCRED: %s"),
521
                         g_strerror (errsv));
David Zeuthen's avatar
David Zeuthen committed
522 523 524 525 526 527 528
            goto out;
          }
        turn_off_so_passcreds = TRUE;
      }
  }
#endif

529
  g_type_ensure (G_TYPE_UNIX_CREDENTIALS_MESSAGE);
David Zeuthen's avatar
David Zeuthen committed
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
  num_bytes_read = g_socket_receive_message (socket,
                                             NULL, /* GSocketAddress **address */
                                             NULL,
                                             0,
                                             &scms,
                                             &nscm,
                                             NULL,
                                             cancellable,
                                             error);
  if (num_bytes_read != 1)
    {
      /* Handle situation where g_socket_receive_message() returns
       * 0 bytes and not setting @error
       */
      if (num_bytes_read == 0 && error != NULL && *error == NULL)
        {
          g_set_error_literal (error,
                               G_IO_ERROR,
                               G_IO_ERROR_FAILED,
                               _("Expecting to read a single byte for receiving credentials but read zero bytes"));
        }
      goto out;
    }

554 555 556
  if (g_unix_credentials_message_is_supported () &&
      /* Fall back on get_credentials if the other side didn't send the credentials */
      nscm > 0)
David Zeuthen's avatar
David Zeuthen committed
557
    {
558 559 560 561 562
      if (nscm != 1)
        {
          g_set_error (error,
                       G_IO_ERROR,
                       G_IO_ERROR_FAILED,
563 564 565
                       ngettext("Expecting 1 control message, got %d",
                                "Expecting 1 control message, got %d",
                                nscm),
566 567 568 569 570 571 572 573 574 575 576 577
                       nscm);
          goto out;
        }

      if (!G_IS_UNIX_CREDENTIALS_MESSAGE (scms[0]))
        {
          g_set_error_literal (error,
                               G_IO_ERROR,
                               G_IO_ERROR_FAILED,
                               _("Unexpected type of ancillary data"));
          goto out;
        }
David Zeuthen's avatar
David Zeuthen committed
578

579 580 581 582
      ret = g_unix_credentials_message_get_credentials (G_UNIX_CREDENTIALS_MESSAGE (scms[0]));
      g_object_ref (ret);
    }
  else
David Zeuthen's avatar
David Zeuthen committed
583
    {
584 585 586 587 588 589 590 591 592 593 594 595 596
      if (nscm != 0)
        {
          g_set_error (error,
                       G_IO_ERROR,
                       G_IO_ERROR_FAILED,
                       _("Not expecting control message, but got %d"),
                       nscm);
          goto out;
        }
      else
        {
          ret = g_socket_get_credentials (socket, error);
        }
David Zeuthen's avatar
David Zeuthen committed
597 598 599 600 601 602 603
    }

 out:

#ifdef __linux__
  if (turn_off_so_passcreds)
    {
604 605 606 607 608
      if (!g_socket_set_option (socket,
				SOL_SOCKET,
				SO_PASSCRED,
				FALSE,
				NULL))
David Zeuthen's avatar
David Zeuthen committed
609
        {
610
          int errsv = errno;
David Zeuthen's avatar
David Zeuthen committed
611 612
          g_set_error (error,
                       G_IO_ERROR,
613
                       g_io_error_from_errno (errsv),
David Zeuthen's avatar
David Zeuthen committed
614
                       _("Error while disabling SO_PASSCRED: %s"),
615
                       g_strerror (errsv));
David Zeuthen's avatar
David Zeuthen committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629
          goto out;
        }
    }
#endif

  if (scms != NULL)
    {
      for (n = 0; n < nscm; n++)
        g_object_unref (scms[n]);
      g_free (scms);
    }
  g_object_unref (socket);
  return ret;
}
630 631

static void
632 633 634 635
receive_credentials_async_thread (GTask         *task,
				  gpointer       source_object,
				  gpointer       task_data,
				  GCancellable  *cancellable)
636 637 638 639
{
  GCredentials *creds;
  GError *error = NULL;

640
  creds = g_unix_connection_receive_credentials (G_UNIX_CONNECTION (source_object),
641 642
                                                 cancellable,
                                                 &error);
643 644
  if (creds)
    g_task_return_pointer (task, creds, g_object_unref);
645
  else
646 647
    g_task_return_error (task, error);
  g_object_unref (task);
648 649 650 651 652
}

/**
 * g_unix_connection_receive_credentials_async:
 * @connection: A #GUnixConnection.
653
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
 * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
 * @user_data: (closure): the data to pass to callback function
 *
 * Asynchronously receive credentials.
 *
 * For more details, see g_unix_connection_receive_credentials() which is
 * the synchronous version of this call.
 *
 * When the operation is finished, @callback will be called. You can then call
 * g_unix_connection_receive_credentials_finish() to get the result of the operation.
 *
 * Since: 2.32
 **/
void
g_unix_connection_receive_credentials_async (GUnixConnection      *connection,
                                              GCancellable         *cancellable,
                                              GAsyncReadyCallback   callback,
                                              gpointer              user_data)
{
673
  GTask *task;
674

675
  task = g_task_new (connection, cancellable, callback, user_data);
676
  g_task_set_source_tag (task, g_unix_connection_receive_credentials_async);
677
  g_task_run_in_thread (task, receive_credentials_async_thread);
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
}

/**
 * g_unix_connection_receive_credentials_finish:
 * @connection: A #GUnixConnection.
 * @result: a #GAsyncResult.
 * @error: a #GError, or %NULL
 *
 * Finishes an asynchronous receive credentials operation started with
 * g_unix_connection_receive_credentials_async().
 *
 * Returns: (transfer full): a #GCredentials, or %NULL on error.
 *     Free the returned object with g_object_unref().
 *
 * Since: 2.32
 **/
GCredentials *
g_unix_connection_receive_credentials_finish (GUnixConnection *connection,
                                              GAsyncResult    *result,
                                              GError         **error)
{
699 700 701
  g_return_val_if_fail (g_task_is_valid (result, connection), NULL);

  return g_task_propagate_pointer (G_TASK (result), error);
702
}