The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
auth_wbclient_pap.c
Go to the documentation of this file.
1/*
2 * This program is is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: e96159eed400fd673d567d91ac68bcff27c84a7b $
19 * @file auth_wbclient_pap.c
20 * @brief PAP authentication against the wbclient library
21 *
22 * @author Matthew Newton (matthew@newtoncomputing.co.uk)
23 *
24 * @copyright 2015-2016 Matthew Newton
25 */
26
27RCSID("$Id: e96159eed400fd673d567d91ac68bcff27c84a7b $")
28
29#include <freeradius-devel/server/base.h>
30#include <freeradius-devel/util/debug.h>
31
32#include <wbclient.h>
33#include <core/ntstatus.h>
34
35#include "rlm_winbind.h"
36#include "auth_wbclient_pap.h"
37
38/** PAP authentication direct to winbind via Samba's libwbclient library
39 *
40 * @param[in] request The current request
41 * @param[in] env The call_env for the current winbind authentication
42 * @param[in] t The module thread instance data.
43 *
44 * @return
45 * - 0 Success
46 * - -1 Authentication failure
47 * - -648 Password expired
48 *
49 */
51{
52 int ret = -1;
53 winbind_ctx_t *wbctx;
54 struct wbcContext *wb_ctx;
55 struct wbcAuthUserParams authparams;
56 wbcErr err;
57 struct wbcAuthUserInfo *info = NULL;
58 struct wbcAuthErrorInfo *error = NULL;
59
60 /*
61 * Clear the auth parameters - this is important, as
62 * there are options that will cause wbcAuthenticateUserEx
63 * to bomb out if not zero.
64 */
65 memset(&authparams, 0, sizeof(authparams));
66
67 /*
68 * username must be set for this function to be called
69 */
70 fr_assert(env->username.type == FR_TYPE_STRING);
71
72 authparams.account_name = env->username.vb_strvalue;
73
74 if (env->domain.type == FR_TYPE_STRING) {
75 authparams.domain_name = env->domain.vb_strvalue;
76 } else {
77 RWDEBUG2("No domain specified; authentication may fail because of this");
78 }
79
80
81 /*
82 * Build the wbcAuthUserParams structure with what we know
83 */
84 authparams.level = WBC_AUTH_USER_LEVEL_PLAIN;
85 authparams.password.plaintext = env->password.vb_strvalue;
86
87 /*
88 * Parameters documented as part of the MSV1_0_SUBAUTH_LOGON structure
89 * at https://msdn.microsoft.com/aa378767.aspx
90 */
91 authparams.parameter_control |= WBC_MSV1_0_CLEARTEXT_PASSWORD_ALLOWED |
92 WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
93 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
94
95 /*
96 * Send auth request across to winbind
97 */
98 wbctx = winbind_slab_reserve(t->slab);
99 if (!wbctx) {
100 RERROR("Unable to get winbind context");
101 goto done;
102 }
103 wb_ctx = wbctx->ctx;
104
105 RDEBUG2("Sending authentication request user='%s' domain='%s'", authparams.account_name,
106 authparams.domain_name);
107
108 err = wbcCtxAuthenticateUserEx(wb_ctx, &authparams, &info, &error);
109
110 winbind_slab_release(wbctx);
111
112 /*
113 * Try and give some useful feedback on what happened. There are only
114 * a few errors that can actually be returned from wbcCtxAuthenticateUserEx.
115 */
116 switch (err) {
117 case WBC_ERR_SUCCESS:
118 ret = 0;
119 RDEBUG2("Authenticated successfully");
120 break;
121
122 case WBC_ERR_WINBIND_NOT_AVAILABLE:
123 RERROR("Unable to contact winbindd");
124 RDEBUG2("Check that winbind is running and that FreeRADIUS has");
125 RDEBUG2("permission to connect to the winbind privileged socket");
126 break;
127
128 case WBC_ERR_DOMAIN_NOT_FOUND:
129 REDEBUG2("Domain not found");
130 break;
131
132 case WBC_ERR_AUTH_ERROR:
133 if (!error) {
134 REDEBUG2("Authentication failed");
135 break;
136 }
137
138 /*
139 * The password needs to be changed, set ret appropriately.
140 */
141 if (error->nt_status == NT_STATUS_PASSWORD_EXPIRED ||
142 error->nt_status == NT_STATUS_PASSWORD_MUST_CHANGE) {
143 ret = -648;
144 }
145
146 /*
147 * Return the NT_STATUS human readable error string, if there is one.
148 */
149 if (error->display_string) {
150 REDEBUG2("%s [0x%X]", error->display_string, error->nt_status);
151 } else {
152 REDEBUG2("Unknown authentication failure [0x%X]", error->nt_status);
153 }
154 break;
155
156 default:
157 /*
158 * Only errors left are
159 * WBC_ERR_INVALID_PARAM
160 * WBC_ERR_NO_MEMORY
161 * neither of which are particularly likely.
162 */
163 if (error && error->display_string) {
164 REDEBUG2("Failed authenticating user: %s (%s)", error->display_string, wbcErrorString(err));
165 } else {
166 REDEBUG2("Failed authenticating user: Winbind error (%s)", wbcErrorString(err));
167 }
168 break;
169 }
170
171
172done:
173 if (info) wbcFreeMemory(info);
174 if (error) wbcFreeMemory(error);
175
176 return ret;
177}
178
int do_auth_wbclient_pap(request_t *request, winbind_auth_call_env_t *env, rlm_winbind_thread_t *t)
PAP authentication direct to winbind via Samba's libwbclient library.
#define RCSID(id)
Definition build.h:483
static fr_slen_t err
Definition dict.h:824
#define RWDEBUG2(fmt,...)
Definition log.h:362
#define RERROR(fmt,...)
Definition log.h:298
#define REDEBUG2(fmt,...)
Definition log.h:372
@ FR_TYPE_STRING
String of printable characters.
#define fr_assert(_expr)
Definition rad_assert.h:38
static bool done
Definition radclient.c:80
#define RDEBUG2(fmt,...)
Definition radclient.h:54
fr_value_box_t password
Definition rlm_winbind.h:34
winbind_slab_list_t * slab
Slab list for winbind handles.
Definition rlm_winbind.h:28
fr_value_box_t domain
Definition rlm_winbind.h:33
struct wbcContext * ctx
Definition rlm_winbind.h:20
fr_value_box_t username
Definition rlm_winbind.h:32