Bug 3772 - Try "Write" (0x0b) if "Write and X" (0x2f) fails
Try "Write" (0x0b) if "Write and X" (0x2f) fails
Product: Samba 3.0
Classification: Unclassified
Component: Client Tools
All All
: P3 normal
: none
Assigned To: Samba Bugzilla Account
Samba QA Contact
Depends on:
  Show dependency treegraph
Reported: 2006-05-13 04:26 UTC by Ramon Casares
Modified: 2006-05-17 04:12 UTC (History)
0 users

See Also:

diff -u client/original.client.c client/client.c (877 bytes, patch)
2006-05-13 04:30 UTC, Ramon Casares
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ramon Casares 2006-05-13 04:26:27 UTC
The SMB server in my HP Photosmart 2610 all-in-one printer does not accept operation "Write and X", therefore I patched source/client/client.c so smbclient
tries a "Write" (0x0b) operation if "Write and X" (0x2f) fails. It is a normal bug, because this printer accepts its printing works directly via TCP on port 9100. I append the diff of the patch. 

   Ramon Casares

diff -u client/original.client.c client/client.c
--- client/original.client.c    2006-05-13 10:47:58.000000000 +0200
+++ client/client.c     2006-05-13 11:06:25.000000000 +0200
@@ -1237,9 +1237,13 @@
                ret = cli_write(targetcli, fnum, 0, buf, nread + start, n);

                if (n != ret) {
-                       d_printf("Error writing file: %s\n", cli_errstr(cli));
-                       rc = 1;
-                       break;
+                  /* before giving-up, lets try another way - RMCG */
+                  ret = cli_smbwrite(targetcli, fnum, buf, nread + start, n);
+                  if (n != ret) {
+                               d_printf("Error writing file: %s\n", cli_errstr(cli));
+                               rc = 1;
+                               break;
+                       }

                nread += n;
Comment 1 Ramon Casares 2006-05-13 04:30:52 UTC
Created attachment 1898 [details]
diff -u client/original.client.c client/client.c
Comment 2 Ramon Casares 2006-05-17 04:08:59 UTC
My patch only works with files under 8k.

$ cmp eco.pdf Downloads/eco.pdf
eco.pdf Downloads/eco.pdf differ: byte 8209, line 76
$ cmp TETEXDOC.pdf Downloads/TETEXDOC.pdf
TETEXDOC.pdf Downloads/TETEXDOC.pdf differ: byte 8209, line 50

So the first error is always in byte 8209 (?). Then I tried a 8136 bytes long
file, and no errors were found. I don't know why, but a

$ grep -r "cli_smbwrite(" source

shows that Samba only uses function "cli_smbwrite", which is the one that sends "Write" operations instead of "Write and X", in:

source/include/proto.h: the header file
source/libsmb/clireadwrite.c: where the function is defined
source/torture/torture.c: where it is tested

So, it is defined, declared, and tested, but not used! Perhaps it is just a
relic of ancient times and not really mantained.

On the other hand, the SMB server in the printer has some other peculiarities, so it is possibly only a partial implementation, enough to work with a specially tunned HP client, but not really open to the world.

So, I will close the bug. 
Sorry for the time you wasted reading this.