Developer's Guide to Oracle® Solaris 11 Security

Exit Print View

Updated: July 2014

Miscellaneous GSSAPI Context Operations on the Client Side

    As a sample program, gss-client performs some functions for demonstration purposes. The following source code is not essential for the basic task, but is provided to demonstrate these other operations:

  • Saving and restoring the context

  • Displaying context flags

  • Obtaining the context status

The source code for these operations is shown in the following example.

Note - The source code for this example is also available through the Oracle download center. See
Example 5-5  gss-client: call_server() Establish Context
/* Save and then restore the context */
     maj_stat = gss_export_sec_context(&min_stat,
     if (maj_stat != GSS_S_COMPLETE) {
             display_status("exporting context", maj_stat, min_stat);
             return -1;
     maj_stat = gss_import_sec_context(&min_stat,
     if (maj_stat != GSS_S_COMPLETE) {
        display_status("importing context", maj_stat, min_stat);
        return -1;
     (void) gss_release_buffer(&min_stat, &context_token);

     /* display the flags */

     /* Get context information */
     maj_stat = gss_inquire_context(&min_stat, context,
                                    &src_name, &targ_name, &lifetime,
                                    &mechanism, &context_flags,
     if (maj_stat != GSS_S_COMPLETE) {
         display_status("inquiring context", maj_stat, min_stat);
         return -1;

     if (maj_stat == GSS_S_CONTEXT_EXPIRED) {
     printf(" context expired\n");
         display_status("Context is expired", maj_stat, min_stat);
         return -1;