mirror of
https://github.com/samba-team/samba.git
synced 2025-01-25 06:04:04 +03:00
r6151: additional examples/tests for libsmbclient
This commit is contained in:
parent
994694f7f2
commit
a3bd496c92
@ -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
|
||||
|
64
examples/libsmbclient/testchmod.c
Normal file
64
examples/libsmbclient/testchmod.c
Normal file
@ -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;
|
||||
}
|
@ -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;
|
||||
|
76
examples/libsmbclient/testutime.c
Normal file
76
examples/libsmbclient/testutime.c
Normal file
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user