summaryrefslogtreecommitdiff
path: root/source3/nsswitch/libwbclient/wbclient.c
blob: 9383fd5406d58a00f57b1325f30d5f957513a9ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
   Unix SMB/CIFS implementation.

   Winbind client API

   Copyright (C) Gerald (Jerry) Carter 2007


   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/* Required Headers */

#include "libwbclient.h"

/* From wb_common.c */

NSS_STATUS winbindd_request_response(int req_type,
				     struct winbindd_request *request,
				     struct winbindd_response *response);

/** @brief Wrapper around Winbind's send/receive API call
 *
 * @param cmd       Winbind command operation to perform
 * @param request   Send structure
 * @param response  Receive structure
 *
 * @return #wbcErr
 **/

/**********************************************************************
 result == NSS_STATUS_UNAVAIL: winbind not around
 result == NSS_STATUS_NOTFOUND: winbind around, but domain missing

 Due to a bad API NSS_STATUS_NOTFOUND is returned both when winbind_off
 and when winbind return WINBINDD_ERROR. So the semantics of this
 routine depends on winbind_on. Grepping for winbind_off I just
 found 3 places where winbind is turned off, and this does not conflict
 (as far as I have seen) with the callers of is_trusted_domains.

 --Volker
**********************************************************************/

wbcErr wbcRequestResponse(int cmd,
			  struct winbindd_request *request,
			  struct winbindd_response *response)
{
	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
	NSS_STATUS nss_status;

	/* for some calls the request and/or response cna be NULL */

	nss_status = winbindd_request_response(cmd, request, response);

	switch (nss_status) {
	case NSS_STATUS_SUCCESS:
		wbc_status = WBC_ERR_SUCCESS;
		break;
	case NSS_STATUS_UNAVAIL:
		wbc_status = WBC_ERR_WINBIND_NOT_AVAILABLE;
		break;
	case NSS_STATUS_NOTFOUND:
		wbc_status = WBC_ERR_DOMAIN_NOT_FOUND;
		break;
	default:
		wbc_status = WBC_ERR_NSS_ERROR;
		break;
	}

	return wbc_status;
}

/** @brief Translate an error value into a string
 *
 * @param error
 *
 * @return a pointer to a static string
 **/
const char *wbcErrorString(wbcErr error)
{
	switch (error) {
	case WBC_ERR_SUCCESS:
		return "WBC_ERR_SUCCESS";
	case WBC_ERR_NOT_IMPLEMENTED:
		return "WBC_ERR_NOT_IMPLEMENTED";
	case WBC_ERR_UNKNOWN_FAILURE:
		return "WBC_ERR_UNKNOWN_FAILURE";
	case WBC_ERR_NO_MEMORY:
		return "WBC_ERR_NO_MEMORY";
	case WBC_ERR_INVALID_SID:
		return "WBC_ERR_INVALID_SID";
	case WBC_ERR_INVALID_PARAM:
		return "WBC_ERR_INVALID_PARAM";
	case WBC_ERR_WINBIND_NOT_AVAILABLE:
		return "WBC_ERR_WINBIND_NOT_AVAILABLE";
	case WBC_ERR_DOMAIN_NOT_FOUND:
		return "WBC_ERR_DOMAIN_NOT_FOUND";
	case WBC_ERR_INVALID_RESPONSE:
		return "WBC_ERR_INVALID_RESPONSE";
	case WBC_ERR_NSS_ERROR:
		return "WBC_ERR_NSS_ERROR";
	case WBC_ERR_AUTH_ERROR:
		return "WBC_ERR_AUTH_ERROR";
	}

	return "unknown wbcErr value";
}

/** @brief Free library allocated memory
 *
 * @param *p Pointer to free
 *
 * @return void
 **/

void wbcFreeMemory(void *p)
{
	if (p)
		talloc_free(p);

	return;
}