libndr: Avoid assigning duplicate versions to symbols
[amitay/samba.git] / source3 / winbindd / winbindd_domain_info.c
1 /*
2  * Unix SMB/CIFS implementation.
3  * async implementation of WINBINDD_DOMAIN_INFO
4  * Copyright (C) Volker Lendecke 2018
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "includes.h"
21 #include "winbindd.h"
22 #include "lib/util/string_wrappers.h"
23
24 struct winbindd_domain_info_state {
25         struct winbindd_domain *domain;
26         struct winbindd_request ping_request;
27 };
28
29 static void winbindd_domain_info_done(struct tevent_req *subreq);
30
31 struct tevent_req *winbindd_domain_info_send(
32         TALLOC_CTX *mem_ctx,
33         struct tevent_context *ev,
34         struct winbindd_cli_state *cli,
35         struct winbindd_request *request)
36 {
37         struct tevent_req *req, *subreq;
38         struct winbindd_domain_info_state *state;
39
40         req = tevent_req_create(mem_ctx, &state,
41                                 struct winbindd_domain_info_state);
42         if (req == NULL) {
43                 return NULL;
44         }
45
46         DEBUG(3, ("[%5lu]: domain_info [%s]\n", (unsigned long)cli->pid,
47                   cli->request->domain_name));
48
49         state->domain = find_domain_from_name_noinit(
50                 cli->request->domain_name);
51
52         if (state->domain == NULL) {
53                 DEBUG(3, ("Did not find domain [%s]\n",
54                           cli->request->domain_name));
55                 tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN);
56                 return tevent_req_post(req, ev);
57         }
58
59         if (state->domain->initialized) {
60                 tevent_req_done(req);
61                 return tevent_req_post(req, ev);
62         }
63
64         state->ping_request.cmd = WINBINDD_PING;
65
66         /*
67          * Send a ping down. This implicitly initializes the domain.
68          */
69
70         subreq = wb_domain_request_send(state, global_event_context(),
71                                         state->domain, &state->ping_request);
72         if (tevent_req_nomem(subreq, req)) {
73                 return tevent_req_post(req, ev);
74         }
75         tevent_req_set_callback(subreq, winbindd_domain_info_done, req);
76
77         return req;
78 }
79
80 static void winbindd_domain_info_done(struct tevent_req *subreq)
81 {
82         struct tevent_req *req = tevent_req_callback_data(
83                 subreq, struct tevent_req);
84         struct winbindd_domain_info_state *state = tevent_req_data(
85                 req, struct winbindd_domain_info_state);
86         struct winbindd_response *response;
87         int ret, err;
88
89         ret = wb_domain_request_recv(subreq, state, &response, &err);
90         TALLOC_FREE(subreq);
91         if (ret == -1) {
92                 DBG_DEBUG("wb_domain_request failed: %s\n", strerror(err));
93                 tevent_req_nterror(req, map_nt_error_from_unix(err));
94                 return;
95         }
96
97         if (!state->domain->initialized) {
98                 DBG_INFO("wb_domain_request did not initialize domain %s\n",
99                          state->domain->name);
100                 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
101                 return;
102         }
103
104         tevent_req_done(req);
105 }
106
107 NTSTATUS winbindd_domain_info_recv(struct tevent_req *req,
108                                    struct winbindd_response *response)
109 {
110         struct winbindd_domain_info_state *state = tevent_req_data(
111                 req, struct winbindd_domain_info_state);
112         struct winbindd_domain *domain = state->domain;
113         NTSTATUS status;
114
115         if (tevent_req_is_nterror(req, &status)) {
116                 DBG_DEBUG("winbindd_domain_info failed: %s\n",
117                           nt_errstr(status));
118                 return status;
119         }
120
121         fstrcpy(response->data.domain_info.name, domain->name);
122         fstrcpy(response->data.domain_info.alt_name, domain->alt_name);
123         sid_to_fstring(response->data.domain_info.sid, &domain->sid);
124
125         response->data.domain_info.native_mode = domain->native_mode;
126         response->data.domain_info.active_directory = domain->active_directory;
127         response->data.domain_info.primary = domain->primary;
128
129         return NT_STATUS_OK;
130 }