# [patch] CUPS printing to an SMB share

## G-LiTe`

Sorry if this has been posted before. (probably not, couldn't find it anywhere)

I've search all over for a fix to this problem, but I've only bumped into useless tutorials telling me the same thing over and over or dead mailinglist threads that died before there was an answer.  :Smile: 

I've been trying to setup CUPS to print to a Windows XP printer share for a while now. It seemed to fail every time with an error like:

```
cli_session_request() failed...

Unable to connect to SAMBA host, will retry in 60 seconds...
```

It was, however, possible for me to connect to the printer share using the smbclient program. (as in: "smbclient //192.168.15.1/HPprinter" in my case)

After searching my ass off on google and whatnot I finally decided to dive into the code myself. It took me a while to figure it out. I was comparing the smbclient code to smbspool's code. I was dump enough to look over the "again" label and goto's. But as soon as I saw them I realised, turning up the loglevel a bit and running smbclient again shows it trying a few times before it was actually able to connect. Simply putting the same code in smbspool worked like a charm.  :Smile: 

I have no idea if this has already been fixed in Samba 3.0 or if there was a patch for this already, but I'm going to post it here regardless for everyone interested:

```
diff -ur samba-2.2.8a.orig/source/client/smbspool.c samba-2.2.8a/source/client/smbspool.c

--- samba-2.2.8a.orig/source/client/smbspool.c  2003-02-28 16:56:18.000000000 +0100

+++ samba-2.2.8a/source/client/smbspool.c       2003-06-16 20:57:16.000000000 +0200

@@ -289,11 +289,12 @@

                                                                                                                                                                                                   

   get_myname(myname);

                                                                                                                                                                                                   

-  zero_ip(&ip);

-

-  make_nmb_name(&calling, myname, 0x0);

+  make_nmb_name(&calling, global_myname, 0x0);

   make_nmb_name(&called, server, 0x20);

                                                                                                                                                                                                   

+again:

+  zero_ip(&ip);

+

  /*

   * Open a new connection to the SMB server...

   */

@@ -320,8 +321,17 @@

                                                                                                                                                                                                   

   if (!cli_session_request(c, &calling, &called))

   {

+    char *p;

     fputs("ERROR: cli_session_request() failed...\n", stderr);

     cli_shutdown(c);

+    if ((p=strchr(called.name, '.'))) {

+       *p = 0;

+       goto again;

+    }

+    if (strcmp(called.name, "*SMBSERVER")) {

+       make_nmb_name(&called , "*SMBSERVER", 0x20);

+       goto again;

+    }

     return (NULL);

   }
```

Maybe something for 2.2.8a-r1?  :Wink: 

btw: Samba 3.0b1 has been released a while ago, I saw nothing on bugzilla. Is there an ebuild for this?

----------

## gatiba

When i connect to the printer via smbclient i receive this:

```
smbclient //192.168.2.2/epson

Unknown parameter encountered: "max packet"

Ignoring unknown parameter "max packet"

added interface ip=192.168.2.3 bcast=192.168.2.255 nmask=255.255.255.0

session request to 192.168.2.2 failed (Called name not present)

session request to 192 failed (Called name not present)

Password:
```

but i can't understand it !  :Sad: 

It can reach my printer?

----------

## G-LiTe`

It can reach your printer, yes.

It probably depends on the setup but I could leave my password blank at that point. (try just pressing enter)

My problem was this part:

```
session request to 192.168.2.2 failed (Called name not present)

session request to 192 failed (Called name not present)
```

It tries several addresses (though some are completely invalid). The smbspool program didn't. It tried only once and failed.

The patch I supplied above fixes this, though it already seems to be fixed in the upcoming samba 3.0. (beta1 seems to use 1 function for all these programs, so both smbclient and smbspool use the same procedure to connect to a host).

----------

## gatiba

Ok now i receive this:

```
bash-2.05b# smbclient //stefano/epson

Unknown parameter encountered: "max packet"

Ignoring unknown parameter "max packet"

added interface ip=192.168.2.3 bcast=192.168.2.255 nmask=255.255.255.0

Got a positive name query response from 192.168.2.2 ( 192.168.2.2 )

Password:

Domain=[UFFICIO] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

smb: \>

```

In fact i changed the path to the shared printer from //192.168.2.2/epson to //stefano/epson, and stefano is the netbios of the windows machine.

Now seems to work but it can't login on the windows machine, i receive this from the cups web interface:

"SMB tree connect failed: NT_STATUS_ACCESS_DENIED"

----------

## SyS_RaGE

first of all. thank you very much for posting this patch. the cli_session_request() error was driving me up the wall. however, using your patch directly samba wouldn't compile. However, I changed 'global_myname' back to just 'myname' and it compiled and now my printer works. I don't know much about diff files, but i assume you can probably just remove these lines completely:

```
-  make_nmb_name(&calling, myname, 0x0); 

+  make_nmb_name(&calling, global_myname, 0x0); 
```

but what i did to make it work was just change them to:

```
-  make_nmb_name(&calling, myname, 0x0); 

+  make_nmb_name(&calling, myname, 0x0); 
```

also, for those that don't know how to apply this patch. put the contents of the patch into a new file /usr/portage/net-fs/samba/files/samba-print.patch

then edit /usr/portage/net-fs/samba/samba-2.2.8a.ebuild and directly under this line:

```
epatch ${FILESDIR}/samba-2.2.5-gp-reloc-fix.patch
```

add:

```
patch -p1 < ${FILESDIR}/samba-print.patch
```

then emerge samba. all should work well. good luck

----------

## G-LiTe`

 *SyS_RaGE wrote:*   

> first of all. thank you very much for posting this patch. the cli_session_request() error was driving me up the wall. however, using your patch directly samba wouldn't compile. However, I changed 'global_myname' back to just 'myname' and it compiled and now my printer works. I don't know much about diff files, but i assume you can probably just remove these lines completely:
> 
> ```
> -  make_nmb_name(&calling, myname, 0x0); 
> 
> ...

 

I can't really confirm that, I'm using samba 3.0b3 now and they changed alot. Printing doesn't work in it yet, I haven't fiddled with it much but it could just be the same problem, because I can connect using smbclient.

I wonder what's taking the 3.0rc1 ebuild so long.. think I'll fiddle one together myself.

----------

## phill_20x6

nevermind, i re-read the thread a little closer  :Wink:  Thanks for the patch!

----------

## phill_20x6

hmm this came up during the emerge:

```
 * Applying samba-2.2.5-gp-reloc-fix.patch...                             [ ok ]

patching file source/client/smbspool.c

Hunk #1 FAILED at 289.

Hunk #2 succeeded at 321 with fuzz 1.

1 out of 2 hunks FAILED -- saving rejects to file source/client/smbspool.c.rej

configure.in:492: warning: AC_TRY_RUN called without default to allow cross compiling

configure.in:493: warning: AC_TRY_RUN called without default to allow cross compiling

>>> Source unpacked.
```

however it seems to be compiling ok still... does this mean the patch hasn't been apllied?

ps. i tried changeing global_myname to myname as sys_rage did, but it came up with that same thing again, so i don't think it's related.

----------

## G-LiTe`

 *phill_20x6 wrote:*   

> hmm this came up during the emerge:
> 
> ```
>  * Applying samba-2.2.5-gp-reloc-fix.patch...                             [ ok ]
> 
> ...

 

It means it's not fully applied, probably because my patch is against 2.2.8a while you are building 2.2.5.

----------

## phill_20x6

Compiling client/smbspool.c

client/smbspool.c: In function `smb_connect':

client/smbspool.c:328: label `again' used but not defined

make: *** [client/smbspool.o] Error 1

!!! ERROR: net-fs/samba-2.2.8a failed.

!!! Function src_compile, Line 117, Exitcode 2

!!! samba compile problem

 :Sad: 

----------

## theBlackDragon

Upgraden naar Samba3_rc2 verhielp het probleem bij mij  :Smile: 

----------

## G-LiTe`

 *theBlackDragon wrote:*   

> Upgraden naar Samba3_rc2 verhielp het probleem bij mij 

 

Keep it english, even though I'm dutch too.  :Wink: 

Upgrading to samba 3.0rc2 indeed fixed it, I noticed yesterday.  :Smile: 

----------

## theBlackDragon

Ow hell, where were my thoughts, my sincere appologies...  :Embarassed: 

Thx for pointing my little mistake out...   :Embarassed: 

----------

## Olli

 *G-LiTe` wrote:*   

>  *phill_20x6 wrote:*   hmm this came up during the emerge:
> 
> ```
>  * Applying samba-2.2.5-gp-reloc-fix.patch...                             [ ok ]
> 
> ...

 

Well I have the same problem with the exact same output for 2.2.8a (the 2.2.5 you mention is the version of the patch for gp-reloc)

```

Calculating dependencies ...done!

>>> emerge (1 of 1) net-fs/samba-2.2.8a to /

>>> md5 src_uri ;-) samba-2.2.8a.tar.bz2

>>> Unpacking source...

>>> Unpacking samba-2.2.8a.tar.bz2 to /var/tmp/portage/samba-2.2.8a/work

 * Applying samba-2.2.5-gp-reloc-fix.patch...                                                                              [ ok ]

patching file source/client/smbspool.c

Hunk #1 FAILED at 289.

Hunk #2 succeeded at 321 with fuzz 1.

1 out of 2 hunks FAILED -- saving rejects to file source/client/smbspool.c.rej

configure.in:492: warning: AC_TRY_RUN called without default to allow cross compiling

configure.in:493: warning: AC_TRY_RUN called without default to allow cross compiling

>>> Source unpacked.

```

----------

