s4:samldb LDB module - MS-SAMR 3.1.1.8.10 "userAccountControl"
[Samba/vl.git] / source4 / torture / libsmbclient / libsmbclient.c
blob2e78c3a40200eaabcf24191331362052492e0058
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 "auth/credentials/credentials.h"
23 #include "lib/cmdline/popt_common.h"
24 #include <libsmbclient.h>
25 #include "torture/libsmbclient/proto.h"
27 bool torture_libsmbclient_init_context(struct torture_context *tctx,
28 SMBCCTX **ctx_p)
30 SMBCCTX *ctx;
32 ctx = smbc_new_context();
33 torture_assert(tctx, ctx, "failed to get new context");
34 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
36 smbc_setDebug(ctx, DEBUGLEVEL);
37 smbc_setOptionDebugToStderr(ctx, 1);
39 /* yes, libsmbclient API frees the username when freeing the context, so
40 * have to pass malloced data here */
41 smbc_setUser(ctx, strdup(cli_credentials_get_username(cmdline_credentials)));
43 *ctx_p = ctx;
45 return true;
48 static bool torture_libsmbclient_version(struct torture_context *tctx)
50 torture_comment(tctx, "Testing smbc_version\n");
52 torture_assert(tctx, smbc_version(), "failed to get version");
54 return true;
57 static bool torture_libsmbclient_initialize(struct torture_context *tctx)
59 SMBCCTX *ctx;
61 torture_comment(tctx, "Testing smbc_new_context\n");
63 ctx = smbc_new_context();
64 torture_assert(tctx, ctx, "failed to get new context");
66 torture_comment(tctx, "Testing smbc_init_context\n");
68 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
70 smbc_free_context(ctx, 1);
72 return true;
75 static bool test_opendir(struct torture_context *tctx,
76 SMBCCTX *ctx,
77 const char *fname,
78 bool expect_success)
80 int handle, ret;
82 torture_comment(tctx, "Testing smbc_opendir(%s)\n", fname);
84 handle = smbc_opendir(fname);
85 if (!expect_success) {
86 return true;
88 if (handle < 0) {
89 torture_fail(tctx, talloc_asprintf(tctx, "failed to obain file handle for '%s'", fname));
92 ret = smbc_closedir(handle);
93 torture_assert_int_equal(tctx, ret, 0,
94 talloc_asprintf(tctx, "failed to close file handle for '%s'", fname));
96 return true;
99 static bool torture_libsmbclient_opendir(struct torture_context *tctx)
101 int i;
102 SMBCCTX *ctx;
103 bool ret = true;
104 const char *bad_urls[] = {
106 NULL,
107 "smb",
108 "smb:",
109 "smb:/",
110 "smb:///",
111 "bms://",
112 ":",
113 ":/",
114 "://",
115 ":///",
116 "/",
117 "//",
118 "///"
120 const char *good_urls[] = {
121 "smb://",
122 "smb://WORKGROUP",
123 "smb://WORKGROUP/"
126 torture_assert(tctx, torture_libsmbclient_init_context(tctx, &ctx), "");
127 smbc_set_context(ctx);
129 for (i=0; i < ARRAY_SIZE(bad_urls); i++) {
130 ret &= test_opendir(tctx, ctx, bad_urls[i], false);
132 for (i=0; i < ARRAY_SIZE(good_urls); i++) {
133 ret &= test_opendir(tctx, ctx, good_urls[i], true);
136 smbc_free_context(ctx, 1);
138 return ret;
141 /* note the strdup for string options on smbc_set calls. I think libsmbclient is
142 * really doing something wrong here: in smbc_free_context libsmbclient just
143 * calls free() on the string options so it assumes the callers have malloced
144 * them before setting them via smbc_set calls. */
146 #define TEST_OPTION_INT(option, val) \
147 torture_comment(tctx, "Testing smbc_set" #option "\n");\
148 smbc_set ##option(ctx, val);\
149 torture_comment(tctx, "Testing smbc_get" #option "\n");\
150 torture_assert_int_equal(tctx, smbc_get ##option(ctx), val, "failed " #option);
152 #define TEST_OPTION_STRING(option, val) \
153 torture_comment(tctx, "Testing smbc_set" #option "\n");\
154 smbc_set ##option(ctx, strdup(val));\
155 torture_comment(tctx, "Testing smbc_get" #option "\n");\
156 torture_assert_str_equal(tctx, smbc_get ##option(ctx), val, "failed " #option);
158 bool torture_libsmbclient_configuration(struct torture_context *tctx)
160 SMBCCTX *ctx;
162 ctx = smbc_new_context();
163 torture_assert(tctx, ctx, "failed to get new context");
164 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
166 TEST_OPTION_INT(Debug, DEBUGLEVEL);
167 TEST_OPTION_STRING(NetbiosName, "torture_netbios");
168 TEST_OPTION_STRING(Workgroup, "torture_workgroup");
169 TEST_OPTION_STRING(User, "torture_user");
170 TEST_OPTION_INT(Timeout, 12345);
172 smbc_free_context(ctx, 1);
174 return true;
177 bool torture_libsmbclient_options(struct torture_context *tctx)
179 SMBCCTX *ctx;
181 ctx = smbc_new_context();
182 torture_assert(tctx, ctx, "failed to get new context");
183 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
185 TEST_OPTION_INT(OptionDebugToStderr, true);
186 TEST_OPTION_INT(OptionFullTimeNames, true);
187 TEST_OPTION_INT(OptionOpenShareMode, SMBC_SHAREMODE_DENY_ALL);
188 /* FIXME: OptionUserData */
189 TEST_OPTION_INT(OptionSmbEncryptionLevel, SMBC_ENCRYPTLEVEL_REQUEST);
190 TEST_OPTION_INT(OptionCaseSensitive, false);
191 TEST_OPTION_INT(OptionBrowseMaxLmbCount, 2);
192 TEST_OPTION_INT(OptionUrlEncodeReaddirEntries, true);
193 TEST_OPTION_INT(OptionOneSharePerServer, true);
194 TEST_OPTION_INT(OptionUseKerberos, false);
195 TEST_OPTION_INT(OptionFallbackAfterKerberos, false);
196 TEST_OPTION_INT(OptionNoAutoAnonymousLogin, true);
197 TEST_OPTION_INT(OptionUseCCache, true);
199 smbc_free_context(ctx, 1);
201 return true;
204 NTSTATUS torture_libsmbclient_init(void)
206 struct torture_suite *suite;
208 suite = torture_suite_create(talloc_autofree_context(), "libsmbclient");
210 torture_suite_add_simple_test(suite, "version", torture_libsmbclient_version);
211 torture_suite_add_simple_test(suite, "initialize", torture_libsmbclient_initialize);
212 torture_suite_add_simple_test(suite, "configuration", torture_libsmbclient_configuration);
213 torture_suite_add_simple_test(suite, "options", torture_libsmbclient_options);
214 torture_suite_add_simple_test(suite, "opendir", torture_libsmbclient_opendir);
216 suite->description = talloc_strdup(suite, "libsmbclient interface tests");
218 torture_register_suite(suite);
220 return NT_STATUS_OK;