summaryrefslogtreecommitdiff
path: root/examples/libsmbclient
diff options
context:
space:
mode:
Diffstat (limited to 'examples/libsmbclient')
-rw-r--r--examples/libsmbclient/Makefile9
-rw-r--r--examples/libsmbclient/smbwrapper/smbw.c10
-rw-r--r--examples/libsmbclient/testacl.c2
-rw-r--r--examples/libsmbclient/testacl2.c2
-rw-r--r--examples/libsmbclient/testacl3.c2
-rw-r--r--examples/libsmbclient/testbrowse.c19
-rw-r--r--examples/libsmbclient/testbrowse2.c17
-rw-r--r--examples/libsmbclient/testsmbc.c2
-rw-r--r--examples/libsmbclient/testtruncate.c82
9 files changed, 115 insertions, 30 deletions
diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile
index 6c70659661..a50e80a918 100644
--- a/examples/libsmbclient/Makefile
+++ b/examples/libsmbclient/Makefile
@@ -1,14 +1,14 @@
#
CC = gcc
-SAMBA_INCL = ../../source/include
+SAMBA_INCL = -I/usr/local/samba/include
EXTLIB_INCL = -I/usr/include/gtk-1.2 \
-I/usr/include/glib-1.2 \
-I/usr/lib/glib/include
EXTLIB_INCL = `gtk-config --cflags`
DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
-CFLAGS = -O0 -g -I$(SAMBA_INCL) $(EXTLIB_INCL) $(DEFS)
+CFLAGS = -O0 -g $(SAMBA_INCL) $(EXTLIB_INCL) $(DEFS)
LDFLAGS = -L/usr/local/samba/lib \
-lldap -lkrb5 -lgssapi_krb5
@@ -24,6 +24,7 @@ TESTS= testsmbc \
teststat \
teststat2 \
teststat3 \
+ testtruncate \
testchmod \
testutime \
testread \
@@ -73,6 +74,10 @@ teststat3: teststat3.o
@echo Linking teststat3
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt
+testtruncate: testtruncate.o
+ @echo Linking testtruncate
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt
+
testchmod: testchmod.o
@echo Linking testchmod
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt
diff --git a/examples/libsmbclient/smbwrapper/smbw.c b/examples/libsmbclient/smbwrapper/smbw.c
index b88290ff6d..e2e44c1f0f 100644
--- a/examples/libsmbclient/smbwrapper/smbw.c
+++ b/examples/libsmbclient/smbwrapper/smbw.c
@@ -174,11 +174,11 @@ static void do_init(StartupType startupType)
exit(1);
}
- smbw_ctx->debug = debug_level;
- smbw_ctx->callbacks.auth_fn = get_auth_data_fn;
- smbw_ctx->options.browse_max_lmb_count = 0;
- smbw_ctx->options.urlencode_readdir_entries = 1;
- smbw_ctx->options.one_share_per_server = 1;
+ smbc_setDebug(smbw_ctx, debug_level);
+ smbc_setFunctionAuthData(smbw_ctx, get_auth_data_fn);
+ smbc_setOptionBrowseMaxLmbCount(smbw_ctx, 0);
+ smbc_setOptionUrlEncodeReaddirEntries(smbw_ctx, 1);
+ smbc_setOptionOneSharePerServer(smbw_ctx, 1);
if (smbc_init_context(smbw_ctx) == NULL) {
fprintf(stderr, "Could not initialize context.\n");
diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c
index 51cc90f101..00e1c2c9da 100644
--- a/examples/libsmbclient/testacl.c
+++ b/examples/libsmbclient/testacl.c
@@ -143,7 +143,7 @@ int main(int argc, const char *argv[])
if (full_time_names) {
SMBCCTX *context = smbc_set_context(NULL);
- smbc_option_set(context, "full_time_names", 1);
+ smbc_setOptionFullTimeNames(context, 1);
}
/* Perform requested action */
diff --git a/examples/libsmbclient/testacl2.c b/examples/libsmbclient/testacl2.c
index df38fe208e..d2a97cf2d2 100644
--- a/examples/libsmbclient/testacl2.c
+++ b/examples/libsmbclient/testacl2.c
@@ -39,7 +39,7 @@ int main(int argc, const char *argv[])
}
SMBCCTX *context = smbc_set_context(NULL);
- smbc_option_set(context, "full_time_names", 1);
+ smbc_setOptionFullTimeNames(context, 1);
the_acl = strdup("system.nt_sec_desc.*");
ret = smbc_getxattr(argv[1], the_acl, value, sizeof(value));
diff --git a/examples/libsmbclient/testacl3.c b/examples/libsmbclient/testacl3.c
index 9102405659..4ef6e80a7b 100644
--- a/examples/libsmbclient/testacl3.c
+++ b/examples/libsmbclient/testacl3.c
@@ -28,7 +28,7 @@ int main(int argc, char * argv[])
smbc_init(get_auth_data_fn, debug);
context = smbc_set_context(NULL);
- smbc_option_set(context, "full_time_names", 1);
+ smbc_setOptionFullTimeNames(context, 1);
for (;;)
{
diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c
index 562d2c2aeb..a7eda365af 100644
--- a/examples/libsmbclient/testbrowse.c
+++ b/examples/libsmbclient/testbrowse.c
@@ -108,24 +108,21 @@ main(int argc, char * argv[])
}
/* Set mandatory options (is that a contradiction in terms?) */
- context->debug = debug;
+ smbc_setDebug(context, debug);
if (context_auth) {
- context->callbacks.auth_fn = NULL;
- smbc_option_set(context,
- "auth_function",
- (void *) get_auth_data_with_context_fn);
- smbc_option_set(context, "user_data", "hello world");
+ smbc_setFunctionAuthDataWithContext(context,
+ get_auth_data_with_context_fn);
+ smbc_setOptionUserData(context, "hello world");
} else {
- context->callbacks.auth_fn =
- (no_auth ? no_auth_data_fn : get_auth_data_fn);
+ smbc_setFunctionAuthData(context, get_auth_data_fn);
}
/* If we've been asked to log to stderr instead of stdout, ... */
if (debug_stderr) {
/* ... then set the option to do so */
- smbc_option_set(context, "debug_to_stderr", 1);
+ smbc_setOptionDebugToStderr(context, 1);
}
-
+
/* Initialize the context using the previously specified options */
if (!smbc_init_context(context)) {
smbc_free_context(context, 0);
@@ -199,7 +196,7 @@ get_auth_data_with_context_fn(SMBCCTX * context,
{
printf("Authenticating with context 0x%lx", context);
if (context != NULL) {
- char *user_data = smbc_option_get(context, "user_data");
+ char *user_data = smbc_getOptionUserData(context);
printf(" with user data %s", user_data);
}
printf("\n");
diff --git a/examples/libsmbclient/testbrowse2.c b/examples/libsmbclient/testbrowse2.c
index 76d98b9602..0ac1d72bb4 100644
--- a/examples/libsmbclient/testbrowse2.c
+++ b/examples/libsmbclient/testbrowse2.c
@@ -93,8 +93,8 @@ SMBCCTX* create_smbctx(){
if ((ctx = smbc_new_context()) == NULL) return NULL;
- ctx->debug = debuglevel;
- ctx->callbacks.auth_fn = smbc_auth_fn;
+ smbc_setDebug(ctx, debuglevel);
+ smbc_setFunctionAuthData(ctx, smbc_auth_fn);
if (smbc_init_context(ctx) == NULL){
smbc_free_context(ctx, 1);
@@ -105,7 +105,7 @@ SMBCCTX* create_smbctx(){
}
void delete_smbctx(SMBCCTX* ctx){
- ctx->callbacks.purge_cached_fn(ctx);
+ smbc_getFunctionPurgeCachedServers(ctx)(ctx);
smbc_free_context(ctx, 1);
}
@@ -114,8 +114,9 @@ smbitem* get_smbitem_list(SMBCCTX *ctx, char *smb_path){
struct smbc_dirent *dirent;
smbitem *list = NULL, *item;
- if ((fd = ctx->opendir(ctx, smb_path)) == NULL) return NULL;
- while((dirent = ctx->readdir(ctx, fd)) != NULL){
+ if ((fd = smbc_getFunctionOpendir(ctx)(ctx, smb_path)) == NULL)
+ return NULL;
+ while((dirent = smbc_getFunctionReaddir(ctx)(ctx, fd)) != NULL){
if (strcmp(dirent->name, "") == 0) continue;
if (strcmp(dirent->name, ".") == 0) continue;
if (strcmp(dirent->name, "..") == 0) continue;
@@ -128,7 +129,7 @@ smbitem* get_smbitem_list(SMBCCTX *ctx, char *smb_path){
strcpy(item->name, dirent->name);
list = item;
}
- ctx->close_fn(ctx, fd);
+ smbc_getFunctionClose(ctx)(ctx, fd);
return /* smbitem_list_sort */ (list);
}
@@ -167,7 +168,7 @@ void recurse(SMBCCTX *ctx, char *smb_group, char *smb_path, int maxlen){
delete_smbctx(ctx1);
}else{
recurse(ctx, smb_group, smb_path, maxlen);
- ctx->callbacks.purge_cached_fn(ctx);
+ smbc_getFunctionPurgeCachedServers(ctx)(ctx);
}
break;
case SMBC_FILE_SHARE:
@@ -181,7 +182,7 @@ void recurse(SMBCCTX *ctx, char *smb_group, char *smb_path, int maxlen){
if (list->type != SMBC_FILE){
recurse(ctx, smb_group, smb_path, maxlen);
if (list->type == SMBC_FILE_SHARE)
- ctx->callbacks.purge_cached_fn(ctx);
+ smbc_getFunctionPurgeCachedServers(ctx)(ctx);
}
break;
}
diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c
index c506f5fd64..1f06437293 100644
--- a/examples/libsmbclient/testsmbc.c
+++ b/examples/libsmbclient/testsmbc.c
@@ -25,7 +25,7 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
-#include <libsmbclient.h>
+#include "libsmbclient.h"
#include "get_auth_data_fn.h"
int global_id = 0;
diff --git a/examples/libsmbclient/testtruncate.c b/examples/libsmbclient/testtruncate.c
new file mode 100644
index 0000000000..8882acd85d
--- /dev/null
+++ b/examples/libsmbclient/testtruncate.c
@@ -0,0 +1,82 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <time.h>
+#include <errno.h>
+#include <libsmbclient.h>
+#include "get_auth_data_fn.h"
+
+
+int main(int argc, char * argv[])
+{
+ int fd;
+ int ret;
+ int debug = 0;
+ int savedErrno;
+ char buffer[128];
+ char * pSmbPath = NULL;
+ char * pLocalPath = NULL;
+ struct stat st;
+
+ if (argc != 2)
+ {
+ printf("usage: "
+ "%s smb://path/to/file\n",
+ argv[0]);
+ return 1;
+ }
+
+ smbc_init(get_auth_data_fn, debug);
+
+ if ((fd = smbc_open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
+ {
+ perror("smbc_open");
+ return 1;
+ }
+
+ strcpy(buffer, "Hello world.\nThis is a test.\n");
+
+ ret = smbc_write(fd, buffer, strlen(buffer));
+ savedErrno = errno;
+ smbc_close(fd);
+
+ if (ret < 0)
+ {
+ errno = savedErrno;
+ perror("write");
+ }
+
+ if (smbc_stat(argv[1], &st) < 0)
+ {
+ perror("smbc_stat");
+ return 1;
+ }
+
+ printf("Original size: %lu\n", (unsigned long) st.st_size);
+
+ if ((fd = smbc_open(argv[1], O_WRONLY, 0)) < 0)
+ {
+ perror("smbc_open");
+ return 1;
+ }
+
+ ret = smbc_ftruncate(fd, 13);
+ savedErrno = errno;
+ smbc_close(fd);
+ if (ret < 0)
+ {
+ errno = savedErrno;
+ perror("smbc_ftruncate");
+ return 1;
+ }
+
+ if (smbc_stat(argv[1], &st) < 0)
+ {
+ perror("smbc_stat");
+ return 1;
+ }
+
+ printf("New size: %lu\n", (unsigned long) st.st_size);
+
+ return 0;
+}