[Samba] programming libsmbclient
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; charbuffer[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 lp_load: refreshing parameters Initialising global parameters params.c:OpenConfFile() - Unable to open configuration file /home/vodmat/.smb/smb.conf: No such file or directory pm_process() returned No lp_servicenumber: couldn't find homes Attempting to register new charset UCS-2LE Registered charset UCS-2LE Attempting to register new charset UTF-16LE Registered charset UTF-16LE Attempting to register new charset UCS-2BE Registered charset UCS-2BE Attempting to register new charset UTF-16BE Registered charset UTF-16BE Attempting to register new charset UTF8 Registered charset UTF8 Attempting to register new charset UTF-8 Registered charset UTF-8 Attempting to register new charset ASCII Registered charset ASCII Attempting to register new charset 646 Registered charset 646 Attempting to register new charset ISO-8859-1 Registered charset ISO-8859-1 Attempting to register new charset UCS2-HEX Registered charset UCS2-HEX Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Could not load config file: /home/vodmat/.smb/smb.conf lp_load: refreshing parameters params.c:pm_process() - Processing
[Samba] programming libsmbclient
hi all, I have a strange problem using the libsmbclient api.. 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 am not sure but, url encoding/decoding that would escape strings with percent in should be 'internals' of samba right ? 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. 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; charbuffer[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 lp_load: refreshing parameters Initialising global parameters params.c:OpenConfFile() - Unable to open configuration file /home/vodmat/.smb/smb.conf: No such file or directory pm_process() returned No lp_servicenumber: couldn't find homes Attempting to register new charset UCS-2LE Registered charset UCS-2LE Attempting to register new charset UTF-16LE Registered charset UTF-16LE Attempting to register new charset UCS-2BE Registered charset UCS-2BE Attempting to register new charset UTF-16BE Registered charset UTF-16BE Attempting to register new charset UTF8 Registered charset UTF8 Attempting to register new charset UTF-8 Registered charset UTF-8 Attempting to register new charset ASCII Registered charset ASCII Attempting to register new charset 646 Registered charset 646 Attempting to register new charset ISO-8859-1 Registered charset ISO-8859-1 Attempting to register new charset UCS2-HEX Registered charset UCS2-HEX Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Substituting charset 'ISO-8859-15' for LOCALE Could not load config file: /home/vodmat/.smb/smb.conf lp_load: refreshing parameters params.c:pm_process