---
name: "gss_accept_sec_context"
section: "3"
platform: "linux"
package: "gss-man"
version: "1.0.4-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/gss_accept_sec_context"
---

# gss\_accept\_sec\_context(3)

API function

## NAME

gss\_accept\_sec\_context - API function

## SYNOPSIS

**#include \<gss.h\>**

**OM\_uint32 gss\_accept\_sec\_context(OM\_uint32 \*** *minor\_status***, gss\_ctx\_id\_t \*** *context\_handle***, const gss\_cred\_id\_t** *acceptor\_cred\_handle***, const gss\_buffer\_t** *input\_token\_buffer***, const gss\_channel\_bindings\_t** *input\_chan\_bindings***, gss\_name\_t \*** *src\_name***, gss\_OID \*** *mech\_type***, gss\_buffer\_t** *output\_token***, OM\_uint32 \*** *ret\_flags***, OM\_uint32 \*** *time\_rec***, gss\_cred\_id\_t \*** *delegated\_cred\_handle***);**

## ARGUMENTS

- OM\_uint32 \* minor\_status

  (Integer, modify) Mechanism specific status code.

- gss\_ctx\_id\_t \* context\_handle

  (gss\_ctx\_id\_t, read/modify) Context handle for new\
     context.  Supply GSS\_C\_NO\_CONTEXT for first call; use value\
     returned in subsequent calls.  Once **gss\_accept\_sec\_context()** has\
     returned a value via this parameter, resources have been assigned\
     to the corresponding context, and must be freed by the\
     application after use with a call to **gss\_delete\_sec\_context()**.

- const gss\_cred\_id\_t acceptor\_cred\_handle

  (gss\_cred\_id\_t, read) Credential handle\
     claimed by context acceptor. Specify GSS\_C\_NO\_CREDENTIAL to\
     accept the context as a default principal.  If\
     GSS\_C\_NO\_CREDENTIAL is specified, but no default acceptor\
     principal is defined, GSS\_S\_NO\_CRED will be returned.

- const gss\_buffer\_t input\_token\_buffer

  (buffer, opaque, read) Token obtained from\
     remote application.

- const gss\_channel\_bindings\_t input\_chan\_bindings

  (channel bindings, read, optional)\
     Application- specified bindings.  Allows application to securely\
     bind channel identification information to the security context.\
     If channel bindings are not used, specify\
     GSS\_C\_NO\_CHANNEL\_BINDINGS.

- gss\_name\_t \* src\_name

  (gss\_name\_t, modify, optional) Authenticated name of\
     context initiator.  After use, this name should be deallocated by\
     passing it to **gss\_release\_name()**.  If not required, specify NULL.

- gss\_OID \* mech\_type

  (Object ID, modify, optional) Security mechanism used.\
     The returned OID value will be a pointer into static storage, and\
     should be treated as read-only by the caller (in particular, it\
     does not need to be freed).  If not required, specify NULL.

- gss\_buffer\_t output\_token

  (buffer, opaque, modify) Token to be passed to peer\
     application.  If the length field of the returned token buffer is\
     0, then no token need be passed to the peer application.  If a\
     non- zero length field is returned, the associated storage must\
     be freed after use by the application with a call to\
     **gss\_release\_buffer()**.

- OM\_uint32 \* ret\_flags

  (bit-mask, modify, optional) Contains various\
     independent flags, each of which indicates that the context\
     supports a specific service option.  If not needed, specify NULL.\
     Symbolic names are provided for each flag, and the symbolic names\
     corresponding to the required flags should be logically-ANDed\
     with the ret\_flags value to test whether a given option is\
     supported by the context.  See below for the flags.

- OM\_uint32 \* time\_rec

  (Integer, modify, optional) Number of seconds for which\
     the context will remain valid. Specify NULL if not required.

- gss\_cred\_id\_t \* delegated\_cred\_handle

  (gss\_cred\_id\_t, modify, optional\
     credential) Handle for credentials received from context\
     initiator.  Only valid if deleg\_flag in ret\_flags is true, in\
     which case an explicit credential handle (i.e. not\
     GSS\_C\_NO\_CREDENTIAL) will be returned; if deleg\_flag is false,\
     **gss\_accept\_sec\_context()** will set this parameter to\
     GSS\_C\_NO\_CREDENTIAL.  If a credential handle is returned, the\
     associated resources must be released by the application after\
     use with a call to **gss\_release\_cred()**.  Specify NULL if not\
     required.

