Pergunta

O api Cyrus SASL não suporta o mecanismo externo? eu estou tentando usá-lo como um cliente, mas ele retorna SASL_NOMECH quando solicitado.

% cat cyrus_sal_ex.c
/* 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 */

static char const * SASL_return_code(int const code) 
{
  switch(code) 
  {
    /* ... */
    case SASL_OK:     return "SASL_OK[0]: successful result";
    /* ... */
    case SASL_NOMECH: return "SASL_NOMECH[-4]: mechanism not supported";
    /* ... */
  }
  return "unrecognized";
}

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_return_code(__result));\
    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_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 # your header/library locations may vary
% ./cyrus_sasl_ex
sasl_client_init( NULL ) == 0
        SASL_OK[0]: successful result
sasl_client_new( "fake", "fakey.mcfaker.ton", "127.0.0.1", "127.255.255.1", NULL, 0, &conn) == 0
        SASL_OK[0]: successful result
sasl_client_start( conn, "EXTERNAL", NULL, &output, &outlen, &mechanism) == -4
        SASL_NOMECH[-4]: mechanism not supported
output: [0 bytes] : NULL
mechanism: EXTERNAL
%

Eu naveguei através do fonte, porém, e parece que todos os clientes devem apoiar o mecanismo externo:

cyrus-sasl-2.1.22/lib/client.c:
196 int sasl_client_init(const sasl_callback_t *callbacks)
197 {
...
227
228   sasl_client_add_plugin("EXTERNAL", &external_client_plug_init);
229

Então, eu estou supondo que eu estou fazendo algo errado aqui. Eu tentei adicionar todos os sasl_callback_ts eu poderia pensar para sasl_client_*(), mas nenhum deles sequer foi chamado. Existe algum argumento que deve passar que afirma que EXTERNO é um mecanismo aceitável? Ou é SASL_NOMECH sempre voltava para EXTERNO -. B / c que não parece certo

Alguém pode me ajudar?

Foi útil?

Solução

Ok, eu encontrei o deixou de fora passo.

De acordo com sasl/sasl.h, eu precisava para definir a propriedade SASL_AUTH_EXTERNAL para o meu sasl_conn_t primeiro:

/* 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.
 */

Uma vez eu fiz isso, o resto funcionou:

% 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

No entanto, desde a versão do Cyrus SASL que vem pré-instalado no OS X 10.5 tem um bug em que faz o plugin externo requer um callback SASL_CB_USER e passa um ponteiro NULL para armazenar seu valor de retorno em, isso significa ainda eu vou ter que atualizar Cyrus SASL em todas essas máquinas.

Ou talvez eu só vou código em torno do bug.

Outras dicas

Isso é causado pelo fato de que Cyrus SASL foi compilado sem mecanismos (eles são assumidos para ser dinamicamente ligada por padrão). Portanto, se houver mecanismos ligados não dinamicamente ele irá informar que não existem mecanismos correspondentes.

Portanto, a melhor resposta é recompilar Cyrus SASL com os mecanismos (chamados plugins no pacote Cyrus) ligados estaticamente. Se você olhar para o cabeçalho config.h e #define os define estáticos correspondente a 1 depois recompilação (i adicionados manualmente as fontes de plug-in a partir das plugins dir para o arquivo libsasl2.a). Então, quando você ligar esta biblioteca você não vai conseguir esse erro (sem a solução que você encontrou).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top