[gnome-online-accounts/wip/rishi/gobject-modernize: 5/5] kerberos-identity: Drop the priv pointer
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts/wip/rishi/gobject-modernize: 5/5] kerberos-identity: Drop the priv pointer
- Date: Thu, 28 Nov 2019 18:29:34 +0000 (UTC)
commit 995927f834d087a334158f3d2132f09c4a5cbe58
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Nov 28 18:37:40 2019 +0100
kerberos-identity: Drop the priv pointer
The current GObject recommendation is to use the generated
get_instance_private function instead of a separate priv pointer in the
instance struct. This saves one pointer per class in the hierarchy
multiplied by the number of instances of the type, and the function is
fast enough because it only does pointer arithmetic.
src/goaidentity/goakerberosidentity.c | 506 +++++++++++++++++-----------------
src/goaidentity/goakerberosidentity.h | 2 -
2 files changed, 253 insertions(+), 255 deletions(-)
---
diff --git a/src/goaidentity/goakerberosidentity.c b/src/goaidentity/goakerberosidentity.c
index 688c87ee..9b8c8098 100644
--- a/src/goaidentity/goakerberosidentity.c
+++ b/src/goaidentity/goakerberosidentity.c
@@ -112,11 +112,13 @@ static void
goa_kerberos_identity_dispose (GObject *object)
{
GoaKerberosIdentity *self = GOA_KERBEROS_IDENTITY (object);
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
G_LOCK (identity_lock);
clear_alarms (self);
- g_clear_pointer (&self->priv->preauth_identity_source,
- g_free);
+ g_clear_pointer (&priv->preauth_identity_source, g_free);
G_UNLOCK (identity_lock);
G_OBJECT_CLASS (goa_kerberos_identity_parent_class)->dispose (object);
@@ -127,11 +129,14 @@ static void
goa_kerberos_identity_finalize (GObject *object)
{
GoaKerberosIdentity *self = GOA_KERBEROS_IDENTITY (object);
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
- g_free (self->priv->identifier);
+ g_free (priv->identifier);
- if (self->priv->credentials_cache != NULL)
- krb5_cc_close (self->priv->kerberos_context, self->priv->credentials_cache);
+ if (priv->credentials_cache != NULL)
+ krb5_cc_close (priv->kerberos_context, priv->credentials_cache);
G_OBJECT_CLASS (goa_kerberos_identity_parent_class)->finalize (object);
}
@@ -143,12 +148,15 @@ goa_kerberos_identity_get_property (GObject *object,
GParamSpec *param_spec)
{
GoaKerberosIdentity *self = GOA_KERBEROS_IDENTITY (object);
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
switch (property_id)
{
case PROP_IDENTIFIER:
G_LOCK (identity_lock);
- g_value_set_string (value, self->priv->identifier);
+ g_value_set_string (value, priv->identifier);
G_UNLOCK (identity_lock);
break;
case PROP_IS_SIGNED_IN:
@@ -157,17 +165,17 @@ goa_kerberos_identity_get_property (GObject *object,
break;
case PROP_START_TIMESTAMP:
G_LOCK (identity_lock);
- g_value_set_int64 (value, (gint64) self->priv->start_time);
+ g_value_set_int64 (value, (gint64) priv->start_time);
G_UNLOCK (identity_lock);
break;
case PROP_RENEWAL_TIMESTAMP:
G_LOCK (identity_lock);
- g_value_set_int64 (value, (gint64) self->priv->renewal_time);
+ g_value_set_int64 (value, (gint64) priv->renewal_time);
G_UNLOCK (identity_lock);
break;
case PROP_EXPIRATION_TIMESTAMP:
G_LOCK (identity_lock);
- g_value_set_int64 (value, (gint64) self->priv->expiration_time);
+ g_value_set_int64 (value, (gint64) priv->expiration_time);
G_UNLOCK (identity_lock);
break;
default:
@@ -251,18 +259,18 @@ static char *
get_identifier (GoaKerberosIdentity *self,
GError **error)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_principal principal;
krb5_error_code error_code;
char *unparsed_name;
char *identifier = NULL;
- if (self->priv->credentials_cache == NULL)
- return NULL;
+ priv = goa_kerberos_identity_get_instance_private (self);
- error_code = krb5_cc_get_principal (self->priv->kerberos_context,
- self->priv->credentials_cache,
- &principal);
+ if (priv->credentials_cache == NULL)
+ return NULL;
+ error_code = krb5_cc_get_principal (priv->kerberos_context, priv->credentials_cache, &principal);
if (error_code != 0)
{
if (error_code == KRB5_CC_END)
@@ -284,37 +292,29 @@ get_identifier (GoaKerberosIdentity *self,
return NULL;
}
- error_code = krb5_unparse_name_flags (self->priv->kerberos_context,
- principal,
- 0,
- &unparsed_name);
-
+ error_code = krb5_unparse_name_flags (priv->kerberos_context, principal, 0, &unparsed_name);
if (error_code != 0)
{
const char *error_message;
- error_message =
- krb5_get_error_message (self->priv->kerberos_context, error_code);
+ error_message = krb5_get_error_message (priv->kerberos_context, error_code);
g_debug ("GoaKerberosIdentity: Error parsing principal identity name: %s",
error_message);
- krb5_free_error_message (self->priv->kerberos_context, error_message);
+ krb5_free_error_message (priv->kerberos_context, error_message);
goto out;
}
identifier = g_strdup (unparsed_name);
- krb5_free_unparsed_name (self->priv->kerberos_context, unparsed_name);
+ krb5_free_unparsed_name (priv->kerberos_context, unparsed_name);
out:
- krb5_free_principal (self->priv->kerberos_context, principal);
+ krb5_free_principal (priv->kerberos_context, principal);
return identifier;
}
static void
goa_kerberos_identity_init (GoaKerberosIdentity *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
- GOA_TYPE_KERBEROS_IDENTITY,
- GoaKerberosIdentityPrivate);
}
static void
@@ -325,11 +325,14 @@ set_and_prefix_error_from_krb5_error_code (GoaKerberosIdentity *self,
const char *format,
...)
{
+ GoaKerberosIdentityPrivate *priv;
const char *error_message;
char *literal_prefix;
va_list args;
- error_message = krb5_get_error_message (self->priv->kerberos_context, error_code);
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ error_message = krb5_get_error_message (priv->kerberos_context, error_code);
g_set_error_literal (error, GOA_IDENTITY_ERROR, code, error_message);
va_start (args, format);
@@ -339,55 +342,49 @@ set_and_prefix_error_from_krb5_error_code (GoaKerberosIdentity *self,
g_prefix_error (error, "%s", literal_prefix);
g_free (literal_prefix);
- krb5_free_error_message (self->priv->kerberos_context, error_message);
+ krb5_free_error_message (priv->kerberos_context, error_message);
}
char *
goa_kerberos_identity_get_principal_name (GoaKerberosIdentity *self)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_principal principal;
krb5_error_code error_code;
char *unparsed_name;
char *principal_name;
int flags;
- if (self->priv->identifier == NULL)
- return NULL;
+ priv = goa_kerberos_identity_get_instance_private (self);
- error_code = krb5_parse_name (self->priv->kerberos_context,
- self->priv->identifier,
- &principal);
+ if (priv->identifier == NULL)
+ return NULL;
+ error_code = krb5_parse_name (priv->kerberos_context, priv->identifier, &principal);
if (error_code != 0)
{
const char *error_message;
- error_message =
- krb5_get_error_message (self->priv->kerberos_context, error_code);
- g_debug
- ("GoaKerberosIdentity: Error parsing identity %s into kerberos principal: %s",
- self->priv->identifier, error_message);
- krb5_free_error_message (self->priv->kerberos_context, error_message);
+ error_message = krb5_get_error_message (priv->kerberos_context, error_code);
+ g_debug ("GoaKerberosIdentity: Error parsing identity %s into kerberos principal: %s",
priv->identifier, error_message);
+ krb5_free_error_message (priv->kerberos_context, error_message);
return NULL;
}
flags = KRB5_PRINCIPAL_UNPARSE_DISPLAY;
- error_code = krb5_unparse_name_flags (self->priv->kerberos_context,
- principal, flags, &unparsed_name);
-
+ error_code = krb5_unparse_name_flags (priv->kerberos_context, principal, flags, &unparsed_name);
if (error_code != 0)
{
const char *error_message;
- error_message =
- krb5_get_error_message (self->priv->kerberos_context, error_code);
+ error_message = krb5_get_error_message (priv->kerberos_context, error_code);
g_debug ("GoaKerberosIdentity: Error parsing principal identity name: %s",
error_message);
- krb5_free_error_message (self->priv->kerberos_context, error_message);
+ krb5_free_error_message (priv->kerberos_context, error_message);
return NULL;
}
principal_name = g_strdup (unparsed_name);
- krb5_free_unparsed_name (self->priv->kerberos_context, unparsed_name);
+ krb5_free_unparsed_name (priv->kerberos_context, unparsed_name);
return principal_name;
}
@@ -395,32 +392,30 @@ goa_kerberos_identity_get_principal_name (GoaKerberosIdentity *self)
char *
goa_kerberos_identity_get_realm_name (GoaKerberosIdentity *self)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_principal principal;
krb5_error_code error_code;
krb5_data *realm;
char *realm_name;
- if (self->priv->identifier == NULL)
- return NULL;
+ priv = goa_kerberos_identity_get_instance_private (self);
- error_code = krb5_parse_name (self->priv->kerberos_context,
- self->priv->identifier, &principal);
+ if (priv->identifier == NULL)
+ return NULL;
+ error_code = krb5_parse_name (priv->kerberos_context, priv->identifier, &principal);
if (error_code != 0)
{
const char *error_message;
- error_message =
- krb5_get_error_message (self->priv->kerberos_context, error_code);
- g_debug
- ("GoaKerberosIdentity: Error parsing identity %s into kerberos principal: %s",
- self->priv->identifier, error_message);
- krb5_free_error_message (self->priv->kerberos_context, error_message);
+ error_message = krb5_get_error_message (priv->kerberos_context, error_code);
+ g_debug ("GoaKerberosIdentity: Error parsing identity %s into kerberos principal: %s",
priv->identifier, error_message);
+ krb5_free_error_message (priv->kerberos_context, error_message);
return NULL;
}
- realm = krb5_princ_realm (self->priv->kerberos_context, principal);
+ realm = krb5_princ_realm (priv->kerberos_context, principal);
realm_name = g_strndup (realm->data, realm->length);
- krb5_free_principal (self->priv->kerberos_context, principal);
+ krb5_free_principal (priv->kerberos_context, principal);
return realm_name;
}
@@ -428,34 +423,42 @@ goa_kerberos_identity_get_realm_name (GoaKerberosIdentity *self)
char *
goa_kerberos_identity_get_preauthentication_source (GoaKerberosIdentity *self)
{
- return g_strdup (self->priv->preauth_identity_source);
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
+ return g_strdup (priv->preauth_identity_source);
}
static const char *
goa_kerberos_identity_get_identifier (GoaIdentity *identity)
{
GoaKerberosIdentity *self = GOA_KERBEROS_IDENTITY (identity);
+ GoaKerberosIdentityPrivate *priv;
- return self->priv->identifier;
+ priv = goa_kerberos_identity_get_instance_private (self);
+ return priv->identifier;
}
static gboolean
credentials_validate_existence (GoaKerberosIdentity *self,
krb5_principal principal, krb5_creds * credentials)
{
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
+
/* Checks if default principal associated with the cache has a valid
* ticket granting ticket in the passed in credentials
*/
- if (krb5_is_config_principal (self->priv->kerberos_context, credentials->server))
+ if (krb5_is_config_principal (priv->kerberos_context, credentials->server))
return FALSE;
/* looking for the krbtgt / REALM pair, so it should be exactly 2 items */
- if (krb5_princ_size (self->priv->kerberos_context, credentials->server) != 2)
+ if (krb5_princ_size (priv->kerberos_context, credentials->server) != 2)
return FALSE;
- if (!krb5_realm_compare (self->priv->kerberos_context,
- credentials->server, principal))
+ if (!krb5_realm_compare (priv->kerberos_context, credentials->server, principal))
{
/* credentials are from some other realm */
return FALSE;
@@ -484,11 +487,14 @@ snoop_preauth_identity_from_credentials (GoaKerberosIdentity *self,
krb5_creds *credentials,
char **identity_source)
{
+ GoaKerberosIdentityPrivate *priv;
GRegex *regex;
GMatchInfo *match_info = NULL;
gboolean identity_source_exposed = FALSE;
- if (!krb5_is_config_principal (self->priv->kerberos_context, credentials->server))
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (!krb5_is_config_principal (priv->kerberos_context, credentials->server))
return FALSE;
regex = g_regex_new ("\"X509_user_identity\":\"(?P<identity_source>[^\"]*)\"",
@@ -520,19 +526,20 @@ snoop_preauth_identity_from_credentials (GoaKerberosIdentity *self,
static krb5_timestamp
get_current_time (GoaKerberosIdentity *self)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_timestamp current_time;
krb5_error_code error_code;
- error_code = krb5_timeofday (self->priv->kerberos_context, ¤t_time);
+ priv = goa_kerberos_identity_get_instance_private (self);
+ error_code = krb5_timeofday (priv->kerberos_context, ¤t_time);
if (error_code != 0)
{
const char *error_message;
- error_message =
- krb5_get_error_message (self->priv->kerberos_context, error_code);
+ error_message = krb5_get_error_message (priv->kerberos_context, error_code);
g_debug ("GoaKerberosIdentity: Error getting current time: %s", error_message);
- krb5_free_error_message (self->priv->kerberos_context, error_message);
+ krb5_free_error_message (priv->kerberos_context, error_message);
return 0;
}
@@ -591,12 +598,14 @@ static gboolean
set_start_time (GoaKerberosIdentity *self,
krb5_timestamp start_time)
{
- if (self->priv->start_time != start_time)
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->start_time != start_time)
{
- self->priv->start_time = start_time;
- queue_notify (self,
- &self->priv->start_time_idle_id,
- "start-timestamp");
+ priv->start_time = start_time;
+ queue_notify (self, &priv->start_time_idle_id, "start-timestamp");
return TRUE;
}
return FALSE;
@@ -606,12 +615,14 @@ static gboolean
set_renewal_time (GoaKerberosIdentity *self,
krb5_timestamp renewal_time)
{
- if (self->priv->renewal_time != renewal_time)
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->renewal_time != renewal_time)
{
- self->priv->renewal_time = renewal_time;
- queue_notify (self,
- &self->priv->renewal_time_idle_id,
- "renewal-timestamp");
+ priv->renewal_time = renewal_time;
+ queue_notify (self, &priv->renewal_time_idle_id, "renewal-timestamp");
return TRUE;
}
return FALSE;
@@ -621,12 +632,14 @@ static gboolean
set_expiration_time (GoaKerberosIdentity *self,
krb5_timestamp expiration_time)
{
- if (self->priv->expiration_time != expiration_time)
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->expiration_time != expiration_time)
{
- self->priv->expiration_time = expiration_time;
- queue_notify (self,
- &self->priv->expiration_time_idle_id,
- "expiration-timestamp");
+ priv->expiration_time = expiration_time;
+ queue_notify (self, &priv->expiration_time_idle_id, "expiration-timestamp");
return TRUE;
}
return FALSE;
@@ -640,10 +653,13 @@ examine_credentials (GoaKerberosIdentity *self,
krb5_timestamp *expiration_time,
gboolean *are_expired)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_timestamp credentials_start_time;
krb5_timestamp credentials_end_time;
krb5_timestamp current_time;
+ priv = goa_kerberos_identity_get_instance_private (self);
+
G_LOCK (identity_lock);
if (credentials->times.starttime != 0)
@@ -655,13 +671,11 @@ examine_credentials (GoaKerberosIdentity *self,
credentials_end_time = credentials->times.endtime;
- if (self->priv->start_time == 0)
+ if (priv->start_time == 0)
*start_time = credentials_start_time;
else
- *start_time = MIN (self->priv->start_time,
- credentials_start_time);
- *expiration_time = MAX (credentials->times.endtime,
- self->priv->expiration_time);
+ *start_time = MIN (priv->start_time, credentials_start_time);
+ *expiration_time = MAX (credentials->times.endtime, priv->expiration_time);
G_UNLOCK (identity_lock);
current_time = get_current_time (self);
@@ -678,6 +692,7 @@ verify_identity (GoaKerberosIdentity *self,
char **preauth_identity_source,
GError **error)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_principal principal = NULL;
krb5_cc_cursor cursor;
krb5_creds credentials;
@@ -687,13 +702,12 @@ verify_identity (GoaKerberosIdentity *self,
krb5_timestamp expiration_time = 0;
VerificationLevel verification_level = VERIFICATION_LEVEL_UNVERIFIED;
- if (self->priv->credentials_cache == NULL)
- goto out;
+ priv = goa_kerberos_identity_get_instance_private (self);
- error_code = krb5_cc_get_principal (self->priv->kerberos_context,
- self->priv->credentials_cache,
- &principal);
+ if (priv->credentials_cache == NULL)
+ goto out;
+ error_code = krb5_cc_get_principal (priv->kerberos_context, priv->credentials_cache, &principal);
if (error_code != 0)
{
if (error_code == KRB5_CC_END || error_code == KRB5_FCC_NOFILE)
@@ -708,8 +722,7 @@ verify_identity (GoaKerberosIdentity *self,
goto out;
}
- error_code = krb5_cc_start_seq_get (self->priv->kerberos_context,
- self->priv->credentials_cache, &cursor);
+ error_code = krb5_cc_start_seq_get (priv->kerberos_context, priv->credentials_cache, &cursor);
if (error_code != 0)
{
set_and_prefix_error_from_krb5_error_code (self,
@@ -724,11 +737,7 @@ verify_identity (GoaKerberosIdentity *self,
verification_level = VERIFICATION_LEVEL_UNVERIFIED;
- error_code = krb5_cc_next_cred (self->priv->kerberos_context,
- self->priv->credentials_cache,
- &cursor,
- &credentials);
-
+ error_code = krb5_cc_next_cred (priv->kerberos_context, priv->credentials_cache, &cursor, &credentials);
while (error_code == 0)
{
if (credentials_validate_existence (self, principal, &credentials))
@@ -751,12 +760,8 @@ verify_identity (GoaKerberosIdentity *self,
snoop_preauth_identity_from_credentials (self, &credentials, preauth_identity_source);
}
- krb5_free_cred_contents (self->priv->kerberos_context, &credentials);
-
- error_code = krb5_cc_next_cred (self->priv->kerberos_context,
- self->priv->credentials_cache,
- &cursor,
- &credentials);
+ krb5_free_cred_contents (priv->kerberos_context, &credentials);
+ error_code = krb5_cc_next_cred (priv->kerberos_context, priv->credentials_cache, &cursor,
&credentials);
}
if (error_code != KRB5_CC_END)
@@ -772,10 +777,7 @@ verify_identity (GoaKerberosIdentity *self,
}
end_sequence:
- error_code = krb5_cc_end_seq_get (self->priv->kerberos_context,
- self->priv->credentials_cache,
- &cursor);
-
+ error_code = krb5_cc_end_seq_get (priv->kerberos_context, priv->credentials_cache, &cursor);
if (error_code != 0)
{
verification_level = VERIFICATION_LEVEL_ERROR;
@@ -797,7 +799,7 @@ out:
G_UNLOCK (identity_lock);
if (principal != NULL)
- krb5_free_principal (self->priv->kerberos_context, principal);
+ krb5_free_principal (priv->kerberos_context, principal);
return verification_level;
}
@@ -805,10 +807,13 @@ static gboolean
goa_kerberos_identity_is_signed_in (GoaIdentity *identity)
{
GoaKerberosIdentity *self = GOA_KERBEROS_IDENTITY (identity);
+ GoaKerberosIdentityPrivate *priv;
gboolean is_signed_in = FALSE;
+ priv = goa_kerberos_identity_get_instance_private (self);
+
G_LOCK (identity_lock);
- if (self->priv->cached_verification_level == VERIFICATION_LEVEL_SIGNED_IN)
+ if (priv->cached_verification_level == VERIFICATION_LEVEL_SIGNED_IN)
is_signed_in = TRUE;
G_UNLOCK (identity_lock);
@@ -859,10 +864,14 @@ static void
on_renewal_alarm_fired (GoaAlarm *alarm,
GoaKerberosIdentity *self)
{
+ GoaKerberosIdentityPrivate *priv;
+
g_return_if_fail (GOA_IS_ALARM (alarm));
g_return_if_fail (GOA_IS_KERBEROS_IDENTITY (self));
- if (self->priv->cached_verification_level == VERIFICATION_LEVEL_SIGNED_IN)
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->cached_verification_level == VERIFICATION_LEVEL_SIGNED_IN)
{
g_debug ("GoaKerberosIdentity: renewal alarm fired for signed-in identity");
g_signal_emit (G_OBJECT (self), signals[NEEDS_RENEWAL], 0);
@@ -883,10 +892,14 @@ static void
on_expiring_alarm_fired (GoaAlarm *alarm,
GoaKerberosIdentity *self)
{
+ GoaKerberosIdentityPrivate *priv;
+
g_return_if_fail (GOA_IS_ALARM (alarm));
g_return_if_fail (GOA_IS_KERBEROS_IDENTITY (self));
- if (self->priv->cached_verification_level == VERIFICATION_LEVEL_SIGNED_IN)
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->cached_verification_level == VERIFICATION_LEVEL_SIGNED_IN)
{
g_debug ("GoaKerberosIdentity: expiring alarm fired for signed-in identity");
g_signal_emit (G_OBJECT (self), signals[EXPIRING], 0);
@@ -933,83 +946,64 @@ reset_alarm (GoaKerberosIdentity *self,
static void
disconnect_alarm_signals (GoaKerberosIdentity *self)
{
- if (self->priv->renewal_alarm)
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->renewal_alarm)
{
- g_signal_handlers_disconnect_by_func (G_OBJECT (self->priv->renewal_alarm),
- G_CALLBACK (on_renewal_alarm_fired),
- self);
- g_signal_handlers_disconnect_by_func (G_OBJECT (self->priv->renewal_alarm),
- G_CALLBACK (on_renewal_alarm_rearmed),
- self);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->renewal_alarm), G_CALLBACK
(on_renewal_alarm_fired), self);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->renewal_alarm), G_CALLBACK
(on_renewal_alarm_rearmed), self);
}
- if (self->priv->expiring_alarm)
+ if (priv->expiring_alarm)
{
- g_signal_handlers_disconnect_by_func (G_OBJECT (self->priv->expiring_alarm),
- G_CALLBACK (on_expiring_alarm_fired),
- self);
- g_signal_handlers_disconnect_by_func (G_OBJECT (self->priv->expiring_alarm),
- G_CALLBACK (on_expiring_alarm_rearmed),
- self);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->expiring_alarm), G_CALLBACK
(on_expiring_alarm_fired), self);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->expiring_alarm), G_CALLBACK
(on_expiring_alarm_rearmed), self);
}
- if (self->priv->expiration_alarm)
+ if (priv->expiration_alarm)
{
- g_signal_handlers_disconnect_by_func (G_OBJECT (self->priv->expiration_alarm),
- G_CALLBACK (on_expiration_alarm_rearmed),
- self);
- g_signal_handlers_disconnect_by_func (G_OBJECT (self->priv->expiration_alarm),
- G_CALLBACK (on_expiration_alarm_fired),
- self);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->expiration_alarm), G_CALLBACK
(on_expiration_alarm_rearmed), self);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (priv->expiration_alarm), G_CALLBACK
(on_expiration_alarm_fired), self);
}
}
static void
connect_alarm_signals (GoaKerberosIdentity *self)
{
- if (self->priv->renewal_alarm)
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->renewal_alarm)
{
- g_signal_connect (G_OBJECT (self->priv->renewal_alarm),
- "fired",
- G_CALLBACK (on_renewal_alarm_fired),
- self);
- g_signal_connect (G_OBJECT (self->priv->renewal_alarm),
- "rearmed",
- G_CALLBACK (on_renewal_alarm_rearmed),
- self);
+ g_signal_connect (G_OBJECT (priv->renewal_alarm), "fired", G_CALLBACK (on_renewal_alarm_fired), self);
+ g_signal_connect (G_OBJECT (priv->renewal_alarm), "rearmed", G_CALLBACK (on_renewal_alarm_rearmed),
self);
}
- g_signal_connect (G_OBJECT (self->priv->expiring_alarm),
- "fired",
- G_CALLBACK (on_expiring_alarm_fired),
- self);
- g_signal_connect (G_OBJECT (self->priv->expiring_alarm),
- "rearmed",
- G_CALLBACK (on_expiring_alarm_rearmed),
- self);
- g_signal_connect (G_OBJECT (self->priv->expiration_alarm),
- "fired",
- G_CALLBACK (on_expiration_alarm_fired),
- self);
- g_signal_connect (G_OBJECT (self->priv->expiration_alarm),
- "rearmed",
- G_CALLBACK (on_expiration_alarm_rearmed),
- self);
+ g_signal_connect (G_OBJECT (priv->expiring_alarm), "fired", G_CALLBACK (on_expiring_alarm_fired), self);
+ g_signal_connect (G_OBJECT (priv->expiring_alarm), "rearmed", G_CALLBACK (on_expiring_alarm_rearmed),
self);
+ g_signal_connect (G_OBJECT (priv->expiration_alarm), "fired", G_CALLBACK (on_expiration_alarm_fired),
self);
+ g_signal_connect (G_OBJECT (priv->expiration_alarm), "rearmed", G_CALLBACK (on_expiration_alarm_rearmed),
self);
}
static void
reset_alarms (GoaKerberosIdentity *self)
{
+ GoaKerberosIdentityPrivate *priv;
GDateTime *start_time = NULL;
GDateTime *expiration_time = NULL;
GDateTime *expiring_time = NULL;
GDateTime *latest_possible_renewal_time = NULL;
GDateTime *renewal_time = NULL;
+ priv = goa_kerberos_identity_get_instance_private (self);
+
G_LOCK (identity_lock);
- start_time = g_date_time_new_from_unix_local (self->priv->start_time);
- if (self->priv->renewal_time != 0)
- latest_possible_renewal_time = g_date_time_new_from_unix_local (self->priv->renewal_time);
- expiration_time = g_date_time_new_from_unix_local (self->priv->expiration_time);
+ start_time = g_date_time_new_from_unix_local (priv->start_time);
+ if (priv->renewal_time != 0)
+ latest_possible_renewal_time = g_date_time_new_from_unix_local (priv->renewal_time);
+ expiration_time = g_date_time_new_from_unix_local (priv->expiration_time);
G_UNLOCK (identity_lock);
/* Let the user reauthenticate 10 min before expiration */
@@ -1030,10 +1024,10 @@ reset_alarms (GoaKerberosIdentity *self)
disconnect_alarm_signals (self);
if (renewal_time != NULL)
- reset_alarm (self, &self->priv->renewal_alarm, renewal_time);
+ reset_alarm (self, &priv->renewal_alarm, renewal_time);
- reset_alarm (self, &self->priv->expiring_alarm, expiring_time);
- reset_alarm (self, &self->priv->expiration_alarm, expiration_time);
+ reset_alarm (self, &priv->expiring_alarm, expiring_time);
+ reset_alarm (self, &priv->expiration_alarm, expiration_time);
g_clear_pointer (&expiring_time, g_date_time_unref);
g_clear_pointer (&renewal_time, g_date_time_unref);
@@ -1047,10 +1041,14 @@ reset_alarms (GoaKerberosIdentity *self)
static void
clear_alarms (GoaKerberosIdentity *self)
{
+ GoaKerberosIdentityPrivate *priv;
+
+ priv = goa_kerberos_identity_get_instance_private (self);
+
disconnect_alarm_signals (self);
- clear_alarm_and_unref_on_idle (self, &self->priv->renewal_alarm);
- clear_alarm_and_unref_on_idle (self, &self->priv->expiring_alarm);
- clear_alarm_and_unref_on_idle (self, &self->priv->expiration_alarm);
+ clear_alarm_and_unref_on_idle (self, &priv->renewal_alarm);
+ clear_alarm_and_unref_on_idle (self, &priv->expiring_alarm);
+ clear_alarm_and_unref_on_idle (self, &priv->expiration_alarm);
}
static gboolean
@@ -1059,30 +1057,32 @@ goa_kerberos_identity_initable_init (GInitable *initable,
GError **error)
{
GoaKerberosIdentity *self = GOA_KERBEROS_IDENTITY (initable);
+ GoaKerberosIdentityPrivate *priv;
GError *verification_error;
+ priv = goa_kerberos_identity_get_instance_private (self);
+
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
- if (self->priv->identifier == NULL)
+ if (priv->identifier == NULL)
{
- self->priv->identifier = get_identifier (self, error);
+ priv->identifier = get_identifier (self, error);
- if (self->priv->identifier != NULL)
- queue_notify (self, &self->priv->identifier_idle_id, "identifier");
+ if (priv->identifier != NULL)
+ queue_notify (self, &priv->identifier_idle_id, "identifier");
}
verification_error = NULL;
- self->priv->cached_verification_level =
- verify_identity (self, &self->priv->preauth_identity_source, &verification_error);
+ priv->cached_verification_level = verify_identity (self, &priv->preauth_identity_source,
&verification_error);
- switch (self->priv->cached_verification_level)
+ switch (priv->cached_verification_level)
{
case VERIFICATION_LEVEL_EXISTS:
case VERIFICATION_LEVEL_SIGNED_IN:
reset_alarms (self);
- queue_notify (self, &self->priv->is_signed_in_idle_id, "is-signed-in");
+ queue_notify (self, &priv->is_signed_in_idle_id, "is-signed-in");
return TRUE;
case VERIFICATION_LEVEL_UNVERIFIED:
@@ -1160,20 +1160,19 @@ static gboolean
create_credential_cache (GoaKerberosIdentity *self,
GError **error)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_ccache default_cache;
const char *cache_type;
krb5_error_code error_code;
- error_code = krb5_cc_default (self->priv->kerberos_context, &default_cache);
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ error_code = krb5_cc_default (priv->kerberos_context, &default_cache);
if (error_code == 0)
{
- cache_type = krb5_cc_get_type (self->priv->kerberos_context, default_cache);
-
- error_code = krb5_cc_new_unique (self->priv->kerberos_context,
- cache_type,
- NULL,
- &self->priv->credentials_cache);
+ cache_type = krb5_cc_get_type (priv->kerberos_context, default_cache);
+ error_code = krb5_cc_new_unique (priv->kerberos_context, cache_type, NULL, &priv->credentials_cache);
}
if (error_code != 0)
@@ -1196,20 +1195,21 @@ goa_kerberos_identity_update_credentials (GoaKerberosIdentity *self,
krb5_creds *new_credentials,
GError **error)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_error_code error_code;
- if (self->priv->credentials_cache == NULL)
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->credentials_cache == NULL)
{
if (!create_credential_cache (self, error))
{
- krb5_free_cred_contents (self->priv->kerberos_context, new_credentials);
+ krb5_free_cred_contents (priv->kerberos_context, new_credentials);
goto out;
}
}
- error_code = krb5_cc_initialize (self->priv->kerberos_context,
- self->priv->credentials_cache,
- principal);
+ error_code = krb5_cc_initialize (priv->kerberos_context, priv->credentials_cache, principal);
if (error_code != 0)
{
set_and_prefix_error_from_krb5_error_code (self,
@@ -1218,14 +1218,11 @@ goa_kerberos_identity_update_credentials (GoaKerberosIdentity *self,
error_code,
_("Could not initialize credentials cache: "));
- krb5_free_cred_contents (self->priv->kerberos_context, new_credentials);
+ krb5_free_cred_contents (priv->kerberos_context, new_credentials);
goto out;
}
- error_code = krb5_cc_store_cred (self->priv->kerberos_context,
- self->priv->credentials_cache,
- new_credentials);
-
+ error_code = krb5_cc_store_cred (priv->kerberos_context, priv->credentials_cache, new_credentials);
if (error_code != 0)
{
set_and_prefix_error_from_krb5_error_code (self,
@@ -1234,10 +1231,10 @@ goa_kerberos_identity_update_credentials (GoaKerberosIdentity *self,
error_code,
_("Could not store new credentials in credentials cache:
"));
- krb5_free_cred_contents (self->priv->kerberos_context, new_credentials);
+ krb5_free_cred_contents (priv->kerberos_context, new_credentials);
goto out;
}
- krb5_free_cred_contents (self->priv->kerberos_context, new_credentials);
+ krb5_free_cred_contents (priv->kerberos_context, new_credentials);
return TRUE;
out:
@@ -1288,6 +1285,7 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
GCancellable *cancellable,
GError **error)
{
+ GoaKerberosIdentityPrivate *priv;
SignInOperation *operation;
krb5_principal principal;
krb5_error_code error_code;
@@ -1297,11 +1295,12 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
char *service_name;
gboolean signed_in;
+ priv = goa_kerberos_identity_get_instance_private (self);
+
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
- error_code = krb5_get_init_creds_opt_alloc (self->priv->kerberos_context,
- &options);
+ error_code = krb5_get_init_creds_opt_alloc (priv->kerberos_context, &options);
if (error_code != 0)
{
set_and_prefix_error_from_krb5_error_code (self,
@@ -1323,16 +1322,13 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
destroy_notify,
cancellable);
- if (g_strcmp0 (self->priv->identifier, principal_name) != 0)
+ if (g_strcmp0 (priv->identifier, principal_name) != 0)
{
- g_free (self->priv->identifier);
- self->priv->identifier = g_strdup (principal_name);
+ g_free (priv->identifier);
+ priv->identifier = g_strdup (principal_name);
}
- error_code = krb5_parse_name (self->priv->kerberos_context,
- principal_name,
- &principal);
-
+ error_code = krb5_parse_name (priv->kerberos_context, principal_name, &principal);
if (error_code != 0)
{
set_and_prefix_error_from_krb5_error_code (self,
@@ -1356,11 +1352,7 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
krb5_get_init_creds_opt_set_renew_life (options, G_MAXINT);
if (preauth_source != NULL)
- {
- krb5_get_init_creds_opt_set_pa (self->priv->kerberos_context,
- options,
- "X509_user_identity", preauth_source);
- }
+ krb5_get_init_creds_opt_set_pa (priv->kerberos_context, options, "X509_user_identity", preauth_source);
/* Poke glibc in case the network changed
*/
@@ -1368,7 +1360,7 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
start_time = 0;
service_name = NULL;
- error_code = krb5_get_init_creds_password (self->priv->kerberos_context,
+ error_code = krb5_get_init_creds_password (priv->kerberos_context,
&new_credentials,
principal,
(char *)
@@ -1389,7 +1381,7 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
destroy_notify (inquiry_data);
sign_in_operation_free (operation);
- krb5_free_principal (self->priv->kerberos_context, principal);
+ krb5_free_principal (priv->kerberos_context, principal);
goto done;
}
@@ -1405,7 +1397,7 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
destroy_notify (inquiry_data);
sign_in_operation_free (operation);
- krb5_free_principal (self->priv->kerberos_context, principal);
+ krb5_free_principal (priv->kerberos_context, principal);
goto done;
}
@@ -1418,10 +1410,10 @@ goa_kerberos_identity_sign_in (GoaKerberosIdentity *self,
&new_credentials,
error))
{
- krb5_free_principal (self->priv->kerberos_context, principal);
+ krb5_free_principal (priv->kerberos_context, principal);
goto done;
}
- krb5_free_principal (self->priv->kerberos_context, principal);
+ krb5_free_principal (priv->kerberos_context, principal);
g_debug ("GoaKerberosIdentity: identity signed in");
signed_in = TRUE;
@@ -1433,14 +1425,17 @@ done:
static void
update_identifier (GoaKerberosIdentity *self, GoaKerberosIdentity *new_identity)
{
+ GoaKerberosIdentityPrivate *priv;
char *new_identifier;
+ priv = goa_kerberos_identity_get_instance_private (self);
+
new_identifier = get_identifier (self, NULL);
- if (g_strcmp0 (self->priv->identifier, new_identifier) != 0 && new_identifier != NULL)
+ if (g_strcmp0 (priv->identifier, new_identifier) != 0 && new_identifier != NULL)
{
- g_free (self->priv->identifier);
- self->priv->identifier = new_identifier;
- queue_notify (self, &self->priv->identifier_idle_id, "identifier");
+ g_free (priv->identifier);
+ priv->identifier = new_identifier;
+ queue_notify (self, &priv->identifier_idle_id, "identifier");
}
else
{
@@ -1452,25 +1447,28 @@ void
goa_kerberos_identity_update (GoaKerberosIdentity *self,
GoaKerberosIdentity *new_identity)
{
+ GoaKerberosIdentityPrivate *priv;
+ GoaKerberosIdentityPrivate *new_identity_priv;
VerificationLevel old_verification_level, new_verification_level;
gboolean time_changed = FALSE;
char *preauth_identity_source = NULL;
- if (self->priv->credentials_cache != NULL)
- krb5_cc_close (self->priv->kerberos_context, self->priv->credentials_cache);
+ priv = goa_kerberos_identity_get_instance_private (self);
+ new_identity_priv = goa_kerberos_identity_get_instance_private (new_identity);
+
+ if (priv->credentials_cache != NULL)
+ krb5_cc_close (priv->kerberos_context, priv->credentials_cache);
- krb5_cc_dup (new_identity->priv->kerberos_context,
- new_identity->priv->credentials_cache,
- &self->priv->credentials_cache);
+ krb5_cc_dup (new_identity_priv->kerberos_context, new_identity_priv->credentials_cache,
&priv->credentials_cache);
G_LOCK (identity_lock);
update_identifier (self, new_identity);
- time_changed |= set_start_time (self, new_identity->priv->start_time);
- time_changed |= set_renewal_time (self, new_identity->priv->renewal_time);
- time_changed |= set_expiration_time (self, new_identity->priv->expiration_time);
- old_verification_level = self->priv->cached_verification_level;
- new_verification_level = new_identity->priv->cached_verification_level;
+ time_changed |= set_start_time (self, new_identity_priv->start_time);
+ time_changed |= set_renewal_time (self, new_identity_priv->renewal_time);
+ time_changed |= set_expiration_time (self, new_identity_priv->expiration_time);
+ old_verification_level = priv->cached_verification_level;
+ new_verification_level = new_identity_priv->cached_verification_level;
G_UNLOCK (identity_lock);
if (time_changed)
@@ -1482,8 +1480,8 @@ goa_kerberos_identity_update (GoaKerberosIdentity *self,
}
G_LOCK (identity_lock);
- g_free (self->priv->preauth_identity_source);
- self->priv->preauth_identity_source = preauth_identity_source;
+ g_free (priv->preauth_identity_source);
+ priv->preauth_identity_source = preauth_identity_source;
G_UNLOCK (identity_lock);
if (new_verification_level != old_verification_level)
@@ -1492,7 +1490,7 @@ goa_kerberos_identity_update (GoaKerberosIdentity *self,
new_verification_level == VERIFICATION_LEVEL_EXISTS)
{
G_LOCK (identity_lock);
- self->priv->cached_verification_level = new_verification_level;
+ priv->cached_verification_level = new_verification_level;
G_UNLOCK (identity_lock);
g_signal_emit (G_OBJECT (self), signals[EXPIRED], 0);
@@ -1501,7 +1499,7 @@ goa_kerberos_identity_update (GoaKerberosIdentity *self,
new_verification_level == VERIFICATION_LEVEL_SIGNED_IN)
{
G_LOCK (identity_lock);
- self->priv->cached_verification_level = new_verification_level;
+ priv->cached_verification_level = new_verification_level;
G_UNLOCK (identity_lock);
g_signal_emit (G_OBJECT (self), signals[UNEXPIRED], 0);
@@ -1509,23 +1507,26 @@ goa_kerberos_identity_update (GoaKerberosIdentity *self,
else
{
G_LOCK (identity_lock);
- self->priv->cached_verification_level = new_verification_level;
+ priv->cached_verification_level = new_verification_level;
G_UNLOCK (identity_lock);
}
- queue_notify (self, &self->priv->is_signed_in_idle_id, "is-signed-in");
+ queue_notify (self, &priv->is_signed_in_idle_id, "is-signed-in");
}
}
gboolean
goa_kerberos_identity_renew (GoaKerberosIdentity *self, GError **error)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_error_code error_code = 0;
krb5_principal principal;
krb5_creds new_credentials;
gboolean renewed = FALSE;
char *name = NULL;
- if (self->priv->credentials_cache == NULL)
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->credentials_cache == NULL)
{
g_set_error (error,
GOA_IDENTITY_ERROR,
@@ -1534,9 +1535,7 @@ goa_kerberos_identity_renew (GoaKerberosIdentity *self, GError **error)
goto out;
}
- error_code = krb5_cc_get_principal (self->priv->kerberos_context,
- self->priv->credentials_cache, &principal);
-
+ error_code = krb5_cc_get_principal (priv->kerberos_context, priv->credentials_cache, &principal);
if (error_code != 0)
{
set_and_prefix_error_from_krb5_error_code (self,
@@ -1548,10 +1547,7 @@ goa_kerberos_identity_renew (GoaKerberosIdentity *self, GError **error)
name = goa_kerberos_identity_get_principal_name (self);
- error_code = krb5_get_renewed_creds (self->priv->kerberos_context,
- &new_credentials,
- principal,
- self->priv->credentials_cache, NULL);
+ error_code = krb5_get_renewed_creds (priv->kerberos_context, &new_credentials, principal,
priv->credentials_cache, NULL);
if (error_code != 0)
{
set_and_prefix_error_from_krb5_error_code (self,
@@ -1575,7 +1571,7 @@ goa_kerberos_identity_renew (GoaKerberosIdentity *self, GError **error)
renewed = TRUE;
free_principal:
- krb5_free_principal (self->priv->kerberos_context, principal);
+ krb5_free_principal (priv->kerberos_context, principal);
out:
g_free (name);
@@ -1586,13 +1582,15 @@ out:
gboolean
goa_kerberos_identity_erase (GoaKerberosIdentity *self, GError **error)
{
+ GoaKerberosIdentityPrivate *priv;
krb5_error_code error_code = 0;
- if (self->priv->credentials_cache != NULL)
+ priv = goa_kerberos_identity_get_instance_private (self);
+
+ if (priv->credentials_cache != NULL)
{
- error_code = krb5_cc_destroy (self->priv->kerberos_context,
- self->priv->credentials_cache);
- self->priv->credentials_cache = NULL;
+ error_code = krb5_cc_destroy (priv->kerberos_context, priv->credentials_cache);
+ priv->credentials_cache = NULL;
}
if (error_code != 0)
@@ -1611,11 +1609,13 @@ GoaIdentity *
goa_kerberos_identity_new (krb5_context context, krb5_ccache cache, GError **error)
{
GoaKerberosIdentity *self;
+ GoaKerberosIdentityPrivate *priv;
self = GOA_KERBEROS_IDENTITY (g_object_new (GOA_TYPE_KERBEROS_IDENTITY, NULL));
+ priv = goa_kerberos_identity_get_instance_private (self);
- krb5_cc_dup (context, cache, &self->priv->credentials_cache);
- self->priv->kerberos_context = context;
+ krb5_cc_dup (context, cache, &priv->credentials_cache);
+ priv->kerberos_context = context;
error = NULL;
if (!g_initable_init (G_INITABLE (self), NULL, error))
diff --git a/src/goaidentity/goakerberosidentity.h b/src/goaidentity/goakerberosidentity.h
index d7cc2ab3..e9898b50 100644
--- a/src/goaidentity/goakerberosidentity.h
+++ b/src/goaidentity/goakerberosidentity.h
@@ -48,8 +48,6 @@ enum _GoaKerberosIdentityDescriptionLevel
struct _GoaKerberosIdentity
{
GObject parent;
-
- GoaKerberosIdentityPrivate *priv;
};
struct _GoaKerberosIdentityClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]