diff options
author | Gerald Carter <jerry@samba.org> | 2005-03-24 16:11:23 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:56:17 -0500 |
commit | 259d44dbb2c2239339f6888fd5da12632abcbb28 (patch) | |
tree | 89c120869821b3b9ee040c1b5c1b404d6c53f56f /source3/utils | |
parent | 987fd2ed97b91804646b8d93fff37d7f2efa6bab (diff) | |
download | samba-259d44dbb2c2239339f6888fd5da12632abcbb28.tar.gz samba-259d44dbb2c2239339f6888fd5da12632abcbb28.tar.bz2 samba-259d44dbb2c2239339f6888fd5da12632abcbb28.zip |
r6038: adding more flesh to 'net rpc service'
open and close the service control manager.
Also experimenting with ideas for cli_xxx() interface.
(This used to be commit 4da89ef17b8c4644b97b923cebfe8e446b508b4d)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_rpc_service.c | 106 |
1 files changed, 72 insertions, 34 deletions
diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index d9791610dd..79e7eaa900 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -20,55 +20,93 @@ #include "includes.h" #include "utils/net.h" + /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv ) +static WERROR open_scmanager( struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hSCM ) { -#if 0 - POLICY_HND dom_pol; - NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + SVCCTL_Q_OPEN_SCMANAGER in; + SVCCTL_R_OPEN_SCMANAGER out; + WERROR result; + fstring server; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + /* leave the database name NULL to get the default service db */ - DOM_SID sid; + in.database = NULL; - if (argc < 2 ) { - d_printf("Usage: net rpc rights revoke <name|SID> <rights...>\n"); - return NT_STATUS_OK; - } + /* set the server name */ - result = name_to_sid(cli, mem_ctx, &sid, argv[0]); - if (!NT_STATUS_IS_OK(result)) - return result; + if ( !(in.servername = TALLOC_P( mem_ctx, UNISTR2 )) ) + return WERR_NOMEM; + fstr_sprintf( server, "\\\\%s", cli->desthost ); + init_unistr2( in.servername, server, UNI_STR_TERMINATE ); - result = cli_lsa_open_policy2(cli, mem_ctx, True, - SEC_RIGHTS_MAXIMUM_ALLOWED, - &dom_pol); + in.access = SC_MANAGER_ALL_ACCESS; + + result = cli_svcctl_open_scm( cli, mem_ctx, &in, &out ); + + if ( !W_ERROR_IS_OK( result ) ) + return result; - if (!NT_STATUS_IS_OK(result)) - return result; + memcpy( hSCM, &out.handle, sizeof(POLICY_HND) ); + + return WERR_OK; +} - result = cli_lsa_remove_account_rights(cli, mem_ctx, &dom_pol, sid, - False, argc-1, argv+1); - if (!NT_STATUS_IS_OK(result)) - goto done; +/******************************************************************** +********************************************************************/ - d_printf("Successfully revoked rights.\n"); +static WERROR close_service_handle( struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hService ) +{ + SVCCTL_Q_CLOSE_SERVICE in; + SVCCTL_R_CLOSE_SERVICE out; + WERROR result; + + ZERO_STRUCT(in); + ZERO_STRUCT(out); + + memcpy( &in.handle, hService, sizeof(POLICY_HND) ); + + result = cli_svcctl_close_service( cli, mem_ctx, &in, &out ); + + if ( !W_ERROR_IS_OK( result ) ) + return result; + + return WERR_OK; +} -done: - if ( !NT_STATUS_IS_OK(result) ) { - d_printf("Failed to revoke privileges for %s (%s)", - argv[0], nt_errstr(result)); - } + + +/******************************************************************** +********************************************************************/ + +static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv ) +{ + POLICY_HND hSCM; + WERROR result = WERR_GENERAL_FAILURE; - cli_lsa_close(cli, mem_ctx, &dom_pol); + if (argc != 0 ) { + d_printf("Usage: net rpc service list\n"); + return NT_STATUS_OK; + } - return result; -#else + if ( !W_ERROR_IS_OK(result = open_scmanager( cli, mem_ctx, &hSCM )) ) { + d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + return werror_to_ntstatus(result); + } + + d_printf("Successfully opened Service Control Manager.\n"); + + close_service_handle( cli, mem_ctx, &hSCM ); + return NT_STATUS_OK; -#endif } @@ -77,7 +115,7 @@ done: static int rpc_service_list( int argc, const char **argv ) { - return run_rpc_command( NULL, PI_LSARPC, 0, + return run_rpc_command( NULL, PI_SVCCTL, 0, rpc_service_list_internal, argc, argv ); } |