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"
30 #include "lib/util/time.h"
32 /* test string to compare with when debug_callback is called */
33 #define TEST_STRING "smbc_setLogCallback test"
35 /* Dummy log callback function */
36 static void debug_callback(void *private_ptr, int level, const char *msg)
38 bool *found = private_ptr;
39 if (strstr(msg, TEST_STRING) != NULL) {
45 static void auth_callback(const char *srv,
51 const char *workgroup =
52 cli_credentials_get_domain(popt_get_cmdline_credentials());
53 const char *username =
54 cli_credentials_get_username(popt_get_cmdline_credentials());
55 const char *password =
56 cli_credentials_get_password(popt_get_cmdline_credentials());
59 if (workgroup != NULL) {
60 ret = strlcpy(wg, workgroup, wglen);
66 if (username != NULL) {
67 ret = strlcpy(un, username, unlen);
73 if (password != NULL) {
74 ret = strlcpy(pw, password, pwlen);
81 bool torture_libsmbclient_init_context(struct torture_context *tctx,
84 const char *workgroup =
85 cli_credentials_get_domain(popt_get_cmdline_credentials());
86 const char *username =
87 cli_credentials_get_username(popt_get_cmdline_credentials());
88 const char *client_proto =
89 torture_setting_string(tctx, "clientprotocol", NULL);
93 int dbglevel = DEBUGLEVEL;
95 ctx = smbc_new_context();
96 torture_assert_not_null_goto(tctx,
100 "Failed to create new context");
102 p = smbc_init_context(ctx);
103 torture_assert_not_null_goto(tctx,
107 "Failed to initialize context");
109 smbc_setDebug(ctx, dbglevel);
110 smbc_setOptionDebugToStderr(ctx, 1);
112 if (workgroup != NULL) {
113 smbc_setWorkgroup(ctx, workgroup);
115 if (username != NULL) {
116 smbc_setUser(ctx, username);
119 smbc_setFunctionAuthData(ctx, auth_callback);
121 if (client_proto != NULL) {
122 smbc_setOptionProtocols(ctx, client_proto, client_proto);
129 smbc_free_context(ctx, 1);
135 static bool torture_libsmbclient_version(struct torture_context *tctx)
137 torture_comment(tctx, "Testing smbc_version\n");
139 torture_assert(tctx, smbc_version(), "failed to get version");
144 static bool torture_libsmbclient_initialize(struct torture_context *tctx)
149 torture_comment(tctx, "Testing smbc_new_context\n");
151 ctx = smbc_new_context();
152 torture_assert(tctx, ctx, "failed to get new context");
154 torture_comment(tctx, "Testing smbc_init_context\n");
156 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
158 smbc_setLogCallback(ctx, &ret, debug_callback);
159 DEBUG(0, (TEST_STRING"\n"));
160 torture_assert(tctx, ret, "Failed debug_callback not called");
162 smbc_setLogCallback(ctx, NULL, NULL);
163 DEBUG(0, (TEST_STRING"\n"));
164 torture_assert(tctx, !ret, "Failed debug_callback called");
166 smbc_free_context(ctx, 1);
171 static bool torture_libsmbclient_setConfiguration(struct torture_context *tctx)
174 struct loadparm_global *global_config = NULL;
175 const char *new_smb_conf = torture_setting_string(tctx,
179 ctx = smbc_new_context();
180 torture_assert_not_null(tctx, ctx, "failed to get new context");
182 torture_assert_not_null(
183 tctx, smbc_init_context(ctx), "failed to init context");
185 torture_comment(tctx, "Testing smbc_setConfiguration - new file %s\n",
188 global_config = get_globals();
189 torture_assert(tctx, global_config, "Global Config is NULL");
191 /* check configuration before smbc_setConfiguration call */
192 torture_comment(tctx, "'workgroup' before setConfiguration %s\n",
193 global_config->workgroup);
194 torture_comment(tctx, "'client min protocol' before "
195 "setConfiguration %d\n",
196 global_config->client_min_protocol);
197 torture_comment(tctx, "'client max protocol' before "
198 "setConfiguration %d\n",
199 global_config->_client_max_protocol);
200 torture_comment(tctx, "'client signing' before setConfiguration %d\n",
201 global_config->client_signing);
202 torture_comment(tctx, "'deadtime' before setConfiguration %d\n",
203 global_config->deadtime);
205 torture_assert_int_equal(tctx, smbc_setConfiguration(ctx, new_smb_conf),
206 0, "setConfiguration conf file not found");
208 /* verify configuration */
209 torture_assert_str_equal(tctx, global_config->workgroup,
211 "smbc_setConfiguration failed, "
212 "'workgroup' not updated");
213 torture_assert_int_equal(tctx, global_config->client_min_protocol, 7,
214 "smbc_setConfiguration failed, 'client min protocol' "
216 torture_assert_int_equal(tctx, global_config->_client_max_protocol, 13,
217 "smbc_setConfiguration failed, 'client max protocol' "
219 torture_assert_int_equal(tctx, global_config->client_signing, 1,
220 "smbc_setConfiguration failed, 'client signing' "
222 torture_assert_int_equal(tctx, global_config->deadtime, 5,
223 "smbc_setConfiguration failed, 'deadtime' not updated");
225 /* Restore configuration to default */
226 smbc_setConfiguration(ctx, get_dyn_CONFIGFILE());
228 smbc_free_context(ctx, 1);
233 static bool test_opendir(struct torture_context *tctx,
240 torture_comment(tctx, "Testing smbc_opendir(%s)\n", fname);
242 handle = smbc_opendir(fname);
243 if (!expect_success) {
247 torture_fail(tctx, talloc_asprintf(tctx, "failed to obain file handle for '%s'", fname));
250 ret = smbc_closedir(handle);
251 torture_assert_int_equal(tctx, ret, 0,
252 talloc_asprintf(tctx, "failed to close file handle for '%s'", fname));
257 static bool torture_libsmbclient_opendir(struct torture_context *tctx)
262 const char *bad_urls[] = {
278 const char *good_urls[] = {
284 torture_assert(tctx, torture_libsmbclient_init_context(tctx, &ctx), "");
285 smbc_set_context(ctx);
287 for (i=0; i < ARRAY_SIZE(bad_urls); i++) {
288 ret &= test_opendir(tctx, ctx, bad_urls[i], false);
290 for (i=0; i < ARRAY_SIZE(good_urls); i++) {
291 ret &= test_opendir(tctx, ctx, good_urls[i], true);
294 smbc_free_context(ctx, 1);
299 static bool torture_libsmbclient_readdirplus(struct torture_context *tctx)
306 const char *filename = NULL;
307 const char *smburl = torture_setting_string(tctx, "smburl", NULL);
309 if (smburl == NULL) {
311 "option --option=torture:smburl="
312 "smb://user:password@server/share missing\n");
315 torture_assert(tctx, torture_libsmbclient_init_context(tctx, &ctx), "");
316 smbc_set_context(ctx);
318 filename = talloc_asprintf(tctx,
319 "%s/test_readdirplus.txt",
321 if (filename == NULL) {
325 /* Ensure the file doesn't exist. */
326 smbc_unlink(filename);
329 fhandle = smbc_creat(filename, 0666);
332 talloc_asprintf(tctx,
333 "failed to create file '%s': %s",
337 ret = smbc_close(fhandle);
338 torture_assert_int_equal(tctx,
341 talloc_asprintf(tctx,
342 "failed to close handle for '%s'",
345 dhandle = smbc_opendir(smburl);
347 int saved_errno = errno;
348 smbc_unlink(filename);
350 talloc_asprintf(tctx,
352 "directory handle for '%s' : %s",
354 strerror(saved_errno)));
357 /* Readdirplus to ensure we see the new file. */
359 const struct libsmb_file_info *exstat =
360 smbc_readdirplus(dhandle);
361 if (exstat == NULL) {
364 if (strcmp(exstat->name, "test_readdirplus.txt") == 0) {
370 /* Remove it again. */
371 smbc_unlink(filename);
372 ret = smbc_closedir(dhandle);
373 torture_assert_int_equal(tctx,
376 talloc_asprintf(tctx,
377 "failed to close directory handle for '%s'",
380 smbc_free_context(ctx, 1);
384 talloc_asprintf(tctx,
385 "failed to find file '%s'",
392 static bool torture_libsmbclient_readdirplus_seek(struct torture_context *tctx)
398 const char *dname = NULL;
399 const char *full_filename[100] = {0};
400 const char *filename[100] = {0};
401 const struct libsmb_file_info *direntries[102] = {0};
403 const char *smburl = torture_setting_string(tctx, "smburl", NULL);
404 bool success = false;
405 off_t telldir_50 = (off_t)-1;
406 off_t telldir_20 = (off_t)-1;
407 size_t getdentries_size = 0;
408 struct smbc_dirent *getdentries = NULL;
409 struct smbc_dirent *dirent_20 = NULL;
410 const struct libsmb_file_info *direntries_20 = NULL;
411 const struct libsmb_file_info *direntriesplus_20 = NULL;
412 const char *plus2_stat_path = NULL;
413 struct stat st = {0};
414 struct stat st2 = {0};
416 torture_assert_not_null(
419 "option --option=torture:smburl="
420 "smb://user:password@server/share missing\n");
422 DEBUG(0,("torture_libsmbclient_readdirplus_seek start\n"));
424 torture_assert(tctx, torture_libsmbclient_init_context(tctx, &ctx), "");
425 smbc_set_context(ctx);
427 dname = talloc_asprintf(tctx,
430 torture_assert_not_null_goto(
431 tctx, dname, success, done, "talloc fail\n");
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 torture_assert_not_null_goto(
439 tctx, filename[i], success, done, "talloc fail");
440 full_filename[i] = talloc_asprintf(tctx,
444 torture_assert_not_null_goto(
445 tctx, full_filename[i], success, done, "talloc fail");
446 (void)smbc_unlink(full_filename[i]);
448 /* Ensure the directory doesn't exist. */
449 (void)smbc_rmdir(dname);
451 /* Create containing directory. */
452 ret = smbc_mkdir(dname, 0777);
458 talloc_asprintf(tctx,
459 "failed to create directory '%s': %s",
463 DEBUG(0,("torture_libsmbclient_readdirplus_seek create\n"));
466 for (i = 0; i < 100; i++) {
467 fhandle = smbc_creat(full_filename[i], 0666);
469 torture_fail_goto(tctx,
471 talloc_asprintf(tctx,
472 "failed to create file '%s': %s",
476 ret = smbc_close(fhandle);
477 torture_assert_int_equal_goto(tctx,
482 talloc_asprintf(tctx,
483 "failed to close handle for '%s'",
487 DEBUG(0,("torture_libsmbclient_readdirplus_seek enum\n"));
489 /* Now enumerate the directory. */
490 dhandle = smbc_opendir(dname);
496 talloc_asprintf(tctx,
498 "directory handle for '%s' : %s",
502 /* Read all the files. 100 we created plus . and .. */
503 for (i = 0; i < 102; i++) {
507 direntries[i] = smbc_readdirplus(dhandle);
508 if (direntries[i] == NULL) {
512 /* Store at offset 50. */
514 telldir_50 = smbc_telldir(dhandle);
517 telldir_50 != (off_t)-1,
520 talloc_asprintf(tctx,
521 "telldir failed file %s\n",
522 direntries[i]->name));
525 if (ISDOT(direntries[i]->name)) {
528 if (ISDOTDOT(direntries[i]->name)) {
532 /* Ensure all our files exist. */
533 for (j = 0; j < 100; j++) {
534 if (strcmp(direntries[i]->name,
544 talloc_asprintf(tctx,
545 "failed to find file %s\n",
546 direntries[i]->name));
550 * We're seeking on in-memory lists here, so
551 * whilst the handle is open we really should
552 * get the same files back in the same order.
555 ret = smbc_lseekdir(dhandle, telldir_50);
556 torture_assert_int_equal_goto(tctx,
561 talloc_asprintf(tctx,
562 "failed to seek (50) directory handle for '%s'",
565 DEBUG(0,("torture_libsmbclient_readdirplus_seek seek\n"));
567 for (i = 51; i < 102; i++) {
568 const struct libsmb_file_info *entry =
569 smbc_readdirplus(dhandle);
572 entry == direntries[i],
575 talloc_asprintf(tctx,
576 "after seek - failed to find "
577 "file %s - got %s\n",
582 /* Seek back to the start. */
583 ret = smbc_lseekdir(dhandle, 0);
584 torture_assert_int_equal_goto(tctx,
589 talloc_asprintf(tctx,
590 "failed to seek directory handle to start for '%s'",
594 * Mix getdents/readdir/readdirplus with lseek to ensure
595 * we get the same result.
598 /* Allocate the space for 20 entries.
599 * Tricky as we need to allocate 20 struct smbc_dirent's + space
600 * for the name lengths.
602 getdentries_size = 20 * (sizeof(struct smbc_dirent) +
603 strlen("test_readdirplus_1000.txt") + 1);
605 getdentries = (struct smbc_dirent *)talloc_array_size(tctx,
608 torture_assert_not_null_goto(
615 ret = smbc_getdents(dhandle, getdentries, getdentries_size);
616 torture_assert_goto(tctx,
620 talloc_asprintf(tctx,
621 "smbd_getdents(1) for '%s' failed\n",
624 telldir_20 = smbc_telldir(dhandle);
627 telldir_20 != (off_t)-1,
630 "telldir (20) failed\n");
632 /* Read another 20. */
633 ret = smbc_getdents(dhandle, getdentries, getdentries_size);
634 torture_assert_goto(tctx,
638 talloc_asprintf(tctx,
639 "smbd_getdents(2) for '%s' failed\n",
642 /* Seek back to 20. */
643 ret = smbc_lseekdir(dhandle, telldir_20);
644 torture_assert_int_equal_goto(tctx,
649 talloc_asprintf(tctx,
650 "failed to seek (20) directory handle for '%s'",
653 /* Read with readdir. */
654 dirent_20 = smbc_readdir(dhandle);
655 torture_assert_not_null_goto(
660 "smbc_readdir (20) failed\n");
662 /* Ensure the getdents and readdir names are the same. */
663 ret = strcmp(dirent_20->name, getdentries[0].name);
669 talloc_asprintf(tctx,
670 "after seek (20) readdir name missmatch "
671 "file %s - got %s\n",
673 getdentries[0].name));
675 /* Seek back to 20. */
676 ret = smbc_lseekdir(dhandle, telldir_20);
677 torture_assert_int_equal_goto(tctx,
682 talloc_asprintf(tctx,
683 "failed to seek (20) directory handle for '%s'",
685 /* Read with readdirplus. */
686 direntries_20 = smbc_readdirplus(dhandle);
687 torture_assert_not_null_goto(
692 "smbc_readdirplus (20) failed\n");
694 /* Ensure the readdirplus and readdir names are the same. */
695 ret = strcmp(dirent_20->name, direntries_20->name);
701 talloc_asprintf(tctx,
702 "after seek (20) readdirplus name missmatch "
703 "file %s - got %s\n",
705 direntries_20->name));
707 /* Seek back to 20. */
708 ret = smbc_lseekdir(dhandle, telldir_20);
709 torture_assert_int_equal_goto(tctx,
714 talloc_asprintf(tctx,
715 "failed to seek (20) directory handle for '%s'",
718 /* Read with readdirplus2. */
719 direntriesplus_20 = smbc_readdirplus2(dhandle, &st2);
720 torture_assert_not_null_goto(
725 "smbc_readdirplus2 (20) failed\n");
727 /* Ensure the readdirplus2 and readdirplus names are the same. */
728 ret = strcmp(direntries_20->name, direntriesplus_20->name);
734 talloc_asprintf(tctx,
735 "after seek (20) readdirplus2 name missmatch "
736 "file %s - got %s\n",
738 direntries_20->name));
740 /* Ensure doing stat gets the same data. */
741 plus2_stat_path = talloc_asprintf(tctx,
744 direntriesplus_20->name);
745 torture_assert_not_null_goto(
752 ret = smbc_stat(plus2_stat_path, &st);
753 torture_assert_int_equal_goto(tctx,
758 talloc_asprintf(tctx,
759 "failed to stat file '%s'",
762 torture_assert_int_equal(tctx,
765 talloc_asprintf(tctx,
766 "file %s mismatched ino value "
767 "stat got %"PRIx64" readdirplus2 got %"PRIx64"" ,
770 (uint64_t)st2.st_ino));
772 torture_assert_int_equal(tctx,
775 talloc_asprintf(tctx,
776 "file %s mismatched dev value "
777 "stat got %"PRIx64" readdirplus2 got %"PRIx64"" ,
780 (uint64_t)st2.st_dev));
782 ret = smbc_closedir(dhandle);
783 torture_assert_int_equal(tctx,
786 talloc_asprintf(tctx,
787 "failed to close directory handle for '%s'",
797 smbc_closedir(dhandle);
799 for (i = 0; i < 100; i++) {
800 if (full_filename[i] != NULL) {
801 smbc_unlink(full_filename[i]);
808 smbc_free_context(ctx, 1);
813 #ifndef SMBC_FILE_MODE
814 #define SMBC_FILE_MODE (S_IFREG | 0444)
817 static bool torture_libsmbclient_readdirplus2(struct torture_context *tctx)
823 bool success = false;
824 const char *filename = NULL;
825 struct stat st2 = {0};
826 struct stat st = {0};
828 const char *smburl = torture_setting_string(tctx, "smburl", NULL);
830 if (smburl == NULL) {
832 "option --option=torture:smburl="
833 "smb://user:password@server/share missing\n");
836 torture_assert_goto(tctx, torture_libsmbclient_init_context(tctx, &ctx), success, done, "");
837 smbc_set_context(ctx);
839 filename = talloc_asprintf(tctx,
840 "%s/test_readdirplus.txt",
842 if (filename == NULL) {
843 torture_fail_goto(tctx, done, "talloc fail\n");
846 /* Ensure the file doesn't exist. */
847 smbc_unlink(filename);
850 fhandle = smbc_creat(filename, 0666);
852 torture_fail_goto(tctx,
854 talloc_asprintf(tctx,
855 "failed to create file '%s': %s",
859 ret = smbc_close(fhandle);
860 torture_assert_int_equal_goto(tctx,
865 talloc_asprintf(tctx,
866 "failed to close handle for '%s'",
869 dhandle = smbc_opendir(smburl);
871 int saved_errno = errno;
872 smbc_unlink(filename);
873 torture_fail_goto(tctx,
875 talloc_asprintf(tctx,
877 "directory handle for '%s' : %s",
879 strerror(saved_errno)));
882 /* readdirplus2 to ensure we see the new file. */
884 const struct libsmb_file_info *exstat =
885 smbc_readdirplus2(dhandle, &st2);
886 if (exstat == NULL) {
890 if (strcmp(exstat->name, "test_readdirplus.txt") == 0) {
897 smbc_unlink(filename);
898 torture_fail_goto(tctx,
900 talloc_asprintf(tctx,
901 "failed to find file '%s'",
905 /* Ensure mode is as expected. */
907 * New file gets SMBC_FILE_MODE plus
908 * archive bit -> S_IXUSR
909 * !READONLY -> S_IWUSR.
911 torture_assert_int_equal_goto(tctx,
913 SMBC_FILE_MODE|S_IXUSR|S_IWUSR,
916 talloc_asprintf(tctx,
917 "file %s st_mode should be 0%o, got 0%o'",
919 SMBC_FILE_MODE|S_IXUSR|S_IWUSR,
920 (unsigned int)st2.st_mode));
922 /* Ensure smbc_stat() gets the same data. */
923 ret = smbc_stat(filename, &st);
924 torture_assert_int_equal_goto(tctx,
929 talloc_asprintf(tctx,
930 "failed to stat file '%s'",
933 torture_assert_int_equal_goto(tctx,
938 talloc_asprintf(tctx,
939 "filename '%s' ino missmatch. "
940 "From smbc_readdirplus2 = %"PRIx64" "
941 "From smbc_stat = %"PRIx64"",
943 (uint64_t)st2.st_ino,
944 (uint64_t)st.st_ino));
947 /* Remove it again. */
948 smbc_unlink(filename);
949 ret = smbc_closedir(dhandle);
950 torture_assert_int_equal_goto(tctx,
955 talloc_asprintf(tctx,
956 "failed to close directory handle for '%s'",
961 smbc_free_context(ctx, 1);
965 bool torture_libsmbclient_configuration(struct torture_context *tctx)
970 ctx = smbc_new_context();
971 torture_assert(tctx, ctx, "failed to get new context");
972 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
974 torture_comment(tctx, "Testing smbc_(set|get)Debug\n");
975 smbc_setDebug(ctx, DEBUGLEVEL);
976 torture_assert_int_equal_goto(tctx,
981 "failed to set DEBUGLEVEL");
983 torture_comment(tctx, "Testing smbc_(set|get)NetbiosName\n");
984 smbc_setNetbiosName(ctx, discard_const("torture_netbios"));
985 torture_assert_str_equal_goto(tctx,
986 smbc_getNetbiosName(ctx),
990 "failed to set NetbiosName");
992 torture_comment(tctx, "Testing smbc_(set|get)Workgroup\n");
993 smbc_setWorkgroup(ctx, discard_const("torture_workgroup"));
994 torture_assert_str_equal_goto(tctx,
995 smbc_getWorkgroup(ctx),
999 "failed to set Workgroup");
1001 torture_comment(tctx, "Testing smbc_(set|get)User\n");
1002 smbc_setUser(ctx, "torture_user");
1003 torture_assert_str_equal_goto(tctx,
1008 "failed to set User");
1010 torture_comment(tctx, "Testing smbc_(set|get)Timeout\n");
1011 smbc_setTimeout(ctx, 12345);
1012 torture_assert_int_equal_goto(tctx,
1013 smbc_getTimeout(ctx),
1017 "failed to set Timeout");
1020 smbc_free_context(ctx, 1);
1025 bool torture_libsmbclient_options(struct torture_context *tctx)
1030 ctx = smbc_new_context();
1031 torture_assert(tctx, ctx, "failed to get new context");
1032 torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
1034 torture_comment(tctx, "Testing smbc_(set|get)OptionDebugToStderr\n");
1035 smbc_setOptionDebugToStderr(ctx, true);
1036 torture_assert_goto(tctx,
1037 smbc_getOptionDebugToStderr(ctx),
1040 "failed to set OptionDebugToStderr");
1042 torture_comment(tctx, "Testing smbc_(set|get)OptionFullTimeNames\n");
1043 smbc_setOptionFullTimeNames(ctx, true);
1044 torture_assert_goto(tctx,
1045 smbc_getOptionFullTimeNames(ctx),
1048 "failed to set OptionFullTimeNames");
1050 torture_comment(tctx, "Testing smbc_(set|get)OptionOpenShareMode\n");
1051 smbc_setOptionOpenShareMode(ctx, SMBC_SHAREMODE_DENY_ALL);
1052 torture_assert_int_equal_goto(tctx,
1053 smbc_getOptionOpenShareMode(ctx),
1054 SMBC_SHAREMODE_DENY_ALL,
1057 "failed to set OptionOpenShareMode");
1059 torture_comment(tctx, "Testing smbc_(set|get)OptionUserData\n");
1060 smbc_setOptionUserData(ctx, (void *)discard_const("torture_user_data"));
1061 torture_assert_str_equal_goto(tctx,
1062 (const char*)smbc_getOptionUserData(ctx),
1063 "torture_user_data",
1066 "failed to set OptionUserData");
1068 torture_comment(tctx,
1069 "Testing smbc_(set|get)OptionSmbEncryptionLevel\n");
1070 smbc_setOptionSmbEncryptionLevel(ctx, SMBC_ENCRYPTLEVEL_REQUEST);
1071 torture_assert_int_equal_goto(tctx,
1072 smbc_getOptionSmbEncryptionLevel(ctx),
1073 SMBC_ENCRYPTLEVEL_REQUEST,
1076 "failed to set OptionSmbEncryptionLevel");
1078 torture_comment(tctx, "Testing smbc_(set|get)OptionCaseSensitive\n");
1079 smbc_setOptionCaseSensitive(ctx, false);
1080 torture_assert_goto(tctx,
1081 !smbc_getOptionCaseSensitive(ctx),
1084 "failed to set OptionCaseSensitive");
1086 torture_comment(tctx,
1087 "Testing smbc_(set|get)OptionBrowseMaxLmbCount\n");
1088 smbc_setOptionBrowseMaxLmbCount(ctx, 2);
1089 torture_assert_int_equal_goto(tctx,
1090 smbc_getOptionBrowseMaxLmbCount(ctx),
1094 "failed to set OptionBrowseMaxLmbCount");
1096 torture_comment(tctx,
1097 "Testing smbc_(set|get)OptionUrlEncodeReaddirEntries\n");
1098 smbc_setOptionUrlEncodeReaddirEntries(ctx, true);
1099 torture_assert_goto(tctx,
1100 smbc_getOptionUrlEncodeReaddirEntries(ctx),
1103 "failed to set OptionUrlEncodeReaddirEntries");
1105 torture_comment(tctx,
1106 "Testing smbc_(set|get)OptionOneSharePerServer\n");
1107 smbc_setOptionOneSharePerServer(ctx, true);
1108 torture_assert_goto(tctx,
1109 smbc_getOptionOneSharePerServer(ctx),
1112 "failed to set OptionOneSharePerServer");
1114 torture_comment(tctx, "Testing smbc_(set|get)OptionUseKerberos\n");
1115 smbc_setOptionUseKerberos(ctx, false);
1116 torture_assert_goto(tctx,
1117 !smbc_getOptionUseKerberos(ctx),
1120 "failed to set OptionUseKerberos");
1122 torture_comment(tctx,
1123 "Testing smbc_(set|get)OptionFallbackAfterKerberos\n");
1124 smbc_setOptionFallbackAfterKerberos(ctx, false);
1125 torture_assert_goto(tctx,
1126 !smbc_getOptionFallbackAfterKerberos(ctx),
1129 "failed to set OptionFallbackAfterKerberos");
1131 torture_comment(tctx,
1132 "Testing smbc_(set|get)OptionNoAutoAnonymousLogin\n");
1133 smbc_setOptionNoAutoAnonymousLogin(ctx, true);
1134 torture_assert_goto(tctx,
1135 smbc_getOptionNoAutoAnonymousLogin(ctx),
1138 "failed to set OptionNoAutoAnonymousLogin");
1140 torture_comment(tctx, "Testing smbc_(set|get)OptionUseCCache\n");
1141 smbc_setOptionUseCCache(ctx, true);
1142 torture_assert_goto(tctx,
1143 smbc_getOptionUseCCache(ctx),
1146 "failed to set OptionUseCCache");
1149 smbc_free_context(ctx, 1);
1154 static bool torture_libsmbclient_list_shares(struct torture_context *tctx)
1156 const char *smburl = torture_setting_string(tctx, "smburl", NULL);
1157 struct smbc_dirent *dirent = NULL;
1158 SMBCCTX *ctx = NULL;
1160 bool ipc_share_found = false;
1163 if (smburl == NULL) {
1165 "option --option=torture:smburl="
1166 "smb://user:password@server missing\n");
1169 ok = torture_libsmbclient_init_context(tctx, &ctx);
1170 torture_assert_goto(tctx,
1174 "Failed to init context");
1175 smbc_set_context(ctx);
1177 torture_comment(tctx, "Listing: %s\n", smburl);
1178 dhandle = smbc_opendir(smburl);
1179 torture_assert_int_not_equal_goto(tctx,
1184 "Failed to open smburl");
1186 while((dirent = smbc_readdir(dhandle)) != NULL) {
1187 torture_comment(tctx, "DIR: %s\n", dirent->name);
1188 torture_assert_not_null_goto(tctx,
1192 "Failed to read name");
1194 if (strequal(dirent->name, "IPC$")) {
1195 ipc_share_found = true;
1199 torture_assert_goto(tctx,
1203 "Failed to list IPC$ share");
1206 smbc_closedir(dhandle);
1210 static bool torture_libsmbclient_utimes(struct torture_context *tctx)
1212 const char *smburl = torture_setting_string(tctx, "smburl", NULL);
1213 SMBCCTX *ctx = NULL;
1216 struct timeval tbuf[2];
1219 if (smburl == NULL) {
1221 "option --option=torture:smburl="
1222 "smb://user:password@server missing\n");
1225 ok = torture_libsmbclient_init_context(tctx, &ctx);
1226 torture_assert(tctx, ok, "Failed to init context");
1227 smbc_set_context(ctx);
1229 fhandle = smbc_open(smburl, O_RDWR|O_CREAT, 0644);
1230 torture_assert_int_not_equal(tctx, fhandle, -1, "smbc_open failed");
1232 ret = smbc_fstat(fhandle, &st);
1233 torture_assert_int_not_equal(tctx, ret, -1, "smbc_fstat failed");
1235 tbuf[0] = convert_timespec_to_timeval(get_atimespec(&st));
1236 tbuf[1] = convert_timespec_to_timeval(get_mtimespec(&st));
1238 tbuf[1] = timeval_add(&tbuf[1], 0, 100000); /* 100 msec */
1240 ret = smbc_utimes(smburl, tbuf);
1241 torture_assert_int_not_equal(tctx, ret, -1, "smbc_utimes failed");
1243 ret = smbc_fstat(fhandle, &st);
1244 torture_assert_int_not_equal(tctx, ret, -1, "smbc_fstat failed");
1246 torture_assert_int_equal(
1248 get_mtimensec(&st) / 1000,
1250 "smbc_utimes did not update msec");
1252 smbc_close(fhandle);
1253 smbc_unlink(smburl);
1257 NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
1259 struct torture_suite *suite;
1261 suite = torture_suite_create(ctx, "libsmbclient");
1263 torture_suite_add_simple_test(suite, "version", torture_libsmbclient_version);
1264 torture_suite_add_simple_test(suite, "initialize", torture_libsmbclient_initialize);
1265 torture_suite_add_simple_test(suite, "configuration", torture_libsmbclient_configuration);
1266 torture_suite_add_simple_test(suite, "setConfiguration", torture_libsmbclient_setConfiguration);
1267 torture_suite_add_simple_test(suite, "options", torture_libsmbclient_options);
1268 torture_suite_add_simple_test(suite, "opendir", torture_libsmbclient_opendir);
1269 torture_suite_add_simple_test(suite, "list_shares", torture_libsmbclient_list_shares);
1270 torture_suite_add_simple_test(suite, "readdirplus",
1271 torture_libsmbclient_readdirplus);
1272 torture_suite_add_simple_test(suite, "readdirplus_seek",
1273 torture_libsmbclient_readdirplus_seek);
1274 torture_suite_add_simple_test(suite, "readdirplus2",
1275 torture_libsmbclient_readdirplus2);
1276 torture_suite_add_simple_test(
1277 suite, "utimes", torture_libsmbclient_utimes);
1279 suite->description = talloc_strdup(suite, "libsmbclient interface tests");
1281 torture_register_suite(ctx, suite);
1283 return NT_STATUS_OK;