## DESCRIPTION

Allows a remotely initiated security context between the application and a remote peer to be established.  The routine may return a output\_token which should be transferred to the peer application, where the peer application will present it to gss\_init\_sec\_context.  If no token need be sent, gss\_accept\_sec\_context will indicate this by setting the length field of the output\_token argument to zero.  To complete the context establishment, one or more reply tokens may be required from the peer application; if so, gss\_accept\_sec\_context will return a status flag of GSS\_S\_CONTINUE\_NEEDED, in which case it should be called again when the reply token is received from the peer application, passing the token to gss\_accept\_sec\_context via the input\_token parameters.

Portable applications should be constructed to use the token length and return status to determine whether a token needs to be sent or waited for.  Thus a typical portable caller should always invoke gss\_accept\_sec\_context within a loop:

\--------------------------------------------------- gss\_ctx\_id\_t context\_hdl = GSS\_C\_NO\_CONTEXT;

do {\
   receive\_token\_from\_peer(input\_token);\
   maj\_stat = gss\_accept\_sec\_context(&min\_stat,\
                                     &context\_hdl,\
                                     cred\_hdl,\
                                     input\_token,\
                                     input\_bindings,\
                                     &client\_name,\
                                     &mech\_type,\
                                     output\_token,\
                                     &ret\_flags,\
                                     &time\_rec,\
                                     &deleg\_cred);\
   if (GSS\_ERROR(maj\_stat)) {\
     report\_error(maj\_stat, min\_stat);\
   };\
   if (output\_token-\>length != 0) {\
     send\_token\_to\_peer(output\_token);

    gss\_release\_buffer(&min\_stat, output\_token);\
   };\
   if (GSS\_ERROR(maj\_stat)) {\
     if (context\_hdl != GSS\_C\_NO\_CONTEXT)\
       gss\_delete\_sec\_context(&min\_stat,\
                              &context\_hdl,\
                              GSS\_C\_NO\_BUFFER);\
     break;\
   }; } while (maj\_stat & GSS\_S\_CONTINUE\_NEEDED); ---------------------------------------------------

Whenever the routine returns a major status that includes the value GSS\_S\_CONTINUE\_NEEDED, the context is not fully established and the following restrictions apply to the output parameters:

The value returned via the time\_rec parameter is undefined Unless the accompanying ret\_flags parameter contains the bit GSS\_C\_PROT\_READY\_FLAG, indicating that per-message services may be applied in advance of a successful completion status, the value returned via the mech\_type parameter may be undefined until the routine returns a major status value of GSS\_S\_COMPLETE.

The values of the GSS\_C\_DELEG\_FLAG, GSS\_C\_MUTUAL\_FLAG,GSS\_C\_REPLAY\_FLAG, GSS\_C\_SEQUENCE\_FLAG, GSS\_C\_CONF\_FLAG,GSS\_C\_INTEG\_FLAG and GSS\_C\_ANON\_FLAG bits returned via the ret\_flags parameter should contain the values that the implementation expects would be valid if context establishment were to succeed.

The values of the GSS\_C\_PROT\_READY\_FLAG and GSS\_C\_TRANS\_FLAG bits within ret\_flags should indicate the actual state at the time gss\_accept\_sec\_context returns, whether or not the context is fully established.

Although this requires that GSS-API implementations set the GSS\_C\_PROT\_READY\_FLAG in the final ret\_flags returned to a caller (i.e. when accompanied by a GSS\_S\_COMPLETE status code), applications should not rely on this behavior as the flag was not defined in Version 1 of the GSS-API. Instead, applications should be prepared to use per-message services after a successful context establishment, according to the GSS\_C\_INTEG\_FLAG and GSS\_C\_CONF\_FLAG values.

All other bits within the ret\_flags argument should be set to zero. While the routine returns GSS\_S\_CONTINUE\_NEEDED, the values returned via the ret\_flags argument indicate the services that the implementation expects to be available from the established context.

If the initial call of **gss\_accept\_sec\_context()** fails, the implementation should not create a context object, and should leave the value of the context\_handle parameter set to GSS\_C\_NO\_CONTEXT to indicate this.  In the event of a failure on a subsequent call, the implementation is permitted to delete the "half-built" security context (in which case it should set the context\_handle parameter to GSS\_C\_NO\_CONTEXT), but the preferred behavior is to leave the security context (and the context\_handle parameter) untouched for the application to delete (using gss\_delete\_sec\_context).

