Add files for new LGPL libwbclient DSO implementing the Winbind client API
[samba.git] / source3 / nsswitch / libwbclient / wbc_pam.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    Winbind client API
5
6    Copyright (C) Gerald (Jerry) Carter 2007
7
8    This library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public
10    License as published by the Free Software Foundation; either
11    version 3 of the License, or (at your option) any later version.
12
13    This library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Library General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 /* Required Headers */
23
24 #include "libwbclient.h"
25
26 /** @brief Authenticate a username/password pair
27  *
28  * @param username     Name of user to authenticate
29  * @param password     Clear text password os user
30  *
31  * @return #wbcErr
32  **/
33
34 wbcErr wbcAuthenticateUser(const char *username, 
35                            const char *password)
36 {
37         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
38         struct winbindd_request request;
39         struct winbindd_response response;
40
41         if (!username) {
42                 wbc_status = WBC_ERR_INVALID_PARAM;
43                 BAIL_ON_WBC_ERROR(wbc_status);
44         }
45
46         /* Initialize request */
47
48         ZERO_STRUCT(request);
49         ZERO_STRUCT(response);
50
51         /* dst is already null terminated from the memset above */
52
53         strncpy(request.data.auth.user, username,
54                 sizeof(request.data.auth.user)-1);
55         strncpy(request.data.auth.pass, password,
56                 sizeof(request.data.auth.user)-1);
57
58         wbc_status = wbcRequestResponse(WINBINDD_PAM_AUTH,
59                                         &request,
60                                         &response);
61         BAIL_ON_WBC_ERROR(wbc_status);
62
63 done:
64         return wbc_status;      
65 }