netapi: make libnetapi_open_ipc_connection static.
[Samba/gebeck_regimport.git] / source3 / lib / netapi / serverinfo.c
blob5f744bea26021b02b5741aefc999caf0cd132210
1 /*
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/>.
20 #include "includes.h"
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_1005(struct libnetapi_ctx *ctx,
32 uint8_t **buffer)
34 struct SERVER_INFO_1005 info1005;
36 info1005.sv1005_comment = lp_serverstring();
37 *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
38 if (!*buffer) {
39 return WERR_NOMEM;
42 return WERR_OK;
45 /****************************************************************
46 ****************************************************************/
48 WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx,
49 struct NetServerGetInfo *r)
51 switch (r->in.level) {
52 case 1005:
53 return NetServerGetInfo_l_1005(ctx, r->out.buffer);
54 default:
55 return WERR_UNKNOWN_LEVEL;
58 return WERR_UNKNOWN_LEVEL;
61 /****************************************************************
62 ****************************************************************/
64 WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
65 struct NetServerGetInfo *r)
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;
73 werr = libnetapi_open_pipe(ctx, r->in.server_name,
74 &ndr_table_srvsvc.syntax_id,
75 &cli,
76 &pipe_cli);
77 if (!W_ERROR_IS_OK(werr)) {
78 goto done;
81 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
82 r->in.server_name,
83 r->in.level,
84 &info,
85 &werr);
86 if (!NT_STATUS_IS_OK(status)) {
87 werr = ntstatus_to_werror(status);
88 goto done;
91 *r->out.buffer = (uint8_t *)talloc_memdup(ctx, &info, sizeof(info));
92 if (!*r->out.buffer) {
93 werr = WERR_NOMEM;
94 goto done;
97 done:
98 return werr;
101 /****************************************************************
102 ****************************************************************/
104 static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
105 struct NetServerSetInfo *r)
107 WERROR werr;
108 struct smbconf_ctx *conf_ctx;
109 struct srvsvc_NetSrvInfo1005 *info1005;
111 if (!r->in.buffer) {
112 *r->out.parm_error = 1005; /* sure here ? */
113 return WERR_INVALID_PARAM;
116 info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
118 if (!info1005->comment) {
119 *r->out.parm_error = 1005;
120 return WERR_INVALID_PARAM;
123 if (!lp_config_backend_is_registry()) {
124 libnetapi_set_error_string(ctx,
125 "Configuration manipulation requested but not "
126 "supported by backend");
127 return WERR_NOT_SUPPORTED;
130 werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
131 if (!W_ERROR_IS_OK(werr)) {
132 goto done;
135 werr = smbconf_set_global_parameter(conf_ctx, "server string",
136 info1005->comment);
138 done:
139 smbconf_shutdown(conf_ctx);
140 return werr;
143 /****************************************************************
144 ****************************************************************/
146 WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
147 struct NetServerSetInfo *r)
149 switch (r->in.level) {
150 case 1005:
151 return NetServerSetInfo_l_1005(ctx, r);
152 default:
153 return WERR_UNKNOWN_LEVEL;
156 return WERR_UNKNOWN_LEVEL;
159 /****************************************************************
160 ****************************************************************/
162 WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
163 struct NetServerSetInfo *r)
165 struct cli_state *cli = NULL;
166 struct rpc_pipe_client *pipe_cli = NULL;
167 NTSTATUS status;
168 WERROR werr;
169 union srvsvc_NetSrvInfo info;
171 werr = libnetapi_open_pipe(ctx, r->in.server_name,
172 &ndr_table_srvsvc.syntax_id,
173 &cli,
174 &pipe_cli);
175 if (!W_ERROR_IS_OK(werr)) {
176 goto done;
179 switch (r->in.level) {
180 case 1005:
181 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
182 break;
183 default:
184 werr = WERR_NOT_SUPPORTED;
185 goto done;
188 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
189 r->in.server_name,
190 r->in.level,
191 &info,
192 r->out.parm_error,
193 &werr);
194 if (!NT_STATUS_IS_OK(status)) {
195 werr = ntstatus_to_werror(status);
196 goto done;
199 done:
200 return werr;
203 /****************************************************************
204 ****************************************************************/
206 WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
207 struct NetRemoteTOD *r)
209 struct cli_state *cli = NULL;
210 struct rpc_pipe_client *pipe_cli = NULL;
211 NTSTATUS status;
212 WERROR werr;
213 struct srvsvc_NetRemoteTODInfo *info = NULL;
215 werr = libnetapi_open_pipe(ctx, r->in.server_name,
216 &ndr_table_srvsvc.syntax_id,
217 &cli,
218 &pipe_cli);
219 if (!W_ERROR_IS_OK(werr)) {
220 goto done;
223 status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, ctx,
224 r->in.server_name,
225 &info,
226 &werr);
227 if (!NT_STATUS_IS_OK(status)) {
228 werr = ntstatus_to_werror(status);
229 goto done;
232 *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
233 sizeof(struct srvsvc_NetRemoteTODInfo));
234 W_ERROR_HAVE_NO_MEMORY(*r->out.buffer);
236 done:
237 return werr;
240 /****************************************************************
241 ****************************************************************/
243 WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx,
244 struct NetRemoteTOD *r)
246 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRemoteTOD);