Skip to content

Commit 8911176

Browse files
committed
Fix serialization to export also the server spn
This ups both context and credentials export versions as the size and content of the serilized structires change. Signed-off-by: Simo Sorce <[email protected]>
1 parent 782837d commit 8911176

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/gss_serialize.c

+26-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct export_attrs {
2626

2727
struct export_name {
2828
uint8_t type;
29-
struct relmem domain;
29+
struct relmem dom_or_spn;
3030
struct relmem name;
3131
struct export_attrs attrs;
3232
};
@@ -38,7 +38,7 @@ struct export_keys {
3838
uint32_t seq_num;
3939
};
4040

41-
#define EXPORT_CTX_VER 0x0004
41+
#define EXPORT_CTX_VER 0x0005
4242
struct export_ctx {
4343
uint16_t version;
4444
uint8_t role;
@@ -211,7 +211,7 @@ static int export_name(struct export_state *state,
211211
if (name->data.user.domain) {
212212
ret = export_data_buffer(state, name->data.user.domain,
213213
strlen(name->data.user.domain),
214-
&exp_name->domain);
214+
&exp_name->dom_or_spn);
215215
if (ret) {
216216
return ret;
217217
}
@@ -227,6 +227,14 @@ static int export_name(struct export_state *state,
227227
break;
228228
case GSSNTLM_NAME_SERVER:
229229
exp_name->type = EXP_NAME_SERV;
230+
if (name->data.server.spn) {
231+
ret = export_data_buffer(state, name->data.server.spn,
232+
strlen(name->data.server.spn),
233+
&exp_name->dom_or_spn);
234+
if (ret) {
235+
return ret;
236+
}
237+
}
230238
if (name->data.server.name) {
231239
ret = export_data_buffer(state, name->data.server.name,
232240
strlen(name->data.server.name),
@@ -599,10 +607,10 @@ static uint32_t import_name(uint32_t *minor_status,
599607
case EXP_NAME_USER:
600608
imp_name->type = GSSNTLM_NAME_USER;
601609
dest = NULL;
602-
if (name->domain.len > 0) {
610+
if (name->dom_or_spn.len > 0) {
603611
retmaj = import_data_buffer(&retmin, state,
604612
&dest, NULL, true,
605-
&name->domain, true);
613+
&name->dom_or_spn, true);
606614
if (retmaj != GSS_S_COMPLETE) goto done;
607615
}
608616
imp_name->data.user.domain = (char *)dest;
@@ -619,6 +627,14 @@ static uint32_t import_name(uint32_t *minor_status,
619627
case EXP_NAME_SERV:
620628
imp_name->type = GSSNTLM_NAME_SERVER;
621629
dest = NULL;
630+
if (name->dom_or_spn.len > 0) {
631+
retmaj = import_data_buffer(&retmin, state,
632+
&dest, NULL, true,
633+
&name->dom_or_spn, true);
634+
if (retmaj != GSS_S_COMPLETE) goto done;
635+
}
636+
imp_name->data.server.spn = (char *)dest;
637+
dest = NULL;
622638
if (name->name.len > 0) {
623639
retmaj = import_data_buffer(&retmin, state,
624640
&dest, NULL, true,
@@ -878,9 +894,11 @@ uint32_t gssntlm_import_sec_context(uint32_t *minor_status,
878894
return GSSERR();
879895
}
880896

897+
#define EXPORT_CRED_VER 0x0002
898+
881899
#pragma pack(push, 1)
882900
struct export_cred {
883-
uint16_t version; /* 0x00 0x02 */
901+
uint16_t version;
884902
uint16_t type;
885903

886904
struct export_name name; /* user or server name */
@@ -933,7 +951,7 @@ uint32_t gssntlm_export_cred(uint32_t *minor_status,
933951
state.exp_data = (uint8_t *)&ecred.data - (uint8_t *)&ecred;
934952
state.exp_len = state.exp_data;
935953

936-
ecred.version = htole16(1);
954+
ecred.version = htole16(EXPORT_CRED_VER);
937955

938956
switch (cred->type) {
939957
case GSSNTLM_CRED_NONE:
@@ -1052,7 +1070,7 @@ uint32_t gssntlm_import_cred(uint32_t *minor_status,
10521070
ecred = (struct export_cred *)state.exp_struct;
10531071
state.exp_data = (char *)ecred->data - (char *)ecred;
10541072

1055-
if (ecred->version != le16toh(1)) {
1073+
if (ecred->version != le16toh(EXPORT_CRED_VER)) {
10561074
set_GSSERRS(ERR_BADARG, GSS_S_DEFECTIVE_TOKEN);
10571075
goto done;
10581076
}

0 commit comments

Comments
 (0)