diff options
Diffstat (limited to 'examples/libsmbclient')
-rw-r--r-- | examples/libsmbclient/Makefile | 20 | ||||
-rw-r--r-- | examples/libsmbclient/testchmod.c | 64 | ||||
-rw-r--r-- | examples/libsmbclient/teststat.c | 31 | ||||
-rw-r--r-- | examples/libsmbclient/testutime.c | 76 |
4 files changed, 179 insertions, 12 deletions
diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 1e89e7077e..4b4919ee7f 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -11,7 +11,15 @@ CFLAGS = -O0 -g -I$(SAMBA_INCL) $(EXTLIB_INCL) $(DEFS) LDFLAGS = -L/usr/local/samba/lib -all: testsmbc tree testacl testbrowse teststat smbsh +TESTS= testsmbc \ + tree \ + testacl \ + testbrowse \ + teststat \ + testchmod \ + testutime + +all: $(TESTS) smbsh testsmbc: testsmbc.o @echo Linking testsmbc @@ -33,9 +41,17 @@ teststat: teststat.o @echo Linking teststat @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< +testchmod: testchmod.o + @echo Linking testchmod + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + +testutime: testutime.o + @echo Linking testutime + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + smbsh: make -C smbwrapper clean: - @rm -f *.o *~ testsmbc tree testacl testbrowse teststat + @rm -f *.o *~ $(TESTS) @make -C smbwrapper clean diff --git a/examples/libsmbclient/testchmod.c b/examples/libsmbclient/testchmod.c new file mode 100644 index 0000000000..774daaed59 --- /dev/null +++ b/examples/libsmbclient/testchmod.c @@ -0,0 +1,64 @@ +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <time.h> +#include <libsmbclient.h> +#include "get_auth_data_fn.h" + + +int main(int argc, char * argv[]) +{ + int ret; + int debug = 0; + int mode = 0666; + char buffer[16384]; + char * pSmbPath = NULL; + struct stat st; + + if (argc == 1) + { + pSmbPath = "smb://RANDOM/Public/small"; + } + else if (argc == 2) + { + pSmbPath = argv[1]; + } + else if (argc == 3) + { + pSmbPath = argv[1]; + mode = (int) strtol(argv[2], NULL, 8); + } + else + { + printf("usage: " + "%s [ smb://path/to/file [ octal_mode ] ]\n", + argv[0]); + return 1; + } + + smbc_init(get_auth_data_fn, debug); + + if (smbc_stat(pSmbPath, &st) < 0) + { + perror("smbc_stat"); + return 1; + } + + printf("\nBefore chmod: mode = %04o\n", st.st_mode); + + if (smbc_chmod(pSmbPath, mode) < 0) + { + perror("smbc_chmod"); + return 1; + } + + if (smbc_stat(pSmbPath, &st) < 0) + { + perror("smbc_stat"); + return 1; + } + + printf("After chmod: mode = %04o\n", st.st_mode); + + return 0; +} diff --git a/examples/libsmbclient/teststat.c b/examples/libsmbclient/teststat.c index bea34cfc09..d67f626d78 100644 --- a/examples/libsmbclient/teststat.c +++ b/examples/libsmbclient/teststat.c @@ -9,6 +9,9 @@ int main(int argc, char * argv[]) { char buffer[16384]; + char mtime[32]; + char ctime[32]; + char atime[32]; char * pSmbPath = NULL; char * pLocalPath = NULL; struct stat st; @@ -38,21 +41,29 @@ int main(int argc, char * argv[]) smbc_init(get_auth_data_fn, 0); - int ret = smbc_stat(pSmbPath, &st); + if (smbc_stat(pSmbPath, &st) < 0) + { + perror("smbc_stat"); + return 1; + } - printf("SAMBA\nret=%d,\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", ret, - st.st_mtime, ctime(&st.st_mtime), - st.st_ctime, ctime(&st.st_ctime), - st.st_atime, ctime(&st.st_atime)); + printf("SAMBA\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", + st.st_mtime, ctime_r(&st.st_mtime, mtime), + st.st_ctime, ctime_r(&st.st_ctime, ctime), + st.st_atime, ctime_r(&st.st_atime, atime)); if (pLocalPath != NULL) { - ret = stat(pLocalPath, &st); + if (stat(pLocalPath, &st) < 0) + { + perror("stat"); + return 1; + } - printf("LOCAL\nret=%d,\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", ret, - st.st_mtime, ctime(&st.st_mtime), - st.st_ctime, ctime(&st.st_ctime), - st.st_atime, ctime(&st.st_atime)); + printf("LOCAL\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", + st.st_mtime, ctime_r(&st.st_mtime, mtime), + st.st_ctime, ctime_r(&st.st_ctime, ctime), + st.st_atime, ctime_r(&st.st_atime, atime)); } return 0; diff --git a/examples/libsmbclient/testutime.c b/examples/libsmbclient/testutime.c new file mode 100644 index 0000000000..3a1540c654 --- /dev/null +++ b/examples/libsmbclient/testutime.c @@ -0,0 +1,76 @@ +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <time.h> +#include <libsmbclient.h> +#include "get_auth_data_fn.h" + + +int main(int argc, char * argv[]) +{ + int ret; + int debug = 0; + int mode = 0666; + char buffer[16384]; + char mtime[32]; + char ctime[32]; + char atime[32]; + char * pSmbPath = NULL; + struct stat st; + struct utimbuf utimbuf; + + if (argc == 1) + { + pSmbPath = "smb://RANDOM/Public/small"; + } + else if (argc == 2) + { + pSmbPath = argv[1]; + } + else if (argc == 3) + { + pSmbPath = argv[1]; + mode = (int) strtol(argv[2], NULL, 8); + } + else + { + printf("usage: " + "%s [ smb://path/to/file [ octal_mode ] ]\n", + argv[0]); + return 1; + } + + smbc_init(get_auth_data_fn, debug); + + if (smbc_stat(pSmbPath, &st) < 0) + { + perror("smbc_stat"); + return 1; + } + + printf("Before\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", + st.st_mtime, ctime_r(&st.st_mtime, mtime), + st.st_ctime, ctime_r(&st.st_ctime, ctime), + st.st_atime, ctime_r(&st.st_atime, atime)); + + utimbuf.actime = st.st_atime - 120; /* unchangable. this one wont change */ + utimbuf.modtime = st.st_mtime - 120; /* this one should succeed */ + if (smbc_utime(pSmbPath, &utimbuf) < 0) + { + perror("smbc_utime"); + return 1; + } + + if (smbc_stat(pSmbPath, &st) < 0) + { + perror("smbc_stat"); + return 1; + } + + printf("After\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", + st.st_mtime, ctime_r(&st.st_mtime, mtime), + st.st_ctime, ctime_r(&st.st_ctime, ctime), + st.st_atime, ctime_r(&st.st_atime, atime)); + + return 0; +} |