Ejemplo n.º 1
0
/* create open */
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
	int ret, new_sockfd;
	struct sock *new_sk;
	struct sock *sk;

	socket_idesc_check(sockfd, sk);

	if (((addr == NULL) && (addrlen != NULL))
			|| ((addr != NULL) && (addrlen == NULL))
			|| ((addrlen != NULL) && (*addrlen <= 0))) {
		return SET_ERRNO(EINVAL);
	}

	ret = kaccept(sk, addr, addrlen, sk->idesc.idesc_flags, &new_sk);
	if (ret < 0) {
		return SET_ERRNO(-ret);
	}

	new_sockfd = get_index(new_sk);
	if (new_sockfd < 0) {
		ksocket_close(new_sk);
		return SET_ERRNO(-new_sockfd);
	}

	return new_sockfd;
}
Ejemplo n.º 2
0
static void socket_close(struct idesc *desc) {
    struct sock *sk = (struct sock *)desc;

    assert(desc);
    assert(desc->idesc_ops == &task_idx_ops_socket);

    ksocket_close(sk);
}
Ejemplo n.º 3
0
void
smb_authsock_close(smb_user_t *user)
{

	ASSERT(MUTEX_HELD(&user->u_mutex));
	if (user->u_authsock == NULL)
		return;
	(void) ksocket_close(user->u_authsock, CRED());
	user->u_authsock = NULL;
	smb_threshold_exit(&user->u_server->sv_ssetup_ct);
}
Ejemplo n.º 4
0
/* create */
int socket(int domain, int type, int protocol) {
	int sockfd = 0;

	struct sock *sk;

	sk = ksocket(domain, type, protocol);
	if (err(sk) != 0) {
		return SET_ERRNO(-err(sk));
	}

	sockfd = get_index(sk);
	if (sockfd < 0) {
		ksocket_close(sk);
		return SET_ERRNO(EMFILE);
	}

	return sockfd;
}
Ejemplo n.º 5
0
/*
 * smb_sodestroy releases all resources associated with a socket previously
 * created with smb_socreate.  The socket must be shutdown using smb_soshutdown
 * before the socket is destroyed with smb_sodestroy, otherwise undefined
 * behavior will result.
 */
void
smb_sodestroy(ksocket_t so)
{
	(void) ksocket_close(so, CRED());
}
Ejemplo n.º 6
0
static uint32_t
smb_authsock_open(smb_user_t *user)
{
	smb_server_t *sv = user->u_server;
	ksocket_t so = NULL;
	uint32_t status;
	int rc;

	/*
	 * If the auth. service is busy, wait our turn.
	 * This may be frequent, so don't log.
	 */
	if ((rc = smb_threshold_enter(&sv->sv_ssetup_ct)) != 0)
		return (NT_STATUS_NO_LOGON_SERVERS);

	rc = ksocket_socket(&so, AF_UNIX, SOCK_STREAM, 0,
	    KSOCKET_SLEEP, CRED());
	if (rc != 0) {
		cmn_err(CE_NOTE, "smb_authsock_open: socket, rc=%d", rc);
		status = NT_STATUS_INSUFF_SERVER_RESOURCES;
		goto errout;
	}

	/*
	 * Set the send/recv timeouts.
	 */
	(void) ksocket_setsockopt(so, SOL_SOCKET, SO_SNDTIMEO,
	    &smb_auth_send_tmo, sizeof (smb_auth_send_tmo), CRED());
	(void) ksocket_setsockopt(so, SOL_SOCKET, SO_RCVTIMEO,
	    &smb_auth_recv_tmo, sizeof (smb_auth_recv_tmo), CRED());

	/*
	 * Connect to the smbd auth. service.
	 *
	 * Would like to set the connect timeout too, but there's
	 * apparently no easy way to do that for AF_UNIX.
	 */
	rc = ksocket_connect(so, (struct sockaddr *)&smbauth_sockname,
	    sizeof (smbauth_sockname), CRED());
	if (rc != 0) {
		DTRACE_PROBE1(error, int, rc);
		status = NT_STATUS_NETLOGON_NOT_STARTED;
		goto errout;
	}

	/* Note: u_authsock cleanup in smb_authsock_close() */
	mutex_enter(&user->u_mutex);
	if (user->u_authsock != NULL) {
		mutex_exit(&user->u_mutex);
		status = NT_STATUS_INTERNAL_ERROR;
		goto errout;
	}
	user->u_authsock = so;
	mutex_exit(&user->u_mutex);
	return (0);

errout:
	if (so != NULL)
		(void) ksocket_close(so, CRED());
	smb_threshold_exit(&sv->sv_ssetup_ct);

	return (status);
}
Ejemplo n.º 7
0
/*
 * iscsi_net_close - shutdown socket connection and release resources
 */
static void
iscsi_net_close(void *socket)
{
	ksocket_t ks = (ksocket_t)socket;
	(void) ksocket_close(ks, CRED());
}