2007-12-19 17:10:24 +03:00
/*
* Unix SMB / CIFS implementation .
* NetApi Server Support
* Copyright ( C ) Guenther Deschner 2007
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
2008-04-08 04:42:50 +04:00
# include "librpc/gen_ndr/libnetapi.h"
2007-12-19 17:10:24 +03:00
# include "lib/netapi/netapi.h"
2008-04-08 04:42:50 +04:00
# include "lib/netapi/libnetapi.h"
2007-12-19 17:10:24 +03:00
# include "libnet/libnet.h"
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
static WERROR NetServerGetInfo_l_1005 ( struct libnetapi_ctx * ctx ,
uint8_t * * buffer )
2007-12-19 17:10:24 +03:00
{
2008-04-10 23:31:12 +04:00
struct SERVER_INFO_1005 info1005 ;
2007-12-19 17:10:24 +03:00
2008-04-10 23:31:12 +04:00
info1005 . sv1005_comment = lp_serverstring ( ) ;
2007-12-19 17:10:24 +03:00
* buffer = ( uint8_t * ) talloc_memdup ( ctx , & info1005 , sizeof ( info1005 ) ) ;
if ( ! * buffer ) {
return WERR_NOMEM ;
}
return WERR_OK ;
}
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetServerGetInfo_l ( struct libnetapi_ctx * ctx ,
struct NetServerGetInfo * r )
2007-12-19 17:10:24 +03:00
{
2008-04-08 04:42:50 +04:00
switch ( r - > in . level ) {
2007-12-19 17:10:24 +03:00
case 1005 :
2008-04-08 04:42:50 +04:00
return NetServerGetInfo_l_1005 ( ctx , r - > out . buffer ) ;
2007-12-19 17:10:24 +03:00
default :
return WERR_UNKNOWN_LEVEL ;
}
return WERR_UNKNOWN_LEVEL ;
}
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetServerGetInfo_r ( struct libnetapi_ctx * ctx ,
struct NetServerGetInfo * r )
2007-12-19 17:10:24 +03:00
{
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
NTSTATUS status ;
WERROR werr ;
union srvsvc_NetSrvInfo info ;
2008-04-08 04:42:50 +04:00
status = cli_full_connection ( & cli , NULL , r - > in . server_name ,
2007-12-19 17:10:24 +03:00
NULL , 0 ,
" IPC$ " , " IPC " ,
ctx - > username ,
ctx - > workgroup ,
ctx - > password ,
2008-04-08 21:42:26 +04:00
CLI_FULL_CONNECTION_USE_KERBEROS |
CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS ,
Undefined , NULL ) ;
2007-12-19 17:10:24 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
pipe_cli = cli_rpc_pipe_open_noauth ( cli , PI_SRVSVC ,
& status ) ;
if ( ! pipe_cli ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
} ;
status = rpccli_srvsvc_NetSrvGetInfo ( pipe_cli , ctx ,
2008-04-08 04:42:50 +04:00
r - > in . server_name ,
r - > in . level ,
2007-12-19 17:10:24 +03:00
& info ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2008-04-08 04:42:50 +04:00
* r - > out . buffer = talloc_memdup ( ctx , & info , sizeof ( info ) ) ;
if ( ! * r - > out . buffer ) {
werr = WERR_NOMEM ;
goto done ;
}
2007-12-19 17:10:24 +03:00
done :
if ( cli ) {
cli_shutdown ( cli ) ;
}
return werr ;
}
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
static WERROR NetServerSetInfo_l_1005 ( struct libnetapi_ctx * ctx ,
struct NetServerSetInfo * r )
2007-12-19 17:10:24 +03:00
{
2008-01-13 03:40:05 +03:00
WERROR werr ;
2008-03-17 20:01:33 +03:00
struct smbconf_ctx * conf_ctx ;
2007-12-19 17:10:24 +03:00
struct srvsvc_NetSrvInfo1005 * info1005 ;
2008-04-08 04:42:50 +04:00
if ( ! r - > in . buffer ) {
* r - > out . parm_error = 1005 ; /* sure here ? */
2007-12-19 17:10:24 +03:00
return WERR_INVALID_PARAM ;
}
2008-04-08 04:42:50 +04:00
info1005 = ( struct srvsvc_NetSrvInfo1005 * ) r - > in . buffer ;
2007-12-19 17:10:24 +03:00
if ( ! info1005 - > comment ) {
2008-04-08 04:42:50 +04:00
* r - > out . parm_error = 1005 ;
2007-12-19 17:10:24 +03:00
return WERR_INVALID_PARAM ;
}
2008-01-16 19:05:38 +03:00
if ( ! lp_config_backend_is_registry ( ) ) {
2008-03-05 17:21:43 +03:00
libnetapi_set_error_string ( ctx ,
" Configuration manipulation requested but not "
" supported by backend " ) ;
2007-12-19 18:07:40 +03:00
return WERR_NOT_SUPPORTED ;
}
2008-03-21 19:55:31 +03:00
werr = smbconf_init_reg ( ctx , & conf_ctx , NULL ) ;
2008-01-13 03:40:05 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-03-17 20:01:33 +03:00
werr = smbconf_set_global_parameter ( conf_ctx , " server string " ,
info1005 - > comment ) ;
2008-01-13 03:40:05 +03:00
2008-01-18 04:38:35 +03:00
done :
2008-03-21 03:04:57 +03:00
smbconf_shutdown ( conf_ctx ) ;
2008-01-13 03:40:05 +03:00
return werr ;
2007-12-19 17:10:24 +03:00
}
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetServerSetInfo_l ( struct libnetapi_ctx * ctx ,
struct NetServerSetInfo * r )
2007-12-19 17:10:24 +03:00
{
2008-04-08 04:42:50 +04:00
switch ( r - > in . level ) {
2007-12-19 17:10:24 +03:00
case 1005 :
2008-04-08 04:42:50 +04:00
return NetServerSetInfo_l_1005 ( ctx , r ) ;
2007-12-19 17:10:24 +03:00
default :
return WERR_UNKNOWN_LEVEL ;
}
return WERR_UNKNOWN_LEVEL ;
}
2008-01-18 04:38:35 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-08 04:42:50 +04:00
WERROR NetServerSetInfo_r ( struct libnetapi_ctx * ctx ,
struct NetServerSetInfo * r )
2007-12-19 17:10:24 +03:00
{
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
NTSTATUS status ;
WERROR werr ;
union srvsvc_NetSrvInfo info ;
2008-04-08 04:42:50 +04:00
status = cli_full_connection ( & cli , NULL , r - > in . server_name ,
2007-12-19 17:10:24 +03:00
NULL , 0 ,
" IPC$ " , " IPC " ,
ctx - > username ,
ctx - > workgroup ,
ctx - > password ,
2008-04-08 21:42:26 +04:00
CLI_FULL_CONNECTION_USE_KERBEROS |
CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS ,
Undefined , NULL ) ;
2007-12-19 17:10:24 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
pipe_cli = cli_rpc_pipe_open_noauth ( cli , PI_SRVSVC ,
& status ) ;
if ( ! pipe_cli ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
} ;
2008-04-08 04:42:50 +04:00
switch ( r - > in . level ) {
2007-12-19 17:10:24 +03:00
case 1005 :
2008-04-08 04:42:50 +04:00
info . info1005 = ( struct srvsvc_NetSrvInfo1005 * ) r - > in . buffer ;
2007-12-19 17:10:24 +03:00
break ;
default :
werr = WERR_NOT_SUPPORTED ;
goto done ;
}
status = rpccli_srvsvc_NetSrvSetInfo ( pipe_cli , ctx ,
2008-04-08 04:42:50 +04:00
r - > in . server_name ,
r - > in . level ,
2008-03-05 11:53:33 +03:00
& info ,
2008-04-08 04:42:50 +04:00
r - > out . parm_error ,
2007-12-19 17:10:24 +03:00
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
done :
if ( cli ) {
cli_shutdown ( cli ) ;
}
return werr ;
}