svn commit: samba r6151 - in
branches/SAMBA_3_0/examples/libsmbclient: .
derrell at samba.org
derrell at samba.org
Thu Mar 31 16:26:16 GMT 2005
Author: derrell
Date: 2005-03-31 16:26:15 +0000 (Thu, 31 Mar 2005)
New Revision: 6151
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=6151
Log:
additional examples/tests for libsmbclient
Added:
branches/SAMBA_3_0/examples/libsmbclient/testchmod.c
branches/SAMBA_3_0/examples/libsmbclient/testutime.c
Modified:
branches/SAMBA_3_0/examples/libsmbclient/Makefile
branches/SAMBA_3_0/examples/libsmbclient/teststat.c
Changeset:
Modified: branches/SAMBA_3_0/examples/libsmbclient/Makefile
===================================================================
--- branches/SAMBA_3_0/examples/libsmbclient/Makefile 2005-03-31 12:40:12 UTC (rev 6150)
+++ branches/SAMBA_3_0/examples/libsmbclient/Makefile 2005-03-31 16:26:15 UTC (rev 6151)
@@ -11,8 +11,16 @@
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
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient
@@ -33,9 +41,17 @@
@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
Added: branches/SAMBA_3_0/examples/libsmbclient/testchmod.c
===================================================================
--- branches/SAMBA_3_0/examples/libsmbclient/testchmod.c 2005-03-31 12:40:12 UTC (rev 6150)
+++ branches/SAMBA_3_0/examples/libsmbclient/testchmod.c 2005-03-31 16:26:15 UTC (rev 6151)
@@ -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;
+}
Modified: branches/SAMBA_3_0/examples/libsmbclient/teststat.c
===================================================================
--- branches/SAMBA_3_0/examples/libsmbclient/teststat.c 2005-03-31 12:40:12 UTC (rev 6150)
+++ branches/SAMBA_3_0/examples/libsmbclient/teststat.c 2005-03-31 16:26:15 UTC (rev 6151)
@@ -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 @@
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;
Added: branches/SAMBA_3_0/examples/libsmbclient/testutime.c
===================================================================
--- branches/SAMBA_3_0/examples/libsmbclient/testutime.c 2005-03-31 12:40:12 UTC (rev 6150)
+++ branches/SAMBA_3_0/examples/libsmbclient/testutime.c 2005-03-31 16:26:15 UTC (rev 6151)
@@ -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;
+}
More information about the samba-cvs
mailing list