我正在尝试使用gsasl认证到Active Directory域。我已经作为管理员kinit了。我试图遵循gsasl tests/gssapi.c中的测试代码,但在调用gsasl_step64()时,下面的代码失败并出现GSASL_GSSAPI_INIT_SEC_CONTEXT_ERROR。
static int callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
{
int ret = GSASL_NO_CALLBACK;
switch (prop) {
case GSASL_AUTHZID:
gsasl_property_set(sctx, GSASL_AUTHZID, "Administrator");
ret = GSASL_OK;
break;
case GSASL_SERVICE:
gsasl_property_set(sctx, prop, "host");
ret = GSASL_OK;
break;
case GSASL_HOSTNAME:
char hostname[HOST_NAME_MAX];
gethostname(hostname, HOST_NAME_MAX);
gsasl_property_set(sctx, prop, hostname);
ret = GSASL_OK;
break;
default:
break;
}
return ret;
}
int main()
{
Gsasl *ctx = NULL;
Gsasl_session *session;
char *s1 = NULL, *s2 = NULL;
int ret;
ret = gsasl_init(&ctx);
if (ret != GSASL_OK) {
cerr << "gsasl_init failed" << endl;
return ret;
}
if (!gsasl_client_support_p(ctx, "GSSAPI")) {
cerr << "No support for GSSAPI." << endl;
return 77;
}
gsasl_callback_set(ctx, callback);
ret = gsasl_client_start(ctx, "GSSAPI", &session);
if (ret != GSASL_OK) {
cerr << "gsasl_client_start failed" << endl;
return ret;
}
do {
ret = gsasl_step64(session, s2, &s1);
gsasl_free(s2);
if (ret != GSASL_OK && ret != GSASL_NEEDS_MORE) {
cerr << "gsasl_step64 failed " << ret << endl;
return ret;
}
} while (ret != GSASL_OK);
if (s1) {
gsasl_free(s1);
}
gsasl_finish(session);
}
有人看出我错在哪里了吗?