/src/samba/source3/libads/cldap.c
Line | Count | Source |
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) |
8 | | |
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. |
13 | | |
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. |
18 | | |
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/>. |
21 | | */ |
22 | | |
23 | | #include "includes.h" |
24 | | #include "../libcli/cldap/cldap.h" |
25 | | #include "../librpc/gen_ndr/ndr_netlogon.h" |
26 | | #include "../lib/tsocket/tsocket.h" |
27 | | #include "../lib/util/tevent_ntstatus.h" |
28 | | #include "libads/cldap.h" |
29 | | #include "libads/netlogon_ping.h" |
30 | | |
31 | | /******************************************************************* |
32 | | do a cldap netlogon query. Always 389/udp |
33 | | *******************************************************************/ |
34 | | |
35 | | static bool ads_cldap_netlogon(TALLOC_CTX *mem_ctx, |
36 | | struct sockaddr_storage *ss, |
37 | | const char *realm, |
38 | | uint32_t nt_version, |
39 | | uint32_t required_flags, |
40 | | struct netlogon_samlogon_response **_reply) |
41 | 0 | { |
42 | 0 | NTSTATUS status; |
43 | 0 | char addrstr[INET6_ADDRSTRLEN]; |
44 | 0 | const char *dest_str; |
45 | 0 | struct tsocket_address *dest_addr; |
46 | 0 | struct netlogon_samlogon_response **responses = NULL; |
47 | 0 | int ret; |
48 | |
|
49 | 0 | dest_str = print_sockaddr(addrstr, sizeof(addrstr), ss); |
50 | |
|
51 | 0 | ret = tsocket_address_inet_from_strings(mem_ctx, "ip", |
52 | 0 | dest_str, LDAP_PORT, |
53 | 0 | &dest_addr); |
54 | 0 | if (ret != 0) { |
55 | 0 | status = map_nt_error_from_unix(errno); |
56 | 0 | DEBUG(2,("Failed to create cldap tsocket_address for %s - %s\n", |
57 | 0 | dest_str, nt_errstr(status))); |
58 | 0 | return false; |
59 | 0 | } |
60 | | |
61 | 0 | status = netlogon_pings( |
62 | 0 | talloc_tos(), /* mem_ctx */ |
63 | 0 | lp_client_netlogon_ping_protocol(), /*proto */ |
64 | 0 | &dest_addr, /* servers */ |
65 | 0 | 1, /* num_servers */ |
66 | 0 | (struct netlogon_ping_filter) { |
67 | 0 | .ntversion = nt_version, |
68 | 0 | .domain = realm, |
69 | 0 | .acct_ctrl = -1, |
70 | 0 | .required_flags = required_flags, |
71 | 0 | }, |
72 | 0 | 1, /* wanted_servers */ |
73 | 0 | timeval_current_ofs(MAX(3, lp_ldap_timeout() / 2), 0), |
74 | 0 | &responses); |
75 | 0 | if (!NT_STATUS_IS_OK(status)) { |
76 | 0 | DBG_NOTICE("netlogon_pings failed: %s\n", nt_errstr(status)); |
77 | 0 | return false; |
78 | 0 | } |
79 | 0 | if (responses == NULL || responses[0] == NULL) { |
80 | 0 | DBG_NOTICE("did not get a reply\n"); |
81 | 0 | TALLOC_FREE(responses); |
82 | 0 | return false; |
83 | 0 | } |
84 | 0 | *_reply = talloc_move(mem_ctx, &responses[0]); |
85 | |
|
86 | 0 | return true; |
87 | 0 | } |
88 | | |
89 | | /******************************************************************* |
90 | | do a cldap netlogon query. Always 389/udp |
91 | | *******************************************************************/ |
92 | | |
93 | | bool ads_cldap_netlogon_5(TALLOC_CTX *mem_ctx, |
94 | | struct sockaddr_storage *ss, |
95 | | const char *realm, |
96 | | uint32_t required_flags, |
97 | | struct NETLOGON_SAM_LOGON_RESPONSE_EX *reply5) |
98 | 0 | { |
99 | 0 | uint32_t nt_version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX; |
100 | 0 | struct netlogon_samlogon_response *reply = NULL; |
101 | 0 | bool ret; |
102 | |
|
103 | 0 | ret = ads_cldap_netlogon( |
104 | 0 | mem_ctx, ss, realm, nt_version, required_flags, &reply); |
105 | 0 | if (!ret) { |
106 | 0 | return false; |
107 | 0 | } |
108 | | |
109 | 0 | if (reply->ntver != NETLOGON_NT_VERSION_5EX) { |
110 | 0 | DEBUG(0,("ads_cldap_netlogon_5: nt_version mismatch: 0x%08x\n", |
111 | 0 | reply->ntver)); |
112 | 0 | return false; |
113 | 0 | } |
114 | | |
115 | 0 | *reply5 = reply->data.nt5_ex; |
116 | |
|
117 | | return true; |
118 | 0 | } |