diff options
author | Luke Leighton <lkcl@samba.org> | 1999-10-31 04:11:17 +0000 |
---|---|---|
committer | Luke Leighton <lkcl@samba.org> | 1999-10-31 04:11:17 +0000 |
commit | dbda98047df356cb854176982db156971d19466a (patch) | |
tree | 6ebfa9d20ccae8480e1ec65759aeb1ec14c13898 /source3 | |
parent | e7b5412943f5b558a8b34645e376c53a39b079a1 (diff) | |
download | samba-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')
-rw-r--r-- | source3/include/ntdomain.h | 3 | ||||
-rw-r--r-- | source3/include/proto.h | 15 | ||||
-rw-r--r-- | source3/rpc_client/cli_svcctl.c | 2 | ||||
-rw-r--r-- | source3/rpc_parse/parse_svc.c | 7 | ||||
-rw-r--r-- | source3/rpcclient/cmd_svcctl.c | 205 | ||||
-rw-r--r-- | source3/rpcclient/rpcclient.c | 7 |
6 files changed, 179 insertions, 60 deletions
diff --git a/source3/include/ntdomain.h b/source3/include/ntdomain.h index 8d35d7aae3..3f2461af95 100644 --- a/source3/include/ntdomain.h +++ b/source3/include/ntdomain.h @@ -162,5 +162,8 @@ struct acct_info #define REG_KEY_FN(fn) void (*fn)(const char*, const char*, time_t) #define REG_VAL_FN(fn) void (*fn)(const char *, const char*, uint32, BUFFER2 *) +#define SVC_QUERY_FN(fn) void (*fn)(QUERY_SERVICE_CONFIG *) +#define SVC_INFO_FN(fn) void (*fn)(ENUM_SRVC_STATUS *) + #endif /* _NT_DOMAIN_H */ diff --git a/source3/include/proto.h b/source3/include/proto.h index ad4c637aa0..aed1d824de 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -2042,7 +2042,7 @@ BOOL svc_open_sc_man(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd); BOOL svc_open_service(struct cli_state *cli, uint16 fnum, POLICY_HND *scm_hnd, - char *srv_name, + const char *srv_name, uint32 des_access, POLICY_HND *hnd); BOOL svc_enum_svcs(struct cli_state *cli, uint16 fnum, @@ -3049,7 +3049,7 @@ BOOL make_svc_r_open_sc_man(SVC_R_OPEN_SC_MAN *r_u, POLICY_HND *hnd, BOOL svc_io_r_open_sc_man(char *desc, SVC_R_OPEN_SC_MAN *r_u, prs_struct *ps, int depth); BOOL make_svc_q_open_service(SVC_Q_OPEN_SERVICE *q_u, POLICY_HND *hnd, - char *server, + const char *server, uint32 des_access) ; BOOL svc_io_q_open_service(char *desc, SVC_Q_OPEN_SERVICE *q_u, prs_struct *ps, int depth); BOOL make_svc_r_open_service(SVC_R_OPEN_SERVICE *r_u, POLICY_HND *hnd, @@ -3303,6 +3303,17 @@ void cmd_time(struct client_info *info); /*The following definitions come from rpcclient/cmd_svcctl.c */ +void svc_display_query_svc_cfg(QUERY_SERVICE_CONFIG *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)); +void cmd_svc_info(struct client_info *info); +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)); void cmd_svc_enum(struct client_info *info); /*The following definitions come from rpcclient/cmd_wkssvc.c */ diff --git a/source3/rpc_client/cli_svcctl.c b/source3/rpc_client/cli_svcctl.c index 292972eae2..f161e4207f 100644 --- a/source3/rpc_client/cli_svcctl.c +++ b/source3/rpc_client/cli_svcctl.c @@ -96,7 +96,7 @@ do a SVC Open Service ****************************************************************************/ BOOL svc_open_service(struct cli_state *cli, uint16 fnum, POLICY_HND *scm_hnd, - char *srv_name, + const char *srv_name, uint32 des_access, POLICY_HND *hnd) { diff --git a/source3/rpc_parse/parse_svc.c b/source3/rpc_parse/parse_svc.c index 6b1155a90b..43594329b5 100644 --- a/source3/rpc_parse/parse_svc.c +++ b/source3/rpc_parse/parse_svc.c @@ -108,7 +108,7 @@ BOOL svc_io_r_open_sc_man(char *desc, SVC_R_OPEN_SC_MAN *r_u, prs_struct *ps, i ********************************************************************/ BOOL make_svc_q_open_service(SVC_Q_OPEN_SERVICE *q_u, POLICY_HND *hnd, - char *server, + const char *server, uint32 des_access) { DEBUG(5,("make_svc_q_open_service\n")); @@ -209,6 +209,7 @@ BOOL svc_io_q_start_service(char *desc, SVC_Q_START_SERVICE *q_s, prs_struct *ps for (i = 0; i < q_s->argc2; i++) { smb_io_unistr2("", &(q_s->argv[i]), 1, ps, depth); + prs_align(ps); } } @@ -396,6 +397,8 @@ BOOL svc_io_r_enum_svcs_status(char *desc, SVC_R_ENUM_SVCS_STATUS *svc, prs_stru buf_offset = ps->offset; ps->offset = buf_offset + svc->buf_size; + prs_align(ps); + prs_uint32("more_buf_size", ps, depth, &(svc->more_buf_size)); prs_uint32("num_svcs", ps, depth, &(svc->num_svcs)); smb_io_enum_hnd("resume_hnd", &(svc->resume_hnd), ps, depth); @@ -508,6 +511,8 @@ BOOL svc_io_r_enum_svcs_status(char *desc, SVC_R_ENUM_SVCS_STATUS *svc, prs_stru ps->offset = srvc_offset; + prs_align(ps); + prs_uint32("more_buf_size", ps, depth, &(svc->more_buf_size)); prs_uint32("num_svcs", ps, depth, &(svc->num_svcs)); smb_io_enum_hnd("resume_hnd", &(svc->resume_hnd), ps, depth); 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 */ |