~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/torture/rpc/echo.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
#include "includes.h"
24
 
#include "torture/torture.h"
25
 
#include "torture/rpc/rpc.h"
 
24
#include "torture/rpc/torture_rpc.h"
26
25
#include "lib/events/events.h"
27
26
#include "librpc/gen_ndr/ndr_echo_c.h"
28
27
 
34
33
        n = i = value; \
35
34
        r.in.in_data = n; \
36
35
        r.out.out_data = &n; \
37
 
        status = dcerpc_echo_AddOne(p, tctx, &r); \
38
 
        torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "AddOne(%d) failed", i)); \
 
36
        torture_assert_ntstatus_ok(tctx, dcerpc_echo_AddOne_r(b, tctx, &r), \
 
37
                talloc_asprintf(tctx, "AddOne(%d) failed", i)); \
39
38
        torture_assert (tctx, n == i+1, talloc_asprintf(tctx, "%d + 1 != %u (should be %u)\n", i, n, i+1)); \
40
39
        torture_comment (tctx, "%d + 1 = %u\n", i, n); \
41
40
} while(0)
42
41
 
43
42
static bool test_addone(struct torture_context *tctx, 
44
 
                                                struct dcerpc_pipe *p)
 
43
                        struct dcerpc_pipe *p)
45
44
{
46
45
        uint32_t i;
47
 
        NTSTATUS status;
48
46
        uint32_t n;
49
47
        struct echo_AddOne r;
 
48
        struct dcerpc_binding_handle *b = p->binding_handle;
50
49
 
51
50
        for (i=0;i<10;i++) {
52
51
                TEST_ADDONE(tctx, i);
63
62
  test the EchoData interface
64
63
*/
65
64
static bool test_echodata(struct torture_context *tctx,
66
 
                                                  struct dcerpc_pipe *p)
 
65
                          struct dcerpc_pipe *p)
67
66
{
68
67
        int i;
69
 
        NTSTATUS status;
70
68
        uint8_t *data_in, *data_out;
71
69
        int len;
72
70
        struct echo_EchoData r;
 
71
        struct dcerpc_binding_handle *b = p->binding_handle;
73
72
 
74
73
        if (torture_setting_bool(tctx, "quick", false) &&
75
74
            (p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) {
87
86
        r.in.len = len;
88
87
        r.in.in_data = data_in;
89
88
 
90
 
        status = dcerpc_echo_EchoData(p, tctx, &r);
91
 
        torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, 
92
 
                                                                                        "EchoData(%d) failed\n", len));
 
89
        torture_assert_ntstatus_ok(tctx, dcerpc_echo_EchoData_r(b, tctx, &r),
 
90
                talloc_asprintf(tctx, "EchoData(%d) failed\n", len));
93
91
 
94
92
        data_out = r.out.out_data;
95
93
 
111
109
  test the SourceData interface
112
110
*/
113
111
static bool test_sourcedata(struct torture_context *tctx,
114
 
                                                  struct dcerpc_pipe *p)
 
112
                            struct dcerpc_pipe *p)
115
113
{
116
114
        int i;
117
 
        NTSTATUS status;
118
115
        int len;
119
116
        struct echo_SourceData r;
 
117
        struct dcerpc_binding_handle *b = p->binding_handle;
120
118
 
121
119
        if (torture_setting_bool(tctx, "quick", false) &&
122
120
            (p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) {
127
125
 
128
126
        r.in.len = len;
129
127
 
130
 
        status = dcerpc_echo_SourceData(p, tctx, &r);
131
 
        torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, 
132
 
                                                                                "SourceData(%d) failed", len));
 
128
        torture_assert_ntstatus_ok(tctx, dcerpc_echo_SourceData_r(b, tctx, &r),
 
129
                talloc_asprintf(tctx, "SourceData(%d) failed", len));
133
130
 
134
131
        for (i=0;i<len;i++) {
135
132
                uint8_t *v = (uint8_t *)r.out.data;
144
141
  test the SinkData interface
145
142
*/
146
143
static bool test_sinkdata(struct torture_context *tctx, 
147
 
                                                  struct dcerpc_pipe *p)
 
144
                          struct dcerpc_pipe *p)
148
145
{
149
146
        int i;
150
 
        NTSTATUS status;
151
147
        uint8_t *data_in;
152
148
        int len;
153
149
        struct echo_SinkData r;
 
150
        struct dcerpc_binding_handle *b = p->binding_handle;
154
151
 
155
152
        if (torture_setting_bool(tctx, "quick", false) &&
156
153
            (p->conn->flags & DCERPC_DEBUG_VALIDATE_BOTH)) {
167
164
        r.in.len = len;
168
165
        r.in.data = data_in;
169
166
 
170
 
        status = dcerpc_echo_SinkData(p, tctx, &r);
171
 
        torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, 
172
 
                                                                                "SinkData(%d) failed", 
173
 
                                                           len));
 
167
        torture_assert_ntstatus_ok(tctx, dcerpc_echo_SinkData_r(b, tctx, &r),
 
168
                talloc_asprintf(tctx, "SinkData(%d) failed", len));
174
169
 
175
170
        torture_comment(tctx, "sunk %d bytes\n", len);
176
171
        return true;
181
176
  test the testcall interface
182
177
*/
183
178
static bool test_testcall(struct torture_context *tctx,
184
 
                                                  struct dcerpc_pipe *p)
 
179
                          struct dcerpc_pipe *p)
185
180
{
186
 
        NTSTATUS status;
187
181
        struct echo_TestCall r;
188
182
        const char *s = NULL;
 
183
        struct dcerpc_binding_handle *b = p->binding_handle;
189
184
 
190
185
        r.in.s1 = "input string";
191
186
        r.out.s2 = &s;
192
187
 
193
 
        status = dcerpc_echo_TestCall(p, tctx, &r);
194
 
        torture_assert_ntstatus_ok(tctx, status, "TestCall failed");
 
188
        torture_assert_ntstatus_ok(tctx, dcerpc_echo_TestCall_r(b, tctx, &r),
 
189
                "TestCall failed");
195
190
 
196
191
        torture_assert_str_equal(tctx, s, "input string", "Didn't receive back same string");
197
192
 
202
197
  test the testcall interface
203
198
*/
204
199
static bool test_testcall2(struct torture_context *tctx,
205
 
                                                  struct dcerpc_pipe *p)
 
200
                           struct dcerpc_pipe *p)
206
201
{
207
 
        NTSTATUS status;
208
202
        struct echo_TestCall2 r;
209
203
        int i;
 
204
        struct dcerpc_binding_handle *b = p->binding_handle;
210
205
 
211
206
        for (i=1;i<=7;i++) {
212
207
                r.in.level = i;
213
208
                r.out.info = talloc(tctx, union echo_Info);
214
209
 
215
210
                torture_comment(tctx, "Testing TestCall2 level %d\n", i);
216
 
                status = dcerpc_echo_TestCall2(p, tctx, &r);
217
 
                torture_assert_ntstatus_ok(tctx, status, "TestCall2 failed");
 
211
                torture_assert_ntstatus_ok(tctx, dcerpc_echo_TestCall2_r(b, tctx, &r),
 
212
                        "TestCall2 failed");
 
213
                torture_assert_ntstatus_ok(tctx, r.out.result, "TestCall2 failed");
218
214
        }
219
215
        return true;
220
216
}
221
217
 
 
218
static void test_sleep_done(struct tevent_req *subreq)
 
219
{
 
220
        bool *done1 = (bool *)tevent_req_callback_data_void(subreq);
 
221
        *done1 = true;
 
222
}
 
223
 
222
224
/*
223
225
  test the TestSleep interface
224
226
*/
225
227
static bool test_sleep(struct torture_context *tctx,
226
 
                                                  struct dcerpc_pipe *p)
 
228
                       struct dcerpc_pipe *p)
