bool torture_mangle(int dummy) { static struct cli_state *cli; int i; bool ret = True; printf("starting mangle test\n"); if (!torture_open_connection(&cli, 0)) { return False; } /* we will use an internal tdb to store the names we have used */ tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0); if (!tdb) { printf("ERROR: Failed to open tdb\n"); return False; } cli_unlink(cli, "\\mangle_test\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); cli_rmdir(cli, "\\mangle_test"); if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\mangle_test"))) { printf("ERROR: Failed to make directory\n"); return False; } for (i=0;i<torture_numops;i++) { fstring name; ZERO_STRUCT(name); gen_name(name); if (!test_one(cli, name)) { ret = False; break; } if (total && total % 100 == 0) { printf("collisions %u/%u - %.2f%% (%u failures)\r", collisions, total, (100.0*collisions) / total, failures); } } cli_unlink(cli, "\\mangle_test\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); if (!NT_STATUS_IS_OK(cli_rmdir(cli, "\\mangle_test"))) { printf("ERROR: Failed to remove directory\n"); return False; } printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n", collisions, total, (100.0*collisions) / total, failures); torture_close_connection(cli); printf("mangle test finished\n"); return (ret && (failures == 0)); }
void nb_rmdir(char *fname) { strupper(fname); if (!cli_rmdir(c, fname)) { #if NBDEBUG printf("rmdir %s failed (%s)\n", fname, cli_errstr(c)); #endif } }
void nb_rmdir(const char *fname) { NTSTATUS status; status = cli_rmdir(c, fname); if (!NT_STATUS_IS_OK(status)) { printf("ERROR: rmdir %s failed (%s)\n", fname, nt_errstr(status)); exit(1); } }
void nb_deltree(const char *dname) { char *mask; if (asprintf(&mask, "%s\\*", dname) == -1) { printf("asprintf failed\n"); return; } total_deleted = 0; cli_list(c, mask, FILE_ATTRIBUTE_DIRECTORY, delete_fn, NULL); free(mask); cli_rmdir(c, dname); if (total_deleted) printf("WARNING: Cleaned up %d files\n", total_deleted); }
/**************************************************************************** check for existance of a nttrans call ****************************************************************************/ static bool scan_nttrans(struct cli_state *cli, int op, int level, int fnum, int dnum, const char *fname) { int data_len = 0; int param_len = 0; unsigned int rparam_len, rdata_len; char param[PARAM_SIZE], data[DATA_SIZE]; NTSTATUS status; memset(data, 0, sizeof(data)); data_len = 4; /* try with a info level only */ param_len = 2; SSVAL(param, 0, level); status = try_nttrans_len(cli, "void", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); if (NT_STATUS_IS_OK(status)) return True; /* try with a file descriptor */ param_len = 6; SSVAL(param, 0, fnum); SSVAL(param, 2, level); SSVAL(param, 4, 0); status = try_nttrans_len(cli, "fnum", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); if (NT_STATUS_IS_OK(status)) return True; /* try with a notify style */ param_len = 6; SSVAL(param, 0, dnum); SSVAL(param, 2, dnum); SSVAL(param, 4, level); status = try_nttrans_len(cli, "notify", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); if (NT_STATUS_IS_OK(status)) return True; /* try with a file name */ param_len = 6; SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); param_len += clistr_push(cli, ¶m[6], fname, -1, STR_TERMINATE); status = try_nttrans_len(cli, "fname", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); if (NT_STATUS_IS_OK(status)) return True; /* try with a new file name */ param_len = 6; SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); param_len += clistr_push(cli, ¶m[6], "\\newfile.dat", -1, STR_TERMINATE); status = try_nttrans_len(cli, "newfile", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); cli_unlink(cli, "\\newfile.dat"); cli_rmdir(cli, "\\newfile.dat"); if (NT_STATUS_IS_OK(status)) return True; /* try dfs style */ cli_mkdir(cli, "\\testdir"); param_len = 2; SSVAL(param, 0, level); param_len += clistr_push(cli, ¶m[2], "\\testdir", -1, STR_TERMINATE); status = try_nttrans_len(cli, "dfs", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); cli_rmdir(cli, "\\testdir"); if (NT_STATUS_IS_OK(status)) return True; return False; }
void nb_cleanup(void) { cli_rmdir(c, "clients"); children[nbio_id].done = 1; }
bool torture_utable(int dummy) { struct cli_state *cli; fstring fname, alt_name; uint16_t fnum; smb_ucs2_t c2; int c, len, fd; int chars_allowed=0, alt_allowed=0; uint8 valid[0x10000]; printf("starting utable\n"); if (!torture_open_connection(&cli, 0)) { return False; } memset(valid, 0, sizeof(valid)); cli_mkdir(cli, "\\utable"); cli_unlink(cli, "\\utable\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); for (c=1; c < 0x10000; c++) { size_t size = 0; char *p; SSVAL(&c2, 0, c); fstrcpy(fname, "\\utable\\x"); p = fname+strlen(fname); if (!convert_string(CH_UTF16LE, CH_UNIX, &c2, 2, p, sizeof(fname)-strlen(fname),&size)) { d_printf("convert_string %s failed !\n", fname); continue; } len = size; p[len] = 0; fstrcat(fname,"_a_long_extension"); if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) { continue; } chars_allowed++; cli_qpathinfo_alt_name(cli, fname, alt_name); if (strncmp(alt_name, "X_A_L", 5) != 0) { alt_allowed++; valid[c] = 1; d_printf("fname=[%s] alt_name=[%s]\n", fname, alt_name); } cli_close(cli, fnum); cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); if (c % 100 == 0) { printf("%d (%d/%d)\r", c, chars_allowed, alt_allowed); } } printf("%d (%d/%d)\n", c, chars_allowed, alt_allowed); cli_rmdir(cli, "\\utable"); d_printf("%d chars allowed %d alt chars allowed\n", chars_allowed, alt_allowed); fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644); if (fd == -1) { d_printf("Failed to create valid.dat - %s", strerror(errno)); return False; } if (write(fd, valid, 0x10000) != 0x10000) { d_printf("Failed to create valid.dat - %s", strerror(errno)); close(fd); return false; } close(fd); d_printf("wrote valid.dat\n"); return True; }
bool torture_casetable(int dummy) { static struct cli_state *cli; char *fname; uint16_t fnum; int c, i; #define MAX_EQUIVALENCE 8 smb_ucs2_t equiv[0x10000][MAX_EQUIVALENCE]; printf("starting casetable\n"); if (!torture_open_connection(&cli, 0)) { return False; } memset(equiv, 0, sizeof(equiv)); cli_unlink(cli, "\\utable\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); cli_rmdir(cli, "\\utable"); if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\utable"))) { printf("Failed to create utable directory!\n"); return False; } for (c=1; c < 0x10000; c++) { SMB_OFF_T size; if (c == '.' || c == '\\') continue; printf("%04x (%c)\n", c, isprint(c)?c:'.'); fname = form_name(c); if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum))) { printf("Failed to create file with char %04x\n", c); continue; } size = 0; if (!NT_STATUS_IS_OK(cli_qfileinfo_basic( cli, fnum, NULL, &size, NULL, NULL, NULL, NULL, NULL))) { continue; } if (size > 0) { /* found a character equivalence! */ int c2[MAX_EQUIVALENCE]; if (size/sizeof(int) >= MAX_EQUIVALENCE) { printf("too many chars match?? size=%ld c=0x%04x\n", (unsigned long)size, c); cli_close(cli, fnum); return False; } cli_read(cli, fnum, (char *)c2, 0, size); printf("%04x: ", c); equiv[c][0] = c; for (i=0; i<size/sizeof(int); i++) { printf("%04x ", c2[i]); equiv[c][i+1] = c2[i]; } printf("\n"); fflush(stdout); } cli_writeall(cli, fnum, 0, (uint8_t *)&c, size, sizeof(c), NULL); cli_close(cli, fnum); } cli_unlink(cli, "\\utable\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); cli_rmdir(cli, "\\utable"); return True; }
static void test_mask(int argc, char *argv[], struct cli_state *cli1, struct cli_state *cli2) { pstring mask, file; int l1, l2, i, j, l; int mc_len = strlen(maskchars); int fc_len = strlen(filechars); cli_mkdir(cli1, "masktest"); cli_mkdir(cli2, "masktest"); cli_unlink(cli1, "\\masktest\\*"); cli_unlink(cli2, "\\masktest\\*"); if (argc >= 2) { while (argc >= 2) { pstrcpy(mask,"\\masktest\\"); pstrcpy(file,"\\masktest\\"); pstrcat(mask, argv[0]); pstrcat(file, argv[1]); testpair(cli1, cli2, mask, file); argv += 2; argc -= 2; } goto finished; } for (i=0; standard_masks[i]; i++) { for (j=0; standard_files[j]; j++) { pstrcpy(mask,"\\masktest\\"); pstrcpy(file,"\\masktest\\"); pstrcat(mask, standard_masks[i]); pstrcat(file, standard_files[j]); testpair(cli1, cli2, mask, file); } } while (1) { l1 = 1 + random() % 20; l2 = 1 + random() % 20; pstrcpy(mask,"\\masktest\\"); pstrcpy(file,"\\masktest\\"); l = strlen(mask); for (i=0;i<l1;i++) { mask[i+l] = maskchars[random() % mc_len]; } mask[l+l1] = 0; for (i=0;i<l2;i++) { file[i+l] = filechars[random() % fc_len]; } file[l+l2] = 0; if (strcmp(file+l,".") == 0 || strcmp(file+l,"..") == 0 || strcmp(mask+l,"..") == 0) continue; testpair(cli1, cli2, mask, file); } finished: cli_rmdir(cli1, "\\masktest"); cli_rmdir(cli2, "\\masktest"); }
/**************************************************************************** check for existance of a nttrans call ****************************************************************************/ static bool scan_nttrans(struct cli_state *cli, int op, int level, int fnum, int dnum, const char *fname) { uint32_t data_len = 0; uint32_t param_len = 0; uint32_t rparam_len, rdata_len; uint8_t *param = NULL; uint8_t data[DATA_SIZE]; NTSTATUS status; const char *newfname; const char *dname; memset(data, 0, sizeof(data)); data_len = 4; /* try with a info level only */ TALLOC_FREE(param); param = talloc_array(talloc_tos(), uint8_t, 2); if (param == NULL) return True; SSVAL(param, 0, level); param_len = talloc_get_size(param); status = try_nttrans_len(cli, "void", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); if (NT_STATUS_IS_OK(status)) return True; /* try with a file descriptor */ TALLOC_FREE(param); param = talloc_array(talloc_tos(), uint8_t, 6); if (param == NULL) return True; SSVAL(param, 0, fnum); SSVAL(param, 2, level); SSVAL(param, 4, 0); param_len = talloc_get_size(param); status = try_nttrans_len(cli, "fnum", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); if (NT_STATUS_IS_OK(status)) return True; /* try with a notify style */ TALLOC_FREE(param); param = talloc_array(talloc_tos(), uint8_t, 6); if (param == NULL) return True; SSVAL(param, 0, dnum); SSVAL(param, 2, dnum); SSVAL(param, 4, level); param_len = talloc_get_size(param); status = try_nttrans_len(cli, "notify", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); if (NT_STATUS_IS_OK(status)) return True; /* try with a file name */ TALLOC_FREE(param); param = talloc_array(talloc_tos(), uint8_t, 6); if (param == NULL) return True; SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); param = trans2_bytes_push_str(param, cli_ucs2(cli), fname, strlen(fname)+1, NULL); if (param == NULL) return True; param_len = talloc_get_size(param); status = try_nttrans_len(cli, "fname", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); if (NT_STATUS_IS_OK(status)) return True; /* try with a new file name */ newfname = "\\newfile.dat"; TALLOC_FREE(param); param = talloc_array(talloc_tos(), uint8_t, 6); if (param == NULL) return True; SSVAL(param, 0, level); SSVAL(param, 2, 0); SSVAL(param, 4, 0); param = trans2_bytes_push_str(param, cli_ucs2(cli), newfname, strlen(newfname)+1, NULL); if (param == NULL) return True; param_len = talloc_get_size(param); status = try_nttrans_len(cli, "newfile", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); cli_unlink(cli, newfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); cli_rmdir(cli, newfname); if (NT_STATUS_IS_OK(status)) return True; /* try dfs style */ dname = "\\testdir"; cli_mkdir(cli, dname); TALLOC_FREE(param); param = talloc_array(talloc_tos(), uint8_t, 2); if (param == NULL) return True; SSVAL(param, 0, level); param = trans2_bytes_push_str(param, cli_ucs2(cli), dname, strlen(dname)+1, NULL); if (param == NULL) return True; param_len = talloc_get_size(param); status = try_nttrans_len(cli, "dfs", op, level, param, data, param_len, &data_len, &rparam_len, &rdata_len); cli_rmdir(cli, dname); if (NT_STATUS_IS_OK(status)) return True; return False; }