s3/passdb: Fix debug message: 'net setmaxrid' does not exist.
[Samba/ekacnet.git] / source3 / libads / cldap.c
blob4c3716a470f724bf11a8b79e0b9d1d484eb3f4bc
1 /*
2 Samba Unix/Linux SMB client library
3 net ads cldap functions
4 Copyright (C) 2001 Andrew Tridgell (tridge@samba.org)
5 Copyright (C) 2003 Jim McDonough (jmcd@us.ibm.com)
6 Copyright (C) 2008 Guenther Deschner (gd@samba.org)
7 Copyright (C) 2009 Stefan Metzmacher (metze@samba.org)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program 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
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "includes.h"
24 #include "../libcli/cldap/cldap.h"
25 #include "../lib/tsocket/tsocket.h"
27 /*******************************************************************
28 do a cldap netlogon query. Always 389/udp
29 *******************************************************************/
31 bool ads_cldap_netlogon(TALLOC_CTX *mem_ctx,
32 const char *server,
33 const char *realm,
34 uint32_t nt_version,
35 struct netlogon_samlogon_response **_reply)
37 struct cldap_socket *cldap;
38 struct cldap_netlogon io;
39 struct netlogon_samlogon_response *reply;
40 NTSTATUS status;
41 struct in_addr addr;
42 char addrstr[INET_ADDRSTRLEN];
43 const char *dest_str;
44 int ret;
45 struct tsocket_address *dest_addr;
47 /* TODO: support ipv6 */
49 addr = interpret_addr2(server);
50 if (is_zero_ip_v4(addr)) {
51 DEBUG(2,("Failed to resolve[%s] into an address for cldap\n",
52 server));
53 return false;
55 dest_str = inet_ntop(AF_INET, &addr,
56 addrstr, sizeof(addrstr));
57 if (!dest_str) {
58 DEBUG(2,("Failed to resolve[%s] into an address for cldap\n",
59 server));
60 return false;
63 ret = tsocket_address_inet_from_strings(mem_ctx, "ipv4",
64 dest_str, LDAP_PORT,
65 &dest_addr);
66 if (ret != 0) {
67 status = map_nt_error_from_unix(errno);
68 DEBUG(2,("Failed to create cldap tsocket_address for %s - %s\n",
69 dest_str, nt_errstr(status)));
70 return false;
74 * as we use a connected udp socket
76 status = cldap_socket_init(mem_ctx, NULL, NULL, dest_addr, &cldap);
77 TALLOC_FREE(dest_addr);
78 if (!NT_STATUS_IS_OK(status)) {
79 DEBUG(2,("Failed to create cldap socket to %s: %s\n",
80 dest_str, nt_errstr(status)));
81 return false;
84 reply = talloc(cldap, struct netlogon_samlogon_response);
85 if (!reply) {
86 goto failed;
90 * as we use a connected socket, so we don't need to specify the
91 * destination
93 io.in.dest_address = NULL;
94 io.in.dest_port = 0;
95 io.in.realm = realm;
96 io.in.host = NULL;
97 io.in.user = NULL;
98 io.in.domain_guid = NULL;
99 io.in.domain_sid = NULL;
100 io.in.acct_control = 0;
101 io.in.version = nt_version;
102 io.in.map_response = false;
104 status = cldap_netlogon(cldap, NULL, reply, &io);
105 if (!NT_STATUS_IS_OK(status)) {
106 DEBUG(2,("cldap_netlogon() failed: %s\n", nt_errstr(status)));
107 goto failed;
110 *reply = io.out.netlogon;
111 *_reply = talloc_move(mem_ctx, &reply);
112 TALLOC_FREE(cldap);
113 return true;
114 failed:
115 TALLOC_FREE(cldap);
116 return false;
119 /*******************************************************************
120 do a cldap netlogon query. Always 389/udp
121 *******************************************************************/
123 bool ads_cldap_netlogon_5(TALLOC_CTX *mem_ctx,
124 const char *server,
125 const char *realm,
126 struct NETLOGON_SAM_LOGON_RESPONSE_EX *reply5)
128 uint32_t nt_version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
129 struct netlogon_samlogon_response *reply = NULL;
130 bool ret;
132 ret = ads_cldap_netlogon(mem_ctx, server, realm, nt_version, &reply);
133 if (!ret) {
134 return false;
137 if (reply->ntver != NETLOGON_NT_VERSION_5EX) {
138 DEBUG(0,("ads_cldap_netlogon_5: nt_version mismatch: 0x%08x\n",
139 reply->ntver));
140 return false;
143 *reply5 = reply->data.nt5_ex;
145 return true;