227
229
{
228
230
        int i;
229
 
        NTSTATUS status;
230
231
#define ASYNC_COUNT 3
231
 
        struct rpc_request *req[ASYNC_COUNT];
 
232
        struct tevent_req *req[ASYNC_COUNT];
232
233
        struct echo_TestSleep r[ASYNC_COUNT];
233
 
        bool done[ASYNC_COUNT];
 
234
        bool done1[ASYNC_COUNT];
 
235
        bool done2[ASYNC_COUNT];
234
236
        struct timeval snd[ASYNC_COUNT];
235
237
        struct timeval rcv[ASYNC_COUNT];
236
238
        struct timeval diff[ASYNC_COUNT];
237
239
        struct tevent_context *ctx;
238
240
        int total_done = 0;
 
241
        struct dcerpc_binding_handle *b = p->binding_handle;
239
242
 
240
243
        if (torture_setting_bool(tctx, "quick", false)) {
241
244
                torture_skip(tctx, "TestSleep disabled - use \"torture:quick=no\" to enable\n");
243
246
        torture_comment(tctx, "Testing TestSleep - use \"torture:quick=yes\" to disable\n");
244
247
 
245
248
        for (i=0;i<ASYNC_COUNT;i++) {
246
 
                done[i]         = false;
 
249
                done1[i]        = false;
 
250
                done2[i]        = false;
247
251
                snd[i]          = timeval_current();
248
252
                rcv[i]          = timeval_zero();
249
253
                r[i].in.seconds = ASYNC_COUNT-i;
250
 
                req[i] = dcerpc_echo_TestSleep_send(p, tctx, &r[i]);
 
254
                req[i] = dcerpc_echo_TestSleep_r_send(tctx, tctx->ev, b, &r[i]);
251
255
                torture_assert(tctx, req[i], "Failed to send async sleep request\n");
 
256
                tevent_req_set_callback(req[i], test_sleep_done, &done1[i]);
252
257
        }
253
258
 
254
259
        ctx = dcerpc_event_context(p);
256
261
                torture_assert(tctx, event_loop_once(ctx) == 0, 
257
262
                                           "Event context loop failed");
258
263
                for (i=0;i<ASYNC_COUNT;i++) {
259
 
                        if (done[i] == false && req[i]->state == RPC_REQUEST_DONE) {
 
264
                        if (done2[i] == false && done1[i] == true) {
260
265
                                int rounded_tdiff;
261
266
                                total_done++;
262
 
                                done[i] = true;
 
267
                                done2[i] = true;
263
268
                                rcv[i]  = timeval_current();
264
269
                                diff[i] = timeval_until(&snd[i], &rcv[i]);
265
270
                                rounded_tdiff = (int)(0.5 + diff[i].tv_sec + (1.0e-6*diff[i].tv_usec));
266
 
                                status  = dcerpc_ndr_request_recv(req[i]);
267
271
                                torture_comment(tctx, "rounded_tdiff=%d\n", rounded_tdiff);
268
 
                                torture_assert_ntstatus_ok(tctx, status, 
269
 
                                                        talloc_asprintf(tctx, "TestSleep(%d) failed", i));
 
272
                                torture_assert_ntstatus_ok(tctx,
 
273
                                        dcerpc_echo_TestSleep_r_recv(req[i], tctx),
 
274
                                        talloc_asprintf(tctx, "TestSleep(%d) failed", i));
270
275
                                torture_assert(tctx, r[i].out.result == r[i].in.seconds,
271
276
                                        talloc_asprintf(tctx, "Failed - Asked to sleep for %u seconds (server replied with %u seconds and the reply takes only %u seconds)", 
272
 
                                                r[i].out.result, r[i].in.seconds, (uint_t)diff[i].tv_sec));
 
277
                                                r[i].out.result, r[i].in.seconds, (unsigned int)diff[i].tv_sec));
273
278
                                torture_assert(tctx, r[i].out.result <= rounded_tdiff, 
274
279
                                        talloc_asprintf(tctx, "Failed - Slept for %u seconds (but reply takes only %u.%06u seconds)", 
275
 
                                                r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec));
 
280
                                                r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec));
276
281
                                if (r[i].out.result+1 == rounded_tdiff) {
277
282
                                        torture_comment(tctx, "Slept for %u seconds (but reply takes %u.%06u seconds - busy server?)\n", 
278
 
                                                        r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
 
283
                                                        r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec);
279
284
                                } else if (r[i].out.result == rounded_tdiff) {
280
285
                                        torture_comment(tctx, "Slept for %u seconds (reply takes %u.%06u seconds - ok)\n", 
281
 
                                                        r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
 
286
                                                        r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec);
282
287
                                } else {
283
 
                                                torture_comment(tctx, "(Failed) - Not async - Slept for %u seconds (but reply takes %u.%06u seconds)", 
284
 
                                                        r[i].out.result, (uint_t)diff[i].tv_sec, (uint_t)diff[i].tv_usec);
285
 
                                        /* TODO: let the test fail here, when we support async rpc on ncacn_np */
 
288
                                        torture_fail(tctx, talloc_asprintf(tctx,
 
289
                                                     "(Failed) - Not async - Slept for %u seconds (but reply takes %u.%06u seconds)\n",
 
290
                                                     r[i].out.result, (unsigned int)diff[i].tv_sec, (unsigned int)diff[i].tv_usec));
286
291
                                }
287
292
                        }
