3

我正在开发一个使用 GSSAPI 登录服务器的 C++ 客户端。对于凭证,我使用 gss 方法来构建凭证对象(在下面的代码中解释)。我这部分的代码是

#include <gssapi.h>             
#include <gssapi_krb5.h>
#include <gssapi/gssapi_generic.h>
#include <gssapi/gssapi_ext.h>

gss_cred_id_t method_to_get_cred(){

      char *username = "asanyal@DOMAIN.COM";
      char *password = "correctpassword";
      gss_buffer_desc send_tok;
      OM_uint32 maj_stat, min_stat;
      gss_cred_id_t cred;
      gss_name_t gss_username;
      gss_OID_set_desc mechs, *mechsp = GSS_C_NO_OID_SET;
      gss_buffer_desc pwbuf;

      send_tok.value = username;
      send_tok.length = strlen(username);

      maj_stat = gss_import_name(&min_stat, &send_tok,(
             gss_OID) gss_nt_user_name,&gss_username);
      if (maj_stat != GSS_S_COMPLETE) {
         printf("parsing client name %d %d \n ", maj_stat, min_stat);
         return -1;
        }
        printf("Maj stat after gss_import_name: %d \n", maj_stat);
         printf("Acquired username \n");
     //getting username complete

     //getting password

      pwbuf.value = password;
      pwbuf.length = strlen(password);

      maj_stat = gss_acquire_cred_with_password(&min_stat,
          gss_username,
          &pwbuf, 0,
          mechsp, GSS_C_INITIATE,
          &cred, NULL, NULL);
          printf("Acquired password \n");


      //getting password complete
       printf("Maj stat and min stat after gss_acquire_cred_with_password: %d %d\n",     maj_stat, min_stat);
           return(cred);
}

现在我正在打印主要状态(gssapi 级别状态)和次要状态(机制级别状态)——在这种情况下是 Kerberos。当我给登录用户(即 asanyal)时,状态 printf 消息为两个值都给出 0(一切顺利)

但是,当我使用不同的用户名(这个用户名在 Active Directory 中注册但我没有以他的身份登录)时,我得到了

majstat = 851968 and minstat = -1765328243

进一步调查显示,此次要状态消息对应于错误

KRB5_CC_NOTFOUND    Matching credential not found

我确定我正在为未登录的用户传递正确的凭据(用户名密码))

Is this something wrong with GSSAPI internally(maybe its unable to get a ticket or something) or am I making some mistake?

Configuration used : Windows Active Directory (Windows Server 2008) and MIT kerberos libraries - version 4.0.1

4

1 回答 1

3

Ok i figured it out, the GSS-API does not include any API calls to directly obtain TGT, ST. For that you need the krb api(in case of underlying kerberos mechanism). Typically you would need a function like:-

krb5_get_init_creds_password(context,&creds,principal,conn->passwd,NULL,NULL,NULL,NULL,opts))            //these are the arguments i specified in my program

along with certain context, credential cache and principal initialization parts.

于 2013-03-21T09:26:50.983 回答