source: branches/samba-3.2.x/source/lib/netapi/serverinfo.c

Last change on this file was 133, checked in by Paul Smedley, 17 years ago

Update trunk to 3.2.0pre3

File size: 5.0 KB
Line 
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
31static 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
48WERROR 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
64WERROR 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, PI_SRVSVC, &pipe_cli);
79 if (!W_ERROR_IS_OK(werr)) {
80 goto done;
81 }
82
83 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
84 r->in.server_name,
85 r->in.level,
86 &info,
87 &werr);
88 if (!NT_STATUS_IS_OK(status)) {
89 werr = ntstatus_to_werror(status);
90 goto done;
91 }
92
93 *r->out.buffer = (uint8_t *)talloc_memdup(ctx, &info, sizeof(info));
94 if (!*r->out.buffer) {
95 werr = WERR_NOMEM;
96 goto done;
97 }
98
99 done:
100 return werr;
101}
102
103/****************************************************************
104****************************************************************/
105
106static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
107 struct NetServerSetInfo *r)
108{
109 WERROR werr;
110 struct smbconf_ctx *conf_ctx;
111 struct srvsvc_NetSrvInfo1005 *info1005;
112
113 if (!r->in.buffer) {
114 *r->out.parm_error = 1005; /* sure here ? */
115 return WERR_INVALID_PARAM;
116 }
117
118 info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
119
120 if (!info1005->comment) {
121 *r->out.parm_error = 1005;
122 return WERR_INVALID_PARAM;
123 }
124
125 if (!lp_config_backend_is_registry()) {
126 libnetapi_set_error_string(ctx,
127 "Configuration manipulation requested but not "
128 "supported by backend");
129 return WERR_NOT_SUPPORTED;
130 }
131
132 werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
133 if (!W_ERROR_IS_OK(werr)) {
134 goto done;
135 }
136
137 werr = smbconf_set_global_parameter(conf_ctx, "server string",
138 info1005->comment);
139
140 done:
141 smbconf_shutdown(conf_ctx);
142 return werr;
143}
144
145/****************************************************************
146****************************************************************/
147
148WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
149 struct NetServerSetInfo *r)
150{
151 switch (r->in.level) {
152 case 1005:
153 return NetServerSetInfo_l_1005(ctx, r);
154 default:
155 return WERR_UNKNOWN_LEVEL;
156 }
157
158 return WERR_UNKNOWN_LEVEL;
159}
160
161/****************************************************************
162****************************************************************/
163
164WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
165 struct NetServerSetInfo *r)
166{
167 struct cli_state *cli = NULL;
168 struct rpc_pipe_client *pipe_cli = NULL;
169 NTSTATUS status;
170 WERROR werr;
171 union srvsvc_NetSrvInfo info;
172
173 werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
174 if (!W_ERROR_IS_OK(werr)) {
175 goto done;
176 }
177
178 werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli);
179 if (!W_ERROR_IS_OK(werr)) {
180 goto done;
181 }
182
183 switch (r->in.level) {
184 case 1005:
185 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
186 break;
187 default:
188 werr = WERR_NOT_SUPPORTED;
189 goto done;
190 }
191
192 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
193 r->in.server_name,
194 r->in.level,
195 &info,
196 r->out.parm_error,
197 &werr);
198 if (!NT_STATUS_IS_OK(status)) {
199 werr = ntstatus_to_werror(status);
200 goto done;
201 }
202
203 done:
204 return werr;
205}
Note: See TracBrowser for help on using the repository browser.