예제 #1
0
파일: status.c 프로젝트: aosm/samba
static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
	struct sessionid sessionid;
	fstring uid_str, gid_str;

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

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

	if (!process_exists_by_pid(sessionid.pid) || !Ucrit_checkUid(sessionid.uid)) {
		return 0;
	}

	Ucrit_addPid( sessionid.pid );

	fstr_sprintf(uid_str, "%d", sessionid.uid);
	fstr_sprintf(gid_str, "%d", sessionid.gid);

	d_printf("%5d   %-12s  %-12s  %-12s (%s)\n",
		 (int)sessionid.pid,
		 numeric_only ? uid_str : uidtoname(sessionid.uid),
		 numeric_only ? gid_str : gidtoname(sessionid.gid), 
		 sessionid.remote_machine, sessionid.hostname);
	
	return 0;
}
예제 #2
0
파일: pidfile.c 프로젝트: gojdic/samba
/* return the pid in a pidfile. return 0 if the process (or pidfile)
   does not exist */
pid_t pidfile_pid(const char *name)
{
	int fd;
	char pidstr[20];
	pid_t pid;
	unsigned int ret;
	char * pidFile;

	if (asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name) == -1) {
		return 0;
	}

	fd = sys_open(pidFile, O_NONBLOCK | O_RDONLY, 0644);
	if (fd == -1) {
		SAFE_FREE(pidFile);
		return 0;
	}

	ZERO_ARRAY(pidstr);

	if (read(fd, pidstr, sizeof(pidstr)-1) <= 0) {
		goto noproc;
	}

	ret = atoi(pidstr);

	if (ret == 0) {
		/* Obviously we had some garbage in the pidfile... */
		DEBUG(1, ("Could not parse contents of pidfile %s\n",
			  pidFile));
		goto noproc;
	}
	
	pid = (pid_t)ret;
	if (!process_exists_by_pid(pid)) {
		goto noproc;
	}

	if (fcntl_lock(fd,SMB_F_SETLK,0,1,F_RDLCK)) {
		/* we could get the lock - it can't be a Samba process */
		goto noproc;
	}

	SAFE_FREE(pidFile);
	close(fd);
	return (pid_t)ret;

 noproc:
	close(fd);
	unlink(pidFile);
	SAFE_FREE(pidFile);
	return 0;
}
예제 #3
0
void sync_check_completion(void)
{
	struct sync_record *s, *next;

	for (s=syncs;s;s=next) {
		next = s->next;
		if (!process_exists_by_pid(s->pid)) {
			/* it has completed - grab the info */
			complete_sync(s);
			DLIST_REMOVE(syncs, s);
			SAFE_FREE(s->fname);
			SAFE_FREE(s);
		}
	}
}
예제 #4
0
/**
 * return the pid in a pidfile. return 0 if the process (or pidfile)
 * does not exist 
 */
