added svcinfo <service name> command.
authorLuke Leighton <lkcl@samba.org>
Sun, 31 Oct 1999 04:11:17 +0000 (04:11 +0000)
committerLuke Leighton <lkcl@samba.org>
Sun, 31 Oct 1999 04:11:17 +0000 (04:11 +0000)
source/include/ntdomain.h
source/include/proto.h
source/rpc_client/cli_svcctl.c
source/rpc_parse/parse_svc.c
source/rpcclient/cmd_svcctl.c
source/rpcclient/rpcclient.c

index 8d35d7aae3671c1816edd8b7689bfd91fea42d36..3f2461af95ce1e79e5dbedf498bdb6c14b7b55d1 100644 (file)
@@ -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 */
 
index ad4c637aa01cd7e40ca1da2c3124efb94799c120..aed1d824de73ec8f8755bdb809f264defd4eff43 100644 (file)
@@ -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  */
index 292972eae2ee50a99745ad01ac7d3ceee608c884..f161e4207f7bab14756a70b8a61c423b8d09ea27 100644 (file)
@@ -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)
 {
index 6b1155a90b89a9bc91585bf2574d4f86b44ec99e..43594329b518a8c5b67bcbeb6ba15716755c1b61 100644 (file)
@@ -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); 
index ac3834fb1638360b619cb3f1dabb5caa596398de..1693823ea6d3b8d1f7445e80dfa06e76b188c4a0 100644 (file)
@@ -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);
        }
 }
 
index b8f159df75818e38239a89e1a25b2cba8877eedb..44adf4417b5c59c654cba6c925dfba0d484ed95d 100644 (file)
@@ -138,6 +138,13 @@ commands[] =
                {COMPL_NONE, COMPL_NONE}
        },
 
+       {
+               "svcinfo",
+               cmd_svc_info,
+               "<service> Service Information",
+               {COMPL_NONE, COMPL_NONE}
+       },
+
        /*
         * scheduler
         */