Fix CID 1138341 Resource leak
[Samba.git] / source4 / torture / libnetapi / libnetapi_server.c
blob1888009402965dd38a1d032d42c1980b15e4c95a
1 /*
2 Unix SMB/CIFS implementation.
3 SMB torture tester
4 Copyright (C) Guenther Deschner 2010
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.
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.
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/>.
20 #include "includes.h"
21 #include "torture/smbtorture.h"
22 #include <netapi.h>
23 #include "torture/libnetapi/proto.h"
25 #define NETAPI_STATUS(tctx, x,y,fn) \
26 torture_warning(tctx, "FAILURE: line %d: %s failed with status: %s (%d)\n", \
27 __LINE__, fn, libnetapi_get_error_string(x,y), y);
29 bool torture_libnetapi_server(struct torture_context *tctx)
31 NET_API_STATUS status = 0;
32 uint8_t *buffer = NULL;
33 int i;
35 const char *hostname = torture_setting_string(tctx, "host", NULL);
36 struct libnetapi_ctx *ctx;
38 torture_assert(tctx, torture_libnetapi_init_context(tctx, &ctx),
39 "failed to initialize libnetapi");
41 torture_comment(tctx, "NetServer tests\n");
43 torture_comment(tctx, "Testing NetRemoteTOD\n");
45 status = NetRemoteTOD(hostname, &buffer);
46 if (status) {
47 NETAPI_STATUS(tctx, ctx, status, "NetRemoteTOD");
48 goto out;
50 NetApiBufferFree(buffer);
52 torture_comment(tctx, "Testing NetRemoteTOD 10 times\n");
54 for (i=0; i<10; i++) {
55 status = NetRemoteTOD(hostname, &buffer);
56 if (status) {
57 NETAPI_STATUS(tctx, ctx, status, "NetRemoteTOD");
58 goto out;
60 NetApiBufferFree(buffer);
63 status = 0;
65 torture_comment(tctx, "NetServer tests succeeded\n");
66 out:
67 if (status != 0) {
68 torture_comment(tctx, "NetServer testsuite failed with: %s\n",
69 libnetapi_get_error_string(ctx, status));
70 libnetapi_free(ctx);
71 return false;
74 libnetapi_free(ctx);
75 return true;