s4-kcc: correctly populate the neighbor object when taking information from repsTo
[Samba/gebeck_regimport.git] / source3 / libads / cldap.c
blob03fa17c26fd3e02cbd771cf98f6b31b4e32e7f09
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"
26 #include "libads/cldap.h"
28 /*******************************************************************
29 do a cldap netlogon query. Always 389/udp
30 *******************************************************************/
32 bool ads_cldap_netlogon(TALLOC_CTX *mem_ctx,
33 struct sockaddr_storage *ss,
34 const char *realm,
35 uint32_t nt_version,
36 struct netlogon_samlogon_response **_reply)
38 struct cldap_socket *cldap;
39 struct cldap_netlogon io;
40 struct netlogon_samlogon_response *reply;
41 NTSTATUS status;
42 char addrstr[INET6_ADDRSTRLEN];
43 const char *dest_str;
44 int ret;
45 struct tsocket_address *dest_addr;
47 dest_str = print_sockaddr(addrstr, sizeof(addrstr), ss);
49 ret = tsocket_address_inet_from_strings(mem_ctx, "ip",
50 dest_str, LDAP_PORT,
51 &dest_addr);
52 if (ret != 0) {
53 status = map_nt_error_from_unix(errno);
54 DEBUG(2,("Failed to create cldap tsocket_address for %s - %s\n",
55 dest_str, nt_errstr(status)));
56 return false;
60 * as we use a connected udp socket
62 status = cldap_socket_init(mem_ctx, NULL, NULL, dest_addr, &cldap);
63 TALLOC_FREE(dest_addr);
64 if (!NT_STATUS_IS_OK(status)) {
65 DEBUG(2,("Failed to create cldap socket to %s: %s\n",
66 dest_str, nt_errstr(status)));
67 return false;
70 reply = talloc(cldap, struct netlogon_samlogon_response);
71 if (!reply) {
72 goto failed;
76 * as we use a connected socket, so we don't need to specify the
77 * destination
79 io.in.dest_address = NULL;
80 io.in.dest_port = 0;
81 io.in.realm = realm;
82 io.in.host = NULL;
83 io.in.user = NULL;
84 io.in.domain_guid = NULL;
85 io.in.domain_sid = NULL;
86 io.in.acct_control = 0;
87 io.in.version = nt_version;
88 io.in.map_response = false;
90 status = cldap_netlogon(cldap, reply, &io);
91 if (!NT_STATUS_IS_OK(status)) {
92 DEBUG(2,("cldap_netlogon() failed: %s\n", nt_errstr(status)));
93 goto failed;
96 *reply = io.out.netlogon;
97 *_reply = talloc_move(mem_ctx, &reply);
98 TALLOC_FREE(cldap);
99 return true;
100 failed:
101 TALLOC_FREE(cldap);
102 return false;
105 /*******************************************************************
106 do a cldap netlogon query. Always 389/udp
107 *******************************************************************/
109 bool ads_cldap_netlogon_5(TALLOC_CTX *mem_ctx,
110 struct sockaddr_storage *ss,
111 const char *realm,
112 struct NETLOGON_SAM_LOGON_RESPONSE_EX *reply5)
114 uint32_t nt_version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
115 struct netlogon_samlogon_response *reply = NULL;
116 bool ret;
118 ret = ads_cldap_netlogon(mem_ctx, ss, realm, nt_version, &reply);
119 if (!ret) {
120 return false;
123 if (reply->ntver != NETLOGON_NT_VERSION_5EX) {
124 DEBUG(0,("ads_cldap_netlogon_5: nt_version mismatch: 0x%08x\n",
125 reply->ntver));
126 return false;
129 *reply5 = reply->data.nt5_ex;
131 return true;