Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
static NTSTATUS smb2srv_negprot_backend(struct smb2srv_request *req, struct smb2_negprot *io)
{
	NTSTATUS status;
	struct timeval current_time;
	struct timeval boot_time;

	req->smb_conn->negotiate.protocol = PROTOCOL_SMB2;

	current_time = timeval_current(); /* TODO: handle timezone?! */
	boot_time = timeval_current(); /* TODO: fix me */

	io->out._pad		= 0;
	io->out.unknown2	= 0x06;
	ZERO_STRUCT(io->out.sessid);
	io->out.unknown3	= 0x0d;
	io->out.unknown4	= 0x00;
	io->out.unknown5	= 0x01;
	io->out.unknown6	= 0x01;
	io->out.unknown7	= 0x01;
	io->out.current_time	= timeval_to_nttime(&current_time);
	io->out.boot_time	= timeval_to_nttime(&boot_time);
	status = smb2srv_negprot_secblob(req, &io->out.secblob);
	NT_STATUS_NOT_OK_RETURN(status);
	io->out.unknown9	= 0x204d4c20;

	return NT_STATUS_OK;
}
Ejemplo n.º 3
0
static NTSTATUS smb2srv_negprot_backend(struct smb2srv_request *req, struct smb2_negprot *io)
{
	NTSTATUS status;
	struct timeval current_time;
	struct timeval boot_time;
	uint16_t i;
	uint16_t dialect = 0;

	/* we only do one dialect for now */
	if (io->in.dialect_count < 1) {
		return NT_STATUS_NOT_SUPPORTED;
	}
	for (i=0; i < io->in.dialect_count; i++) {
		dialect = io->in.dialects[i];
		if (dialect == SMB2_DIALECT_REVISION_202) {
			break;
		}
	}
	if (dialect != SMB2_DIALECT_REVISION_202) {
		DEBUG(0,("Got unexpected SMB2 dialect %u\n", dialect));
		return NT_STATUS_NOT_SUPPORTED;
	}

	req->smb_conn->negotiate.protocol = PROTOCOL_SMB2_02;

	current_time = timeval_current(); /* TODO: handle timezone?! */
	boot_time = timeval_current(); /* TODO: fix me */

	ZERO_STRUCT(io->out);
	switch (lpcfg_server_signing(req->smb_conn->lp_ctx)) {
	case SMB_SIGNING_OFF:
		io->out.security_mode = 0;
		break;
	case SMB_SIGNING_SUPPORTED:
	case SMB_SIGNING_AUTO:
		io->out.security_mode = SMB2_NEGOTIATE_SIGNING_ENABLED;
		break;
	case SMB_SIGNING_REQUIRED:
		io->out.security_mode = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED;
		/* force signing on immediately */
		req->smb_conn->smb2_signing_required = true;
		break;
	}
	io->out.dialect_revision   = dialect;
	io->out.capabilities       = 0;
	io->out.max_transact_size  = lpcfg_parm_ulong(req->smb_conn->lp_ctx, NULL,
						   "smb2", "max transaction size", 0x10000);
	io->out.max_read_size      = lpcfg_parm_ulong(req->smb_conn->lp_ctx, NULL,
						   "smb2", "max read size", 0x10000);
	io->out.max_write_size     = lpcfg_parm_ulong(req->smb_conn->lp_ctx, NULL,
						   "smb2", "max write size", 0x10000);
	io->out.system_time	   = timeval_to_nttime(&current_time);
	io->out.server_start_time  = timeval_to_nttime(&boot_time);
	io->out.reserved2          = 0;
	status = smb2srv_negprot_secblob(req, &io->out.secblob);
	NT_STATUS_NOT_OK_RETURN(status);

	return NT_STATUS_OK;
}
Ejemplo n.º 4
0
/* Test the rate at which the server will accept connections.  */
bool torture_bench_treeconnect(struct torture_context *tctx)
{
	const char *host = torture_setting_string(tctx, "host", NULL);
	const char *share = torture_setting_string(tctx, "share", NULL);

	int timelimit = torture_setting_int(tctx, "timelimit",
					TIME_LIMIT_SECS);
	int nprocs = torture_setting_int(tctx, "nprocs", 4);

	int *curr_counts = map_count_buffer(nprocs, sizeof(int));
	int *last_counts = talloc_array(NULL, int, nprocs);

	struct timeval now, last, start;
	int i, delta;

	torture_assert(tctx, nprocs > 0, "bad proc count");
	torture_assert(tctx, timelimit > 0, "bad timelimit");
	torture_assert(tctx, curr_counts, "allocation failure");
	torture_assert(tctx, last_counts, "allocation failure");

	start = last = timeval_current();
	for (i = 0; i < nprocs; ++i) {
		fork_tcon_client(tctx, &curr_counts[i], timelimit, host, share);
	}

	while (children_remain()) {

		sleep(1);
		now = timeval_current();

		for (i = 0, delta = 0; i < nprocs; ++i) {
			delta += curr_counts[i] - last_counts[i];
		}

		printf("%u connections/sec\n",
			(unsigned)rate_convert_secs(delta, &last, &now));

		memcpy(last_counts, curr_counts, nprocs * sizeof(int));
		last = timeval_current();
	}

	now = timeval_current();

	for (i = 0, delta = 0; i < nprocs; ++i) {
		delta += curr_counts[i];
	}

	printf("TOTAL: %u connections/sec over %u secs\n",
			(unsigned)rate_convert_secs(delta, &start, &now),
			timelimit);
	return true;
}
Ejemplo n.º 5
0
int ctdb_statistics_init(struct ctdb_context *ctdb)
{
	bzero(&ctdb->statistics, sizeof(struct ctdb_statistics));
	ctdb->statistics.statistics_start_time = timeval_current();

	bzero(&ctdb->statistics_current, sizeof(struct ctdb_statistics));
	ctdb->statistics_current.statistics_start_time = timeval_current();

	bzero(ctdb->statistics_history, sizeof(ctdb->statistics_history));

	tevent_add_timer(ctdb->ev, ctdb,
			 timeval_current_ofs(ctdb->tunable.stat_history_interval, 0),
			 ctdb_statistics_update, ctdb);
	return 0;
}
Ejemplo n.º 6
0
void link_t::loop() {
	timeval_t last_conn = timeval_long_ago;

	while(true) {
		try {
			{
				timeval_t now = timeval_current();
				interval_t to_sleep = conn_timeout - (timeval_current() - last_conn);

				if(to_sleep > interval_zero && bq_sleep(&to_sleep) < 0)
					throw exception_sys_t(log::error, errno, "bq_sleep: %m");

			}

			last_conn = timeval_current();

			netaddr_t const &netaddr = remote_netaddr();

			int fd = socket(netaddr.sa->sa_family, SOCK_STREAM, 0);
			if(fd < 0)
				throw exception_sys_t(remote_errors, errno, "socket: %m");

			fd_guard_t fd_guard(fd);

			bq_fd_setup(fd);

			interval_t timeout = conn_timeout;

			if(bq_connect(fd, netaddr.sa, netaddr.sa_len, &timeout) < 0)
				throw exception_sys_t(remote_errors, errno, "connect: %m");

			log_debug("connected");

			bq_conn_fd_t conn(fd, ctl(), remote_errors, /* dup = */ true);

			proto_instance->proc(conn);
		}
		catch(exception_sys_t const &ex) {
			if(ex.errno_val == ECANCELED)
				throw;

			ex.log();
		}
		catch(exception_t const &ex) {
			ex.log();
		}
	}
}
Ejemplo n.º 7
0
void nb_setup(struct cli_state *cli)
{
	signal(SIGSEGV, sigsegv);
	c = cli;
	nb_start = timeval_current();
	children[nbio_id].done = 0;
}
Ejemplo n.º 8
0
/*
 * allocate a new session structure with a VUID.
 * gensec_ctx is optional, but talloc_steal'ed when present
 */
