No subject

Sun Sep 6 16:29:27 MDT 2009

2009 20:01:35 +0200=0ASubject: [PATCH] The format of data we are sending =
over the network will be flexible=0A when sending over the network in =
protocol v2. To be able to do this,=0A we create a new va-list function =
that is creating the buffer to send. Also it=0A makes it easier for the =
receiver to parse the data; it sends an initial=0A header containing the =
full length of the buffer to be send. For the=0A individual strings, it =
sends sub headers containing the length of the=0A upcoming substring to be =
send. With the header-data-header-data [..]=0A structure we don't need to =
quote the sub strings finally enabling=0A having all possible character =
sets in filenames etc..=0A=0AIn the sending function, implement mkdir to =
actually send it's data=0Afor testing.=0A---=0A source3/modules/vfs_smb_tra=
ffic_analyzer.c |   78 ++++++++++++++++++++++++++--=0A 1 files changed, 74 =
insertions(+), 4 deletions(-)=0A=0Adiff --git a/source3/modules/vfs_smb_tra=
ffic_analyzer.c b/source3/modules/vfs_smb_traffic_analyzer.c=0Aindex =
e6ec214..95125ca 100644=0A--- a/source3/modules/vfs_smb_traffic_analyzer.c=
=0A+++ b/source3/modules/vfs_smb_traffic_analyzer.c=0A@@ -168,7 +168,7 @@ =
static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct =
*handle,=0A 	return sock;=0A }=0A =0A-/* Private data allowing shared =
connection sockets. */=0A+/* Private data allowing shared connection =
sockets. 	*/=0A =0A struct refcounted_sock {=0A 	struct refcounted_s=
ock *next, *prev;=0A@@ -178,7 +178,60 @@ struct refcounted_sock {=0A 	=
unsigned int ref_count;=0A };=0A =0A-/* Send data over a socket */=0A+=0A+/=
* The marshaller for the protocol version 2.		*/=0A+static char =
*smb_traffic_analyzer_create_string( struct tm *tm, \=0A+	int =
seconds, vfs_handle_struct *handle, \=0A+	char *username, int count, =
... )=0A+{=0A+	=0A+	va_list ap;=0A+	char *arg =3D NULL;=0A+	char *str =
=3D NULL;=0A+	int len;=0A+	char *header =3D NULL;=0A+	char *buf =
=3D NULL;=0A+	char *timestr =3D NULL;=0A+=0A+	/* first create the data =
that is transfered with any VFS op	*/=0A+	len =3D strlen( username =
);=0A+	buf =3D talloc_asprintf(talloc_tos(),"%04u%s", len, username);=0A+	=
len =3D strlen( handle->conn->connectpath );=0A+	buf =3D talloc_aspr=
intf_append( buf, "%04u%s", len, \=0A+		handle->conn->connectpath =
);=0A+	len =3D strlen( pdb_get_domain(handle->conn->server_info->sam_accou=
nt) );=0A+	buf =3D talloc_asprintf_append( buf, "%04u%s", len, \=0A+	=
	pdb_get_domain(handle->conn->server_info->sam_account) );=0A+	=
timestr =3D talloc_asprintf(talloc_tos(), \=0A+		"%04d-%02d-%02d =
%02d:%02d:%02d.%03d", \=0A+		tm->tm_year+1900, \=0A+		=
tm->tm_mon+1, \=0A+		tm->tm_mday, \=0A+		tm->tm_hour=
, \=0A+		tm->tm_min, \=0A+		tm->tm_sec, \=0A+		=
(int)seconds);=0A+	len =3D strlen( timestr );=0A+	buf =3D talloc_aspr=
intf_append( buf, "%04u%s", len, timestr);=0A+	=0A+	va_start( ap, =
count );=0A+	while ( count-- ) {=0A+		arg =3D va_arg( ap, char * =
);=0A+		/* protocol v2 sends a four byte string	*/=0A+		/* =
as a header to each block, including	*/=0A+		/* the numbers of =
bytes to come in the	*/=0A+		/* next string.				=
*/=0A+		len =3D strlen( arg );=0A+		buf =3D talloc_aspr=
intf_append( buf, "%04u%s", len, arg);=0A+	}=0A+	va_end( ap =
);=0A+=0A+	/* now create the protocol v2 header.	*/=0A+	len =3D =
strlen( buf );=0A+	str =3D talloc_asprintf_append( str, "V2,%017u%s", =
len, buf);=0A+	DEBUG(10, ("smb_traffic_analyzer_create_string: %s\n",str))=
;=0A+	return str;=0A+}=0A =0A static void smb_traffic_analyzer_send_data(=
vfs_handle_struct *handle,=0A 					void =
*data,=0A@@ -275,8 +328,25 @@ static void smb_traffic_analyzer_send_data(vf=
s_handle_struct *handle,=0A 			tm->tm_sec,=0A 			=
(int)seconds);=0A 	} else if ( strcmp( protocol_version, "V2") =3D=3D =
0) {=0A-		/* protocol version 2	*/=0A-		/* in =
development	*/=0A+=0A+		switch( vfs_operation ) {=0A+		=
	case vfs_id_mkdir: ;=0A+				struct =
mkdir_data *s_data =3D \=0A+					(struct =
mkdir_data *) data;=0A+				str =3D smb_traffic_analyze=
r_create_string( tm, \=0A+					seconds, =
handle, username, \=0A+					3, s_data->path, =
\=0A+					talloc_asprintf( talloc_tos(), =
"%u", \=0A+						s_data->mode), =
\=0A+					talloc_asprintf( talloc_tos(), =
"%u", \=0A+						s_data->result =
));=0A+				break;=0A+			default:=0A=
+				DEBUG(1, ("smb_traffic_analyzer: error! =
"=0A+					"wrong VFS operation id detected!\n=
"));=0A+				return;=0A+		}=0A+=0A 	=
} else {=0A 		DEBUG(1, ("smb_traffic_analyzer_send_data_socket: =
"=0A 			"error, unkown protocol given!\n"));=0A-- =

More information about the samba-technical mailing list