During context establishment, the informational status bits GSS\_S\_OLD\_TOKEN and GSS\_S\_DUPLICATE\_TOKEN indicate fatal errors, and GSS-API mechanisms should always return them in association with a routine error of GSS\_S\_FAILURE.  This requirement for pairing did not exist in version 1 of the GSS-API specification, so applications that wish to run over version 1 implementations must special-case these codes.

The \`ret\_flags\` values:

\`GSS\_C\_DELEG\_FLAG\`:: - True - Delegated credentials are available via the delegated\_cred\_handle parameter. - False - No credentials were delegated.

\`GSS\_C\_MUTUAL\_FLAG\`:: - True - Remote peer asked for mutual authentication. - False - Remote peer did not ask for mutual authentication.

\`GSS\_C\_REPLAY\_FLAG\`:: - True - replay of protected messages will be detected. - False - replayed messages will not be detected.

\`GSS\_C\_SEQUENCE\_FLAG\`:: - True - out-of-sequence protected messages will be detected. - False - out-of-sequence messages will not be detected.

\`GSS\_C\_CONF\_FLAG\`:: - True - Confidentiality service may be invoked by calling the gss\_wrap routine. - False - No confidentiality service (via gss\_wrap) available. gss\_wrap will provide message encapsulation, data-origin authentication and integrity services only.

\`GSS\_C\_INTEG\_FLAG\`:: - True - Integrity service may be invoked by calling either gss\_get\_mic or gss\_wrap routines. - False - Per-message integrity service unavailable.

\`GSS\_C\_ANON\_FLAG\`:: - True - The initiator does not wish to be authenticated; the src\_name parameter (if requested) contains an anonymous internal name. - False - The initiator has been authenticated normally.

\`GSS\_C\_PROT\_READY\_FLAG\`:: - True - Protection services (as specified by the states of the GSS\_C\_CONF\_FLAG and GSS\_C\_INTEG\_FLAG) are available if the accompanying major status return value is either GSS\_S\_COMPLETE or GSS\_S\_CONTINUE\_NEEDED. - False - Protection services (as specified by the states of the GSS\_C\_CONF\_FLAG and GSS\_C\_INTEG\_FLAG) are available only if the accompanying major status return value is GSS\_S\_COMPLETE.

\`GSS\_C\_TRANS\_FLAG\`:: - True - The resultant security context may be transferred to other processes via a call to **gss\_export\_sec\_context()**. - False - The security context is not transferable.

All other bits should be set to zero.

## RETURN VALUE

\`GSS\_S\_CONTINUE\_NEEDED\`: Indicates that a token from the peer application is required to complete the context, and that gss\_accept\_sec\_context must be called again with that token.

\`GSS\_S\_DEFECTIVE\_TOKEN\`: Indicates that consistency checks performed on the input\_token failed.

\`GSS\_S\_DEFECTIVE\_CREDENTIAL\`: Indicates that consistency checks performed on the credential failed.

\`GSS\_S\_NO\_CRED\`: The supplied credentials were not valid for context acceptance, or the credential handle did not reference any credentials.

\`GSS\_S\_CREDENTIALS\_EXPIRED\`: The referenced credentials have expired.

\`GSS\_S\_BAD\_BINDINGS\`: The input\_token contains different channel bindings to those specified via the input\_chan\_bindings parameter.

\`GSS\_S\_NO\_CONTEXT\`: Indicates that the supplied context handle did not refer to a valid context.

\`GSS\_S\_BAD\_SIG\`: The input\_token contains an invalid MIC.

\`GSS\_S\_OLD\_TOKEN\`: The input\_token was too old.  This is a fatal error during context establishment.

\`GSS\_S\_DUPLICATE\_TOKEN\`: The input\_token is valid, but is a duplicate of a token already processed.  This is a fatal error during context establishment.

\`GSS\_S\_BAD\_MECH\`: The received token specified a mechanism that is not supported by the implementation or the provided credential.

## REPORTING BUGS

Report bugs to \<bug-gss@gnu.org\>. GNU Generic Security Service home page: http://www.gnu.org/software/gss/ General help using GNU software: http://www.gnu.org/gethelp/

## COPYRIGHT

Copyright © 2003-2022 Simon Josefsson.\
 Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved.

## SEE ALSO

The full documentation for **gss** is maintained as a Texinfo manual.  If the **info** and **gss** programs are properly installed at your site, the command

-

  **info gss**

should give you access to the complete manual.
