コード例 #1
0
static GSocketControlMessage *
g_unix_credentials_message_deserialize (gint     level,
                                        gint     type,
                                        gsize    size,
                                        gpointer data)
{
  GSocketControlMessage *message;

  message = NULL;

#ifdef __linux__
  {
    GCredentials *credentials;
    struct ucred *ucred;

    if (level != SOL_SOCKET || type != SCM_CREDENTIALS)
      goto out;

    if (size != sizeof (struct ucred))
      {
        g_warning ("Expected a struct ucred (%" G_GSIZE_FORMAT " bytes) but "
                   "got %" G_GSIZE_FORMAT " bytes of data",
                   sizeof (struct ucred),
                   size);
        goto out;
      }

    ucred = data;

    credentials = g_credentials_new ();
    g_credentials_set_native (credentials, ucred);
    message = g_unix_credentials_message_new_with_credentials (credentials);
    g_object_unref (credentials);
 out:
    ;
  }
#endif

  return message;
}
コード例 #2
0
static GSocketControlMessage *
g_unix_credentials_message_deserialize (gint     level,
                                        gint     type,
                                        gsize    size,
                                        gpointer data)
{
    GSocketControlMessage *message;

    message = NULL;

#ifdef __linux__
    {
        GCredentials *credentials;
        struct ucred *ucred;

        if (level != SOL_SOCKET || type != SCM_CREDENTIALS)
            goto out;

        if (size != sizeof (struct ucred))
        {
            g_warning ("Expected a struct ucred (%" G_GSIZE_FORMAT " bytes) but "
                       "got %" G_GSIZE_FORMAT " bytes of data",
                       sizeof (struct ucred),
                       size);
            goto out;
        }

        ucred = data;

        if (ucred->uid == (uid_t)-1 &&
                ucred->gid == (gid_t)-1)
        {
            /* This happens if the remote side didn't pass the credentials */
            goto out;
        }

        credentials = g_credentials_new ();
        g_credentials_set_native (credentials, G_CREDENTIALS_TYPE_LINUX_UCRED, ucred);
        message = g_unix_credentials_message_new_with_credentials (credentials);
        g_object_unref (credentials);
out:
        ;
    }
#elif defined(__FreeBSD__)
    {
        GCredentials *credentials;
        struct cmsgcred *cred;

        if (level != SOL_SOCKET || type != SCM_CREDS)
        {
            goto out;
        }
        if (size < sizeof *cred)
        {
            g_warning ("Expected a struct cmsgcred (%" G_GSIZE_FORMAT " bytes) but "
                       "got %" G_GSIZE_FORMAT " bytes of data",
                       CMSG_LEN (sizeof *cred),
                       size);
            goto out;
        }

        cred = data;

        credentials = g_credentials_new ();
        g_credentials_set_native (credentials, G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED, cred);
        message = g_unix_credentials_message_new_with_credentials (credentials);
        g_object_unref (credentials);
out:
        ;
    }
#endif

    return message;
}