Use SERVER_INFO_1005 in libnetapi.
[Samba/gebeck_regimport.git] / source3 / lib / netapi / serverinfo.c
blob643b04c4da3301e60976d12165984d1566bd70ea
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/libnetapi.h"
25 #include "libnet/libnet.h"
27 /****************************************************************
28 ****************************************************************/
30 static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx,
31 uint8_t **buffer)
33 struct SERVER_INFO_1005 info1005;
35 info1005.sv1005_comment = lp_serverstring();
36 *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
37 if (!*buffer) {
38 return WERR_NOMEM;
41 return WERR_OK;
44 /****************************************************************
45 ****************************************************************/
47 WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx,
48 struct NetServerGetInfo *r)
50 switch (r->in.level) {
51 case 1005:
52 return NetServerGetInfo_l_1005(ctx, r->out.buffer);
53 default:
54 return WERR_UNKNOWN_LEVEL;
57 return WERR_UNKNOWN_LEVEL;
60 /****************************************************************
61 ****************************************************************/
63 WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
64 struct NetServerGetInfo *r)
66 struct cli_state *cli = NULL;
67 struct rpc_pipe_client *pipe_cli = NULL;
68 NTSTATUS status;
69 WERROR werr;
70 union srvsvc_NetSrvInfo info;
72 status = cli_full_connection(&cli, NULL, r->in.server_name,
73 NULL, 0,
74 "IPC$", "IPC",
75 ctx->username,
76 ctx->workgroup,
77 ctx->password,
78 CLI_FULL_CONNECTION_USE_KERBEROS |
79 CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
80 Undefined, NULL);
82 if (!NT_STATUS_IS_OK(status)) {
83 werr = ntstatus_to_werror(status);
84 goto done;
87 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC,
88 &status);
89 if (!pipe_cli) {
90 werr = ntstatus_to_werror(status);
91 goto done;
94 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
95 r->in.server_name,
96 r->in.level,
97 &info,
98 &werr);
99 if (!NT_STATUS_IS_OK(status)) {
100 werr = ntstatus_to_werror(status);
101 goto done;
104 *r->out.buffer = talloc_memdup(ctx, &info, sizeof(info));
105 if (!*r->out.buffer) {
106 werr = WERR_NOMEM;
107 goto done;
110 done:
111 if (cli) {
112 cli_shutdown(cli);
115 return werr;
118 /****************************************************************
119 ****************************************************************/
121 static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
122 struct NetServerSetInfo *r)
124 WERROR werr;
125 struct smbconf_ctx *conf_ctx;
126 struct srvsvc_NetSrvInfo1005 *info1005;
128 if (!r->in.buffer) {
129 *r->out.parm_error = 1005; /* sure here ? */
130 return WERR_INVALID_PARAM;
133 info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
135 if (!info1005->comment) {
136 *r->out.parm_error = 1005;
137 return WERR_INVALID_PARAM;
140 if (!lp_config_backend_is_registry()) {
141 libnetapi_set_error_string(ctx,
142 "Configuration manipulation requested but not "
143 "supported by backend");
144 return WERR_NOT_SUPPORTED;
147 werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
148 if (!W_ERROR_IS_OK(werr)) {
149 goto done;
152 werr = smbconf_set_global_parameter(conf_ctx, "server string",
153 info1005->comment);
155 done:
156 smbconf_shutdown(conf_ctx);
157 return werr;
160 /****************************************************************
161 ****************************************************************/
163 WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
164 struct NetServerSetInfo *r)
166 switch (r->in.level) {
167 case 1005:
168 return NetServerSetInfo_l_1005(ctx, r);
169 default:
170 return WERR_UNKNOWN_LEVEL;
173 return WERR_UNKNOWN_LEVEL;
176 /****************************************************************
177 ****************************************************************/
179 WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
180 struct NetServerSetInfo *r)
182 struct cli_state *cli = NULL;
183 struct rpc_pipe_client *pipe_cli = NULL;
184 NTSTATUS status;
185 WERROR werr;
186 union srvsvc_NetSrvInfo info;
188 status = cli_full_connection(&cli, NULL, r->in.server_name,
189 NULL, 0,
190 "IPC$", "IPC",
191 ctx->username,
192 ctx->workgroup,
193 ctx->password,
194 CLI_FULL_CONNECTION_USE_KERBEROS |
195 CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
196 Undefined, NULL);
198 if (!NT_STATUS_IS_OK(status)) {
199 werr = ntstatus_to_werror(status);
200 goto done;
203 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC,
204 &status);
205 if (!pipe_cli) {
206 werr = ntstatus_to_werror(status);
207 goto done;
210 switch (r->in.level) {
211 case 1005:
212 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
213 break;
214 default:
215 werr = WERR_NOT_SUPPORTED;
216 goto done;
219 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
220 r->in.server_name,
221 r->in.level,
222 &info,
223 r->out.parm_error,
224 &werr);
225 if (!NT_STATUS_IS_OK(status)) {
226 werr = ntstatus_to_werror(status);
227 goto done;
230 done:
231 if (cli) {
232 cli_shutdown(cli);
235 return werr;