source: branches/samba-3.3.x/source/nsswitch/libwbclient/wbclient.c

Last change on this file was 206, checked in by Herwig Bauernfeind, 16 years ago

Import Samba 3.3 branch at 3.0.0 level (psmedley's port)

File size: 4.2 KB
Line 
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
29NSS_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
55wbcErr 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 /* for some calls the request and/or response can be NULL */
63
64 nss_status = winbindd_request_response(cmd, request, response);
65
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;
79 }
80
81 return wbc_status;
82}
83
84/** @brief Translate an error value into a string
85 *
86 * @param error
87 *
88 * @return a pointer to a static string
89 **/
90const char *wbcErrorString(wbcErr error)
91{
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";
121 }
122
123 return "unknown wbcErr value";
124}
125
126/** @brief Free library allocated memory
127 *
128 * @param *p Pointer to free
129 *
130 * @return void
131 **/
132
133void wbcFreeMemory(void *p)
134{
135 if (p)
136 talloc_free(p);
137
138 return;
139}
140
141wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details)
142{
143 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
144 struct wbcLibraryDetails *info;
145
146 info = talloc(NULL, struct wbcLibraryDetails);
147 BAIL_ON_PTR_ERROR(info, wbc_status);
148
149 info->major_version = WBCLIENT_MAJOR_VERSION;
150 info->minor_version = WBCLIENT_MINOR_VERSION;
151 info->vendor_version = talloc_strdup(info,
152 WBCLIENT_VENDOR_VERSION);
153 BAIL_ON_PTR_ERROR(info->vendor_version, wbc_status);
154
155 *_details = info;
156 info = NULL;
157
158 wbc_status = WBC_ERR_SUCCESS;
159
160done:
161 talloc_free(info);
162 return wbc_status;
163}
164
165
Note: See TracBrowser for help on using the repository browser.