Хорошо, я нашел пропущенный шаг.
Согласно sasl/sasl.h
, мне нужно было установить свойство SASL_AUTH_EXTERNAL
для моего sasl_conn_t
первого:
/* set property in SASL connection state
* returns:
* SASL_OK -- value set
* SASL_BADPARAM -- invalid property or value
*/
LIBSASL_API int sasl_setprop(sasl_conn_t *conn,
int propnum,
const void *value);
#define SASL_SSF_EXTERNAL 100 /* external SSF active (sasl_ssf_t *) */
#define SASL_SEC_PROPS 101 /* sasl_security_properties_t */
#define SASL_AUTH_EXTERNAL 102 /* external authentication ID (const char *) */
/* If the SASL_AUTH_EXTERNAL value is non-NULL, then a special version of the
* EXTERNAL mechanism is enabled (one for server-embedded EXTERNAL mechanisms).
* Otherwise, the EXTERNAL mechanism will be absent unless a plug-in
* including EXTERNAL is present.
*/
Как только я это сделал, все остальное сработало:
% cat cyrus_sasl_ex.c
/* Example of using the Cyrus SASL api */
#include <stdio.h> /* for printf() */
#include <sasl/sasl.h> /* for sasl_client_*(), SASL_*, sasl_*_t */
int main()
{
char const * output = NULL;
unsigned outlen = 0;
char const * mechanism = NULL;
sasl_conn_t * conn;
# define PRINT_RESULT( x ) do\
{\
int const __result = (x);\
printf("%s == %d\n\t%s\n", #x, __result, sasl_errstring(__result,NULL,NULL));\
if (__result < 0) goto done;\
}\
while (0)
PRINT_RESULT( sasl_client_init( NULL ) );
PRINT_RESULT( sasl_client_new( "fake", "fakey.mcfaker.ton", "127.0.0.1", "127.255.255.1", NULL, 0, &conn) );
PRINT_RESULT( sasl_setprop( conn, SASL_AUTH_EXTERNAL, "fake authority" ) );
PRINT_RESULT( sasl_client_start( conn, "EXTERNAL", NULL, &output, &outlen, &mechanism) );
done:
# undef PRINT_RESULT
printf("output: [%d bytes] : %s\n", outlen, (output ? output : "NULL") );
printf("mechanism: %s\n", (mechanism ? mechanism : "NULL"));
return 0;
}
% gcc -I/sw/include -L/sw/lib -lsasl2 cyrus_sasl_ex.c -o cyrus_sasl_ex
% ./cyrus_sasl_ex
sasl_client_init( NULL ) == 0
successful result
sasl_client_new( "fake", "fakey.mcfaker.ton", "127.0.0.1", "127.255.255.1", NULL, 0, &conn) == 0
successful result
sasl_setprop( conn, SASL_AUTH_EXTERNAL, "fake authority" ) == 0
successful result
sasl_client_start( conn, "EXTERNAL", NULL, &output, &outlen, &mechanism) == 0
successful result
output: [0 bytes] :
mechanism: EXTERNAL
Однако, поскольку версия Cyrus SASL, поставляемая с предустановленной версией OS X 10.5, содержит ошибку, из-за которой внешний плагин требует обратного вызова SASL_CB_USER
и передает ему нулевой указатель для сохранения своего возвращаемого значения, это означает, что мне придется обновить Cyrus SASL на всех этих машинах.
Или, может быть, я просто напишу об ошибке.