struct smbsrv_session *smbsrv_session_new(struct smbsrv_connection *smb_conn,
        TALLOC_CTX *mem_ctx,
        struct gensec_security *gensec_ctx)
{
    struct smbsrv_session *sess = NULL;
    int i;

    /* Ensure no vuid gets registered in share level security. */
    if (smb_conn->config.security == SEC_SHARE) return NULL;

    sess = talloc_zero(mem_ctx, struct smbsrv_session);
    if (!sess) return NULL;
    sess->smb_conn = smb_conn;

    i = idr_get_new_random(smb_conn->sessions.idtree_vuid, sess, smb_conn->sessions.idtree_limit);
    if (i == -1) {
        DEBUG(1,("ERROR! Out of connection structures\n"));
        talloc_free(sess);
        return NULL;
    }
    sess->vuid = i;

    /* use this to keep tabs on all our info from the authentication */
    sess->gensec_ctx = talloc_steal(sess, gensec_ctx);

    DLIST_ADD(smb_conn->sessions.list, sess);
    talloc_set_destructor(sess, smbsrv_session_destructor);

    /* now fill in some statistics */
    sess->statistics.connect_time = timeval_current();

    return sess;
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
static void _do_debug_v(const char *format, va_list ap)
{
	struct timeval t;
	char *s = NULL;
	struct tm *tm;
	char tbuf[100];
	int ret;

	ret = vasprintf(&s, format, ap);
	if (ret == -1) {
		fprintf(stderr, "vasprintf failed in _do_debug_v, cannot print debug message.\n");
		fflush(stderr);
		return;
	}

	t = timeval_current();
	tm = localtime(&t.tv_sec);

	strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);

