Do not start a transaction this way.
[Samba.git] / nsswitch / libwbclient / wbclient.c
blobf5c72315f2e117ea87bb46c1d5de48a3dae03935
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);
33 /** @brief Wrapper around Winbind's send/receive API call
35 * @param cmd Winbind command operation to perform
36 * @param request Send structure
37 * @param response Receive structure
39 * @return #wbcErr
40 **/
42 /**********************************************************************
43 result == NSS_STATUS_UNAVAIL: winbind not around
44 result == NSS_STATUS_NOTFOUND: winbind around, but domain missing
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.
52 --Volker
53 **********************************************************************/
55 wbcErr wbcRequestResponse(int cmd,
56 struct winbindd_request *request,
57 struct winbindd_response *response)
59 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
60 NSS_STATUS nss_status;
62 /* for some calls the request and/or response can be NULL */
64 nss_status = winbindd_request_response(cmd, request, response);
66 switch (nss_status) {
67 case NSS_STATUS_SUCCESS:
68 wbc_status = WBC_ERR_SUCCESS;
69 break;
70 case NSS_STATUS_UNAVAIL:
71 wbc_status = WBC_ERR_WINBIND_NOT_AVAILABLE;
72 break;
73 case NSS_STATUS_NOTFOUND:
74 wbc_status = WBC_ERR_DOMAIN_NOT_FOUND;
75 break;
76 default:
77 wbc_status = WBC_ERR_NSS_ERROR;
78 break;
81 return wbc_status;
84 /** @brief Translate an error value into a string
86 * @param error
88 * @return a pointer to a static string
89 **/
90 const char *wbcErrorString(wbcErr error)
92 switch (error) {
93 case WBC_ERR_SUCCESS:
94 return "WBC_ERR_SUCCESS";
95 case WBC_ERR_NOT_IMPLEMENTED:
96 return "WBC_ERR_NOT_IMPLEMENTED";
97 case WBC_ERR_UNKNOWN_FAILURE:
98 return "WBC_ERR_UNKNOWN_FAILURE";
99 case WBC_ERR_NO_MEMORY:
100 return "WBC_ERR_NO_MEMORY";
101 case WBC_ERR_INVALID_SID:
102 return "WBC_ERR_INVALID_SID";
103 case WBC_ERR_INVALID_PARAM:
104 return "WBC_ERR_INVALID_PARAM";
105 case WBC_ERR_WINBIND_NOT_AVAILABLE:
106 return "WBC_ERR_WINBIND_NOT_AVAILABLE";
107 case WBC_ERR_DOMAIN_NOT_FOUND:
108 return "WBC_ERR_DOMAIN_NOT_FOUND";
109 case WBC_ERR_INVALID_RESPONSE:
110 return "WBC_ERR_INVALID_RESPONSE";
111 case WBC_ERR_NSS_ERROR:
112 return "WBC_ERR_NSS_ERROR";
113 case WBC_ERR_UNKNOWN_USER:
114 return "WBC_ERR_UNKNOWN_USER";
115 case WBC_ERR_UNKNOWN_GROUP:
116 return "WBC_ERR_UNKNOWN_GROUP";
117 case WBC_ERR_AUTH_ERROR:
118 return "WBC_ERR_AUTH_ERROR";
119 case WBC_ERR_PWD_CHANGE_FAILED:
120 return "WBC_ERR_PWD_CHANGE_FAILED";
123 return "unknown wbcErr value";
126 /* Free library allocated memory */
127 void wbcFreeMemory(void *p)
129 if (p)
130 talloc_free(p);
132 return;
135 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details)
137 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
138 struct wbcLibraryDetails *info;
140 info = talloc(NULL, struct wbcLibraryDetails);
141 BAIL_ON_PTR_ERROR(info, wbc_status);
143 info->major_version = WBCLIENT_MAJOR_VERSION;
144 info->minor_version = WBCLIENT_MINOR_VERSION;
145 info->vendor_version = talloc_strdup(info,
146 WBCLIENT_VENDOR_VERSION);
147 BAIL_ON_PTR_ERROR(info->vendor_version, wbc_status);
149 *_details = info;
150 info = NULL;
152 wbc_status = WBC_ERR_SUCCESS;
154 done:
155 talloc_free(info);
156 return wbc_status;