GSS-API Programming Guide


This is the entrypoint to the program. The program takes the following syntax on the command line:

gss-client [-port port] [-d] [-mech mech] host service msg

After parsing the command line, main() converts the name of the appropriate security mechanism (if provided) to an OID, establishes a secure connection, and then destroys the mechanism OID, if necessary.

Note –

main() uses a nonstandard function, gss_release_oid(). This function is not supported by all implementations of the GSS-API and should not be used if possible. Since applications should use a default mechanism (specified by GSS_C_NULL_OID) instead of allocating one of their own, this function should not be needed in any case. It is included here for reasons of backward compatibility and to show the full extent of this implementation of the GSS-API.

Example A–2 main()

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
          argc--; argv++;
     if (argc != 3)

     if (argc > 1) {
                strcpy(hostname, argv[0]);
        } else if (gethostname(hostname, sizeof(hostname)) == -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)

     if (g_mechOid != GSS_C_NULL_OID)
         (void) gss_release_oid(&min_stat, &gmechOid);
     return 0;