r6151: additional examples/tests for libsmbclient
authorDerrell Lipman <derrell@samba.org>
Thu, 31 Mar 2005 16:26:15 +0000 (16:26 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:56:25 +0000 (10:56 -0500)
(This used to be commit a3bd496c921dc775b59be4ff2941f4824ffbec03)

examples/libsmbclient/Makefile
examples/libsmbclient/testchmod.c [new file with mode: 0644]
examples/libsmbclient/teststat.c
examples/libsmbclient/testutime.c [new file with mode: 0644]

index 1e89e7077e7d52413a260b0193fb369707a406cf..4b4919ee7ff2bbc3e2cb824a0e19050c6abe090b 100644 (file)
@@ -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 (file)
index 0000000..774daae
--- /dev/null
@@ -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; 
+}
index bea34cfc098e0800a83b7846818f970411187b06..d67f626d78df7c376eed7e191ecabdff36073751 100644 (file)
@@ -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 (file)
index 0000000..3a1540c
--- /dev/null
@@ -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; 
+}