s4-smbtorture: add NDR_PRINT macros for RAP tests (when called with -d10).
[samba.git] / source4 / torture / rap / rap.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for various RAP operations
4    Copyright (C) Volker Lendecke 2004
5    Copyright (C) Tim Potter 2005
6    Copyright (C) Jelmer Vernooij 2007
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "libcli/libcli.h"
24 #include "torture/smbtorture.h"
25 #include "torture/util.h"
26 #include "../librpc/gen_ndr/ndr_rap.h"
27 #include "librpc/ndr/libndr.h"
28 #include "param/param.h"
29 #include "torture/rap/proto.h"
30
31 #define RAP_GOTO(call) do { \
32         NTSTATUS _status; \
33         _status = call; \
34         if (!NT_STATUS_IS_OK(_status)) { \
35                 result = _status; \
36                 goto done; \
37         } \
38 } while (0)
39
40 #define NDR_GOTO(call) do { \
41         enum ndr_err_code _ndr_err; \
42         _ndr_err = call; \
43         if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
44                 result = ndr_map_error2ntstatus(_ndr_err); \
45                 goto done; \
46         } \
47 } while (0)
48
49 #define NDR_RETURN(call) do { \
50         enum ndr_err_code _ndr_err; \
51         _ndr_err = call; \
52         if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
53                 return ndr_map_error2ntstatus(_ndr_err); \
54         } \
55 } while (0)
56
57 struct rap_call {
58         uint16_t callno;
59         char *paramdesc;
60         const char *datadesc;
61
62         uint16_t status;
63         uint16_t convert;
64         
65         uint16_t rcv_paramlen, rcv_datalen;
66
67         struct ndr_push *ndr_push_param;
68         struct ndr_push *ndr_push_data;
69         struct ndr_pull *ndr_pull_param;
70         struct ndr_pull *ndr_pull_data;
71 };
72
73 #define RAPNDR_FLAGS (LIBNDR_FLAG_NOALIGN|LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_NULLTERM);
74
75 static struct rap_call *new_rap_cli_call(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, uint16_t callno)
76 {
77         struct rap_call *call;
78
79         call = talloc(mem_ctx, struct rap_call);
80
81         if (call == NULL)
82                 return NULL;
83
84         call->callno = callno;
85         call->rcv_paramlen = 4;
86
87         call->paramdesc = NULL;
88         call->datadesc = NULL;
89
90         call->ndr_push_param = ndr_push_init_ctx(mem_ctx, iconv_convenience);
91         call->ndr_push_param->flags = RAPNDR_FLAGS;
92
93         call->ndr_push_data = ndr_push_init_ctx(mem_ctx, iconv_convenience);
94         call->ndr_push_data->flags = RAPNDR_FLAGS;
95
96         return call;
97 }
98
99 static void rap_cli_push_paramdesc(struct rap_call *call, char desc)
100 {
101         int len = 0;
102
103         if (call->paramdesc != NULL)
104                 len = strlen(call->paramdesc);
105
106         call->paramdesc = talloc_realloc(call,
107                                          call->paramdesc,
108                                          char,
109                                          len+2);
110
111         call->paramdesc[len] = desc;
112         call->paramdesc[len+1] = '\0';
113 }
114
115 static void rap_cli_push_word(struct rap_call *call, uint16_t val)
116 {
117         rap_cli_push_paramdesc(call, 'W');
118         ndr_push_uint16(call->ndr_push_param, NDR_SCALARS, val);
119 }
120
121 static void rap_cli_push_dword(struct rap_call *call, uint32_t val)
122 {
123         rap_cli_push_paramdesc(call, 'D');
124         ndr_push_uint32(call->ndr_push_param, NDR_SCALARS, val);
125 }
126
127 static void rap_cli_push_rcvbuf(struct rap_call *call, int len)
128 {
129         rap_cli_push_paramdesc(call, 'r');
130         rap_cli_push_paramdesc(call, 'L');
131         ndr_push_uint16(call->ndr_push_param, NDR_SCALARS, len);
132         call->rcv_datalen = len;
133 }
134
135 static void rap_cli_expect_multiple_entries(struct rap_call *call)
136 {
137         rap_cli_push_paramdesc(call, 'e');
138         rap_cli_push_paramdesc(call, 'h');
139         call->rcv_paramlen += 4; /* uint16_t entry count, uint16_t total */
140 }
141
142 static void rap_cli_expect_word(struct rap_call *call)
143 {
144         rap_cli_push_paramdesc(call, 'h');
145         call->rcv_paramlen += 2;
146 }
147
148 static void rap_cli_push_string(struct rap_call *call, const char *str)
149 {
150         if (str == NULL) {
151                 rap_cli_push_paramdesc(call, 'O');
152                 return;
153         }
154         rap_cli_push_paramdesc(call, 'z');
155         ndr_push_string(call->ndr_push_param, NDR_SCALARS, str);
156 }
157
158 static void rap_cli_expect_format(struct rap_call *call, const char *format)
159 {
160         call->datadesc = format;
161 }
162
163 static NTSTATUS rap_pull_string(TALLOC_CTX *mem_ctx, struct ndr_pull *ndr,
164                                 uint16_t convert, const char **dest)
165 {
166         uint16_t string_offset;
167         uint16_t ignore;
168         const char *p;
169         size_t len;
170
171         NDR_RETURN(ndr_pull_uint16(ndr, NDR_SCALARS, &string_offset));
172         NDR_RETURN(ndr_pull_uint16(ndr, NDR_SCALARS, &ignore));
173
174         string_offset -= convert;
175
176         if (string_offset+1 > ndr->data_size)
177                 return NT_STATUS_INVALID_PARAMETER;
178
179         p = (const char *)(ndr->data + string_offset);
180         len = strnlen(p, ndr->data_size-string_offset);
181
182         if ( string_offset + len + 1 >  ndr->data_size )
183                 return NT_STATUS_INVALID_PARAMETER;
184
185         *dest = talloc_zero_array(mem_ctx, char, len+1);
186         pull_string((char *)*dest, p, len+1, len, STR_ASCII);
187
188         return NT_STATUS_OK;
189 }
190
191 static NTSTATUS rap_cli_do_call(struct smbcli_tree *tree, 
192                                 struct smb_iconv_convenience *iconv_convenience,
193                                 struct rap_call *call)
194 {
195         NTSTATUS result;
196         DATA_BLOB param_blob;
197         struct ndr_push *params;
198         struct smb_trans2 trans;
199
200         params = ndr_push_init_ctx(call, iconv_convenience);
201
202         if (params == NULL)
203                 return NT_STATUS_NO_MEMORY;
204
205         params->flags = RAPNDR_FLAGS;
206
207         trans.in.max_param = call->rcv_paramlen;
208         trans.in.max_data = call->rcv_datalen;
209         trans.in.max_setup = 0;
210         trans.in.flags = 0;
211         trans.in.timeout = 0;
212         trans.in.setup_count = 0;
213         trans.in.setup = NULL;
214         trans.in.trans_name = "\\PIPE\\LANMAN";
215
216         NDR_RETURN(ndr_push_uint16(params, NDR_SCALARS, call->callno));
217         if (call->paramdesc)
218                 NDR_RETURN(ndr_push_string(params, NDR_SCALARS, call->paramdesc));
219         if (call->datadesc)
220                 NDR_RETURN(ndr_push_string(params, NDR_SCALARS, call->datadesc));
221
222         param_blob = ndr_push_blob(call->ndr_push_param);
223         NDR_RETURN(ndr_push_bytes(params, param_blob.data,
224                                  param_blob.length));
225
226         trans.in.params = ndr_push_blob(params);
227         trans.in.data = data_blob(NULL, 0);
228
229         result = smb_raw_trans(tree, call, &trans);
230
231         if (!NT_STATUS_IS_OK(result))
232                 return result;
233
234         call->ndr_pull_param = ndr_pull_init_blob(&trans.out.params, call,
235                                                   iconv_convenience);
236         call->ndr_pull_param->flags = RAPNDR_FLAGS;
237
238         call->ndr_pull_data = ndr_pull_init_blob(&trans.out.data, call,
239                                                  iconv_convenience);
240         call->ndr_pull_data->flags = RAPNDR_FLAGS;
241
242         return result;
243 }
244
245
246 static NTSTATUS smbcli_rap_netshareenum(struct smbcli_tree *tree,
247                                         struct smb_iconv_convenience *iconv_convenience,
248                                         TALLOC_CTX *mem_ctx,
249                                         struct rap_NetShareEnum *r)
250 {
251         struct rap_call *call;
252         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
253         int i;
254
255         call = new_rap_cli_call(tree, iconv_convenience, RAP_WshareEnum);
256
257         if (call == NULL)
258                 return NT_STATUS_NO_MEMORY;
259
260         rap_cli_push_word(call, r->in.level); /* Level */
261         rap_cli_push_rcvbuf(call, r->in.bufsize);
262         rap_cli_expect_multiple_entries(call);
263
264         switch(r->in.level) {
265         case 0:
266                 rap_cli_expect_format(call, "B13");
267                 break;
268         case 1:
269                 rap_cli_expect_format(call, "B13BWz");
270                 break;
271         }
272
273         if (DEBUGLEVEL >= 10) {
274                 NDR_PRINT_IN_DEBUG(rap_NetShareEnum, r);
275         }
276
277         result = rap_cli_do_call(tree, iconv_convenience, call);
278
279         if (!NT_STATUS_IS_OK(result))
280                 goto done;
281
282         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.status));
283         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.convert));
284         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.count));
285         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.available));
286
287         r->out.info = talloc_array(mem_ctx, union rap_share_info, r->out.count);
288
289         if (r->out.info == NULL) {
290                 result = NT_STATUS_NO_MEMORY;
291                 goto done;
292         }
293
294         for (i=0; i<r->out.count; i++) {
295                 switch(r->in.level) {
296                 case 0:
297                         NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
298                                                 r->out.info[i].info0.share_name, 13));
299                         break;
300                 case 1:
301                         NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
302                                                 r->out.info[i].info1.share_name, 13));
303                         NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
304                                                 &r->out.info[i].info1.reserved1, 1));
305                         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_data,
306                                                NDR_SCALARS, &r->out.info[i].info1.share_type));
307                         RAP_GOTO(rap_pull_string(mem_ctx, call->ndr_pull_data,
308                                                r->out.convert,
309                                                &r->out.info[i].info1.comment));
310                         break;
311                 }
312         }
313
314         if (DEBUGLEVEL >= 10) {
315                 NDR_PRINT_OUT_DEBUG(rap_NetShareEnum, r);
316         }
317         result = NT_STATUS_OK;
318
319  done:
320         talloc_free(call);
321         return result;
322 }
323
324 static bool test_netshareenum(struct torture_context *tctx, 
325                               struct smbcli_state *cli)
326 {
327         struct rap_NetShareEnum r;
328         int i;
329
330         r.in.level = 1;
331         r.in.bufsize = 8192;
332
333         torture_assert_ntstatus_ok(tctx, 
334                 smbcli_rap_netshareenum(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r), "");
335
336         for (i=0; i<r.out.count; i++) {
337                 printf("%s %d %s\n", r.out.info[i].info1.share_name,
338                        r.out.info[i].info1.share_type,
339                        r.out.info[i].info1.comment);
340         }
341
342         return true;
343 }
344
345 static NTSTATUS smbcli_rap_netserverenum2(struct smbcli_tree *tree,
346                                           struct smb_iconv_convenience *iconv_convenience, 
347                                           TALLOC_CTX *mem_ctx,
348                                           struct rap_NetServerEnum2 *r)
349 {
350         struct rap_call *call;
351         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
352         int i;
353
354         call = new_rap_cli_call(mem_ctx, iconv_convenience, RAP_NetServerEnum2);
355
356         if (call == NULL)
357                 return NT_STATUS_NO_MEMORY;
358
359         rap_cli_push_word(call, r->in.level);
360         rap_cli_push_rcvbuf(call, r->in.bufsize);
361         rap_cli_expect_multiple_entries(call);
362         rap_cli_push_dword(call, r->in.servertype);
363         rap_cli_push_string(call, r->in.domain);
364
365         switch(r->in.level) {
366         case 0:
367                 rap_cli_expect_format(call, "B16");
368                 break;
369         case 1:
370                 rap_cli_expect_format(call, "B16BBDz");
371                 break;
372         }
373
374         if (DEBUGLEVEL >= 10) {
375                 NDR_PRINT_IN_DEBUG(rap_NetServerEnum2, r);
376         }
377
378         result = rap_cli_do_call(tree, iconv_convenience, call);
379
380         if (!NT_STATUS_IS_OK(result))
381                 goto done;
382
383         result = NT_STATUS_INVALID_PARAMETER;
384
385         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.status));
386         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.convert));
387         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.count));
388         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.available));
389
390         r->out.info = talloc_array(mem_ctx, union rap_server_info, r->out.count);
391
392         if (r->out.info == NULL) {
393                 result = NT_STATUS_NO_MEMORY;
394                 goto done;
395         }
396
397         for (i=0; i<r->out.count; i++) {
398                 switch(r->in.level) {
399                 case 0:
400                         NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
401                                                 r->out.info[i].info0.name, 16));
402                         break;
403                 case 1:
404                         NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
405                                                 r->out.info[i].info1.name, 16));
406                         NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
407                                               &r->out.info[i].info1.version_major, 1));
408                         NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
409                                               &r->out.info[i].info1.version_minor, 1));
410                         NDR_GOTO(ndr_pull_uint32(call->ndr_pull_data,
411                                                NDR_SCALARS, &r->out.info[i].info1.servertype));
412                         RAP_GOTO(rap_pull_string(mem_ctx, call->ndr_pull_data,
413                                                r->out.convert,
414                                                &r->out.info[i].info1.comment));
415                 }
416         }
417
418         if (DEBUGLEVEL >= 10) {
419                 NDR_PRINT_OUT_DEBUG(rap_NetServerEnum2, r);
420         }
421
422         result = NT_STATUS_OK;
423
424  done:
425         talloc_free(call);
426         return result;
427 }
428
429 static bool test_netserverenum(struct torture_context *tctx, 
430                                struct smbcli_state *cli)
431 {
432         struct rap_NetServerEnum2 r;
433         int i;
434
435         r.in.level = 0;
436         r.in.bufsize = 8192;
437         r.in.servertype = 0xffffffff;
438         r.in.servertype = 0x80000000;
439         r.in.domain = NULL;
440
441         torture_assert_ntstatus_ok(tctx, 
442                    smbcli_rap_netserverenum2(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r), "");
443
444         for (i=0; i<r.out.count; i++) {
445                 switch (r.in.level) {
446                 case 0:
447                         printf("%s\n", r.out.info[i].info0.name);
448                         break;
449                 case 1:
450                         printf("%s %x %s\n", r.out.info[i].info1.name,
451                                r.out.info[i].info1.servertype,
452                                r.out.info[i].info1.comment);
453                         break;
454                 }
455         }
456
457         return true;
458 }
459
460 NTSTATUS smbcli_rap_netservergetinfo(struct smbcli_tree *tree,
461                                               struct smb_iconv_convenience *iconv_convenience, 
462                                      TALLOC_CTX *mem_ctx,
463                                      struct rap_WserverGetInfo *r)
464 {
465         struct rap_call *call;
466         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
467
468         if (!(call = new_rap_cli_call(mem_ctx, iconv_convenience, RAP_WserverGetInfo))) {
469                 return NT_STATUS_NO_MEMORY;
470         }
471
472         rap_cli_push_word(call, r->in.level);
473         rap_cli_push_rcvbuf(call, r->in.bufsize);
474         rap_cli_expect_word(call);
475
476         switch(r->in.level) {
477         case 0:
478                 rap_cli_expect_format(call, "B16");
479                 break;
480         case 1:
481                 rap_cli_expect_format(call, "B16BBDz");
482                 break;
483         default:
484                 result = NT_STATUS_INVALID_PARAMETER;
485                 goto done;
486         }
487
488         if (DEBUGLEVEL >= 10) {
489                 NDR_PRINT_IN_DEBUG(rap_WserverGetInfo, r);
490         }
491
492         result = rap_cli_do_call(tree, iconv_convenience, call);
493
494         if (!NT_STATUS_IS_OK(result))
495                 goto done;
496
497         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.status));
498         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.convert));
499         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.available));
500
501         switch(r->in.level) {
502         case 0:
503                 NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
504                                         r->out.info.info0.name, 16));
505                 break;
506         case 1:
507                 NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
508                                         r->out.info.info1.name, 16));
509                 NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
510                                       &r->out.info.info1.version_major, 1));
511                 NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
512                                       &r->out.info.info1.version_minor, 1));
513                 NDR_GOTO(ndr_pull_uint32(call->ndr_pull_data,
514                                        NDR_SCALARS, &r->out.info.info1.servertype));
515                 RAP_GOTO(rap_pull_string(mem_ctx, call->ndr_pull_data,
516                                        r->out.convert,
517                                        &r->out.info.info1.comment));
518         }
519
520         if (DEBUGLEVEL >= 10) {
521                 NDR_PRINT_OUT_DEBUG(rap_WserverGetInfo, r);
522         }
523  done:
524         talloc_free(call);
525         return result;
526 }
527
528 NTSTATUS smbcli_rap_netprintqenum(struct smbcli_tree *tree,
529                                   struct smb_iconv_convenience *iconv_convenience,
530                                   TALLOC_CTX *mem_ctx,
531                                   struct rap_NetPrintQEnum *r)
532 {
533         struct rap_call *call;
534         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
535         int i;
536
537         if (!(call = new_rap_cli_call(mem_ctx, iconv_convenience, RAP_WPrintQEnum))) {
538                 return NT_STATUS_NO_MEMORY;
539         }
540
541         rap_cli_push_word(call, r->in.level);
542         rap_cli_push_rcvbuf(call, r->in.bufsize);
543         rap_cli_expect_multiple_entries(call);
544
545         switch(r->in.level) {
546         case 0:
547                 rap_cli_expect_format(call, "B13");
548                 break;
549         case 1:
550                 rap_cli_expect_format(call, "B13BWWWzzzzzWW");
551                 break;
552         case 2:
553                 rap_cli_expect_format(call, "B13BWWWzzzzzWN");
554                 break;
555         case 3:
556                 rap_cli_expect_format(call, "zWWWWzzzzWWzzl");
557                 break;
558         case 4:
559                 rap_cli_expect_format(call, "zWWWWzzzzWNzzl");
560                 break;
561         case 5:
562                 rap_cli_expect_format(call, "z");
563                 break;
564         default:
565                 result = NT_STATUS_INVALID_PARAMETER;
566                 goto done;
567         }
568
569         if (DEBUGLEVEL >= 10) {
570                 NDR_PRINT_IN_DEBUG(rap_NetPrintQEnum, r);
571         }
572
573         result = rap_cli_do_call(tree, iconv_convenience, call);
574
575         if (!NT_STATUS_IS_OK(result))
576                 goto done;
577
578         result = NT_STATUS_INVALID_PARAMETER;
579
580         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.status));
581         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.convert));
582         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.count));
583         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_param, NDR_SCALARS, &r->out.available));
584
585         r->out.info = talloc_array(mem_ctx, union rap_printq_info, r->out.count);
586
587         if (r->out.info == NULL) {
588                 result = NT_STATUS_NO_MEMORY;
589                 goto done;
590         }
591
592         for (i=0; i<r->out.count; i++) {
593                 switch(r->in.level) {
594                 case 0:
595                         NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
596                                                 r->out.info[i].info0.PrintQName, 13));
597                         break;
598                 case 1:
599                         NDR_GOTO(ndr_pull_bytes(call->ndr_pull_data,
600                                                 r->out.info[i].info1.PrintQName, 13));
601                         NDR_GOTO(ndr_pull_uint8(call->ndr_pull_data,
602                                                 NDR_SCALARS, &r->out.info[i].info1.Pad1));
603                         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_data,
604                                                  NDR_SCALARS,  &r->out.info[i].info1.Priority));
605                         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_data,
606                                                  NDR_SCALARS,  &r->out.info[i].info1.StartTime));
607                         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_data,
608                                                  NDR_SCALARS,  &r->out.info[i].info1.UntilTime));
609                         RAP_GOTO(rap_pull_string(mem_ctx, call->ndr_pull_data,
610                                                r->out.convert,
611                                                &r->out.info[i].info1.SeparatorPageFilename));
612                         RAP_GOTO(rap_pull_string(mem_ctx, call->ndr_pull_data,
613                                                r->out.convert,
614                                                &r->out.info[i].info1.PrintProcessorDllName));
615                         RAP_GOTO(rap_pull_string(mem_ctx, call->ndr_pull_data,
616                                                r->out.convert,
617                                                &r->out.info[i].info1.PrintDestinationsName));
618                         RAP_GOTO(rap_pull_string(mem_ctx, call->ndr_pull_data,
619                                                r->out.convert,
620                                                &r->out.info[i].info1.PrintParameterString));
621                         RAP_GOTO(rap_pull_string(mem_ctx, call->ndr_pull_data,
622                                                r->out.convert,
623                                                &r->out.info[i].info1.CommentString));
624                         NDR_GOTO(ndr_pull_rap_PrintQStatusCode(call->ndr_pull_data,
625                                                  NDR_SCALARS,  &r->out.info[i].info1.PrintQStatus));
626                         NDR_GOTO(ndr_pull_uint16(call->ndr_pull_data,
627                                                  NDR_SCALARS,  &r->out.info[i].info1.PrintJobCount));
628
629                         break;
630                 }
631         }
632
633         if (DEBUGLEVEL >= 10) {
634                 NDR_PRINT_OUT_DEBUG(rap_NetPrintQEnum, r);
635         }
636
637         result = NT_STATUS_OK;
638
639  done:
640         talloc_free(call);
641         return result;
642 }
643
644 static bool test_netservergetinfo(struct torture_context *tctx, 
645                                   struct smbcli_state *cli)
646 {
647         struct rap_WserverGetInfo r;
648         bool res = true;
649
650         r.in.bufsize = 0xffff;
651
652         r.in.level = 0;
653         torture_assert_ntstatus_ok(tctx,
654                 smbcli_rap_netservergetinfo(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r),
655                 "rap_netservergetinfo level 0 failed");
656
657         if (torture_setting_bool(tctx, "samba3", false)) {
658                 torture_skip(tctx, "skipping netservergetinfo level 1 against samba3");
659         }
660
661         r.in.level = 1;
662         torture_assert_ntstatus_ok(tctx,
663                 smbcli_rap_netservergetinfo(cli->tree, lp_iconv_convenience(tctx->lp_ctx), tctx, &r),
664                 "rap_netservergetinfo level 1 failed");
665
666         return res;
667 }
668
669 bool torture_rap_scan(struct torture_context *torture, struct smbcli_state *cli)
670 {
671         int callno;
672
673         for (callno = 0; callno < 0xffff; callno++) {
674                 struct rap_call *call = new_rap_cli_call(torture, lp_iconv_convenience(torture->lp_ctx), callno);
675                 NTSTATUS result;
676
677                 result = rap_cli_do_call(cli->tree, lp_iconv_convenience(torture->lp_ctx), call);
678
679                 if (!NT_STATUS_EQUAL(result, NT_STATUS_INVALID_PARAMETER))
680                         continue;
681
682                 printf("callno %d is RAP call\n", callno);
683         }
684
685         return true;
686 }
687
688 NTSTATUS torture_rap_init(void)
689 {
690         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "RAP");
691         struct torture_suite *suite_basic = torture_suite_create(suite, "BASIC");
692
693         torture_suite_add_suite(suite, suite_basic);
694         torture_suite_add_suite(suite, torture_rap_rpc(suite));
695         torture_suite_add_suite(suite, torture_rap_printing(suite));
696
697         torture_suite_add_1smb_test(suite_basic, "netserverenum", 
698                                     test_netserverenum);
699         torture_suite_add_1smb_test(suite_basic, "netshareenum",
700                                     test_netshareenum);
701         torture_suite_add_1smb_test(suite_basic, "netservergetinfo",
702                                     test_netservergetinfo);
703
704         torture_suite_add_1smb_test(suite, "SCAN", torture_rap_scan);
705
706         suite->description = talloc_strdup(suite, 
707                                                 "Remote Administration Protocol tests");
708
709         torture_register_suite(suite);
710
711         return NT_STATUS_OK;
712 }