Allow NULL queue to writev_send
[Samba.git] / nsswitch / libwbclient / wbclient.c
bloba4ef0beeef93755b8036089b8f523757ed00bf25
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind client API
6 Copyright (C) Gerald (Jerry) Carter 2007
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.
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.
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/>.
23 /* Required Headers */
25 #include "libwbclient.h"
27 /* From wb_common.c */
29 NSS_STATUS winbindd_request_response(int req_type,
30 struct winbindd_request *request,
31 struct winbindd_response *response);
32 NSS_STATUS winbindd_priv_request_response(int req_type,
33 struct winbindd_request *request,
34 struct winbindd_response *response);
36 /** @brief Wrapper around Winbind's send/receive API call
38 * @param cmd Winbind command operation to perform
39 * @param request Send structure
40 * @param response Receive structure
42 * @return #wbcErr
43 **/
45 /**********************************************************************
46 result == NSS_STATUS_UNAVAIL: winbind not around
47 result == NSS_STATUS_NOTFOUND: winbind around, but domain missing
49 Due to a bad API NSS_STATUS_NOTFOUND is returned both when winbind_off
50 and when winbind return WINBINDD_ERROR. So the semantics of this
51 routine depends on winbind_on. Grepping for winbind_off I just
52 found 3 places where winbind is turned off, and this does not conflict
53 (as far as I have seen) with the callers of is_trusted_domains.
55 --Volker
56 **********************************************************************/
58 static wbcErr wbcRequestResponseInt(
59 int cmd,
60 struct winbindd_request *request,
61 struct winbindd_response *response,
62 NSS_STATUS (*fn)(int req_type,
63 struct winbindd_request *request,
64 struct winbindd_response *response))
66 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
67 NSS_STATUS nss_status;
69 /* for some calls the request and/or response can be NULL */
71 nss_status = fn(cmd, request, response);
73 switch (nss_status) {
74 case NSS_STATUS_SUCCESS:
75 wbc_status = WBC_ERR_SUCCESS;
76 break;
77 case NSS_STATUS_UNAVAIL:
78 wbc_status = WBC_ERR_WINBIND_NOT_AVAILABLE;
79 break;
80 case NSS_STATUS_NOTFOUND:
81 wbc_status = WBC_ERR_DOMAIN_NOT_FOUND;
82 break;
83 default:
84 wbc_status = WBC_ERR_NSS_ERROR;
85 break;
88 return wbc_status;
91 wbcErr wbcRequestResponse(int cmd,
92 struct winbindd_request *request,
93 struct winbindd_response *response)
95 return wbcRequestResponseInt(cmd, request, response,
96 winbindd_request_response);
99 wbcErr wbcRequestResponsePriv(int cmd,
100 struct winbindd_request *request,
101 struct winbindd_response *response)
103 return wbcRequestResponseInt(cmd, request, response,
104 winbindd_priv_request_response);
107 /** @brief Translate an error value into a string
109 * @param error
111 * @return a pointer to a static string
113 const char *wbcErrorString(wbcErr error)
115 switch (error) {
116 case WBC_ERR_SUCCESS:
117 return "WBC_ERR_SUCCESS";
118 case WBC_ERR_NOT_IMPLEMENTED:
119 return "WBC_ERR_NOT_IMPLEMENTED";
120 case WBC_ERR_UNKNOWN_FAILURE:
121 return "WBC_ERR_UNKNOWN_FAILURE";
122 case WBC_ERR_NO_MEMORY:
123 return "WBC_ERR_NO_MEMORY";
124 case WBC_ERR_INVALID_SID:
125 return "WBC_ERR_INVALID_SID";
126 case WBC_ERR_INVALID_PARAM:
127 return "WBC_ERR_INVALID_PARAM";
128 case WBC_ERR_WINBIND_NOT_AVAILABLE:
129 return "WBC_ERR_WINBIND_NOT_AVAILABLE";
130 case WBC_ERR_DOMAIN_NOT_FOUND:
131 return "WBC_ERR_DOMAIN_NOT_FOUND";
132 case WBC_ERR_INVALID_RESPONSE:
133 return "WBC_ERR_INVALID_RESPONSE";
134 case WBC_ERR_NSS_ERROR:
135 return "WBC_ERR_NSS_ERROR";
136 case WBC_ERR_UNKNOWN_USER:
137 return "WBC_ERR_UNKNOWN_USER";
138 case WBC_ERR_UNKNOWN_GROUP:
139 return "WBC_ERR_UNKNOWN_GROUP";
140 case WBC_ERR_AUTH_ERROR:
141 return "WBC_ERR_AUTH_ERROR";
142 case WBC_ERR_PWD_CHANGE_FAILED:
143 return "WBC_ERR_PWD_CHANGE_FAILED";
146 return "unknown wbcErr value";
149 /* Free library allocated memory */
150 void wbcFreeMemory(void *p)
152 if (p)
153 talloc_free(p);
155 return;
158 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details)
160 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
161 struct wbcLibraryDetails *info;
163 info = talloc(NULL, struct wbcLibraryDetails);
164 BAIL_ON_PTR_ERROR(info, wbc_status);
166 info->major_version = WBCLIENT_MAJOR_VERSION;
167 info->minor_version = WBCLIENT_MINOR_VERSION;
168 info->vendor_version = talloc_strdup(info,
169 WBCLIENT_VENDOR_VERSION);
170 BAIL_ON_PTR_ERROR(info->vendor_version, wbc_status);
172 *_details = info;
173 info = NULL;
175 wbc_status = WBC_ERR_SUCCESS;
177 done:
178 talloc_free(info);
179 return wbc_status;