1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

First pass at the libsmbclient code ...

This code handles the basic stuff and compiles and links under Linux, but
I do not know about any other operating systems. Now onto directory
listing routines, including those that list workgroups, servers, etc.

Nothing is built automatically yet, you have to make client/testsmbc to build
the library and test program. Also, no make install targets are defined for
libsmbclient.so as yet, either.

Would be good if people test on operating systems other than Linux.
(This used to be commit 51c0436a50)
This commit is contained in:
Richard Sharpe 2000-12-26 05:57:10 +00:00
parent b0a219686b
commit b87c484051
4 changed files with 1524 additions and 0 deletions

View File

@ -277,6 +277,8 @@ SMBW_OBJ = smbwrapper/smbw.o \
SMBWRAPPER_OBJ = $(SMBW_OBJ) smbwrapper/wrapped.o
LIBSMBCLIENT_OBJ = libsmb/libsmbclient.o $(LIB_OBJ) $(LIBSMB_OBJ) $(PARAM_OBJ) $(UBIQX_OBJ)
CLIENT_OBJ = client/client.o client/clitar.o \
$(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) $(LIB_OBJ)
@ -338,6 +340,7 @@ NSS_OBJ = $(NSS_OBJ_0:.o=.po)
PICOBJS = $(SMBWRAPPER_OBJ:.o=.po)
PICOBJS32 = $(SMBWRAPPER_OBJ:.o=.po32)
LIBSMBCLIENT_PICOBJS = $(LIBSMBCLIENT_OBJ:.0=.po)
WINBINDD_OBJ1 = \
nsswitch/winbindd.o \
@ -576,6 +579,14 @@ bin/smbwrapper.32.@SHLIBEXT@: $(PICOBJS32)
@echo Linking shared library $@
@$(LD) -32 @LDSHFLAGS@ -o $@ $(PICOBJS32) $(LIBS)
bin/libsmbclient.so: $(LIBSMBCLIENT_PICOBJS)
@echo Linking libsmbclient shared library $@
@$(LD) -shared -o $@ $(LIBSMBCLIENT_PICOBJS) $(LIBS) # Anything else?
client/testsmbc: client/testsmbc.o bin/libsmbclient.so
@echo Linking testsmbc
@$(CC) $(CFLAGS) -o $@ client/testsmbc.o -Lbin -lsmbclient
bin/smbsh: $(SMBSH_OBJ) bin/.dummy
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(SMBSH_OBJ) $(LDFLAGS) $(LIBS)

219
source3/client/testsmbc.c Normal file
View File

@ -0,0 +1,219 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB client library test program
Copyright (C) Andrew Tridgell 1998
Copyright (C) Richard Sharpe 2000
Copyright (C) John Terpsra 2000
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <errno.h>
#include <libsmbclient.h>
void auth_fn(char *server, char *share,
char **workgroup, char **username, char **password)
{
static char wg[128], un[128], pw[128];
/* DO nothing for now ... change later */
fprintf(stdout, "Enter workgroup: ");
fgets(wg, sizeof(wg), stdin);
if (wg[strlen(wg) - 1] == 0x0a) /* A new line? */
wg[strlen(wg) - 1] = 0x00;
fprintf(stdout, "Enter username: ");
fgets(un, sizeof(un), stdin);
if (un[strlen(un) - 1] == 0x0a) /* A new line? */
un[strlen(un) - 1] = 0x00;
fprintf(stdout, "Enter password: ");
fgets(pw, sizeof(pw), stdin);
if (pw[strlen(pw) - 1] == 0x0a) /* A new line? */
pw[strlen(pw) - 1] = 0x00;
*workgroup = wg; *password = pw; *username = un;
}
int main(int argc, char *argv[])
{
int err, fd;
const char *file = "smb://samba/public/testfile.txt";
const char *file2 = "smb://samba/public/testfile2.txt";
const char *workgroup = "sambanet";
char buff[256];
struct stat st1, st2;
err = smbc_init(auth_fn, workgroup, 10); /* Initialize things */
if (err < 0) {
fprintf(stderr, "Initializing the smbclient library ...: %s\n", strerror(errno));
}
/* For now, open a file on a server that is hard coded ... later will
* read from the command line ...
*/
fd = smbc_open(file, O_RDWR | O_CREAT, 0666);
if (fd < 0) {
fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
exit(0);
}
fprintf(stdout, "Opened or created file: %s\n", file);
/* Now, write some date to the file ... */
bzero(buff, sizeof(buff));
strcpy(buff, "Some test data for the moment ...");
err = smbc_write(fd, buff, sizeof(buff));
if (err < 0) {
fprintf(stderr, "writing file: %s: %s\n", file, strerror(errno));
exit(0);
}
fprintf(stdout, "Wrote %d bytes to file: %s\n", sizeof(buff), buff);
/* Now, seek the file back to offset 0 */
err = smbc_lseek(fd, SEEK_SET, 0);
if (err < 0) {
fprintf(stderr, "Seeking file: %s: %s\n", file, strerror(errno));
exit(0);
}
fprintf(stdout, "Completed lseek on file: %s\n", file);
/* Now, read the file contents back ... */
err = smbc_read(fd, buff, sizeof(buff));
if (err < 0) {
fprintf(stderr, "Reading file: %s: %s\n", file, strerror(errno));
exit(0);
}
fprintf(stdout, "Read file: %s\n", buff); /* Should check the contents */
fprintf(stdout, "Now fstat'ing file: %s\n", file);
err = smbc_fstat(fd, &st1);
if (err < 0) {
fprintf(stderr, "Fstat'ing file: %s: %s\n", file, strerror(errno));
exit(0);
}
/* Now, close the file ... */
err = smbc_close(fd);
if (err < 0) {
fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));
}
/* Now, rename the file ... */
err = smbc_rename(file, file2);
if (err < 0) {
fprintf(stderr, "Renaming file: %s to %s: %s\n", file, file2, strerror(errno));
}
fprintf(stdout, "Renamed file %s to %s\n", file, file2);
/* Now, create a file and delete it ... */
fprintf(stdout, "Now, creating file: %s so we can delete it.\n", file);
fd = smbc_open(file, O_RDWR | O_CREAT, 0666);
if (fd < 0) {
fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
exit(0);
}
fprintf(stdout, "Opened or created file: %s\n", file);
err = smbc_close(fd);
if (err < 0) {
fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));
exit(0);
}
/* Now, delete the file ... */
fprintf(stdout, "File %s created, now deleting ...\n", file);
err = smbc_unlink(file);
if (err < 0) {
fprintf(stderr, "Deleting file: %s: %s\n", file, strerror(errno));
exit(0);
}
/* Now, stat the file, file 2 ... */
fprintf(stdout, "Now stat'ing file: %s\n", file);
err = smbc_stat(file2, &st2);
if (err < 0) {
fprintf(stderr, "Stat'ing file: %s: %s\n", file, strerror(errno));
exit(0);
}
fprintf(stdout, "Stat'ed file: %s. Size = %d, mode = %04X\n", file2,
st2.st_size, st2.st_mode);
fprintf(stdout, "Earlier stat: %s, Size = %d, mode = %04X\n", file,
st1.st_size, st1.st_mode);
}

