1 /* callbacks.c --- Implementation of gsasl callbacks.
2 * Copyright (C) 2002, 2003, 2004, 2005, 2006 Simon Josefsson
4 * This file is part of GNU SASL.
6 * GNU SASL is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNU SASL is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU SASL; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "callbacks.h"
29 locale_to_utf8 (char *str
)
31 #if HAVE_LANGINFO_CODESET
34 char *from
= nl_langinfo (CODESET
);
35 char *q
= iconv_string (str
, from
, "UTF-8");
37 fprintf (stderr
, "warning: Could not convert string to UTF-8...\n");
50 readutf8line (const char *prompt
)
52 char *p
= readline (prompt
);
54 return locale_to_utf8 (p
);
58 readutf8pass (const char *prompt
)
60 char *p
= getpass (prompt
);
62 return locale_to_utf8 (p
);
66 callback (Gsasl
* ctx
, Gsasl_session
* sctx
, Gsasl_property prop
)
68 int rc
= GSASL_NO_CALLBACK
;
72 case GSASL_ANONYMOUS_TOKEN
:
73 if (args_info
.anonymous_token_arg
== NULL
)
74 args_info
.anonymous_token_arg
=
75 readutf8line ("Enter anonymous token (e.g., email address): ");
77 gsasl_property_set (sctx
, GSASL_ANONYMOUS_TOKEN
,
78 args_info
.anonymous_token_arg
);
84 if (args_info
.password_arg
== NULL
)
85 args_info
.password_arg
= readutf8pass ("Enter password: ");
87 gsasl_property_set (sctx
, GSASL_PASSWORD
, args_info
.password_arg
);
93 if (args_info
.passcode_arg
== NULL
)
94 args_info
.passcode_arg
= readutf8pass ("Enter passcode: ");
96 gsasl_property_set (sctx
, GSASL_PASSCODE
, args_info
.passcode_arg
);
102 if (args_info
.authentication_id_arg
== NULL
)
111 if (pw
&& pw
->pw_name
)
113 printf ("Using system username `%s' as "
114 "authentication identity.\n", pw
->pw_name
);
115 args_info
.authentication_id_arg
= strdup (pw
->pw_name
);
119 args_info
.authentication_id_arg
=
120 readutf8line ("Enter authentication ID: ");
123 gsasl_property_set (sctx
, GSASL_AUTHID
,
124 args_info
.authentication_id_arg
);
129 gsasl_property_set (sctx
, GSASL_AUTHZID
,
130 args_info
.authorization_id_arg
);
135 if (args_info
.service_arg
== NULL
)
136 args_info
.service_arg
=
137 readutf8line ("Enter GSSAPI service name (e.g. \"imap\"): ");
139 gsasl_property_set (sctx
, GSASL_SERVICE
, args_info
.service_arg
);
145 if (args_info
.hostname_arg
== NULL
)
146 args_info
.hostname_arg
= readutf8line ("Enter hostname of server: ");
148 gsasl_property_set (sctx
, GSASL_HOSTNAME
, args_info
.hostname_arg
);
154 if (args_info
.realm_arg
== NULL
)
155 args_info
.realm_arg
=
156 readutf8line ("Enter realm of server (optional): ");
158 if (args_info
.realm_arg
&& *args_info
.realm_arg
)
159 gsasl_property_set (sctx
, GSASL_REALM
, args_info
.realm_arg
);
165 printf ("Mechanism requested unsupported property `%d'.\n", prop
);