Skip to content
This repository was archived by the owner on Feb 24, 2024. It is now read-only.

Commit 430a12b

Browse files
committed
Add password= keyword to authGSSClientInit
1 parent 51a4c34 commit 430a12b

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

pysrc/kerberos.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def authGSSClientInit(service, **kwargs):
160160
161161
@param mech_oid: Optional GGS mech OID
162162
163+
@param password: Optional string containing the service principal's password
164+
163165
@return: A tuple of (result, context) where result is the result code (see
164166
above) and context is an opaque value that will need to be passed to
165167
subsequent functions.

src/kerberos.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,22 @@ static PyObject* authGSSClientInit(PyObject* self, PyObject* args, PyObject* key
151151
{
152152
const char *service = NULL;
153153
const char *principal = NULL;
154+
const char *password = NULL;
154155
gss_client_state *state = NULL;
155156
PyObject *pystate = NULL;
156157
gss_server_state *delegatestate = NULL;
157158
PyObject *pydelegatestate = NULL;
158159
gss_OID mech_oid = GSS_C_NO_OID;
159160
PyObject *pymech_oid = NULL;
160161
static char *kwlist[] = {
161-
"service", "principal", "gssflags", "delegated", "mech_oid", NULL
162+
"service", "principal", "gssflags", "delegated", "mech_oid", "password", NULL
162163
};
163164
long int gss_flags = GSS_C_MUTUAL_FLAG | GSS_C_SEQUENCE_FLAG;
164165
int result = 0;
165166

166167
if (! PyArg_ParseTupleAndKeywords(
167-
args, keywds, "s|zlOO", kwlist,
168-
&service, &principal, &gss_flags, &pydelegatestate, &pymech_oid
168+
args, keywds, "s|zlOOz", kwlist,
169+
&service, &principal, &gss_flags, &pydelegatestate, &pymech_oid, &password
169170
)) {
170171
return NULL;
171172
}
@@ -191,7 +192,7 @@ static PyObject* authGSSClientInit(PyObject* self, PyObject* args, PyObject* key
191192
}
192193

193194
result = authenticate_gss_client_init(
194-
service, principal, gss_flags, delegatestate, mech_oid, state
195+
service, principal, gss_flags, delegatestate, mech_oid, state, password
195196
);
196197

197198
if (result == AUTH_GSS_ERROR) {

src/kerberosgss.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,16 @@ char* server_principal_details(const char* service, const char* hostname)
128128

129129
int authenticate_gss_client_init(
130130
const char* service, const char* principal, long int gss_flags,
131-
gss_server_state* delegatestate, gss_OID mech_oid, gss_client_state* state
131+
gss_server_state* delegatestate, gss_OID mech_oid, gss_client_state* state,
132+
const char *password
132133
)
133134
{
134135
OM_uint32 maj_stat;
135136
OM_uint32 min_stat;
136137
gss_buffer_desc name_token = GSS_C_EMPTY_BUFFER;
137138
gss_buffer_desc principal_token = GSS_C_EMPTY_BUFFER;
138139
int ret = AUTH_GSS_COMPLETE;
139-
140+
140141
state->server_name = GSS_C_NO_NAME;
141142
state->mech_oid = mech_oid;
142143
state->context = GSS_C_NO_CONTEXT;
@@ -177,10 +178,24 @@ int authenticate_gss_client_init(
177178
goto end;
178179
}
179180

180-
maj_stat = gss_acquire_cred(
181-
&min_stat, name, GSS_C_INDEFINITE, GSS_C_NO_OID_SET,
182-
GSS_C_INITIATE, &state->client_creds, NULL, NULL
183-
);
181+
if (password != NULL) {
182+
gss_buffer_desc gss_password = {
183+
.length = strlen(password),
184+
.value = password
185+
};
186+
maj_stat = gss_acquire_cred_with_password(
187+
&min_stat, name, &gss_password,
188+
GSS_C_INDEFINITE, GSS_C_NO_OID_SET,
189+
GSS_C_INITIATE, &state->client_creds, NULL, NULL
190+
);
191+
} else {
192+
printf("No password provided\n");
193+
maj_stat = gss_acquire_cred(
194+
&min_stat, name, GSS_C_INDEFINITE, GSS_C_NO_OID_SET,
195+
GSS_C_INITIATE, &state->client_creds, NULL, NULL
196+
);
197+
}
198+
184199
if (GSS_ERROR(maj_stat)) {
185200
set_gss_error(maj_stat, min_stat);
186201
ret = AUTH_GSS_ERROR;

src/kerberosgss.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <gssapi/gssapi.h>
1818
#include <gssapi/gssapi_generic.h>
1919
#include <gssapi/gssapi_krb5.h>
20+
#include <gssapi/gssapi_ext.h>
2021

2122
#define krb5_get_err_text(context,code) error_message(code)
2223

@@ -55,7 +56,8 @@ char* server_principal_details(const char* service, const char* hostname);
5556

5657
int authenticate_gss_client_init(
5758
const char* service, const char* principal, long int gss_flags,
58-
gss_server_state* delegatestate, gss_OID mech_oid, gss_client_state* state
59+
gss_server_state* delegatestate, gss_OID mech_oid, gss_client_state* state,
60+
const char *password
5961
);
6062
int authenticate_gss_client_clean(
6163
gss_client_state *state

0 commit comments

Comments
 (0)