Skip to content

Commit

Permalink
Fix Kerberos' support on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
amosavian committed Nov 14, 2023
1 parent a4cf6ea commit dd26794
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/krb5-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@
#endif

#include <krb5/krb5.h>
#if __APPLE__
#include <GSS/GSS.h>
#else
#include <gssapi/gssapi_krb5.h>
#include <gssapi/gssapi.h>
#endif
#include <stdio.h>

#include "slist.h"
Expand Down Expand Up @@ -212,13 +216,21 @@ krb5_negotiate_reply(struct smb2_context *smb2,

/* TODO: the proper mechanism (SPNEGO vs NTLM vs KRB5) should be
* selected based on the SMB negotiation flags */
#ifdef __APPLE__
auth_data->mech_type = GSS_SPNEGO_MECHANISM;
#else
auth_data->mech_type = &gss_mech_spnego;
#endif
auth_data->cred = GSS_C_NO_CREDENTIAL;

/* Create creds for the user */
mechOidSet.count = 1;
#ifdef __APPLE__
mechOidSet.elements = discard_const(GSS_SPNEGO_MECHANISM);
#else
mechOidSet.elements = discard_const(&gss_mech_spnego);

#endif

if (smb2->use_cached_creds) {
krb5_error_code ret = 0;
const char *cname = NULL;
Expand Down Expand Up @@ -266,6 +278,7 @@ krb5_negotiate_reply(struct smb2_context *smb2,
return NULL;
}

#ifndef __APPLE__ // gss_set_neg_mechs is not defined on macOS/iOS.
if (smb2->sec != SMB2_SEC_UNDEFINED) {
wantMech.count = 1;
if (smb2->sec == SMB2_SEC_KRB5) {
Expand All @@ -280,6 +293,7 @@ krb5_negotiate_reply(struct smb2_context *smb2,
return NULL;
}
}
#endif

if (nc_password) {
free(nc_password);
Expand Down
4 changes: 4 additions & 0 deletions lib/krb5-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@
extern "C" {
#endif

#if __APPLE__
#import <GSS/GSS.h>
#else
#include <gssapi/gssapi.h>

static const gss_OID_desc gss_mech_spnego = {
6, "\x2b\x06\x01\x05\x05\x02"
};
#endif

static const gss_OID_desc spnego_mech_krb5 = {
9, "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02"
Expand Down

0 comments on commit dd26794

Please sign in to comment.