288
293
                }
297
302
static bool test_enum(struct torture_context *tctx,
298
303
                                                  struct dcerpc_pipe *p)
299
304
{
300
 
        NTSTATUS status;
301
305
        struct echo_TestEnum r;
302
306
        enum echo_Enum1 v = ECHO_ENUM1;
303
307
        struct echo_Enum2 e2;
304
308
        union echo_Enum3 e3;
 
309
        struct dcerpc_binding_handle *b = p->binding_handle;
305
310
 
306
311
        r.in.foo1 = &v;
307
312
        r.in.foo2 = &e2;
314
319
        e2.e2 = ECHO_ENUM1_32;
315
320
        e3.e1 = ECHO_ENUM2;
316
321
 
317
 
        status = dcerpc_echo_TestEnum(p, tctx, &r);
318
 
        torture_assert_ntstatus_ok(tctx, status, "TestEnum failed");
 
322
        torture_assert_ntstatus_ok(tctx, dcerpc_echo_TestEnum_r(b, tctx, &r),
 
323
                "TestEnum failed");
319
324
        return true;
320
325
}
321
326
 
325
330
static bool test_surrounding(struct torture_context *tctx,
326
331
                                                  struct dcerpc_pipe *p)
327
332
{
328
 
        NTSTATUS status;
329
333
        struct echo_TestSurrounding r;
 
334
        struct dcerpc_binding_handle *b = p->binding_handle;
330
335
 
331
336
        ZERO_STRUCT(r);
332
337
        r.in.data = talloc(tctx, struct echo_Surrounding);
336
341
 
337
342
        r.out.data = talloc(tctx, struct echo_Surrounding);
338
343
 
339
 
        status = dcerpc_echo_TestSurrounding(p, tctx, &r);
340
 
        torture_assert_ntstatus_ok(tctx, status, "TestSurrounding failed");
 
344
        torture_assert_ntstatus_ok(tctx, dcerpc_echo_TestSurrounding_r(b, tctx, &r),
 
345
                "TestSurrounding failed");
341
346
        
342
347
        torture_assert(tctx, r.out.data->x == 2 * r.in.data->x,
343
348
                "TestSurrounding did not make the array twice as large");
349
354
  test multiple levels of pointers
350
355
*/
351
356
static bool test_doublepointer(struct torture_context *tctx,
352
 
                                                           struct dcerpc_pipe *p)
 
357
                               struct dcerpc_pipe *p)
