bd063332bf5fc3dfe14ceb05f9fc27bcfe614cba
[kai/samba.git] / source3 / lib / netapi / serverinfo.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  NetApi Server Support
4  *  Copyright (C) Guenther Deschner 2007
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
22 #include "librpc/gen_ndr/libnetapi.h"
23 #include "lib/netapi/netapi.h"
24 #include "lib/netapi/netapi_private.h"
25 #include "lib/netapi/libnetapi.h"
26 #include "libnet/libnet.h"
27
28 /****************************************************************
29 ****************************************************************/
30
31 static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx,
32                                       uint8_t **buffer)
33 {
34         struct SERVER_INFO_1005 info1005;
35
36         info1005.sv1005_comment = lp_serverstring();
37         *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
38         if (!*buffer) {
39                 return WERR_NOMEM;
40         }
41
42         return WERR_OK;
43 }
44
45 /****************************************************************
46 ****************************************************************/
47
48 WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx,
49                           struct NetServerGetInfo *r)
50 {
51         switch (r->in.level) {
52                 case 1005:
53                         return NetServerGetInfo_l_1005(ctx, r->out.buffer);
54                 default:
55                         return WERR_UNKNOWN_LEVEL;
56         }
57
58         return WERR_UNKNOWN_LEVEL;
59 }
60
61 /****************************************************************
62 ****************************************************************/
63
64 WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
65                           struct NetServerGetInfo *r)
66 {
67         struct cli_state *cli = NULL;
68         struct rpc_pipe_client *pipe_cli = NULL;
69         NTSTATUS status;
70         WERROR werr;
71         union srvsvc_NetSrvInfo info;
72
73         werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
74         if (!W_ERROR_IS_OK(werr)) {
75                 goto done;
76         }
77
78         werr = libnetapi_open_pipe(ctx, cli, &ndr_table_srvsvc.syntax_id,
79                                    &pipe_cli);
80         if (!W_ERROR_IS_OK(werr)) {
81                 goto done;
82         }
83
84         status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
85                                              r->in.server_name,
86                                              r->in.level,
87                                              &info,
88                                              &werr);
89         if (!NT_STATUS_IS_OK(status)) {
90                 werr = ntstatus_to_werror(status);
91                 goto done;
92         }
93
94         *r->out.buffer = (uint8_t *)talloc_memdup(ctx, &info, sizeof(info));
95         if (!*r->out.buffer) {
96                 werr = WERR_NOMEM;
97                 goto done;
98         }
99
100  done:
101         return werr;
102 }
103
104 /****************************************************************
105 ****************************************************************/
106
107 static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
108                                       struct NetServerSetInfo *r)
109 {
110         WERROR werr;
111         struct smbconf_ctx *conf_ctx;
112         struct srvsvc_NetSrvInfo1005 *info1005;
113
114         if (!r->in.buffer) {
115                 *r->out.parm_error = 1005; /* sure here ? */
116                 return WERR_INVALID_PARAM;
117         }
118
119         info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
120
121         if (!info1005->comment) {
122                 *r->out.parm_error = 1005;
123                 return WERR_INVALID_PARAM;
124         }
125
126         if (!lp_config_backend_is_registry()) {
127                 libnetapi_set_error_string(ctx,
128                         "Configuration manipulation requested but not "
129                         "supported by backend");
130                 return WERR_NOT_SUPPORTED;
131         }
132
133         werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
134         if (!W_ERROR_IS_OK(werr)) {
135                 goto done;
136         }
137
138         werr = smbconf_set_global_parameter(conf_ctx, "server string",
139                                             info1005->comment);
140
141  done:
142         smbconf_shutdown(conf_ctx);
143         return werr;
144 }
145
146 /****************************************************************
147 ****************************************************************/
148
149 WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
150                           struct NetServerSetInfo *r)
151 {
152         switch (r->in.level) {
153                 case 1005:
154                         return NetServerSetInfo_l_1005(ctx, r);
155                 default:
156                         return WERR_UNKNOWN_LEVEL;
157         }
158
159         return WERR_UNKNOWN_LEVEL;
160 }
161
162 /****************************************************************
163 ****************************************************************/
164
165 WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
166                           struct NetServerSetInfo *r)
167 {
168         struct cli_state *cli = NULL;
169         struct rpc_pipe_client *pipe_cli = NULL;
170         NTSTATUS status;
171         WERROR werr;
172         union srvsvc_NetSrvInfo info;
173
174         werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
175         if (!W_ERROR_IS_OK(werr)) {
176                 goto done;
177         }
178
179         werr = libnetapi_open_pipe(ctx, cli, &ndr_table_srvsvc.syntax_id,
180                                    &pipe_cli);
181         if (!W_ERROR_IS_OK(werr)) {
182                 goto done;
183         }
184
185         switch (r->in.level) {
186                 case 1005:
187                         info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
188                         break;
189                 default:
190                         werr = WERR_NOT_SUPPORTED;
191                         goto done;
192         }
193
194         status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
195                                              r->in.server_name,
196                                              r->in.level,
197                                              &info,
198                                              r->out.parm_error,
199                                              &werr);
200         if (!NT_STATUS_IS_OK(status)) {
201                 werr = ntstatus_to_werror(status);
202                 goto done;
203         }
204
205  done:
206         return werr;
207 }
208
209 /****************************************************************
210 ****************************************************************/
211
212 WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
213                       struct NetRemoteTOD *r)
214 {
215         struct cli_state *cli = NULL;
216         struct rpc_pipe_client *pipe_cli = NULL;
217         NTSTATUS status;
218         WERROR werr;
219         struct srvsvc_NetRemoteTODInfo *info = NULL;
220
221         werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
222         if (!W_ERROR_IS_OK(werr)) {
223                 goto done;
224         }
225
226         werr = libnetapi_open_pipe(ctx, cli, &ndr_table_srvsvc.syntax_id,
227                                    &pipe_cli);
228         if (!W_ERROR_IS_OK(werr)) {
229                 goto done;
230         }
231
232         status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, ctx,
233                                             r->in.server_name,
234                                             &info,
235                                             &werr);
236         if (!NT_STATUS_IS_OK(status)) {
237                 werr = ntstatus_to_werror(status);
238                 goto done;
239         }
240
241         *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
242                           sizeof(struct srvsvc_NetRemoteTODInfo));
243         W_ERROR_HAVE_NO_MEMORY(*r->out.buffer);
244
245  done:
246         return werr;
247 }
248
249 /****************************************************************
250 ****************************************************************/
251
252 WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx,
253                       struct NetRemoteTOD *r)
254 {
255         LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRemoteTOD);
256 }
257