[Samba] programming libsmbclient
Henrik Zagerholm
henke at mac.se
Fri May 25 22:19:30 GMT 2007
I made my own which works so far :)
Just do
m_pURLEncode = new Replace( "%", "%25" );
fd = smbc_open( m_pURLEncode->Translate(ossSMBURL.str()).c_str(),
O_RDONLY, 0 );
So I just replace all % with %25 which is the code for % and you
should be ok.
Cheers,
henrik
10 maj 2007 kl. 16:06 skrev Mattieu Puel:
> hi all,
> I have a strange problem using the libsmbclient..
>
> retrieving or stating files named with percents in is for some
> of them impossible. Example: a file located at "smb://test/test/%
> 7C2.txt" cannot be retrieved
> with my code, smbc_open fails with the code
> NT_STATUS_OBJECT_NAME_INVALID. I have not found
> on the web exemples of url encoding/decoding that would escape
> strings with "percent" in..
> At the same time under the same constraints, a file named 'whatever-
> you-want-except-with-percent'
> is correctly stated, opened, read.
> I tested the code on several distributions (debian, gentoo..) with
> the same results. I tried
> with several CIFS servers too (Win Xp, linux...). Attached: the source
> and the trace given by smbc_init with debug = 9.
>
> Has anyone any idea ?
>
>
> the code:
>
>
> ----------------------------------------------------------------------
> ----------------
> #include <sys/types.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <string.h>
> #include <time.h>
> #include <errno.h>
> #include <libsmbclient.h>
>
> static void
> get_auth_data_fn(const char * pServer,
> const char * pShare,
> char * pWorkgroup,
> int maxLenWorkgroup,
> char * pUsername,
> int maxLenUsername,
> char * pPassword,
> int maxLenPassword)
> {
> sprintf( pWorkgroup, "%s", "WG" );
> sprintf( pUsername, "%s", "test" );
> sprintf( pPassword, "%s", "test" );
> }
>
>
> int main(int argc, char * argv[])
> {
> int fd;
> int ret;
> int debug = 9;
> int savedErrno;
> char buffer[2048];
> char * pSmbPath = NULL;
>
> if (argc == 2)
> {
> pSmbPath = argv[1];
> }
> else
> {
> printf("usage: "
> "%s [ smb://path/to/file ]\n",
> argv[0]);
> return 1;
> }
>
> smbc_init(get_auth_data_fn, debug);
>
> printf("Open file %s\n", pSmbPath);
>
> if ((fd = smbc_open(pSmbPath, O_RDONLY, 0)) < 0)
> {
> perror("smbc_open");
> return 1;
> }
>
> do
> {
> ret = smbc_read(fd, buffer, sizeof(buffer));
> savedErrno = errno;
> if (ret > 0) fwrite(buffer, 1, ret, stdout);
> } while (ret > 0);
>
> smbc_close(fd);
>
> if (ret < 0)
> {
> errno = savedErrno;
> perror("read");
> return 1;
> }
>
>
> return 0;
> }
>
> ----------------------------------------------------------------------
> --------
>
> the tail of the trace:
>
> Server connect ok: //regis/dossier: 0x8050508
> write_socket(4,88)
> write_socket(4,88) wrote 88
> size=35
> smb_com=0x2d
> smb_rcls=51
> smb_reh=0
> smb_err=49152
> smb_flg=136
> smb_flg2=51201
> smb_tid=2048
> smb_pid=13079
> smb_uid=2048
> smb_mid=5
> smt_wct=0
> smb_bcc=0
> smbc errno NT_STATUS_OBJECT_NAME_INVALID -> 22
> smbc_open: Argument invalide
> Open file smb://regis/dossier/a%7C2.txt
>
>
>
>
> --
> Mattieu PUEL
> Recherche & développement
> --
> Intradot Labs SAS
> +33 4 78 80 87 90 | www.intradot.com
> --
> Intradot a déménagé !
> Notez bien notre nouvelle adresse :
> 97 rue Racine - 69100 Villeurbanne
> <trace>
> --
> To unsubscribe from this list go to the following URL and read the
> instructions: https://lists.samba.org/mailman/listinfo/samba
More information about the samba
mailing list