Back to index

lightdm  1.3.2
Classes | Defines | Typedefs | Enumerations | Functions
xauthority.h File Reference
#include <glib-object.h>
#include <gio/gio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  XAuthority
struct  XAuthorityClass

Defines

#define XAUTHORITY_TYPE   (xauth_get_type())
#define XAUTHORITY(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), XAUTHORITY_TYPE, XAuthority));
#define XAUTH_FAMILY_INTERNET   0
#define XAUTH_FAMILY_DECNET   1
#define XAUTH_FAMILY_CHAOS   2
#define XAUTH_FAMILY_SERVER_INTERPRETED   5
#define XAUTH_FAMILY_INTERNET6   6
#define XAUTH_FAMILY_LOCALHOST   252
#define XAUTH_FAMILY_KRB5_PRINCIPAL   253
#define XAUTH_FAMILY_NETNAME   254
#define XAUTH_FAMILY_LOCAL   256
#define XAUTH_FAMILY_WILD   65535

Typedefs

typedef struct XAuthorityPrivate

Enumerations

enum  XAuthWriteMode { XAUTH_WRITE_MODE_REPLACE, XAUTH_WRITE_MODE_REMOVE, XAUTH_WRITE_MODE_SET }

Functions

GType xauth_get_type (void)
XAuthorityxauth_new (guint16 family, const guint8 *address, gsize address_length, const gchar *number, const gchar *name, const guint8 *data, gsize data_length)
XAuthorityxauth_new_cookie (guint16 family, const guint8 *address, gsize address_length, const gchar *number)
void xauth_set_family (XAuthority *auth, guint16 family)
guint16 xauth_get_family (XAuthority *auth)
void xauth_set_address (XAuthority *auth, const guint8 *address, gsize address_length)
const guint8 * xauth_get_address (XAuthority *auth)
const gsize xauth_get_address_length (XAuthority *auth)
void xauth_set_number (XAuthority *auth, const gchar *number)
const gchar * xauth_get_number (XAuthority *auth)
void xauth_set_authorization_name (XAuthority *auth, const gchar *name)
const gchar * xauth_get_authorization_name (XAuthority *auth)
void xauth_set_authorization_data (XAuthority *auth, const guint8 *data, gsize data_length)
const guint8 * xauth_get_authorization_data (XAuthority *auth)
guint8 * xauth_copy_authorization_data (XAuthority *auth)
gsize xauth_get_authorization_data_length (XAuthority *auth)
gboolean xauth_write (XAuthority *auth, XAuthWriteMode mode, GFile *file, GError **error)

Class Documentation

struct XAuthority

Definition at line 25 of file xauthority.h.

Collaboration diagram for XAuthority:
Class Members
GObject parent_instance
GObjectClass parent_instance
XAuthorityPrivate * priv
struct XAuthorityClass

Definition at line 31 of file xauthority.h.

Class Members
GObjectClass parent_class

Define Documentation

#define XAUTH_FAMILY_CHAOS   2

Definition at line 38 of file xauthority.h.

#define XAUTH_FAMILY_DECNET   1

Definition at line 37 of file xauthority.h.

#define XAUTH_FAMILY_INTERNET   0

Definition at line 36 of file xauthority.h.

#define XAUTH_FAMILY_INTERNET6   6

Definition at line 40 of file xauthority.h.

#define XAUTH_FAMILY_KRB5_PRINCIPAL   253

Definition at line 42 of file xauthority.h.

#define XAUTH_FAMILY_LOCAL   256

Definition at line 44 of file xauthority.h.

#define XAUTH_FAMILY_LOCALHOST   252

Definition at line 41 of file xauthority.h.

#define XAUTH_FAMILY_NETNAME   254

Definition at line 43 of file xauthority.h.

Definition at line 39 of file xauthority.h.

#define XAUTH_FAMILY_WILD   65535

Definition at line 45 of file xauthority.h.

#define XAUTHORITY (   obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), XAUTHORITY_TYPE, XAuthority));

Definition at line 21 of file xauthority.h.

#define XAUTHORITY_TYPE   (xauth_get_type())

Definition at line 20 of file xauthority.h.


Typedef Documentation

typedef struct XAuthorityPrivate

Definition at line 23 of file xauthority.h.


Enumeration Type Documentation

Enumerator:
XAUTH_WRITE_MODE_REPLACE 
XAUTH_WRITE_MODE_REMOVE 
XAUTH_WRITE_MODE_SET 

Definition at line 47 of file xauthority.h.


Function Documentation

Definition at line 153 of file xauthority.c.

{
    guint8 *data;

    g_return_val_if_fail (auth != NULL, NULL);

    data = g_malloc (auth->priv->authorization_data_length);
    memcpy (data, auth->priv->authorization_data, auth->priv->authorization_data_length);
    return data;
}

