Skip to content

Commit cff0d9b

Browse files
ethomsonEdward Thomson
authored andcommitted
http: refactor GSSAPI / negotiate / NTLM auth
Name the GSSAPI and ntlmclient authentication providers as such. Today they're named after the authentication mechanism ("Negotiate", "NTLM") instead of their implementation. If we have competing implementations for the same mechanism (eg, a future Windows SSPI-based provider for Negotiate and NTLM) then this will get confusing.
1 parent f68f542 commit cff0d9b

3 files changed

Lines changed: 46 additions & 46 deletions

File tree

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
#include <krb5.h>
2121
#endif
2222

23-
static gss_OID_desc negotiate_oid_spnego =
23+
static gss_OID_desc gssapi_oid_spnego =
2424
{ 6, (void *) "\x2b\x06\x01\x05\x05\x02" };
25-
static gss_OID_desc negotiate_oid_krb5 =
25+
static gss_OID_desc gssapi_oid_krb5 =
2626
{ 9, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" };
2727

28-
static gss_OID negotiate_oids[] =
29-
{ &negotiate_oid_spnego, &negotiate_oid_krb5, NULL };
28+
static gss_OID gssapi_oids[] =
29+
{ &gssapi_oid_spnego, &gssapi_oid_krb5, NULL };
3030

3131
typedef struct {
3232
git_http_auth_context parent;
@@ -36,9 +36,9 @@ typedef struct {
3636
char *challenge;
3737
gss_ctx_id_t gss_context;
3838
gss_OID oid;
39-
} http_auth_negotiate_context;
39+
} http_auth_gssapi_context;
4040

41-
static void negotiate_err_set(
41+
static void gssapi_err_set(
4242
OM_uint32 status_major,
4343
OM_uint32 status_minor,
4444
const char *message)
@@ -58,11 +58,11 @@ static void negotiate_err_set(
5858
}
5959
}
6060

61-
static int negotiate_set_challenge(
61+
static int gssapi_set_challenge(
6262
git_http_auth_context *c,
6363
const char *challenge)
6464
{
65-
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
65+
http_auth_gssapi_context *ctx = (http_auth_gssapi_context *)c;
6666

6767
GIT_ASSERT_ARG(ctx);
6868
GIT_ASSERT_ARG(challenge);
@@ -76,7 +76,7 @@ static int negotiate_set_challenge(
7676
return 0;
7777
}
7878

79-
static void negotiate_context_dispose(http_auth_negotiate_context *ctx)
79+
static void gssapi_context_dispose(http_auth_gssapi_context *ctx)
8080
{
8181
OM_uint32 status_minor;
8282

@@ -92,12 +92,12 @@ static void negotiate_context_dispose(http_auth_negotiate_context *ctx)
9292
ctx->challenge = NULL;
9393
}
9494

95-
static int negotiate_next_token(
95+
static int gssapi_next_token(
9696
git_str *buf,
9797
git_http_auth_context *c,
9898
git_credential *cred)
9999
{
100-
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
100+
http_auth_gssapi_context *ctx = (http_auth_gssapi_context *)c;
101101
OM_uint32 status_major, status_minor;
102102
gss_buffer_desc target_buffer = GSS_C_EMPTY_BUFFER,
103103
input_token = GSS_C_EMPTY_BUFFER,
@@ -126,7 +126,7 @@ static int negotiate_next_token(
126126
GSS_C_NT_HOSTBASED_SERVICE, &server);
127127

128128
if (GSS_ERROR(status_major)) {
129-
negotiate_err_set(status_major, status_minor,
129+
gssapi_err_set(status_major, status_minor,
130130
"could not parse principal");
131131
error = -1;
132132
goto done;
@@ -152,10 +152,10 @@ static int negotiate_next_token(
152152
input_token.length = input_buf.size;
153153
input_token_ptr = &input_token;
154154
} else if (ctx->gss_context != GSS_C_NO_CONTEXT) {
155-
negotiate_context_dispose(ctx);
155+
gssapi_context_dispose(ctx);
156156
}
157157

158-
mech = &negotiate_oid_spnego;
158+
mech = &gssapi_oid_spnego;
159159

160160
status_major = gss_init_sec_context(
161161
&status_minor,
@@ -173,14 +173,14 @@ static int negotiate_next_token(
173173
NULL);
174174

175175
if (GSS_ERROR(status_major)) {
176-
negotiate_err_set(status_major, status_minor, "negotiate failure");
176+
gssapi_err_set(status_major, status_minor, "negotiate failure");
177177
error = -1;
178178
goto done;
179179
}
180180

181181
/* This message merely told us auth was complete; we do not respond. */
182182
if (status_major == GSS_S_COMPLETE) {
183-
negotiate_context_dispose(ctx);
183+
gssapi_context_dispose(ctx);
184184
ctx->complete = 1;
185185
goto done;
186186
}
@@ -204,20 +204,20 @@ static int negotiate_next_token(
204204
return error;
205205
}
206206

207-
static int negotiate_is_complete(git_http_auth_context *c)
207+
static int gssapi_is_complete(git_http_auth_context *c)
208208
{
209-
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
209+
http_auth_gssapi_context *ctx = (http_auth_gssapi_context *)c;
210210

211211
GIT_ASSERT_ARG(ctx);
212212

213213
return (ctx->complete == 1);
214214
}
215215

216-
static void negotiate_context_free(git_http_auth_context *c)
216+
static void gssapi_context_free(git_http_auth_context *c)
217217
{
218-
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
218+
http_auth_gssapi_context *ctx = (http_auth_gssapi_context *)c;
219219

220-
negotiate_context_dispose(ctx);
220+
gssapi_context_dispose(ctx);
221221

222222
ctx->configured = 0;
223223
ctx->complete = 0;
@@ -226,8 +226,8 @@ static void negotiate_context_free(git_http_auth_context *c)
226226
git__free(ctx);
227227
}
228228

229-
static int negotiate_init_context(
230-
http_auth_negotiate_context *ctx,
229+
static int gssapi_init_context(
230+
http_auth_gssapi_context *ctx,
231231
const git_net_url *url)
232232
{
233233
OM_uint32 status_major, status_minor;
@@ -239,13 +239,13 @@ static int negotiate_init_context(
239239
status_major = gss_indicate_mechs(&status_minor, &mechanism_list);
240240

241241
if (GSS_ERROR(status_major)) {
242-
negotiate_err_set(status_major, status_minor,
242+
gssapi_err_set(status_major, status_minor,
243243
"could not query mechanisms");
244244
return -1;
245245
}
246246

247247
if (mechanism_list) {
248-
for (oid = negotiate_oids; *oid; oid++) {
248+
for (oid = gssapi_oids; *oid; oid++) {
249249
for (i = 0; i < mechanism_list->count; i++) {
250250
item = &mechanism_list->elements[i];
251251

@@ -285,25 +285,25 @@ int git_http_auth_negotiate(
285285
git_http_auth_context **out,
286286
const git_net_url *url)
287287
{
288-
http_auth_negotiate_context *ctx;
288+
http_auth_gssapi_context *ctx;
289289

290290
*out = NULL;
291291

292-
ctx = git__calloc(1, sizeof(http_auth_negotiate_context));
292+
ctx = git__calloc(1, sizeof(http_auth_gssapi_context));
293293
GIT_ERROR_CHECK_ALLOC(ctx);
294294

295-
if (negotiate_init_context(ctx, url) < 0) {
295+
if (gssapi_init_context(ctx, url) < 0) {
296296
git__free(ctx);
297297
return -1;
298298
}
299299

300300
ctx->parent.type = GIT_HTTP_AUTH_NEGOTIATE;
301301
ctx->parent.credtypes = GIT_CREDENTIAL_DEFAULT;
302302
ctx->parent.connection_affinity = 1;
303-
ctx->parent.set_challenge = negotiate_set_challenge;
304-
ctx->parent.next_token = negotiate_next_token;
305-
ctx->parent.is_complete = negotiate_is_complete;
306-
ctx->parent.free = negotiate_context_free;
303+
ctx->parent.set_challenge = gssapi_set_challenge;
304+
ctx->parent.next_token = gssapi_next_token;
305+
ctx->parent.is_complete = gssapi_is_complete;
306+
ctx->parent.free = gssapi_context_free;
307307

308308
*out = (git_http_auth_context *)ctx;
309309

src/libgit2/transports/auth_ntlm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
77

8-
#ifndef INCLUDE_transports_auth_ntlm_h__
9-
#define INCLUDE_transports_auth_ntlm_h__
8+
#ifndef INCLUDE_transports_auth_ntlmclient_h__
9+
#define INCLUDE_transports_auth_ntlmclient_h__
1010

1111
#include "auth.h"
1212

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef struct {
2323
bool complete;
2424
} http_auth_ntlm_context;
2525

26-
static int ntlm_set_challenge(
26+
static int ntlmclient_set_challenge(
2727
git_http_auth_context *c,
2828
const char *challenge)
2929
{
@@ -40,7 +40,7 @@ static int ntlm_set_challenge(
4040
return 0;
4141
}
4242

43-
static int ntlm_set_credentials(http_auth_ntlm_context *ctx, git_credential *_cred)
43+
static int ntlmclient_set_credentials(http_auth_ntlm_context *ctx, git_credential *_cred)
4444
{
4545
git_credential_userpass_plaintext *cred;
4646
const char *sep, *username;
@@ -76,7 +76,7 @@ static int ntlm_set_credentials(http_auth_ntlm_context *ctx, git_credential *_cr
7676
return error;
7777
}
7878

79-
static int ntlm_next_token(
79+
static int ntlmclient_next_token(
8080
git_str *buf,
8181
git_http_auth_context *c,
8282
git_credential *cred)
@@ -104,7 +104,7 @@ static int ntlm_next_token(
104104
*/
105105
ctx->complete = true;
106106

107-
if (cred && ntlm_set_credentials(ctx, cred) != 0)
107+
if (cred && ntlmclient_set_credentials(ctx, cred) != 0)
108108
goto done;
109109

110110
if (challenge_len < 4) {
@@ -162,15 +162,15 @@ static int ntlm_next_token(
162162
return error;
163163
}
164164

165-
static int ntlm_is_complete(git_http_auth_context *c)
165+
static int ntlmclient_is_complete(git_http_auth_context *c)
166166
{
167167
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
168168

169169
GIT_ASSERT_ARG(ctx);
170170
return (ctx->complete == true);
171171
}
172172

173-
static void ntlm_context_free(git_http_auth_context *c)
173+
static void ntlmclient_context_free(git_http_auth_context *c)
174174
{
175175
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
176176

@@ -179,7 +179,7 @@ static void ntlm_context_free(git_http_auth_context *c)
179179
git__free(ctx);
180180
}
181181

182-
static int ntlm_init_context(
182+
static int ntlmclient_init_context(
183183
http_auth_ntlm_context *ctx,
184184
const git_net_url *url)
185185
{
@@ -206,18 +206,18 @@ int git_http_auth_ntlm(
206206
ctx = git__calloc(1, sizeof(http_auth_ntlm_context));
207207
GIT_ERROR_CHECK_ALLOC(ctx);
208208

209-
if (ntlm_init_context(ctx, url) < 0) {
209+
if (ntlmclient_init_context(ctx, url) < 0) {
210210
git__free(ctx);
211211
return -1;
212212
}
213213

214214
ctx->parent.type = GIT_HTTP_AUTH_NTLM;
215215
ctx->parent.credtypes = GIT_CREDENTIAL_USERPASS_PLAINTEXT;
216216
ctx->parent.connection_affinity = 1;
217-
ctx->parent.set_challenge = ntlm_set_challenge;
218-
ctx->parent.next_token = ntlm_next_token;
219-
ctx->parent.is_complete = ntlm_is_complete;
220-
ctx->parent.free = ntlm_context_free;
217+
ctx->parent.set_challenge = ntlmclient_set_challenge;
218+
ctx->parent.next_token = ntlmclient_next_token;
219+
ctx->parent.is_complete = ntlmclient_is_complete;
220+
ctx->parent.free = ntlmclient_context_free;
221221

222222
*out = (git_http_auth_context *)ctx;
223223

0 commit comments

Comments
 (0)