openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/dbus/1.12.16-r0/dbus-1.12.16/bus/driver.c
static dbus_bool_t bus_driver_check_caller_is_privileged(
    DBusConnection* connection, BusTransaction* transaction,
    DBusMessage* message, DBusError* error)
{
#ifdef DBUS_UNIX
    unsigned long uid;

    if (!dbus_connection_get_unix_user(connection, &uid))
    {
        const char* method = dbus_message_get_member(message);

        bus_context_log_and_set_error(
            bus_transaction_get_context(transaction), DBUS_SYSTEM_LOG_SECURITY,
            error, DBUS_ERROR_ACCESS_DENIED,
            "rejected attempt to call %s by connection %s (%s) with "
            "unknown uid",
            method, nonnull(bus_connection_get_name(connection), "(inactive)"),
            bus_connection_get_loginfo(connection));
        return FALSE;
    }

    /* I'm writing it in this slightly strange form so that it's more
     * obvious that this security-sensitive code is correct.
     */
    if (_dbus_unix_user_is_process_owner(uid))
    {
        /* OK */
    }
    else if (uid == 0)
    {
        /* OK */
    }
    else
    {
        const char* method = dbus_message_get_member(message);

        bus_context_log_and_set_error(
            bus_transaction_get_context(transaction), DBUS_SYSTEM_LOG_SECURITY,
            error, DBUS_ERROR_ACCESS_DENIED,
            "rejected attempt to call %s by connection %s (%s) with "
            "uid %lu",
            method, nonnull(bus_connection_get_name(connection), "(inactive)"),
            bus_connection_get_loginfo(connection), uid);
        return FALSE;
    }

    return TRUE;
#elif defined(DBUS_WIN)
    char* windows_sid = NULL;
    dbus_bool_t ret = FALSE;

    if (!dbus_connection_get_windows_user(connection, &windows_sid))
    {
        const char* method = dbus_message_get_member(message);

        bus_context_log_and_set_error(
            bus_transaction_get_context(transaction), DBUS_SYSTEM_LOG_SECURITY,
            error, DBUS_ERROR_ACCESS_DENIED,
            "rejected attempt to call %s by unknown uid", method);
        goto out;
    }

    if (!_dbus_windows_user_is_process_owner(windows_sid))
    {
        const char* method = dbus_message_get_member(message);

        bus_context_log_and_set_error(
            bus_transaction_get_context(transaction), DBUS_SYSTEM_LOG_SECURITY,
            error, DBUS_ERROR_ACCESS_DENIED,
            "rejected attempt to call %s by uid %s", method, windows_sid);
        goto out;
    }

    ret = TRUE;
out:
    dbus_free(windows_sid);
    return ret;
#else
    /* make sure we fail closed in the hypothetical case that we are neither
     * Unix nor Windows */
    dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED,
                   "please teach bus/driver.c how uids work on this platform");
    return FALSE;
#endif
}
/*
 * Log a security warning and set error unless the uid of the connection
 * is either the uid of this process, or on Unix, uid 0 (root).
 *
 * This is intended to be a second line of defence after <deny> rules,
 * to mitigate incorrect system bus security policy configuration files
 * like the ones in CVE-2014-8148 and CVE-2014-8156, and (if present)
 * LSM rules; so it doesn't need to be perfect, but as long as we have
 * potentially dangerous functionality in the system bus, it does need
 * to exist.
 */
Log a security warning and set error unless the uid of the connection
is either the uid of this process, or on Unix, uid 0 (root).

