LCOV - code coverage report
Current view: top level - source4/torture/rpc - atsvc.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 7 67 10.4 %
Date: 2023-11-21 12:31:41 Functions: 1 5 20.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    test suite for atsvc rpc operations
       4             : 
       5             :    Copyright (C) Tim Potter 2003
       6             :    
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             :    
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             :    
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "librpc/gen_ndr/ndr_atsvc_c.h"
      23             : #include "torture/rpc/torture_rpc.h"
      24             : 
      25           0 : static bool test_JobGetInfo(struct dcerpc_pipe *p, struct torture_context *tctx, uint32_t job_id)
      26             : {
      27           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
      28           0 :         struct atsvc_JobGetInfo r;
      29           0 :         struct atsvc_JobInfo *info = talloc(tctx, struct atsvc_JobInfo);
      30           0 :         if (!info) {
      31           0 :                 return false;
      32             :         }
      33             : 
      34           0 :         r.in.servername = dcerpc_server_name(p);
      35           0 :         r.in.job_id = job_id;
      36           0 :         r.out.job_info = &info;
      37             : 
      38           0 :         torture_assert_ntstatus_ok(tctx, dcerpc_atsvc_JobGetInfo_r(b, tctx, &r),
      39             :                 "JobGetInfo failed");
      40           0 :         torture_assert_ntstatus_ok(tctx, r.out.result, "JobGetInfo failed");
      41             : 
      42           0 :         return true;
      43             : }
      44             : 
      45           0 : static bool test_JobDel(struct dcerpc_pipe *p, struct torture_context *tctx, uint32_t min_job_id,
      46             :                         uint32_t max_job_id)
      47             : {
      48           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
      49           0 :         struct atsvc_JobDel r;
      50             : 
      51           0 :         r.in.servername = dcerpc_server_name(p);
      52           0 :         r.in.min_job_id = min_job_id;
      53           0 :         r.in.max_job_id = max_job_id;
      54             : 
      55           0 :         torture_assert_ntstatus_ok(tctx, dcerpc_atsvc_JobDel_r(b, tctx, &r),
      56             :                 "JobDel failed");
      57           0 :         torture_assert_ntstatus_ok(tctx, r.out.result, "JobDel failed");
      58             : 
      59           0 :         return true;
      60             : }
      61             : 
      62           0 : static bool test_JobEnum(struct torture_context *tctx, struct dcerpc_pipe *p)
      63             : {
      64           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
      65           0 :         struct atsvc_JobEnum r;
      66           0 :         struct atsvc_enum_ctr ctr;
      67           0 :         uint32_t resume_handle = 0, i, total_entries = 0;
      68             :         
      69           0 :         bool ret = true;
      70             : 
      71           0 :         r.in.servername = dcerpc_server_name(p);
      72           0 :         ctr.entries_read = 0;
      73           0 :         ctr.first_entry = NULL;
      74           0 :         r.in.ctr = r.out.ctr = &ctr;
      75           0 :         r.in.preferred_max_len = 0xffffffff;
      76           0 :         r.in.resume_handle = r.out.resume_handle = &resume_handle;
      77           0 :         r.out.total_entries = &total_entries;
      78             : 
      79           0 :         torture_assert_ntstatus_ok(tctx, dcerpc_atsvc_JobEnum_r(b, tctx, &r),
      80             :                 "JobEnum failed");
      81           0 :         torture_assert_ntstatus_ok(tctx, r.out.result, "JobEnum failed");
      82             : 
      83           0 :         for (i = 0; i < r.out.ctr->entries_read; i++) {
      84           0 :                 if (!test_JobGetInfo(p, tctx, r.out.ctr->first_entry[i].job_id)) {
      85           0 :                         ret = false;
      86             :                 }
      87             :         }
      88             : 
      89           0 :         return ret;
      90             : }
      91             : 
      92           0 : static bool test_JobAdd(struct torture_context *tctx, struct dcerpc_pipe *p)
      93             : {
      94           0 :         struct dcerpc_binding_handle *b = p->binding_handle;
      95           0 :         struct atsvc_JobAdd r;
      96           0 :         struct atsvc_JobInfo info;
      97             : 
      98           0 :         r.in.servername = dcerpc_server_name(p);
      99           0 :         info.job_time = 0x050ae4c0; /* 11:30pm */
     100           0 :         info.days_of_month = 0;     /* n/a */
     101           0 :         info.days_of_week = 0x02;   /* Tuesday */
     102           0 :         info.flags = 0x11;          /* periodic, non-interactive */
     103           0 :         info.command = "foo.exe";
     104           0 :         r.in.job_info = &info;
     105             : 
     106           0 :         torture_assert_ntstatus_ok(tctx, dcerpc_atsvc_JobAdd_r(b, tctx, &r),
     107             :                 "JobAdd failed");
     108           0 :         torture_assert_ntstatus_ok(tctx, r.out.result, "JobAdd failed");
     109             : 
     110             :         /* Run EnumJobs again in case there were no jobs to begin with */
     111             : 
     112           0 :         if (!test_JobEnum(tctx, p)) {
     113           0 :                 return false;
     114             :         }
     115             : 
     116           0 :         if (!test_JobGetInfo(p, tctx, *r.out.job_id)) {
     117           0 :                 return false;
     118             :         }
     119             : 
     120           0 :         if (!test_JobDel(p, tctx, *r.out.job_id, *r.out.job_id)) {
     121           0 :                 return false;
     122             :         }
     123             : 
     124           0 :         return true;
     125             : }
     126             : 
     127        2358 : struct torture_suite *torture_rpc_atsvc(TALLOC_CTX *mem_ctx)
     128             : {
     129        2358 :         struct torture_suite *suite = torture_suite_create(mem_ctx, "atsvc");
     130         125 :         struct torture_rpc_tcase *tcase;
     131             :         
     132        2358 :         tcase = torture_suite_add_rpc_iface_tcase(suite, "atsvc", &ndr_table_atsvc);
     133             : 
     134        2358 :         torture_rpc_tcase_add_test(tcase, "JobEnum", test_JobEnum);
     135        2358 :         torture_rpc_tcase_add_test(tcase, "JobAdd", test_JobAdd);
     136             : 
     137        2358 :         return suite;
     138             : }

Generated by: LCOV version 1.14