| 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 "replace.h"
|
|---|
| 26 | #include "talloc.h"
|
|---|
| 27 | #include "tevent.h"
|
|---|
| 28 | #include "libwbclient.h"
|
|---|
| 29 |
|
|---|
| 30 | /* From wb_common.c */
|
|---|
| 31 |
|
|---|
| 32 | NSS_STATUS winbindd_request_response(int req_type,
|
|---|
| 33 | struct winbindd_request *request,
|
|---|
| 34 | struct winbindd_response *response);
|
|---|
| 35 | NSS_STATUS winbindd_priv_request_response(int req_type,
|
|---|
| 36 | struct winbindd_request *request,
|
|---|
| 37 | struct winbindd_response *response);
|
|---|
| 38 |
|
|---|
| 39 | /** @brief Wrapper around Winbind's send/receive API call
|
|---|
| 40 | *
|
|---|
| 41 | * @param cmd Winbind command operation to perform
|
|---|
| 42 | * @param request Send structure
|
|---|
| 43 | * @param response Receive structure
|
|---|
| 44 | *
|
|---|
| 45 | * @return #wbcErr
|
|---|
| 46 | **/
|
|---|
| 47 |
|
|---|
| 48 | /**********************************************************************
|
|---|
| 49 | result == NSS_STATUS_UNAVAIL: winbind not around
|
|---|
| 50 | result == NSS_STATUS_NOTFOUND: winbind around, but domain missing
|
|---|
| 51 |
|
|---|
| 52 | Due to a bad API NSS_STATUS_NOTFOUND is returned both when winbind_off
|
|---|
| 53 | and when winbind return WINBINDD_ERROR. So the semantics of this
|
|---|
| 54 | routine depends on winbind_on. Grepping for winbind_off I just
|
|---|
| 55 | found 3 places where winbind is turned off, and this does not conflict
|
|---|
| 56 | (as far as I have seen) with the callers of is_trusted_domains.
|
|---|
| 57 |
|
|---|
| 58 | --Volker
|
|---|
| 59 | **********************************************************************/
|
|---|
| 60 |
|
|---|
| 61 | static wbcErr wbcRequestResponseInt(
|
|---|
| 62 | int cmd,
|
|---|
| 63 | struct winbindd_request *request,
|
|---|
| 64 | struct winbindd_response *response,
|
|---|
| 65 | NSS_STATUS (*fn)(int req_type,
|
|---|
| 66 | struct winbindd_request *request,
|
|---|
| 67 | struct winbindd_response *response))
|
|---|
| 68 | {
|
|---|
| 69 | wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
|
|---|
| 70 | NSS_STATUS nss_status;
|
|---|
| 71 |
|
|---|
| 72 | /* for some calls the request and/or response can be NULL */
|
|---|
| 73 |
|
|---|
| 74 | nss_status = fn(cmd, request, response);
|
|---|
| 75 |
|
|---|
| 76 | switch (nss_status) {
|
|---|
| 77 | case NSS_STATUS_SUCCESS:
|
|---|
| 78 | wbc_status = WBC_ERR_SUCCESS;
|
|---|
| 79 | break;
|
|---|
| 80 | case NSS_STATUS_UNAVAIL:
|
|---|
| 81 | wbc_status = WBC_ERR_WINBIND_NOT_AVAILABLE;
|
|---|
| 82 | break;
|
|---|
| 83 | case NSS_STATUS_NOTFOUND:
|
|---|
| 84 | wbc_status = WBC_ERR_DOMAIN_NOT_FOUND;
|
|---|
| 85 | break;
|
|---|
| 86 | default:
|
|---|
| 87 | wbc_status = WBC_ERR_NSS_ERROR;
|
|---|
| 88 | break;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | return wbc_status;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | wbcErr wbcRequestResponse(int cmd,
|
|---|
| 95 | struct winbindd_request *request,
|
|---|
| 96 | struct winbindd_response *response)
|
|---|
| 97 | {
|
|---|
| 98 | return wbcRequestResponseInt(cmd, request, response,
|
|---|
| 99 | winbindd_request_response);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | wbcErr wbcRequestResponsePriv(int cmd,
|
|---|
| 103 | struct winbindd_request *request,
|
|---|
| 104 | struct winbindd_response *response)
|
|---|
| 105 | {
|
|---|
| 106 | return wbcRequestResponseInt(cmd, request, response,
|
|---|
| 107 | winbindd_priv_request_response);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | /** @brief Translate an error value into a string
|
|---|
| 111 | *
|
|---|
| 112 | * @param error
|
|---|
| 113 | *
|
|---|
| 114 | * @return a pointer to a static string
|
|---|
| 115 | **/
|
|---|
| 116 | const char *wbcErrorString(wbcErr error)
|
|---|
| 117 | {
|
|---|
| 118 | switch (error) {
|
|---|
| 119 | case WBC_ERR_SUCCESS:
|
|---|
| 120 | return "WBC_ERR_SUCCESS";
|
|---|
| 121 | case WBC_ERR_NOT_IMPLEMENTED:
|
|---|
| 122 | return "WBC_ERR_NOT_IMPLEMENTED";
|
|---|
| 123 | case WBC_ERR_UNKNOWN_FAILURE:
|
|---|
| 124 | return "WBC_ERR_UNKNOWN_FAILURE";
|
|---|
| 125 | case WBC_ERR_NO_MEMORY:
|
|---|
| 126 | return "WBC_ERR_NO_MEMORY";
|
|---|
| 127 | case WBC_ERR_INVALID_SID:
|
|---|
| 128 | return "WBC_ERR_INVALID_SID";
|
|---|
| 129 | case WBC_ERR_INVALID_PARAM:
|
|---|
| 130 | return "WBC_ERR_INVALID_PARAM";
|
|---|
| 131 | case WBC_ERR_WINBIND_NOT_AVAILABLE:
|
|---|
| 132 | return "WBC_ERR_WINBIND_NOT_AVAILABLE";
|
|---|
| 133 | case WBC_ERR_DOMAIN_NOT_FOUND:
|
|---|
| 134 | return "WBC_ERR_DOMAIN_NOT_FOUND";
|
|---|
| 135 | case WBC_ERR_INVALID_RESPONSE:
|
|---|
| 136 | return "WBC_ERR_INVALID_RESPONSE";
|
|---|
| 137 | case WBC_ERR_NSS_ERROR:
|
|---|
| 138 | return "WBC_ERR_NSS_ERROR";
|
|---|
| 139 | case WBC_ERR_UNKNOWN_USER:
|
|---|
| 140 | return "WBC_ERR_UNKNOWN_USER";
|
|---|
| 141 | case WBC_ERR_UNKNOWN_GROUP:
|
|---|
| 142 | return "WBC_ERR_UNKNOWN_GROUP";
|
|---|
| 143 | case WBC_ERR_AUTH_ERROR:
|
|---|
| 144 | return "WBC_ERR_AUTH_ERROR";
|
|---|
| 145 | case WBC_ERR_PWD_CHANGE_FAILED:
|
|---|
| 146 | return "WBC_ERR_PWD_CHANGE_FAILED";
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | return "unknown wbcErr value";
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | /* Free library allocated memory */
|
|---|
| 153 | void wbcFreeMemory(void *p)
|
|---|
| 154 | {
|
|---|
| 155 | if (p)
|
|---|
| 156 | talloc_free(p);
|
|---|
| 157 |
|
|---|
| 158 | return;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details)
|
|---|
| 162 | {
|
|---|
| 163 | wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
|
|---|
| 164 | struct wbcLibraryDetails *info;
|
|---|
| 165 |
|
|---|
| 166 | info = talloc(NULL, struct wbcLibraryDetails);
|
|---|
| 167 | BAIL_ON_PTR_ERROR(info, wbc_status);
|
|---|
| 168 |
|
|---|
| 169 | info->major_version = WBCLIENT_MAJOR_VERSION;
|
|---|
| 170 | info->minor_version = WBCLIENT_MINOR_VERSION;
|
|---|
| 171 | info->vendor_version = talloc_strdup(info,
|
|---|
| 172 | WBCLIENT_VENDOR_VERSION);
|
|---|
| 173 | BAIL_ON_PTR_ERROR(info->vendor_version, wbc_status);
|
|---|
| 174 |
|
|---|
| 175 | *_details = info;
|
|---|
| 176 | info = NULL;
|
|---|
| 177 |
|
|---|
| 178 | wbc_status = WBC_ERR_SUCCESS;
|
|---|
| 179 |
|
|---|
| 180 | done:
|
|---|
| 181 | talloc_free(info);
|
|---|
| 182 | return wbc_status;
|
|---|
| 183 | }
|
|---|