static bool test_async_resolve(struct torture_context *tctx) { struct nbt_name n; struct tevent_context *ev; int timelimit = torture_setting_int(tctx, "timelimit", 2); const char *host = torture_setting_string(tctx, "host", NULL); int count = 0; struct timeval tv = timeval_current(); TALLOC_CTX *mem_ctx = tctx; ev = tctx->ev; ZERO_STRUCT(n); n.name = host; torture_comment(tctx, "Testing async resolve of '%s' for %d seconds\n", host, timelimit); while (timeval_elapsed(&tv) < timelimit) { struct socket_address **s; struct composite_context *c = resolve_name_host_send(mem_ctx, ev, NULL, 0, 0, &n); torture_assert(tctx, c != NULL, "resolve_name_host_send"); torture_assert_ntstatus_ok(tctx, resolve_name_host_recv(c, mem_ctx, &s, NULL), "async resolve failed"); count++; } torture_comment(tctx, "async rate of %.1f resolves/sec\n", count/timeval_elapsed(&tv)); return true; }
static void nb_target_rate(struct child_struct *child, double rate) { double tdelay; if (child->rate.last_bytes == 0) { child->rate.last_bytes = child->bytes; child->rate.last_time = timeval_current(); return; } if (rate != 0) { tdelay = (child->bytes - child->rate.last_bytes)/(1.0e6*rate) - timeval_elapsed(&child->rate.last_time); } else { tdelay = - timeval_elapsed(&child->rate.last_time); } if (tdelay > 0 && rate != 0) { msleep(tdelay*1000); } else { child->max_latency = MAX(child->max_latency, -tdelay); } child->rate.last_time = timeval_current(); child->rate.last_bytes = child->bytes; }
/* * Callback routine when required locks are not obtained within timeout * Called from parent context */ static void ctdb_lock_timeout_handler(struct tevent_context *ev, struct tevent_timer *ttimer, struct timeval current_time, void *private_data) { static const char * debug_locks = NULL; struct lock_context *lock_ctx; struct ctdb_context *ctdb; pid_t pid; lock_ctx = talloc_get_type_abort(private_data, struct lock_context); ctdb = lock_ctx->ctdb; if (lock_ctx->type == LOCK_RECORD || lock_ctx->type == LOCK_DB) { DEBUG(DEBUG_WARNING, ("Unable to get %s lock on database %s for %.0lf seconds\n", (lock_ctx->type == LOCK_RECORD ? "RECORD" : "DB"), lock_ctx->ctdb_db->db_name, timeval_elapsed(&lock_ctx->start_time))); } else { DEBUG(DEBUG_WARNING, ("Unable to get ALLDB locks for %.0lf seconds\n", timeval_elapsed(&lock_ctx->start_time))); } /* Fire a child process to find the blocking process. */ if (debug_locks == NULL) { debug_locks = getenv("CTDB_DEBUG_LOCKS"); if (debug_locks == NULL) { debug_locks = talloc_asprintf(ctdb, "%s/debug_locks.sh", getenv("CTDB_BASE")); } } if (debug_locks != NULL) { pid = vfork(); if (pid == 0) { execl(debug_locks, debug_locks, NULL); _exit(0); } ctdb_track_child(ctdb, pid); } else { DEBUG(DEBUG_WARNING, (__location__ " Unable to setup lock debugging - no memory?\n")); } /* reset the timeout timer */ // talloc_free(lock_ctx->ttimer); lock_ctx->ttimer = tevent_add_timer(ctdb->ev, lock_ctx, timeval_current_ofs(10, 0), ctdb_lock_timeout_handler, (void *)lock_ctx); }
static void report_rate(struct tevent_context *ev, struct tevent_timer *te, struct timeval t, void *private_data) { struct offline_state *state = talloc_get_type(private_data, struct offline_state); int i; uint32_t total=0, total_offline=0, total_online=0; for (i=0;i<numstates;i++) { total += state[i].count - state[i].lastcount; if (timeval_elapsed(&state[i].tv_start) > latencies[state[i].op]) { latencies[state[i].op] = timeval_elapsed(&state[i].tv_start); } state[i].lastcount = state[i].count; total_online += state[i].online_count; total_offline += state[i].offline_count; } printf("ops/s=%4u offline=%5u online=%4u set_lat=%.1f/%.1f get_lat=%.1f/%.1f save_lat=%.1f/%.1f load_lat=%.1f/%.1f\n", total, total_offline, total_online, latencies[OP_SETOFFLINE], worst_latencies[OP_SETOFFLINE], latencies[OP_GETOFFLINE], worst_latencies[OP_GETOFFLINE], latencies[OP_SAVEFILE], worst_latencies[OP_SAVEFILE], latencies[OP_LOADFILE], worst_latencies[OP_LOADFILE]); fflush(stdout); event_add_timed(ev, state, timeval_current_ofs(1, 0), report_rate, state); for (i=0;i<OP_ENDOFLIST;i++) { if (latencies[i] > worst_latencies[i]) { worst_latencies[i] = latencies[i]; } latencies[i] = 0; } /* send an echo on each interface to ensure it stays alive - this helps with IP takeover */ for (i=0;i<numstates;i++) { struct smb_echo p; struct smbcli_request *req; if (!state[i].tree) { continue; } p.in.repeat_count = 1; p.in.size = 0; p.in.data = NULL; req = smb_raw_echo_send(state[i].tree->session->transport, &p); req->async.private_data = &state[i]; req->async.fn = echo_completion; } }
static void simple_suite_finish(struct torture_context *ctx, struct torture_suite *suite) { printf("%s took %g secs\n\n", suite->name, timeval_elapsed(&last_suite_started)); }
int create_regular_file(char *dirname, int n) { struct timeval before,after; char file_name[4096]; char remove_file[4096]; int err = 0; double create_file; int i; int ret; gettimeofday(&before,NULL); for ( i = 0; i < n ; i++) { sprintf(file_name,"%s/%s.%d", dirname, "file", i); ret = open(file_name, O_CREAT|O_RDWR,0600); if ( ret == -1 ) { err = errno; fprintf(stderr,"%s:Creating file %s caused error\n", strerror(errno),file_name); exit(err); } } gettimeofday(&after,NULL); create_file = timeval_elapsed(&before,&after) * 1e6 / n; printf("Time to create a regular file is %.01f us\n", create_file); for ( i = 0; i < n; i++) { sprintf(file_name,"%s/%s.%d", dirname, "file", i); unlink(file_name); } return 0; }
int create_pipe(char *dirname, int n) { struct timeval before,after; char pipe_name[4096]; char remove_pipe[4096]; int err = 0; double create_pipe; int i; int ret; gettimeofday(&before,NULL); for ( i = 0; i < n ; i++) { sprintf(pipe_name,"%s/%s.%d", dirname, "pipe", i); ret = mkfifo(pipe_name, 0644); if ( ret == -1 ) { err = errno; fprintf(stderr,"%s:Creating pipe %s caused error\n", strerror(errno),pipe_name); exit(err); } } gettimeofday(&after,NULL); create_pipe = timeval_elapsed(&before,&after) * 1e6 / n; printf("Time to create a pipe is %.01f us\n", create_pipe); for ( i = 0; i < n; i++) { sprintf(pipe_name,"%s/%s.%d", dirname, "pipe", i); unlink(pipe_name); } return 0; }
/* measure the speed of talloc versus malloc */ static bool test_speed(void) { void *ctx = talloc_new(NULL); unsigned count; const int loop = 1000; int i; struct timeval tv; printf("test: speed [\nTALLOC VS MALLOC SPEED\n]\n"); tv = timeval_current(); count = 0; do { void *p1, *p2, *p3; for (i=0;i<loop;i++) { p1 = talloc_size(ctx, loop % 100); p2 = talloc_strdup(p1, "foo bar"); p3 = talloc_size(p1, 300); talloc_free(p1); } count += 3 * loop; } while (timeval_elapsed(&tv) < 5.0); fprintf(stderr, "talloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); talloc_free(ctx); tv = timeval_current(); count = 0; do { void *p1, *p2, *p3; for (i=0;i<loop;i++) { p1 = malloc(loop % 100); p2 = strdup("foo bar"); p3 = malloc(300); free(p1); free(p2); free(p3); } count += 3 * loop; } while (timeval_elapsed(&tv) < 5.0); fprintf(stderr, "malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv)); printf("success: speed\n"); return true; }
static void finish_op(struct child_struct *child, struct op *op) { double t = timeval_elapsed(&child->lasttime); op->count++; op->total_time += t; if (t > op->max_latency) { op->max_latency = t; } }
static void nb_time_delay(struct child_struct *child, double targett) { double elapsed = timeval_elapsed(&child->starttime); if (targett > elapsed) { msleep(1000*(targett - elapsed)); } else if (elapsed - targett > child->max_latency) { child->max_latency = MAX(elapsed - targett, child->max_latency); } }
/* test resolution using sync method */ static bool test_sync_resolve(struct torture_context *tctx) { int timelimit = torture_setting_int(tctx, "timelimit", 2); struct timeval tv = timeval_current(); int count = 0; const char *host = torture_setting_string(tctx, "host", NULL); torture_comment(tctx, "Testing sync resolve of '%s' for %d seconds\n", host, timelimit); while (timeval_elapsed(&tv) < timelimit) { inet_ntoa(interpret_addr2(host)); count++; } torture_comment(tctx, "sync rate of %.1f resolves/sec\n", count/timeval_elapsed(&tv)); return true; }
void nbio_time_delay(double targett) { double elapsed = timeval_elapsed(&children[nbio_id].starttime); if (targett > elapsed) { smb_msleep(1000*(targett - elapsed)); } else if (elapsed - targett > children[nbio_id].max_latency) { children[nbio_id].max_latency = MAX(elapsed - targett, children[nbio_id].max_latency); } }
static bool torture_winbind_struct_ping(struct torture_context *torture) { struct timeval tv = timeval_current(); int timelimit = torture_setting_int(torture, "timelimit", 5); uint32_t total = 0; torture_comment(torture, "Running WINBINDD_PING (struct based) for %d seconds\n", timelimit); while (timeval_elapsed(&tv) < timelimit) { DO_STRUCT_REQ_REP(WINBINDD_PING, NULL, NULL); total++; } torture_comment(torture, "%u (%.1f/s) WINBINDD_PING (struct based)\n", total, total / timeval_elapsed(&tv)); return true; }
/* * Callback routine when the required locks are obtained. * Called from parent context */ static void ctdb_lock_handler(struct tevent_context *ev, struct tevent_fd *tfd, uint16_t flags, void *private_data) { struct lock_context *lock_ctx; char c; bool locked; double t; int id; lock_ctx = talloc_get_type_abort(private_data, struct lock_context); /* cancel the timeout event */ TALLOC_FREE(lock_ctx->ttimer); t = timeval_elapsed(&lock_ctx->start_time); id = lock_bucket_id(t); /* Read the status from the child process */ if (sys_read(lock_ctx->fd[0], &c, 1) != 1) { locked = false; } else { locked = (c == 0 ? true : false); } /* Update statistics */ CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.num_calls); if (lock_ctx->ctdb_db) { CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_calls); } if (locked) { if (lock_ctx->ctdb_db) { CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.buckets[id]); CTDB_UPDATE_LATENCY(lock_ctx->ctdb, lock_ctx->ctdb_db, lock_type_str[lock_ctx->type], locks.latency, lock_ctx->start_time); CTDB_UPDATE_DB_LATENCY(lock_ctx->ctdb_db, lock_type_str[lock_ctx->type], locks.latency, t); CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.buckets[id]); } } else { CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.num_failed); if (lock_ctx->ctdb_db) { CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_failed); } } process_callbacks(lock_ctx, locked); }
/* main child loop */ static void run_child(struct child *child) { srandom(time(NULL) ^ getpid()); while (1) { double latency; unsigned fnumber = random() % options.nfiles; char *fname = filename(fnumber); if (kill(parent_pid, 0) != 0) { /* parent has exited */ exit(0); } child->tv_start = timeval_current(); child->op = random() % OP_ENDOFLIST; switch (child->op) { case OP_LOADFILE: child_loadfile(child, fname, fnumber); break; case OP_SAVEFILE: child_savefile(child, fname, fnumber); break; case OP_MIGRATE: child_migrate(child, fname); break; case OP_GETOFFLINE: child_getoffline(child, fname); break; case OP_ENDOFLIST: break; } latency = timeval_elapsed(&child->tv_start); if (latency > child->latencies[child->op]) { child->latencies[child->op] = latency; } if (latency > child->worst_latencies[child->op]) { child->worst_latencies[child->op] = latency; } child->count++; free(fname); } }
void cron_update(void) { TimeVal now; double dt; List *iter, *next; timeval_now(&now); dt = timeval_elapsed(&cron_info.now, &now); for(iter = cron_info.oneshot; iter != NULL; iter = next) { Job *job = list_data(iter); next = list_next(iter); if(timeval_passed(&job->when.oneshot, &now)) { if(job->handler == (int (*)(void *)) printf) printf("%s\n", (const char *) job->data); else job->handler(job->data); job_remove(&cron_info.oneshot, iter); } } for(iter = cron_info.periodic; iter != NULL; iter = next) { Job *job = list_data(iter); next = list_next(iter); job->when.periodic.bucket += dt; if(job->when.periodic.bucket >= job->when.periodic.period) { if(job->handler == (int (*)(void *)) printf) /* Clever? */ printf("%s\n", (const char *) job->data); else { if(!job->handler(job->data)) job_remove(&cron_info.periodic, iter); else job->when.periodic.bucket = 0.0; } } } cron_info.now = now; }
void nb_alarm(int ignore) { int i; int lines=0, num_clients=0; if (nbio_id != -1) return; for (i=0;i<nprocs;i++) { lines += children[i].line; if (!children[i].done) num_clients++; } printf("%4d %8d %.2f MB/sec\r", num_clients, lines/nprocs, 1.0e-6 * nbio_total() / timeval_elapsed(&nb_start)); signal(SIGALRM, nb_alarm); alarm(1); }
/* test directory listing speed */ bool torture_dirtest1(struct torture_context *tctx, struct smbcli_state *cli) { int i; int fnum; bool correct = true; extern int torture_numops; struct timeval tv; torture_comment(tctx, "Creating %d random filenames\n", torture_numops); srandom(0); tv = timeval_current(); for (i=0;i<torture_numops;i++) { char *fname; asprintf(&fname, "\\%x", (int)random()); fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum == -1) { fprintf(stderr,"(%s) Failed to open %s\n", __location__, fname); return false; } smbcli_close(cli->tree, fnum); free(fname); } torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "a*.*", 0, list_fn, NULL)); torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "b*.*", 0, list_fn, NULL)); torture_comment(tctx, "Matched %d\n", smbcli_list(cli->tree, "xyzabc", 0, list_fn, NULL)); torture_comment(tctx, "dirtest core %g seconds\n", timeval_elapsed(&tv)); srandom(0); for (i=0;i<torture_numops;i++) { char *fname; asprintf(&fname, "\\%x", (int)random()); smbcli_unlink(cli->tree, fname); free(fname); } return correct; }
int create_character_special_file(char *dir, int n) { int mknod_ret; int err; struct timeval before, after; double create; dev_t dev; char name[4096]; char remove_name[4096]; int i; gettimeofday(&before,NULL); for ( i = 0; i < n; i++ ) { sprintf(name,"%s/%s.%d", dir, "chr", i); dev = makedev(2,2); /* creates a device with given major and minor numbers and returns a structure of type dev_t */ mknod_ret = mknod(name,S_IFCHR|0644,dev); if(mknod_ret) { err = errno; fprintf(stderr,"%s:Creating device file %s failed\n", strerror(errno),name); exit(err); } } gettimeofday(&after,NULL); create = timeval_elapsed(&before,&after) * 1e6 / n; printf("Time to create character special file is %.01f us\n",create); for ( i = 0; i < n; i++ ) { sprintf(remove_name,"%s/%s.%d", dir, "chr", i); unlink(remove_name); } return 0; }
void sync_update(double slice) { List *iter, *next; PNode *n; TimeVal now; /* Create nodes that need to be created. */ for(iter = sync_info.queue_create; iter != NULL; iter = next) { next = list_next(iter); n = list_data(iter); verse_send_node_create(~0, n->type, 0); /* Move node from "to create" to "pending" list; no change in refcount. */ sync_info.queue_create = list_unlink(sync_info.queue_create, iter); list_destroy(iter); sync_info.queue_create_pend = list_prepend(sync_info.queue_create_pend, n); } /* Synchronize existing nodes. */ timeval_now(&now); for(iter = sync_info.queue_sync; iter != NULL; iter = next) { PNode *n = list_data(iter); next = list_next(iter); if(timeval_elapsed(&n->sync.last_send, &now) < 0.1) continue; n->sync.last_send = now; if(sync_node(n)) { sync_info.queue_sync = list_unlink(sync_info.queue_sync, iter); printf("removing node %u from sync queue, it's in sync\n", n->id); nodedb_unref(n); list_destroy(iter); n->sync.busy = 0; } } }
void nbio_target_rate(double rate) { static double last_bytes; static struct timeval last_time; double tdelay; if (last_bytes == 0) { last_bytes = children[nbio_id].bytes; last_time = timeval_current(); return; } tdelay = (children[nbio_id].bytes - last_bytes)/(1.0e6*rate) - timeval_elapsed(&last_time); if (tdelay > 0) { smb_msleep(tdelay*1000); } else { children[nbio_id].max_latency = MAX(children[nbio_id].max_latency, -tdelay); } last_time = timeval_current(); last_bytes = children[nbio_id].bytes; }
int create_directory(char *dirname, int n) { char name[4096]; char rmdir_name[4096]; double create; int makedir_ret; int err; int i; struct timeval before, after; gettimeofday(&before,NULL); for ( i = 1; i < n; i++ ) { sprintf(name,"%s/%s.%d", dirname, "dir", i); makedir_ret = mkdir(name,0755); if (makedir_ret == -1) { err = errno; fprintf(stderr,"%s:creating directory %s created error\n", strerror(errno),name); exit(err); } } gettimeofday(&after,NULL); create = timeval_elapsed(&before,&after) * 1e6 / n; printf("Time to create directory is %.01f us\n",create); for ( i = 0; i < n; i++) { sprintf(rmdir_name,"%s/%s.%d", dirname, "dir", i); rmdir(rmdir_name); } return 0; }
static void test_store_records(struct db_context *db, struct tevent_context *ev) { TDB_DATA key; uint32_t *counters; TALLOC_CTX *tmp_ctx = talloc_stackframe(); struct timeval start; key = string_term_tdb_data("testkey"); start = timeval_current(); while ((timelimit == 0) || (timeval_elapsed(&start) < timelimit)) { struct db_record *rec; TDB_DATA data; TDB_DATA value; int ret; NTSTATUS status; if (!no_trans) { if (verbose) DEBUG(1, ("starting transaction\n")); ret = dbwrap_transaction_start(db); if (ret != 0) { DEBUG(0, ("Failed to start transaction on node " "%d\n", pnn)); goto fail; } if (verbose) DEBUG(1, ("transaction started\n")); do_sleep(torture_delay); } if (verbose) DEBUG(1, ("calling fetch_lock\n")); rec = dbwrap_fetch_locked(db, tmp_ctx, key); if (rec == NULL) { DEBUG(0, ("Failed to fetch record\n")); goto fail; } if (verbose) DEBUG(1, ("fetched record ok\n")); do_sleep(torture_delay); value = dbwrap_record_get_value(rec); data.dsize = MAX(value.dsize, sizeof(uint32_t) * (pnn+1)); data.dptr = (unsigned char *)talloc_zero_size(tmp_ctx, data.dsize); if (data.dptr == NULL) { DEBUG(0, ("Failed to allocate data\n")); goto fail; } memcpy(data.dptr, value.dptr, value.dsize); counters = (uint32_t *)data.dptr; /* bump our counter */ counters[pnn]++; if (verbose) DEBUG(1, ("storing data\n")); status = dbwrap_record_store(rec, data, TDB_REPLACE); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to store record\n")); if (!no_trans) { ret = dbwrap_transaction_cancel(db); if (ret != 0) { DEBUG(0, ("Error cancelling transaction.\n")); } } goto fail; } talloc_free(rec); if (verbose) DEBUG(1, ("stored data ok\n")); do_sleep(torture_delay); if (!no_trans) { if (verbose) DEBUG(1, ("calling transaction_commit\n")); ret = dbwrap_transaction_commit(db); if (ret != 0) { DEBUG(0, ("Failed to commit transaction\n")); goto fail; } if (verbose) DEBUG(1, ("transaction committed\n")); } /* store the counters and verify that they are sane */ if (verbose || (pnn == 0)) { if (!check_counters(db, data)) { goto fail; } } talloc_free(data.dptr); do_sleep(torture_delay); } goto done; fail: success = false; done: talloc_free(tmp_ctx); return; }
/* test the delayed reply to a open that leads to a sharing violation */ static bool test_mux_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) { union smb_open io; NTSTATUS status; int fnum1, fnum2; bool ret = true; struct smbcli_request *req1, *req2; struct timeval tv; double d; printf("Testing multiplexed open/open/close\n"); printf("send first open\n"); io.generic.level = RAW_OPEN_NTCREATEX; io.ntcreatex.in.root_fid.fnum = 0; io.ntcreatex.in.flags = 0; io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA; io.ntcreatex.in.create_options = 0; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ; io.ntcreatex.in.alloc_size = 0; io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; io.ntcreatex.in.security_flags = 0; io.ntcreatex.in.fname = BASEDIR "\\open.dat"; status = smb_raw_open(cli->tree, mem_ctx, &io); CHECK_STATUS(status, NT_STATUS_OK); fnum1 = io.ntcreatex.out.file.fnum; printf("send 2nd open, non-conflicting\n"); io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; status = smb_raw_open(cli->tree, mem_ctx, &io); CHECK_STATUS(status, NT_STATUS_OK); fnum2 = io.ntcreatex.out.file.fnum; tv = timeval_current(); printf("send 3rd open, conflicting\n"); io.ntcreatex.in.share_access = 0; status = smb_raw_open(cli->tree, mem_ctx, &io); CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); d = timeval_elapsed(&tv); if (d < 0.5 || d > 1.5) { printf("bad timeout for conflict - %.2f should be 1.0\n", d); } else { printf("open delay %.2f\n", d); } printf("send async open, conflicting\n"); tv = timeval_current(); req1 = smb_raw_open_send(cli->tree, &io); printf("send 2nd async open, conflicting\n"); tv = timeval_current(); req2 = smb_raw_open_send(cli->tree, &io); printf("close first sync open\n"); smbcli_close(cli->tree, fnum1); printf("cancel 2nd async open (should be ignored)\n"); smb_raw_ntcancel(req2); d = timeval_elapsed(&tv); if (d > 0.25) { printf("bad timeout after cancel - %.2f should be <0.25\n", d); ret = false; } printf("close the 2nd sync open\n"); smbcli_close(cli->tree, fnum2); printf("see if the 1st async open now succeeded\n"); status = smb_raw_open_recv(req1, mem_ctx, &io); CHECK_STATUS(status, NT_STATUS_OK); d = timeval_elapsed(&tv); if (d > 0.25) { printf("bad timeout for async conflict - %.2f should be <0.25\n", d); ret = false; } else { printf("async open delay %.2f\n", d); } printf("2nd async open should have timed out\n"); status = smb_raw_open_recv(req2, mem_ctx, &io); CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); d = timeval_elapsed(&tv); if (d < 0.8) { printf("bad timeout for async conflict - %.2f should be 1.0\n", d); } printf("close the 1st async open\n"); smbcli_close(cli->tree, io.ntcreatex.out.file.fnum); done: return ret; }
/* test a lock that conflicts with an existing lock */ static bool test_mux_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) { union smb_lock io; NTSTATUS status; int fnum; bool ret = true; struct smbcli_request *req; struct smb_lock_entry lock[1]; struct timeval t; printf("TESTING MULTIPLEXED LOCK/LOCK/UNLOCK\n"); fnum = smbcli_open(cli->tree, BASEDIR "\\write.dat", O_RDWR | O_CREAT, DENY_NONE); if (fnum == -1) { printf("open failed in mux_write - %s\n", smbcli_errstr(cli->tree)); ret = false; goto done; } printf("establishing a lock\n"); io.lockx.level = RAW_LOCK_LOCKX; io.lockx.in.file.fnum = fnum; io.lockx.in.mode = 0; io.lockx.in.timeout = 0; io.lockx.in.lock_cnt = 1; io.lockx.in.ulock_cnt = 0; lock[0].pid = 1; lock[0].offset = 0; lock[0].count = 4; io.lockx.in.locks = &lock[0]; status = smb_raw_lock(cli->tree, &io); CHECK_STATUS(status, NT_STATUS_OK); printf("the second lock will conflict with the first\n"); lock[0].pid = 2; io.lockx.in.timeout = 1000; status = smb_raw_lock(cli->tree, &io); CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); printf("this will too, but we'll unlock while waiting\n"); t = timeval_current(); req = smb_raw_lock_send(cli->tree, &io); printf("unlock the first range\n"); lock[0].pid = 1; io.lockx.in.ulock_cnt = 1; io.lockx.in.lock_cnt = 0; io.lockx.in.timeout = 0; status = smb_raw_lock(cli->tree, &io); CHECK_STATUS(status, NT_STATUS_OK); printf("recv the async reply\n"); status = smbcli_request_simple_recv(req); CHECK_STATUS(status, NT_STATUS_OK); printf("async lock took %.2f msec\n", timeval_elapsed(&t) * 1000); if (timeval_elapsed(&t) > 0.1) { printf("failed to trigger early lock retry\n"); return false; } printf("reopening with an exit\n"); smb_raw_exit(cli->session); fnum = smbcli_open(cli->tree, BASEDIR "\\write.dat", O_RDWR | O_CREAT, DENY_NONE); printf("Now trying with a cancel\n"); io.lockx.level = RAW_LOCK_LOCKX; io.lockx.in.file.fnum = fnum; io.lockx.in.mode = 0; io.lockx.in.timeout = 0; io.lockx.in.lock_cnt = 1; io.lockx.in.ulock_cnt = 0; lock[0].pid = 1; lock[0].offset = 0; lock[0].count = 4; io.lockx.in.locks = &lock[0]; status = smb_raw_lock(cli->tree, &io); CHECK_STATUS(status, NT_STATUS_OK); lock[0].pid = 2; io.lockx.in.timeout = 1000; status = smb_raw_lock(cli->tree, &io); CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); req = smb_raw_lock_send(cli->tree, &io); /* cancel the blocking lock */ smb_raw_ntcancel(req); printf("sending 2nd cancel\n"); /* the 2nd cancel is totally harmless, but tests the server trying to cancel an already cancelled request */ smb_raw_ntcancel(req); printf("sent 2nd cancel\n"); lock[0].pid = 1; io.lockx.in.ulock_cnt = 1; io.lockx.in.lock_cnt = 0; io.lockx.in.timeout = 0; status = smb_raw_lock(cli->tree, &io); CHECK_STATUS(status, NT_STATUS_OK); status = smbcli_request_simple_recv(req); CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); printf("cancel a lock using exit to close file\n"); lock[0].pid = 1; io.lockx.in.ulock_cnt = 0; io.lockx.in.lock_cnt = 1; io.lockx.in.timeout = 1000; status = smb_raw_lock(cli->tree, &io); CHECK_STATUS(status, NT_STATUS_OK); t = timeval_current(); lock[0].pid = 2; req = smb_raw_lock_send(cli->tree, &io); smb_raw_exit(cli->session); smb_raw_exit(cli->session); smb_raw_exit(cli->session); smb_raw_exit(cli->session); printf("recv the async reply\n"); status = smbcli_request_simple_recv(req); CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); printf("async lock exit took %.2f msec\n", timeval_elapsed(&t) * 1000); if (timeval_elapsed(&t) > 0.1) { printf("failed to trigger early lock failure\n"); return false; } done: return ret; }
void nb_alarm(int sig) { int i; int lines=0; double t; int in_warmup = 0; int num_connected = 0; if (nbio_id != -1) return; for (i=0;i<nprocs;i++) { if (children[i].connected) { num_connected++; } if (children[i].bytes == 0) { in_warmup = 1; } lines += children[i].line; } t = timeval_elapsed(&tv_start); if (!in_warmup && warmup>0 && t > warmup) { tv_start = timeval_current(); warmup = 0; for (i=0;i<nprocs;i++) { children[i].warmup_bytes = children[i].bytes; } goto next; } if (t < warmup) { in_warmup = 1; } else if (!in_warmup && !in_cleanup && t > timelimit) { for (i=0;i<nprocs;i++) { children[i].done = 1; } tv_end = timeval_current(); in_cleanup = 1; } if (t < 1) { goto next; } if (!in_cleanup) { tv_end = timeval_current(); } if (in_warmup) { printf("%4d %8d %.2f MB/sec warmup %.0f sec \n", num_connected, lines/nprocs, nbio_result(), t); } else if (in_cleanup) { printf("%4d %8d %.2f MB/sec cleanup %.0f sec \n", num_connected, lines/nprocs, nbio_result(), t); } else { printf("%4d %8d %.2f MB/sec execute %.0f sec latency %.2f msec \n", num_connected, lines/nprocs, nbio_result(), t, nbio_latency() * 1.0e3); } fflush(stdout); next: signal(SIGALRM, nb_alarm); alarm(1); }
static void sig_alarm(int sig) { int i, op; unsigned total=0, total_offline=0, total_online=0, total_migrate_failures=0, total_migrate_ok=0, total_io_failures=0; double latencies[OP_ENDOFLIST]; double worst_latencies[OP_ENDOFLIST]; if (timeval_elapsed(&tv_start) >= options.timelimit) { printf("timelimit reached - killing children\n"); for (i=0; i<options.nprocesses; i++) { kill(children[i].pid, SIGTERM); } } for (op=0; op<OP_ENDOFLIST; op++) { latencies[op] = 0; worst_latencies[op] = 0; } for (i=0; i<options.nprocesses; i++) { if (kill(children[i].pid, 0) != 0) { continue; } total += children[i].count - children[i].lastcount; children[i].lastcount = children[i].count; total_online += children[i].online_count; total_offline += children[i].offline_count; total_migrate_failures += children[i].migrate_fail_count; total_io_failures += children[i].io_fail_count; total_migrate_ok += children[i].migrate_ok_count; for (op=0; op<OP_ENDOFLIST; op++) { if (children[i].latencies[op] > latencies[op]) { latencies[op] = children[i].latencies[op]; } children[i].latencies[op] = 0; } if (timeval_elapsed(&children[i].tv_start) > latencies[children[i].op]) { double lat; lat = timeval_elapsed(&children[i].tv_start); latencies[children[i].op] = lat; if (lat > worst_latencies[children[i].op]) { worst_latencies[children[i].op] = lat; } } for (op=0; op<OP_ENDOFLIST; op++) { double lat = children[i].worst_latencies[op]; if (lat > worst_latencies[op]) { worst_latencies[op] = lat; } } } printf("ops/s=%4u offline=%u/%u failures: mig=%u io=%u latencies: mig=%4.1f/%4.1f stat=%4.1f/%4.1f write=%4.1f/%4.1f read=%4.1f/%4.1f\n", total, total_offline, total_online+total_offline, total_migrate_failures, total_io_failures, latencies[OP_MIGRATE], worst_latencies[OP_MIGRATE], latencies[OP_GETOFFLINE], worst_latencies[OP_GETOFFLINE], latencies[OP_SAVEFILE], worst_latencies[OP_SAVEFILE], latencies[OP_LOADFILE], worst_latencies[OP_LOADFILE]); fflush(stdout); signal(SIGALRM, sig_alarm); alarm(1); }
/* test offline file handling */ bool torture_test_offline(struct torture_context *torture) { bool ret = true; TALLOC_CTX *mem_ctx = talloc_new(torture); int i; int timelimit = torture_setting_int(torture, "timelimit", 10); struct timeval tv; struct offline_state *state; struct smbcli_state *cli; bool progress; progress = torture_setting_bool(torture, "progress", true); nconnections = torture_setting_int(torture, "nprocs", 4); numstates = nconnections * torture_entries; state = talloc_zero_array(mem_ctx, struct offline_state, numstates); printf("Opening %d connections with %d simultaneous operations and %u files\n", nconnections, numstates, torture_numops); for (i=0;i<nconnections;i++) { state[i].tctx = torture; state[i].mem_ctx = talloc_new(state); state[i].ev = torture->ev; if (!torture_open_connection_ev(&cli, i, torture, torture->ev)) { return false; } state[i].tree = cli->tree; state[i].client = i; /* allow more time for offline files */ state[i].tree->session->transport->options.request_timeout = 200; } /* the others are repeats on the earlier connections */ for (i=nconnections;i<numstates;i++) { state[i].tctx = torture; state[i].mem_ctx = talloc_new(state); state[i].ev = torture->ev; state[i].tree = state[i % nconnections].tree; state[i].client = i; } num_connected = i; if (!torture_setup_dir(cli, BASEDIR)) { goto failed; } /* pre-create files */ printf("Pre-creating %u files ....\n", torture_numops); for (i=0;i<torture_numops;i++) { int fnum; char *fname = filename(mem_ctx, i); char buf[FILE_SIZE]; NTSTATUS status; memset(buf, 1+(i % 255), sizeof(buf)); fnum = smbcli_open(state[0].tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum == -1) { printf("Failed to open %s on connection %d\n", fname, i); goto failed; } if (smbcli_write(state[0].tree, fnum, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { printf("Failed to write file of size %u\n", FILE_SIZE); goto failed; } status = smbcli_close(state[0].tree, fnum); if (!NT_STATUS_IS_OK(status)) { printf("Close failed - %s\n", nt_errstr(status)); goto failed; } talloc_free(fname); } /* start the async ops */ for (i=0;i<numstates;i++) { state[i].tv_start = timeval_current(); test_offline(&state[i]); } tv = timeval_current(); if (progress) { event_add_timed(torture->ev, state, timeval_current_ofs(1, 0), report_rate, state); } printf("Running for %d seconds\n", timelimit); while (timeval_elapsed(&tv) < timelimit) { event_loop_once(torture->ev); if (test_failed) { DEBUG(0,("test failed\n")); goto failed; } } printf("\nWaiting for completion\n"); test_finished = true; for (i=0;i<numstates;i++) { while (state[i].loadfile || state[i].savefile || state[i].req) { event_loop_once(torture->ev); } } printf("worst latencies: set_lat=%.1f get_lat=%.1f save_lat=%.1f load_lat=%.1f\n", worst_latencies[OP_SETOFFLINE], worst_latencies[OP_GETOFFLINE], worst_latencies[OP_SAVEFILE], worst_latencies[OP_LOADFILE]); smbcli_deltree(state[0].tree, BASEDIR); talloc_free(mem_ctx); printf("\n"); return ret; failed: talloc_free(mem_ctx); return false; }
/* test UDP/138 netlogon requests */ static bool nbt_test_netlogon(struct torture_context *tctx) { struct dgram_mailslot_handler *dgmslot; struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx)); struct socket_address *dest; const char *myaddress; struct nbt_netlogon_packet logon; struct nbt_netlogon_response *response; struct nbt_name myname; NTSTATUS status; struct timeval tv = timeval_current(); struct socket_address *socket_address; const char *address; struct nbt_name name; struct interface *ifaces; name.name = lp_workgroup(tctx->lp_ctx); name.type = NBT_NAME_LOGON; name.scope = NULL; /* do an initial name resolution to find its IP */ torture_assert_ntstatus_ok(tctx, resolve_name(lp_resolve_context(tctx->lp_ctx), &name, tctx, &address, tctx->ev), talloc_asprintf(tctx, "Failed to resolve %s", name.name)); load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); myaddress = talloc_strdup(dgmsock, iface_best_ip(ifaces, address)); socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, myaddress, lp_dgram_port(tctx->lp_ctx)); torture_assert(tctx, socket_address != NULL, "Error getting address"); /* try receiving replies on port 138 first, which will only work if we are root and smbd/nmbd are not running - fall back to listening on any port, which means replies from most windows versions won't be seen */ status = socket_listen(dgmsock->sock, socket_address, 0, 0); if (!NT_STATUS_IS_OK(status)) { talloc_free(socket_address); socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, myaddress, 0); torture_assert(tctx, socket_address != NULL, "Error getting address"); socket_listen(dgmsock->sock, socket_address, 0, 0); } /* setup a temporary mailslot listener for replies */ dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, netlogon_handler, NULL); ZERO_STRUCT(logon); logon.command = LOGON_PRIMARY_QUERY; logon.req.pdc.computer_name = TEST_NAME; logon.req.pdc.mailslot_name = dgmslot->mailslot_name; logon.req.pdc.unicode_name = TEST_NAME; logon.req.pdc.nt_version = 1; logon.req.pdc.lmnt_token = 0xFFFF; logon.req.pdc.lm20_token = 0xFFFF; make_nbt_name_client(&myname, TEST_NAME); dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, address, lp_dgram_port(tctx->lp_ctx)); torture_assert(tctx, dest != NULL, "Error getting address"); status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, NBT_MAILSLOT_NETLOGON, &myname, &logon); torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); while (timeval_elapsed(&tv) < 5 && !dgmslot->private_data) { event_loop_once(dgmsock->event_ctx); } response = talloc_get_type(dgmslot->private_data, struct nbt_netlogon_response); torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); torture_assert(tctx, response->response_type == NETLOGON_GET_PDC, "Got incorrect type of netlogon response"); torture_assert(tctx, response->data.get_pdc.command == NETLOGON_RESPONSE_FROM_PDC, "Got incorrect netlogon response command"); return true; }
/* test UDP/138 netlogon requests */ static bool nbt_test_netlogon2(struct torture_context *tctx) { struct dgram_mailslot_handler *dgmslot; struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx)); struct socket_address *dest; const char *myaddress; struct nbt_netlogon_packet logon; struct nbt_netlogon_response *response; struct nbt_name myname; NTSTATUS status; struct timeval tv = timeval_current(); struct socket_address *socket_address; const char *address; struct nbt_name name; struct interface *ifaces; struct test_join *join_ctx; struct cli_credentials *machine_credentials; const struct dom_sid *dom_sid; name.name = lp_workgroup(tctx->lp_ctx); name.type = NBT_NAME_LOGON; name.scope = NULL; /* do an initial name resolution to find its IP */ torture_assert_ntstatus_ok(tctx, resolve_name(lp_resolve_context(tctx->lp_ctx), &name, tctx, &address, tctx->ev), talloc_asprintf(tctx, "Failed to resolve %s", name.name)); load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces); myaddress = talloc_strdup(dgmsock, iface_best_ip(ifaces, address)); socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, myaddress, lp_dgram_port(tctx->lp_ctx)); torture_assert(tctx, socket_address != NULL, "Error getting address"); /* try receiving replies on port 138 first, which will only work if we are root and smbd/nmbd are not running - fall back to listening on any port, which means replies from some windows versions won't be seen */ status = socket_listen(dgmsock->sock, socket_address, 0, 0); if (!NT_STATUS_IS_OK(status)) { talloc_free(socket_address); socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, myaddress, 0); torture_assert(tctx, socket_address != NULL, "Error getting address"); socket_listen(dgmsock->sock, socket_address, 0, 0); } /* setup a temporary mailslot listener for replies */ dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, netlogon_handler, NULL); ZERO_STRUCT(logon); logon.command = LOGON_SAM_LOGON_REQUEST; logon.req.logon.request_count = 0; logon.req.logon.computer_name = TEST_NAME; logon.req.logon.user_name = ""; logon.req.logon.mailslot_name = dgmslot->mailslot_name; logon.req.logon.nt_version = NETLOGON_NT_VERSION_5EX_WITH_IP|NETLOGON_NT_VERSION_5|NETLOGON_NT_VERSION_1; logon.req.logon.lmnt_token = 0xFFFF; logon.req.logon.lm20_token = 0xFFFF; make_nbt_name_client(&myname, TEST_NAME); dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, address, lp_dgram_port(tctx->lp_ctx)); torture_assert(tctx, dest != NULL, "Error getting address"); status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, NBT_MAILSLOT_NETLOGON, &myname, &logon); torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); while (timeval_elapsed(&tv) < 5 && dgmslot->private_data == NULL) { event_loop_once(dgmsock->event_ctx); } response = talloc_get_type(dgmslot->private_data, struct nbt_netlogon_response); torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); map_netlogon_samlogon_response(&response->data.samlogon); torture_assert_int_equal(tctx, response->data.samlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX, "Got incorrect netlogon response command"); torture_assert_int_equal(tctx, response->data.samlogon.data.nt5_ex.nt_version, NETLOGON_NT_VERSION_5EX_WITH_IP|NETLOGON_NT_VERSION_5EX|NETLOGON_NT_VERSION_1, "Got incorrect netlogon response command"); /* setup (another) temporary mailslot listener for replies */ dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, netlogon_handler, NULL); ZERO_STRUCT(logon); logon.command = LOGON_SAM_LOGON_REQUEST; logon.req.logon.request_count = 0; logon.req.logon.computer_name = TEST_NAME; logon.req.logon.user_name = TEST_NAME"$"; logon.req.logon.mailslot_name = dgmslot->mailslot_name; logon.req.logon.nt_version = 1; logon.req.logon.lmnt_token = 0xFFFF; logon.req.logon.lm20_token = 0xFFFF; make_nbt_name_client(&myname, TEST_NAME); dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, address, lp_dgram_port(tctx->lp_ctx)); torture_assert(tctx, dest != NULL, "Error getting address"); status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, NBT_MAILSLOT_NETLOGON, &myname, &logon); torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); while (timeval_elapsed(&tv) < 5 && dgmslot->private_data == NULL) { event_loop_once(dgmsock->event_ctx); } response = talloc_get_type(dgmslot->private_data, struct nbt_netlogon_response); torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); map_netlogon_samlogon_response(&response->data.samlogon); torture_assert_int_equal(tctx, response->data.samlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN, "Got incorrect netlogon response command"); torture_assert_str_equal(tctx, response->data.samlogon.data.nt5_ex.user_name, TEST_NAME"$", "Got incorrect user in netlogon response"); join_ctx = torture_join_domain(tctx, TEST_NAME, ACB_WSTRUST, &machine_credentials); torture_assert(tctx, join_ctx != NULL, talloc_asprintf(tctx, "Failed to join domain %s as %s\n", lp_workgroup(tctx->lp_ctx), TEST_NAME)); dom_sid = torture_join_sid(join_ctx); /* setup (another) temporary mailslot listener for replies */ dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, netlogon_handler, NULL); ZERO_STRUCT(logon); logon.command = LOGON_SAM_LOGON_REQUEST; logon.req.logon.request_count = 0; logon.req.logon.computer_name = TEST_NAME; logon.req.logon.user_name = TEST_NAME"$"; logon.req.logon.mailslot_name = dgmslot->mailslot_name; logon.req.logon.sid = *dom_sid; logon.req.logon.nt_version = 1; logon.req.logon.lmnt_token = 0xFFFF; logon.req.logon.lm20_token = 0xFFFF; make_nbt_name_client(&myname, TEST_NAME); dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, address, lp_dgram_port(tctx->lp_ctx)); torture_assert(tctx, dest != NULL, "Error getting address"); status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, NBT_MAILSLOT_NETLOGON, &myname, &logon); torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); while (timeval_elapsed(&tv) < 5 && dgmslot->private_data == NULL) { event_loop_once(dgmsock->event_ctx); } response = talloc_get_type(dgmslot->private_data, struct nbt_netlogon_response); torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); map_netlogon_samlogon_response(&response->data.samlogon); torture_assert_int_equal(tctx, response->data.samlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN, "Got incorrect netlogon response command"); /* setup (another) temporary mailslot listener for replies */ dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, netlogon_handler, NULL); torture_assert(tctx, dgmslot != NULL, "Error getting a Mailslot for GetDC reply"); ZERO_STRUCT(logon); logon.command = LOGON_SAM_LOGON_REQUEST; logon.req.logon.request_count = 0; logon.req.logon.computer_name = TEST_NAME; logon.req.logon.user_name = TEST_NAME"$"; logon.req.logon.mailslot_name = dgmslot->mailslot_name; logon.req.logon.sid = *dom_sid; logon.req.logon.acct_control = ACB_WSTRUST; logon.req.logon.nt_version = 1; logon.req.logon.lmnt_token = 0xFFFF; logon.req.logon.lm20_token = 0xFFFF; make_nbt_name_client(&myname, TEST_NAME); dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, address, lp_dgram_port(tctx->lp_ctx)); torture_assert(tctx, dest != NULL, "Error getting address"); status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, NBT_MAILSLOT_NETLOGON, &myname, &logon); torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); while (timeval_elapsed(&tv) < 5 && dgmslot->private_data == NULL) { event_loop_once(dgmsock->event_ctx); } response = talloc_get_type(dgmslot->private_data, struct nbt_netlogon_response); torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); map_netlogon_samlogon_response(&response->data.samlogon); torture_assert_int_equal(tctx, response->data.samlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE, "Got incorrect netlogon response command"); dgmslot->private_data = NULL; ZERO_STRUCT(logon); logon.command = LOGON_SAM_LOGON_REQUEST; logon.req.logon.request_count = 0; logon.req.logon.computer_name = TEST_NAME; logon.req.logon.user_name = TEST_NAME"$"; logon.req.logon.mailslot_name = dgmslot->mailslot_name; logon.req.logon.sid = *dom_sid; logon.req.logon.acct_control = ACB_NORMAL; logon.req.logon.nt_version = 1; logon.req.logon.lmnt_token = 0xFFFF; logon.req.logon.lm20_token = 0xFFFF; make_nbt_name_client(&myname, TEST_NAME); dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, address, lp_dgram_port(tctx->lp_ctx)); torture_assert(tctx, dest != NULL, "Error getting address"); status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, NBT_MAILSLOT_NETLOGON, &myname, &logon); torture_assert_ntstatus_ok(tctx, status, "Failed to send netlogon request"); while (timeval_elapsed(&tv) < 5 && dgmslot->private_data == NULL) { event_loop_once(dgmsock->event_ctx); } response = talloc_get_type(dgmslot->private_data, struct nbt_netlogon_response); torture_assert(tctx, response != NULL, "Failed to receive a netlogon reply packet"); torture_assert_int_equal(tctx, response->response_type, NETLOGON_SAMLOGON, "Got incorrect type of netlogon response"); map_netlogon_samlogon_response(&response->data.samlogon); torture_assert_int_equal(tctx, response->data.samlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN, "Got incorrect netlogon response command"); torture_leave_domain(tctx, join_ctx); return true; }