summaryrefslogtreecommitdiff
path: root/source3/rpcclient
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-10-31 04:11:17 +0000
committerLuke Leighton <lkcl@samba.org>1999-10-31 04:11:17 +0000
commitdbda98047df356cb854176982db156971d19466a (patch)
tree6ebfa9d20ccae8480e1ec65759aeb1ec14c13898 /source3/rpcclient
parente7b5412943f5b558a8b34645e376c53a39b079a1 (diff)
downloadsamba-dbda98047df356cb854176982db156971d19466a.tar.gz
samba-dbda98047df356cb854176982db156971d19466a.tar.bz2
samba-dbda98047df356cb854176982db156971d19466a.zip
added svcinfo <service name> command.
(This used to be commit c243231d8596a732aba69179ff8f3882e7118297)
Diffstat (limited to 'source3/rpcclient')
-rw-r--r--source3/rpcclient/cmd_svcctl.c205
-rw-r--r--source3/rpcclient/rpcclient.c7
2 files changed, 156 insertions, 56 deletions
diff --git a/source3/rpcclient/cmd_svcctl.c b/source3/rpcclient/cmd_svcctl.c
index ac3834fb16..1693823ea6 100644
--- a/source3/rpcclient/cmd_svcctl.c
+++ b/source3/rpcclient/cmd_svcctl.c
@@ -36,24 +36,53 @@ extern int smb_tidx;
extern FILE* out_hnd;
+void svc_display_query_svc_cfg(QUERY_SERVICE_CONFIG *cfg)
+{
+ display_query_svc_cfg(out_hnd, ACTION_HEADER , cfg);
+ display_query_svc_cfg(out_hnd, ACTION_ENUMERATE, cfg);
+ display_query_svc_cfg(out_hnd, ACTION_FOOTER , cfg);
+}
+
+BOOL svc_query_service(struct cli_state *cli, uint16 fnum,
+ POLICY_HND *pol_scm,
+ const char *svc_name,
+ SVC_QUERY_FN(svc_query_fn))
+{
+ BOOL res2 = True;
+ BOOL res3;
+ POLICY_HND pol_svc;
+ QUERY_SERVICE_CONFIG cfg;
+ uint32 svc_buf_size = 0x8000;
+
+ res2 = res2 ? svc_open_service(cli, fnum,
+ pol_scm,
+ svc_name, 0x80000001,
+ &pol_svc) : False;
+ res3 = res2 ? svc_query_svc_cfg(cli, fnum,
+ &pol_svc, &cfg,
+ &svc_buf_size) : False;
+
+ if (res3 && svc_query_fn != NULL)
+ {
+ svc_query_fn(&cfg);
+ }
+
+ res2 = res2 ? svc_close(cli, fnum, &pol_svc) : False;
+
+ return res3;
+}
+
/****************************************************************************
-nt svcistry enum
+nt service info
****************************************************************************/
-void cmd_svc_enum(struct client_info *info)
+void cmd_svc_info(struct client_info *info)
{
uint16 fnum;
BOOL res = True;
BOOL res1 = True;
- int i;
- uint32 resume_hnd = 0;
- uint32 buf_size = 0;
- uint32 dos_error = 0;
- ENUM_SRVC_STATUS *svcs = NULL;
- uint32 num_svcs = 0;
- fstring tmp;
- BOOL request_info = False;
+ fstring svc_name;
- POLICY_HND sc_man_pol;
+ POLICY_HND pol_scm;
fstring srv_name;
@@ -61,11 +90,12 @@ void cmd_svc_enum(struct client_info *info)
fstrcat(srv_name, info->myhostname);
strupper(srv_name);
- DEBUG(4,("cmd_svc_enum: server:%s\n", srv_name));
+ DEBUG(4,("cmd_svc_info: server:%s\n", srv_name));
- if (next_token(NULL, tmp, NULL, sizeof(tmp)))
+ if (!next_token(NULL, svc_name, NULL, sizeof(svc_name)))
{
- request_info = strequal(tmp, "-i");
+ report(out_hnd,"svcinfo <service name>\n");
+ return;
}
/* open SVCCTL session. */
@@ -74,80 +104,143 @@ void cmd_svc_enum(struct client_info *info)
/* open service control manager receive a policy handle */
res = res ? svc_open_sc_man(smb_cli, fnum,
srv_name, NULL, 0x80000004,
- &sc_man_pol) : False;
+ &pol_scm) : False;
+
+ res1 = svc_query_service(smb_cli, fnum, &pol_scm, svc_name,
+ svc_display_query_svc_cfg);
+
+ res = res ? svc_close(smb_cli, fnum, &pol_scm) : False;
+
+ /* close the session */
+ cli_nt_session_close(smb_cli, fnum);
+
+ if (res && res1)
+ {
+ DEBUG(5,("cmd_svc_info: query succeeded\n"));
+ }
+ else
+ {
+ DEBUG(5,("cmd_svc_info: query failed\n"));
+ }
+}
+
+static void svc_display_svc_info(ENUM_SRVC_STATUS *svc)
+{
+ display_svc_info(out_hnd, ACTION_HEADER , svc);
+ display_svc_info(out_hnd, ACTION_ENUMERATE, svc);
+ display_svc_info(out_hnd, ACTION_FOOTER , svc);
+}
+
+/****************************************************************************
+nt service enum
+****************************************************************************/
+BOOL msrpc_svc_enum(struct client_info *info,
+ ENUM_SRVC_STATUS **svcs,
+ uint32 *num_svcs,
+ SVC_INFO_FN(info_fn),
+ SVC_QUERY_FN(query_fn))
+{
+ uint16 fnum;
+ BOOL res = True;
+ BOOL res1 = False;
+ int i;
+ uint32 resume_hnd = 0;
+ uint32 buf_size = 0;
+ uint32 dos_error = 0;
+
+ POLICY_HND pol_scm;
+
+ fstring srv_name;
+
+ (*svcs) = NULL;
+ (*num_svcs) = 0;
+
+ fstrcpy(srv_name, "\\\\");
+ fstrcat(srv_name, info->myhostname);
+ strupper(srv_name);
+
+ /* open SVCCTL session. */
+ res = res ? cli_nt_session_open(smb_cli, PIPE_SVCCTL, &fnum) : False;
+
+ /* open service control manager receive a policy handle */
+ res = res ? svc_open_sc_man(smb_cli, fnum,
+ srv_name, NULL, 0x80000004,
+ &pol_scm) : False;
do
{
+ if ((*svcs) != NULL)
+ {
+ free(*svcs);
+ (*svcs) = NULL;
+ (*num_svcs) = 0;
+ }
+
buf_size += 0x800;
/* enumerate services */
res1 = res ? svc_enum_svcs(smb_cli, fnum,
- &sc_man_pol,
+ &pol_scm,
0x00000030, 0x00000003,
&buf_size, &resume_hnd, &dos_error,
- &svcs, &num_svcs) : False;
+ svcs, num_svcs) : False;
- } while (dos_error == ERRmoredata);
+ } while (res1 && dos_error == ERRmoredata);
- if (res1 && dos_error == 0x0 && num_svcs > 0 && svcs != NULL)
+ if (res1 && dos_error == 0x0 && (*num_svcs) > 0 && (*svcs) != NULL)
{
- fprintf(out_hnd,"Services\n");
- fprintf(out_hnd,"--------\n");
+ report(out_hnd,"Services\n");
+ report(out_hnd,"--------\n");
}
- for (i = 0; i < num_svcs && svcs != NULL && res1; i++)
+ for (i = 0; i < (*num_svcs) && (*svcs) != NULL && res1; i++)
{
- BOOL res2 = request_info;
- BOOL res3;
- POLICY_HND svc_pol;
fstring svc_name;
- QUERY_SERVICE_CONFIG cfg;
- uint32 svc_buf_size = 0x800;
- unistr_to_ascii(svc_name, svcs[i].uni_srvc_name.buffer,
+ unistr_to_ascii(svc_name, (*svcs)[i].uni_srvc_name.buffer,
sizeof(svc_name)-1);
- res2 = res2 ? svc_open_service(smb_cli, fnum,
- &sc_man_pol,
- svc_name, 0x80000001,
- &svc_pol) : False;
- res3 = res2 ? svc_query_svc_cfg(smb_cli, fnum,
- &svc_pol, &cfg,
- &svc_buf_size) : False;
-
- if (res3)
+ if (query_fn != NULL)
{
- display_query_svc_cfg(out_hnd, ACTION_HEADER , &cfg);
- display_query_svc_cfg(out_hnd, ACTION_ENUMERATE, &cfg);
- display_query_svc_cfg(out_hnd, ACTION_FOOTER , &cfg);
+ res1 = svc_query_service(smb_cli, fnum, &pol_scm,
+ svc_name, query_fn);
}
- else
+ else if (info_fn != NULL)
{
- display_svc_info(out_hnd, ACTION_HEADER , &svcs[i]);
- display_svc_info(out_hnd, ACTION_ENUMERATE, &svcs[i]);
- display_svc_info(out_hnd, ACTION_FOOTER , &svcs[i]);
+ info_fn(&(*svcs)[i]);
}
-
- res2 = res2 ? svc_close(smb_cli, fnum, &svc_pol) : False;
}
- if (svcs != NULL)
- {
- free(svcs);
- }
-
- res = res ? svc_close(smb_cli, fnum, &sc_man_pol) : False;
+ res = res ? svc_close(smb_cli, fnum, &pol_scm) : False;
/* close the session */
cli_nt_session_close(smb_cli, fnum);
- if (res && res1)
+ return res1;
+}
+
+/****************************************************************************
+nt service enum
+****************************************************************************/
+void cmd_svc_enum(struct client_info *info)
+{
+ ENUM_SRVC_STATUS *svcs = NULL;
+ uint32 num_svcs = 0;
+ fstring tmp;
+ BOOL request_info = False;
+
+ if (next_token(NULL, tmp, NULL, sizeof(tmp)))
{
- DEBUG(5,("cmd_svc_enum: query succeeded\n"));
+ request_info = strequal(tmp, "-i");
}
- else
+
+ msrpc_svc_enum(info, &svcs, &num_svcs,
+ request_info ? NULL : svc_display_svc_info,
+ request_info ? svc_display_query_svc_cfg : NULL);
+
+ if (svcs != NULL)
{
- DEBUG(5,("cmd_svc_enum: query failed\n"));
+ free(svcs);
}
}
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index b8f159df75..44adf4417b 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -138,6 +138,13 @@ commands[] =
{COMPL_NONE, COMPL_NONE}
},
+ {
+ "svcinfo",
+ cmd_svc_info,
+ "<service> Service Information",
+ {COMPL_NONE, COMPL_NONE}
+ },
+
/*
* scheduler
*/