353
358
{
354
 
        NTSTATUS status;
355
359
        struct echo_TestDoublePointer r;
356
360
        uint16_t value = 12;
357
361
        uint16_t *pvalue = &value;
358
362
        uint16_t **ppvalue = &pvalue;
 
363
        struct dcerpc_binding_handle *b = p->binding_handle;
359
364
 
360
365
        ZERO_STRUCT(r);
361
366
        r.in.data = &ppvalue;
362
367
 
363
 
        status = dcerpc_echo_TestDoublePointer(p, tctx, &r);
364
 
        torture_assert_ntstatus_ok(tctx, status, "TestDoublePointer failed");
 
368
        torture_assert_ntstatus_ok(tctx, dcerpc_echo_TestDoublePointer_r(b, tctx, &r),
 
369
                "TestDoublePointer failed");
365
370
 
366
371
        torture_assert_int_equal(tctx, value, r.out.result, 
367
372
                                        "TestDoublePointer did not return original value");
396
401
        }
397
402
        req->ignore_timeout = true;
398
403
 
399
 
        status  = dcerpc_ndr_request_recv(req);
 
404
        status  = dcerpc_echo_TestSleep_recv(req);
400
405
        torture_assert_ntstatus_equal(tctx, status, NT_STATUS_IO_TIMEOUT, 
401
406
                                                                  "request should have timed out");
402
407
 
414
419
                goto failed;
415
420
        }
416
421
        req->ignore_timeout = true;
417
 
        status  = dcerpc_ndr_request_recv(req);
 
422
        status  = dcerpc_echo_TestSleep_recv(req);
418
423
        torture_assert_ntstatus_equal(tctx, status, NT_STATUS_IO_TIMEOUT, 
419
424
                "request should have timed out");
420
425
 
430
435
 
431
436
struct torture_suite *torture_rpc_echo(TALLOC_CTX *mem_ctx)
432
437
{
433
 
        struct torture_suite *suite = torture_suite_create(
434
 
                mem_ctx, "ECHO");
 
438
        struct torture_suite *suite = torture_suite_create(mem_ctx, "echo");
435
439
        struct torture_rpc_tcase *tcase;
436
440
 
437
441
        tcase = torture_suite_add_rpc_iface_tcase(suite, "echo",