/*
 * process_broadcast_mse(): deal with all broadcast message and forward
 * */
void process_broadcast_msg(message_header *mh, char* msg, int cid) {
	char in_token[11] = { '\0' };
	memcpy(in_token, msg, TOKEN_LENTH);
	printf("\tReceived peer_token: %s\n", in_token);

	char source_token[TOKEN_LENTH + 1] = {'\0'};uint32_t
	source_ip = 0;
	uint16_t source_udp_port = 0;

	memcpy(source_token, msg, TOKEN_LENTH);
	memcpy(&source_ip, msg + TOKEN_LENTH, 4);
	memcpy(&source_udp_port, msg + TOKEN_LENTH + 4, 2);

	char remote_port[MAXLINE] = { '\0' };
	char temp_ip[MAXLINE] = { '\0' };
	//use connection id to get ip and remote port
	get_connection_info(cid, temp_ip, remote_port);
	add_peer_token_to_container(source_token, source_udp_port, source_ip, remote_port);
	//send out broadcast message
	int i, sock_fd = -1;
	for (i = 0; i < MAX_CONNECTIONS; i++) {
		if (i != cid) {
			sock_fd = get_conn_fd(i);
			if (sock_fd != -1) {
				char package[TOKEN_LENTH + 7] = {'\0'};memcpy(package, source_token, TOKEN_LENTH);
				memcpy(package + TOKEN_LENTH, &network_ip, 4);
				memcpy(package + TOKEN_LENTH + 4, &self_peer_msg.udp_port, 2);

				send_message(sock_fd, mh, msg);
			}
		}
	}
}
示例#2
0
文件: auth.c 项目: ozaki-r/netbsd-src
struct passwd *
getpwnamallow(const char *user)
{
#ifdef HAVE_LOGIN_CAP
 	extern login_cap_t *lc;
#ifdef BSD_AUTH
 	auth_session_t *as;
#endif
#endif
	struct ssh *ssh = active_state; /* XXX */
	struct passwd *pw;
	struct connection_info *ci = get_connection_info(1, options.use_dns);

	ci->user = user;
	parse_server_match_config(&options, ci);
	log_change_level(options.log_level);
	process_permitopen(ssh, &options);

	pw = getpwnam(user);
	if (pw == NULL) {
		pfilter_notify(1);
		logit("Invalid user %.100s from %.100s port %d",
		    user, ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
		return (NULL);
	}
	if (!allowed_user(pw))
		return (NULL);
#ifdef HAVE_LOGIN_CAP
	if ((lc = login_getclass(pw->pw_class)) == NULL) {
		debug("unable to get login class: %s", user);
		return (NULL);
	}
#ifdef BSD_AUTH
	if ((as = auth_open()) == NULL || auth_setpwd(as, pw) != 0 ||
	    auth_approval(as, lc, pw->pw_name, "ssh") <= 0) {
		debug("Approval failure for %s", user);
		pw = NULL;
	}
	if (as != NULL)
		auth_close(as);
#endif
#endif
	if (pw != NULL)
		return (pwcopy(pw));
	return (NULL);
}
/*
 * process_private_msg(): deal with all private message
 */
void process_private_msg(char* msg, int cid) {
	/* construct private_msg */
	char init_token[TOKEN_LENTH + 1] = {'\0'};char ip[MAXLINE] = {'\0'};
	char tcp_port[MAXLINE] = {'\0'};

	strncpy(init_token, msg, TOKEN_LENTH);
	//sender infomation
	get_connection_info(cid, ip, tcp_port);
	printf("\t got init_token: %s from %s:%s\n", init_token, ip, tcp_port);
	add_init_token(init_token);

	//check number of init-tokens
	int num_tokens = count_init_token();
	int num_peers = count_current_connections();

	if ( num_tokens == num_peers ) { // received enough tokens
		get_peer_token();
		is_peerToken_determined = 1;
		printf("\t peer token determined: %s\n", self_peer_msg.peer_token);
		send_udp_message();
	}
}
示例#4
0
struct passwd *
getpwnamallow(const char *user)
{
#ifdef HAVE_LOGIN_CAP
	extern login_cap_t *lc;
#ifdef BSD_AUTH
	auth_session_t *as;
#endif
#endif
	struct passwd *pw;
	struct connection_info *ci = get_connection_info(1, options.use_dns);

	ci->user = user;
	parse_server_match_config(&options, ci);

#if defined(_AIX) && defined(HAVE_SETAUTHDB)
	aix_setauthdb(user);
#endif

	pw = getpwnam(user);

#if defined(_AIX) && defined(HAVE_SETAUTHDB)
	aix_restoreauthdb();
#endif
#ifdef HAVE_CYGWIN
	/*
	 * Windows usernames are case-insensitive.  To avoid later problems
	 * when trying to match the username, the user is only allowed to
	 * login if the username is given in the same case as stored in the
	 * user database.
	 */
	if (pw != NULL && strcmp(user, pw->pw_name) != 0) {
		logit("Login name %.100s does not match stored username %.100s",
		    user, pw->pw_name);
		pw = NULL;
	}
#endif
	if (pw == NULL) {
		BLACKLIST_NOTIFY(BLACKLIST_AUTH_FAIL);
		logit("Invalid user %.100s from %.100s",
		    user, get_remote_ipaddr());
#ifdef CUSTOM_FAILED_LOGIN
		record_failed_login(user,
		    get_canonical_hostname(options.use_dns), "ssh");
#endif
#ifdef SSH_AUDIT_EVENTS
		audit_event(SSH_INVALID_USER);
#endif /* SSH_AUDIT_EVENTS */
		return (NULL);
	}
	if (!allowed_user(pw))
		return (NULL);
#ifdef HAVE_LOGIN_CAP
	if ((lc = login_getpwclass(pw)) == NULL) {
		debug("unable to get login class: %s", user);
		return (NULL);
	}
#ifdef BSD_AUTH
	if ((as = auth_open()) == NULL || auth_setpwd(as, pw) != 0 ||
	    auth_approval(as, lc, pw->pw_name, "ssh") <= 0) {
		debug("Approval failure for %s", user);
		pw = NULL;
	}
	if (as != NULL)
		auth_close(as);
#endif
#endif
	if (pw != NULL)
		return (pwcopy(pw));
	return (NULL);
}
示例#5
0
static void
process_message(iscsid_request_t *req, iscsid_response_t **prsp, int *prsp_temp)
{
	iscsid_response_t *rsp;
	void *p = req->parameter;

	*prsp_temp = FALSE;
	*prsp = rsp = (iscsid_response_t *)(void *)rsp_buf;
	rsp->parameter_length = 0;
	rsp->status = ISCSID_STATUS_SUCCESS;

	switch (req->request) {
	case ISCSID_ADD_TARGET:
		if (req->parameter_length < sizeof(iscsid_add_target_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		add_target((iscsid_add_target_req_t *)p, prsp, prsp_temp);
		break;

	case ISCSID_ADD_PORTAL:
		if (req->parameter_length != sizeof(iscsid_add_portal_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		add_portal((iscsid_add_portal_req_t *)p, prsp, prsp_temp);
		break;

	case ISCSID_SET_TARGET_OPTIONS:
		if (req->parameter_length != sizeof(iscsid_get_set_target_options_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = set_target_options((iscsid_get_set_target_options_t *)p);
		break;

	case ISCSID_GET_TARGET_OPTIONS:
		if (req->parameter_length != sizeof(iscsid_sym_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = ISCSID_STATUS_NOTIMPL;
		break;

	case ISCSID_SET_TARGET_AUTHENTICATION:
		if (req->parameter_length !=
			sizeof(iscsid_set_target_authentication_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = set_target_auth((iscsid_set_target_authentication_req_t *)p);
		break;

	case ISCSID_SLP_FIND_TARGETS:
		rsp->status = ISCSID_STATUS_NOTIMPL;
		break;

	case ISCSID_REFRESH_TARGETS:
		if (req->parameter_length < sizeof(iscsid_refresh_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = refresh_targets((iscsid_refresh_req_t *)p);
		break;

	case ISCSID_REMOVE_TARGET:
		if (req->parameter_length != sizeof(iscsid_list_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = remove_target((iscsid_list_id_t *)p);
		break;

	case ISCSID_SEARCH_LIST:
		if (req->parameter_length != sizeof(iscsid_search_list_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		search_list((iscsid_search_list_req_t *)p, prsp, prsp_temp);
		break;

	case ISCSID_GET_LIST:
		if (req->parameter_length != sizeof(iscsid_get_list_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		get_list((iscsid_get_list_req_t *)p, prsp, prsp_temp);
		break;

	case ISCSID_GET_TARGET_INFO:
		if (req->parameter_length != sizeof(iscsid_list_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		get_target_info((iscsid_list_id_t *)p, prsp, prsp_temp);
		break;

	case ISCSID_GET_PORTAL_INFO:
		if (req->parameter_length != sizeof(iscsid_list_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		get_portal_info((iscsid_list_id_t *)p, prsp, prsp_temp);
		break;

#ifndef ISCSI_MINIMAL
	case ISCSID_ADD_ISNS_SERVER:
		if (req->parameter_length != sizeof(iscsid_add_isns_server_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		add_isns_server((iscsid_add_isns_server_req_t *)p,
						prsp, prsp_temp);
		break;

	case ISCSID_GET_ISNS_SERVER:
		if (req->parameter_length != sizeof(iscsid_sym_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		get_isns_server((iscsid_sym_id_t *)p, prsp, prsp_temp);
		break;

	case ISCSID_SLP_FIND_ISNS_SERVERS:
		rsp->status = ISCSID_STATUS_NOTIMPL;
		break;

	case ISCSID_REMOVE_ISNS_SERVER:
		if (req->parameter_length != sizeof(iscsid_sym_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = remove_isns_server((iscsid_sym_id_t *)p);
		break;
#endif

	case ISCSID_ADD_INITIATOR_PORTAL:
		if (req->parameter_length != sizeof(iscsid_add_initiator_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		add_initiator_portal((iscsid_add_initiator_req_t *)p,
							prsp, prsp_temp);
		break;

	case ISCSID_GET_INITIATOR_PORTAL:
		if (req->parameter_length != sizeof(iscsid_sym_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		get_initiator_portal((iscsid_sym_id_t *)p, prsp, prsp_temp);
		break;

	case ISCSID_REMOVE_INITIATOR_PORTAL:
		if (req->parameter_length != sizeof(iscsid_sym_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = remove_initiator_portal((iscsid_sym_id_t *)p);
		break;

	case ISCSID_LOGIN:
		if (req->parameter_length != sizeof(iscsid_login_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		login((iscsid_login_req_t *)p, rsp);
		break;

	case ISCSID_ADD_CONNECTION:
		if (req->parameter_length != sizeof(iscsid_login_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		add_connection((iscsid_login_req_t *)p, rsp);
		break;

	case ISCSID_LOGOUT:
		if (req->parameter_length != sizeof(iscsid_sym_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = logout((iscsid_sym_id_t *)p);
		break;

	case ISCSID_REMOVE_CONNECTION:
		if (req->parameter_length != sizeof(iscsid_remove_connection_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = remove_connection((iscsid_remove_connection_req_t *)p);
		break;

	case ISCSID_GET_SESSION_LIST:
		get_session_list(prsp, prsp_temp);
		break;

	case ISCSID_GET_CONNECTION_LIST:
		if (req->parameter_length != sizeof(iscsid_sym_id_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		get_connection_list((iscsid_sym_id_t *)p, prsp, prsp_temp);
		break;

	case ISCSID_GET_CONNECTION_INFO:
		if (req->parameter_length != sizeof(iscsid_get_connection_info_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		get_connection_info((iscsid_get_connection_info_req_t *)p,
							prsp, prsp_temp);
		break;

	case ISCSID_SET_NODE_NAME:
		if (req->parameter_length != sizeof(iscsid_set_node_name_req_t)) {
			rsp->status = ISCSID_STATUS_INVALID_PARAMETER;
			break;
		}
		rsp->status = set_node_name((iscsid_set_node_name_req_t *)p);
		break;

	case ISCSID_GET_VERSION:
		get_version(prsp, prsp_temp);
		break;

	default:
		rsp->status = ISCSID_STATUS_INVALID_REQUEST;
		break;
	}
}