Skip to content

Commit cf0df4a

Browse files
committed
Low-level: allow mutating input creds in add_cred
This commit adds an optional parameter to `add_cred`, `mutate_input`, which allows `add_cred` to either create a new set of credentials containing the input credentials and the new credentials (False) or to just modify the input credentials, adding the new credentials directly to them (True). Previously, only the former was possible. Closes #18.
1 parent 45da7af commit cf0df4a

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

gssapi/raw/creds.pyx

+16-5
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def release_cred(Creds creds not None):
175175

176176
def add_cred(Creds input_cred, Name name not None, OID mech not None,
177177
usage='initiate', init_lifetime=None,
178-
accept_lifetime=None):
178+
accept_lifetime=None, mutate_input=False):
179179
"""Add a credential element to a credential.
180180
181181
This method can be used to either compose two credentials (i.e., original
@@ -192,11 +192,14 @@ def add_cred(Creds input_cred, Name name not None, OID mech not None,
192192
security contexts (None for indefinite)
193193
accept_lifetime (int): lifetime of credentials for use in accepting
194194
security contexts (None for indefinite)
195+
mutate_input (bool): whether to mutate the input credentials (True)
196+
or produce a new set of credentials (False). Defaults to False
195197
196198
Returns:
197199
AddCredResult: the actual mechanisms with which the credentials may be
198200
used, the actual initiator TTL, and the actual acceptor TTL (None for
199-
either indefinite or not supported)
201+
either indefinite or not supported). Note that the credentials may
202+
be set to None if mutate_input is set to True.
200203
201204
Raises:
202205
GSSError
@@ -220,6 +223,10 @@ def add_cred(Creds input_cred, Name name not None, OID mech not None,
220223
cdef OM_uint32 input_acceptor_ttl = c_py_ttl_to_c(accept_lifetime)
221224

222225
cdef gss_cred_id_t output_creds
226+
cdef gss_cred_id_t *output_creds_ptr = NULL
227+
if not mutate_input:
228+
output_creds_ptr = &output_creds
229+
223230
cdef gss_OID_set actual_mechs
224231
cdef OM_uint32 actual_initiator_ttl, actual_acceptor_ttl
225232

@@ -228,14 +235,18 @@ def add_cred(Creds input_cred, Name name not None, OID mech not None,
228235
with nogil:
229236
maj_stat = gss_add_cred(&min_stat, raw_input_cred, name.raw_name,
230237
&mech.raw_oid, c_usage, input_initiator_ttl,
231-
input_acceptor_ttl, &output_creds,
238+
input_acceptor_ttl, output_creds_ptr,
232239
&actual_mechs, &actual_initiator_ttl,
233240
&actual_acceptor_ttl)
234241

235242
cdef Creds rc
236243
if maj_stat == GSS_S_COMPLETE:
237-
rc = Creds()
238-
rc.raw_creds = output_creds
244+
if mutate_input:
245+
rc = None
246+
else:
247+
rc = Creds()
248+
rc.raw_creds = output_creds
249+
239250
return AddCredResult(rc, c_create_oid_set(actual_mechs),
240251
c_c_ttl_to_py(actual_initiator_ttl),
241252
c_c_ttl_to_py(actual_acceptor_ttl))

gssapi/tests/test_raw.py

+3
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ def test_add_cred(self):
402402

403403
new_creds.should_be_a(gb.Creds)
404404

405+
# NB(sross): we skip testing add_cred with mutate for the same reasons
406+
# that testing add_cred in the high-level API is skipped
407+
405408
def test_inquire_creds(self):
406409
name = gb.import_name(SERVICE_PRINCIPAL,
407410
gb.NameType.kerberos_principal)

0 commit comments

Comments
 (0)