rpcclient "Service Control Manager" svcenum [-i] command.
[samba.git] / source / rpcclient / cmd_svcctl.c
index 4f0978e17ff227b162b94e0d1af43c018d8e5c66..e30c20af6415909151129e8f7c4d5a2a5b160847 100644 (file)
@@ -46,10 +46,15 @@ void cmd_svc_enum(struct client_info *info)
        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;
 
        POLICY_HND sc_man_pol;
-       fstring full_keyname;
+       
        fstring srv_name;
 
        fstrcpy(srv_name, "\\\\");
@@ -58,61 +63,79 @@ void cmd_svc_enum(struct client_info *info)
 
        DEBUG(4,("cmd_svc_enum: server:%s\n", srv_name));
 
+       if (next_token(NULL, tmp, NULL, sizeof(tmp)))
+       {
+               request_info = strequal(tmp, "-i");
+       }
+
        /* 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 ? do_svc_open_sc_man(smb_cli, fnum,
+       res = res ? svc_open_sc_man(smb_cli, fnum,
                                srv_name, NULL, 0x80000004,
                                &sc_man_pol) : False;
 
        do
        {
-       /* enumerate services */
-       res1 = res ? do_svc_enum_svcs(smb_cli, fnum,
-                               &sc_man_pol,
-                               0x00000030, 0x00000003,
-                                       0x00000080, &resume_hnd, &svcs) : False;
+               buf_size += 0x800;
 
-       } while (resume_hnd != 0);
+               /* enumerate services */
+               res1 = res ? svc_enum_svcs(smb_cli, fnum,
+                                       &sc_man_pol,
+                                       0x00000030, 0x00000003,
+                                       &buf_size, &resume_hnd, &dos_error,
+                                       &svcs, &num_svcs) : False;
 
-       if (svcs != NULL)
-       {
-               free(svcs);
-       }
+       } while (dos_error == ERRmoredata);
 
-#if 0
-       if (res1 && num_subkeys > 0)
+       if (res1 && dos_error == 0x0 && num_svcs > 0 && svcs != NULL)
        {
-               fprintf(out_hnd,"Subkeys\n");
-               fprintf(out_hnd,"-------\n");
+               fprintf(out_hnd,"Services\n");
+               fprintf(out_hnd,"--------\n");
        }
 
-       for (i = 0; i < num_subkeys; i++)
+       for (i = 0; i < num_svcs && svcs != NULL && res1; i++)
        {
-               BOOL res2 = True;
-               /*
-                * enumerate key
-                */
-
-               /* enum key */
-               res2 = res2 ? do_svc_enum_key(smb_cli, fnum, &key_pol,
-                                       i, enum_name,
-                                       &enum_unk1, &enum_unk2,
-                                       &key_mod_time) : False;
-               
-               if (res2)
+               BOOL res2 = request_info;
+               BOOL res3;
+               POLICY_HND svc_pol;
+               fstring svc_name;
+               QUERY_SERVICE_CONFIG cfg;
+               uint32 svc_buf_size = 0x800;
+
+               fstrcpy(svc_name, unistr2(svcs[i].uni_srvc_name.buffer));
+
+               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)
                {
-                       display_svc_key_info(out_hnd, ACTION_HEADER   , enum_name, key_mod_time);
-                       display_svc_key_info(out_hnd, ACTION_ENUMERATE, enum_name, key_mod_time);
-                       display_svc_key_info(out_hnd, ACTION_FOOTER   , enum_name, key_mod_time);
+                       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);
+               }
+               else
+               {
+                       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]);
                }
 
+               res2 = res2 ? svc_close(smb_cli, fnum, &svc_pol) : False;
        }
 
+       if (svcs != NULL)
+       {
+               free(svcs);
        }
-#endif
-       res  = res  ? do_svc_close(smb_cli, fnum, &sc_man_pol) : False;
+
+       res = res ? svc_close(smb_cli, fnum, &sc_man_pol) : False;
 
        /* close the session */
        cli_nt_session_close(smb_cli, fnum);