File: execresult.cf

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (233 lines) | stat: -rw-r--r-- 9,526 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#######################################################
#
# Test returnszero()
#
#######################################################

body common control
{
      inputs => { "../../default.cf.sub" };
      bundlesequence  => { default("$(this.promise_filename)") };   
      version => "1.0";
}

bundle common g
{
  vars:
      "dummy" string => "dummy";
}

#######################################################

bundle agent init
{
  vars:
      "dummy" string => "dummy";
}

#######################################################

bundle agent test
{
  meta:
      "test_soft_fail" string => "windows",
        meta => { "ENT-10217" };
  vars:
      "dummy" string => "dummy";
}

#######################################################

bundle agent check
{
  vars:
      "cwd" string => dirname("$(this.promise_filename)");

    windows::
      "zero_rel" string => "type $(cwd)$(const.dirsep)text.txt";
      "one_rel" string => "type $(cwd)$(const.dirsep)text.txt.doesnotexist";
      "nxe_rel" string => "nosuchprogramexists";
      "zero_abs" string => "c:\windows\system32\cmd.exe /C type $(cwd)$(const.dirsep)text.txt";
      "one_abs" string => "c:\windows\system32\cmd.exe /C type $(cwd)$(const.dirsep)text.txt.doesnotexist";
      "nxe_abs" string => "c:\xbin\nosuchprogramexists";
      "zero_powershell" string => "Get-Content $(cwd)$(const.dirsep)text.txt";
      "one_powershell" string => "Get-Content $(cwd)$(const.dirsep)text.txt.doesnotexist";
      "nxe_powershell" string => "nosuchprogramexists";
    !windows::
      "zero_rel" string => "cat $(cwd)$(const.dirsep)text.txt";
      "one_rel" string => "cat $(cwd)$(const.dirsep)text.txt.doesnotexist";
      "nxe_rel" string => "nosuchprogramexists";
      "zero_abs" string => "/bin/cat $(cwd)$(const.dirsep)text.txt";
      "one_abs" string => "/bin/cat $(cwd)$(const.dirsep)text.txt.doesnotexist";
      "nxe_abs" string => "/xbin/nosuchprogramexists";

  classes:
      # Test whether we extracted the expected string.
      "zero_noshell_rel" expression => regcmp(".*Succeeded.*", execresult("$(zero_rel)", "noshell"));
      "zero_useshell_rel" expression => regcmp(".*Succeeded.*", execresult("$(zero_rel)", "useshell"));
      "zero_noshell_abs" expression => regcmp(".*Succeeded.*", execresult("$(zero_abs)", "noshell"));
      "zero_useshell_abs" expression => regcmp(".*Succeeded.*", execresult("$(zero_abs)", "useshell"));

      "one_noshell_rel" expression => regcmp(".*Succeeded.*", execresult("$(one_rel)", "noshell"));
      "one_useshell_rel" expression => regcmp(".*Succeeded.*", execresult("$(one_rel)", "useshell"));
      "one_noshell_abs" expression => regcmp(".*Succeeded.*", execresult("$(one_abs)", "noshell"));
      "one_useshell_abs" expression => regcmp(".*Succeeded.*", execresult("$(one_abs)", "useshell"));

      "nxe_noshell_rel" expression => regcmp(".*Succeeded.*", execresult("$(nxe_rel)", "noshell"));
      "nxe_useshell_rel" expression => regcmp(".*Succeeded.*", execresult("$(nxe_rel)", "useshell"));
      "nxe_noshell_abs" expression => regcmp(".*Succeeded.*", execresult("$(nxe_abs)", "noshell"));
      "nxe_useshell_abs" expression => regcmp(".*Succeeded.*", execresult("$(nxe_abs)", "useshell"));

      # Test whether any assignment happens at all.
      "does_assign_zero_noshell_rel" expression => regcmp(".*", execresult("$(zero_rel)", "noshell"));
      "does_assign_zero_useshell_rel" expression => regcmp(".*", execresult("$(zero_rel)", "useshell"));
      "does_assign_zero_noshell_abs" expression => regcmp(".*", execresult("$(zero_abs)", "noshell"));
      "does_assign_zero_useshell_abs" expression => regcmp(".*", execresult("$(zero_abs)", "useshell"));

      "does_assign_one_noshell_rel" expression => regcmp(".*", execresult("$(one_rel)", "noshell"));
      "does_assign_one_useshell_rel" expression => regcmp(".*", execresult("$(one_rel)", "useshell"));
      "does_assign_one_noshell_abs" expression => regcmp(".*", execresult("$(one_abs)", "noshell"));
      "does_assign_one_useshell_abs" expression => regcmp(".*", execresult("$(one_abs)", "useshell"));

      "does_assign_nxe_noshell_rel" expression => regcmp(".*", execresult("$(nxe_rel)", "noshell"));
      "does_assign_nxe_useshell_rel" expression => regcmp(".*", execresult("$(nxe_rel)", "useshell"));
      "does_assign_nxe_noshell_abs" expression => regcmp(".*", execresult("$(nxe_abs)", "noshell"));
      "does_assign_nxe_useshell_abs" expression => regcmp(".*", execresult("$(nxe_abs)", "useshell"));

    windows::
      # Test whether we extracted the expected string.
      "zero_powershell" expression => regcmp(".*Succeeded.*", execresult("$(zero_powershell)", "powershell"));
      "one_powershell" expression => regcmp(".*Succeeded.*", execresult("$(one_powershell)", "powershell"));
      "nxe_powershell" expression => regcmp(".*Succeeded.*", execresult("$(nxe_powershell)", "powershell"));

      # Test whether any assignment happens at all.
      "does_assign_zero_powershell" expression => regcmp(".*", execresult("$(zero_powershell)", "powershell"));
      "does_assign_one_powershell" expression => regcmp(".*", execresult("$(one_powershell)", "powershell"));
      "does_assign_nxe_powershell" expression => regcmp(".*", execresult("$(nxe_powershell)", "powershell"));

    any::
      "ok_common" and => {
			   "!zero_noshell_rel", "zero_useshell_rel", "zero_noshell_abs", "zero_useshell_abs",
			   "!one_noshell_rel", "!one_useshell_rel", "!one_noshell_abs", "!one_useshell_abs",
			   "!nxe_noshell_rel", "!nxe_useshell_rel", "!nxe_noshell_abs", "!nxe_useshell_abs",
			   "!does_assign_zero_noshell_rel", "does_assign_zero_useshell_rel", "does_assign_zero_noshell_abs", "does_assign_zero_useshell_abs",
			   "!does_assign_one_noshell_rel", "does_assign_one_useshell_rel", "does_assign_one_noshell_abs", "does_assign_one_useshell_abs",
			   "!does_assign_nxe_noshell_rel", "does_assign_nxe_useshell_rel", "!does_assign_nxe_noshell_abs", "!does_assign_nxe_useshell_abs",
      };
    windows::
      "ok_windows" and => {
			    "zero_powershell", "!one_powershell", "!nxe_powershell",
			    "does_assign_zero_powershell", "does_assign_one_powershell", "does_assign_nxe_powershell",
      };
      "ok" and => {
                    "ok_common", "ok_windows",
      };

    !windows::
      "ok" and => { "ok_common" };

  reports:
    DEBUG.zero_noshell_rel::
      "'$(zero_rel)' executes command successfully with noshell";

    DEBUG.!zero_useshell_rel::
      "'$(zero_rel)' executes command unsuccessfully with useshell";


    DEBUG.one_noshell_rel::
      "'$(one_rel)' executes command successfully with noshell";

    DEBUG.one_useshell_rel::
      "'$(one_rel)' executes command successfully with useshell";


    DEBUG.nxe_noshell_rel::
      "'$(nxe_rel)' executes command successfully with noshell";

    DEBUG.nxe_useshell_rel::
      "'$(nxe_rel)' executes command successfully with useshell";

    DEBUG.!zero_noshell_abs::
      "'$(zero_abs)' executes command unsuccessfully with noshell";

    DEBUG.!zero_useshell_abs::
      "'$(zero_abs)' executes command unsuccessfully with useshell";


    DEBUG.one_noshell_abs::
      "'$(one_abs)' executes command successfully with noshell";

    DEBUG.one_useshell_abs::
      "'$(one_abs)' executes command successfully with useshell";


    DEBUG.nxe_noshell_abs::
      "'$(nxe_abs)' executes command successfully with noshell";

    DEBUG.nxe_useshell_abs::
      "'$(nxe_abs)' executes command successfully with useshell";


    DEBUG.does_assign_zero_noshell_rel::
      "'$(zero_rel)' executes command with noshell";

    DEBUG.!does_assign_zero_useshell_rel::
      "'$(zero_rel)' does not execute command with useshell";


    DEBUG.does_assign_one_noshell_rel::
      "'$(one_rel)' executes command with noshell";

    DEBUG.!does_assign_one_useshell_rel::
      "'$(one_rel)' does not execute command with useshell";


    DEBUG.does_assign_nxe_noshell_rel::
      "'$(nxe_rel)' executes command with noshell";

    DEBUG.!does_assign_nxe_useshell_rel::
      "'$(nxe_rel)' does not execute command with useshell";

    DEBUG.!does_assign_zero_noshell_abs::
      "'$(zero_abs)' does not execute command with noshell";

    DEBUG.!does_assign_zero_useshell_abs::
      "'$(zero_abs)' does not execute command with useshell";


    DEBUG.!does_assign_one_noshell_abs::
      "'$(one_abs)' does not execute command with noshell";

    DEBUG.!does_assign_one_useshell_abs::
      "'$(one_abs)' does not execute command with useshell";


    DEBUG.does_assign_nxe_noshell_abs::
      "'$(nxe_abs)' executes command with noshell";

    DEBUG.does_assign_nxe_useshell_abs::
      "'$(nxe_abs)' executes command with useshell";

    windows.DEBUG.!zero_powershell::
      "'$(zero_powershell)' executes command unsuccessfully with powershell";

    windows.DEBUG.one_powershell::
      "'$(one_powershell)' executes command successfully with powershell";

    windows.DEBUG.nxe_powershell::
      "'$(nxe_powershell)' executes command successfully with powershell";

    windows.DEBUG.!does_assign_zero_powershell::
      "'$(zero_powershell)' does not execute command with powershell";

    windows.DEBUG.!does_assign_one_powershell::
      "'$(one_powershell)' does not execute command with powershell";

    windows.DEBUG.!does_assign_nxe_powershell::
      "'$(nxe_powershell)' does not execute command with powershell";

    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}