pid_t pidfile_pid(const char *piddir, const char *name)
{
	int fd;
	char pidstr[20];
	pid_t ret;
	char *pidFile;

	if (asprintf(&pidFile, "%s/%s.pid", piddir, name) < 0) {
		return 0;
	}

	fd = open(pidFile, O_NONBLOCK | O_RDONLY, 0644);

	if (fd == -1) {
		SAFE_FREE(pidFile);
		return 0;
	}

	ZERO_STRUCT(pidstr);

	if (read(fd, pidstr, sizeof(pidstr)-1) <= 0) {
		goto noproc;
	}

	ret = (pid_t)atoi(pidstr);
	
	if (!process_exists_by_pid(ret)) {
		goto noproc;
	}

	if (fcntl_lock(fd,F_SETLK,0,1,F_RDLCK)) {
		/* we could get the lock - it can't be a Samba process */
		goto noproc;
	}

	close(fd);
	SAFE_FREE(pidFile);
	return ret;

 noproc:
	close(fd);
	unlink(pidFile);
	SAFE_FREE(pidFile);
	return 0;
}
예제 #5
0
static bool serverid_exists_local(const struct server_id *id)
{
	bool exists = process_exists_by_pid(id->pid);
	uint64_t unique;
	int ret;

	if (!exists) {
		return false;
	}

	if (id->unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) {
		return true;
	}

	ret = messaging_dgm_get_unique(id->pid, &unique);
	if (ret != 0) {
		return false;
	}

	return (unique == id->unique_id);
}
예제 #6
0
파일: serverid.c 프로젝트: Gazzonyx/samba
bool serverids_exist(const struct server_id *ids, int num_ids, bool *results)
{
	int *todo_idx = NULL;
	struct server_id *todo_ids = NULL;
	bool *todo_results = NULL;
	int todo_num = 0;
	int *remote_idx = NULL;
	int remote_num = 0;
	int *verify_idx = NULL;
	int verify_num = 0;
	int t, idx;
	bool result = false;
	struct db_context *db;

	db = serverid_db();
	if (db == NULL) {
		return false;
	}

	todo_idx = talloc_array(talloc_tos(), int, num_ids);
	if (todo_idx == NULL) {
		goto fail;
	}
	todo_ids = talloc_array(talloc_tos(), struct server_id, num_ids);
	if (todo_ids == NULL) {
		goto fail;
	}
	todo_results = talloc_array(talloc_tos(), bool, num_ids);
	if (todo_results == NULL) {
		goto fail;
	}

	remote_idx = talloc_array(talloc_tos(), int, num_ids);
	if (remote_idx == NULL) {
		goto fail;
	}
	verify_idx = talloc_array(talloc_tos(), int, num_ids);
	if (verify_idx == NULL) {
		goto fail;
	}

	for (idx=0; idx<num_ids; idx++) {
		results[idx] = false;

		if (server_id_is_disconnected(&ids[idx])) {
			continue;
		}

		if (procid_is_me(&ids[idx])) {
			results[idx] = true;
			continue;
		}

		if (procid_is_local(&ids[idx])) {
			bool exists = process_exists_by_pid(ids[idx].pid);

			if (!exists) {
				continue;
			}

			if (ids[idx].unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) {
				results[idx] = true;
				continue;
			}

			verify_idx[verify_num] = idx;
			verify_num += 1;
			continue;
		}

		if (!lp_clustering()) {
			continue;
		}

		remote_idx[remote_num] = idx;
		remote_num += 1;
	}

	if (remote_num != 0 &&
	    ctdb_serverids_exist_supported(messaging_ctdbd_connection()))
	{
		int old_remote_num = remote_num;

		remote_num = 0;
		todo_num = 0;

		for (t=0; t<old_remote_num; t++) {
			idx = remote_idx[t];

			if (ids[idx].unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) {
				remote_idx[remote_num] = idx;
				remote_num += 1;
				continue;
			}

			todo_idx[todo_num] = idx;
			todo_ids[todo_num] = ids[idx];
			todo_results[todo_num] = false;
			todo_num += 1;
		}

		/*
		 * Note: this only uses CTDB_CONTROL_CHECK_SRVIDS
		 * to verify that the server_id still exists,
		 * which means only the server_id.unique_id and
		 * server_id.vnn are verified, while server_id.pid
		 * is not verified at all.
		 *
		 * TODO: do we want to verify server_id.pid somehow?
		 */
		if (!ctdb_serverids_exist(messaging_ctdbd_connection(),
					  todo_ids, todo_num, todo_results))
		{
			goto fail;
		}

		for (t=0; t<todo_num; t++) {
			idx = todo_idx[t];

			results[idx] = todo_results[t];
		}
	}

	if (remote_num != 0) {
		todo_num = 0;

		for (t=0; t<remote_num; t++) {
			idx = remote_idx[t];
			todo_idx[todo_num] = idx;
			todo_ids[todo_num] = ids[idx];
			todo_results[todo_num] = false;
			todo_num += 1;
		}

		if (!ctdb_processes_exist(messaging_ctdbd_connection(),
					  todo_ids, todo_num,
					  todo_results)) {
			goto fail;
		}

		for (t=0; t<todo_num; t++) {
			idx = todo_idx[t];

			if (!todo_results[t]) {
				continue;
			}

			if (ids[idx].unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) {
				results[idx] = true;
				continue;
			}

			verify_idx[verify_num] = idx;
			verify_num += 1;
		}
	}

	for (t=0; t<verify_num; t++) {
		struct serverid_exists_state state;
		struct serverid_key key;
		TDB_DATA tdbkey;
		NTSTATUS status;

		idx = verify_idx[t];

		serverid_fill_key(&ids[idx], &key);
		tdbkey = make_tdb_data((uint8_t *)&key, sizeof(key));

		state.id = &ids[idx];
		state.exists = false;
		status = dbwrap_parse_record(db, tdbkey, server_exists_parse, &state);
		if (!NT_STATUS_IS_OK(status)) {
			results[idx] = false;
			continue;
		}
		results[idx] = state.exists;
	}

	result = true;
fail:
	TALLOC_FREE(verify_idx);
	TALLOC_FREE(remote_idx);
	TALLOC_FREE(todo_results);
	TALLOC_FREE(todo_ids);
	TALLOC_FREE(todo_idx);
	return result;
}
예제 #7
0
/***************************************************************************
  check the DNS queue
  ****************************************************************************/
