[Samba] Re: VFS calls after disconnect

Chetana chetana at fstream.net
Wed Feb 2 10:22:51 GMT 2005


Hello,
	Below is the sample code almost similar to the one in Samba Developers's
guide. I tested it with a win2k client for samba 3.0.2a on FreeBSD.
When the example_connect is called the second time by the same client
handle->data is null.
The test can be reproduced as follows-
1) search for the computer from windows explorer. Access the vfs share and
create directory or perform any other operation.
2) use the back button of the explorer to return back to the share and map
it to a network drive.

Is there some way that this data can be preserved irrespective of the number
of times that an already connected client tries a reconnection?

Any help is highly appreciated!
Thanks,
Chetana

static int connectCnt = 0;
struct example_privates {
	char *some_string;
	int db_connection;
};

static int example_connect(vfs_handle_struct *handle,
	connection_struct *conn, const char *service,
	const char* user)
{
	struct example_privates *data = NULL;

	if ( connectCnt > 0 ) {
		DEBUG(0,("connection to client already exists\n"));
		SMB_VFS_HANDLE_GET_DATA(handle, data, struct example_privates, -1);
		data = (struct example_privates*)handle->data ;
		DEBUG(0,("data->db_connection = %d\n" , data->db_connection ));
		return 1;
	}

	/* alloc our private data */
	data = (struct example_privates *)talloc_zero(conn->mem_ctx, sizeof(struct
example_privates));
	if (!data) {
		DEBUG(0,("talloc_zero() failed\n"));
		return -1;
	}

	/* init out private data */
	data->some_string = talloc_strdup(conn->mem_ctx,"test");
	if (!data->some_string) {
		DEBUG(0,("talloc_strdup() failed\n"));
		return -1;
	}

	connectCnt ++;
	data->db_connection = connectCnt ;

	/* and now store the private data pointer in handle->data
	 * we don't need to specify a free_function here because
	 * we use the connection TALLOC context.
	 * (return -1 if something failed.)
	 */
	VFS_HANDLE_SET_DATA(handle, data, NULL, struct example_privates, -1);


	return 1;
}





More information about the samba mailing list