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 rpc_pipe_client
*pipe_cli
= NULL
;
167 union srvsvc_NetSrvInfo info
;
169 if (!r
->out
.buffer
) {
170 return WERR_INVALID_PARAM
;
173 switch (r
->in
.level
) {
180 return WERR_UNKNOWN_LEVEL
;
183 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
184 &ndr_table_srvsvc
.syntax_id
,
186 if (!W_ERROR_IS_OK(werr
)) {
190 status
= rpccli_srvsvc_NetSrvGetInfo(pipe_cli
, ctx
,
195 if (!NT_STATUS_IS_OK(status
)) {
196 werr
= ntstatus_to_werror(status
);
200 status
= map_server_info_to_SERVER_INFO_buffer(ctx
, r
->in
.level
, &info
,
202 if (!NT_STATUS_IS_OK(status
)) {
203 werr
= ntstatus_to_werror(status
);
211 /****************************************************************
212 ****************************************************************/
214 static WERROR
NetServerSetInfo_l_1005(struct libnetapi_ctx
*ctx
,
215 struct NetServerSetInfo
*r
)
218 struct smbconf_ctx
*conf_ctx
;
219 struct srvsvc_NetSrvInfo1005
*info1005
;
222 *r
->out
.parm_error
= 1005; /* sure here ? */
223 return WERR_INVALID_PARAM
;
226 info1005
= (struct srvsvc_NetSrvInfo1005
*)r
->in
.buffer
;
228 if (!info1005
->comment
) {
229 *r
->out
.parm_error
= 1005;
230 return WERR_INVALID_PARAM
;
233 if (!lp_config_backend_is_registry()) {
234 libnetapi_set_error_string(ctx
,
235 "Configuration manipulation requested but not "
236 "supported by backend");
237 return WERR_NOT_SUPPORTED
;
240 werr
= smbconf_init_reg(ctx
, &conf_ctx
, NULL
);
241 if (!W_ERROR_IS_OK(werr
)) {
245 werr
= smbconf_set_global_parameter(conf_ctx
, "server string",
249 smbconf_shutdown(conf_ctx
);
253 /****************************************************************
254 ****************************************************************/
256 WERROR
NetServerSetInfo_l(struct libnetapi_ctx
*ctx
,
257 struct NetServerSetInfo
*r
)
259 switch (r
->in
.level
) {
261 return NetServerSetInfo_l_1005(ctx
, r
);
263 return WERR_UNKNOWN_LEVEL
;
266 return WERR_UNKNOWN_LEVEL
;
269 /****************************************************************
270 ****************************************************************/
272 WERROR
NetServerSetInfo_r(struct libnetapi_ctx
*ctx
,
273 struct NetServerSetInfo
*r
)
275 struct rpc_pipe_client
*pipe_cli
= NULL
;
278 union srvsvc_NetSrvInfo info
;
280 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
281 &ndr_table_srvsvc
.syntax_id
,
283 if (!W_ERROR_IS_OK(werr
)) {
287 switch (r
->in
.level
) {
289 info
.info1005
= (struct srvsvc_NetSrvInfo1005
*)r
->in
.buffer
;
292 werr
= WERR_NOT_SUPPORTED
;
296 status
= rpccli_srvsvc_NetSrvSetInfo(pipe_cli
, ctx
,
302 if (!NT_STATUS_IS_OK(status
)) {
303 werr
= ntstatus_to_werror(status
);
311 /****************************************************************
312 ****************************************************************/
314 WERROR
NetRemoteTOD_r(struct libnetapi_ctx
*ctx
,
315 struct NetRemoteTOD
*r
)
317 struct rpc_pipe_client
*pipe_cli
= NULL
;
320 struct srvsvc_NetRemoteTODInfo
*info
= NULL
;
322 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
323 &ndr_table_srvsvc
.syntax_id
,
325 if (!W_ERROR_IS_OK(werr
)) {
329 status
= rpccli_srvsvc_NetRemoteTOD(pipe_cli
, ctx
,
333 if (!NT_STATUS_IS_OK(status
)) {
334 werr
= ntstatus_to_werror(status
);
338 *r
->out
.buffer
= (uint8_t *)talloc_memdup(ctx
, info
,
339 sizeof(struct srvsvc_NetRemoteTODInfo
));
340 W_ERROR_HAVE_NO_MEMORY(*r
->out
.buffer
);
346 /****************************************************************
347 ****************************************************************/
349 WERROR
NetRemoteTOD_l(struct libnetapi_ctx
*ctx
,
350 struct NetRemoteTOD
*r
)
352 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetRemoteTOD
);