[206] | 1 | #include <stdio.h>
|
---|
| 2 | #include <unistd.h>
|
---|
| 3 | #include <string.h>
|
---|
| 4 | #include <time.h>
|
---|
| 5 | #include <libsmbclient.h>
|
---|
| 6 | #include "get_auth_data_fn.h"
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | int main(int argc, char * argv[])
|
---|
| 10 | {
|
---|
| 11 | int ret;
|
---|
| 12 | int debug = 0;
|
---|
| 13 | char buffer[16384];
|
---|
| 14 | char mtime[32];
|
---|
| 15 | char ctime[32];
|
---|
| 16 | char atime[32];
|
---|
| 17 | char * pSmbPath = NULL;
|
---|
| 18 | time_t t = time(NULL);
|
---|
| 19 | struct tm tm;
|
---|
| 20 | struct stat st;
|
---|
| 21 | struct utimbuf utimbuf;
|
---|
| 22 |
|
---|
| 23 | if (argc == 1)
|
---|
| 24 | {
|
---|
| 25 | pSmbPath = "smb://RANDOM/Public/small";
|
---|
| 26 | }
|
---|
| 27 | else if (argc == 2)
|
---|
| 28 | {
|
---|
| 29 | pSmbPath = argv[1];
|
---|
| 30 | }
|
---|
| 31 | else if (argc == 3)
|
---|
| 32 | {
|
---|
| 33 | pSmbPath = argv[1];
|
---|
| 34 | t = (time_t) strtol(argv[2], NULL, 10);
|
---|
| 35 | }
|
---|
| 36 | else
|
---|
| 37 | {
|
---|
| 38 | printf("usage: "
|
---|
| 39 | "%s [ smb://path/to/file [ mtime ] ]\n",
|
---|
| 40 | argv[0]);
|
---|
| 41 | return 1;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | smbc_init(get_auth_data_fn, debug);
|
---|
| 45 |
|
---|
| 46 | if (smbc_stat(pSmbPath, &st) < 0)
|
---|
| 47 | {
|
---|
| 48 | perror("smbc_stat");
|
---|
| 49 | return 1;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | printf("Before\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
|
---|
| 53 | st.st_mtime, ctime_r(&st.st_mtime, mtime),
|
---|
| 54 | st.st_ctime, ctime_r(&st.st_ctime, ctime),
|
---|
| 55 | st.st_atime, ctime_r(&st.st_atime, atime));
|
---|
| 56 |
|
---|
| 57 | utimbuf.actime = t; /* unchangable (wont change) */
|
---|
| 58 | utimbuf.modtime = t; /* this one should succeed */
|
---|
| 59 | if (smbc_utime(pSmbPath, &utimbuf) < 0)
|
---|
| 60 | {
|
---|
| 61 | perror("smbc_utime");
|
---|
| 62 | return 1;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | if (smbc_stat(pSmbPath, &st) < 0)
|
---|
| 66 | {
|
---|
| 67 | perror("smbc_stat");
|
---|
| 68 | return 1;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | printf("After\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
|
---|
| 72 | st.st_mtime, ctime_r(&st.st_mtime, mtime),
|
---|
| 73 | st.st_ctime, ctime_r(&st.st_ctime, ctime),
|
---|
| 74 | st.st_atime, ctime_r(&st.st_atime, atime));
|
---|
| 75 |
|
---|
| 76 | return 0;
|
---|
| 77 | }
|
---|