	fprintf(stderr, "%s.%06u [%s%5u]: %s", tbuf, (unsigned)t.tv_usec,
		debug_extra, (unsigned)getpid(), s);
	fflush(stderr);
	free(s);
}
Ejemplo n.º 11
0
void check(ref_t<file_t> &file_ref, interval_t const &check_time) {
	file_t *file = file_ref;
	timeval_t time = timeval_current();

	if(time > file->check_time + check_time) {
		struct stat st;
		bool stat_res = (::stat(file->sys_name_z.ptr(), &st) >= 0 && S_ISREG(st.st_mode));
		if(
			stat_res
				? !*file || file->dev != st.st_dev || file->ino != st.st_ino
				: *file
		) {
			file_ref = file = new file_t(file->sys_name_z, time);
		}
		else if(stat_res) {
			timeval_t mtime = timeval_unix_origin + st.st_mtime * interval_second;

			if(st.st_size != file->size) {
				log_error("File \"%s\" incorrectly changed", file->sys_name_z.ptr());
				file->size = st.st_size;
			}

			if(mtime != file->mtime)
				file->mtime = mtime;
		}

		file->check_time = time;
	}

	file->access_time = time;
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
/*
 * Lock record / db depending on type
 */
static struct lock_request *ctdb_lock_internal(struct ctdb_context *ctdb,
					       struct ctdb_db_context *ctdb_db,
					       TDB_DATA key,
					       uint32_t priority,
					       void (*callback)(void *, bool),
					       void *private_data,
					       enum lock_type type,
					       bool auto_mark)
{
	struct lock_context *lock_ctx = NULL;
	struct lock_request *request;

	if (callback == NULL) {
		DEBUG(DEBUG_WARNING, ("No callback function specified, not locking\n"));
		return NULL;
	}

#if 0
	/* Disable this optimization to ensure first-in-first-out fair
	 * scheduling of lock requests */

	/* get a context for this key - search only the pending contexts,
	 * current contexts might in the middle of processing callbacks */
	lock_ctx = find_lock_context(ctdb->lock_pending, ctdb_db, key, priority, type);
#endif

	/* No existing context, create one */
	if (lock_ctx == NULL) {
		lock_ctx = talloc_zero(ctdb, struct lock_context);
		if (lock_ctx == NULL) {
			DEBUG(DEBUG_ERR, ("Failed to create a new lock context\n"));
			return NULL;
		}

		lock_ctx->type = type;
		lock_ctx->ctdb = ctdb;
		lock_ctx->ctdb_db = ctdb_db;
		lock_ctx->key.dsize = key.dsize;
		if (key.dsize > 0) {
			lock_ctx->key.dptr = talloc_memdup(lock_ctx, key.dptr, key.dsize);
		} else {
			lock_ctx->key.dptr = NULL;
		}
		lock_ctx->priority = priority;
		lock_ctx->auto_mark = auto_mark;

		lock_ctx->child = -1;
		lock_ctx->block_child = -1;

		DLIST_ADD_END(ctdb->lock_pending, lock_ctx, NULL);
		ctdb->lock_num_pending++;
		CTDB_INCREMENT_STAT(ctdb, locks.num_pending);
		if (ctdb_db) {
			CTDB_INCREMENT_DB_STAT(ctdb_db, locks.num_pending);
		}

		/* Start the timer when we activate the context */
		lock_ctx->start_time = timeval_current();
	}
Ejemplo n.º 14
0
/*
  called when a wins name register has completed
*/
static void nbtd_wins_register_handler(struct composite_context *c)
{
	NTSTATUS status;
	struct nbt_name_register_wins io;
	struct nbtd_iface_name *iname = talloc_get_type(c->async.private_data, 
							struct nbtd_iface_name);
	TALLOC_CTX *tmp_ctx = talloc_new(iname);

	status = nbt_name_register_wins_recv(c, tmp_ctx, &io);
	if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
		/* none of the WINS servers responded - try again 
		   periodically */
		int wins_retry_time = lp_parm_int(iname->iface->nbtsrv->task->lp_ctx, NULL, "nbtd", "wins_retry", 300);
		event_add_timed(iname->iface->nbtsrv->task->event_ctx, 
				iname,
				timeval_current_ofs(wins_retry_time, 0),
				nbtd_wins_register_retry,
				iname);
		talloc_free(tmp_ctx);
		return;
	}

	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1,("Name register failure with WINS for %s - %s\n", 
			 nbt_name_string(tmp_ctx, &iname->name), nt_errstr(status)));
		talloc_free(tmp_ctx);
		return;
	}	

	if (io.out.rcode != 0) {
		DEBUG(1,("WINS server %s rejected name register of %s - %s\n", 
			 io.out.wins_server, nbt_name_string(tmp_ctx, &iname->name), 
			 nt_errstr(nbt_rcode_to_ntstatus(io.out.rcode))));
		iname->nb_flags |= NBT_NM_CONFLICT;
		talloc_free(tmp_ctx);
		return;
	}	

	/* success - start a periodic name refresh */
	iname->nb_flags |= NBT_NM_ACTIVE;
	if (iname->wins_server) {
		/*
		 * talloc_free() would generate a warning,
		 * so steal it into the tmp context
		 */
		talloc_steal(tmp_ctx, iname->wins_server);
	}
	iname->wins_server = talloc_steal(iname, io.out.wins_server);

	iname->registration_time = timeval_current();
	nbtd_wins_start_refresh_timer(iname);

	DEBUG(3,("Registered %s with WINS server %s\n",
		 nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));

	talloc_free(tmp_ctx);
}
Ejemplo n.º 15
0
static void ctdb_statistics_update(struct tevent_context *ev,
				   struct tevent_timer *te,
				   struct timeval t, void *p)
{
	struct ctdb_context *ctdb = talloc_get_type(p, struct ctdb_context);

