Revert "s3:configure: add --enable-as-needed"
[Samba/gebeck_regimport.git] / nsswitch / libwbclient / wbclient.c
blob31a736da0b59d3f3b53d7daf4f36e52fde419805
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 "replace.h"
26 #include "libwbclient.h"
28 /* From wb_common.c */
30 NSS_STATUS winbindd_request_response(int req_type,
31 struct winbindd_request *request,
32 struct winbindd_response *response);
34 /** @brief Wrapper around Winbind's send/receive API call
36 * @param cmd Winbind command operation to perform
37 * @param request Send structure
38 * @param response Receive structure
40 * @return #wbcErr
41 **/
43 /**********************************************************************
44 result == NSS_STATUS_UNAVAIL: winbind not around
45 result == NSS_STATUS_NOTFOUND: winbind around, but domain missing
47 Due to a bad API NSS_STATUS_NOTFOUND is returned both when winbind_off
48 and when winbind return WINBINDD_ERROR. So the semantics of this
49 routine depends on winbind_on. Grepping for winbind_off I just
50 found 3 places where winbind is turned off, and this does not conflict
51 (as far as I have seen) with the callers of is_trusted_domains.
53 --Volker
54 **********************************************************************/
56 wbcErr wbcRequestResponse(int cmd,
57 struct winbindd_request *request,
58 struct winbindd_response *response)
60 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
61 NSS_STATUS nss_status;
63 /* for some calls the request and/or response can be NULL */
65 nss_status = winbindd_request_response(cmd, request, response);
67 switch (nss_status) {
68 case NSS_STATUS_SUCCESS:
69 wbc_status = WBC_ERR_SUCCESS;
70 break;
71 case NSS_STATUS_UNAVAIL:
72 wbc_status = WBC_ERR_WINBIND_NOT_AVAILABLE;
73 break;
74 case NSS_STATUS_NOTFOUND:
75 wbc_status = WBC_ERR_DOMAIN_NOT_FOUND;
76 break;
77 default:
78 wbc_status = WBC_ERR_NSS_ERROR;
79 break;
82 return wbc_status;
85 /** @brief Translate an error value into a string
87 * @param error
89 * @return a pointer to a static string
90 **/
91 const char *wbcErrorString(wbcErr error)
93 switch (error) {
94 case WBC_ERR_SUCCESS:
95 return "WBC_ERR_SUCCESS";
96 case WBC_ERR_NOT_IMPLEMENTED:
97 return "WBC_ERR_NOT_IMPLEMENTED";
98 case WBC_ERR_UNKNOWN_FAILURE:
99 return "WBC_ERR_UNKNOWN_FAILURE";
100 case WBC_ERR_NO_MEMORY:
101 return "WBC_ERR_NO_MEMORY";
102 case WBC_ERR_INVALID_SID:
103 return "WBC_ERR_INVALID_SID";
104 case WBC_ERR_INVALID_PARAM:
105 return "WBC_ERR_INVALID_PARAM";
106 case WBC_ERR_WINBIND_NOT_AVAILABLE:
107 return "WBC_ERR_WINBIND_NOT_AVAILABLE";
108 case WBC_ERR_DOMAIN_NOT_FOUND:
109 return "WBC_ERR_DOMAIN_NOT_FOUND";
110 case WBC_ERR_INVALID_RESPONSE:
111 return "WBC_ERR_INVALID_RESPONSE";
112 case WBC_ERR_NSS_ERROR:
113 return "WBC_ERR_NSS_ERROR";
114 case WBC_ERR_UNKNOWN_USER:
115 return "WBC_ERR_UNKNOWN_USER";
116 case WBC_ERR_UNKNOWN_GROUP:
117 return "WBC_ERR_UNKNOWN_GROUP";
118 case WBC_ERR_AUTH_ERROR:
119 return "WBC_ERR_AUTH_ERROR";
120 case WBC_ERR_PWD_CHANGE_FAILED:
121 return "WBC_ERR_PWD_CHANGE_FAILED";
124 return "unknown wbcErr value";
127 /* Free library allocated memory */
128 void wbcFreeMemory(void *p)
130 if (p)
131 talloc_free(p);
133 return;
136 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details)
138 struct wbcLibraryDetails *info;
140 info = talloc(NULL, struct wbcLibraryDetails);
141 if (info == NULL) {
142 return WBC_ERR_NO_MEMORY;
145 info->major_version = WBCLIENT_MAJOR_VERSION;
146 info->minor_version = WBCLIENT_MINOR_VERSION;
147 info->vendor_version = WBCLIENT_VENDOR_VERSION;
149 *_details = info;
150 return WBC_ERR_SUCCESS;