#include <iostream>

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include "globus_gss_assist.h"
#include "tokens.h"

int main()
{
  assert(globus_module_activate(GLOBUS_GSI_GSSAPI_MODULE) == GLOBUS_SUCCESS);

  int acceptor = socket(AF_INET, SOCK_STREAM, 0);
  assert(acceptor != -1);

  struct sockaddr_in me;
  memset ((char *)&me, 0, sizeof(struct sockaddr_in));
  me.sin_family = AF_INET;
  me.sin_addr.s_addr = INADDR_ANY;
  me.sin_port = htons(10001);

  assert(bind(acceptor, (struct sockaddr*)&me, sizeof(struct sockaddr_in)) != -1);
  assert(listen(acceptor, 10) != -1);

  OM_uint32 major = 0, minor = 0;

  gss_cred_id_t credential = GSS_C_NO_CREDENTIAL;

  major = globus_gss_assist_acquire_cred(&minor,
                                         GSS_C_BOTH,
                                         &credential);

  if(GSS_ERROR(major))
  {
    char * str = NULL;
    globus_gss_assist_display_status_str(&str,
                                         "Failed to acquire credentials : ",
                                         major, minor, 0);
    std::cout << str;
    exit(1);
  }

  struct sockaddr_in him;
  socklen_t addrlen = sizeof(struct sockaddr_in);

  int sck = accept(acceptor, (struct sockaddr*)&him, &addrlen);

  gss_ctx_id_t context = GSS_C_NO_CONTEXT;
  char * name = NULL;
  OM_uint32 flags = 0;
  int token_status = 0;
  gss_cred_id_t delegated_cred = GSS_C_NO_CREDENTIAL;

  major = globus_gss_assist_accept_sec_context(&minor,
                                               &context,
                                               credential,
                                               &name,
                                               &flags,
                                               NULL,
                                               &token_status,
                                               &delegated_cred,
                                               &get_token,
                                               (void *) &sck,
                                               &send_token,
                                               (void *) &sck);

  if(GSS_ERROR(major))
  {
    std::cout << "Major : " << minor << std::endl;
    std::cout << "Minor : " << major << std::endl;

    char * str = NULL;
    globus_gss_assist_display_status_str(&str,
                                         "Failed to establish security context : ",
                                         major, minor, 0);
    std::cout << str;
    exit(1);
  }

  if(name)
    std::cout << name << std::endl;

  gss_delete_sec_context(&minor,
                         &context,
                         GSS_C_NO_BUFFER);

  gss_release_cred(&minor,
                   &credential);


  assert(globus_module_deactivate(GLOBUS_GSI_GSSAPI_MODULE) == GLOBUS_SUCCESS);

}



Topic revision: r1 - 2006-07-13 - ValerioVenturi
 
TWIKI.NET
This site is powered by the TWiki collaboration platformCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback