2 * Unix SMB/CIFS implementation.
3 * NetApi Server Support
4 * Copyright (C) Guenther Deschner 2007
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.
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.
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/>.
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"
28 /****************************************************************
29 ****************************************************************/
31 static WERROR
NetServerGetInfo_l_101(struct libnetapi_ctx
*ctx
,
34 struct SERVER_INFO_101 i
;
36 i
.sv101_platform_id
= PLATFORM_ID_NT
;
37 i
.sv101_name
= global_myname();
38 i
.sv101_version_major
= lp_major_announce_version();
39 i
.sv101_version_minor
= lp_minor_announce_version();
40 i
.sv101_type
= lp_default_server_announce();
41 i
.sv101_comment
= lp_serverstring();
43 *buffer
= (uint8_t *)talloc_memdup(ctx
, &i
, sizeof(i
));
51 /****************************************************************
52 ****************************************************************/
54 static WERROR
NetServerGetInfo_l_1005(struct libnetapi_ctx
*ctx
,
57 struct SERVER_INFO_1005 info1005
;
59 info1005
.sv1005_comment
= lp_serverstring();
60 *buffer
= (uint8_t *)talloc_memdup(ctx
, &info1005
, sizeof(info1005
));
68 /****************************************************************
69 ****************************************************************/
71 WERROR
NetServerGetInfo_l(struct libnetapi_ctx
*ctx
,
72 struct NetServerGetInfo
*r
)
74 switch (r
->in
.level
) {
76 return NetServerGetInfo_l_101(ctx
, r
->out
.buffer
);
78 return NetServerGetInfo_l_1005(ctx
, r
->out
.buffer
);
80 return WERR_UNKNOWN_LEVEL
;
83 return WERR_UNKNOWN_LEVEL
;
86 /****************************************************************
87 ****************************************************************/
89 static NTSTATUS
map_server_info_to_SERVER_INFO_buffer(TALLOC_CTX
*mem_ctx
,
91 union srvsvc_NetSrvInfo
*i
,
94 struct SERVER_INFO_100 i100
;
95 struct SERVER_INFO_101 i101
;
96 struct SERVER_INFO_102 i102
;
97 struct SERVER_INFO_1005 i1005
;
99 uint32_t num_info
= 0;
103 i100
.sv100_platform_id
= i
->info100
->platform_id
;
104 i100
.sv100_name
= talloc_strdup(mem_ctx
, i
->info100
->server_name
);
106 ADD_TO_ARRAY(mem_ctx
, struct SERVER_INFO_100
, i100
,
107 (struct SERVER_INFO_100
**)buffer
,
112 i101
.sv101_platform_id
= i
->info101
->platform_id
;
113 i101
.sv101_name
= talloc_strdup(mem_ctx
, i
->info101
->server_name
);
114 i101
.sv101_version_major
= i
->info101
->version_major
;
115 i101
.sv101_version_minor
= i
->info101
->version_minor
;
116 i101
.sv101_type
= i
->info101
->server_type
;
117 i101
.sv101_comment
= talloc_strdup(mem_ctx
, i
->info101
->comment
);
119 ADD_TO_ARRAY(mem_ctx
, struct SERVER_INFO_101
, i101
,
120 (struct SERVER_INFO_101
**)buffer
,
125 i102
.sv102_platform_id
= i
->info102
->platform_id
;
126 i102
.sv102_name
= talloc_strdup(mem_ctx
, i
->info102
->server_name
);
127 i102
.sv102_version_major
= i
->info102
->version_major
;
128 i102
.sv102_version_minor
= i
->info102
->version_minor
;
129 i102
.sv102_type
= i
->info102
->server_type
;
130 i102
.sv102_comment
= talloc_strdup(mem_ctx
, i
->info102
->comment
);
131 i102
.sv102_users
= i
->info102
->users
;
132 i102
.sv102_disc
= i
->info102
->disc
;
133 i102
.sv102_hidden
= i
->info102
->hidden
;
134 i102
.sv102_announce
= i
->info102
->announce
;
135 i102
.sv102_anndelta
= i
->info102
->anndelta
;
136 i102
.sv102_licenses
= i
->info102
->licenses
;
137 i102
.sv102_userpath
= talloc_strdup(mem_ctx
, i
->info102
->userpath
);
139 ADD_TO_ARRAY(mem_ctx
, struct SERVER_INFO_102
, i102
,
140 (struct SERVER_INFO_102
**)buffer
,
145 i1005
.sv1005_comment
= talloc_strdup(mem_ctx
, i
->info1005
->comment
);
147 ADD_TO_ARRAY(mem_ctx
, struct SERVER_INFO_1005
, i1005
,
148 (struct SERVER_INFO_1005
**)buffer
,
152 return NT_STATUS_NOT_SUPPORTED
;
158 /****************************************************************
159 ****************************************************************/
161 WERROR
NetServerGetInfo_r(struct libnetapi_ctx
*ctx
,
162 struct NetServerGetInfo
*r
)
164 struct cli_state
*cli
= NULL
;
165 struct rpc_pipe_client
*pipe_cli
= NULL
;
168 union srvsvc_NetSrvInfo info
;
170 if (!r
->out
.buffer
) {
171 return WERR_INVALID_PARAM
;
174 switch (r
->in
.level
) {
181 return WERR_UNKNOWN_LEVEL
;
184 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
185 &ndr_table_srvsvc
.syntax_id
,
188 if (!W_ERROR_IS_OK(werr
)) {
192 status
= rpccli_srvsvc_NetSrvGetInfo(pipe_cli
, ctx
,
197 if (!NT_STATUS_IS_OK(status
)) {
198 werr
= ntstatus_to_werror(status
);
202 status
= map_server_info_to_SERVER_INFO_buffer(ctx
, r
->in
.level
, &info
,
204 if (!NT_STATUS_IS_OK(status
)) {
205 werr
= ntstatus_to_werror(status
);
213 /****************************************************************
214 ****************************************************************/
216 static WERROR
NetServerSetInfo_l_1005(struct libnetapi_ctx
*ctx
,
217 struct NetServerSetInfo
*r
)
220 struct smbconf_ctx
*conf_ctx
;
221 struct srvsvc_NetSrvInfo1005
*info1005
;
224 *r
->out
.parm_error
= 1005; /* sure here ? */
225 return WERR_INVALID_PARAM
;
228 info1005
= (struct srvsvc_NetSrvInfo1005
*)r
->in
.buffer
;
230 if (!info1005
->comment
) {
231 *r
->out
.parm_error
= 1005;
232 return WERR_INVALID_PARAM
;
235 if (!lp_config_backend_is_registry()) {
236 libnetapi_set_error_string(ctx
,
237 "Configuration manipulation requested but not "
238 "supported by backend");
239 return WERR_NOT_SUPPORTED
;
242 werr
= smbconf_init_reg(ctx
, &conf_ctx
, NULL
);
243 if (!W_ERROR_IS_OK(werr
)) {
247 werr
= smbconf_set_global_parameter(conf_ctx
, "server string",
251 smbconf_shutdown(conf_ctx
);
255 /****************************************************************
256 ****************************************************************/
258 WERROR
NetServerSetInfo_l(struct libnetapi_ctx
*ctx
,
259 struct NetServerSetInfo
*r
)
261 switch (r
->in
.level
) {
263 return NetServerSetInfo_l_1005(ctx
, r
);
265 return WERR_UNKNOWN_LEVEL
;
268 return WERR_UNKNOWN_LEVEL
;
271 /****************************************************************
272 ****************************************************************/
274 WERROR
NetServerSetInfo_r(struct libnetapi_ctx
*ctx
,
275 struct NetServerSetInfo
*r
)
277 struct cli_state
*cli
= NULL
;
278 struct rpc_pipe_client
*pipe_cli
= NULL
;
281 union srvsvc_NetSrvInfo info
;
283 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
284 &ndr_table_srvsvc
.syntax_id
,
287 if (!W_ERROR_IS_OK(werr
)) {
291 switch (r
->in
.level
) {
293 info
.info1005
= (struct srvsvc_NetSrvInfo1005
*)r
->in
.buffer
;
296 werr
= WERR_NOT_SUPPORTED
;
300 status
= rpccli_srvsvc_NetSrvSetInfo(pipe_cli
, ctx
,
306 if (!NT_STATUS_IS_OK(status
)) {
307 werr
= ntstatus_to_werror(status
);
315 /****************************************************************
316 ****************************************************************/
318 WERROR
NetRemoteTOD_r(struct libnetapi_ctx
*ctx
,
319 struct NetRemoteTOD
*r
)
321 struct cli_state
*cli
= NULL
;
322 struct rpc_pipe_client
*pipe_cli
= NULL
;
325 struct srvsvc_NetRemoteTODInfo
*info
= NULL
;
327 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
328 &ndr_table_srvsvc
.syntax_id
,
331 if (!W_ERROR_IS_OK(werr
)) {
335 status
= rpccli_srvsvc_NetRemoteTOD(pipe_cli
, ctx
,
339 if (!NT_STATUS_IS_OK(status
)) {
340 werr
= ntstatus_to_werror(status
);
344 *r
->out
.buffer
= (uint8_t *)talloc_memdup(ctx
, info
,
345 sizeof(struct srvsvc_NetRemoteTODInfo
));
346 W_ERROR_HAVE_NO_MEMORY(*r
->out
.buffer
);
352 /****************************************************************
353 ****************************************************************/
355 WERROR
NetRemoteTOD_l(struct libnetapi_ctx
*ctx
,
356 struct NetRemoteTOD
*r
)
358 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetRemoteTOD
);