コード例 #1
0
/*
  create a transport structure based on an established socket
*/
struct smb2_transport *smb2_transport_init(struct smbcli_socket *sock,
        TALLOC_CTX *parent_ctx,
        struct smbcli_options *options)
{
    struct smb2_transport *transport;

    transport = talloc_zero(parent_ctx, struct smb2_transport);
    if (!transport) return NULL;

    transport->ev = sock->event.ctx;
    transport->options = *options;

    TALLOC_FREE(sock->event.fde);
    TALLOC_FREE(sock->event.te);

    transport->conn = smbXcli_conn_create(transport,
                                          sock->sock->fd,
                                          sock->hostname,
                                          options->signing,
                                          0, /* smb1_capabilities */
                                          NULL); /* client_guid */
    if (transport->conn == NULL) {
        talloc_free(transport);
        return NULL;
    }
    sock->sock->fd = -1;
    TALLOC_FREE(sock);

    talloc_set_destructor(transport, transport_destructor);

    return transport;
}
コード例 #2
0
ファイル: transport.c プロジェクト: DanilKorotenko/samba
/*
  create a transport structure based on an established socket
*/
struct smb2_transport *smb2_transport_init(struct smbcli_socket *sock,
					   TALLOC_CTX *parent_ctx,
					   struct smbcli_options *options)
{
	struct smb2_transport *transport;

	transport = talloc_zero(parent_ctx, struct smb2_transport);
	if (!transport) return NULL;

	transport->ev = sock->event.ctx;
	transport->options = *options;

	if (transport->options.max_protocol == PROTOCOL_DEFAULT) {
		transport->options.max_protocol = PROTOCOL_LATEST;
	}

	if (transport->options.max_protocol < PROTOCOL_SMB2_02) {
		transport->options.max_protocol = PROTOCOL_LATEST;
	}

	TALLOC_FREE(sock->event.fde);
	TALLOC_FREE(sock->event.te);

	transport->conn = smbXcli_conn_create(transport,
					      sock->sock->fd,
					      sock->hostname,
					      options->signing,
					      0, /* smb1_capabilities */
					      &options->client_guid,
					      options->smb2_capabilities);
	if (transport->conn == NULL) {
		talloc_free(transport);
		return NULL;
	}
	sock->sock->fd = -1;
	TALLOC_FREE(sock);

	talloc_set_destructor(transport, transport_destructor);

	return transport;
}
コード例 #3
0
/*
  create a transport structure based on an established socket
*/
struct smb2_transport *smb2_transport_init(struct smbcli_socket *sock,
					   TALLOC_CTX *parent_ctx,
					   struct smbcli_options *options)
{
	struct smb2_transport *transport;
	struct GUID client_guid;
	uint32_t smb2_capabilities = 0;

	transport = talloc_zero(parent_ctx, struct smb2_transport);
	if (!transport) return NULL;

	transport->ev = sock->event.ctx;
	transport->options = *options;

	TALLOC_FREE(sock->event.fde);
	TALLOC_FREE(sock->event.te);

	client_guid = GUID_random();

	/* TODO: hand this in via the options? */
	smb2_capabilities = SMB2_CAP_ALL;

	transport->conn = smbXcli_conn_create(transport,
					      sock->sock->fd,
					      sock->hostname,
					      options->signing,
					      0, /* smb1_capabilities */
					      &client_guid,
					      smb2_capabilities);
	if (transport->conn == NULL) {
		talloc_free(transport);
		return NULL;
	}
	sock->sock->fd = -1;
	TALLOC_FREE(sock);

	talloc_set_destructor(transport, transport_destructor);

