1 /* callbacks.c --- Implementation of gsasl callbacks.
2 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Simon Josefsson
4 * This file is part of GNU SASL.
6 * This program 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 3 of the License, or
9 * (at your option) any later version.
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "callbacks.h"
28 locale_to_utf8 (char *str
)
30 #if HAVE_LANGINFO_CODESET
33 char *from
= nl_langinfo (CODESET
);
34 char *q
= str_iconv (str
, from
, "UTF-8");
36 fprintf (stderr
, "warning: Could not convert string to UTF-8...\n");
49 readutf8line (const char *prompt
)
51 char *p
= readline (prompt
);
53 return locale_to_utf8 (p
);
57 readutf8pass (const char *prompt
)
59 char *p
= getpass (prompt
);
61 return locale_to_utf8 (p
);
65 callback (Gsasl
* ctx
, Gsasl_session
* sctx
, Gsasl_property prop
)
67 int rc
= GSASL_NO_CALLBACK
;
71 case GSASL_ANONYMOUS_TOKEN
:
72 if (args_info
.anonymous_token_arg
== NULL
)
73 args_info
.anonymous_token_arg
=
74 readutf8line ("Enter anonymous token (e.g., email address): ");
76 gsasl_property_set (sctx
, GSASL_ANONYMOUS_TOKEN
,
77 args_info
.anonymous_token_arg
);
83 if (args_info
.password_arg
== NULL
)
84 args_info
.password_arg
= readutf8pass ("Enter password: ");
86 gsasl_property_set (sctx
, GSASL_PASSWORD
, args_info
.password_arg
);
92 if (args_info
.passcode_arg
== NULL
)
93 args_info
.passcode_arg
= readutf8pass ("Enter passcode: ");
95 gsasl_property_set (sctx
, GSASL_PASSCODE
, args_info
.passcode_arg
);
101 if (args_info
.authentication_id_arg
== NULL
)
110 if (pw
&& pw
->pw_name
)
112 printf ("Using system username `%s' as "
113 "authentication identity.\n", pw
->pw_name
);
114 args_info
.authentication_id_arg
= strdup (pw
->pw_name
);
118 args_info
.authentication_id_arg
=
119 readutf8line ("Enter authentication ID: ");
122 gsasl_property_set (sctx
, GSASL_AUTHID
,
123 args_info
.authentication_id_arg
);
128 gsasl_property_set (sctx
, GSASL_AUTHZID
,
129 args_info
.authorization_id_arg
);
134 if (args_info
.service_arg
== NULL
)
135 args_info
.service_arg
=
136 readutf8line ("Enter GSSAPI service name (e.g. \"imap\"): ");
138 gsasl_property_set (sctx
, GSASL_SERVICE
, args_info
.service_arg
);
144 if (args_info
.hostname_arg
== NULL
)
145 args_info
.hostname_arg
= readutf8line ("Enter hostname of server: ");
147 gsasl_property_set (sctx
, GSASL_HOSTNAME
, args_info
.hostname_arg
);
153 if (args_info
.realm_arg
== NULL
)
154 args_info
.realm_arg
=
155 readutf8line ("Enter realm of server (optional): ");
157 if (args_info
.realm_arg
&& *args_info
.realm_arg
)
158 gsasl_property_set (sctx
, GSASL_REALM
, args_info
.realm_arg
);
163 case GSASL_VALIDATE_GSSAPI
:
166 printf ("Authzid: %s\nDisplay Name: %s\n",
167 gsasl_property_fast (sctx
, GSASL_AUTHZID
),
168 gsasl_property_fast (sctx
, GSASL_GSSAPI_DISPLAY_NAME
));
169 str
= readutf8line ("Validate GSS-API user? (y/n) ");
170 if (strcmp (str
, "y") == 0 || strcmp (str
, "Y") == 0)
173 rc
= GSASL_AUTHENTICATION_ERROR
;
179 printf ("Mechanism requested unsupported property `%d'.\n", prop
);