Skip to content

Commit fe9ff79

Browse files
committed
Add option to set the default NEGOTIATE flags
This requires to explicitly acquire credentials before calling into the ISC or ASC functions. Then setting the new default flags on the credntial. It is not elegant to mix credentials and context flags, but it is the only way to do it in GSSAPI currently, and there is precedent in other mechanisms like KRB5. Signed-off-by: Simo Sorce <[email protected]>
1 parent b2ccd7d commit fe9ff79

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

src/gss_creds.c

+46
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,57 @@ uint32_t gssntlm_inquire_cred_by_mech(uint32_t *minor_status,
717717
return GSSERRS(0, GSS_S_COMPLETE);
718718
}
719719

720+
gss_OID_desc gssntlm_neg_flags_oid = {
721+
GSS_NTLMSSP_NEG_FLAGS_OID_LENGTH,
722+
discard_const(GSS_NTLMSSP_NEG_FLAGS_OID_STRING)
723+
};
724+
725+
static uint32_t gssntlm_set_cred_neg_flags(uint32_t *minor_status,
726+
struct gssntlm_cred *cred,
727+
const gss_buffer_t value)
728+
{
729+
730+
if (cred == NULL || value == NULL) {
731+
*minor_status = EINVAL;
732+
return GSS_S_CALL_INACCESSIBLE_READ;
733+
}
734+
if (value->length == 0) {
735+
/* special to reset to library defaults */
736+
if (cred->type == GSSNTLM_CRED_SERVER) {
737+
cred->neg_flags = NTLMSSP_DEFAULT_SERVER_FLAGS;
738+
} else {
739+
cred->neg_flags = NTLMSSP_DEFAULT_CLIENT_FLAGS;
740+
}
741+
} else if (value->length == sizeof(uint32_t)) {
742+
cred->neg_flags = *(uint32_t *)value->value;
743+
} else {
744+
*minor_status = EINVAL;
745+
return GSS_S_FAILURE;
746+
}
747+
748+
*minor_status = 0;
749+
return GSS_S_COMPLETE;
750+
}
751+
720752
uint32_t gssntlm_set_cred_option(uint32_t *minor_status,
721753
gss_cred_id_t *cred_handle,
722754
const gss_OID desired_object,
723755
const gss_buffer_t value)
724756
{
757+
struct gssntlm_cred *cred;
758+
759+
if (minor_status == NULL) return GSS_S_CALL_INACCESSIBLE_WRITE;
760+
*minor_status = 0;
761+
762+
if (cred_handle == NULL) return GSS_S_CALL_INACCESSIBLE_WRITE;
763+
cred = (struct gssntlm_cred *)*cred_handle;
764+
765+
if (desired_object == GSS_C_NO_OID) return GSS_S_CALL_INACCESSIBLE_READ;
766+
767+
if (gss_oid_equal(desired_object, &gssntlm_neg_flags_oid)) {
768+
return gssntlm_set_cred_neg_flags(minor_status, cred, value);
769+
}
770+
725771
*minor_status = EINVAL;
726772
return GSS_S_UNAVAILABLE;
727773
}

src/gss_ntlmssp.h

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ struct gssntlm_cred {
9595
bool creds_in_cache;
9696
} external;
9797
} cred;
98+
99+
/* set cred options provided default flags
100+
* this is currently intentionally not imported/exported
101+
* as it is considered an ephemeral local status
102+
*/
103+
uint32_t neg_flags;
98104
};
99105

100106
struct gssntlm_ctx {

src/gss_sec_ctx.c

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ uint32_t gssntlm_init_sec_context(uint32_t *minor_status,
116116
ctx->gss_flags = req_flags;
117117

118118
ctx->neg_flags = NTLMSSP_DEFAULT_CLIENT_FLAGS;
119+
/* override neg_flags default if requested */
120+
if (cred->neg_flags) {
121+
ctx->neg_flags = cred->neg_flags;
122+
}
119123

120124
/*
121125
* we ignore unsupported flags for now
@@ -635,6 +639,11 @@ uint32_t gssntlm_accept_sec_context(uint32_t *minor_status,
635639
ctx->neg_flags = NTLMSSP_DEFAULT_SERVER_FLAGS;
636640
/* Fixme: How do we allow anonymous negotition ? */
637641

642+
/* override neg_flags default if requested */
643+
if (cred->neg_flags) {
644+
ctx->neg_flags = cred->neg_flags;
645+
}
646+
638647
if (gssntlm_sec_lm_ok(ctx)) {
639648
ctx->neg_flags |= NTLMSSP_REQUEST_NON_NT_SESSION_KEY;
640649
ctx->neg_flags |= NTLMSSP_NEGOTIATE_LM_KEY;

src/gssapi_ntlmssp.h

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ extern "C" {
5959
#define GSS_NTLMSSP_DEBUG_OID_STRING GSS_NTLMSSP_BASE_OID_STRING "\x04"
6060
#define GSS_NTLMSSP_DEBUG_OID_LENGTH GSS_NTLMSSP_BASE_OID_LENGTH + 1
6161

62+
/* Set Default Neg Flags Cred Option OID
63+
* Use this with gss_set_cred_option to provide a set of NEGOTIATE flags
64+
* to override the default selection on context initialization.
65+
*/
66+
#define GSS_NTLMSSP_NEG_FLAGS_OID_STRING GSS_NTLMSSP_BASE_OID_STRING "\x05"
67+
#define GSS_NTLMSSP_NEG_FLAGS_OID_LENGTH GSS_NTLMSSP_BASE_OID_LENGTH + 1
6268

6369

6470
#define GSS_NTLMSSP_CS_DOMAIN "ntlmssp_domain"

0 commit comments

Comments
 (0)