Example #1
0
/**
 * reads data from a file descriptor and checks if the received data matches
 * the data in the given noncefile.
 *
 * @param fd the file descriptor to read the nonce from
 * @param noncefile the nonce file to check the received data against
 * @param error error details on fail
 * @return TRUE iff a nonce could be successfully read from the file descriptor
 * and matches the nonce from the given nonce file
 */
dbus_bool_t
_dbus_noncefile_check_nonce (int fd,
                             const DBusNonceFile *noncefile,
                             DBusError* error)
{
    return do_check_nonce (fd, _dbus_noncefile_get_path (noncefile), error);
}
Example #2
0
DBusSocket
_dbus_accept_with_noncefile (DBusSocket listen_fd, const DBusNonceFile *noncefile)
{
  DBusSocket fd = _dbus_socket_get_invalid ();
  DBusString nonce;

  _dbus_assert (noncefile != NULL);

  /* Make it valid to "free" this even if _dbus_string_init() runs
   * out of memory: see comment in do_check_nonce() */
  _dbus_string_init_const (&nonce, "");

  if (!_dbus_string_init (&nonce))
    goto out;

  //PENDING(kdab): set better errors
  if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce, NULL) != TRUE)
    goto out;

  fd = _dbus_accept (listen_fd);

  if (!_dbus_socket_is_valid (fd))
    goto out;

  if (do_check_nonce(fd, &nonce, NULL) != TRUE) {
    _dbus_verbose ("nonce check failed. Closing socket.\n");
    _dbus_close_socket(fd, NULL);
    _dbus_socket_invalidate (&fd);
    goto out;
  }

out:
  _dbus_string_free (&nonce);
  return fd;
}
Example #3
0
int
_dbus_accept_with_noncefile (int listen_fd, const DBusNonceFile *noncefile)
{
  int fd;
  DBusString nonce;

  _dbus_assert (noncefile != NULL);
  if (!_dbus_string_init (&nonce))
    return -1;
  //PENDING(kdab): set better errors
  if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce, NULL) != TRUE)
    return -1;
  fd = _dbus_accept (listen_fd);
  if (_dbus_socket_is_invalid (fd))
    return fd;
  if (do_check_nonce(fd, &nonce, NULL) != TRUE) {
    _dbus_verbose ("nonce check failed. Closing socket.\n");
    _dbus_close_socket(fd, NULL);
    return -1;
  }

  return fd;
}