[134] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
| 2 | * |
---|
| 3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 8 | * (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 18 | * |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include "config.h" |
---|
| 22 | |
---|
| 23 | #include <stdlib.h> |
---|
| 24 | #include <stdio.h> |
---|
| 25 | #include <fcntl.h> |
---|
| 26 | #include <unistd.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | #include <signal.h> |
---|
| 29 | #include <sys/stat.h> |
---|
| 30 | #include <sys/types.h> |
---|
| 31 | #include <sys/socket.h> |
---|
| 32 | #include <errno.h> |
---|
| 33 | |
---|
| 34 | #include <glib.h> |
---|
| 35 | #include <glib/gi18n.h> |
---|
| 36 | #include <glib-object.h> |
---|
| 37 | |
---|
| 38 | #include "gdm-display.h" |
---|
| 39 | #include "gdm-xdmcp-display.h" |
---|
| 40 | |
---|
| 41 | #include "gdm-common.h" |
---|
| 42 | #include "gdm-address.h" |
---|
| 43 | |
---|
| 44 | #define GDM_XDMCP_DISPLAY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_XDMCP_DISPLAY, GdmXdmcpDisplayPrivate)) |
---|
| 45 | |
---|
| 46 | struct GdmXdmcpDisplayPrivate |
---|
| 47 | { |
---|
| 48 | GdmAddress *remote_address; |
---|
| 49 | gint32 session_number; |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | enum { |
---|
| 53 | PROP_0, |
---|
| 54 | PROP_REMOTE_ADDRESS, |
---|
| 55 | PROP_SESSION_NUMBER, |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | static void gdm_xdmcp_display_class_init (GdmXdmcpDisplayClass *klass); |
---|
| 59 | static void gdm_xdmcp_display_init (GdmXdmcpDisplay *xdmcp_display); |
---|
| 60 | static void gdm_xdmcp_display_finalize (GObject *object); |
---|
| 61 | |
---|
| 62 | G_DEFINE_ABSTRACT_TYPE (GdmXdmcpDisplay, gdm_xdmcp_display, GDM_TYPE_DISPLAY) |
---|
| 63 | |
---|
| 64 | gint32 |
---|
| 65 | gdm_xdmcp_display_get_session_number (GdmXdmcpDisplay *display) |
---|
| 66 | { |
---|
| 67 | g_return_val_if_fail (GDM_IS_XDMCP_DISPLAY (display), 0); |
---|
| 68 | |
---|
| 69 | return display->priv->session_number; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | GdmAddress * |
---|
| 73 | gdm_xdmcp_display_get_remote_address (GdmXdmcpDisplay *display) |
---|
| 74 | { |
---|
| 75 | g_return_val_if_fail (GDM_IS_XDMCP_DISPLAY (display), NULL); |
---|
| 76 | |
---|
| 77 | return display->priv->remote_address; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | static gboolean |
---|
| 81 | gdm_xdmcp_display_create_authority (GdmDisplay *display) |
---|
| 82 | { |
---|
| 83 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
| 84 | |
---|
| 85 | return GDM_DISPLAY_CLASS (gdm_xdmcp_display_parent_class)->create_authority (display); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | static gboolean |
---|
| 89 | gdm_xdmcp_display_add_user_authorization (GdmDisplay *display, |
---|
| 90 | const char *username, |
---|
| 91 | char **filename, |
---|
| 92 | GError **error) |
---|
| 93 | { |
---|
| 94 | return GDM_DISPLAY_CLASS (gdm_xdmcp_display_parent_class)->add_user_authorization (display, username, filename, error); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | static gboolean |
---|
| 98 | gdm_xdmcp_display_remove_user_authorization (GdmDisplay *display, |
---|
| 99 | const char *username, |
---|
| 100 | GError **error) |
---|
| 101 | { |
---|
| 102 | return GDM_DISPLAY_CLASS (gdm_xdmcp_display_parent_class)->remove_user_authorization (display, username, error); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | static gboolean |
---|
| 106 | gdm_xdmcp_display_manage (GdmDisplay *display) |
---|
| 107 | { |
---|
| 108 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
| 109 | |
---|
| 110 | GDM_DISPLAY_CLASS (gdm_xdmcp_display_parent_class)->manage (display); |
---|
| 111 | |
---|
| 112 | return TRUE; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | static gboolean |
---|
| 116 | gdm_xdmcp_display_unmanage (GdmDisplay *display) |
---|
| 117 | { |
---|
| 118 | g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); |
---|
| 119 | |
---|
| 120 | GDM_DISPLAY_CLASS (gdm_xdmcp_display_parent_class)->unmanage (display); |
---|
| 121 | return TRUE; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | static void |
---|
| 125 | _gdm_xdmcp_display_set_remote_address (GdmXdmcpDisplay *display, |
---|
| 126 | GdmAddress *address) |
---|
| 127 | { |
---|
| 128 | if (display->priv->remote_address != NULL) { |
---|
| 129 | gdm_address_free (display->priv->remote_address); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | g_assert (address != NULL); |
---|
| 133 | |
---|
| 134 | gdm_address_debug (address); |
---|
| 135 | display->priv->remote_address = gdm_address_copy (address); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | static void |
---|
| 139 | gdm_xdmcp_display_set_property (GObject *object, |
---|
| 140 | guint prop_id, |
---|
| 141 | const GValue *value, |
---|
| 142 | GParamSpec *pspec) |
---|
| 143 | { |
---|
| 144 | GdmXdmcpDisplay *self; |
---|
| 145 | |
---|
| 146 | self = GDM_XDMCP_DISPLAY (object); |
---|
| 147 | |
---|
| 148 | switch (prop_id) { |
---|
| 149 | case PROP_REMOTE_ADDRESS: |
---|
| 150 | _gdm_xdmcp_display_set_remote_address (self, g_value_get_boxed (value)); |
---|
| 151 | break; |
---|
| 152 | case PROP_SESSION_NUMBER: |
---|
| 153 | self->priv->session_number = g_value_get_int (value); |
---|
| 154 | break; |
---|
| 155 | default: |
---|
| 156 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
| 157 | break; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | static void |
---|
| 162 | gdm_xdmcp_display_get_property (GObject *object, |
---|
| 163 | guint prop_id, |
---|
| 164 | GValue *value, |
---|
| 165 | GParamSpec *pspec) |
---|
| 166 | { |
---|
| 167 | GdmXdmcpDisplay *self; |
---|
| 168 | |
---|
| 169 | self = GDM_XDMCP_DISPLAY (object); |
---|
| 170 | |
---|
| 171 | switch (prop_id) { |
---|
| 172 | case PROP_REMOTE_ADDRESS: |
---|
| 173 | g_value_set_boxed (value, self->priv->remote_address); |
---|
| 174 | break; |
---|
| 175 | case PROP_SESSION_NUMBER: |
---|
| 176 | g_value_set_int (value, self->priv->session_number); |
---|
| 177 | break; |
---|
| 178 | default: |
---|
| 179 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
| 180 | break; |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | static void |
---|
| 185 | gdm_xdmcp_display_get_timed_login_details (GdmDisplay *display, |
---|
| 186 | gboolean *enabledp, |
---|
| 187 | char **usernamep, |
---|
| 188 | int *delayp) |
---|
| 189 | { |
---|
| 190 | *enabledp = FALSE; |
---|
| 191 | *usernamep = g_strdup (""); |
---|
| 192 | *delayp = 0; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | static void |
---|
| 196 | gdm_xdmcp_display_class_init (GdmXdmcpDisplayClass *klass) |
---|
| 197 | { |
---|
| 198 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
| 199 | GdmDisplayClass *display_class = GDM_DISPLAY_CLASS (klass); |
---|
| 200 | |
---|
| 201 | object_class->get_property = gdm_xdmcp_display_get_property; |
---|
| 202 | object_class->set_property = gdm_xdmcp_display_set_property; |
---|
| 203 | object_class->finalize = gdm_xdmcp_display_finalize; |
---|
| 204 | |
---|
| 205 | display_class->create_authority = gdm_xdmcp_display_create_authority; |
---|
| 206 | display_class->add_user_authorization = gdm_xdmcp_display_add_user_authorization; |
---|
| 207 | display_class->remove_user_authorization = gdm_xdmcp_display_remove_user_authorization; |
---|
| 208 | display_class->manage = gdm_xdmcp_display_manage; |
---|
| 209 | display_class->unmanage = gdm_xdmcp_display_unmanage; |
---|
| 210 | display_class->get_timed_login_details = gdm_xdmcp_display_get_timed_login_details; |
---|
| 211 | |
---|
| 212 | g_type_class_add_private (klass, sizeof (GdmXdmcpDisplayPrivate)); |
---|
| 213 | |
---|
| 214 | g_object_class_install_property (object_class, |
---|
| 215 | PROP_REMOTE_ADDRESS, |
---|
| 216 | g_param_spec_boxed ("remote-address", |
---|
| 217 | "Remote address", |
---|
| 218 | "Remote address", |
---|
| 219 | GDM_TYPE_ADDRESS, |
---|
| 220 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); |
---|
| 221 | |
---|
| 222 | g_object_class_install_property (object_class, |
---|
| 223 | PROP_SESSION_NUMBER, |
---|
| 224 | g_param_spec_int ("session-number", |
---|
| 225 | "session-number", |
---|
| 226 | "session-number", |
---|
| 227 | G_MININT, |
---|
| 228 | G_MAXINT, |
---|
| 229 | 0, |
---|
| 230 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); |
---|
| 231 | |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | static void |
---|
| 235 | gdm_xdmcp_display_init (GdmXdmcpDisplay *xdmcp_display) |
---|
| 236 | { |
---|
| 237 | |
---|
| 238 | xdmcp_display->priv = GDM_XDMCP_DISPLAY_GET_PRIVATE (xdmcp_display); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | static void |
---|
| 242 | gdm_xdmcp_display_finalize (GObject *object) |
---|
| 243 | { |
---|
| 244 | GdmXdmcpDisplay *xdmcp_display; |
---|
| 245 | |
---|
| 246 | g_return_if_fail (object != NULL); |
---|
| 247 | g_return_if_fail (GDM_IS_XDMCP_DISPLAY (object)); |
---|
| 248 | |
---|
| 249 | xdmcp_display = GDM_XDMCP_DISPLAY (object); |
---|
| 250 | |
---|
| 251 | g_return_if_fail (xdmcp_display->priv != NULL); |
---|
| 252 | |
---|
| 253 | G_OBJECT_CLASS (gdm_xdmcp_display_parent_class)->finalize (object); |
---|
| 254 | } |
---|