55 char const *dom_name,
char const *
name)
57 struct wbcDomainSid sid;
58 enum wbcSidType name_type;
60 char *res_domain = NULL;
61 char *res_name = NULL;
65 err = wbcCtxLookupName(wb_ctx, dom_name,
name, &sid, &name_type);
66 if (!WBC_ERROR_IS_OK(
err))
return NULL;
69 err = wbcCtxLookupSid(wb_ctx, &sid, &res_domain, &res_name, &name_type);
70 if (!WBC_ERROR_IS_OK(
err))
return NULL;
72 MEM(res = talloc_strdup(ctx, res_name));
74 wbcFreeMemory(res_domain);
75 wbcFreeMemory(res_name);
99 struct wbcContext *wb_ctx = NULL;
100 struct wbcAuthUserParams authparams;
102 struct wbcAuthUserInfo *info = NULL;
103 struct wbcAuthErrorInfo *error = NULL;
112 memset(&authparams, 0,
sizeof(authparams));
115 authparams.domain_name = env_data->
wb_domain.vb_strvalue;
117 RWDEBUG2(
"No domain specified; authentication may fail because of this");
123 authparams.account_name = env_data->
wb_username.vb_strvalue;
128 authparams.level = WBC_AUTH_USER_LEVEL_RESPONSE;
129 authparams.password.response.nt_length =
NT_LENGTH;
132 authparams.password.response.nt_data = resp;
134 memcpy(authparams.password.response.challenge, challenge,
sizeof(authparams.password.response.challenge));
137 WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
138 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
143 wbctx = mschap_slab_reserve(auth_ctx->t->slab);
145 RERROR(
"Unable to get winbind connection from pool");
150 RDEBUG2(
"Sending authentication request user \"%pV\" domain \"%pV\"",
153 err = wbcCtxAuthenticateUserEx(wb_ctx, &authparams, &info, &error);
154 if (
err == WBC_ERR_AUTH_ERROR &&
inst->wb_retry_with_normalised_username) {
158 char *normalised_username = NULL;
161 authparams.account_name);
162 if (!normalised_username)
goto release;
164 RDEBUG2(
"Starting retry, normalised username \"%pV\" -> \"%pV\"",
168 if (
talloc_memcmp_bstr(authparams.account_name, normalised_username) == 0)
goto release;
170 authparams.account_name = normalised_username;
176 RDEBUG2(
"Retrying authentication request user \"%pV\" domain \"%pV\"",
191 RERROR(
"Unable to get MS-CHAP2-Response");
196 vp_response->vp_octets + 2,
197 vp_challenge->vp_octets,
198 vp_chap_user_name->vp_strvalue, vp_chap_user_name->vp_length);
200 err = wbcCtxAuthenticateUserEx(wb_ctx, &authparams, &info, &error);
205 mschap_slab_release(wbctx);
212 case WBC_ERR_SUCCESS:
214 RDEBUG2(
"Authenticated successfully");
219 case WBC_ERR_WINBIND_NOT_AVAILABLE:
220 RERROR(
"Unable to contact winbind!");
221 RDEBUG2(
"Check that winbind is running and that FreeRADIUS has");
222 RDEBUG2(
"permission to connect to the winbind privileged socket.");
225 case WBC_ERR_DOMAIN_NOT_FOUND:
229 case WBC_ERR_AUTH_ERROR:
238 if (error->nt_status == NT_STATUS_PASSWORD_EXPIRED ||
239 error->nt_status == NT_STATUS_PASSWORD_MUST_CHANGE) {
246 if (error->display_string) {
247 REDEBUG2(
"%s [0x%X]", error->display_string, error->nt_status);
249 REDEBUG2(
"Authentication failed [0x%X]", error->nt_status);
260 if (error && error->display_string) {
261 REDEBUG2(
"libwbclient error: wbcErr %d (%s)",
err, error->display_string);
269 if (info) wbcFreeMemory(info);
270 if (error) wbcFreeMemory(error);
int do_auth_wbclient(rlm_mschap_t const *inst, request_t *request, uint8_t const *challenge, uint8_t const *response, uint8_t nthashhash[NT_DIGEST_LENGTH], mschap_auth_ctx_t *auth_ctx)
Check NTLM authentication direct to winbind via Samba's libwbclient library.
void mschap_challenge_hash(uint8_t challenge[static MSCHAP_CHALLENGE_LENGTH], uint8_t const peer_challenge[static MSCHAP_PEER_CHALLENGE_LENGTH], uint8_t const auth_challenge[static MSCHAP_PEER_AUTHENTICATOR_CHALLENGE_LENGTH], char const *user_name, size_t user_name_len)
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.