Exemplo n.º 1
0
 int main(int argc, char *argv[])
{
	pid_t pid;
	int i, n;
	static pstring servicesf = CONFIGFILE;
	char buf[12];

	TimeInit();
	setup_logging(argv[0],True);
	
	charset_initialise();

	lp_load(servicesf,False,False,False);

	message_init();

	if (argc != 3) {
		fprintf(stderr, "%s: Usage - %s pid count\n", argv[0], argv[0]);
		exit(1);
	}

	pid = atoi(argv[1]);
	n = atoi(argv[2]);

	message_register(MSG_PONG, pong_message);

	for (i=0;i<n;i++) {
		message_send_pid(pid, MSG_PING, NULL, 0, True);
	}

	while (pong_count < i) {
		message_dispatch();
		msleep(1);
	}

	/* Now test that the duplicate filtering code works. */
	pong_count = 0;

	safe_strcpy(buf, "1234567890", sizeof(buf)-1);

	for (i=0;i<n;i++) {
		message_send_pid(getpid(), MSG_PING, NULL, 0, False);
		message_send_pid(getpid(), MSG_PING, buf, 11, False);
	}

	for (i=0;i<n;i++) {
		message_dispatch();
		msleep(1);
	}

	if (pong_count != 2) {
		fprintf(stderr, "Duplicate filter failed (%d).\n", pong_count);
		exit(1);
	}

	return (0);
}
Exemplo n.º 2
0
static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
	struct connections_data crec;
	struct msg_all *msg_all = (struct msg_all *)state;

	if (dbuf.dsize != sizeof(crec))
		return 0;

	memcpy(&crec, dbuf.dptr, sizeof(crec));

	if (crec.cnum != -1)
		return 0;

	/* if the msg send fails because the pid was not found (i.e. smbd died), 
	 * the msg has already been deleted from the messages.tdb.*/
	if (!message_send_pid(crec.pid, msg_all->msg_type,
			      msg_all->buf, msg_all->len,
			      msg_all->duplicates)) {
		
		/* if the pid was not found delete the entry from connections.tdb */
		if (errno == ESRCH) {
			DEBUG(2,("pid %u doesn't exist - deleting connections %d [%s]\n",
					(unsigned int)crec.pid, crec.cnum, crec.name));
			tdb_delete(the_tdb, kbuf);
		}
	}
	msg_all->n_sent++;
	return 0;
}
Exemplo n.º 3
0
static BOOL send_message(pid_t pid, int msg_type, const void *buf, int len,
			 BOOL duplicates)
{
	TDB_CONTEXT *tdb;
	BOOL ret;
	int n_sent = 0;

	if (!message_init())
		return False;

	if (pid != 0)
		return message_send_pid(pid, msg_type, buf, len, duplicates);

	tdb = tdb_open_log(lock_path("connections.tdb"), 0, 
			   TDB_DEFAULT, O_RDWR, 0);
	if (!tdb) {
		fprintf(stderr,"Failed to open connections database"
			": %s\n", strerror(errno));
		return False;
	}
	
	ret = message_send_all(tdb,msg_type, buf, len, duplicates,
			       &n_sent);
	DEBUG(10,("smbcontrol/send_message: broadcast message to "
		  "%d processes\n", n_sent));
	
	tdb_close(tdb);
	
	return ret;
}
Exemplo n.º 4
0
static void notify_deferred_opens(struct share_mode_lock *lck)
{
 	int i;
 
 	for (i=0; i<lck->num_share_modes; i++) {
 		struct share_mode_entry *e = &lck->share_modes[i];
 
 		if (!is_deferred_open_entry(e)) {
 			continue;
 		}
 
 		if (procid_is_me(&e->pid)) {
 			/*
 			 * We need to notify ourself to retry the open.  Do
 			 * this by finding the queued SMB record, moving it to
 			 * the head of the queue and changing the wait time to
 			 * zero.
 			 */
 			schedule_deferred_open_smb_message(e->op_mid);
 		} else {
			char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];

			share_mode_entry_to_message(msg, e);

 			message_send_pid(e->pid, MSG_SMB_OPEN_RETRY,
 					 msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
 		}
 	}
}
Exemplo n.º 5
0
/****************************************************************************
send a "set debug level" message
****************************************************************************/
void debug_message_send(pid_t pid, const char *params_str)
{
    if (!params_str)
        return;
    message_send_pid(pid, MSG_DEBUG, params_str, strlen(params_str) + 1,
                     False);
}
Exemplo n.º 6
0
/****************************************************************************
send a message to a named destination
****************************************************************************/
static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL duplicates)
{
	BOOL retval = False;
	pid_t pid = 0;
	TDB_CONTEXT *the_tdb;

	the_tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDWR, 0);
	if (!the_tdb) {
		fprintf(stderr,"Failed to open connections database in send_message.\n");
		return False;
	}

	/* "smbd" is the only broadcast operation */
	if (strequal(dest,"smbd")) {
		retval = message_send_all(the_tdb,msg_type, buf, len, duplicates, NULL);
	} else if (strequal(dest,"nmbd")) {
		pid = pidfile_pid(dest);
		if (pid == 0) {
			fprintf(stderr,"Can't find pid for nmbd\n");
		}
	} else if (strequal(dest,"self")) {
		pid = getpid();
	} else {
		pid = atoi(dest);
		if (pid == 0) {
			fprintf(stderr,"Not a valid pid\n");
		}		
	} 

	tdb_close(the_tdb);
	if (pid)
		return message_send_pid(pid, msg_type, buf, len, duplicates);
	else
		return retval;
}
Exemplo n.º 7
0
Arquivo: status.c Projeto: aosm/samba
static BOOL send_status_message(struct process_id pid)
{
	TDB_CONTEXT *tdb;
	BOOL ret;
	int n_sent = 0;

	if (!message_init())
		return False;

	if (procid_to_pid(&pid) != 0) {
		return NT_STATUS_IS_OK(message_send_pid(pid, MSG_USR_STATS,
				    NULL, 0, False /* duplicates */));
	}

	tdb = tdb_open_log(lock_path("connections.tdb"), 0,
			   TDB_DEFAULT, O_RDWR, 0);
	if (!tdb) {
		fprintf(stderr,"Failed to open connections database"
			": %s\n", strerror(errno));
		return False;
	}

	ret = message_send_all(tdb, MSG_USR_STATS, NULL, 0,
				False /* duplicates */, &n_sent);
	DEBUG(10,("smbcontrol/send_message: broadcast message to "
		  "%d processes\n", n_sent));
	tdb_close(tdb);
	return ret;
}
Exemplo n.º 8
0
/**
 * Respond to a POOL_USAGE message by sending back string form of memory
 * usage stats.
 **/
