* src/krb5-auth-dialog.c:
Refactor code slightly, removing an #ifdef in favor
of a wrapper. Consolidate coding style.
git-svn-id: http://svn.gnome.org/svn/krb5-auth-dialog/trunk@67
517b70f8-ed25-0410-8bf6-
f5db08f7b76e
* src/krb5-auth-dialog.c: Clean up the #ifdefs to
make things slightly more readable.
* src/krb5-auth-dialog.c: Clean up the #ifdefs to
make things slightly more readable.
+ Refactor code slightly, removing an #ifdef in favor
+ of a wrapper. Consolidate coding style.
2006-07-24 Christopher Aillon <caillon@redhat.com>
2006-07-24 Christopher Aillon <caillon@redhat.com>
+static krb5_error_code
+get_renewed_creds(krb5_context context,
+ krb5_creds *creds,
+ krb5_principal client,
+ krb5_ccache ccache,
+ char *in_tkt_service)
+{
+#ifdef HAVE_KRB5_GET_RENEWED_CREDS
+ return krb5_get_renewed_creds (context, creds, client, ccache, in_tkt_service);
+#else
+ return 1; /* XXX is there something better to return? */
+#endif
+}
+
static int
get_cred_proxiable(krb5_creds *creds)
{
static int
get_cred_proxiable(krb5_creds *creds)
{
gchar *expiry_text;
gchar *tmp;
gchar *expiry_text;
gchar *tmp;
expiry_text = g_strdup_printf (ngettext("Your credentials expire in %d minute",
"Your credentials expire in %d minutes",
minutes),
minutes);
expiry_text = g_strdup_printf (ngettext("Your credentials expire in %d minute",
"Your credentials expire in %d minutes",
minutes),
minutes);
expiry_text = g_strdup (_("Your credentials have expired"));
tmp = g_strdup_printf ("<span foreground=\"red\">%s</span>", expiry_text);
g_free (expiry_text);
expiry_text = g_strdup (_("Your credentials have expired"));
tmp = g_strdup_printf ("<span foreground=\"red\">%s</span>", expiry_text);
g_free (expiry_text);
}
minutes_left = (creds_expiry - now) / 60;
}
minutes_left = (creds_expiry - now) / 60;
expiry_text = minutes_to_expiry_text (minutes_left);
expiry_markup = g_strdup_printf ("<span size=\"smaller\" style=\"italic\">%s</span>", expiry_text);
expiry_text = minutes_to_expiry_text (minutes_left);
expiry_markup = g_strdup_printf ("<span size=\"smaller\" style=\"italic\">%s</span>", expiry_text);
gchar *prompt;
int pw4len;
gchar *prompt;
int pw4len;
- if (krb5prompt == NULL)
+ if (krb5prompt == NULL) {
prompt = g_strdup (_("Please enter your Kerberos password."));
prompt = g_strdup (_("Please enter your Kerberos password."));
/* Kerberos's prompts are a mess, and basically impossible to
* translate. There's basically no way short of doing a lot of
* string parsing to translate them. The most common prompt is
/* Kerberos's prompts are a mess, and basically impossible to
* translate. There's basically no way short of doing a lot of
* string parsing to translate them. The most common prompt is
* cannot do any of the fancier strings (like challenges),
* though. */
pw4len = strlen ("Password for ");
* cannot do any of the fancier strings (like challenges),
* though. */
pw4len = strlen ("Password for ");
- if (strncmp (krb5prompt, "Password for ", pw4len) == 0)
- {
+ if (strncmp (krb5prompt, "Password for ", pw4len) == 0) {
gchar *uid = (gchar *) (krb5prompt + pw4len);
prompt = g_strdup_printf (_("Please enter the password for '%s'"), uid);
gchar *uid = (gchar *) (krb5prompt + pw4len);
prompt = g_strdup_printf (_("Please enter the password for '%s'"), uid);
prompt = g_strdup (krb5prompt);
prompt = g_strdup (krb5prompt);
}
/* Clear the password entry field */
}
/* Clear the password entry field */
wrong_label = glade_xml_get_widget (xml, "krb5_wrong_label");
wrong_text = NULL;
wrong_label = glade_xml_get_widget (xml, "krb5_wrong_label");
wrong_text = NULL;
- if (wrong_label)
- {
- if (invalid_password)
+ if (wrong_label) {
+ if (invalid_password) {
wrong_text = g_strdup (_("The password you entered is invalid"));
wrong_text = g_strdup (_("The password you entered is invalid"));
krb5_timestamp now;
int minutes_left;
krb5_timestamp now;
int minutes_left;
wrong_markup = g_strdup_printf ("<span size=\"smaller\" style=\"italic\">%s</span>", wrong_text);
gtk_label_set_markup (GTK_LABEL (wrong_label), wrong_markup);
g_free(wrong_text);
g_free(wrong_markup);
wrong_markup = g_strdup_printf ("<span size=\"smaller\" style=\"italic\">%s</span>", wrong_text);
gtk_label_set_markup (GTK_LABEL (wrong_label), wrong_markup);
g_free(wrong_text);
g_free(wrong_markup);
gtk_label_set_text (GTK_LABEL (wrong_label), "");
gtk_label_set_text (GTK_LABEL (wrong_label), "");
dialog = glade_xml_get_widget (xml, "krb5_dialog");
dialog = glade_xml_get_widget (xml, "krb5_dialog");
- for (i = 0; i < num_prompts; i++)
- {
+ for (i = 0; i < num_prompts; i++) {
const gchar *password = NULL;
int password_len = 0;
int response;
const gchar *password = NULL;
int password_len = 0;
int response;
retval = TRUE;
/* If our creds are expiring, determine whether they are renewable */
retval = TRUE;
/* If our creds are expiring, determine whether they are renewable */
- if (retval && get_cred_renewable(&my_creds) && my_creds.times.renew_till > now)
+ if (retval && get_cred_renewable(&my_creds) && my_creds.times.renew_till > now) {
krb5_free_cred_contents (kcontext, &my_creds);
krb5_free_cred_contents (kcontext, &my_creds);
return retval;
krb5_get_init_creds_opt_init (&opts);
return retval;
krb5_get_init_creds_opt_init (&opts);
- if (get_tgt_from_ccache (kcontext, &my_creds))
- {
+ if (get_tgt_from_ccache (kcontext, &my_creds)) {
set_options_using_creds (kcontext, &my_creds, &opts);
creds_expiry = my_creds.times.endtime;
set_options_using_creds (kcontext, &my_creds, &opts);
creds_expiry = my_creds.times.endtime;
-#ifdef HAVE_KRB5_GET_RENEWED_CREDS
- retval = krb5_get_renewed_creds (kcontext, &my_creds, kprincipal, ccache, NULL);
+ retval = get_renewed_creds (kcontext, &my_creds, kprincipal, ccache, NULL);
/* If we succeeded in renewing the credentials, we store it. */
/* If we succeeded in renewing the credentials, we store it. */
/* Else, try to get new credentials, so just fall through */
}
/* Else, try to get new credentials, so just fall through */
}
krb5_free_cred_contents (kcontext, &my_creds);
} else {
creds_expiry = 0;
krb5_free_cred_contents (kcontext, &my_creds);
} else {
creds_expiry = 0;
if (canceled) {
canceled_creds_expiry = creds_expiry;
}
if (canceled) {
canceled_creds_expiry = creds_expiry;
}
switch (retval) {
case KRB5KDC_ERR_PREAUTH_FAILED:
case KRB5KRB_AP_ERR_BAD_INTEGRITY:
switch (retval) {
case KRB5KDC_ERR_PREAUTH_FAILED:
case KRB5KRB_AP_ERR_BAD_INTEGRITY:
store:
retval = krb5_cc_initialize(kcontext, ccache, kprincipal);
store:
retval = krb5_cc_initialize(kcontext, ccache, kprincipal);
retval = krb5_cc_store_cred(kcontext, ccache, &my_creds);
retval = krb5_cc_store_cred(kcontext, ccache, &my_creds);
creds_expiry = my_creds.times.endtime;
out:
creds_expiry = my_creds.times.endtime;
out:
memset(&ccache, 0, sizeof(ccache));
ret = FALSE;
memset(&ccache, 0, sizeof(ccache));
ret = FALSE;
- if (krb5_cc_default(context, &ccache) == 0)
- {
+ if (krb5_cc_default(context, &ccache) == 0) {
memset(&principal, 0, sizeof(principal));
memset(&principal, 0, sizeof(principal));
- if (krb5_cc_get_principal(context, ccache, &principal) == 0)
- {
+ if (krb5_cc_get_principal(context, ccache, &principal) == 0) {
memset(&tgt_principal, 0, sizeof(tgt_principal));
if (krb5_build_principal_ext(context, &tgt_principal,
get_principal_realm_length(principal),
memset(&tgt_principal, 0, sizeof(tgt_principal));
if (krb5_build_principal_ext(context, &tgt_principal,
get_principal_realm_length(principal),
if (krb5_cc_retrieve_cred(context, ccache,
0,
&mcreds,
if (krb5_cc_retrieve_cred(context, ccache,
0,
&mcreds,
ret = TRUE;
} else {
memset(creds, 0, sizeof(*creds));
ret = TRUE;
} else {
memset(creds, 0, sizeof(*creds));
krb5_creds creds;
err = krb5_init_context(&kcontext);
krb5_creds creds;
err = krb5_init_context(&kcontext);
have_tgt = get_tgt_from_ccache(kcontext, &creds);
if (have_tgt) {
have_tgt = get_tgt_from_ccache(kcontext, &creds);
if (have_tgt) {
client = gnome_master_client ();
gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY);
client = gnome_master_client ();
gnome_client_set_restart_style (client, GNOME_RESTART_ANYWAY);
- if (run_always && !run_auto)
+ if (run_always && !run_auto) {
- if (using_krb5 () || always_run)
- {
+ }
+ if (using_krb5 () || always_run) {
g_signal_connect (G_OBJECT (client), "die",
G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (G_OBJECT (client), "die",
G_CALLBACK (gtk_main_quit), NULL);
#ifdef ENABLE_NETWORK_MANAGER
nm_context = libnm_glib_init ();
#ifdef ENABLE_NETWORK_MANAGER
nm_context = libnm_glib_init ();
g_warning ("Could not initialize libnm_glib");
g_warning ("Could not initialize libnm_glib");
nm_callback_id = libnm_glib_register_callback (nm_context, network_state_cb, &is_online, NULL);
nm_callback_id = libnm_glib_register_callback (nm_context, network_state_cb, &is_online, NULL);
- if (nm_callback_id == 0)
- {
+ if (nm_callback_id == 0) {
libnm_glib_shutdown (nm_context);
nm_context = NULL;
libnm_glib_shutdown (nm_context);
nm_context = NULL;
xml = glade_xml_new (GLADEDIR "krb5-auth-dialog.glade", NULL, NULL);
dialog = glade_xml_get_widget (xml, "krb5_dialog");
xml = glade_xml_new (GLADEDIR "krb5-auth-dialog.glade", NULL, NULL);
dialog = glade_xml_get_widget (xml, "krb5_dialog");
- if (credentials_expiring (NULL))
+ if (credentials_expiring (NULL)) {
g_timeout_add (CREDENTIAL_CHECK_INTERVAL * 1000, (GSourceFunc)credentials_expiring, NULL);
g_timeout_add (CREDENTIAL_CHECK_INTERVAL * 1000, (GSourceFunc)credentials_expiring, NULL);