Here is the caller graph for this function:

const guint8* xauth_get_address ( XAuthority auth)

Definition at line 92 of file xauthority.c.

{
    g_return_val_if_fail (auth != NULL, NULL);
    return auth->priv->address;
}

Here is the caller graph for this function:

const gsize xauth_get_address_length ( XAuthority auth)

Definition at line 99 of file xauthority.c.

{
    g_return_val_if_fail (auth != NULL, 0);
    return auth->priv->address_length;
}

Here is the caller graph for this function:

const guint8* xauth_get_authorization_data ( XAuthority auth)

Definition at line 146 of file xauthority.c.

{
    g_return_val_if_fail (auth != NULL, NULL);
    return auth->priv->authorization_data;
}

Here is the caller graph for this function:

Definition at line 165 of file xauthority.c.

{
    g_return_val_if_fail (auth != NULL, 0);
    return auth->priv->authorization_data_length;
}

Here is the caller graph for this function:

const gchar* xauth_get_authorization_name ( XAuthority auth)

Definition at line 129 of file xauthority.c.

{
    g_return_val_if_fail (auth != NULL, NULL);
    return auth->priv->authorization_name;
}

Here is the caller graph for this function:

guint16 xauth_get_family ( XAuthority auth)

Definition at line 75 of file xauthority.c.

{
    g_return_val_if_fail (auth != NULL, 0);
    return auth->priv->family;
}

Here is the caller graph for this function:

const gchar* xauth_get_number ( XAuthority auth)

Definition at line 114 of file xauthority.c.

{
    g_return_val_if_fail (auth != NULL, NULL);
    return auth->priv->number;
}

Here is the caller graph for this function:

GType xauth_get_type ( void  )
XAuthority* xauth_new ( guint16  family,
const guint8 *  address,
gsize  address_length,
const gchar *  number,
const gchar *  name,
const guint8 *  data,
gsize  data_length 
)

Definition at line 42 of file xauthority.c.

{
    XAuthority *auth = g_object_new (XAUTHORITY_TYPE, NULL);

    xauth_set_family (auth, family);  
    xauth_set_address (auth, address, address_length);
    xauth_set_number (auth, number);
    xauth_set_authorization_name (auth, name);
    xauth_set_authorization_data (auth, data, data_length);

    return auth;
}

Here is the call graph for this function:

Here is the caller graph for this function:

XAuthority* xauth_new_cookie ( guint16  family,
const guint8 *  address,
gsize  address_length,
const gchar *  number 
)

Definition at line 56 of file xauthority.c.

