r25235: add simple WINBIND-STRUCT-GETDCNAME test
[kai/samba.git] / source / torture / winbind / struct_based.c
1 /*
2    Unix SMB/CIFS implementation.
3    SMB torture tester - winbind struct based protocol
4    Copyright (C) Stefan Metzmacher 2007
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "pstring.h"
22 #include "torture/torture.h"
23 #include "torture/winbind/proto.h"
24 #include "nsswitch/winbind_client.h"
25 #include "param/param.h"
26
27 #define DO_STRUCT_REQ_REP(op,req,rep) do { \
28         NSS_STATUS _result; \
29         _result = winbindd_request_response(op, req, rep); \
30         torture_assert_int_equal(torture, _result, NSS_STATUS_SUCCESS, \
31                                  __STRING(op) "(struct based)"); \
32 } while (0)
33
34 static bool torture_winbind_struct_ping(struct torture_context *torture)
35 {
36         struct timeval tv = timeval_current();
37         int timelimit = torture_setting_int(torture, "timelimit", 5);
38         uint32_t total = 0;
39
40         torture_comment(torture,
41                         "Running WINBINDD_PING (struct based) for %d seconds\n",
42                         timelimit);
43
44         while (timeval_elapsed(&tv) < timelimit) {
45                 DO_STRUCT_REQ_REP(WINBINDD_PING, NULL, NULL);
46                 total++;
47         }
48
49         torture_comment(torture,
50                         "%u (%.1f/s) WINBINDD_PING (struct based)\n",
51                         total, total / timeval_elapsed(&tv));
52
53         return true;
54 }
55
56 static bool torture_winbind_struct_getdcname(struct torture_context *torture)
57 {
58         struct winbindd_request req;
59         struct winbindd_response rep;
60
61         ZERO_STRUCT(req);
62         ZERO_STRUCT(rep);
63
64         fstrcpy(req.domain_name, lp_workgroup());
65
66         DO_STRUCT_REQ_REP(WINBINDD_GETDCNAME, &req, &rep);
67
68         /*
69          * TODO: test all trusted domains
70          */
71
72         return true;
73 }
74
75 struct torture_suite *torture_winbind_struct_init(void)
76 {
77         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "STRUCT");
78
79         torture_suite_add_simple_test(suite, "PING", torture_winbind_struct_ping);
80         torture_suite_add_simple_test(suite, "GETDCNAME", torture_winbind_struct_getdcname);
81
82         suite->description = talloc_strdup(suite, "WINBIND - struct based protocol tests");
83
84         return suite;
85 }