void run_dns_queue(void)
{
	struct query_record r;
	struct packet_struct *p, *p2;
	struct name_record *namerec;
	int size;

	if (fd_in == -1)
		return;

        /* Allow SIGTERM to kill us. */
        BlockSignals(False, SIGTERM);

	if (!process_exists_by_pid(child_pid)) {
		close(fd_in);
		close(fd_out);
		start_async_dns();
	}

	if ((size=read_data(fd_in, (char *)&r, sizeof(r))) != sizeof(r)) {
		if (size) {
			DEBUG(0,("Incomplete DNS answer from child!\n"));
			fd_in = -1;
		}
                BlockSignals(True, SIGTERM);
		return;
	}

        BlockSignals(True, SIGTERM);

	namerec = add_dns_result(&r.name, r.result);

	if (dns_current) {
		if (query_current(&r)) {
			DEBUG(3,("DNS calling send_wins_name_query_response\n"));
			in_dns = 1;
			if(namerec == NULL)
				send_wins_name_query_response(NAM_ERR, dns_current, NULL);
			else
				send_wins_name_query_response(0,dns_current,namerec);
			in_dns = 0;
		}

		dns_current->locked = False;
		free_packet(dns_current);
		dns_current = NULL;
	}

	/* loop over the whole dns queue looking for entries that
	   match the result we just got */
	for (p = dns_queue; p;) {
		struct nmb_packet *nmb = &p->packet.nmb;
		struct nmb_name *question = &nmb->question.question_name;

		if (nmb_name_equal(question, &r.name)) {
			DEBUG(3,("DNS calling send_wins_name_query_response\n"));
			in_dns = 1;
			if(namerec == NULL)
				send_wins_name_query_response(NAM_ERR, p, NULL);
			else
				send_wins_name_query_response(0,p,namerec);
			in_dns = 0;
			p->locked = False;

			if (p->prev)
				p->prev->next = p->next;
			else
				dns_queue = p->next;
			if (p->next)
				p->next->prev = p->prev;
			p2 = p->next;
			free_packet(p);
			p = p2;
		} else {
			p = p->next;
		}
	}

	if (dns_queue) {
		dns_current = dns_queue;
		dns_queue = dns_queue->next;
		if (dns_queue)
			dns_queue->prev = NULL;
		dns_current->next = NULL;

		if (!write_child(dns_current)) {
			DEBUG(3,("failed to send DNS query to child!\n"));
			return;
		}
	}
}
예제 #8
0
파일: pidfile.c 프로젝트: sprymak/samba
/* return the pid in a pidfile. return 0 if the process (or pidfile)
   does not exist */
pid_t pidfile_pid(const char *program_name)
{
	int fd;
	char pidstr[20];
	pid_t pid;
	unsigned int ret;
	char *name;
	const char *short_configfile;
	char * pidFile;

	/* Add a suffix to the program name if this is a process with a
	 * none default configuration file name. */
	if (strcmp( CONFIGFILE, get_dyn_CONFIGFILE()) == 0) {
		name = SMB_STRDUP(program_name);
	} else {
		short_configfile = strrchr( get_dyn_CONFIGFILE(), '/');
		if (short_configfile == NULL) {
			/* conf file in current directory */
			short_configfile = get_dyn_CONFIGFILE();
		} else {
			/* full/relative path provided */
			short_configfile++;
		}
		if (asprintf(&name, "%s-%s", program_name,
				short_configfile) == -1) {
			smb_panic("asprintf failed");
		}
	}

	if (asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name) == -1) {
		SAFE_FREE(name);
		return 0;
	}

	SAFE_FREE(name);

	fd = open(pidFile, O_NONBLOCK | O_RDONLY, 0644);
	if (fd == -1) {
		SAFE_FREE(pidFile);
		return 0;
	}

	ZERO_ARRAY(pidstr);

	if (read(fd, pidstr, sizeof(pidstr)-1) <= 0) {
		goto noproc;
	}

	ret = atoi(pidstr);

	if (ret == 0) {
		/* Obviously we had some garbage in the pidfile... */
		DEBUG(1, ("Could not parse contents of pidfile %s\n",
			  pidFile));
		goto noproc;
	}
	
	pid = (pid_t)ret;
	if (!process_exists_by_pid(pid)) {
		goto noproc;
	}

	if (fcntl_lock(fd,F_SETLK,0,1,F_RDLCK)) {
		/* we could get the lock - it can't be a Samba process */
		goto noproc;
	}

	SAFE_FREE(pidFile);
	close(fd);
	return (pid_t)ret;

 noproc:
	close(fd);
	unlink(pidFile);
	SAFE_FREE(pidFile);
	return 0;
}