	memmove(&ctdb->statistics_history[1], &ctdb->statistics_history[0], (MAX_STAT_HISTORY-1)*sizeof(struct ctdb_statistics));
	memcpy(&ctdb->statistics_history[0], &ctdb->statistics_current, sizeof(struct ctdb_statistics));
	ctdb->statistics_history[0].statistics_current_time = timeval_current();


	bzero(&ctdb->statistics_current, sizeof(struct ctdb_statistics));
	ctdb->statistics_current.statistics_start_time = timeval_current();

	tevent_add_timer(ctdb->ev, ctdb,
			 timeval_current_ofs(ctdb->tunable.stat_history_interval, 0),
			 ctdb_statistics_update, ctdb);
}
Ejemplo n.º 16
0
static bool recalc_brl_timeout(void)
{
	struct blocking_lock_record *blr;
	struct timeval next_timeout;

	TALLOC_FREE(brl_timeout);

	next_timeout = timeval_zero();	

	for (blr = blocking_lock_queue; blr; blr = blr->next) {
		if (timeval_is_zero(&blr->expire_time)) {
			/*
			 * If we're blocked on pid 0xFFFFFFFF this is
			 * a POSIX lock, so calculate a timeout of
			 * 10 seconds into the future.
			 */
                        if (blr->blocking_pid == 0xFFFFFFFF) {
				struct timeval psx_to = timeval_current_ofs(10, 0);
				next_timeout = timeval_min(&next_timeout, &psx_to);
                        }

			continue;
		}

		if (timeval_is_zero(&next_timeout)) {
			next_timeout = blr->expire_time;
		}
		else {
			next_timeout = timeval_min(&next_timeout,
						   &blr->expire_time);
		}
	}

	if (timeval_is_zero(&next_timeout)) {
		DEBUG(10, ("Next timeout = Infinite.\n"));
		return True;
	}

	if (DEBUGLVL(10)) {
		struct timeval cur, from_now;

		cur = timeval_current();
		from_now = timeval_until(&cur, &next_timeout);
		DEBUG(10, ("Next timeout = %d.%d seconds from now.\n",
		    (int)from_now.tv_sec, (int)from_now.tv_usec));
	}

	if (!(brl_timeout = event_add_timed(smbd_event_context(), NULL,
					    next_timeout,
					    brl_timeout_fn, NULL))) {
		return False;
	}

	return True;
}
Ejemplo n.º 17
0
/*
  called when a wins name refresh has completed
*/
static void nbtd_wins_refresh_handler(struct composite_context *c)
{
	NTSTATUS status;
	struct nbt_name_refresh_wins io;
	struct nbtd_iface_name *iname = talloc_get_type(c->async.private_data, 
							struct nbtd_iface_name);
	TALLOC_CTX *tmp_ctx = talloc_new(iname);

	status = nbt_name_refresh_wins_recv(c, tmp_ctx, &io);
	if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
		/* our WINS server is dead - start registration over
		   from scratch */
		DEBUG(2,("Failed to refresh %s with WINS server %s\n",
			 nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));
		talloc_free(tmp_ctx);
		nbtd_winsclient_register(iname);
		return;
	}

	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1,("Name refresh failure with WINS for %s - %s\n", 
			 nbt_name_string(tmp_ctx, &iname->name), nt_errstr(status)));
		talloc_free(tmp_ctx);
		return;
	}

	if (io.out.rcode != 0) {
		DEBUG(1,("WINS server %s rejected name refresh of %s - %s\n", 
			 io.out.wins_server, nbt_name_string(tmp_ctx, &iname->name), 
			 nt_errstr(nbt_rcode_to_ntstatus(io.out.rcode))));
		iname->nb_flags |= NBT_NM_CONFLICT;
		talloc_free(tmp_ctx);
		return;
	}	

	DEBUG(4,("Refreshed name %s with WINS server %s\n",
		 nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));
	/* success - start a periodic name refresh */
	iname->nb_flags |= NBT_NM_ACTIVE;
	if (iname->wins_server) {
		/*
		 * talloc_free() would generate a warning,
		 * so steal it into the tmp context
		 */
		talloc_steal(tmp_ctx, iname->wins_server);
	}
	iname->wins_server = talloc_steal(iname, io.out.wins_server);

	iname->registration_time = timeval_current();
	nbtd_wins_start_refresh_timer(iname);

	talloc_free(tmp_ctx);
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
0
void nbio_shmem(int n, int t_timelimit, int t_warmup)
{
	nprocs = n;
	children = anonymous_shared_allocate(sizeof(*children) * nprocs);
	if (!children) {
		printf("Failed to setup shared memory!\n");
		nb_exit(1);
	}
	memset(children, 0, sizeof(*children) * nprocs);
	timelimit = t_timelimit;
	warmup = t_warmup;
	in_cleanup = 0;
	tv_start = timeval_current();
}
Ejemplo n.º 20
0
static NTSTATUS lsa_secret_set_common(TALLOC_CTX *mem_ctx,
				      const char *key,
				      struct lsa_secret *secret,
				      DATA_BLOB *secret_current,
				      DATA_BLOB *secret_old,
				      struct security_descriptor *sd)
{
	enum ndr_err_code ndr_err;
	DATA_BLOB blob;
	struct timeval now = timeval_current();

