libsmb and the cli_ routines and libsmbclient connection handling

Tim Potter tpot at linuxcare.com.au
Thu Jan 25 17:43:27 GMT 2001


Richard Sharpe writes:

> I am getting to the point where I need to change the functionality of the
> cli_ routines I use from libsmb in libsmbclient.
> 
> Currently, there is a one-to-one connection between a share and a server.

I've got some code in a work area that does this.  Unfortunately
I'm not sure whether the API is nice or not.  I'll describe it
and perhaps people can make some comments.

I've basically hacked all the NT pipe specific stuff out of the
cli_state structure and into a cli_pipe_state structure.  This
structure also contains a pointer to a cli_state which can be
shared amongst pipe users:

struct cli_pipe_state {
       struct cli_state *smb;
       uint32 ntlmssp_srv_flgs;           /* ntlmssp server flags */
       unsigned char ntlmssp_hash[258];   /* ntlmssp data. */
       uint32 ntlmssp_seq_num;            /* ntlmssp sequence number */
       uint16 nt_pipe_fnum;               /* Pipe handle. */
       uint16 max_recv_frag;
       uint32 ntlmssp_cli_flgs;           /* ntlmssp client flags */
       uint16 max_xmit_frag;
       fstring srv_name_slash;            /* \\remote server. */
       fstring clnt_name_slash;           /* \\local client. */
       fstring mach_acct;                 /* MYNAME$. */
};

(Various routines in libsmb and cli_pipe.c have been modified to
support this).

To do a shared client connection you do something like this (warning -
untested code typed in from memory ahead):

uint32 do_stuff(void)
{
	struct cli_state cli;
	struct cli_pipe_state cli_pipe;
	POLICY_HND pol;
	uint32 result = NT_STATUS_UNSUCCESSFUL;

	ZERO_STRUCT(cli);
	ZERO_STRUCT(cli_pipe);
	
	init_rpcclient_creds(&creds); /* This sets up username/password */
	
	if (cli_pipe_init(&cli, server, &creds) == NULL) {
		goto done;
	}
	
	cli_pipe.smb = &cli;
	
	if (!cli_lsa_open_pipe(&cli_pipe)) {
		goto done;
	}
	
	if ((result = cli_lsa_open_policy(&cli_pipe, True, 
					  SEC_RIGHTS_MAXIMUM_ALLOWED, 
					  &pol)) != NT_STATUS_NOPROBLEMO) {
		goto done;
	}  

	ZERO_STRUCT(another_cli_pipe);

	another_cli_pipe.smb = &cli;

	if (cli_samr_open_pip(&cli_pipe)) {
		goto done;
	}

	if ((result = cli_samr_connect(&cli_pipe, server,
				       MAXIMUM_ALLOWED_ACCESS,
				       &pol2)) != NT_STATUS_NOPROBLEMO) {
		gotod eon;
	}

 done:
	cli_samr_close(&another_cli_pipe, &pol2);
	cli_lsa_close(&cli_pipe, &pol);

	return result;
}

Basically you can share a pipe connection that has the same
username/password combination to the same server but you have to
manage the cli_state and cli_pipe_state stuff yourself.  This is
very different to the TNG method which everything is managed for
you.



Tim.





More information about the samba-technical mailing list