Bug 3339 - libsmbclient smbc_stat returns wrong mtime and atime
libsmbclient smbc_stat returns wrong mtime and atime
Product: Samba 3.0
Classification: Unclassified
Component: libsmbclient
x86 Windows XP
: P3 major
: none
Assigned To: Derrell Lipman
Samba QA Contact
Depends on:
  Show dependency treegraph
Reported: 2005-12-19 07:03 UTC by Henrik
Modified: 2005-12-29 13:00 UTC (History)
0 users

See Also:

testprogram to reproduce the error (1.43 KB, text/plain)
2005-12-19 07:06 UTC, Henrik
no flags Details
tcpdump -s 0 -w output file (4.78 KB, application/octet-stream)
2005-12-19 07:07 UTC, Henrik
no flags Details
Readme how we went about with this problem (1.03 KB, text/plain)
2005-12-19 07:07 UTC, Henrik
no flags Details
Makefile for testprogram (685 bytes, text/plain)
2005-12-19 07:08 UTC, Henrik
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Henrik 2005-12-19 07:03:20 UTC
We are using libsmbclient from Samba 3.0.21rc1 and the function smbc_stat return wrong values.
atime always returns value 1 and mtime always returns file access time. ctime works as intended.

We enclose one testprogram staterror.c and also a tcpdump -s 0 -w ftime-problem.pcap file.

Comment 1 Henrik 2005-12-19 07:06:42 UTC
Created attachment 1623 [details]
testprogram to reproduce the error
Comment 2 Henrik 2005-12-19 07:07:12 UTC
Created attachment 1624 [details]
tcpdump -s 0 -w output file
Comment 3 Henrik 2005-12-19 07:07:45 UTC
Created attachment 1625 [details]
Readme how we went about with this problem
Comment 4 Henrik 2005-12-19 07:08:04 UTC
Created attachment 1626 [details]
Makefile for testprogram
Comment 5 Derrell Lipman 2005-12-24 18:58:29 UTC
It seems that your application and libsmbclient were not compiled with the same options.  The attributes are (mostly) correct in my testing.  I modified your test program a little bit.  Instead of comparing against a random local file, I set up a Samba server on the local machine, and then compared smbc_stat() of that file against stat() of the same file.  During my testing, I discovered that the parsing of the last_write_time and change_time were reversed.  We pull change_time as mtime.  This should not matter in most cases, though, since last_write_time and change_time tend to be the same.  Additionally, I discovered that the create time of a file returned by the Samba server is not always identical to the create time found by stat() of the local file; i.e. when mtime is less than ctime, mtime is sometimes returned as ctime.  I need to look into that, but it's independent of the problem you are encountering.

One potential issue is that libsmbclient may be compiled with "struct stat" really being "struct timeval" with st_atime referencing actual field tv_atim.sec.  Since struct stat.st_*time are simple time_t values and struct timeval tv_*tim is a structure containing two values the same size as time_t, the atime=mtime that you're seeing is likely related to this.  Confirm that your application is being compiled with exactly the same options as libsmbclient.

If after looking into the above you still feel there's a problem, please reopen this bug.
Comment 6 Henrik 2005-12-25 10:35:24 UTC
Hi Derell,

I'll look into your comments and I'll try your suggested solution.
I understand why the local and samba ctime is different as ctime on linux is CHANGE time and not CREATION time but I guess you already new that. The best way to test samba ctime is to look at a winbox and see if it reports the same creation time as creation attribute is not stored on the linux fs. 

I discovered this issue when upgrading from 3.0.20a to b and my Ruby/SMB library started returning wrong values. I havn't written the original  Ruby/SMB code so I can't really say what is going on there but to test it out I used the example program supplied with Samba 3.0.21-rc1 that uses smbc_stat and it too returned wrong values. 

I'll let you know how it goes!

Comment 7 Henrik 2005-12-29 08:44:13 UTC
Hi Derell,
I've looked into your solutions but can't really understand the libsmbclient compilation options.
I hve a fbsd box with a port install of samba.3.0.20b and there my program works as planned and returns the right mtime, atime and ctime of the file residing on my Win box. I also know that it worked when I made a rpm install on a fedora box with the same version.

But after installing the 3.0.21 rpm on my fedora box the program no longer returns the right values of the file on my Win box so it looks like their is a compilation issue in the distributed rpm. I really didn't understand your paramters when compiling libsmbclient so I would be greatfull if your could give me a little info on how I should compile libsmbclient correctly and also it would be nice with the modified version you made of my littel testprogram and also which paramters you used when you compiled the program.

Comment 8 Derrell Lipman 2005-12-29 09:47:02 UTC
Please pull latest code from SVN.  Use the SAMBA_3_0 branch.  (for instructions to pull the code, see http://us2.samba.org/samba/subversion.html)

Change directory into the 'source' directory, type

 autogen.sh && configure --enable-debug && make && make install

(You can pass the --prefix option to configure if you like, to specify where samba will be installed to.

Change directory to ../examples/libsmbclient and type "make".

Configure a samba server on the local machine.  Provide a public (read-only, if desired) shared folder and put a file in it.  Run ./teststat2 giving it two parameters: the url for the file on the local samba server and the pathname for the same file via its local path.  You should get reasonable results from the smbc_stat() call, resembling the results from stat() on the same file.

Please let me know your results.
Comment 9 Henrik 2005-12-29 11:09:11 UTC
Is the repo broken?
Using :svn update
At revision 12579.

Compiling dynconfig.c
In file included from include/includes.h:1032,
                 from /home/jonas/svnsmb/source/dynconfig.c:21:
include/proto.h:1601: error: syntax error before 'kpasswd_err_to_krb5_err'
include/proto.h:1601: error: syntax error before 'res_code'
include/proto.h:1601: warning: data definition has no type or storage class
make: *** [dynconfig.o] Error 

Comment 10 Derrell Lipman 2005-12-29 11:19:48 UTC
Did you do "make distclean" and start from scratch?  There some changes recently that modified prototypes.  Also, please ensure that you are using the SAMBA_3_0 branch.
Comment 11 Henrik 2005-12-29 12:22:42 UTC
Hi Derell,

I can inform you that when using your instructions I get the correct values?
Why is that? =)

Comment 12 Derrell Lipman 2005-12-29 13:00:18 UTC
Ok.  That indicates that the library is fine, and you just have some compilation or linking problem with your application, or there's something going on with the rpm you downloaded.  Look at the Makefile in examples/libsmbclient and compile your application exactly the same way.  In fact, move your test program into examples/libsmbclient, clone the "teststat2" portion of the Makefile and add your test application below it with everything the same except for the applciation name.  I expect you'll get proper results once you build that way.  If not, email me offline and I'll try to help you figure out the problem.

Marking as closed.