2 Unix SMB/CIFS implementation.
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/>.
21 #include "system/dir.h"
22 #include "torture/smbtorture.h"
23 #include "auth/credentials/credentials.h"
24 #include "lib/cmdline/popt_common.h"
25 #include <libsmbclient.h>
26 #include "torture/libsmbclient/proto.h"
27 #include "lib/param/loadparm.h"
28 #include "lib/param/param_global.h"
29 #include "dynconfig.h"
31 /* test string to compare with when debug_callback is called */
32 #define TEST_STRING "smbc_setLogCallback test"
34 /* Dummy log callback function */
35 static void debug_callback(void *private_ptr, int level, const char *msg)
37 bool *found = private_ptr;
38 if (strstr(msg, TEST_STRING) != NULL) {
44 static void auth_callback(const char *srv,
50 const char *workgroup =
51 cli_credentials_get_domain(popt_get_cmdline_credentials());
52 const char *username =
53 cli_credentials_get_username(popt_get_cmdline_credentials());
54 const char *password =
55 cli_credentials_get_password(popt_get_cmdline_credentials());
58 if (workgroup != NULL) {
59 ret = strlcpy(wg, workgroup, wglen);
65 if (username != NULL) {
66 ret = strlcpy(un, username, unlen);
72 if (password != NULL) {
73 ret = strlcpy(pw, password, pwlen);
80 bool torture_libsmbclient_init_context(struct torture_context *tctx,
83 const char *workgroup =
84 cli_credentials_get_domain(popt_get_cmdline_credentials());
85 const char *username =
86 cli_credentials_get_username(popt_get_cmdline_credentials());
87 const char *client_proto =
88 torture_setting_string(tctx, "clientprotocol", NULL);
93 ctx = smbc_new_context();
94 torture_assert_not_null_goto(tctx,
98 "Failed to create new context");
100 p = smbc_init_context(ctx);
101 torture_assert_not_null_goto(tctx,
105 "Failed to initialize context");
107 smbc_setDebug(ctx, DEBUGLEVEL);
108 smbc_setOptionDebugToStderr(ctx, 1);
110 if (workgroup != NULL) {
111 smbc_setWorkgroup(ctx, workgroup);
113 if (username != NULL) {
114 smbc_setUser(ctx, username);
117 smbc_setFunctionAuthData(ctx, auth_callback);
119 if (client_proto != NULL) {
120 smbc_setOptionProtocols(ctx, client_proto, client_proto);
127 smbc_free_context(ctx, 1);
133 static bool torture_libsmbclient_version(struct torture_context *tctx)
135 torture_comment(tctx, "Testing smbc_version\n");
137 torture_assert(tctx, smbc_version(), "failed to get version");
142 static bool torture_libsmbclient_initialize(struct torture_context *tctx)
147 torture_comment(tctx, "Testing smbc_new_context\n");
149 ctx = smbc_new_context();
150 torture_assert(tctx, ctx, "failed to get new context");
152 torture_comment(tctx, "Testing smbc_init_context\n");
154 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
156 smbc_setLogCallback(ctx, &ret, debug_callback);
157 DEBUG(0, (TEST_STRING"\n"));
158 torture_assert(tctx, ret, "Failed debug_callback not called");
160 smbc_setLogCallback(ctx, NULL, NULL);
161 DEBUG(0, (TEST_STRING"\n"));
162 torture_assert(tctx, !ret, "Failed debug_callback called");
164 smbc_free_context(ctx, 1);
169 static bool torture_libsmbclient_setConfiguration(struct torture_context *tctx)
172 struct loadparm_global *global_config = NULL;
173 const char *new_smb_conf = torture_setting_string(tctx,
177 ctx = smbc_new_context();
178 torture_assert(tctx, ctx, "failed to get new context");
180 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
182 torture_comment(tctx, "Testing smbc_setConfiguration - new file %s\n",
185 global_config = get_globals();
186 torture_assert(tctx, global_config, "Global Config is NULL");
188 /* check configuration before smbc_setConfiguration call */
189 torture_comment(tctx, "'workgroup' before setConfiguration %s\n",
190 global_config->workgroup);
191 torture_comment(tctx, "'client min protocol' before "
192 "setConfiguration %d\n",
193 global_config->client_min_protocol);
194 torture_comment(tctx, "'client max protocol' before "
195 "setConfiguration %d\n",
196 global_config->_client_max_protocol);
197 torture_comment(tctx, "'client signing' before setConfiguration %d\n",
198 global_config->client_signing);
199 torture_comment(tctx, "'deadtime' before setConfiguration %d\n",
200 global_config->deadtime);
202 torture_assert_int_equal(tctx, smbc_setConfiguration(ctx, new_smb_conf),
203 0, "setConfiguration conf file not found");
205 /* verify configuration */
206 torture_assert_str_equal(tctx, global_config->workgroup,
208 "smbc_setConfiguration failed, "
209 "'workgroup' not updated");
210 torture_assert_int_equal(tctx, global_config->client_min_protocol, 7,
211 "smbc_setConfiguration failed, 'client min protocol' "
213 torture_assert_int_equal(tctx, global_config->_client_max_protocol, 13,
214 "smbc_setConfiguration failed, 'client max protocol' "
216 torture_assert_int_equal(tctx, global_config->client_signing, 1,
217 "smbc_setConfiguration failed, 'client signing' "
219 torture_assert_int_equal(tctx, global_config->deadtime, 5,
220 "smbc_setConfiguration failed, 'deadtime' not updated");
222 /* Restore configuration to default */
223 smbc_setConfiguration(ctx, get_dyn_CONFIGFILE());
225 smbc_free_context(ctx, 1);
230 static bool test_opendir(struct torture_context *tctx,
237 torture_comment(tctx, "Testing smbc_opendir(%s)\n", fname);
239 handle = smbc_opendir(fname);
240 if (!expect_success) {
244 torture_fail(tctx, talloc_asprintf(tctx, "failed to obain file handle for '%s'", fname));
247 ret = smbc_closedir(handle);
248 torture_assert_int_equal(tctx, ret, 0,
249 talloc_asprintf(tctx, "failed to close file handle for '%s'", fname));
254 static bool torture_libsmbclient_opendir(struct torture_context *tctx)
259 const char *bad_urls[] = {
275 const char *good_urls[] = {
281 torture_assert(tctx, torture_libsmbclient_init_context(tctx, &ctx), "");
282 smbc_set_context(ctx);
284 for (i=0; i < ARRAY_SIZE(bad_urls); i++) {
285 ret &= test_opendir(tctx, ctx, bad_urls[i], false);
287 for (i=0; i < ARRAY_SIZE(good_urls); i++) {
288 ret &= test_opendir(tctx, ctx, good_urls[i], true);
291 smbc_free_context(ctx, 1);
296 static bool torture_libsmbclient_readdirplus(struct torture_context *tctx)
303 const char *filename = NULL;
304 const char *smburl = torture_setting_string(tctx, "smburl", NULL);
306 if (smburl == NULL) {
308 "option --option=torture:smburl="
309 "smb://user:password@server/share missing\n");
312 torture_assert(tctx, torture_libsmbclient_init_context(tctx, &ctx), "");
313 smbc_set_context(ctx);
315 filename = talloc_asprintf(tctx,
316 "%s/test_readdirplus.txt",
318 if (filename == NULL) {
322 /* Ensure the file doesn't exist. */
323 smbc_unlink(filename);
326 fhandle = smbc_creat(filename, 0666);
329 talloc_asprintf(tctx,
330 "failed to create file '%s': %s",
334 ret = smbc_close(fhandle);
335 torture_assert_int_equal(tctx,
338 talloc_asprintf(tctx,
339 "failed to close handle for '%s'",
342 dhandle = smbc_opendir(smburl);
344 int saved_errno = errno;
345 smbc_unlink(filename);
347 talloc_asprintf(tctx,
349 "directory handle for '%s' : %s",
351 strerror(saved_errno)));
354 /* Readdirplus to ensure we see the new file. */
356 const struct libsmb_file_info *exstat =
357 smbc_readdirplus(dhandle);
358 if (exstat == NULL) {
361 if (strcmp(exstat->name, "test_readdirplus.txt") == 0) {
367 /* Remove it again. */
368 smbc_unlink(filename);
369 ret = smbc_closedir(dhandle);
370 torture_assert_int_equal(tctx,
373 talloc_asprintf(tctx,
374 "failed to close directory handle for '%s'",
377 smbc_free_context(ctx, 1);
381 talloc_asprintf(tctx,
382 "failed to find file '%s'",
389 static bool torture_libsmbclient_readdirplus_seek(struct torture_context *tctx)
395 const char *dname = NULL;
396 const char *full_filename[100] = {0};
397 const char *filename[100] = {0};
398 const struct libsmb_file_info *direntries[102] = {0};
400 const char *smburl = torture_setting_string(tctx, "smburl", NULL);
401 bool success = false;
402 off_t telldir_50 = (off_t)-1;
403 off_t telldir_20 = (off_t)-1;
404 size_t getdentries_size = 0;
405 struct smbc_dirent *getdentries = NULL;
406 struct smbc_dirent *dirent_20 = NULL;
407 const struct libsmb_file_info *direntries_20 = NULL;
408 const struct libsmb_file_info *direntriesplus_20 = NULL;
409 const char *plus2_stat_path = NULL;
410 struct stat st = {0};
411 struct stat st2 = {0};
413 if (smburl == NULL) {
415 "option --option=torture:smburl="
416 "smb://user:password@server/share missing\n");
419 DEBUG(0,("torture_libsmbclient_readdirplus_seek start\n"));
421 torture_assert(tctx, torture_libsmbclient_init_context(tctx, &ctx), "");
422 smbc_set_context(ctx);
424 dname = talloc_asprintf(tctx,
428 torture_fail_goto(tctx,
433 /* Ensure the files don't exist. */
434 for (i = 0; i < 100; i++) {
435 filename[i] = talloc_asprintf(tctx,
436 "test_readdirplus_%u.txt",
438 if (filename[i] == NULL) {
439 torture_fail_goto(tctx,
443 full_filename[i] = talloc_asprintf(tctx,
447 if (full_filename[i] == NULL) {
448 torture_fail_goto(tctx,
452 (void)smbc_unlink(full_filename[i]);
454 /* Ensure the directory doesn't exist. */
455 (void)smbc_rmdir(dname);
457 /* Create containing directory. */
458 ret = smbc_mkdir(dname, 0777);
460 torture_fail_goto(tctx,
462 talloc_asprintf(tctx,
463 "failed to create directory '%s': %s",
468 DEBUG(0,("torture_libsmbclient_readdirplus_seek create\n"));
471 for (i = 0; i < 100; i++) {
472 fhandle = smbc_creat(full_filename[i], 0666);
474 torture_fail_goto(tctx,
476 talloc_asprintf(tctx,
477 "failed to create file '%s': %s",
481 ret = smbc_close(fhandle);
482 torture_assert_int_equal_goto(tctx,
487 talloc_asprintf(tctx,
488 "failed to close handle for '%s'",
492 DEBUG(0,("torture_libsmbclient_readdirplus_seek enum\n"));
494 /* Now enumerate the directory. */
495 dhandle = smbc_opendir(dname);
497 torture_fail_goto(tctx,
499 talloc_asprintf(tctx,
501 "directory handle for '%s' : %s",
506 /* Read all the files. 100 we created plus . and .. */
507 for (i = 0; i < 102; i++) {
511 direntries[i] = smbc_readdirplus(dhandle);
512 if (direntries[i] == NULL) {
516 /* Store at offset 50. */
518 telldir_50 = smbc_telldir(dhandle);
519 if (telldir_50 == (off_t)-1) {
520 torture_fail_goto(tctx,
522 talloc_asprintf(tctx,
523 "telldir failed file %s\n",
524 direntries[i]->name));
528 if (ISDOT(direntries[i]->name)) {
531 if (ISDOTDOT(direntries[i]->name)) {
535 /* Ensure all our files exist. */
536 for (j = 0; j < 100; j++) {
537 if (strcmp(direntries[i]->name,
543 torture_fail_goto(tctx,
545 talloc_asprintf(tctx,
546 "failed to find file %s\n",
547 direntries[i]->name));
552 * We're seeking on in-memory lists here, so
553 * whilst the handle is open we really should
554 * get the same files back in the same order.
557 ret = smbc_lseekdir(dhandle, telldir_50);
558 torture_assert_int_equal_goto(tctx,
563 talloc_asprintf(tctx,
564 "failed to seek (50) directory handle for '%s'",
567 DEBUG(0,("torture_libsmbclient_readdirplus_seek seek\n"));
569 for (i = 51; i < 102; i++) {
570 const struct libsmb_file_info *entry =
571 smbc_readdirplus(dhandle);
572 if (entry != direntries[i]) {
573 torture_fail_goto(tctx,
575 talloc_asprintf(tctx,
576 "after seek - failed to find "
577 "file %s - got %s\n",
583 /* Seek back to the start. */
584 ret = smbc_lseekdir(dhandle, 0);
585 torture_assert_int_equal_goto(tctx,
590 talloc_asprintf(tctx,
591 "failed to seek directory handle to start for '%s'",
595 * Mix getdents/readdir/readdirplus with lseek to ensure
596 * we get the same result.
599 /* Allocate the space for 20 entries.
600 * Tricky as we need to allocate 20 struct smbc_dirent's + space
601 * for the name lengths.
603 getdentries_size = 20 * (sizeof(struct smbc_dirent) +
604 strlen("test_readdirplus_1000.txt") + 1);
606 getdentries = (struct smbc_dirent *)talloc_array_size(tctx,
610 ret = smbc_getdents(dhandle, getdentries, getdentries_size);
611 torture_assert_goto(tctx,
615 talloc_asprintf(tctx,
616 "smbd_getdents(1) for '%s' failed\n",
619 telldir_20 = smbc_telldir(dhandle);
620 if (telldir_20 == (off_t)-1) {
621 torture_fail_goto(tctx,
623 talloc_asprintf(tctx,
624 "telldir (20) failed\n"));
626 /* Read another 20. */
627 ret = smbc_getdents(dhandle, getdentries, getdentries_size);
628 torture_assert_goto(tctx,
632 talloc_asprintf(tctx,
633 "smbd_getdents(2) for '%s' failed\n",
636 /* Seek back to 20. */
637 ret = smbc_lseekdir(dhandle, telldir_20);
638 torture_assert_int_equal_goto(tctx,
643 talloc_asprintf(tctx,
644 "failed to seek (20) directory handle for '%s'",
647 /* Read with readdir. */
648 dirent_20 = smbc_readdir(dhandle);
649 if (dirent_20 == NULL) {
650 torture_fail_goto(tctx,
652 talloc_asprintf(tctx,
653 "smbc_readdir (20) failed\n"));
656 /* Ensure the getdents and readdir names are the same. */
657 ret = strcmp(dirent_20->name, getdentries[0].name);
659 torture_fail_goto(tctx,
661 talloc_asprintf(tctx,
662 "after seek (20) readdir name missmatch "
663 "file %s - got %s\n",
665 getdentries[0].name));
668 /* Seek back to 20. */
669 ret = smbc_lseekdir(dhandle, telldir_20);
670 torture_assert_int_equal_goto(tctx,
675 talloc_asprintf(tctx,
676 "failed to seek (20) directory handle for '%s'",
678 /* Read with readdirplus. */
679 direntries_20 = smbc_readdirplus(dhandle);
680 if (direntries_20 == NULL) {
681 torture_fail_goto(tctx,
683 talloc_asprintf(tctx,
684 "smbc_readdirplus (20) failed\n"));
687 /* Ensure the readdirplus and readdir names are the same. */
688 ret = strcmp(dirent_20->name, direntries_20->name);
690 torture_fail_goto(tctx,
692 talloc_asprintf(tctx,
693 "after seek (20) readdirplus name missmatch "
694 "file %s - got %s\n",
696 direntries_20->name));
699 /* Seek back to 20. */
700 ret = smbc_lseekdir(dhandle, telldir_20);
701 torture_assert_int_equal_goto(tctx,
706 talloc_asprintf(tctx,
707 "failed to seek (20) directory handle for '%s'",
710 /* Read with readdirplus2. */
711 direntriesplus_20 = smbc_readdirplus2(dhandle, &st2);
712 if (direntriesplus_20 == NULL) {
713 torture_fail_goto(tctx,
715 talloc_asprintf(tctx,
716 "smbc_readdirplus2 (20) failed\n"));
719 /* Ensure the readdirplus2 and readdirplus names are the same. */
720 ret = strcmp(direntries_20->name, direntriesplus_20->name);
722 torture_fail_goto(tctx,
724 talloc_asprintf(tctx,
725 "after seek (20) readdirplus2 name missmatch "
726 "file %s - got %s\n",
728 direntries_20->name));
731 /* Ensure doing stat gets the same data. */
732 plus2_stat_path = talloc_asprintf(tctx,
735 direntriesplus_20->name);
736 if (plus2_stat_path == NULL) {
737 torture_fail_goto(tctx,
742 ret = smbc_stat(plus2_stat_path, &st);
743 torture_assert_int_equal_goto(tctx,
748 talloc_asprintf(tctx,
749 "failed to stat file '%s'",
752 torture_assert_int_equal(tctx,
755 talloc_asprintf(tctx,
756 "file %s mismatched ino value "
757 "stat got %"PRIx64" readdirplus2 got %"PRIx64"" ,
760 (uint64_t)st2.st_ino));
762 torture_assert_int_equal(tctx,
765 talloc_asprintf(tctx,
766 "file %s mismatched dev value "
767 "stat got %"PRIx64" readdirplus2 got %"PRIx64"" ,
770 (uint64_t)st2.st_dev));
772 ret = smbc_closedir(dhandle);
773 torture_assert_int_equal(tctx,
776 talloc_asprintf(tctx,
777 "failed to close directory handle for '%s'",
787 smbc_closedir(dhandle);
789 for (i = 0; i < 100; i++) {
790 if (full_filename[i] != NULL) {
791 smbc_unlink(full_filename[i]);
798 smbc_free_context(ctx, 1);
803 #ifndef SMBC_FILE_MODE
804 #define SMBC_FILE_MODE (S_IFREG | 0444)
807 static bool torture_libsmbclient_readdirplus2(struct torture_context *tctx)
813 bool success = false;
814 const char *filename = NULL;
815 struct stat st2 = {0};
816 struct stat st = {0};
818 const char *smburl = torture_setting_string(tctx, "smburl", NULL);
820 if (smburl == NULL) {
822 "option --option=torture:smburl="
823 "smb://user:password@server/share missing\n");
826 torture_assert_goto(tctx, torture_libsmbclient_init_context(tctx, &ctx), success, done, "");
827 smbc_set_context(ctx);
829 filename = talloc_asprintf(tctx,
830 "%s/test_readdirplus.txt",
832 if (filename == NULL) {
833 torture_fail_goto(tctx, done, "talloc fail\n");
836 /* Ensure the file doesn't exist. */
837 smbc_unlink(filename);
840 fhandle = smbc_creat(filename, 0666);
842 torture_fail_goto(tctx,
844 talloc_asprintf(tctx,
845 "failed to create file '%s': %s",
849 ret = smbc_close(fhandle);
850 torture_assert_int_equal_goto(tctx,
855 talloc_asprintf(tctx,
856 "failed to close handle for '%s'",
859 dhandle = smbc_opendir(smburl);
861 int saved_errno = errno;
862 smbc_unlink(filename);
863 torture_fail_goto(tctx,
865 talloc_asprintf(tctx,
867 "directory handle for '%s' : %s",
869 strerror(saved_errno)));
872 /* readdirplus2 to ensure we see the new file. */
874 const struct libsmb_file_info *exstat =
875 smbc_readdirplus2(dhandle, &st2);
876 if (exstat == NULL) {
880 if (strcmp(exstat->name, "test_readdirplus.txt") == 0) {
887 smbc_unlink(filename);
888 torture_fail_goto(tctx,
890 talloc_asprintf(tctx,
891 "failed to find file '%s'",
895 /* Ensure mode is as expected. */
897 * New file gets SMBC_FILE_MODE plus
898 * archive bit -> S_IXUSR
899 * !READONLY -> S_IWUSR.
901 torture_assert_int_equal_goto(tctx,
903 SMBC_FILE_MODE|S_IXUSR|S_IWUSR,
906 talloc_asprintf(tctx,
907 "file %s st_mode should be 0%o, got 0%o'",
909 SMBC_FILE_MODE|S_IXUSR|S_IWUSR,
910 (unsigned int)st2.st_mode));
912 /* Ensure smbc_stat() gets the same data. */
913 ret = smbc_stat(filename, &st);
914 torture_assert_int_equal_goto(tctx,
919 talloc_asprintf(tctx,
920 "failed to stat file '%s'",
923 torture_assert_int_equal_goto(tctx,
928 talloc_asprintf(tctx,
929 "filename '%s' ino missmatch. "
930 "From smbc_readdirplus2 = %"PRIx64" "
931 "From smbc_stat = %"PRIx64"",
933 (uint64_t)st2.st_ino,
934 (uint64_t)st.st_ino));
937 /* Remove it again. */
938 smbc_unlink(filename);
939 ret = smbc_closedir(dhandle);
940 torture_assert_int_equal_goto(tctx,
945 talloc_asprintf(tctx,
946 "failed to close directory handle for '%s'",
951 smbc_free_context(ctx, 1);
955 bool torture_libsmbclient_configuration(struct torture_context *tctx)
960 ctx = smbc_new_context();
961 torture_assert(tctx, ctx, "failed to get new context");
962 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
964 torture_comment(tctx, "Testing smbc_(set|get)Debug\n");
965 smbc_setDebug(ctx, DEBUGLEVEL);
966 torture_assert_int_equal_goto(tctx,
971 "failed to set DEBUGLEVEL");
973 torture_comment(tctx, "Testing smbc_(set|get)NetbiosName\n");
974 smbc_setNetbiosName(ctx, discard_const("torture_netbios"));
975 torture_assert_str_equal_goto(tctx,
976 smbc_getNetbiosName(ctx),
980 "failed to set NetbiosName");
982 torture_comment(tctx, "Testing smbc_(set|get)Workgroup\n");
983 smbc_setWorkgroup(ctx, discard_const("torture_workgroup"));
984 torture_assert_str_equal_goto(tctx,
985 smbc_getWorkgroup(ctx),
989 "failed to set Workgroup");
991 torture_comment(tctx, "Testing smbc_(set|get)User\n");
992 smbc_setUser(ctx, "torture_user");
993 torture_assert_str_equal_goto(tctx,
998 "failed to set User");
1000 torture_comment(tctx, "Testing smbc_(set|get)Timeout\n");
1001 smbc_setTimeout(ctx, 12345);
1002 torture_assert_int_equal_goto(tctx,
1003 smbc_getTimeout(ctx),
1007 "failed to set Timeout");
1010 smbc_free_context(ctx, 1);
1015 bool torture_libsmbclient_options(struct torture_context *tctx)
1020 ctx = smbc_new_context();
1021 torture_assert(tctx, ctx, "failed to get new context");
1022 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
1024 torture_comment(tctx, "Testing smbc_(set|get)OptionDebugToStderr\n");
1025 smbc_setOptionDebugToStderr(ctx, true);
1026 torture_assert_goto(tctx,
1027 smbc_getOptionDebugToStderr(ctx),
1030 "failed to set OptionDebugToStderr");
1032 torture_comment(tctx, "Testing smbc_(set|get)OptionFullTimeNames\n");
1033 smbc_setOptionFullTimeNames(ctx, true);
1034 torture_assert_goto(tctx,
1035 smbc_getOptionFullTimeNames(ctx),
1038 "failed to set OptionFullTimeNames");
1040 torture_comment(tctx, "Testing smbc_(set|get)OptionOpenShareMode\n");
1041 smbc_setOptionOpenShareMode(ctx, SMBC_SHAREMODE_DENY_ALL);
1042 torture_assert_int_equal_goto(tctx,
1043 smbc_getOptionOpenShareMode(ctx),
1044 SMBC_SHAREMODE_DENY_ALL,
1047 "failed to set OptionOpenShareMode");
1049 torture_comment(tctx, "Testing smbc_(set|get)OptionUserData\n");
1050 smbc_setOptionUserData(ctx, (void *)discard_const("torture_user_data"));
1051 torture_assert_str_equal_goto(tctx,
1052 (const char*)smbc_getOptionUserData(ctx),
1053 "torture_user_data",
1056 "failed to set OptionUserData");
1058 torture_comment(tctx,
1059 "Testing smbc_(set|get)OptionSmbEncryptionLevel\n");
1060 smbc_setOptionSmbEncryptionLevel(ctx, SMBC_ENCRYPTLEVEL_REQUEST);
1061 torture_assert_int_equal_goto(tctx,
1062 smbc_getOptionSmbEncryptionLevel(ctx),
1063 SMBC_ENCRYPTLEVEL_REQUEST,
1066 "failed to set OptionSmbEncryptionLevel");
1068 torture_comment(tctx, "Testing smbc_(set|get)OptionCaseSensitive\n");
1069 smbc_setOptionCaseSensitive(ctx, false);
1070 torture_assert_goto(tctx,
1071 !smbc_getOptionCaseSensitive(ctx),
1074 "failed to set OptionCaseSensitive");
1076 torture_comment(tctx,
1077 "Testing smbc_(set|get)OptionBrowseMaxLmbCount\n");
1078 smbc_setOptionBrowseMaxLmbCount(ctx, 2);
1079 torture_assert_int_equal_goto(tctx,
1080 smbc_getOptionBrowseMaxLmbCount(ctx),
1084 "failed to set OptionBrowseMaxLmbCount");
1086 torture_comment(tctx,
1087 "Testing smbc_(set|get)OptionUrlEncodeReaddirEntries\n");
1088 smbc_setOptionUrlEncodeReaddirEntries(ctx, true);
1089 torture_assert_goto(tctx,
1090 smbc_getOptionUrlEncodeReaddirEntries(ctx),
1093 "failed to set OptionUrlEncodeReaddirEntries");
1095 torture_comment(tctx,
1096 "Testing smbc_(set|get)OptionOneSharePerServer\n");
1097 smbc_setOptionOneSharePerServer(ctx, true);
1098 torture_assert_goto(tctx,
1099 smbc_getOptionOneSharePerServer(ctx),
1102 "failed to set OptionOneSharePerServer");
1104 torture_comment(tctx, "Testing smbc_(set|get)OptionUseKerberos\n");
1105 smbc_setOptionUseKerberos(ctx, false);
1106 torture_assert_goto(tctx,
1107 !smbc_getOptionUseKerberos(ctx),
1110 "failed to set OptionUseKerberos");
1112 torture_comment(tctx,
1113 "Testing smbc_(set|get)OptionFallbackAfterKerberos\n");
1114 smbc_setOptionFallbackAfterKerberos(ctx, false);
1115 torture_assert_goto(tctx,
1116 !smbc_getOptionFallbackAfterKerberos(ctx),
1119 "failed to set OptionFallbackAfterKerberos");
1121 torture_comment(tctx,
1122 "Testing smbc_(set|get)OptionNoAutoAnonymousLogin\n");
1123 smbc_setOptionNoAutoAnonymousLogin(ctx, true);
1124 torture_assert_goto(tctx,
1125 smbc_getOptionNoAutoAnonymousLogin(ctx),
1128 "failed to set OptionNoAutoAnonymousLogin");
1130 torture_comment(tctx, "Testing smbc_(set|get)OptionUseCCache\n");
1131 smbc_setOptionUseCCache(ctx, true);
1132 torture_assert_goto(tctx,
1133 smbc_getOptionUseCCache(ctx),
1136 "failed to set OptionUseCCache");
1139 smbc_free_context(ctx, 1);
1144 static bool torture_libsmbclient_list_shares(struct torture_context *tctx)
1146 const char *smburl = torture_setting_string(tctx, "smburl", NULL);
1147 struct smbc_dirent *dirent = NULL;
1148 SMBCCTX *ctx = NULL;
1150 bool ipc_share_found = false;
1153 if (smburl == NULL) {
1155 "option --option=torture:smburl="
1156 "smb://user:password@server missing\n");
1159 ok = torture_libsmbclient_init_context(tctx, &ctx);
1160 torture_assert_goto(tctx,
1164 "Failed to init context");
1165 smbc_set_context(ctx);
1167 torture_comment(tctx, "Listing: %s\n", smburl);
1168 dhandle = smbc_opendir(smburl);
1169 torture_assert_int_not_equal_goto(tctx,
1174 "Failed to open smburl");
1176 while((dirent = smbc_readdir(dhandle)) != NULL) {
1177 torture_comment(tctx, "DIR: %s\n", dirent->name);
1178 torture_assert_not_null_goto(tctx,
1182 "Failed to read name");
1184 if (strequal(dirent->name, "IPC$")) {
1185 ipc_share_found = true;
1189 torture_assert_goto(tctx,
1193 "Failed to list IPC$ share");
1196 smbc_closedir(dhandle);
1200 NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
1202 struct torture_suite *suite;
1204 suite = torture_suite_create(ctx, "libsmbclient");
1206 torture_suite_add_simple_test(suite, "version", torture_libsmbclient_version);
1207 torture_suite_add_simple_test(suite, "initialize", torture_libsmbclient_initialize);
1208 torture_suite_add_simple_test(suite, "configuration", torture_libsmbclient_configuration);
1209 torture_suite_add_simple_test(suite, "setConfiguration", torture_libsmbclient_setConfiguration);
1210 torture_suite_add_simple_test(suite, "options", torture_libsmbclient_options);
1211 torture_suite_add_simple_test(suite, "opendir", torture_libsmbclient_opendir);
1212 torture_suite_add_simple_test(suite, "list_shares", torture_libsmbclient_list_shares);
1213 torture_suite_add_simple_test(suite, "readdirplus",
1214 torture_libsmbclient_readdirplus);
1215 torture_suite_add_simple_test(suite, "readdirplus_seek",
1216 torture_libsmbclient_readdirplus_seek);
1217 torture_suite_add_simple_test(suite, "readdirplus2",
1218 torture_libsmbclient_readdirplus2);
1220 suite->description = talloc_strdup(suite, "libsmbclient interface tests");
1222 torture_register_suite(ctx, suite);
1224 return NT_STATUS_OK;