View File

@ -0,0 +1,154 @@
/*
Unix SMB/Netbios implementation.
Version 2.0
SMB client library API definitions
Copyright (C) Andrew Tridgell 1998
Copyright (C) Richard Sharpe 2000
Copyright (C) John Terpsra 2000
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _SMBCLIENT_H
#define _SMBCLIENT_H
/* Make sure we have the following includes for now ... */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#define SMBC_FILE_MODE (S_IFREG | 0444)
#define SMBC_DIR_MODE (S_IFDIR | 0555)
typedef void (*smbc_get_auth_data_fn)(char *server, char *share,
char **workgroup, char **username,
char **password);
/*
* Init the smbc package
*/
int smbc_init(smbc_get_auth_data_fn fn, const char *workgroup, int debug);
/*
* Open a file on an SMB server, this has the same form as normal open
* but the fname is a URL of the form smb://server/share/path
*/
int smbc_open(const char *fname, int flags, mode_t mode);
/*
* Create a file on an SMB server, similar to smbc_open
*/
int smbc_creat(const char *fname, mode_t mode);
/*
* Read from a file, what about pread?
*/
ssize_t smbc_read(int fd, void *buf, size_t count);
/*
* Write to a file, what about pwrite?
*/
ssize_t smbc_write(int fd, void *buf, size_t count);
/*
* Close a file by fd
*/
int smbc_close(int fd);
/*
* Unlink a file on server, share, dir, file ...
*/
int smbc_unlink(const char *fname);
/*
* rename oname to nname ... probably need to be on the same
* server initially. Later can copy between servers ...
*/
int smbc_rename(const char *oname, const char *nname);
/*
* Seek to a specific location in a file on an SMB server
*/
off_t smbc_lseek(int fd, off_t offset, int whence);
/*
* Stat a file to get info via file name
*/
int smbc_stat(const char *fname, struct stat *st);
/*
* Stat a file to get info via an fd
*/
int smbc_fstat(int fd, struct stat *st);
/*
* Chown a file
*/
int smbc_chown(const *fname, uid_t owner, gid_t group);
/*
* Chmod a file
*/
int smbc_chmod(const char *fname, mode_t newmode);
/*
* Open a directory on a URL (server and share and dir)
*/
int smbc_opendir(const char *fname);
/*
* Close a directory
*/
int smbc_closedir(int fd);
/*
* Get a directory entry
*/
int smbc_getdents(unsigned int fd, struct dirent *dirp, int count);
/*
* Create a directory on a server, share, dir in fname URL
*/
int smbc_mkdir(const char *fname, mode_t mode);
/*
* lseek on directories, rewind by smbc_lseekdir(fd, 0, SEEK_SET)
*/
int smbc_lseekdir(int fd, off_t offset, int whence);
/*
* Must also provide print functions ... soon
*/
#endif

File diff suppressed because it is too large Load Diff