#include #include #include /*+ * Function: display_status * * Purpose: displays GSS-API messages * * Arguments: * * msg a string to be displayed with the message * maj_stat the GSS-API major status code * min_stat the GSS-API minor status code * * Effects: * * The GSS-API messages associated with maj_stat and min_stat are * displayed on stderr, each preceeded by "GSS-API error : " and * followed by a newline. */ static void display_status_1(char *m, OM_uint32 code, int type) { OM_uint32 maj_stat, min_stat; gss_buffer_desc msg; OM_uint32 msg_ctx; msg_ctx = 0; while (1) { maj_stat = gss_display_status(&min_stat, code, type, GSS_C_NULL_OID, &msg_ctx, &msg); printf("GSS-API error %s: %s\r\n", m, (char *)msg.value); (void) gss_release_buffer(&min_stat, &msg); if (!msg_ctx) break; } } void display_status (char *msg, OM_uint32 maj_stat, OM_uint32 min_stat) { display_status_1(msg, maj_stat, GSS_C_GSS_CODE); display_status_1(msg, min_stat, GSS_C_MECH_CODE); } void usage(char * app) { fprintf(stderr, "usage: %s principal-name\n",app); } int main(int argc, char *argv[]) { gss_buffer_desc name_val; gss_OID_set mech_names; gss_name_t name_hdl; OM_uint32 maj_stat; OM_uint32 min_stat; gss_name_t src_name, targ_name; gss_buffer_desc sname, tname; OM_uint32 lifetime; gss_OID mechanism, name_type; int is_local; OM_uint32 context_flags; int is_open; gss_qop_t qop_state; gss_buffer_desc oid_name; size_t i; int token_flags; gss_cred_id_t cred_hdl; gss_ctx_id_t context; if ( argc < 2 ) { usage(argv[0]); return(1); } name_val.value = argv[1]; name_val.length = strlen(name_val.value); name_type = GSS_C_NT_USER_NAME; maj_stat = gss_import_name(&min_stat, &name_val, name_type, &name_hdl); if (maj_stat != GSS_S_COMPLETE) { display_status("gss_import_name", maj_stat, min_stat); return -1; } maj_stat = gss_acquire_cred(&min_stat, name_hdl, GSS_C_INDEFINITE, NULL, GSS_C_INITIATE, &cred_hdl, NULL, NULL); if (maj_stat != GSS_S_COMPLETE) { display_status("client's gss_acquire_cred", maj_stat, min_stat); return -1; } return 0; }