	if (!secret) {
		secret = talloc_zero(mem_ctx, struct lsa_secret);
	}
Ejemplo n.º 21
0
struct timeval *get_timed_events_timeout(struct timeval *to_ret)
{
    struct timeval now;

    if (timed_events == NULL) {
        return NULL;
    }

    now = timeval_current();
    *to_ret = timeval_until(&now, &timed_events->when);

    DEBUG(10, ("timed_events_timeout: %d/%d\n", (int)to_ret->tv_sec,
               (int)to_ret->tv_usec));

    return to_ret;
}
Ejemplo n.º 22
0
/*
  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);
    }
}
Ejemplo n.º 23
0
/*
 * the session will be marked as valid for usage
 * by attaching a auth_session_info to the session.
 *
 * session_info will be talloc_stealed
 */
NTSTATUS smbsrv_session_sesssetup_finished(struct smbsrv_session *sess,
        struct auth_session_info *session_info)
{
    /* this check is to catch programmer errors */
    if (!session_info) {
        talloc_free(sess);
        return NT_STATUS_ACCESS_DENIED;
    }

    /* mark the session as successful authenticated */
    sess->session_info = talloc_steal(sess, session_info);

    /* now fill in some statistics */
    sess->statistics.auth_time = timeval_current();

    return NT_STATUS_OK;
}
Ejemplo n.º 24
0
/*
  one child operation
 */
static void child_op(struct child_struct *child, const char *opname,
		     const char *fname, const char *fname2, 
		     char **params, const char *status)
{
	static struct dbench_op prev_op;
	struct dbench_op op;
	unsigned i;

	child->lasttime = timeval_current();

	ZERO_STRUCT(op);
	op.child = child;
	op.op = opname;
	op.fname = fname;
	op.fname2 = fname2;
	op.status = status;
	for (i=0;i<sizeof(op.params)/sizeof(op.params[0]);i++) {
		switch (params[i][0]) {
		case '*':
		case '+':
			op.params[i] = parse_special(params[i], prev_op.params[i]);
			break;
		default:
			op.params[i] = params[i]?ival(params[i]):0;
		}
	}

	prev_op = op;

	if (strcasecmp(op.op, "Sleep") == 0) {
		nb_sleep(op.params[0]);
		return;
	}

	for (i=0;nb_ops->ops[i].name;i++) {
		if (strcasecmp(op.op, nb_ops->ops[i].name) == 0) {
			nb_ops->ops[i].fn(&op);
			finish_op(child, &child->ops[i]);
			return;
		}
	}

	printf("[%u] Unknown operation %s in pid %u\n", 
	       child->line, op.op, (unsigned)getpid());
}
Ejemplo n.º 25
0
/*
  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;
}
Ejemplo n.º 26
0
Archivo: dir.c Proyecto: AllardJ/Tomato
/*
  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;
}
Ejemplo n.º 27
0
/*
  get pending ops info for a specified DN
*/
static WERROR kccdrs_replica_get_info_pending_ops(TALLOC_CTX *mem_ctx,
						  struct ldb_context *samdb,
						  struct drsuapi_DsReplicaGetInfo *r,
						  union drsuapi_DsReplicaInfo *reply,
						  struct ldb_dn *dn)
{
	struct timeval now = timeval_current();

