summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlexander Bokovoy <ab@samba.org>2008-01-16 23:24:44 +0300
committerAlexander Bokovoy <ab@samba.org>2008-01-16 23:24:44 +0300
commitfd03ea4a903b79a0a7894315b3b43fb08108f938 (patch)
tree0dbce899aca9e727977b2a0becbcc78c6c2de6a4 /examples
parente2ffd5110173c6c7d9c15853646988e536331ed0 (diff)
parent60c3ec3fca08b7d36df760cd6093adb5a807afa0 (diff)
downloadsamba-fd03ea4a903b79a0a7894315b3b43fb08108f938.tar.gz
samba-fd03ea4a903b79a0a7894315b3b43fb08108f938.tar.bz2
samba-fd03ea4a903b79a0a7894315b3b43fb08108f938.zip
Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into v3-2-test
(This used to be commit b01f34141509c90b12003786957790866c286cba)
Diffstat (limited to 'examples')
-rw-r--r--examples/libsmbclient/Makefile2
-rw-r--r--examples/libsmbclient/get_auth_data_fn.h22
-rw-r--r--examples/libsmbclient/smbwrapper/Makefile2
-rw-r--r--examples/libsmbclient/smbwrapper/select.c5
-rw-r--r--examples/libsmbclient/smbwrapper/wrapper.c1
-rw-r--r--examples/libsmbclient/testacl.c27
-rw-r--r--examples/libsmbclient/testread.c76
7 files changed, 86 insertions, 49 deletions
diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile
index 6500707e75..26b80575fb 100644
--- a/examples/libsmbclient/Makefile
+++ b/examples/libsmbclient/Makefile
@@ -13,7 +13,7 @@ CFLAGS = -O0 -g -I$(SAMBA_INCL) $(EXTLIB_INCL) $(DEFS)
LDFLAGS = -L/usr/local/samba/lib \
-lldap -lkrb5 -lgssapi_krb5
#LIBSMBCLIENT = /usr/local/samba/lib/libsmbclient.so
-LIBSMBCLIENT = -lsmbclient -ldl -lresolv
+LIBSMBCLIENT = -lwbclient -lsmbclient -ldl -lresolv
TESTS= testsmbc \
testacl \
diff --git a/examples/libsmbclient/get_auth_data_fn.h b/examples/libsmbclient/get_auth_data_fn.h
index eb493885af..b1d36c8bea 100644
--- a/examples/libsmbclient/get_auth_data_fn.h
+++ b/examples/libsmbclient/get_auth_data_fn.h
@@ -8,7 +8,23 @@ get_auth_data_fn(const char * pServer,
char * pPassword,
int maxLenPassword)
{
- char temp[128];
+ char temp[128];
+ char server[256] = { '\0' };
+ char share[256] = { '\0' };
+ char workgroup[256] = { '\0' };
+ char username[256] = { '\0' };
+ char password[256] = { '\0' };
+
+ if (strcmp(server, pServer) == 0 &&
+ strcmp(share, pShare) == 0 &&
+ *workgroup != '\0' &&
+ *username != '\0')
+ {
+ strncpy(pWorkgroup, workgroup, maxLenWorkgroup - 1);
+ strncpy(pUsername, username, maxLenUsername - 1);
+ strncpy(pPassword, password, maxLenPassword - 1);
+ return;
+ }
fprintf(stdout, "Workgroup: [%s] ", pWorkgroup);
fgets(temp, sizeof(temp), stdin);
@@ -48,4 +64,8 @@ get_auth_data_fn(const char * pServer,
{
strncpy(pPassword, temp, maxLenPassword - 1);
}
+
+ strncpy(workgroup, pWorkgroup, sizeof(workgroup) - 1);
+ strncpy(username, pUsername, sizeof(username) - 1);
+ strncpy(password, pPassword, sizeof(password) - 1);
}
diff --git a/examples/libsmbclient/smbwrapper/Makefile b/examples/libsmbclient/smbwrapper/Makefile
index c94ef8fa6a..726435319f 100644
--- a/examples/libsmbclient/smbwrapper/Makefile
+++ b/examples/libsmbclient/smbwrapper/Makefile
@@ -1,4 +1,4 @@
-LIBS = -lsmbclient -ldl
+LIBS = -lwbclient -lsmbclient -ldl
DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL)
diff --git a/examples/libsmbclient/smbwrapper/select.c b/examples/libsmbclient/smbwrapper/select.c
index 4e87a2e2e8..bb7a25f13e 100644
--- a/examples/libsmbclient/smbwrapper/select.c
+++ b/examples/libsmbclient/smbwrapper/select.c
@@ -72,13 +72,12 @@ int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorf
int ret;
fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf;
struct timeval tval2, *ptval, end_time, now_time;
- extern void GetTimeOfDay(struct timeval *tval);
readfds2 = (readfds ? &readfds_buf : NULL);
writefds2 = (writefds ? &writefds_buf : NULL);
errorfds2 = (errorfds ? &errorfds_buf : NULL);
if (tval) {
- GetTimeOfDay(&end_time);
+ gettimeofday(&end_time, NULL);
end_time.tv_sec += tval->tv_sec;
end_time.tv_usec += tval->tv_usec;
end_time.tv_sec += end_time.tv_usec / 1000000;
@@ -96,7 +95,7 @@ int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorf
if (errorfds)
errorfds_buf = *errorfds;
if (tval) {
- GetTimeOfDay(&now_time);
+ gettimeofday(&now_time, NULL);
tval2.tv_sec = end_time.tv_sec - now_time.tv_sec;
tval2.tv_usec = end_time.tv_usec - now_time.tv_usec;
if ((signed long) tval2.tv_usec < 0) {
diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c
index 30f9037d53..958e00636e 100644
--- a/examples/libsmbclient/smbwrapper/wrapper.c
+++ b/examples/libsmbclient/smbwrapper/wrapper.c
@@ -61,6 +61,7 @@
#include <dirent.h>
#include <signal.h>
#include <stdarg.h>
+#include <string.h>
#ifdef __USE_GNU
# define SMBW_USE_GNU
#endif
diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c
index 4d327b39a7..51cc90f101 100644
--- a/examples/libsmbclient/testacl.c
+++ b/examples/libsmbclient/testacl.c
@@ -7,6 +7,7 @@
enum acl_mode
{
+ SMB_ACL_LIST,
SMB_ACL_GET,
SMB_ACL_SET,
SMB_ACL_DELETE,
@@ -24,7 +25,7 @@ int main(int argc, const char *argv[])
int debug = 0;
int numeric = 0;
int full_time_names = 0;
- enum acl_mode mode = SMB_ACL_GET;
+ enum acl_mode mode = SMB_ACL_LIST;
static char *the_acl = NULL;
int ret;
char *p;
@@ -149,6 +150,30 @@ int main(int argc, const char *argv[])
switch(mode)
{
+ case SMB_ACL_LIST:
+ ret = smbc_listxattr(path, value, sizeof(value)-2);
+ if (ret < 0)
+ {
+ printf("Could not get attribute list for [%s] %d: %s\n",
+ path, errno, strerror(errno));
+ return 1;
+ }
+
+ /*
+ * The list of attributes has a series of null-terminated strings.
+ * The list of strings terminates with an extra null byte, thus two in
+ * a row. Ensure that our buffer, which is conceivably shorter than
+ * the list of attributes, actually ends with two null bytes in a row.
+ */
+ value[sizeof(value) - 2] = '\0';
+ value[sizeof(value) - 1] = '\0';
+ printf("Supported attributes:\n");
+ for (p = value; *p; p += strlen(p) + 1)
+ {
+ printf("\t%s\n", p);
+ }
+ break;
+
case SMB_ACL_GET:
if (the_acl == NULL)
{
diff --git a/examples/libsmbclient/testread.c b/examples/libsmbclient/testread.c
index d59fc70ec1..3f94884895 100644
--- a/examples/libsmbclient/testread.c
+++ b/examples/libsmbclient/testread.c
@@ -10,66 +10,58 @@
int main(int argc, char * argv[])
{
+ int i;
int fd;
int ret;
int debug = 0;
int mode = 0666;
int savedErrno;
char buffer[2048];
- char * pSmbPath = NULL;
+ char path[2048];
+ char * p;
time_t t0;
time_t t1;
struct stat st;
- if (argc == 1)
- {
- pSmbPath = "smb://RANDOM/Public/bigfile";
- }
- else if (argc == 2)
- {
- pSmbPath = argv[1];
- }
- else
- {
- printf("usage: "
- "%s [ smb://path/to/file ]\n",
- argv[0]);
- return 1;
- }
-
smbc_init(get_auth_data_fn, debug);
- printf("Open file %s\n", pSmbPath);
-
- t0 = time(NULL);
-
- if ((fd = smbc_open(pSmbPath, O_RDONLY, 0)) < 0)
+ for (;;)
{
- perror("smbc_open");
- return 1;
- }
+ fprintf(stdout, "Path: ");
+ *path = '\0';
+ fgets(path, sizeof(path) - 1, stdin);
+ if (strlen(path) == 0)
+ {
+ return 0;
+ }
- printf("Beginning read loop.\n");
+ p = path + strlen(path) - 1;
+ if (*p == '\n')
+ {
+ *p = '\0';
+ }
+
+ if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
+ {
+ perror("smbc_open");
+ continue;
+ }
- do
- {
- ret = smbc_read(fd, buffer, sizeof(buffer));
- savedErrno = errno;
- if (ret > 0) fwrite(buffer, 1, ret, stdout);
- } while (ret > 0);
+ do
+ {
+ ret = smbc_read(fd, buffer, sizeof(buffer));
+ savedErrno = errno;
+ if (ret > 0) fwrite(buffer, 1, ret, stdout);
+ } while (ret > 0);
- smbc_close(fd);
+ smbc_close(fd);
- if (ret < 0)
- {
- errno = savedErrno;
- perror("read");
- return 1;
+ if (ret < 0)
+ {
+ errno = savedErrno;
+ perror("read");
+ }
}
- t1 = time(NULL);
-
- printf("Elapsed time: %d seconds\n", t1 - t0);
-
return 0;
}