Merge branch 'v3-2-test' of ssh://jra@git.samba.org/data/git/samba into v3-2-test
[ira/wip.git] / source / nsswitch / libwbclient / wbclient.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    Winbind client API
5
6    Copyright (C) Gerald (Jerry) Carter 2007
7
8
9    This library is free software; you can redistribute it and/or
10    modify it under the terms of the GNU Lesser General Public
11    License as published by the Free Software Foundation; either
12    version 3 of the License, or (at your option) any later version.
13
14    This library is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    Library General Public License for more details.
18
19    You should have received a copy of the GNU Lesser General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 /* Required Headers */
24
25 #include "libwbclient.h"
26
27 /* From wb_common.c */
28
29 NSS_STATUS winbindd_request_response(int req_type,
30                                      struct winbindd_request *request,
31                                      struct winbindd_response *response);
32
33 /** @brief Wrapper around Winbind's send/receive API call
34  *
35  * @param cmd       Winbind command operation to perform
36  * @param request   Send structure
37  * @param response  Receive structure
38  *
39  * @return #wbcErr
40  **/
41
42 /**********************************************************************
43  result == NSS_STATUS_UNAVAIL: winbind not around
44  result == NSS_STATUS_NOTFOUND: winbind around, but domain missing
45
46  Due to a bad API NSS_STATUS_NOTFOUND is returned both when winbind_off
47  and when winbind return WINBINDD_ERROR. So the semantics of this
48  routine depends on winbind_on. Grepping for winbind_off I just
49  found 3 places where winbind is turned off, and this does not conflict
50  (as far as I have seen) with the callers of is_trusted_domains.
51
52  --Volker
53 **********************************************************************/
54
55 wbcErr wbcRequestResponse(int cmd,
56                           struct winbindd_request *request,
57                           struct winbindd_response *response)
58 {
59         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
60         NSS_STATUS nss_status;
61
62         if (!request || !response) {
63                 wbc_status = WBC_ERR_INVALID_PARAM;
64                 BAIL_ON_WBC_ERROR(wbc_status);
65         }
66
67
68         nss_status = winbindd_request_response(cmd, request, response);
69
70         switch (nss_status) {
71         case NSS_STATUS_SUCCESS:
72                 wbc_status = WBC_ERR_SUCCESS;
73                 break;
74         case NSS_STATUS_UNAVAIL:
75                 return WBC_ERR_WINBIND_NOT_AVAILABLE;
76                 break;
77         case NSS_STATUS_NOTFOUND:
78                 return WBC_ERR_DOMAIN_NOT_FOUND;
79                 break;
80         default:
81                 wbc_status = WBC_ERR_NSS_ERROR;
82                 break;
83         }
84
85 done:
86         return wbc_status;
87 }
88
89 /** @brief Free library allocated memory
90  *
91  * @param *p Pointer to free
92  *
93  * @return void
94  **/
95
96 void wbcFreeMemory(void *p)
97 {
98         if (p)
99                 talloc_free(p);
100
101         return;
102 }
103
104
105