This is intended to be a second line of defence after  rules,
to mitigate incorrect system bus security policy configuration files
like the ones in CVE-2014-8148 and CVE-2014-8156, and (if present)
LSM rules; so it doesn't need to be perfect, but as long as we have
potentially dangerous functionality in the system bus, it does need
to exist.
Log a security warning and set error unless the uid of the connection is either the uid of this process or on Unix uid 0 ( root ) . This is intended to be a second line of defence after rules to mitigate incorrect system bus security policy configuration files like the ones in CVE - 2014 - 8148 and CVE - 2014 - 8156 and ( if present ) LSM rules ; so it doesn ' t need to be perfect but as long as we have potentially dangerous functionality in the system bus it does need to exist .
static dbus_bool_t bus_driver_check_caller_is_privileged(
    DBusConnection* connection, BusTransaction* transaction,
    DBusMessage* message, DBusError* error)
{
#ifdef DBUS_UNIX
    unsigned long uid;
    if (!dbus_connection_get_unix_user(connection, &uid))
    {
        const char* method = dbus_message_get_member(message);
        bus_context_log_and_set_error(
            bus_transaction_get_context(transaction), DBUS_SYSTEM_LOG_SECURITY,
            error, DBUS_ERROR_ACCESS_DENIED,
            "rejected attempt to call %s by connection %s (%s) with "
            "unknown uid",
            method, nonnull(bus_connection_get_name(connection), "(inactive)"),
            bus_connection_get_loginfo(connection));
        return FALSE;
    }
    if (_dbus_unix_user_is_process_owner(uid))
    {
    }
    else if (uid == 0)
    {
    }
    else
    {
        const char* method = dbus_message_get_member(message);
        bus_context_log_and_set_error(
            bus_transaction_get_context(transaction), DBUS_SYSTEM_LOG_SECURITY,
            error, DBUS_ERROR_ACCESS_DENIED,
            "rejected attempt to call %s by connection %s (%s) with "
            "uid %lu",
            method, nonnull(bus_connection_get_name(connection), "(inactive)"),
            bus_connection_get_loginfo(connection), uid);
        return FALSE;
    }
    return TRUE;
#elif defined(DBUS_WIN)
    char* windows_sid = NULL;
    dbus_bool_t ret = FALSE;
    if (!dbus_connection_get_windows_user(connection, &windows_sid))
    {
        const char* method = dbus_message_get_member(message);
        bus_context_log_and_set_error(
            bus_transaction_get_context(transaction), DBUS_SYSTEM_LOG_SECURITY,
            error, DBUS_ERROR_ACCESS_DENIED,
            "rejected attempt to call %s by unknown uid", method);
        goto out;
    }
    if (!_dbus_windows_user_is_process_owner(windows_sid))
    {
        const char* method = dbus_message_get_member(message);
        bus_context_log_and_set_error(
            bus_transaction_get_context(transaction), DBUS_SYSTEM_LOG_SECURITY,
            error, DBUS_ERROR_ACCESS_DENIED,
            "rejected attempt to call %s by uid %s", method, windows_sid);
        goto out;
    }
    ret = TRUE;
out:
    dbus_free(windows_sid);
    return ret;
#else
    dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED,
                   "please teach bus/driver.c how uids work on this platform");
    return FALSE;
#endif
}
static dbus_bool_t bus_driver_check_caller_is_privileged ( DBusConnection * connection , BusTransaction * transaction , DBusMessage * message , DBusError * error ) { #ifdef DBUS_UNIX unsigned long uid ; if ( ! dbus_connection_get_unix_user ( connection , & uid ) ) { const char * method = dbus_message_get_member ( message ) ; bus_context_log_and_set_error ( bus_transaction_get_context ( transaction ) , DBUS_SYSTEM_LOG_SECURITY , error , DBUS_ERROR_ACCESS_DENIED , " " " " , method , nonnull ( bus_connection_get_name ( connection ) , " " ) , bus_connection_get_loginfo ( connection ) ) ; return FALSE ; } if ( _dbus_unix_user_is_process_owner ( uid ) ) { } else if ( uid == 0 ) { } else { const char * method = dbus_message_get_member ( message ) ; bus_context_log_and_set_error ( bus_transaction_get_context ( transaction ) , DBUS_SYSTEM_LOG_SECURITY , error , DBUS_ERROR_ACCESS_DENIED , " " " " , method , nonnull ( bus_connection_get_name ( connection ) , " " ) , bus_connection_get_loginfo ( connection ) , uid ) ; return FALSE ; } return TRUE ; #elif defined ( DBUS_WIN ) char * windows_sid = NULL ; dbus_bool_t ret = FALSE ; if ( ! dbus_connection_get_windows_user ( connection , & windows_sid ) ) { const char * method = dbus_message_get_member ( message ) ; bus_context_log_and_set_error ( bus_transaction_get_context ( transaction ) , DBUS_SYSTEM_LOG_SECURITY , error , DBUS_ERROR_ACCESS_DENIED , " " , method ) ; goto out ; } if ( ! _dbus_windows_user_is_process_owner ( windows_sid ) ) { const char * method = dbus_message_get_member ( message ) ; bus_context_log_and_set_error ( bus_transaction_get_context ( transaction ) , DBUS_SYSTEM_LOG_SECURITY , error , DBUS_ERROR_ACCESS_DENIED , " " , method , windows_sid ) ; goto out ; } ret = TRUE ; out : dbus_free ( windows_sid ) ; return ret ; #else dbus_set_error ( error , DBUS_ERROR_ACCESS_DENIED , " " ) ; return FALSE ; #endif }
Log a security warning and set error unless the uid of the connection
 is either the uid of this process, or on Unix, uid 0 (root).
Log a security warning and set error unless the uid of the connection is either the uid of this process or on Unix uid 0 ( root ) .
/* I'm writing it in this slightly strange form so that it's more
     * obvious that this security-sensitive code is correct.
     */ /* OK */ /* OK */ /* make sure we fail closed in the hypothetical case that we are neither
     * Unix nor Windows */