| 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 |
|
|---|
| 36 | /** @brief Wrapper around Winbind's send/receive API call
|
|---|
| 37 | *
|
|---|
| 38 | * @param cmd Winbind command operation to perform
|
|---|
| 39 | * @param request Send structure
|
|---|
| 40 | * @param response Receive structure
|
|---|
| 41 | *
|
|---|
| 42 | * @return #wbcErr
|
|---|
| 43 | **/
|
|---|
| 44 |
|
|---|
| 45 | /**********************************************************************
|
|---|
| 46 | result == NSS_STATUS_UNAVAIL: winbind not around
|
|---|
| 47 | result == NSS_STATUS_NOTFOUND: winbind around, but domain missing
|
|---|
| 48 |
|
|---|
| 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.
|
|---|
| 54 |
|
|---|
| 55 | --Volker
|
|---|
| 56 | **********************************************************************/
|
|---|
| 57 |
|
|---|
| 58 | wbcErr wbcRequestResponse(int cmd,
|
|---|
| 59 | struct winbindd_request *request,
|
|---|
| 60 | struct winbindd_response *response)
|
|---|
| 61 | {
|
|---|
| 62 | wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
|
|---|
| 63 | NSS_STATUS nss_status;
|
|---|
| 64 |
|
|---|
| 65 | /* for some calls the request and/or response can be NULL */
|
|---|
| 66 |
|
|---|
| 67 | nss_status = winbindd_request_response(cmd, request, response);
|
|---|
| 68 |
|
|---|
| 69 | switch (nss_status) {
|
|---|
| 70 | case NSS_STATUS_SUCCESS:
|
|---|
| 71 | wbc_status = WBC_ERR_SUCCESS;
|
|---|
| 72 | break;
|
|---|
| 73 | case NSS_STATUS_UNAVAIL:
|
|---|
| 74 | wbc_status = WBC_ERR_WINBIND_NOT_AVAILABLE;
|
|---|
| 75 | break;
|
|---|
| 76 | case NSS_STATUS_NOTFOUND:
|
|---|
| 77 | wbc_status = WBC_ERR_DOMAIN_NOT_FOUND;
|
|---|
| 78 | break;
|
|---|
| 79 | default:
|
|---|
| 80 | wbc_status = WBC_ERR_NSS_ERROR;
|
|---|
| 81 | break;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | return wbc_status;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /** @brief Translate an error value into a string
|
|---|
| 88 | *
|
|---|
| 89 | * @param error
|
|---|
| 90 | *
|
|---|
| 91 | * @return a pointer to a static string
|
|---|
| 92 | **/
|
|---|
| 93 | const char *wbcErrorString(wbcErr error)
|
|---|
| 94 | {
|
|---|
| 95 | switch (error) {
|
|---|
| 96 | case WBC_ERR_SUCCESS:
|
|---|
| 97 | return "WBC_ERR_SUCCESS";
|
|---|
| 98 | case WBC_ERR_NOT_IMPLEMENTED:
|
|---|
| 99 | return "WBC_ERR_NOT_IMPLEMENTED";
|
|---|
| 100 | case WBC_ERR_UNKNOWN_FAILURE:
|
|---|
| 101 | return "WBC_ERR_UNKNOWN_FAILURE";
|
|---|
| 102 | case WBC_ERR_NO_MEMORY:
|
|---|
| 103 | return "WBC_ERR_NO_MEMORY";
|
|---|
| 104 | case WBC_ERR_INVALID_SID:
|
|---|
| 105 | return "WBC_ERR_INVALID_SID";
|
|---|
| 106 | case WBC_ERR_INVALID_PARAM:
|
|---|
| 107 | return "WBC_ERR_INVALID_PARAM";
|
|---|
| 108 | case WBC_ERR_WINBIND_NOT_AVAILABLE:
|
|---|
| 109 | return "WBC_ERR_WINBIND_NOT_AVAILABLE";
|
|---|
| 110 | case WBC_ERR_DOMAIN_NOT_FOUND:
|
|---|
| 111 | return "WBC_ERR_DOMAIN_NOT_FOUND";
|
|---|
| 112 | case WBC_ERR_INVALID_RESPONSE:
|
|---|
| 113 | return "WBC_ERR_INVALID_RESPONSE";
|
|---|
| 114 | case WBC_ERR_NSS_ERROR:
|
|---|
| 115 | return "WBC_ERR_NSS_ERROR";
|
|---|
| 116 | case WBC_ERR_UNKNOWN_USER:
|
|---|
| 117 | return "WBC_ERR_UNKNOWN_USER";
|
|---|
| 118 | case WBC_ERR_UNKNOWN_GROUP:
|
|---|
| 119 | return "WBC_ERR_UNKNOWN_GROUP";
|
|---|
| 120 | case WBC_ERR_AUTH_ERROR:
|
|---|
| 121 | return "WBC_ERR_AUTH_ERROR";
|
|---|
| 122 | case WBC_ERR_PWD_CHANGE_FAILED:
|
|---|
| 123 | return "WBC_ERR_PWD_CHANGE_FAILED";
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | return "unknown wbcErr value";
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | /* Free library allocated memory */
|
|---|
| 130 | void wbcFreeMemory(void *p)
|
|---|
| 131 | {
|
|---|
| 132 | if (p)
|
|---|
| 133 | talloc_free(p);
|
|---|
| 134 |
|
|---|
| 135 | return;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details)
|
|---|
| 139 | {
|
|---|
| 140 | wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
|
|---|
| 141 | struct wbcLibraryDetails *info;
|
|---|
| 142 |
|
|---|
| 143 | info = talloc(NULL, struct wbcLibraryDetails);
|
|---|
| 144 | BAIL_ON_PTR_ERROR(info, wbc_status);
|
|---|
| 145 |
|
|---|
| 146 | info->major_version = WBCLIENT_MAJOR_VERSION;
|
|---|
| 147 | info->minor_version = WBCLIENT_MINOR_VERSION;
|
|---|
| 148 | info->vendor_version = talloc_strdup(info,
|
|---|
| 149 | WBCLIENT_VENDOR_VERSION);
|
|---|
| 150 | BAIL_ON_PTR_ERROR(info->vendor_version, wbc_status);
|
|---|
| 151 |
|
|---|
| 152 | *_details = info;
|
|---|
| 153 | info = NULL;
|
|---|
| 154 |
|
|---|
| 155 | wbc_status = WBC_ERR_SUCCESS;
|
|---|
| 156 |
|
|---|
| 157 | done:
|
|---|
| 158 | talloc_free(info);
|
|---|
| 159 | return wbc_status;
|
|---|
| 160 | }
|
|---|