{
    guint8 cookie[16];
    gint i;
  
    for (i = 0; i < 16; i++)
        cookie[i] = g_random_int () & 0xFF;

    return xauth_new (family, address, address_length, number, "MIT-MAGIC-COOKIE-1", cookie, 16);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xauth_set_address ( XAuthority auth,
const guint8 *  address,
gsize  address_length 
)

Definition at line 82 of file xauthority.c.

{
    g_return_if_fail (auth != NULL);
    g_free (auth->priv->address);
    auth->priv->address = g_malloc (address_length);
    memcpy (auth->priv->address, address, address_length);
    auth->priv->address_length = address_length;
}

Here is the caller graph for this function:

void xauth_set_authorization_data ( XAuthority auth,
const guint8 *  data,
gsize  data_length 
)

Definition at line 136 of file xauthority.c.

{
    g_return_if_fail (auth != NULL);
    g_free (auth->priv->authorization_data);
    auth->priv->authorization_data = g_malloc (data_length);
    memcpy (auth->priv->authorization_data, data, data_length);
    auth->priv->authorization_data_length = data_length;
}

Here is the caller graph for this function:

void xauth_set_authorization_name ( XAuthority auth,
const gchar *  name 
)

Definition at line 121 of file xauthority.c.

{
    g_return_if_fail (auth != NULL);
    g_free (auth->priv->authorization_name);
    auth->priv->authorization_name = g_strdup (name);
}

Here is the caller graph for this function:

void xauth_set_family ( XAuthority auth,
guint16  family 
)

Definition at line 68 of file xauthority.c.

{
    g_return_if_fail (auth != NULL);
    auth->priv->family = family;
}

Here is the caller graph for this function:

void xauth_set_number ( XAuthority auth,
const gchar *  number 
)

Definition at line 106 of file xauthority.c.

{
    g_return_if_fail (auth != NULL);
    g_free (auth->priv->number);
    auth->priv->number = g_strdup (number);
}

Here is the caller graph for this function:

gboolean xauth_write ( XAuthority auth,
XAuthWriteMode  mode,
GFile *  file,
GError **  error 
)

Definition at line 240 of file xauthority.c.

{
    GList *link, *records = NULL;
    GFileInputStream *input_stream = NULL;
    GFileOutputStream *output_stream;
    XAuthority *a;
    gboolean result;
    gboolean matched = FALSE;

    g_return_val_if_fail (auth != NULL, FALSE);
    g_return_val_if_fail (file != NULL, FALSE);

    /* Read out existing records */
    if (mode != XAUTH_WRITE_MODE_SET)
    {
        GError *read_error = NULL;

        input_stream = g_file_read (file, NULL, &read_error);
        if (read_error && !g_error_matches (read_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
            g_warning ("Error reading existing Xauthority: %s", read_error->message);
        g_clear_error (&read_error);
    }
    while (input_stream)
    {
        gboolean eof = FALSE, address_matches = FALSE;
        guint16 address_length = 0;
        guint16 authorization_data_length = 0;
        GError *read_error = NULL;

        a = g_object_new (XAUTHORITY_TYPE, NULL);

        result = read_uint16 (G_INPUT_STREAM (input_stream), &a->priv->family, &eof, &read_error) &&
                 read_uint16 (G_INPUT_STREAM (input_stream), &address_length, NULL, &read_error) &&
                 read_data (G_INPUT_STREAM (input_stream), address_length, &a->priv->address, &read_error) &&
                 read_string (G_INPUT_STREAM (input_stream), &a->priv->number, &read_error) &&
                 read_string (G_INPUT_STREAM (input_stream), &a->priv->authorization_name, &read_error) &&
                 read_uint16 (G_INPUT_STREAM (input_stream), &authorization_data_length, NULL, &read_error) &&
                 read_data (G_INPUT_STREAM (input_stream), authorization_data_length, &a->priv->authorization_data, &read_error);
        a->priv->address_length = address_length;
        a->priv->authorization_data_length = authorization_data_length;
        if (read_error)
            g_warning ("Error reading X authority %s: %s", g_file_get_path (file), read_error->message);
        g_clear_error (&read_error);

        if (eof || !result)
        {
            g_object_unref (a);
            break;
        }

        if (auth->priv->address_length == a->priv->address_length)
        {
            guint16 i;
            for (i = 0; i < auth->priv->address_length && auth->priv->address[i] == a->priv->address[i]; i++);
            address_matches = i == auth->priv->address_length;
        }

        /* If this record matches, then update or delete it */
        if (!matched &&
            auth->priv->family == a->priv->family &&
            address_matches &&
            strcmp (auth->priv->number, a->priv->number) == 0)
        {
            matched = TRUE;
            if (mode == XAUTH_WRITE_MODE_REMOVE)
            {
                g_object_unref (a);
                continue;
            }
            else
                xauth_set_authorization_data (a, auth->priv->authorization_data, auth->priv->authorization_data_length);
        }

        records = g_list_append (records, a);
    }
    if (input_stream)
    {
        GError *close_error = NULL;
        g_input_stream_close (G_INPUT_STREAM (input_stream), NULL, &close_error);
        if (close_error)
            g_warning ("Error closing Xauthority: %s", close_error->message);
        g_clear_error (&close_error);
        g_object_unref (input_stream);
    }

    /* If didn't exist, then add a new one */
    if (!matched)
        records = g_list_append (records, g_object_ref (auth));

    output_stream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_PRIVATE, NULL, error);
    if (!output_stream)
        return FALSE;

    /* Workaround because g_file_replace () generates a file does not exist error even though it can replace it */
    g_clear_error (error);

    /* Write records back */
    result = TRUE;
    for (link = records; link && result; link = link->next)
    {
        XAuthority *a = link->data;

        result = write_uint16 (G_OUTPUT_STREAM (output_stream), a->priv->family, error) &&
                 write_uint16 (G_OUTPUT_STREAM (output_stream), a->priv->address_length, error) &&
                 write_data (G_OUTPUT_STREAM (output_stream), a->priv->address, a->priv->address_length, error) &&
                 write_string (G_OUTPUT_STREAM (output_stream), a->priv->number, error) &&
                 write_string (G_OUTPUT_STREAM (output_stream), a->priv->authorization_name, error) &&
                 write_uint16 (G_OUTPUT_STREAM (output_stream), a->priv->authorization_data_length, error) &&
                 write_data (G_OUTPUT_STREAM (output_stream), a->priv->authorization_data, a->priv->authorization_data_length, error);

        g_object_unref (a);
    }
    g_list_free (records);

    if (result)
        result = g_output_stream_close (G_OUTPUT_STREAM (output_stream), NULL, error);
    g_object_unref (output_stream);

    return result;
}    

Here is the call graph for this function:

Here is the caller graph for this function: