0

I am using gssapi in C for the first time. I am trying to reconstruct example on Oracle doc http://docs.oracle.com/cd/E19683-01/816-1331/sampleprogs-1/index.html. In my .c file I call gss_str_to_oid(&min_stat, &tok, oid); and get an undefined reference error. I included #include "gssapi.h" at the top of my .c file. In gssapi.h there is a function call

OM_uint32 KRB5_CALLCONV
gss_str_to_oid(
    OM_uint32 *,        /* minor_status */
    gss_buffer_t,       /* oid_str */
    gss_OID *); 

So what am I doing wrong? I thought that if you included #include "gssapi.h" it would give me access to function in gssapi. Both files are in my src folder. So what am I doing wrong. I am using eclipse and from what in my makefile under targets it says all: GSS-API. I am including most of my code below.

main

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <error.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "gssapi.h"
#include "gssapi_ext.h"
#include "gss-misc.h"

/* global mech oid needed by display status, and acquire cred */
FILE *display_file;
gss_OID g_mechOid = GSS_C_NULL_OID;


void usage()
{
     fprintf(stderr, "Usage: gss-client [-port port] [-d]"
                        " [-mech mechOid] host service msg\n");
     exit(1);
}

static void parse_oid(char *mechanism, gss_OID *oid)
{
    char        *mechstr = 0, *cp;
    gss_buffer_desc tok;
    OM_uint32 maj_stat, min_stat;

    if (isdigit(mechanism[0])) {
        mechstr = malloc(strlen(mechanism)+5);
        if (!mechstr) {
            printf("Couldn't allocate mechanism scratch!\n");
            return;
        }
        sprintf(mechstr, "{ %s }", mechanism);
        for (cp = mechstr; *cp; cp++)
            if (*cp == '.')
                *cp = ' ';
        tok.value = mechstr;
    } else
        tok.value = mechanism;
    tok.length = strlen(tok.value);
      maj_stat = gss_str_to_oid(&min_stat, &tok, oid);
    if (maj_stat != GSS_S_COMPLETE) {
 //       display_status("str_to_oid", maj_stat, min_stat);
        return;
    }
    if (mechstr)
        free(mechstr);
}

int main(argc, argv)
     int argc;
     char **argv;
{
    /* char *service_name, *hostname, *msg; */
     char *msg;
     char service_name[128];
     char hostname[128];
     char *mechanism = 0;
     u_short port = 4444;
     int use_file = 0;
     OM_uint32 deleg_flag = 0, min_stat;

     display_file = stdout;

     /* Parse arguments. */

     argc--; argv++;
     while (argc) {
          if (strcmp(*argv, "-port") == 0) {
               argc--; argv++;
               if (!argc) usage();
               port = atoi(*argv);
           } else if (strcmp(*argv, "-mech") == 0) {
               argc--; argv++;
               if (!argc) usage();
               mechanism = *argv;
           } else if (strcmp(*argv, "-d") == 0) {
               deleg_flag = GSS_C_DELEG_FLAG;
          } else if (strcmp(*argv, "-f") == 0) {
               use_file = 1;
          } else
                break;
          argc--; argv++;
     }
     if (argc != 3)
          usage();

     if (argc > 1) {
                strcpy(hostname, argv[0]);
        } else if (gethostname(hostname, sizeof(hostname)) == -1) {
                        perror("gethostname");
                        exit(1);
        }


     if (argc > 2) {
        strcpy(service_name, argv[1]);
        strcat(service_name, "@");
        strcat(service_name, hostname);

     }

      msg = argv[2];

     if (mechanism)
         parse_oid(mechanism, &g_mechOid);

/*     if (call_server(hostname, port, g_mechOid, service_name,
                   deleg_flag, msg, use_file) < 0)
          exit(1);*/

/*
     if (g_mechOid != GSS_C_NULL_OID)
         (void) gss_release_oid(&min_stat, &gmechOid);
*/

     return 0;
}

gssapi.h

/* New for V2 */
OM_uint32 KRB5_CALLCONV
gss_str_to_oid(
    OM_uint32 *,        /* minor_status */
    gss_buffer_t,       /* oid_str */
    gss_OID *);  
Aaron
  • 4,380
  • 19
  • 85
  • 141

3 Answers3

1

You just can't include the header you have to link the library either dynamically or statically. Is there some dll, lib, so, etc you need to add to your project? Without makefile or your project setup been shown in your question; I think you will not receive a very clear answer. Just including header file isn't enough, the undefined is not a compilation error but a linker error, which means its missing a reference because you are not linking the library to your program.

Daniel Lopez
  • 1,728
  • 3
  • 24
  • 40
  • I have written c programs in eclipse before and have never had this problem or had to write a make. Why would I have to here? – Aaron Apr 14 '15 at 22:05
  • You never make mistake doesn't mean you can't make a mistake in the future. If there is a library that came with those headers include it in your project, or else the undefined references will never go away. I am afraid that is the only way. Unless you have linked the library. If am not being clear I can give you a specific instruction on how to do so in eclipse. – Daniel Lopez Apr 14 '15 at 22:19
  • A link would be great on what to do to the makefile in ecslipse. I know eclipse creates a makefile for you, I thought that automatically linked the files. But I guess I am wrong – Aaron Apr 14 '15 at 22:26
0

The documentation for GSSAPI in C and C++ in not the greatest. Turns out you need to download gssapi. Here is the link http://www.gnu.org/software/gss/manual/gss.html. It is under download and install

Aaron
  • 4,380
  • 19
  • 85
  • 141
0

So, I faced same problem. I found out that you need to add some .so files to your project.

Just in case check that your system has libkrb5-dev packet (most likely it is already installed if you have gssapi.h).

Required files are stored in folder "/usr/lib/x86_64-linux-gnu/" (debian in my case):

list of files

I added libkdb5.so and libgssapi_krb5.so to QT .pro file and all works fine:

LIBS += -lkdb5
LIBS += -lgssapi_krb5

If you need to find that files .so use folloing commands:

apt-file update
dpkg -L libkrb5-dev
Ivan
  • 445
  • 4
  • 6