diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-03-05 19:42:15 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-03-05 19:42:15 +0100 |
commit | 63036a6f3380652c0cb54627bdeabcd212fa2f8c (patch) | |
tree | 90194f23cb1e6ca483e7773233c326a9b705f85f /examples | |
parent | d41d580c600e3228ff8fee5c16c47580f661a240 (diff) | |
parent | 932c287a406048759fa1ac4bf86e29d96991ded1 (diff) | |
download | samba-63036a6f3380652c0cb54627bdeabcd212fa2f8c.tar.gz samba-63036a6f3380652c0cb54627bdeabcd212fa2f8c.tar.bz2 samba-63036a6f3380652c0cb54627bdeabcd212fa2f8c.zip |
Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into v3-2-test
(This used to be commit 3482cd9b0e81bbc801f1cec33fca82fc45a3ddef)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/libsmbclient/Makefile | 9 | ||||
-rw-r--r-- | examples/libsmbclient/smbwrapper/smbw.c | 10 | ||||
-rw-r--r-- | examples/libsmbclient/testacl.c | 2 | ||||
-rw-r--r-- | examples/libsmbclient/testacl2.c | 2 | ||||
-rw-r--r-- | examples/libsmbclient/testacl3.c | 2 | ||||
-rw-r--r-- | examples/libsmbclient/testbrowse.c | 19 | ||||
-rw-r--r-- | examples/libsmbclient/testbrowse2.c | 17 | ||||
-rw-r--r-- | examples/libsmbclient/testsmbc.c | 2 | ||||
-rw-r--r-- | examples/libsmbclient/testtruncate.c | 82 | ||||
-rw-r--r-- | examples/scripts/mount/mount.smbfs | 115 |
10 files changed, 230 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; +} diff --git a/examples/scripts/mount/mount.smbfs b/examples/scripts/mount/mount.smbfs new file mode 100644 index 0000000000..3b57bc5141 --- /dev/null +++ b/examples/scripts/mount/mount.smbfs @@ -0,0 +1,115 @@ +#!/bin/bash +# Debian mount.smbfs compatibility wrapper +# Copyright 2007, Steve Langasek <vorlon at debian.org> +# Licensed under the GNU General Public License, version 2. See the +# file /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>. + +# This script accepts all documented mount options for mount.smbfs, +# passing through those that are also recognized by mount.cifs, +# converting those that are not recognized but map to available cifs +# options, and warning about the use of options for which no equivalent +# exists. + +# known bugs: quoted spaces in arguments are not passed intact + +set -e + +# reverse the order of username and password in a "username" parameter, +# taking care to leave any "%password" bit intact + +reverse_username_workgroup() { + local workgroup password username + + username="$1" + case "$username" in + *%*) password="${username#*%}" + username="${username%%%*}" + ;; + *) ;; + esac + case "$username" in + */*) workgroup="${username#*/}" + username="${username%%/*}" + ;; + *) ;; + esac + if [ -n "$workgroup" ]; then + username="$workgroup\\$username" + fi + if [ -n "$password" ]; then + username="$username%$password" + fi + echo "$username" +} + + +# parse out the mount options that have been specified using -o, and if +# necessary, convert them for use by mount.cifs + +parse_mount_options () { + local OLD_IFS IFS options option username + OLD_IFS="$IFS" + IFS="," + options="" + workgroup="" + password="" + + for option in $@; do + case "$option" in + sockopt=* | scope=* | codepage=* | ttl=* | debug=*) + echo "Warning: ignoring deprecated smbfs option '$option'" >&2 + ;; + + krb) + options="$options${options:+,}sec=krb5" + ;; + + guest) + echo "Warning: mapping 'guest' to 'guest,sec=none'" >&2 + options="$options${options:+,}guest,sec=none" + ;; + + # username and workgroup are reversed in username= arguments, + # so need to be parsed out + username=*/*) + IFS="$OLD_IFS" + username="${option#username=}" + username="$(reverse_username_workgroup "$username")" + IFS="," + options="$options${options:+,}username=$username" + ;; + + *) + options="$options${options:+,}$option" + ;; + esac + done + IFS="$OLD_IFS" + echo $options +} + +args=() +while [ "$#" -gt 0 ]; do + case "$1" in + -o*) + arg=${1#-o} + shift + if [ -z "$arg" ]; then + arg=$1 + shift + fi + arg="$(parse_mount_options "$arg")" + if [ -n "$arg" ]; then + args=("${args[@]}" "-o" "$arg") + fi + ;; + *) + args=("${args[@]}" "$1") + shift + ;; + esac +done + +USER="$(reverse_username_workgroup "$USER")" + +exec /sbin/mount.cifs "${args[@]}" |