	if (!ldb_dn_validate(dn)) {
		return WERR_INVALID_PARAMETER;
	}
	reply->pendingops = talloc(mem_ctx, struct drsuapi_DsReplicaOpCtr);
	W_ERROR_HAVE_NO_MEMORY(reply->pendingops);

	/* claim no pending ops for now */
	reply->pendingops->time = timeval_to_nttime(&now);
	reply->pendingops->count = 0;
	reply->pendingops->array = NULL;

	return WERR_OK;
}
Ejemplo n.º 28
0
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;
}
Ejemplo n.º 29
0
static NTSTATUS create_sys_acl_blob(const struct security_descriptor *psd,
				    DATA_BLOB *pblob,
				    uint16_t hash_type,
				    uint8_t hash[XATTR_SD_HASH_SIZE],
				    const char *description,
				    uint8_t sys_acl_hash[XATTR_SD_HASH_SIZE])
{
	struct xattr_NTACL xacl;
	struct security_descriptor_hash_v4 sd_hs4;
	enum ndr_err_code ndr_err;
	TALLOC_CTX *ctx = talloc_tos();
	NTTIME nttime_now;
	struct timeval now = timeval_current();
	nttime_now = timeval_to_nttime(&now);

	ZERO_STRUCT(xacl);
	ZERO_STRUCT(sd_hs4);

	xacl.version = 4;
	xacl.info.sd_hs4 = &sd_hs4;
	xacl.info.sd_hs4->sd = discard_const_p(struct security_descriptor, psd);
	xacl.info.sd_hs4->hash_type = hash_type;
	memcpy(&xacl.info.sd_hs4->hash[0], hash, XATTR_SD_HASH_SIZE);
	xacl.info.sd_hs4->description = description;
	xacl.info.sd_hs4->time = nttime_now;
	memcpy(&xacl.info.sd_hs4->sys_acl_hash[0], sys_acl_hash, XATTR_SD_HASH_SIZE);

	ndr_err = ndr_push_struct_blob(
			pblob, ctx, &xacl,
			(ndr_push_flags_fn_t)ndr_push_xattr_NTACL);

	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		DEBUG(5, ("create_acl_blob: ndr_push_xattr_NTACL failed: %s\n",
			ndr_errstr(ndr_err)));
		return ndr_map_error2ntstatus(ndr_err);
	}

	return NT_STATUS_OK;
}
Ejemplo n.º 30
0
void ccache_regain_all_now(void)
{
	struct WINBINDD_CCACHE_ENTRY *cur;
	struct timeval t = timeval_current();

	for (cur = ccache_list; cur; cur = cur->next) {
		struct tevent_timer *new_event;

		/*
		 * if refresh_time is 0, we know that the
		 * the event has the krb5_ticket_gain_handler
		 */
		if (cur->refresh_time == 0) {
			new_event = tevent_add_timer(winbind_event_context(),
						    cur,
						    t,
						    krb5_ticket_gain_handler,
						    cur);
		} else {
			new_event = tevent_add_timer(winbind_event_context(),
						    cur,
						    t,
						    krb5_ticket_refresh_handler,
						    cur);
		}

		if (!new_event) {
			continue;
		}

		TALLOC_FREE(cur->event);
		cur->event = new_event;
	}

	return;
}