void msg_pool_usage(int msg_type, struct process_id src_pid,
		    void *UNUSED(buf), size_t UNUSED(len),
		    void *private_data)
{
	struct msg_pool_usage_state state;

	SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE);
	
	DEBUG(2,("Got POOL_USAGE\n"));

	state.mem_ctx = talloc_init("msg_pool_usage");
	if (!state.mem_ctx) {
		return;
	}
	state.len	= 0;
	state.buflen	= 512;
	state.s		= NULL;

	talloc_report_depth_cb(NULL, 0, -1, msg_pool_usage_helper, &state);

	if (!state.s) {
		talloc_destroy(state.mem_ctx);
		return;
	}
	
	message_send_pid(src_pid, MSG_POOL_USAGE,
			 state.s, strlen(state.s)+1, True);

	talloc_destroy(state.mem_ctx);
}
Exemplo n.º 9
0
static void ping_message(int msg_type, struct process_id src,
			 void *buf, size_t len)
{
	const char *msg = buf ? buf : "none";

	DEBUG(1,("INFO: Received PING message from PID %s [%s]\n",
		 procid_str_static(&src), msg));
	message_send_pid(src, MSG_PONG, buf, len, True);
}
Exemplo n.º 10
0
static void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len)
{
    char *message = debug_list_class_names_and_levels();

    DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",(unsigned int)src));
    message_send_pid(src, MSG_DEBUGLEVEL, message, strlen(message) + 1, True);

    SAFE_FREE(message);
}
Exemplo n.º 11
0
static int shutdown_other_smbds(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
				void *p)
{
	struct sessionid *sessionid = (struct sessionid *)dbuf.dptr;
	const char *ip = (const char *)p;

	if (!process_exists(pid_to_procid(sessionid->pid))) {
		return 0;
	}

	if (sessionid->pid == sys_getpid()) {
		return 0;
	}

	if (strcmp(ip, sessionid->ip_addr) != 0) {
		return 0;
	}

	message_send_pid(pid_to_procid(sessionid->pid), MSG_SHUTDOWN,
			 NULL, 0, True);
	return 0;
}
Exemplo n.º 12
0
BOOL rename_share_filename(struct share_mode_lock *lck,
			const char *servicepath,
			const char *newname)
{
	size_t sp_len;
	size_t fn_len;
	size_t msg_len;
	char *frm = NULL;
	int i;

	if (!lck) {
		return False;
	}

	DEBUG(10, ("rename_share_filename: servicepath %s newname %s\n",
		servicepath, newname));

	/*
	 * rename_internal_fsp() and rename_internals() add './' to
	 * head of newname if newname does not contain a '/'.
	 */
	while (newname[0] && newname[1] && newname[0] == '.' && newname[1] == '/') {
		newname += 2;
	}

	lck->servicepath = talloc_strdup(lck, servicepath);
	lck->filename = talloc_strdup(lck, newname);
	if (lck->filename == NULL || lck->servicepath == NULL) {
		DEBUG(0, ("rename_share_filename: talloc failed\n"));
		return False;
	}
	lck->modified = True;

	sp_len = strlen(lck->servicepath);
	fn_len = strlen(lck->filename);

	msg_len = MSG_FILE_RENAMED_MIN_SIZE + sp_len + 1 + fn_len + 1;

	/* Set up the name changed message. */
	frm = TALLOC(lck, msg_len);
	if (!frm) {
		return False;
	}

	SDEV_T_VAL(frm,0,lck->dev);
	SINO_T_VAL(frm,8,lck->ino);

	DEBUG(10,("rename_share_filename: msg_len = %u\n", (unsigned int)msg_len ));

	safe_strcpy(&frm[16], lck->servicepath, sp_len);
	safe_strcpy(&frm[16 + sp_len + 1], lck->filename, fn_len);

	/* Send the messages. */
	for (i=0; i<lck->num_share_modes; i++) {
		struct share_mode_entry *se = &lck->share_modes[i];
		if (!is_valid_share_mode_entry(se)) {
			continue;
		}
		/* But not to ourselves... */
		if (procid_is_me(&se->pid)) {
			continue;
		}

		DEBUG(10,("rename_share_filename: sending rename message to pid %u "
			"dev %x, inode  %.0f sharepath %s newname %s\n",
			(unsigned int)procid_to_pid(&se->pid),
			(unsigned int)lck->dev, (double)lck->ino,
			lck->servicepath, lck->filename ));

		become_root();
		message_send_pid(se->pid, MSG_SMB_FILE_RENAME,
				frm, msg_len, True);
		unbecome_root();
	}

	return True;
}
Exemplo n.º 13
0
void brl_close(SMB_DEV_T dev, SMB_INO_T ino, pid_t pid, int tid, int fnum)
{
	TDB_DATA kbuf, dbuf;
	int count, i, j, dcount=0;
	struct lock_struct *locks;

	kbuf = locking_key(dev,ino);

	dbuf.dptr = NULL;

	tdb_chainlock(tdb, kbuf);
	dbuf = tdb_fetch(tdb, kbuf);

	if (!dbuf.dptr) goto fail;

	/* there are existing locks - remove any for this fnum */
	locks = (struct lock_struct *)dbuf.dptr;
	count = dbuf.dsize / sizeof(*locks);

	for (i=0; i<count; i++) {
		struct lock_struct *lock = &locks[i];

		if (lock->context.tid == tid &&
		    lock->context.pid == pid &&
		    lock->fnum == fnum) {

			/* Send unlock messages to any pending waiters that overlap. */
			for (j=0; j<count; j++) {
				struct lock_struct *pend_lock = &locks[j];

				/* Ignore our own or non-pending locks. */
				if (pend_lock->lock_type != PENDING_LOCK)
					continue;

				if (pend_lock->context.tid == tid &&
				    pend_lock->context.pid == pid &&
				    pend_lock->fnum == fnum)
					continue;

				/* We could send specific lock info here... */
				if (brl_pending_overlap(lock, pend_lock))
					message_send_pid(pend_lock->context.pid,
							MSG_SMB_UNLOCK,
							NULL, 0, True);
			}

			/* found it - delete it */
			if (count > 1 && i < count-1) {
				memmove(&locks[i], &locks[i+1], 
					sizeof(*locks)*((count-1) - i));
			}
			count--;
			i--;
			dcount++;
		}
	}

	if (count == 0) {
		tdb_delete(tdb, kbuf);
	} else if (count < (dbuf.dsize / sizeof(*locks))) {
		dbuf.dsize -= dcount * sizeof(*locks);
		tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
	}

	/* we didn't find it */
 fail:
	SAFE_FREE(dbuf.dptr);
	tdb_chainunlock(tdb, kbuf);
}
Exemplo n.º 14
0
BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, int fnum,
		uint16 smbpid, pid_t pid, uint16 tid,
		br_off start, br_off size,
		BOOL remove_pending_locks_only)
{
	TDB_DATA kbuf, dbuf;
	int count, i, j;
	struct lock_struct *locks;
	struct lock_context context;

	kbuf = locking_key(dev,ino);

	dbuf.dptr = NULL;

	tdb_chainlock(tdb, kbuf);
	dbuf = tdb_fetch(tdb, kbuf);

	if (!dbuf.dptr) {
		DEBUG(10,("brl_unlock: tdb_fetch failed !\n"));
		goto fail;
	}

	context.smbpid = smbpid;
	context.pid = pid;
	context.tid = tid;

	/* there are existing locks - find a match */
	locks = (struct lock_struct *)dbuf.dptr;
	count = dbuf.dsize / sizeof(*locks);

#if ZERO_ZERO
	for (i=0; i<count; i++) {
		struct lock_struct *lock = &locks[i];

		if (lock->lock_type == WRITE_LOCK &&
		    brl_same_context(&lock->context, &context) &&
		    lock->fnum == fnum &&
		    lock->start == start &&
		    lock->size == size) {
			/* found it - delete it */
			if (count == 1) {
				tdb_delete(tdb, kbuf);
			} else {
				if (i < count-1) {
					memmove(&locks[i], &locks[i+1], 
						sizeof(*locks)*((count-1) - i));
				}
				dbuf.dsize -= sizeof(*locks);
				tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
			}

			SAFE_FREE(dbuf.dptr);
			tdb_chainunlock(tdb, kbuf);
			return True;
		}
	}
#endif

	locks = (struct lock_struct *)dbuf.dptr;
	count = dbuf.dsize / sizeof(*locks);
	for (i=0; i<count; i++) {
		struct lock_struct *lock = &locks[i];

		if (brl_same_context(&lock->context, &context) &&
				lock->fnum == fnum &&
				lock->start == start &&
				lock->size == size) {

			if (remove_pending_locks_only && lock->lock_type != PENDING_LOCK)
				continue;

			if (lock->lock_type != PENDING_LOCK) {
				/* Send unlock messages to any pending waiters that overlap. */
				for (j=0; j<count; j++) {
					struct lock_struct *pend_lock = &locks[j];

					/* Ignore non-pending locks. */
					if (pend_lock->lock_type != PENDING_LOCK)
						continue;

					/* We could send specific lock info here... */
					if (brl_pending_overlap(lock, pend_lock)) {
						DEBUG(10,("brl_unlock: sending unlock message to pid %u\n",
									(unsigned int)pend_lock->context.pid ));

						message_send_pid(pend_lock->context.pid,
								MSG_SMB_UNLOCK,
								NULL, 0, True);
					}
				}
			}

			/* found it - delete it */
			if (count == 1) {
				tdb_delete(tdb, kbuf);
			} else {
				if (i < count-1) {
					memmove(&locks[i], &locks[i+1], 
						sizeof(*locks)*((count-1) - i));
				}
				dbuf.dsize -= sizeof(*locks);
				tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
			}

			SAFE_FREE(dbuf.dptr);
			tdb_chainunlock(tdb, kbuf);
			return True;
		}
	}

	/* we didn't find it */

 fail:
	SAFE_FREE(dbuf.dptr);
	tdb_chainunlock(tdb, kbuf);
	return False;
}
Exemplo n.º 15
0
void ping_message(int msg_type, pid_t src, void *buf, size_t len)
{
	const char *msg = buf ? buf : "none";
	DEBUG(1,("INFO: Received PING message from PID %u [%s]\n",(unsigned int)src, msg));
	message_send_pid(src, MSG_PONG, buf, len, True);
}
Exemplo n.º 16
0
void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len)
{
	DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",(unsigned int)src));
	message_send_pid(src, MSG_DEBUGLEVEL, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS), True);
}
Exemplo n.º 17
0
Arquivo: debug.c Projeto: jophxy/samba
/****************************************************************************
send a "set debug level" message
****************************************************************************/
void debug_message_send(pid_t pid, int level)
{
	message_send_pid(pid, MSG_DEBUG, &level, sizeof(int), False);
}