	return transport;
}
コード例 #4
0
struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
				   int fd,
				   const char *remote_name,
				   const char *remote_realm,
				   int signing_state, int flags)
{
	struct cli_state *cli = NULL;
	bool use_spnego = lp_client_use_spnego();
	bool force_dos_errors = false;
	bool force_ascii = false;
	bool use_level_II_oplocks = false;
	uint32_t smb1_capabilities = 0;
	uint32_t smb2_capabilities = 0;
	struct GUID client_guid = GUID_random();

	/* Check the effective uid - make sure we are not setuid */
	if (is_setuid_root()) {
		DEBUG(0,("libsmb based programs must *NOT* be setuid root.\n"));
		return NULL;
	}

	cli = talloc_zero(mem_ctx, struct cli_state);
	if (!cli) {
		return NULL;
	}

	cli->server_domain = talloc_strdup(cli, "");
	if (!cli->server_domain) {
		goto error;
	}
	cli->server_os = talloc_strdup(cli, "");
	if (!cli->server_os) {
		goto error;
	}
	cli->server_type = talloc_strdup(cli, "");
	if (!cli->server_type) {
		goto error;
	}

	cli->dfs_mountpoint = talloc_strdup(cli, "");
	if (!cli->dfs_mountpoint) {
		goto error;
	}
	cli->raw_status = NT_STATUS_INTERNAL_ERROR;
	cli->map_dos_errors = true; /* remove this */
	cli->timeout = CLIENT_TIMEOUT;
	cli->case_sensitive = false;

	/* Set the CLI_FORCE_DOSERR environment variable to test
	   client routines using DOS errors instead of STATUS32
	   ones.  This intended only as a temporary hack. */	
	if (getenv("CLI_FORCE_DOSERR")) {
		force_dos_errors = true;
	}
	if (flags & CLI_FULL_CONNECTION_FORCE_DOS_ERRORS) {
		force_dos_errors = true;
	}

	if (getenv("CLI_FORCE_ASCII")) {
		force_ascii = true;
	}
	if (!lp_unicode()) {
		force_ascii = true;
	}
	if (flags & CLI_FULL_CONNECTION_FORCE_ASCII) {
		force_ascii = true;
	}

	if (flags & CLI_FULL_CONNECTION_DONT_SPNEGO) {
		use_spnego = false;
	} else if (flags & CLI_FULL_CONNECTION_USE_KERBEROS) {
		cli->use_kerberos = true;
	}
	if ((flags & CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS) &&
	     cli->use_kerberos) {
		cli->fallback_after_kerberos = true;
	}

	if (flags & CLI_FULL_CONNECTION_USE_CCACHE) {
		cli->use_ccache = true;
	}

	if (flags & CLI_FULL_CONNECTION_USE_NT_HASH) {
		cli->pw_nt_hash = true;
	}

	if (flags & CLI_FULL_CONNECTION_OPLOCKS) {
		cli->use_oplocks = true;
	}
	if (flags & CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS) {
		use_level_II_oplocks = true;
	}

	if (signing_state == SMB_SIGNING_DEFAULT) {
		signing_state = lp_client_signing();
	}

	smb1_capabilities = 0;
	smb1_capabilities |= CAP_LARGE_FILES;
	smb1_capabilities |= CAP_NT_SMBS | CAP_RPC_REMOTE_APIS;
	smb1_capabilities |= CAP_LOCK_AND_READ | CAP_NT_FIND;
	smb1_capabilities |= CAP_DFS | CAP_W2K_SMBS;
	smb1_capabilities |= CAP_LARGE_READX|CAP_LARGE_WRITEX;
	smb1_capabilities |= CAP_LWIO;

	if (!force_dos_errors) {
		smb1_capabilities |= CAP_STATUS32;
	}

	if (!force_ascii) {
		smb1_capabilities |= CAP_UNICODE;
	}

	if (use_spnego) {
		smb1_capabilities |= CAP_EXTENDED_SECURITY;
	}

	if (use_level_II_oplocks) {
		smb1_capabilities |= CAP_LEVEL_II_OPLOCKS;
	}

	smb2_capabilities = SMB2_CAP_ALL;

	if (remote_realm) {
		cli->remote_realm = talloc_strdup(cli, remote_realm);
		if (cli->remote_realm == NULL) {
			goto error;
		}
	}

	cli->conn = smbXcli_conn_create(cli, fd, remote_name,
					signing_state,
					smb1_capabilities,
					&client_guid,
					smb2_capabilities);
	if (cli->conn == NULL) {
		goto error;
	}

	cli->smb1.pid = (uint16_t)getpid();
	cli->smb1.vc_num = cli->smb1.pid;
	cli->smb1.tcon = smbXcli_tcon_create(cli);
	if (cli->smb1.tcon == NULL) {
		goto error;
	}
	smb1cli_tcon_set_id(cli->smb1.tcon, UINT16_MAX);
	cli->smb1.session = smbXcli_session_create(cli, cli->conn);
	if (cli->smb1.session == NULL) {
		goto error;
	}

	cli->initialised = 1;
	return cli;

        /* Clean up after malloc() error */

 error:

	TALLOC_FREE(cli);
        return NULL;
}