From 49177b07c831bd463752e6489c29e9dc0e680301 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Thu, 17 May 2001 02:29:00 +0000 Subject: Adding an examples directory for libsmbclient to the head branch along with a simple Makefile and a small README ... (This used to be commit 950821d69cb6dcc723f8610584718c6217136d55) --- examples/libsmbclient/Makefile | 20 + examples/libsmbclient/README | 8 + examples/libsmbclient/testsmbc.c | 456 ++++++++++++++++++++++ examples/libsmbclient/tree.c | 812 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1296 insertions(+) create mode 100644 examples/libsmbclient/Makefile create mode 100644 examples/libsmbclient/README create mode 100644 examples/libsmbclient/testsmbc.c create mode 100644 examples/libsmbclient/tree.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile new file mode 100644 index 0000000000..20bc99cac0 --- /dev/null +++ b/examples/libsmbclient/Makefile @@ -0,0 +1,20 @@ +# + +SAMBA_INCL = ../../source/include + +CFLAGS = -I$(SAMBA_INCL) + +LDFLAGS = -L/usr/lib + +all: testsmbc tree + +testsmbc: testsmbc.o + @echo Linking testsmbc + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient + +tree: tree.o + @echo Linking tree + @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient $< + +clean: + @rm -f *.o *~ \ No newline at end of file diff --git a/examples/libsmbclient/README b/examples/libsmbclient/README new file mode 100644 index 0000000000..d9a9f82917 --- /dev/null +++ b/examples/libsmbclient/README @@ -0,0 +1,8 @@ +Some simple example programs for libsmbclient ... + +testsmbc.c is kinda broken as it has many hardcoded bits in it + +tree.c is an example of how you might do some of these things with GTK+ +It needs lots of work but shows you some ways to use libsmbclient. + +Richard Sharpe, 17-May-2001 ... diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c new file mode 100644 index 0000000000..7aae9d8561 --- /dev/null +++ b/examples/libsmbclient/testsmbc.c @@ -0,0 +1,456 @@ +/* + 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 +#include +#include +#include +#include +#include +#include + +void auth_fn(const char *server, const char *share, + char *workgroup, int wgmaxlen, char *username, int unmaxlen, + char *password, int pwmaxlen) +{ + char temp[128]; + + fprintf(stdout, "Need password for //%s/%s\n", server, share); + + fprintf(stdout, "Enter workgroup: [%s] ", workgroup); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */ + temp[strlen(temp) - 1] = 0x00; + + if (temp[0]) strncpy(workgroup, temp, wgmaxlen - 1); + + fprintf(stdout, "Enter username: [%s] ", username); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */ + temp[strlen(temp) - 1] = 0x00; + + if (temp[0]) strncpy(username, temp, unmaxlen - 1); + + fprintf(stdout, "Enter password: [%s] ", password); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */ + temp[strlen(temp) - 1] = 0x00; + + if (temp[0]) strncpy(password, temp, pwmaxlen - 1); + +} + +int global_id = 0; + +void print_list_fn(struct print_job_info *pji) +{ + + fprintf(stdout, "Print job: ID: %u, Prio: %u, Size: %u, User: %s, Name: %s\n", + pji->id, pji->priority, pji->size, pji->user, pji->name); + + global_id = pji->id; + +} + +int main(int argc, char *argv[]) +{ + int err, fd, dh1, dh2, dh3, dsize, dirc; + const char *file = "smb://samba/public/testfile.txt"; + const char *file2 = "smb://samba/public/testfile2.txt"; + char buff[256]; + char dirbuf[512]; + char *dirp; + struct stat st1, st2; + + err = smbc_init(auth_fn, 10); /* Initialize things */ + + if (err < 0) { + + fprintf(stderr, "Initializing the smbclient library ...: %s\n", strerror(errno)); + + } + + if (argc > 1) { + + /* Try to list the print jobs ... */ + + if (smbc_list_print_jobs("smb://samba/pclp", print_list_fn) < 0) { + + fprintf(stderr, "Could not list print jobs: %s, %d\n", strerror(errno), errno); + exit(1); + + } + + /* Try to delete the last job listed */ + + if (global_id > 0) { + + fprintf(stdout, "Trying to delete print job %u\n", global_id); + + if (smbc_unlink_print_job("smb://samba/pclp", global_id) < 0) { + + fprintf(stderr, "Failed to unlink job id %u, %s, %u\n", global_id, + strerror(errno), errno); + + exit(1); + + } + + } + + /* Try to print a file ... */ + + if (smbc_print_file("smb://samba/public/testfile2.txt", "smb://samba/pclp") < 0) { + + fprintf(stderr, "Failed to print job: %s %u\n", strerror(errno), errno); + exit(1); + + } + + /* Try to delete argv[1] as a file ... */ + + if (smbc_unlink(argv[1]) < 0) { + + fprintf(stderr, "Could not unlink: %s, %s, %d\n", + argv[1], strerror(errno), errno); + + exit(0); + + } + + if ((dh1 = smbc_opendir("smb://"))<1) { + + fprintf(stderr, "Could not open directory: smb://: %s\n", + strerror(errno)); + + exit(1); + + } + + if ((dh2 = smbc_opendir("smb://sambanet")) < 0) { + + fprintf(stderr, "Could not open directory: smb://sambanet: %s\n", + strerror(errno)); + + exit(1); + + } + + if ((dh3 = smbc_opendir("smb://samba")) < 0) { + + fprintf(stderr, "Could not open directory: smb://samba: %s\n", + strerror(errno)); + + exit(1); + + } + + fprintf(stdout, "Directory handles: %u, %u, %u\n", dh1, dh2, dh3); + + /* Now, list those directories, but in funny ways ... */ + + dirp = (char *)dirbuf; + + if ((dirc = smbc_getdents(dh1, (struct smbc_dirent *)dirp, + sizeof(dirbuf))) < 0) { + + fprintf(stderr, "Problems getting directory entries: %s\n", + strerror(errno)); + + exit(1); + + } + + /* Now, process the list of names ... */ + + fprintf(stdout, "Directory listing, size = %u\n", dirc); + + while (dirc > 0) { + + dsize = ((struct smbc_dirent *)dirp)->dirlen; + fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n", + ((struct smbc_dirent *)dirp)->smbc_type, + ((struct smbc_dirent *)dirp)->name, + ((struct smbc_dirent *)dirp)->comment); + + dirp += dsize; + (char *)dirc -= dsize; + + } + + dirp = (char *)dirbuf; + + if ((dirc = smbc_getdents(dh2, (struct smbc_dirent *)dirp, + sizeof(dirbuf))) < 0) { + + fprintf(stderr, "Problems getting directory entries: %s\n", + strerror(errno)); + + exit(1); + + } + + /* Now, process the list of names ... */ + + fprintf(stdout, "\nDirectory listing, size = %u\n", dirc); + + while (dirc > 0) { + + dsize = ((struct smbc_dirent *)dirp)->dirlen; + fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n", + ((struct smbc_dirent *)dirp)->smbc_type, + ((struct smbc_dirent *)dirp)->name, + ((struct smbc_dirent *)dirp)->comment); + + dirp += dsize; + (char *)dirc -= dsize; + + } + + dirp = (char *)dirbuf; + + if ((dirc = smbc_getdents(dh3, (struct smbc_dirent *)dirp, + sizeof(dirbuf))) < 0) { + + fprintf(stderr, "Problems getting directory entries: %s\n", + strerror(errno)); + + exit(1); + + } + + /* Now, process the list of names ... */ + + fprintf(stdout, "Directory listing, size = %u\n", dirc); + + while (dirc > 0) { + + dsize = ((struct smbc_dirent *)dirp)->dirlen; + fprintf(stdout, "\nDir Ent, Type: %u, Name: %s, Comment: %s\n", + ((struct smbc_dirent *)dirp)->smbc_type, + ((struct smbc_dirent *)dirp)->name, + ((struct smbc_dirent *)dirp)->comment); + + (char *)dirp += dsize; + (char *)dirc -= dsize; + + } + + exit(1); + + } + + /* 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 | O_TRUNC, 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, + (int)st2.st_size, st2.st_mode); + fprintf(stdout, " time: %s\n", ctime(&st2.st_atime)); + fprintf(stdout, "Earlier stat: %s, Size = %d, mode = %04X\n", file, + (int)st1.st_size, st1.st_mode); + fprintf(stdout, " time: %s\n", ctime(&st1.st_atime)); + + /* Now, make a directory ... */ + + fprintf(stdout, "Making directory smb://samba/public/make-dir\n"); + + if (smbc_mkdir("smb://samba/public/make-dir", 0666) < 0) { + + fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n", + strerror(errno)); + + if (errno == EEXIST) { /* Try to delete the directory */ + + fprintf(stdout, "Trying to delete directory: smb://samba/public/make-dir\n"); + + if (smbc_rmdir("smb://samba/public/make-dir") < 0) { /* Error */ + + fprintf(stderr, "Error removing directory: smb://samba/public/make-dir: %s\n", strerror(errno)); + + exit(0); + + } + + fprintf(stdout, "Making directory: smb://samba/public/make-dir\n"); + + if (smbc_mkdir("smb://samba/public/make-dir", 666) < 0) { + + fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n", + strerror(errno)); + + fprintf(stderr, "I give up!\n"); + + exit(1); + + } + + } + + exit(0); + + } + + fprintf(stdout, "Made dir: make-dir\n"); + return 0; +} diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c new file mode 100644 index 0000000000..da60236e60 --- /dev/null +++ b/examples/libsmbclient/tree.c @@ -0,0 +1,812 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB client GTK+ tree-based application + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Richard Sharpe 2001 + Copyright (C) John Terpstra 2001 + + 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. +*/ + +/* example-gtk+ application, ripped off from the gtk+ tree.c sample */ + +#include +#include +#include +#include "libsmbclient.h" + +static GtkWidget *clist; + +struct tree_data { + + guint32 type; /* Type of tree item, an SMBC_TYPE */ + char name[256]; /* May need to change this later */ + +}; + +void error_message(gchar *message) { + + GtkWidget *dialog, *label, *okay_button; + + /* Create the widgets */ + + dialog = gtk_dialog_new(); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + label = gtk_label_new (message); + okay_button = gtk_button_new_with_label("Okay"); + + /* Ensure that the dialog box is destroyed when the user clicks ok. */ + + gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked", + GTK_SIGNAL_FUNC (gtk_widget_destroy), dialog); + gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), + okay_button); + + /* Add the label, and show everything we've added to the dialog. */ + + gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), + label); + gtk_widget_show_all (dialog); +} + +/* + * We are given a widget, and we want to retrieve its URL so we + * can do a directory listing. + * + * We walk back up the tree, picking up pieces until we hit a server or + * workgroup type and return a path from there + */ + +static char path_string[1024]; + +char *get_path(GtkWidget *item) +{ + GtkWidget *p = item; + struct tree_data *pd; + char *comps[1024]; /* We keep pointers to the components here */ + int i = 0, j, level,type; + + /* Walk back up the tree, getting the private data */ + + level = GTK_TREE(item->parent)->level; + + /* Pick up this item's component info */ + + pd = (struct tree_data *)gtk_object_get_user_data(GTK_OBJECT(item)); + + comps[i++] = pd->name; + type = pd->type; + + while (level > 0 && type != SMBC_SERVER && type != SMBC_WORKGROUP) { + + /* Find the parent and extract the data etc ... */ + + p = GTK_WIDGET(p->parent); + p = GTK_WIDGET(GTK_TREE(p)->tree_owner); + + pd = (struct tree_data *)gtk_object_get_user_data(GTK_OBJECT(p)); + + level = GTK_TREE(item->parent)->level; + + comps[i++] = pd->name; + type = pd->type; + + } + + /* + * Got a list of comps now, should check that we did not hit a workgroup + * when we got other things as well ... Later + * + * Now, build the path + */ + + snprintf(path_string, sizeof(path_string), "smb:/"); + + for (j = i - 1; j >= 0; j--) { + + strncat(path_string, "/", sizeof(path_string) - strlen(path_string)); + strncat(path_string, comps[j], sizeof(path_string) - strlen(path_string)); + + } + + fprintf(stdout, "Path string = %s\n", path_string); + + return path_string; + +} + +struct tree_data *make_tree_data(guint32 type, const char *name) +{ + struct tree_data *p = (struct tree_data *)malloc(sizeof(struct tree_data)); + + if (p) { + + p->type = type; + strncpy(p->name, name, sizeof(p->name)); + + } + + return p; + +} + +/* Note that this is called every time the user clicks on an item, + whether it is already selected or not. */ +static void cb_select_child (GtkWidget *root_tree, GtkWidget *child, + GtkWidget *subtree) +{ + gint dh, err, dirlen; + char dirbuf[512]; + struct smbc_dirent *dirp; + struct stat st1; + char path[1024], path1[1024]; + + g_print ("select_child called for root tree %p, subtree %p, child %p\n", + root_tree, subtree, child); + + /* Now, figure out what it is, and display it in the clist ... */ + + gtk_clist_clear(GTK_CLIST(clist)); /* Clear the CLIST */ + + /* Now, get the private data for the subtree */ + + strncpy(path, get_path(child), 1024); + + if ((dh = smbc_opendir(path)) < 0) { /* Handle error */ + + g_print("cb_select_child: Could not open dir %s, %s\n", path, + strerror(errno)); + + gtk_main_quit(); + + return; + + } + + while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf, + sizeof(dirbuf))) != 0) { + + if (err < 0) { + + g_print("cb_select_child: Could not read dir %s, %s\n", path, + strerror(errno)); + + gtk_main_quit(); + + return; + + } + + dirp = (struct smbc_dirent *)dirbuf; + + while (err > 0) { + gchar col1[128], col2[128], col3[128], col4[128]; + gchar *rowdata[4] = {col1, col2, col3, col4}; + + dirlen = dirp->dirlen; + + /* Format each of the items ... */ + + strncpy(col1, dirp->name, 128); + + col2[0] = col3[0] = col4[0] = (char)0; + + switch (dirp->smbc_type) { + + case SMBC_WORKGROUP: + + break; + + case SMBC_SERVER: + + strncpy(col2, (dirp->comment?dirp->comment:""), 128); + + break; + + case SMBC_FILE_SHARE: + + strncpy(col2, (dirp->comment?dirp->comment:""), 128); + + break; + + case SMBC_PRINTER_SHARE: + + strncpy(col2, (dirp->comment?dirp->comment:""), 128); + break; + + case SMBC_COMMS_SHARE: + + break; + + case SMBC_IPC_SHARE: + + break; + + case SMBC_DIR: + case SMBC_FILE: + + /* Get stats on the file/dir and see what we have */ + + if ((strcmp(dirp->name, ".") != 0) && + (strcmp(dirp->name, "..") != 0)) { + + strncpy(path1, path, sizeof(path1)); + strncat(path1, "/", sizeof(path) - strlen(path)); + strncat(path1, dirp->name, sizeof(path) - strlen(path)); + + if (smbc_stat(path1, &st1) < 0) { + + if (errno != EBUSY) { + + g_print("cb_select_child: Could not stat file %s, %s\n", path1, + strerror(errno)); + + gtk_main_quit(); + + return; + + } + else { + + strncpy(col2, "Device or resource busy", sizeof(col2)); + + } + } + else { + /* Now format each of the relevant things ... */ + + snprintf(col2, sizeof(col2), "%c%c%c%c%c%c%c%c%c(%0X)", + (st1.st_mode&S_IRUSR?'r':'-'), + (st1.st_mode&S_IWUSR?'w':'-'), + (st1.st_mode&S_IXUSR?'x':'-'), + (st1.st_mode&S_IRGRP?'r':'-'), + (st1.st_mode&S_IWGRP?'w':'-'), + (st1.st_mode&S_IXGRP?'x':'-'), + (st1.st_mode&S_IROTH?'r':'-'), + (st1.st_mode&S_IWOTH?'w':'-'), + (st1.st_mode&S_IXOTH?'x':'-'), + st1.st_mode); + snprintf(col3, sizeof(col3), "%u", st1.st_size); + snprintf(col4, sizeof(col4), "%s", ctime(&st1.st_mtime)); + } + } + + break; + + default: + + break; + } + + gtk_clist_append(GTK_CLIST(clist), rowdata); + + (char *)dirp += dirlen; + err -= dirlen; + + } + + } + +} + +/* Note that this is never called */ +static void cb_unselect_child( GtkWidget *root_tree, + GtkWidget *child, + GtkWidget *subtree ) +{ + g_print ("unselect_child called for root tree %p, subtree %p, child %p\n", + root_tree, subtree, child); +} + +/* for all the GtkItem:: and GtkTreeItem:: signals */ +static void cb_itemsignal( GtkWidget *item, + gchar *signame ) +{ + GtkWidget *real_tree, *aitem, *subtree; + gchar *name; + GtkLabel *label; + gint dh, err, dirlen, level; + char dirbuf[512]; + struct smbc_dirent *dirp; + + label = GTK_LABEL (GTK_BIN (item)->child); + /* Get the text of the label */ + gtk_label_get (label, &name); + + level = GTK_TREE(item->parent)->level; + + /* Get the level of the tree which the item is in */ + g_print ("%s called for item %s->%p, level %d\n", signame, name, + item, GTK_TREE (item->parent)->level); + + real_tree = GTK_TREE_ITEM_SUBTREE(item); /* Get the subtree */ + + if (strncmp(signame, "expand", 6) == 0) { /* Expand called */ + char server[128]; + + if ((dh = smbc_opendir(get_path(item))) < 0) { /* Handle error */ + gchar errmsg[256]; + + g_print("cb_itemsignal: Could not open dir %s, %s\n", get_path(item), + strerror(errno)); + + snprintf(errmsg, sizeof(errmsg), "cb_itemsignal: Could not open dir %s, %s\n", get_path(item), strerror(errno)); + + error_message(errmsg); + + /* gtk_main_quit();*/ + + return; + + } + + while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf, + sizeof(dirbuf))) != 0) { + + if (err < 0) { /* An error, report it */ + gchar errmsg[256]; + + g_print("cb_itemsignal: Could not read dir smbc://, %s\n", + strerror(errno)); + + snprintf(errmsg, sizeof(errmsg), "cb_itemsignal: Could not read dir smbc://, %s\n", strerror(errno)); + + error_message(errmsg); + + /* gtk_main_quit();*/ + + return; + + } + + dirp = (struct smbc_dirent *)dirbuf; + + while (err > 0) { + struct tree_data *my_data; + + dirlen = dirp->dirlen; + + my_data = make_tree_data(dirp->smbc_type, dirp->name); + + if (!my_data) { + + g_print("Could not allocate space for tree_data: %s\n", + dirp->name); + + gtk_main_quit(); + return; + + } + + aitem = gtk_tree_item_new_with_label(dirp->name); + + /* Connect all GtkItem:: and GtkTreeItem:: signals */ + gtk_signal_connect (GTK_OBJECT(aitem), "select", + GTK_SIGNAL_FUNC(cb_itemsignal), "select"); + gtk_signal_connect (GTK_OBJECT(aitem), "deselect", + GTK_SIGNAL_FUNC(cb_itemsignal), "deselect"); + gtk_signal_connect (GTK_OBJECT(aitem), "toggle", + GTK_SIGNAL_FUNC(cb_itemsignal), "toggle"); + gtk_signal_connect (GTK_OBJECT(aitem), "expand", + GTK_SIGNAL_FUNC(cb_itemsignal), "expand"); + gtk_signal_connect (GTK_OBJECT(aitem), "collapse", + GTK_SIGNAL_FUNC(cb_itemsignal), "collapse"); + /* Add it to the parent tree */ + gtk_tree_append (GTK_TREE(real_tree), aitem); + + gtk_widget_show (aitem); + + gtk_object_set_user_data(GTK_OBJECT(aitem), (gpointer)my_data); + + fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen); + + if (dirp->smbc_type != SMBC_FILE && + dirp->smbc_type != SMBC_IPC_SHARE && + (strcmp(dirp->name, ".") != 0) && + (strcmp(dirp->name, "..") !=0)){ + + subtree = gtk_tree_new(); + gtk_tree_item_set_subtree(GTK_TREE_ITEM(aitem), subtree); + + gtk_signal_connect(GTK_OBJECT(subtree), "select_child", + GTK_SIGNAL_FUNC(cb_select_child), real_tree); + gtk_signal_connect(GTK_OBJECT(subtree), "unselect_child", + GTK_SIGNAL_FUNC(cb_unselect_child), real_tree); + + } + + (char *)dirp += dirlen; + err -= dirlen; + + } + + } + + smbc_closedir(dh); + + } + else if (strncmp(signame, "collapse", 8) == 0) { + GtkWidget *subtree = gtk_tree_new(); + + gtk_tree_remove_items(GTK_TREE(real_tree), GTK_TREE(real_tree)->children); + + gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree); + + gtk_signal_connect (GTK_OBJECT(subtree), "select_child", + GTK_SIGNAL_FUNC(cb_select_child), real_tree); + gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child", + GTK_SIGNAL_FUNC(cb_unselect_child), real_tree); + + } + +} + +static void cb_selection_changed( GtkWidget *tree ) +{ + GList *i; + + g_print ("selection_change called for tree %p\n", tree); + g_print ("selected objects are:\n"); + + i = GTK_TREE_SELECTION(tree); + while (i){ + gchar *name; + GtkLabel *label; + GtkWidget *item; + + /* Get a GtkWidget pointer from the list node */ + item = GTK_WIDGET (i->data); + label = GTK_LABEL (GTK_BIN (item)->child); + gtk_label_get (label, &name); + g_print ("\t%s on level %d\n", name, GTK_TREE + (item->parent)->level); + i = i->next; + } +} + +/* + * Expand or collapse the whole network ... + */ +static void cb_wholenet(GtkWidget *item, gchar *signame) +{ + GtkWidget *real_tree, *aitem, *subtree; + gchar *name; + GtkLabel *label; + gint dh, err, dirlen; + char dirbuf[512]; + struct smbc_dirent *dirp; + + label = GTK_LABEL (GTK_BIN (item)->child); + gtk_label_get (label, &name); + g_print ("%s called for item %s->%p, level %d\n", signame, name, + item, GTK_TREE (item->parent)->level); + + real_tree = GTK_TREE_ITEM_SUBTREE(item); /* Get the subtree */ + + if (strncmp(signame, "expand", 6) == 0) { /* Expand called */ + + if ((dh = smbc_opendir("smb://")) < 0) { /* Handle error */ + + g_print("cb_wholenet: Could not open dir smbc://, %s\n", + strerror(errno)); + + gtk_main_quit(); + + return; + + } + + while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf, + sizeof(dirbuf))) != 0) { + + if (err < 0) { /* An error, report it */ + + g_print("cb_wholenet: Could not read dir smbc://, %s\n", + strerror(errno)); + + gtk_main_quit(); + + return; + + } + + dirp = (struct smbc_dirent *)dirbuf; + + while (err > 0) { + struct tree_data *my_data; + + dirlen = dirp->dirlen; + + my_data = make_tree_data(dirp->smbc_type, dirp->name); + + aitem = gtk_tree_item_new_with_label(dirp->name); + + /* Connect all GtkItem:: and GtkTreeItem:: signals */ + gtk_signal_connect (GTK_OBJECT(aitem), "select", + GTK_SIGNAL_FUNC(cb_itemsignal), "select"); + gtk_signal_connect (GTK_OBJECT(aitem), "deselect", + GTK_SIGNAL_FUNC(cb_itemsignal), "deselect"); + gtk_signal_connect (GTK_OBJECT(aitem), "toggle", + GTK_SIGNAL_FUNC(cb_itemsignal), "toggle"); + gtk_signal_connect (GTK_OBJECT(aitem), "expand", + GTK_SIGNAL_FUNC(cb_itemsignal), "expand"); + gtk_signal_connect (GTK_OBJECT(aitem), "collapse", + GTK_SIGNAL_FUNC(cb_itemsignal), "collapse"); + + gtk_tree_append (GTK_TREE(real_tree), aitem); + /* Show it - this can be done at any time */ + gtk_widget_show (aitem); + + gtk_object_set_user_data(GTK_OBJECT(aitem), (gpointer)my_data); + + fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen); + + subtree = gtk_tree_new(); + + gtk_tree_item_set_subtree(GTK_TREE_ITEM(aitem), subtree); + + gtk_signal_connect(GTK_OBJECT(subtree), "select_child", + GTK_SIGNAL_FUNC(cb_select_child), real_tree); + gtk_signal_connect(GTK_OBJECT(subtree), "unselect_child", + GTK_SIGNAL_FUNC(cb_unselect_child), real_tree); + + (char *)dirp += dirlen; + err -= dirlen; + + } + + } + + smbc_closedir(dh); + + } + else { /* Must be collapse ... FIXME ... */ + GtkWidget *subtree = gtk_tree_new(); + + gtk_tree_remove_items(GTK_TREE(real_tree), GTK_TREE(real_tree)->children); + + gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree); + + gtk_signal_connect (GTK_OBJECT(subtree), "select_child", + GTK_SIGNAL_FUNC(cb_select_child), real_tree); + gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child", + GTK_SIGNAL_FUNC(cb_unselect_child), real_tree); + + + } + +} + +/* Should put up a dialog box to ask the user for username and password */ + +static void +auth_fn(const char *server, const char *share, + char *workgroup, int wgmaxlen, char *username, int unmaxlen, + char *password, int pwmaxlen) +{ + + strncpy(username, "test", unmaxlen); + strncpy(password, "test", pwmaxlen); + +} + +static char *col_titles[] = { + "Name", "Attributes", "Size", "Modification Date", +}; + +int main( int argc, + char *argv[] ) +{ + GtkWidget *window, *scrolled_win, *scrolled_win2, *tree; + GtkWidget *subtree, *item, *main_hbox, *r_pane, *l_pane; + gint err, dh; + gint i; + char dirbuf[512]; + struct smbc_dirent *dirp; + + gtk_init (&argc, &argv); + + /* Init the smbclient library */ + + err = smbc_init(auth_fn, 10); + + /* Print an error response ... */ + + if (err < 0) { + + fprintf(stderr, "smbc_init returned %s (%i)\nDo you have a ~/.smb/smb.conf file?\n", strerror(errno), errno); + exit(1); + + } + + /* a generic toplevel window */ + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_widget_set_name(window, "main browser window"); + gtk_signal_connect (GTK_OBJECT(window), "delete_event", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + gtk_window_set_title(GTK_WINDOW(window), "The Linux Windows Network Browser"); + gtk_widget_set_usize(GTK_WIDGET(window), 750, -1); + gtk_container_set_border_width (GTK_CONTAINER(window), 5); + + gtk_widget_show (window); + + /* A container for the two panes ... */ + + main_hbox = gtk_hbox_new(FALSE, 1); + gtk_container_border_width(GTK_CONTAINER(main_hbox), 1); + gtk_container_add(GTK_CONTAINER(window), main_hbox); + + gtk_widget_show(main_hbox); + + l_pane = gtk_hpaned_new(); + gtk_paned_gutter_size(GTK_PANED(l_pane), (GTK_PANED(l_pane))->handle_size); + r_pane = gtk_hpaned_new(); + gtk_paned_gutter_size(GTK_PANED(r_pane), (GTK_PANED(r_pane))->handle_size); + gtk_container_add(GTK_CONTAINER(main_hbox), l_pane); + gtk_widget_show(l_pane); + + /* A generic scrolled window */ + scrolled_win = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_widget_set_usize (scrolled_win, 150, 200); + gtk_container_add (GTK_CONTAINER(l_pane), scrolled_win); + gtk_widget_show (scrolled_win); + + /* Another generic scrolled window */ + scrolled_win2 = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win2), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_widget_set_usize (scrolled_win2, 150, 200); + gtk_paned_add2 (GTK_PANED(l_pane), scrolled_win2); + gtk_widget_show (scrolled_win2); + + /* Create the root tree */ + tree = gtk_tree_new(); + g_print ("root tree is %p\n", tree); + /* connect all GtkTree:: signals */ + gtk_signal_connect (GTK_OBJECT(tree), "select_child", + GTK_SIGNAL_FUNC(cb_select_child), tree); + gtk_signal_connect (GTK_OBJECT(tree), "unselect_child", + GTK_SIGNAL_FUNC(cb_unselect_child), tree); + gtk_signal_connect (GTK_OBJECT(tree), "selection_changed", + GTK_SIGNAL_FUNC(cb_selection_changed), tree); + /* Add it to the scrolled window */ + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrolled_win), + tree); + /* Set the selection mode */ + gtk_tree_set_selection_mode (GTK_TREE(tree), + GTK_SELECTION_MULTIPLE); + /* Show it */ + gtk_widget_show (tree); + + /* Now, create a clist and attach it to the second pane */ + + clist = gtk_clist_new_with_titles(4, col_titles); + + gtk_container_add (GTK_CONTAINER(scrolled_win2), clist); + + gtk_widget_show(clist); + + /* Now, build the top level display ... */ + + if ((dh = smbc_opendir("smb:///")) < 0) { + + fprintf(stderr, "Could not list default workgroup: smb:///: %s\n", + strerror(errno)); + + exit(1); + + } + + /* Create a tree item for Whole Network */ + + item = gtk_tree_item_new_with_label ("Whole Network"); + /* Connect all GtkItem:: and GtkTreeItem:: signals */ + gtk_signal_connect (GTK_OBJECT(item), "select", + GTK_SIGNAL_FUNC(cb_itemsignal), "select"); + gtk_signal_connect (GTK_OBJECT(item), "deselect", + GTK_SIGNAL_FUNC(cb_itemsignal), "deselect"); + gtk_signal_connect (GTK_OBJECT(item), "toggle", + GTK_SIGNAL_FUNC(cb_itemsignal), "toggle"); + gtk_signal_connect (GTK_OBJECT(item), "expand", + GTK_SIGNAL_FUNC(cb_wholenet), "expand"); + gtk_signal_connect (GTK_OBJECT(item), "collapse", + GTK_SIGNAL_FUNC(cb_wholenet), "collapse"); + /* Add it to the parent tree */ + gtk_tree_append (GTK_TREE(tree), item); + /* Show it - this can be done at any time */ + gtk_widget_show (item); + + subtree = gtk_tree_new(); /* A subtree for Whole Network */ + + gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree); + + gtk_signal_connect (GTK_OBJECT(subtree), "select_child", + GTK_SIGNAL_FUNC(cb_select_child), tree); + gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child", + GTK_SIGNAL_FUNC(cb_unselect_child), tree); + + /* Now, get the items in smb:/// and add them to the tree */ + + dirp = (struct smbc_dirent *)dirbuf; + + while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf, + sizeof(dirbuf))) != 0) { + + if (err < 0) { /* Handle the error */ + + fprintf(stderr, "Could not read directory for smbc:///: %s\n", + strerror(errno)); + + exit(1); + + } + + fprintf(stdout, "Dir len: %u\n", err); + + while (err > 0) { /* Extract each entry and make a sub-tree */ + struct tree_data *my_data; + int dirlen = dirp->dirlen; + + my_data = make_tree_data(dirp->smbc_type, dirp->name); + + item = gtk_tree_item_new_with_label(dirp->name); + /* Connect all GtkItem:: and GtkTreeItem:: signals */ + gtk_signal_connect (GTK_OBJECT(item), "select", + GTK_SIGNAL_FUNC(cb_itemsignal), "select"); + gtk_signal_connect (GTK_OBJECT(item), "deselect", + GTK_SIGNAL_FUNC(cb_itemsignal), "deselect"); + gtk_signal_connect (GTK_OBJECT(item), "toggle", + GTK_SIGNAL_FUNC(cb_itemsignal), "toggle"); + gtk_signal_connect (GTK_OBJECT(item), "expand", + GTK_SIGNAL_FUNC(cb_itemsignal), "expand"); + gtk_signal_connect (GTK_OBJECT(item), "collapse", + GTK_SIGNAL_FUNC(cb_itemsignal), "collapse"); + /* Add it to the parent tree */ + gtk_tree_append (GTK_TREE(tree), item); + /* Show it - this can be done at any time */ + gtk_widget_show (item); + + gtk_object_set_user_data(GTK_OBJECT(item), (gpointer)my_data); + + fprintf(stdout, "Added: %s, len: %u\n", dirp->name, dirlen); + + subtree = gtk_tree_new(); + + gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), subtree); + + gtk_signal_connect (GTK_OBJECT(subtree), "select_child", + GTK_SIGNAL_FUNC(cb_select_child), tree); + gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child", + GTK_SIGNAL_FUNC(cb_unselect_child), tree); + + (char *)dirp += dirlen; + err -= dirlen; + + } + + } + + smbc_closedir(dh); /* FIXME, check for error :-) */ + + /* Show the window and loop endlessly */ + gtk_main(); + return 0; +} +/* example-end */ -- cgit From 89cf21971736c63d0dfb80563f85afd33af2237a Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sat, 30 Jun 2001 04:01:51 +0000 Subject: Add a static linking target to the examples Makefile so I can test out static linking ... (This used to be commit 9627bace72eb3be322f8895b055a31768e551136) --- examples/libsmbclient/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 20bc99cac0..3b56def3fd 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -12,9 +12,13 @@ testsmbc: testsmbc.o @echo Linking testsmbc @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient +testsmbc-static: testsmbc.o + @echo Linking testsmbc + @$(CC) $(CFLAGS) -static $(LDFLAGS) -o $@ $< -lsmbclient -ldl -lnsl + tree: tree.o @echo Linking tree @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient $< clean: - @rm -f *.o *~ \ No newline at end of file + @rm -f *.o *~ -- cgit From 9178d7591b64c1e3ac92b19506811c5944476071 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sat, 30 Jun 2001 11:08:06 +0000 Subject: Make sure we compile with gcc by default. (This used to be commit 93c45024cdbbf51322106e2a5961db8c09618833) --- examples/libsmbclient/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 3b56def3fd..8c1def8a16 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -1,4 +1,5 @@ # +CC = gcc SAMBA_INCL = ../../source/include -- cgit From 0bd559ad1d83ca471055ee24ae10d26b6d1c8689 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 4 Nov 2002 17:10:08 +0000 Subject: testsmbc should only be in examples (This used to be commit 7aad086c9a20c4c700dfce3f81d89ab982702198) --- examples/libsmbclient/testsmbc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c index 7aae9d8561..ec98774dcf 100644 --- a/examples/libsmbclient/testsmbc.c +++ b/examples/libsmbclient/testsmbc.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 2.0 + Unix SMB/CIFS implementation. SMB client library test program Copyright (C) Andrew Tridgell 1998 Copyright (C) Richard Sharpe 2000 -- cgit From b45c92f31ea0442d623ac2d92dcd97215c1ed481 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 15 Nov 2002 22:51:03 +0000 Subject: Fix some problems with tree.c reported by users. (This used to be commit b0772a1a0531896d5b343863434622d4d0ff437f) --- examples/libsmbclient/Makefile | 2 +- examples/libsmbclient/testsmbc.c | 126 +-------------------------------------- examples/libsmbclient/tree.c | 3 +- 3 files changed, 6 insertions(+), 125 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 8c1def8a16..5fe9977c0a 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -11,7 +11,7 @@ all: testsmbc tree testsmbc: testsmbc.o @echo Linking testsmbc - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient -L/usr/local/lib testsmbc-static: testsmbc.o @echo Linking testsmbc diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c index ec98774dcf..888a9c0d4f 100644 --- a/examples/libsmbclient/testsmbc.c +++ b/examples/libsmbclient/testsmbc.c @@ -94,74 +94,10 @@ int main(int argc, char *argv[]) if (argc > 1) { - /* Try to list the print jobs ... */ + if ((dh1 = smbc_opendir(argv[1]))<1) { - if (smbc_list_print_jobs("smb://samba/pclp", print_list_fn) < 0) { - - fprintf(stderr, "Could not list print jobs: %s, %d\n", strerror(errno), errno); - exit(1); - - } - - /* Try to delete the last job listed */ - - if (global_id > 0) { - - fprintf(stdout, "Trying to delete print job %u\n", global_id); - - if (smbc_unlink_print_job("smb://samba/pclp", global_id) < 0) { - - fprintf(stderr, "Failed to unlink job id %u, %s, %u\n", global_id, - strerror(errno), errno); - - exit(1); - - } - - } - - /* Try to print a file ... */ - - if (smbc_print_file("smb://samba/public/testfile2.txt", "smb://samba/pclp") < 0) { - - fprintf(stderr, "Failed to print job: %s %u\n", strerror(errno), errno); - exit(1); - - } - - /* Try to delete argv[1] as a file ... */ - - if (smbc_unlink(argv[1]) < 0) { - - fprintf(stderr, "Could not unlink: %s, %s, %d\n", - argv[1], strerror(errno), errno); - - exit(0); - - } - - if ((dh1 = smbc_opendir("smb://"))<1) { - - fprintf(stderr, "Could not open directory: smb://: %s\n", - strerror(errno)); - - exit(1); - - } - - if ((dh2 = smbc_opendir("smb://sambanet")) < 0) { - - fprintf(stderr, "Could not open directory: smb://sambanet: %s\n", - strerror(errno)); - - exit(1); - - } - - if ((dh3 = smbc_opendir("smb://samba")) < 0) { - - fprintf(stderr, "Could not open directory: smb://samba: %s\n", - strerror(errno)); + fprintf(stderr, "Could not open directory: %s: %s\n", + argv[1], strerror(errno)); exit(1); @@ -202,62 +138,6 @@ int main(int argc, char *argv[]) dirp = (char *)dirbuf; - if ((dirc = smbc_getdents(dh2, (struct smbc_dirent *)dirp, - sizeof(dirbuf))) < 0) { - - fprintf(stderr, "Problems getting directory entries: %s\n", - strerror(errno)); - - exit(1); - - } - - /* Now, process the list of names ... */ - - fprintf(stdout, "\nDirectory listing, size = %u\n", dirc); - - while (dirc > 0) { - - dsize = ((struct smbc_dirent *)dirp)->dirlen; - fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n", - ((struct smbc_dirent *)dirp)->smbc_type, - ((struct smbc_dirent *)dirp)->name, - ((struct smbc_dirent *)dirp)->comment); - - dirp += dsize; - (char *)dirc -= dsize; - - } - - dirp = (char *)dirbuf; - - if ((dirc = smbc_getdents(dh3, (struct smbc_dirent *)dirp, - sizeof(dirbuf))) < 0) { - - fprintf(stderr, "Problems getting directory entries: %s\n", - strerror(errno)); - - exit(1); - - } - - /* Now, process the list of names ... */ - - fprintf(stdout, "Directory listing, size = %u\n", dirc); - - while (dirc > 0) { - - dsize = ((struct smbc_dirent *)dirp)->dirlen; - fprintf(stdout, "\nDir Ent, Type: %u, Name: %s, Comment: %s\n", - ((struct smbc_dirent *)dirp)->smbc_type, - ((struct smbc_dirent *)dirp)->name, - ((struct smbc_dirent *)dirp)->comment); - - (char *)dirp += dsize; - (char *)dirc -= dsize; - - } - exit(1); } diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c index da60236e60..f357c0306d 100644 --- a/examples/libsmbclient/tree.c +++ b/examples/libsmbclient/tree.c @@ -51,7 +51,8 @@ void error_message(gchar *message) { /* Ensure that the dialog box is destroyed when the user clicks ok. */ gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked", - GTK_SIGNAL_FUNC (gtk_widget_destroy), dialog); + GTK_SIGNAL_FUNC (gtk_widget_destroy), + GTK_OBJECT(dialog)); gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), okay_button); -- cgit From 7b581a60d2cc16500c5f54af3217d261d68646b5 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 15 Nov 2002 22:55:15 +0000 Subject: One more small fix in tree.c (This used to be commit 0674d5a2b0f7ee621940c93b3b58960efd91a763) --- examples/libsmbclient/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c index f357c0306d..8dc9cc408b 100644 --- a/examples/libsmbclient/tree.c +++ b/examples/libsmbclient/tree.c @@ -745,8 +745,6 @@ int main( int argc, /* Now, get the items in smb:/// and add them to the tree */ - dirp = (struct smbc_dirent *)dirbuf; - while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf, sizeof(dirbuf))) != 0) { @@ -759,6 +757,8 @@ int main( int argc, } + dirp = (struct smbc_dirent *)dirbuf; + fprintf(stdout, "Dir len: %u\n", err); while (err > 0) { /* Extract each entry and make a sub-tree */ -- cgit From 3bff6c4f981eb97f14117f350be00ff1cdfa26a9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 22 Jan 2003 23:50:14 +0000 Subject: Sync with HEAD. (This used to be commit db3901827fe776041fa38900e80ab2fab94c28a6) --- examples/libsmbclient/testsmbc.c | 129 ++------------------------------------- examples/libsmbclient/tree.c | 7 ++- 2 files changed, 8 insertions(+), 128 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c index 7aae9d8561..888a9c0d4f 100644 --- a/examples/libsmbclient/testsmbc.c +++ b/examples/libsmbclient/testsmbc.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 2.0 + Unix SMB/CIFS implementation. SMB client library test program Copyright (C) Andrew Tridgell 1998 Copyright (C) Richard Sharpe 2000 @@ -95,74 +94,10 @@ int main(int argc, char *argv[]) if (argc > 1) { - /* Try to list the print jobs ... */ + if ((dh1 = smbc_opendir(argv[1]))<1) { - if (smbc_list_print_jobs("smb://samba/pclp", print_list_fn) < 0) { - - fprintf(stderr, "Could not list print jobs: %s, %d\n", strerror(errno), errno); - exit(1); - - } - - /* Try to delete the last job listed */ - - if (global_id > 0) { - - fprintf(stdout, "Trying to delete print job %u\n", global_id); - - if (smbc_unlink_print_job("smb://samba/pclp", global_id) < 0) { - - fprintf(stderr, "Failed to unlink job id %u, %s, %u\n", global_id, - strerror(errno), errno); - - exit(1); - - } - - } - - /* Try to print a file ... */ - - if (smbc_print_file("smb://samba/public/testfile2.txt", "smb://samba/pclp") < 0) { - - fprintf(stderr, "Failed to print job: %s %u\n", strerror(errno), errno); - exit(1); - - } - - /* Try to delete argv[1] as a file ... */ - - if (smbc_unlink(argv[1]) < 0) { - - fprintf(stderr, "Could not unlink: %s, %s, %d\n", - argv[1], strerror(errno), errno); - - exit(0); - - } - - if ((dh1 = smbc_opendir("smb://"))<1) { - - fprintf(stderr, "Could not open directory: smb://: %s\n", - strerror(errno)); - - exit(1); - - } - - if ((dh2 = smbc_opendir("smb://sambanet")) < 0) { - - fprintf(stderr, "Could not open directory: smb://sambanet: %s\n", - strerror(errno)); - - exit(1); - - } - - if ((dh3 = smbc_opendir("smb://samba")) < 0) { - - fprintf(stderr, "Could not open directory: smb://samba: %s\n", - strerror(errno)); + fprintf(stderr, "Could not open directory: %s: %s\n", + argv[1], strerror(errno)); exit(1); @@ -203,62 +138,6 @@ int main(int argc, char *argv[]) dirp = (char *)dirbuf; - if ((dirc = smbc_getdents(dh2, (struct smbc_dirent *)dirp, - sizeof(dirbuf))) < 0) { - - fprintf(stderr, "Problems getting directory entries: %s\n", - strerror(errno)); - - exit(1); - - } - - /* Now, process the list of names ... */ - - fprintf(stdout, "\nDirectory listing, size = %u\n", dirc); - - while (dirc > 0) { - - dsize = ((struct smbc_dirent *)dirp)->dirlen; - fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n", - ((struct smbc_dirent *)dirp)->smbc_type, - ((struct smbc_dirent *)dirp)->name, - ((struct smbc_dirent *)dirp)->comment); - - dirp += dsize; - (char *)dirc -= dsize; - - } - - dirp = (char *)dirbuf; - - if ((dirc = smbc_getdents(dh3, (struct smbc_dirent *)dirp, - sizeof(dirbuf))) < 0) { - - fprintf(stderr, "Problems getting directory entries: %s\n", - strerror(errno)); - - exit(1); - - } - - /* Now, process the list of names ... */ - - fprintf(stdout, "Directory listing, size = %u\n", dirc); - - while (dirc > 0) { - - dsize = ((struct smbc_dirent *)dirp)->dirlen; - fprintf(stdout, "\nDir Ent, Type: %u, Name: %s, Comment: %s\n", - ((struct smbc_dirent *)dirp)->smbc_type, - ((struct smbc_dirent *)dirp)->name, - ((struct smbc_dirent *)dirp)->comment); - - (char *)dirp += dsize; - (char *)dirc -= dsize; - - } - exit(1); } diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c index da60236e60..8dc9cc408b 100644 --- a/examples/libsmbclient/tree.c +++ b/examples/libsmbclient/tree.c @@ -51,7 +51,8 @@ void error_message(gchar *message) { /* Ensure that the dialog box is destroyed when the user clicks ok. */ gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked", - GTK_SIGNAL_FUNC (gtk_widget_destroy), dialog); + GTK_SIGNAL_FUNC (gtk_widget_destroy), + GTK_OBJECT(dialog)); gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), okay_button); @@ -744,8 +745,6 @@ int main( int argc, /* Now, get the items in smb:/// and add them to the tree */ - dirp = (struct smbc_dirent *)dirbuf; - while ((err = smbc_getdents(dh, (struct smbc_dirent *)dirbuf, sizeof(dirbuf))) != 0) { @@ -758,6 +757,8 @@ int main( int argc, } + dirp = (struct smbc_dirent *)dirbuf; + fprintf(stdout, "Dir len: %u\n", err); while (err > 0) { /* Extract each entry and make a sub-tree */ -- cgit From a30e39022795f00fa1b4144362260aea160f3d31 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 22 Jan 2003 23:51:39 +0000 Subject: Sync with HEAD. The -L/usr/local/lib bit looks a bit dodgy though. (This used to be commit 81bfd9a4d9c80b87b020b998e9722750339c422d) --- examples/libsmbclient/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 8c1def8a16..5fe9977c0a 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -11,7 +11,7 @@ all: testsmbc tree testsmbc: testsmbc.o @echo Linking testsmbc - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient -L/usr/local/lib testsmbc-static: testsmbc.o @echo Linking testsmbc -- cgit From 60cf0f28ce3ebb21511330a0b14a6b2a42b47be0 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 28 Mar 2003 21:12:11 +0000 Subject: Fix some uncleanness with testsmbc.c (This used to be commit 73ef6d35bbadc3ea549309119857effe3c1bc7ef) --- examples/libsmbclient/testsmbc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c index 888a9c0d4f..9af845a5ea 100644 --- a/examples/libsmbclient/testsmbc.c +++ b/examples/libsmbclient/testsmbc.c @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) } - fprintf(stdout, "Directory handles: %u, %u, %u\n", dh1, dh2, dh3); + fprintf(stdout, "Directory handles: %u\n", dh1); /* Now, list those directories, but in funny ways ... */ -- cgit From 4a090ba06a54f5da179ac02bb307cc03d08831bf Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 16 Jul 2003 05:34:56 +0000 Subject: trying to get HEAD building again. If you want the code prior to this merge, checkout HEAD_PRE_3_0_0_BETA_3_MERGE (This used to be commit adb98e7b7cd0f025b52c570e4034eebf4047b1ad) --- examples/libsmbclient/testsmbc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c index 9af845a5ea..888a9c0d4f 100644 --- a/examples/libsmbclient/testsmbc.c +++ b/examples/libsmbclient/testsmbc.c @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) } - fprintf(stdout, "Directory handles: %u\n", dh1); + fprintf(stdout, "Directory handles: %u, %u, %u\n", dh1, dh2, dh3); /* Now, list those directories, but in funny ways ... */ -- cgit From 966a448f93a8326aeed25bfc0cd9b98a36835dea Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 24 Oct 2003 20:24:05 +0000 Subject: Apply these patches as well ... not sure if they all build. They don't on FreeBSD 4.3. They might on Linux. (This used to be commit 1f115c95d635377a36c0a3a1f56b4b8def04fd7e) --- examples/libsmbclient/Makefile | 13 ++++++++++--- examples/libsmbclient/tree.c | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 5fe9977c0a..e7c82a3aee 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -2,16 +2,19 @@ CC = gcc SAMBA_INCL = ../../source/include +EXTLIB_INCL = -I/usr/include/gtk-1.2 \ + -I/usr/include/glib-1.2 \ + -I/usr/lib/glib/include -CFLAGS = -I$(SAMBA_INCL) +CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) LDFLAGS = -L/usr/lib -all: testsmbc tree +all: testsmbc tree testacl testsmbc: testsmbc.o @echo Linking testsmbc - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient -L/usr/local/lib + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient -L/usr/local/lib testsmbc-static: testsmbc.o @echo Linking testsmbc @@ -21,5 +24,9 @@ tree: tree.o @echo Linking tree @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient $< +testacl: testacl.o + @echo Linking testacl + @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient -lpopt $< + clean: @rm -f *.o *~ diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c index 8dc9cc408b..f50b3670cf 100644 --- a/examples/libsmbclient/tree.c +++ b/examples/libsmbclient/tree.c @@ -706,9 +706,9 @@ int main( int argc, /* Now, build the top level display ... */ - if ((dh = smbc_opendir("smb:///")) < 0) { + if ((dh = smbc_opendir("smb://")) < 0) { - fprintf(stderr, "Could not list default workgroup: smb:///: %s\n", + fprintf(stderr, "Could not list workgroups: smb://: %s\n", strerror(errno)); exit(1); -- cgit From 018a3cc5080efd3c26ad8c04036ed367969f700d Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Wed, 5 Nov 2003 16:58:25 +0000 Subject: Apply the changes that Derrell Lipman supplied ... (This used to be commit 600e056a33bd658a8e0eb41af9c83d32b9e2e082) --- examples/libsmbclient/tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c index 8dc9cc408b..f50b3670cf 100644 --- a/examples/libsmbclient/tree.c +++ b/examples/libsmbclient/tree.c @@ -706,9 +706,9 @@ int main( int argc, /* Now, build the top level display ... */ - if ((dh = smbc_opendir("smb:///")) < 0) { + if ((dh = smbc_opendir("smb://")) < 0) { - fprintf(stderr, "Could not list default workgroup: smb:///: %s\n", + fprintf(stderr, "Could not list workgroups: smb://: %s\n", strerror(errno)); exit(1); -- cgit From 19aff105aad2d4b2689e2a0e955c77a93e12857f Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Wed, 12 Nov 2003 21:46:39 +0000 Subject: Add testacl.c ... from Derrell Lipman. (This used to be commit af42af75a45d6e6538009694704e11eb83c88457) --- examples/libsmbclient/testacl.c | 280 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100644 examples/libsmbclient/testacl.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c new file mode 100644 index 0000000000..47668f7c9c --- /dev/null +++ b/examples/libsmbclient/testacl.c @@ -0,0 +1,280 @@ +#include +#include +#include +#include +#include "libsmbclient.h" + +enum acl_mode +{ + SMB_ACL_GET, + SMB_ACL_SET, + SMB_ACL_DELETE, + SMB_ACL_MODIFY, + SMB_ACL_ADD, + SMB_ACL_CHOWN, + SMB_ACL_CHGRP +}; + +static void +get_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) + +{ + char temp[128]; + + fprintf(stdout, "Workgroup: [%s] ", pWorkgroup); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); + } + + fprintf(stdout, "Username: [%s] ", pUsername); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pUsername, temp, maxLenUsername - 1); + } + + fprintf(stdout, "Password: "); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pPassword, temp, maxLenPassword - 1); + } +} + + +int main(int argc, const char *argv[]) +{ + int opt; + int flags; + int debug = 0; + int numeric = 0; + enum acl_mode mode = SMB_ACL_GET; + static char *the_acl = NULL; + int ret; + char *p; + char *debugstr; + char path[1024]; + char value[1024]; + poptContext pc; + struct poptOption long_options[] = + { + POPT_AUTOHELP + { + "numeric", 'n', POPT_ARG_NONE, &numeric, + 1, "Don't resolve sids or masks to names" + }, + { + "debug", 'd', POPT_ARG_INT, &debug, + 0, "Set debug level (0-100)" + }, + { + "delete", 'D', POPT_ARG_STRING, NULL, + 'D', "Delete an acl", "ACL" + }, + { + "modify", 'M', POPT_ARG_STRING, NULL, + 'M', "Modify an acl", "ACL" + }, + { + "add", 'a', POPT_ARG_STRING, NULL, + 'a', "Add an acl", "ACL" + }, + { + "set", 'S', POPT_ARG_STRING, NULL, + 'S', "Set acls", "ACLS" + }, + { + "chown", 'C', POPT_ARG_STRING, NULL, + 'C', "Change ownership of a file", "USERNAME" + }, + { + "chgrp", 'G', POPT_ARG_STRING, NULL, + 'G', "Change group ownership of a file", "GROUPNAME" + }, + { + "get", 'g', POPT_ARG_STRING, NULL, + 'g', "Get a specific acl attribute", "ACL" + }, + { + NULL + } + }; + + setbuf(stdout, NULL); + + pc = poptGetContext("smbcacls", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "smb://server1/share1/filename"); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'S': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_SET; + break; + + case 'D': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_DELETE; + break; + + case 'M': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_MODIFY; + break; + + case 'a': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_ADD; + break; + + case 'g': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_GET; + break; + + case 'C': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_CHOWN; + break; + + case 'G': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_CHGRP; + break; + } + } + + /* Make connection to server */ + if(!poptPeekArg(pc)) { + poptPrintUsage(pc, stderr, 0); + return 1; + } + + strcpy(path, poptGetArg(pc)); + + if (smbc_init(get_auth_data_fn, debug) != 0) + { + printf("Could not initialize smbc_ library\n"); + return 1; + } + + /* Perform requested action */ + + switch(mode) + { + case SMB_ACL_GET: + if (the_acl == NULL) + { + if (numeric) + { + the_acl = "system.nt_sec_desc.*"; + } + else + { + the_acl = "system.nt_sec_desc.*+"; + } + } + ret = smbc_getxattr(path, the_acl, value, sizeof(value)); + if (ret < 0) + { + printf("Could not get attributes for [%s] %d: %s\n", + path, errno, strerror(errno)); + return 1; + } + + printf("Attributes for [%s] are:\n%s\n", path, value); + break; + + case SMB_ACL_ADD: + flags = SMBC_XATTR_FLAG_CREATE; + debugstr = "add attributes"; + goto do_set; + + case SMB_ACL_MODIFY: + flags = SMBC_XATTR_FLAG_REPLACE; + debugstr = "modify attributes"; + goto do_set; + + case SMB_ACL_CHOWN: + snprintf(value, sizeof(value), + "system.nt_sec_desc.owner%s:%s", + numeric ? "" : "+", the_acl); + the_acl = value; + debugstr = "chown owner"; + goto do_set; + + case SMB_ACL_CHGRP: + snprintf(value, sizeof(value), + "system.nt_sec_desc.group%s:%s", + numeric ? "" : "+", the_acl); + the_acl = value; + debugstr = "change group"; + goto do_set; + + case SMB_ACL_SET: + flags = 0; + debugstr = "set attributes"; + + do_set: + if ((p = strchr(the_acl, ':')) == NULL) + { + printf("Missing value. ACL must be name:value pair\n"); + return 1; + } + + *p++ = '\0'; + + ret = smbc_setxattr(path, the_acl, p, strlen(p), flags); + if (ret < 0) + { + printf("Could not %s for [%s] %d: %s\n", + debugstr, path, errno, strerror(errno)); + return 1; + } + break; + + case SMB_ACL_DELETE: + ret = smbc_removexattr(path, the_acl); + if (ret < 0) + { + printf("Could not remove attribute %s for [%s] %d:%s\n", + the_acl, path, errno, strerror(errno)); + return 1; + } + break; + + default: + printf("operation not yet implemented\n"); + break; + } + + return 0; +} -- cgit From d3d4c7446e43a484535ea05a6fb3234d78199e95 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Thu, 13 Nov 2003 21:40:27 +0000 Subject: Add this to samba-head. (This used to be commit d761175f131f80ae24549adca6ffc629f84a9803) --- examples/libsmbclient/testacl.c | 280 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100644 examples/libsmbclient/testacl.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c new file mode 100644 index 0000000000..47668f7c9c --- /dev/null +++ b/examples/libsmbclient/testacl.c @@ -0,0 +1,280 @@ +#include +#include +#include +#include +#include "libsmbclient.h" + +enum acl_mode +{ + SMB_ACL_GET, + SMB_ACL_SET, + SMB_ACL_DELETE, + SMB_ACL_MODIFY, + SMB_ACL_ADD, + SMB_ACL_CHOWN, + SMB_ACL_CHGRP +}; + +static void +get_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) + +{ + char temp[128]; + + fprintf(stdout, "Workgroup: [%s] ", pWorkgroup); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); + } + + fprintf(stdout, "Username: [%s] ", pUsername); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pUsername, temp, maxLenUsername - 1); + } + + fprintf(stdout, "Password: "); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pPassword, temp, maxLenPassword - 1); + } +} + + +int main(int argc, const char *argv[]) +{ + int opt; + int flags; + int debug = 0; + int numeric = 0; + enum acl_mode mode = SMB_ACL_GET; + static char *the_acl = NULL; + int ret; + char *p; + char *debugstr; + char path[1024]; + char value[1024]; + poptContext pc; + struct poptOption long_options[] = + { + POPT_AUTOHELP + { + "numeric", 'n', POPT_ARG_NONE, &numeric, + 1, "Don't resolve sids or masks to names" + }, + { + "debug", 'd', POPT_ARG_INT, &debug, + 0, "Set debug level (0-100)" + }, + { + "delete", 'D', POPT_ARG_STRING, NULL, + 'D', "Delete an acl", "ACL" + }, + { + "modify", 'M', POPT_ARG_STRING, NULL, + 'M', "Modify an acl", "ACL" + }, + { + "add", 'a', POPT_ARG_STRING, NULL, + 'a', "Add an acl", "ACL" + }, + { + "set", 'S', POPT_ARG_STRING, NULL, + 'S', "Set acls", "ACLS" + }, + { + "chown", 'C', POPT_ARG_STRING, NULL, + 'C', "Change ownership of a file", "USERNAME" + }, + { + "chgrp", 'G', POPT_ARG_STRING, NULL, + 'G', "Change group ownership of a file", "GROUPNAME" + }, + { + "get", 'g', POPT_ARG_STRING, NULL, + 'g', "Get a specific acl attribute", "ACL" + }, + { + NULL + } + }; + + setbuf(stdout, NULL); + + pc = poptGetContext("smbcacls", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "smb://server1/share1/filename"); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'S': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_SET; + break; + + case 'D': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_DELETE; + break; + + case 'M': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_MODIFY; + break; + + case 'a': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_ADD; + break; + + case 'g': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_GET; + break; + + case 'C': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_CHOWN; + break; + + case 'G': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_CHGRP; + break; + } + } + + /* Make connection to server */ + if(!poptPeekArg(pc)) { + poptPrintUsage(pc, stderr, 0); + return 1; + } + + strcpy(path, poptGetArg(pc)); + + if (smbc_init(get_auth_data_fn, debug) != 0) + { + printf("Could not initialize smbc_ library\n"); + return 1; + } + + /* Perform requested action */ + + switch(mode) + { + case SMB_ACL_GET: + if (the_acl == NULL) + { + if (numeric) + { + the_acl = "system.nt_sec_desc.*"; + } + else + { + the_acl = "system.nt_sec_desc.*+"; + } + } + ret = smbc_getxattr(path, the_acl, value, sizeof(value)); + if (ret < 0) + { + printf("Could not get attributes for [%s] %d: %s\n", + path, errno, strerror(errno)); + return 1; + } + + printf("Attributes for [%s] are:\n%s\n", path, value); + break; + + case SMB_ACL_ADD: + flags = SMBC_XATTR_FLAG_CREATE; + debugstr = "add attributes"; + goto do_set; + + case SMB_ACL_MODIFY: + flags = SMBC_XATTR_FLAG_REPLACE; + debugstr = "modify attributes"; + goto do_set; + + case SMB_ACL_CHOWN: + snprintf(value, sizeof(value), + "system.nt_sec_desc.owner%s:%s", + numeric ? "" : "+", the_acl); + the_acl = value; + debugstr = "chown owner"; + goto do_set; + + case SMB_ACL_CHGRP: + snprintf(value, sizeof(value), + "system.nt_sec_desc.group%s:%s", + numeric ? "" : "+", the_acl); + the_acl = value; + debugstr = "change group"; + goto do_set; + + case SMB_ACL_SET: + flags = 0; + debugstr = "set attributes"; + + do_set: + if ((p = strchr(the_acl, ':')) == NULL) + { + printf("Missing value. ACL must be name:value pair\n"); + return 1; + } + + *p++ = '\0'; + + ret = smbc_setxattr(path, the_acl, p, strlen(p), flags); + if (ret < 0) + { + printf("Could not %s for [%s] %d: %s\n", + debugstr, path, errno, strerror(errno)); + return 1; + } + break; + + case SMB_ACL_DELETE: + ret = smbc_removexattr(path, the_acl); + if (ret < 0) + { + printf("Could not remove attribute %s for [%s] %d:%s\n", + the_acl, path, errno, strerror(errno)); + return 1; + } + break; + + default: + printf("operation not yet implemented\n"); + break; + } + + return 0; +} -- cgit From 716dd32809b1fe2e6a836700297145c170d103c0 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Thu, 13 Nov 2003 21:42:07 +0000 Subject: Update Makefile ... (This used to be commit b92fd87b2461dff0e05ad4a7b0a475539c21d4c0) --- examples/libsmbclient/Makefile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 5fe9977c0a..c84cc3c977 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -2,12 +2,15 @@ CC = gcc SAMBA_INCL = ../../source/include +EXTLIB_INCL = -I/usr/include/gtk-1.2 \ + -I/usr/include/glib-1.2 \ + -I/usr/lib/glib/include -CFLAGS = -I$(SAMBA_INCL) +CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) LDFLAGS = -L/usr/lib -all: testsmbc tree +all: testsmbc tree testacl testsmbc: testsmbc.o @echo Linking testsmbc @@ -21,5 +24,9 @@ tree: tree.o @echo Linking tree @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient $< +testacl: testacl.o + @echo Linking testacl + @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient -lpopt $< + clean: @rm -f *.o *~ -- cgit From 2e2b6548200faadecf21d668596835ef160f7adb Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 9 Feb 2004 18:48:44 +0000 Subject: merge from 3.0 (This used to be commit 309a9a4cafc3c892840e28198a41973b236a528e) --- examples/libsmbclient/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index c84cc3c977..e7c82a3aee 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -14,7 +14,7 @@ all: testsmbc tree testacl testsmbc: testsmbc.o @echo Linking testsmbc - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient -L/usr/local/lib + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient -L/usr/local/lib testsmbc-static: testsmbc.o @echo Linking testsmbc -- cgit From 8d976560e07ccf11ac49926ee742ca41ff77c248 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 19 Mar 2004 17:36:56 +0000 Subject: Apply some more of Derrell Lipman's changes. (This used to be commit a6457e1c817663cf5f3e77e4dd431ac0d9184dc7) --- examples/libsmbclient/Makefile | 6 ++- examples/libsmbclient/testbrowse.c | 91 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 examples/libsmbclient/testbrowse.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index e7c82a3aee..fcd5ef2900 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -10,7 +10,7 @@ CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) LDFLAGS = -L/usr/lib -all: testsmbc tree testacl +all: testsmbc tree testacl testbrowse testsmbc: testsmbc.o @echo Linking testsmbc @@ -28,5 +28,9 @@ testacl: testacl.o @echo Linking testacl @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient -lpopt $< +testbrowse: testbrowse.o + @echo Linking testbrowse + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< + clean: @rm -f *.o *~ diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c new file mode 100644 index 0000000000..d2472230a2 --- /dev/null +++ b/examples/libsmbclient/testbrowse.c @@ -0,0 +1,91 @@ +/* + Unix SMB/CIFS implementation. + SMB client library test program for browsing with different master browsers + Copyright (C) Derrell Lipman 2004 + + 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 +#include +#include +#include +#include +#include +#include + +static void +auth_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int workgroup_len, + char * pUsername, + int username_len, + char * pPassword, + int password_len) + +{ + strncpy(pUsername, "anonymous", username_len); /* doesn't matter what */ + strncpy(pPassword, "password", password_len); /* ditto */ +} + + +int +main(int argc, char * argv[]) +{ + int debug = 4; + int opt; + char * p; + char buf[1024]; + int dir; + struct smbc_dirent * dirent; + char ** ppUrl; + char * urlList[] = + { + "smb://", + "smb://?mb=.any", + "smb://?mb=.all", + "smb://?mb=xx", /* this one is suupposed to fail */ + NULL + }; + + if (smbc_init(auth_fn, debug) != 0) + { + printf("Could not initialize smbc_ library\n"); + return 1; + } + + for (ppUrl = urlList; *ppUrl != NULL; ppUrl++) + { + printf("Opening (%s)...\n", *ppUrl); + + if ((dir = smbc_opendir(*ppUrl)) < 0) + { + printf("Could not open [%s] (%d:%s)\n", + *ppUrl, errno, strerror(errno)); + continue; + } + + while ((dirent = smbc_readdir(dir)) != NULL) + { + printf("%s\n", dirent->name); + } + + smbc_closedir(dir); + } + + exit(0); +} + -- cgit From fd312721ea57c562b70a753a37fcefad66db2e32 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 19 Mar 2004 17:48:08 +0000 Subject: missed some of Derrel's changes (This used to be commit 3aac1e549eaf4693ded84be432a2c94b6331ef6d) --- examples/libsmbclient/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index e7c82a3aee..fcd5ef2900 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -10,7 +10,7 @@ CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) LDFLAGS = -L/usr/lib -all: testsmbc tree testacl +all: testsmbc tree testacl testbrowse testsmbc: testsmbc.o @echo Linking testsmbc @@ -28,5 +28,9 @@ testacl: testacl.o @echo Linking testacl @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient -lpopt $< +testbrowse: testbrowse.o + @echo Linking testbrowse + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< + clean: @rm -f *.o *~ -- cgit From fbc611f431db443c23486f768ca5e2bc4db95c24 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 29 Mar 2005 00:42:51 +0000 Subject: r6108: Added smbsh/smbwrapper for Linux to example/libsmbclient tree; provided more complete libsmbclient testbrowse utility (This used to be commit 15736b97c837a16d9c009b8bff18b31429ccbe83) --- examples/libsmbclient/Makefile | 8 +- examples/libsmbclient/smbwrapper/Makefile | 35 + examples/libsmbclient/smbwrapper/README | 40 + examples/libsmbclient/smbwrapper/opendir_smbsh.c | 47 + examples/libsmbclient/smbwrapper/select.c | 124 ++ examples/libsmbclient/smbwrapper/smbsh.c | 160 ++ examples/libsmbclient/smbwrapper/smbw.c | 910 ++++++++++++ examples/libsmbclient/smbwrapper/smbw.h | 163 ++ examples/libsmbclient/smbwrapper/smbw_dir.c | 355 +++++ examples/libsmbclient/smbwrapper/smbw_stat.c | 146 ++ examples/libsmbclient/smbwrapper/wrapper.c | 1729 ++++++++++++++++++++++ examples/libsmbclient/smbwrapper/wrapper.h | 209 +++ examples/libsmbclient/testbrowse.c | 219 ++- examples/libsmbclient/testsmbc.c | 2 +- examples/libsmbclient/tree.c | 8 +- 15 files changed, 4094 insertions(+), 61 deletions(-) create mode 100644 examples/libsmbclient/smbwrapper/Makefile create mode 100644 examples/libsmbclient/smbwrapper/README create mode 100644 examples/libsmbclient/smbwrapper/opendir_smbsh.c create mode 100644 examples/libsmbclient/smbwrapper/select.c create mode 100644 examples/libsmbclient/smbwrapper/smbsh.c create mode 100644 examples/libsmbclient/smbwrapper/smbw.c create mode 100644 examples/libsmbclient/smbwrapper/smbw.h create mode 100644 examples/libsmbclient/smbwrapper/smbw_dir.c create mode 100644 examples/libsmbclient/smbwrapper/smbw_stat.c create mode 100644 examples/libsmbclient/smbwrapper/wrapper.c create mode 100644 examples/libsmbclient/smbwrapper/wrapper.h (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index fcd5ef2900..6c89fd431e 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -10,7 +10,7 @@ CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) LDFLAGS = -L/usr/lib -all: testsmbc tree testacl testbrowse +all: testsmbc tree testacl testbrowse smbsh testsmbc: testsmbc.o @echo Linking testsmbc @@ -32,5 +32,9 @@ testbrowse: testbrowse.o @echo Linking testbrowse @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< +smbsh: + make -C smbwrapper + clean: - @rm -f *.o *~ + @rm -f *.o *~ testsmbc tree testacl testbrowse + @make -C smbwrapper clean diff --git a/examples/libsmbclient/smbwrapper/Makefile b/examples/libsmbclient/smbwrapper/Makefile new file mode 100644 index 0000000000..099c204986 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/Makefile @@ -0,0 +1,35 @@ +LIBS = -lsmbclient -ldl +DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE + +CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) + +LDFLAGS = -L/usr/lib + +SMBINCLUDE = -I../../../source/include +CFLAGS= -fpic -g -O0 $(DEFS) $(SMBINCLUDE) + +BIN = . + +SMBWRAPPER_OBJS = smbw.o smbw_dir.o smbw_stat.o wrapper.o select.o +SMBSH_OBJS = smbsh.o + +all: $(BIN)/smbwrapper.so $(BIN)/smbsh + +$(BIN)/smbwrapper.so: $(SMBWRAPPER_OBJS) + $(CC) -g \ + -Wl,-init=smbw_initialize \ + -shared \ + --export-all-symbols \ + -o $(BIN)/smbwrapper.so \ + $(SMBWRAPPER_OBJS) \ + $(LIBS) \ + -Wl,-soname=`basename $@` + +$(BIN)/smbsh: $(SMBSH_OBJS) + $(CC) -g -o $(BIN)/smbsh $(SMBSH_OBJS) $(LIBS) + +opendir_smbsh: opendir_smbsh.o + $(CC) -g -o opendir_smbsh opendir_smbsh.o $(LIBS) $(DMALLOC) + +clean: + rm -f *.o *~ opendir_smbsh smbsh smbwrapper.so diff --git a/examples/libsmbclient/smbwrapper/README b/examples/libsmbclient/smbwrapper/README new file mode 100644 index 0000000000..7b71ec06ba --- /dev/null +++ b/examples/libsmbclient/smbwrapper/README @@ -0,0 +1,40 @@ +To create "smbsh" on Linux, just type "make". + +If you execute "smbsh" in *this* directory (so that it can find the required +shared library), you'll find yourself in a new shell. You can then issue +commands referencing the "/smb" pseudo-filesystem: + + ls /smb + ls /smb/WORKGROUP_OR_DOMAIN + ls /smb/SERVER + ls /smb/SERVER/SHARE + ls /smb/SERVER/SHARE/PATH + +Note that WORKGROUP_OR_DOMAIN is *not* used other than at that level. This is +consistent with the smb:// URI definition. + +Usage: + smbsh [-L ] + [-p ] + [-a ] + [-d ] + [-n] (do not ask for username/password) + [-W ] + [-U +#include +#include +#include +#include +#include + +int +main(int argc, char * argv[]) +{ + char * p; + char buf[1024]; + DIR * dir; + struct dirent * dirent; + + setbuf(stdout, NULL); + + for (fputs("path: ", stdout), p = fgets(buf, sizeof(buf), stdin); + p != NULL && *p != '\n' && *p != '\0'; + fputs("path: ", stdout), p = fgets(buf, sizeof(buf), stdin)) + { + if ((p = strchr(buf, '\n')) != NULL) + { + *p = '\0'; + } + + printf("Opening (%s)...\n", buf); + + if ((dir = opendir(buf)) == NULL) + { + printf("Could not open directory [%s]: \n", + buf, strerror(errno)); + continue; + } + + while ((dirent = readdir(dir)) != NULL) + { + printf("%-30s", dirent->d_name); + printf("%-30s", dirent->d_name + strlen(dirent->d_name) + 1); + printf("\n"); + } + + closedir(dir); + } + + exit(0); +} diff --git a/examples/libsmbclient/smbwrapper/select.c b/examples/libsmbclient/smbwrapper/select.c new file mode 100644 index 0000000000..aa90169ee7 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/select.c @@ -0,0 +1,124 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + Samba select/poll implementation + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Derrell Lipman 2003-2005 + + 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. +*/ + +/* + * WHY THIS FILE? + * + * This file implements the two functions in the select() family, as required + * by samba. The samba native functions, though, implement a pipe to help + * alleviate a deadlock problem, but which creates problems of its own (the + * timeout stops working correctly). Those functions also require that all + * signal handlers call a function which writes to the pipe -- a task which is + * difficult to do in the smbwrapper environment. + */ + + +#include +#include +#include + +int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval) +{ + int ret; + fd_set *readfds2, readfds_buf; + + /* If readfds is NULL we need to provide our own set. */ + if (readfds) { + readfds2 = readfds; + } else { + readfds2 = &readfds_buf; + FD_ZERO(readfds2); + } + + errno = 0; + ret = select(maxfd,readfds2,writefds,errorfds,tval); + + if (ret <= 0) { + FD_ZERO(readfds2); + if (writefds) + FD_ZERO(writefds); + if (errorfds) + FD_ZERO(errorfds); + } + + return ret; +} + +/******************************************************************* + Similar to sys_select() but catch EINTR and continue. + This is what sys_select() used to do in Samba. +********************************************************************/ + +int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval) +{ + 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); + end_time.tv_sec += tval->tv_sec; + end_time.tv_usec += tval->tv_usec; + end_time.tv_sec += end_time.tv_usec / 1000000; + end_time.tv_usec %= 1000000; + ptval = &tval2; + } else { + ptval = NULL; + } + + do { + if (readfds) + readfds_buf = *readfds; + if (writefds) + writefds_buf = *writefds; + if (errorfds) + errorfds_buf = *errorfds; + if (tval) { + GetTimeOfDay(&now_time); + 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) { + tval2.tv_usec += 1000000; + tval2.tv_sec--; + } + if ((signed long) tval2.tv_sec < 0) { + ret = 0; + break; /* time has already elapsed */ + } + } + + ret = sys_select(maxfd, readfds2, writefds2, errorfds2, ptval); + } while (ret == -1 && errno == EINTR); + + if (readfds) + *readfds = readfds_buf; + if (writefds) + *writefds = writefds_buf; + if (errorfds) + *errorfds = errorfds_buf; + + return ret; +} diff --git a/examples/libsmbclient/smbwrapper/smbsh.c b/examples/libsmbclient/smbwrapper/smbsh.c new file mode 100644 index 0000000000..7b33de766f --- /dev/null +++ b/examples/libsmbclient/smbwrapper/smbsh.c @@ -0,0 +1,160 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB wrapper functions - frontend + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Derrell Lipman 2003-2005 + + 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 +#include +#include +#include +#include +#include +#include +#include + +#ifndef FALSE +# define FALSE (0) +# define TRUE (! FALSE) +#endif + +static void smbsh_usage(void) +{ + printf("smbsh [options] [command [args] ...]\n\n"); + printf(" -p prepend library name\n"); + printf(" -a append library name\n"); + printf(" -n"); + printf(" -W workgroup\n"); + printf(" -U username\n"); + printf(" -P prefix\n"); + printf(" -R resolve order\n"); + printf(" -d debug level\n"); + printf(" -l logfile\n"); + printf(" -L libdir\n"); + exit(0); +} + +int main(int argc, char *argv[]) +{ + char *p, *u; + char *libd = "."; + char line[PATH_MAX], pre[PATH_MAX], post[PATH_MAX]; + int opt; + int no_ask = 0; + struct stat statbuf; + extern char *optarg; + extern int optind; + + *pre = *post = '\0'; + + while ((opt = getopt(argc, argv, "p:a:d:nL:W:U:h")) != -1) { + switch (opt) { + case 'p': /* prepend library before smbwrapper.so */ + if (*pre != '\0') + strncat(pre, " ", PATH_MAX - strlen(pre)); + strncat(pre, optarg, PATH_MAX - strlen(pre)); + break; + + case 'a': /* append library after smbwrapper.so */ + strncat(post, " ", PATH_MAX - strlen(post)); + strncat(post, optarg, PATH_MAX - strlen(post)); + break; + + case 'd': + setenv("DEBUG", optarg, TRUE); + break; + + case 'n': /* don't ask for username/password */ + no_ask++; + break; + + case 'L': + libd = optarg; + break; + + case 'W': + setenv("WORKGROUP", optarg, TRUE); + break; + + case 'U': + p = strchr(optarg,'%'); + if (p) { + *p=0; + setenv("PASSWORD", p+1, TRUE); + } + setenv("USER", optarg, TRUE); + break; + + case 'h': + default: + smbsh_usage(); + } + } + + + if (! no_ask) { + if (!getenv("USER")) { + printf("Username: "); + u = fgets(line, sizeof(line)-1, stdin); + setenv("USER", u, TRUE); + } + + if (!getenv("PASSWORD")) { + p = getpass("Password: "); + setenv("PASSWORD", p, TRUE); + } + } + + strncpy(line, pre, PATH_MAX - strlen(line)); + strncat(line, " ", PATH_MAX - strlen(line)); + strncat(line, libd, PATH_MAX - strlen(line)); + strncat(line, "/smbwrapper.so", PATH_MAX - strlen(line)); + strncat(line, post, PATH_MAX - strlen(line)); + setenv("LD_PRELOAD", line, TRUE); + setenv("LD_BIND_NOW", "true", TRUE); + + snprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd); + + if (stat(line, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) { + snprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd); + setenv("_RLD_LIST", line, TRUE); + snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); + setenv("_RLDN32_LIST", line, TRUE); + } else { + snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); + setenv("_RLD_LIST", line, TRUE); + } + + if (optind < argc) { + execvp(argv[optind], &argv[optind]); + } else { + char *shellpath = getenv("SHELL"); + + setenv("PS1", "smbsh$ ", TRUE); + + if(shellpath) { + execl(shellpath,"smbsh", NULL); + } else { + setenv("SHELL", "/bin/sh", TRUE); + execl("/bin/sh", "smbsh", NULL); + } + } + printf("launch failed!\n"); + return 1; +} diff --git a/examples/libsmbclient/smbwrapper/smbw.c b/examples/libsmbclient/smbwrapper/smbw.c new file mode 100644 index 0000000000..d2f1c18695 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/smbw.c @@ -0,0 +1,910 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB wrapper functions + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Derrell Lipman 2003-2005 + + 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 +#include +#include +#include +#include +#include "smbw.h" + +int smbw_fd_map[__FD_SETSIZE]; +int smbw_ref_count[__FD_SETSIZE]; +char smbw_cwd[PATH_MAX]; +char smbw_prefix[] = SMBW_PREFIX; + +/* needs to be here because of dumb include files on some systems */ +int creat_bits = O_WRONLY|O_CREAT|O_TRUNC; + +int smbw_initialized = 0; + +static int debug_level = 0; + +static SMBCCTX *smbw_ctx; + +extern int smbw_debug; + + +int smbw_ref(int client_fd, Ref_Count_Type type, ...) +{ + va_list ap; + + /* client id values begin at SMBC_BASE_FC. */ + client_fd -= SMBC_BASE_FD; + + va_start(ap, type); + switch(type) + { + case SMBW_RCT_Increment: + return ++smbw_ref_count[client_fd]; + + case SMBW_RCT_Decrement: + return --smbw_ref_count[client_fd]; + + case SMBW_RCT_Get: + return smbw_ref_count[client_fd]; + + case SMBW_RCT_Set: + return (smbw_ref_count[client_fd] = va_arg(ap, int)); + } + va_end(ap); + + /* never gets here */ + return -1; +} + + +/* + * Return a username and password given a server and share name + * + * Returns 0 upon success; + * non-zero otherwise, and errno is set to indicate the error. + */ +static void get_envvar_auth_data(const char *srv, + const char *shr, + char *wg, int wglen, + char *un, int unlen, + char *pw, int pwlen) +{ + char *u; + char *p; + char *w; + + /* Fall back to environment variables */ + + w = getenv("WORKGROUP"); + if (w == NULL) w = ""; + + u = getenv("USER"); + if (u == NULL) u = ""; + + p = getenv("PASSWORD"); + if (p == NULL) p = ""; + + strncpy(wg, w, wglen); + strncpy(un, u, unlen); + strncpy(pw, p, pwlen); +} + +static smbc_get_auth_data_fn get_auth_data_fn = get_envvar_auth_data; + +/***************************************************** +set the get auth data function +******************************************************/ +void smbw_set_auth_data_fn(smbc_get_auth_data_fn fn) +{ + get_auth_data_fn = fn; +} + + +/***************************************************** +ensure that all connections are terminated upon exit +******************************************************/ +static void do_shutdown(void) +{ + if (smbw_ctx != NULL) { + smbc_free_context(smbw_ctx, 1); + } +} + + +/***************************************************** +initialise structures +*******************************************************/ +static void do_init(int is_real_startup) +{ + int i; + char *p; + + smbw_initialized = 1; /* this must be first to avoid recursion! */ + + smbw_ctx = NULL; /* don't free context until it's established */ + + /* initially, no file descriptors are mapped */ + for (i = 0; i < __FD_SETSIZE; i++) { + smbw_fd_map[i] = -1; + smbw_ref_count[i] = 0; + } + + /* See if we've been told to start in a particular directory */ + if ((p=getenv("SMBW_DIR")) != NULL) { + strncpy(smbw_cwd, p, PATH_MAX); + + /* we don't want the old directory to be busy */ + (* smbw_libc.chdir)("/"); + + } else { + *smbw_cwd = '\0'; + } + + if ((p=getenv("DEBUG"))) { + debug_level = atoi(p); + } + + if ((smbw_ctx = smbc_new_context()) == NULL) { + 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; +// smbw_cache_functions(smbw_ctx); + + if (smbc_init_context(smbw_ctx) == NULL) { + exit(1); + } + + smbc_set_context(smbw_ctx); + + /* if not real startup, exit handler has already been established */ + if (is_real_startup) { + atexit(do_shutdown); + } +} + +/***************************************************** +initialise structures, real start up vs a fork() +*******************************************************/ +void smbw_init(void) +{ + do_init(1); +} + + +/***************************************************** +determine if a file descriptor is a smb one +*******************************************************/ +int smbw_fd(int smbw_fd) +{ + SMBW_INIT(); + + return (smbw_fd >= 0 && + smbw_fd < __FD_SETSIZE && + smbw_fd_map[smbw_fd] >= SMBC_BASE_FD); /* minimum smbc_ fd */ +} + + +/***************************************************** +determine if a path is a smb one +*******************************************************/ +int smbw_path(const char *name) +{ + int len; + int ret; + int saved_errno; + + saved_errno = errno; + + SMBW_INIT(); + + len = strlen(smbw_prefix); + + ret = ((strncmp(name, smbw_prefix, len) == 0 && + (name[len] == '\0' || name[len] == '/')) || + (*name != '/' && *smbw_cwd != '\0')); + + errno = saved_errno; + return ret; +} + + +/***************************************************** +remove redundent stuff from a filename +*******************************************************/ +void smbw_clean_fname(char *name) +{ + char *p, *p2; + int l; + int modified = 1; + + if (!name) return; + + DEBUG(10, ("Clean [%s]...\n", name)); + + while (modified) { + modified = 0; + + if ((p=strstr(name,"/./"))) { + modified = 1; + while (*p) { + p[0] = p[2]; + p++; + } + DEBUG(10, ("\tclean 1 (/./) produced [%s]\n", name)); + } + + if ((p=strstr(name,"//"))) { + modified = 1; + while (*p) { + p[0] = p[1]; + p++; + } + DEBUG(10, ("\tclean 2 (//) produced [%s]\n", name)); + } + + if (strcmp(name,"/../")==0) { + modified = 1; + name[1] = 0; + DEBUG(10,("\tclean 3 (^/../$) produced [%s]\n", name)); + } + + if ((p=strstr(name,"/../"))) { + modified = 1; + for (p2 = (p > name ? p-1 : p); p2 > name; p2--) { + if (p2[0] == '/') break; + } + if (p2 > name) p2++; + while (*p2) { + p2[0] = p[3]; + p2++; + p++; + } + DEBUG(10, ("\tclean 4 (/../) produced [%s]\n", name)); + } + + if (strcmp(name,"/..")==0) { + modified = 1; + name[1] = 0; + DEBUG(10, ("\tclean 5 (^/..$) produced [%s]\n", name)); + } + + l = strlen(name); + p = l>=3?(name+l-3):name; + if (strcmp(p,"/..")==0) { + modified = 1; + for (p2=p-1;p2>name;p2--) { + if (p2[0] == '/') break; + } + if (p2==name) { + p[0] = '/'; + p[1] = 0; + } else { + p2[0] = 0; + } + DEBUG(10, ("\tclean 6 (/..) produced [%s]\n", name)); + } + + l = strlen(name); + p = l>=2?(name+l-2):name; + if (strcmp(p,"/.")==0) { + modified = 1; + if (p == name) { + p[1] = 0; + } else { + p[0] = 0; + } + DEBUG(10, ("\tclean 7 (/.) produced [%s]\n", name)); + } + + if (strncmp(p=name,"./",2) == 0) { + modified = 1; + do { + p[0] = p[2]; + } while (*p++); + DEBUG(10, ("\tclean 8 (^./) produced [%s]\n", name)); + } + + l = strlen(p=name); + if (l > 1 && p[l-1] == '/') { + modified = 1; + p[l-1] = 0; + DEBUG(10, ("\tclean 9 (/) produced [%s]\n", name)); + } + } +} + +void smbw_fix_path(const char *src, char *dest) +{ + const char *p; + int len = strlen(smbw_prefix); + + if (*src == '/') { + for (p = src + len; *p == '/'; p++) + ; + snprintf(dest, PATH_MAX, "smb://%s", p); + } else { + snprintf(dest, PATH_MAX, "%s/%s", smbw_cwd, src); + } + + smbw_clean_fname(dest + 5); + + DEBUG(10, ("smbw_fix_path(%s) returning [%s]\n", src, dest)); +} + + + +/***************************************************** +a wrapper for open() +*******************************************************/ +int smbw_open(const char *fname, int flags, mode_t mode) +{ + int client_fd; + int smbw_fd; + char path[PATH_MAX]; + + SMBW_INIT(); + + if (!fname) { + errno = EINVAL; + return -1; + } + + smbw_fd = (smbw_libc.open)(SMBW_DUMMY, O_WRONLY, 0200); + if (smbw_fd == -1) { + errno = EMFILE; + return -1; + } + + smbw_fix_path(fname, path); + if (flags == creat_bits) { + client_fd = smbc_creat(path, mode); + } else { + client_fd = smbc_open(path, flags, mode); + } + + if (client_fd < 0) { + (* smbw_libc.close)(smbw_fd); + return -1; + } + + smbw_fd_map[smbw_fd] = client_fd; + smbw_ref(client_fd, SMBW_RCT_Increment); + return smbw_fd; +} + + +/***************************************************** +a wrapper for pread() + +there should really be an smbc_pread() to avoid the two +lseek()s required in this kludge. +*******************************************************/ +ssize_t smbw_pread(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs) +{ + int client_fd; + ssize_t ret; + int saved_errno; + SMBW_OFF_T old_ofs; + + client_fd = smbw_fd_map[smbw_fd]; + + if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 || + smbc_lseek(client_fd, ofs, SEEK_SET) < 0) { + return -1; + } + + if ((ret = smbc_read(client_fd, buf, count)) < 0) { + saved_errno = errno; + (void) smbc_lseek(client_fd, old_ofs, SEEK_SET); + errno = saved_errno; + return -1; + } + + return ret; +} + +/***************************************************** +a wrapper for read() +*******************************************************/ +ssize_t smbw_read(int smbw_fd, void *buf, size_t count) +{ + int client_fd; + + client_fd = smbw_fd_map[smbw_fd]; + + return smbc_read(client_fd, buf, count); +} + + + +/***************************************************** +a wrapper for write() +*******************************************************/ +ssize_t smbw_write(int smbw_fd, void *buf, size_t count) +{ + int client_fd; + + client_fd = smbw_fd_map[smbw_fd]; + + return smbc_write(client_fd, buf, count); +} + +/***************************************************** +a wrapper for pwrite() +*******************************************************/ +ssize_t smbw_pwrite(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs) +{ + int saved_errno; + int client_fd; + ssize_t ret; + SMBW_OFF_T old_ofs; + + client_fd = smbw_fd_map[smbw_fd]; + + if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 || + smbc_lseek(client_fd, ofs, SEEK_SET) < 0) { + return -1; + } + + if ((ret = smbc_write(client_fd, buf, count)) < 0) { + saved_errno = errno; + (void) smbc_lseek(client_fd, old_ofs, SEEK_SET); + errno = saved_errno; + return -1; + } + + return ret; +} + +/***************************************************** +a wrapper for close() +*******************************************************/ +int smbw_close(int smbw_fd) +{ + int client_fd; + + client_fd = smbw_fd_map[smbw_fd]; + + if (smbw_ref(client_fd, SMBW_RCT_Decrement) > 0) { + return 0; + } + + (* smbw_libc.close)(smbw_fd); + smbw_fd_map[smbw_fd] = -1; + return smbc_close(client_fd); +} + + +/***************************************************** +a wrapper for fcntl() +*******************************************************/ +int smbw_fcntl(int smbw_fd, int cmd, long arg) +{ + return 0; +} + + +/***************************************************** +a wrapper for access() +*******************************************************/ +int smbw_access(const char *name, int mode) +{ + struct SMBW_stat st; + + SMBW_INIT(); + + if (smbw_stat(name, &st)) return -1; + + if (((mode & R_OK) && !(st.s_mode & S_IRUSR)) || + ((mode & W_OK) && !(st.s_mode & S_IWUSR)) || + ((mode & X_OK) && !(st.s_mode & S_IXUSR))) { + errno = EACCES; + return -1; + } + + return 0; +} + +/***************************************************** +a wrapper for readlink() - needed for correct errno setting +*******************************************************/ +int smbw_readlink(const char *fname, char *buf, size_t bufsize) +{ + struct SMBW_stat st; + int ret; + + SMBW_INIT(); + + ret = smbw_stat(fname, &st); + if (ret != 0) { + return -1; + } + + /* it exists - say it isn't a link */ + errno = EINVAL; + return -1; +} + + +/***************************************************** +a wrapper for unlink() +*******************************************************/ +int smbw_unlink(const char *fname) +{ + char path[PATH_MAX]; + + SMBW_INIT(); + + smbw_fix_path(fname, path); + return smbc_unlink(path); +} + + +/***************************************************** +a wrapper for rename() +*******************************************************/ +int smbw_rename(const char *oldname, const char *newname) +{ + char path_old[PATH_MAX]; + char path_new[PATH_MAX]; + + SMBW_INIT(); + + smbw_fix_path(oldname, path_old); + smbw_fix_path(newname, path_new); + return smbc_rename(path_old, path_new); +} + + +/***************************************************** +a wrapper for utimes +*******************************************************/ +int smbw_utimes(const char *fname, void *buf) +{ + char path[PATH_MAX]; + + smbw_fix_path(fname, path); + return smbc_utimes(path, buf); +} + + +/***************************************************** +a wrapper for utime +*******************************************************/ +int smbw_utime(const char *fname, void *buf) +{ + char path[PATH_MAX]; + + smbw_fix_path(fname, path); + return smbc_utime(path, buf); +} + +/***************************************************** +a wrapper for chown() +*******************************************************/ +int smbw_chown(const char *fname, uid_t owner, gid_t group) +{ + /* always indiciate that this is not supported. */ + errno = ENOTSUP; + return -1; +} + +/***************************************************** +a wrapper for chmod() +*******************************************************/ +int smbw_chmod(const char *fname, mode_t newmode) +{ + char path[PATH_MAX]; + + smbw_fix_path(fname, path); + return smbc_chmod(path, newmode); +} + + +/***************************************************** +a wrapper for lseek() +*******************************************************/ +SMBW_OFF_T smbw_lseek(int smbw_fd, + SMBW_OFF_T offset, + int whence) +{ + int client_fd; + SMBW_OFF_T ret; + + client_fd = smbw_fd_map[smbw_fd]; + + ret = smbc_lseek(client_fd, offset, whence); + if (smbw_debug) + { + printf("smbw_lseek(%d/%d, 0x%llx) returned 0x%llx\n", + smbw_fd, client_fd, + (unsigned long long) offset, + (unsigned long long) ret); + } + return ret; +} + +/***************************************************** +a wrapper for dup() +*******************************************************/ +int smbw_dup(int smbw_fd) +{ + int fd2; + + fd2 = (smbw_libc.dup)(smbw_fd); + if (fd2 == -1) { + return -1; + } + + smbw_fd_map[fd2] = smbw_fd_map[smbw_fd]; + smbw_ref(smbw_fd_map[smbw_fd], SMBW_RCT_Increment); + return fd2; +} + + +/***************************************************** +a wrapper for dup2() +*******************************************************/ +int smbw_dup2(int smbw_fd, int fd2) +{ + if ((* smbw_libc.dup2)(smbw_fd, fd2) != fd2) { + return -1; + } + + smbw_fd_map[fd2] = smbw_fd_map[smbw_fd]; + smbw_ref(smbw_fd_map[smbw_fd], SMBW_RCT_Increment); + return fd2; +} + + +/***************************************************** +when we fork we have to close all connections and files +in the child +*******************************************************/ +int smbw_fork(void) +{ + int i; + pid_t child_pid; + int p[2]; + char c = 0; + + SMBW_INIT(); + + if (pipe(p)) return (* smbw_libc.fork)(); + + child_pid = (* smbw_libc.fork)(); + + if (child_pid) { + /* block the parent for a moment until the sockets are + closed */ + (* smbw_libc.close)(p[1]); + (* smbw_libc.read)(p[0], &c, 1); + (* smbw_libc.close)(p[0]); + return child_pid; + } + + (* smbw_libc.close)(p[0]); + + /* close all server connections and locally-opened files */ + for (i = 0; i < __FD_SETSIZE; i++) { + if (smbw_fd_map[i] > 0 && + smbw_ref(smbw_fd_map[i], SMBW_RCT_Get) > 0) { + + smbc_close(smbw_fd_map[i]); + smbw_ref(smbw_fd_map[i], SMBW_RCT_Set, 0); + (* smbw_libc.close)(i); + } + + smbw_fd_map[i] = -1; + } + + /* unblock the parent */ + write(p[1], &c, 1); + (* smbw_libc.close)(p[1]); + + /* specify directory to start in, if it's simulated smb */ + if (*smbw_cwd != '\0') { + setenv("SMBW_DIR", smbw_cwd, 1); + } else { + unsetenv("SMBW_DIR"); + } + + /* Re-initialize this library for the child */ + do_init(0); + + /* and continue in the child */ + return 0; +} + +int smbw_setxattr(const char *fname, + const char *name, + const void *value, + size_t size, + int flags) +{ + char path[PATH_MAX]; + + if (strcmp(name, "system.posix_acl_access") == 0) + { + name = "system.*"; + } + + smbw_fix_path(fname, path); + return smbc_setxattr(path, name, value, size, flags); +} + +int smbw_lsetxattr(const char *fname, + const char *name, + const void *value, + size_t size, + int flags) +{ + char path[PATH_MAX]; + + if (strcmp(name, "system.posix_acl_access") == 0) + { + name = "system.*"; + } + + smbw_fix_path(fname, path); + return smbc_lsetxattr(path, name, value, size, flags); +} + +int smbw_fsetxattr(int smbw_fd, + const char *name, + const void *value, + size_t size, + int flags) +{ + int client_fd; + + if (strcmp(name, "system.posix_acl_access") == 0) + { + name = "system.*"; + } + + client_fd = smbw_fd_map[smbw_fd]; + return smbc_fsetxattr(client_fd, name, value, size, flags); +} + +int smbw_getxattr(const char *fname, + const char *name, + const void *value, + size_t size) +{ + char path[PATH_MAX]; + + if (strcmp(name, "system.posix_acl_access") == 0) + { + name = "system.*"; + } + + smbw_fix_path(fname, path); + + return smbc_getxattr(path, name, value, size); +} + +int smbw_lgetxattr(const char *fname, + const char *name, + const void *value, + size_t size) +{ + char path[PATH_MAX]; + + if (strcmp(name, "system.posix_acl_access") == 0) + { + name = "system.*"; + } + + smbw_fix_path(fname, path); + return smbc_lgetxattr(path, name, value, size); +} + +int smbw_fgetxattr(int smbw_fd, + const char *name, + const void *value, + size_t size) +{ + int client_fd; + + if (strcmp(name, "system.posix_acl_access") == 0) + { + name = "system.*"; + } + + client_fd = smbw_fd_map[smbw_fd]; + return smbc_fgetxattr(client_fd, name, value, size); +} + +int smbw_removexattr(const char *fname, + const char *name) +{ + char path[PATH_MAX]; + + if (strcmp(name, "system.posix_acl_access") == 0) + { + name = "system.*"; + } + + smbw_fix_path(fname, path); + return smbc_removexattr(path, name); +} + +int smbw_lremovexattr(const char *fname, + const char *name) +{ + char path[PATH_MAX]; + + if (strcmp(name, "system.posix_acl_access") == 0) + { + name = "system.*"; + } + + smbw_fix_path(fname, path); + return smbc_lremovexattr(path, name); +} + +int smbw_fremovexattr(int smbw_fd, + const char *name) +{ + int client_fd; + + if (strcmp(name, "system.posix_acl_access") == 0) + { + name = "system.*"; + } + + client_fd = smbw_fd_map[smbw_fd]; + return smbc_fremovexattr(client_fd, name); +} + +int smbw_listxattr(const char *fname, + char *list, + size_t size) +{ + char path[PATH_MAX]; + + smbw_fix_path(fname, path); + return smbc_listxattr(path, list, size); +} + +int smbw_llistxattr(const char *fname, + char *list, + size_t size) +{ + char path[PATH_MAX]; + + smbw_fix_path(fname, path); + return smbc_llistxattr(path, list, size); +} + +int smbw_flistxattr(int smbw_fd, + char *list, + size_t size) +{ + int client_fd; + + client_fd = smbw_fd_map[smbw_fd]; + return smbc_flistxattr(client_fd, list, size); +} diff --git a/examples/libsmbclient/smbwrapper/smbw.h b/examples/libsmbclient/smbwrapper/smbw.h new file mode 100644 index 0000000000..717b5c2f1c --- /dev/null +++ b/examples/libsmbclient/smbwrapper/smbw.h @@ -0,0 +1,163 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB wrapper functions - definitions + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Derrell Lipman 2003-2005 + + 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 _SMBW_H +#define _SMBW_H + +#include +#include +#include +#include +#include +#include +#include +#include "config.h" /* must come before libsmbclient.h */ +#include "libsmbclient.h" +#include "wrapper.h" + +#undef DEBUG +#define DEBUG(level, s) do { if (level <= debug_level) printf s; } while (0) + + +#define SMBW_PREFIX "/smb" +#define SMBW_DUMMY "/dev/null" + +extern int smbw_initialized; +#define SMBW_INIT() do { if (! smbw_initialized) smbw_init(); } while (0) + +#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) +# define SMBW_OFF_T off64_t +#else +# define SMBW_OFF_T off_t +#endif + + +/* The following definitions come from smbwrapper/smbw.c */ + +typedef enum { + SMBW_RCT_Increment, + SMBW_RCT_Decrement, + SMBW_RCT_Get, + SMBW_RCT_Set +} Ref_Count_Type; + +int smbw_ref(int client_fd, Ref_Count_Type type, ...); +void smbw_init(void); +int smbw_fd(int fd); +int smbw_path(const char *path); +void smbw_clean_fname(char *name); +void smbw_fix_path(const char *src, char *dest); +void smbw_set_auth_data_fn(smbc_get_auth_data_fn fn); +int smbw_open(const char *fname, int flags, mode_t mode); +ssize_t smbw_pread(int fd, void *buf, size_t count, SMBW_OFF_T ofs); +ssize_t smbw_read(int fd, void *buf, size_t count); +ssize_t smbw_write(int fd, void *buf, size_t count); +ssize_t smbw_pwrite(int fd, void *buf, size_t count, SMBW_OFF_T ofs); +int smbw_close(int fd); +int smbw_fcntl(int fd, int cmd, long arg); +int smbw_access(const char *name, int mode); +int smbw_readlink(const char *path, char *buf, size_t bufsize); +int smbw_unlink(const char *fname); +int smbw_rename(const char *oldname, const char *newname); +int smbw_utime(const char *fname, void *buf); +int smbw_utimes(const char *fname, void *buf); +int smbw_chown(const char *fname, uid_t owner, gid_t group); +int smbw_chmod(const char *fname, mode_t newmode); +SMBW_OFF_T smbw_lseek(int smbw_fd, SMBW_OFF_T offset, int whence); +int smbw_dup(int fd); +int smbw_dup2(int fd, int fd2); +int smbw_fork(void); + +/* The following definitions come from smbwrapper/smbw_dir.c */ + +int smbw_dirp(DIR * dirp); +int smbw_dir_open(const char *fname); +int smbw_dir_fstat(int fd, SMBW_stat *st); +int smbw_dir_close(int fd); +int smbw_getdents(unsigned int fd, SMBW_dirent *dirp, int count); +int smbw_chdir(const char *name); +int smbw_mkdir(const char *fname, mode_t mode); +int smbw_rmdir(const char *fname); +char *smbw_getcwd(char *buf, size_t size); +int smbw_fchdir(int fd); +DIR *smbw_opendir(const char *fname); +SMBW_dirent *smbw_readdir(DIR *dirp); +int smbw_readdir_r(DIR *dirp, + struct SMBW_dirent *__restrict entry, + struct SMBW_dirent **__restrict result); +int smbw_closedir(DIR *dirp); +void smbw_seekdir(DIR *dirp, long long offset); +long long smbw_telldir(DIR *dirp); +int smbw_setxattr(const char *fname, + const char *name, + const void *value, + size_t size, + int flags); +int smbw_lsetxattr(const char *fname, + const char *name, + const void *value, + size_t size, + int flags); +int smbw_fsetxattr(int smbw_fd, + const char *name, + const void *value, + size_t size, + int flags); +int smbw_getxattr(const char *fname, + const char *name, + const void *value, + size_t size); +int smbw_lgetxattr(const char *fname, + const char *name, + const void *value, + size_t size); +int smbw_fgetxattr(int smbw_fd, + const char *name, + const void *value, + size_t size); +int smbw_removexattr(const char *fname, + const char *name); +int smbw_lremovexattr(const char *fname, + const char *name); +int smbw_fremovexattr(int smbw_fd, + const char *name); +int smbw_listxattr(const char *fname, + char *list, + size_t size); +int smbw_llistxattr(const char *fname, + char *list, + size_t size); +int smbw_flistxattr(int smbw_fd, + char *list, + size_t size); + +/* The following definitions come from smbwrapper/smbw_stat.c */ + +int smbw_fstat(int fd, SMBW_stat *st); +int smbw_stat(const char *fname, SMBW_stat *st); + +/* The following definitions come from smbwrapper/cache.c */ +int +smbw_cache_functions(SMBCCTX * context); + + +#endif /* _SMBW_H */ diff --git a/examples/libsmbclient/smbwrapper/smbw_dir.c b/examples/libsmbclient/smbwrapper/smbw_dir.c new file mode 100644 index 0000000000..f3ec03e5a8 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/smbw_dir.c @@ -0,0 +1,355 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB wrapper directory functions + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Derrell Lipman 2003-2005 + + 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 "smbw.h" + +/***************************************************** +determine if a directory handle is a smb one +*******************************************************/ +int smbw_dirp(DIR * dirp) +{ + return ((char *) dirp >= (char *) smbw_fd_map && + (char *) dirp < (char *) &smbw_fd_map[__FD_SETSIZE] && + *(int *) dirp != -1); +} + + +/***************************************************** +a wrapper for getdents() +*******************************************************/ +int smbw_getdents(unsigned int fd_smbw, + struct SMBW_dirent *dirent_external, + int count) +{ + int remaining; + int fd_client = smbw_fd_map[fd_smbw]; + struct smbc_dirent *dirent_internal; + + + for (remaining = count; + remaining > sizeof(struct SMBW_dirent); + dirent_external++) { + + /* + * We do these one at a time because there's otherwise no way + * to limit how many smbc_getdents() will return for us, and + * if it returns too many, it also doesn't give us offsets to + * be able to seek back to where we need to be. In practice, + * this one-at-a-time retrieval isn't a problem because the + * time-consuming network transaction is all done at + * smbc_opendir() time. + */ + dirent_internal = smbc_readdir(fd_client); + if (dirent_internal == NULL) { + break; + } + + remaining -= sizeof(struct SMBW_dirent); + + dirent_external->d_ino = -1; /* not supported */ + dirent_external->d_off = smbc_telldir(fd_client); + dirent_external->d_reclen = sizeof(struct SMBW_dirent); + dirent_external->d_type = dirent_internal->smbc_type; + + strncpy(dirent_external->d_name, + dirent_internal->name, + sizeof(dirent_external->d_name) - 1); + strncpy(dirent_external->d_comment, + dirent_internal->comment, + sizeof(dirent_external->d_comment) - 1); + } + + return(count - remaining); +} + + +/***************************************************** +a wrapper for chdir() +*******************************************************/ +int smbw_chdir(const char *name) +{ + int simulate; + struct stat statbuf; + char path[PATH_MAX]; + char *p; + + SMBW_INIT(); + + if (!name) { + errno = EINVAL; + return -1; + } + + if (! smbw_path((char *) name)) { + if ((* smbw_libc.chdir)(name) == 0) { + *smbw_cwd = '\0'; + return 0; + } + + return -1; + } + + smbw_fix_path(name, path); + + /* ensure it exists */ + p = path + 6; /* look just past smb:// */ + simulate = (strchr(p, '/') == NULL); + + /* special case for full-network scan, workgroups, and servers */ + if (! simulate) { + + if (smbc_stat(path, &statbuf) < 0) { + return -1; + } + + /* ensure it's a directory */ + if (! S_ISDIR(statbuf.st_mode)) { + errno = ENOTDIR; + return -1; + } + } + + strncpy(smbw_cwd, path, PATH_MAX); + + /* we don't want the old directory to be busy */ + (* smbw_libc.chdir)("/"); + + return 0; +} + + +/***************************************************** +a wrapper for mkdir() +*******************************************************/ +int smbw_mkdir(const char *fname, mode_t mode) +{ + char path[PATH_MAX]; + + if (!fname) { + errno = EINVAL; + return -1; + } + + SMBW_INIT(); + + smbw_fix_path(fname, path); + return smbc_mkdir(path, mode); +} + +/***************************************************** +a wrapper for rmdir() +*******************************************************/ +int smbw_rmdir(const char *fname) +{ + char path[PATH_MAX]; + + if (!fname) { + errno = EINVAL; + return -1; + } + + SMBW_INIT(); + + smbw_fix_path(fname, path); + return smbc_rmdir(path); +} + + +/***************************************************** +a wrapper for getcwd() +*******************************************************/ +char *smbw_getcwd(char *buf, size_t size) +{ + SMBW_INIT(); + + if (*smbw_cwd == '\0') { + return (* smbw_libc.getcwd)(buf, size); + } + + if (buf == NULL) { + if (size == 0) { + size = strlen(smbw_cwd) + 1; + } + buf = malloc(size); + if (buf == NULL) { + errno = ENOMEM; + return NULL; + } + } + + strncpy(buf, smbw_cwd, size); + buf[size-1] = '\0'; + return buf; +} + +/***************************************************** +a wrapper for fchdir() +*******************************************************/ +int smbw_fchdir(int fd_smbw) +{ + int ret; + + SMBW_INIT(); + + if (! smbw_fd(fd_smbw)) { + ret = (* smbw_libc.fchdir)(fd_smbw); + (void) (* smbw_libc.getcwd)(smbw_cwd, PATH_MAX); + return ret; + } + + errno = EACCES; + return -1; +} + +/***************************************************** +open a directory on the server +*******************************************************/ +DIR *smbw_opendir(const char *fname) +{ + int fd_client; + int fd_smbw; + char path[PATH_MAX]; + DIR * dirp; + + SMBW_INIT(); + + if (!fname) { + errno = EINVAL; + return NULL; + } + + fd_smbw = (smbw_libc.open)(SMBW_DUMMY, O_WRONLY, 0200); + if (fd_smbw == -1) { + errno = EMFILE; + return NULL; + } + + smbw_fix_path(fname, path); + fd_client = smbc_opendir(path); + + if (fd_client < 0) { + (* smbw_libc.close)(fd_smbw); + return NULL; + } + + smbw_fd_map[fd_smbw] = fd_client; + smbw_ref(fd_client, SMBW_RCT_Increment); + dirp = (DIR *) &smbw_fd_map[fd_smbw]; + return dirp; +} + +/***************************************************** +read one entry from a directory +*******************************************************/ +struct SMBW_dirent *smbw_readdir(DIR *dirp) +{ + int fd_smbw; + int fd_client; + struct smbc_dirent *dirent_internal; + static struct SMBW_dirent dirent_external; + + fd_smbw = (int *) dirp - smbw_fd_map; + fd_client = smbw_fd_map[fd_smbw]; + + if ((dirent_internal = smbc_readdir(fd_client)) == NULL) { + return NULL; + } + + dirent_external.d_ino = -1; /* not supported */ + dirent_external.d_off = smbc_telldir(fd_client); + dirent_external.d_reclen = sizeof(struct SMBW_dirent); + dirent_external.d_type = dirent_internal->smbc_type; + strncpy(dirent_external.d_name, + dirent_internal->name, + sizeof(dirent_external.d_name) - 1); + strncpy(dirent_external.d_comment, + dirent_internal->comment, + sizeof(dirent_external.d_comment) - 1); + + return &dirent_external; +} + +/***************************************************** +read one entry from a directory in a reentrant fashion +ha! samba is not re-entrant, and neither is the +libsmbclient library +*******************************************************/ +int smbw_readdir_r(DIR *dirp, + struct SMBW_dirent *__restrict entry, + struct SMBW_dirent **__restrict result) +{ + SMBW_dirent *dirent; + + dirent = smbw_readdir(dirp); + + if (dirent != NULL) { + *entry = *dirent; + if (result != NULL) { + *result = entry; + } + return 0; + } + + if (result != NULL) { + *result = NULL; + } + return EBADF; +} + + +/***************************************************** +close a DIR* +*******************************************************/ +int smbw_closedir(DIR *dirp) +{ + int fd_smbw = (int *) dirp - smbw_fd_map; + int fd_client = smbw_fd_map[fd_smbw]; + + (* smbw_libc.close)(fd_smbw); + if (smbw_ref(fd_client, SMBW_RCT_Decrement) > 0) { + return 0; + } + smbw_fd_map[fd_smbw] = -1; + return smbc_closedir(fd_client); +} + +/***************************************************** +seek in a directory +*******************************************************/ +void smbw_seekdir(DIR *dirp, long long offset) +{ + int fd_smbw = (int *) dirp - smbw_fd_map; + int fd_client = smbw_fd_map[fd_smbw]; + + smbc_lseekdir(fd_client, offset); +} + +/***************************************************** +current loc in a directory +*******************************************************/ +long long smbw_telldir(DIR *dirp) +{ + int fd_smbw = (int *) dirp - smbw_fd_map; + int fd_client = smbw_fd_map[fd_smbw]; + + return (long long) smbc_telldir(fd_client); +} diff --git a/examples/libsmbclient/smbwrapper/smbw_stat.c b/examples/libsmbclient/smbwrapper/smbw_stat.c new file mode 100644 index 0000000000..70b3064d22 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/smbw_stat.c @@ -0,0 +1,146 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB wrapper stat functions + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Derrell Lipman 2003-2005 + + 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 "smbw.h" + +static int timezone_diff = -1; + +#define TM_YEAR_BASE 1900 + +/******************************************************************* +yield the difference between *A and *B, in seconds, ignoring leap seconds +********************************************************************/ +static int tm_diff(struct tm *a, struct tm *b) +{ + int ay = a->tm_year + (TM_YEAR_BASE - 1); + int by = b->tm_year + (TM_YEAR_BASE - 1); + int intervening_leap_days = + (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); + int years = ay - by; + int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); + int hours = 24*days + (a->tm_hour - b->tm_hour); + int minutes = 60*hours + (a->tm_min - b->tm_min); + int seconds = 60*minutes + (a->tm_sec - b->tm_sec); + + return seconds; +} + +/******************************************************************* + return the UTC offset in seconds west of UTC, or 0 if it cannot be determined + ******************************************************************/ +static int TimeZone(time_t t) +{ + struct tm *tm = gmtime(&t); + struct tm tm_utc; + if (!tm) + return 0; + tm_utc = *tm; + tm = localtime(&t); + if (!tm) + return 0; + return tm_diff(&tm_utc,tm); + +} + + +static void copy_stat(struct SMBW_stat *external, struct stat *internal) +{ + if (timezone_diff < 0) + { + timezone_diff = TimeZone(time(NULL)); + } + + external->s_dev = internal->st_dev; + external->s_ino = internal->st_ino; + external->s_mode = internal->st_mode; + external->s_nlink = internal->st_nlink; + external->s_uid = internal->st_uid; + external->s_gid = internal->st_gid; + external->s_rdev = internal->st_rdev; + external->s_size = internal->st_size; + external->s_blksize = internal->st_blksize; + external->s_blocks = internal->st_blocks; + external->s_atime = internal->st_atime + timezone_diff; + external->s_mtime = internal->st_mtime + timezone_diff; + external->s_ctime = internal->st_ctime + timezone_diff; +} + + +/***************************************************** +a wrapper for fstat() +*******************************************************/ +int smbw_fstat(int fd_smbw, struct SMBW_stat *st) +{ + int fd_client = smbw_fd_map[fd_smbw]; + struct stat statbuf; + + if (smbc_fstat(fd_client, &statbuf) < 0) { + return -1; + } + + copy_stat(st, &statbuf); + + return 0; +} + + +/***************************************************** +a wrapper for stat() +*******************************************************/ +int smbw_stat(const char *fname, struct SMBW_stat *st) +{ + int simulate; + char *p; + char path[PATH_MAX]; + struct stat statbuf; + + SMBW_INIT(); + + smbw_fix_path(fname, path); + + p = path + 6; /* look just past smb:// */ + simulate = (strchr(p, '/') == NULL); + + /* special case for full-network scan, workgroups, and servers */ + if (simulate) { + statbuf.st_dev = 0; + statbuf.st_ino = 0; + statbuf.st_mode = 0040777; + statbuf.st_nlink = 1; + statbuf.st_uid = 0; + statbuf.st_gid = 0; + statbuf.st_rdev = 0; + statbuf.st_size = 0; + statbuf.st_blksize = 1024; + statbuf.st_blocks = 1; + statbuf.st_atime = 0; /* beginning of epoch */ + statbuf.st_mtime = 0; /* beginning of epoch */ + statbuf.st_ctime = 0; /* beginning of epoch */ + + } else if (smbc_stat(path, &statbuf) < 0) { + return -1; + } + + copy_stat(st, &statbuf); + + return 0; +} diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c new file mode 100644 index 0000000000..71d6f203ad --- /dev/null +++ b/examples/libsmbclient/smbwrapper/wrapper.c @@ -0,0 +1,1729 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB wrapper functions + Copyright (C) Andrew Tridgell 1998 + Copyright (C) Derrell Lipman 2002-2005 + + 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. +*/ + +/* + * This is a rewrite of the original wrapped.c file, using libdl to obtain + * pointers into the C library rather than attempting to find undocumented + * functions in the C library to call for native file access. The problem + * with the original implementation's paradigm is that samba manipulates + * defines such that it gets the sizes of structures that it wants + * (e.g. mapping 32-bit functions to 64-bit functions with their associated + * 64-bit structure fields), but programs run under smbsh or using + * smbwrapper.so were not necessarily compiled with the same flags. As an + * example of the problem, a program calling stat() passes a pointer to a + * "struct stat" but the fields in that structure are different in samba than + * they are in the calling program if the calling program was not compiled to + * force stat() to be mapped to stat64(). + * + * In this version, we provide an interface to each of the native functions, + * not just the ones that samba is compiled to map to. We obtain the function + * pointers from the C library using dlsym(), and for native file operations, + * directly call the same function that the calling application was + * requesting. Since the size of the calling application's structures vary + * depending on what function was called, we use our own internal structures + * for passing information to/from the SMB equivalent functions, and map them + * back to the native structures before returning the result to the caller. + * + * This implementation was completed 25 December 2002. + * Derrell Lipman + */ + +/* We do not want auto munging of 32->64 bit names in this file (only) */ +#undef _FILE_OFFSET_BITS +#undef _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "libsmbclient.h" +#include "wrapper.h" + +/* + * Debug bits: + * 0x0 = none + * 0x1 = display symbol definitions not found in C library + * 0x2 = show wrapper functions being called + * 0x4 = log to file SMBW_DEBUG_FILE instead of stderr + */ +#define SMBW_DEBUG 0x0 +#define SMBW_DEBUG_FILE "/tmp/smbw.log" + +int smbw_debug = 0; + +#if SMBW_DEBUG & 0x2 +static int debugFd = 2; +#endif + +#ifndef ENOTSUP +#define ENOTSUP EOPNOTSUPP +#endif + +/* + * None of the methods of having the initialization function called + * automatically upon shared library startup are effective in all situations. + * We provide the "-init" parameter to the linker which is effective most of + * the time, but fails for applications that provide their own shared + * libraries with _init() functions (e.g. ps). We can't use "-z initfirst" + * because the environment isn't yet set up at that point, so we can't find + * our shared memory identifier (see shared.c). We therefore must resort to + * this tried-and-true method of keeping an "initialized" flag. We check it + * prior to calling the initialize() function to save a function call (a slow + * operation on x86). + */ +#if SMBW_DEBUG & 0x2 +# define check_init(buf) \ + do { \ + int saved_errno = errno; \ + if (! initialized) initialize(); \ + (* smbw_libc.write)(debugFd, "["buf"]", sizeof(buf)+1); \ + errno = saved_errno; \ + } while (0); +#else +# define check_init(buf) \ + do { \ + if (! initialized) smbw_initialize(); \ + } while (0); +#endif + +static void initialize(void); + +static int initialized = 0; + +SMBW_libc_pointers smbw_libc; + +/* + * A public entry point used by the "-init" option to the linker. + */ +void smbw_initialize(void) +{ + initialize(); +} + +static void initialize(void) +{ + void *lib = NULL; + int saved_errno; +#if SMBW_DEBUG & 0x1 + char *error; +#endif + + saved_errno = errno; + + if (initialized) { + errno = saved_errno; + return; + } + initialized = 1; + + if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { + exit(1); + } + +#if SMBW_DEBUG & 0x1 +# define GETSYM(symname, symstring) \ + if ((smbw_libc.symname = dlsym(lib, symstring)) == NULL) { \ + if (smbw_libc.write != NULL && \ + (error = dlerror()) != NULL) { \ + (* smbw_libc.write)(1, error, strlen(error)); \ + (* smbw_libc.write)(1, "\n", 1); \ + } \ + } +#else +# define GETSYM(symname, symstring) \ + smbw_libc.symname = dlsym(lib, symstring); +#endif + + /* + * Get pointers to each of the symbols we'll need, from the C library + * + * Some of these symbols may not be found in the C library. That's + * fine. We declare all of them here, and if the C library supports + * them, they may be called so we have the wrappers for them. If the + * C library doesn't support them, then the wrapper function will + * never be called, and the null pointer will never be dereferenced. + */ + do { + GETSYM(write, "write"); /* first, to allow debugging */ + GETSYM(open, "open"); + GETSYM(_open, "_open"); + GETSYM(__open, "__open"); + GETSYM(open64, "open64"); + GETSYM(_open64, "_open64"); + GETSYM(__open64, "__open64"); + GETSYM(pread, "pread"); + GETSYM(pread64, "pread64"); + GETSYM(pwrite, "pwrite"); + GETSYM(pwrite64, "pwrite64"); + GETSYM(close, "close"); + GETSYM(__close, "__close"); + GETSYM(_close, "_close"); + GETSYM(fcntl, "fcntl"); + GETSYM(__fcntl, "__fcntl"); + GETSYM(_fcntl, "_fcntl"); + GETSYM(getdents, "getdents"); + GETSYM(__getdents, "__getdents"); + GETSYM(_getdents, "_getdents"); + GETSYM(getdents64, "getdents64"); + GETSYM(lseek, "lseek"); + GETSYM(__lseek, "__lseek"); + GETSYM(_lseek, "_lseek"); + GETSYM(lseek64, "lseek64"); + GETSYM(__lseek64, "__lseek64"); + GETSYM(_lseek64, "_lseek64"); + GETSYM(read, "read"); + GETSYM(__read, "__read"); + GETSYM(_read, "_read"); + GETSYM(__write, "__write"); + GETSYM(_write, "_write"); + GETSYM(access, "access"); + GETSYM(chmod, "chmod"); + GETSYM(fchmod, "fchmod"); + GETSYM(chown, "chown"); + GETSYM(fchown, "fchown"); + GETSYM(__xstat, "__xstat"); + GETSYM(getcwd, "getcwd"); + GETSYM(mkdir, "mkdir"); + GETSYM(__fxstat, "__fxstat"); + GETSYM(__lxstat, "__lxstat"); + GETSYM(stat, "stat"); + GETSYM(lstat, "lstat"); + GETSYM(fstat, "fstat"); + GETSYM(unlink, "unlink"); + GETSYM(utime, "utime"); + GETSYM(utimes, "utimes"); + GETSYM(readlink, "readlink"); + GETSYM(rename, "rename"); + GETSYM(rmdir, "rmdir"); + GETSYM(symlink, "symlink"); + GETSYM(dup, "dup"); + GETSYM(dup2, "dup2"); + GETSYM(opendir, "opendir"); + GETSYM(readdir, "readdir"); + GETSYM(closedir, "closedir"); + GETSYM(telldir, "telldir"); + GETSYM(seekdir, "seekdir"); + GETSYM(creat, "creat"); + GETSYM(creat64, "creat64"); + GETSYM(__xstat64, "__xstat64"); + GETSYM(stat64, "stat64"); + GETSYM(__fxstat64, "__fxstat64"); + GETSYM(fstat64, "fstat64"); + GETSYM(__lxstat64, "__lxstat64"); + GETSYM(lstat64, "lstat64"); + GETSYM(_llseek, "_llseek"); + GETSYM(readdir64, "readdir64"); + GETSYM(readdir_r, "readdir_r"); + GETSYM(readdir64_r, "readdir64_r"); + GETSYM(setxattr, "setxattr"); + GETSYM(lsetxattr, "lsetxattr"); + GETSYM(fsetxattr, "fsetxattr"); + GETSYM(getxattr, "getxattr"); + GETSYM(lgetxattr, "lgetxattr"); + GETSYM(fgetxattr, "fgetxattr"); + GETSYM(removexattr, "removexattr"); + GETSYM(lremovexattr, "lremovexattr"); + GETSYM(fremovexattr, "fremovexattr"); + GETSYM(listxattr, "listxattr"); + GETSYM(llistxattr, "llistxattr"); + GETSYM(flistxattr, "flistxattr"); + GETSYM(chdir, "chdir"); + GETSYM(fchdir, "fchdir"); + GETSYM(fork, "fork"); + GETSYM(select, "select"); + GETSYM(_select, "_select"); + GETSYM(__select, "__select"); + } while (0); + + dlclose(lib); + + if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { + exit(1); + } + +#if SMBW_DEBUG & 4 + { + if ((debugFd = + open(SMBW_DEBUG_FILE, O_WRONLY | O_CREAT | O_APPEND)) < 0) + { +# define SMBW_MESSAGE "Could not create " SMBW_DEBUG_FILE "\n" + (* smbw_libc.write)(1, SMBW_MESSAGE, sizeof(SMBW_MESSAGE)); +# undef SMBW_MESSAGE + exit(1); + } + } +#endif + + errno = saved_errno; +} + +/** + ** Static Functions + **/ + +static void stat_convert(struct SMBW_stat *src, struct stat *dest) +{ + memset(dest, '\0', sizeof(*dest)); + dest->st_size = src->s_size; + dest->st_mode = src->s_mode; + dest->st_ino = src->s_ino; + dest->st_dev = src->s_dev; + dest->st_rdev = src->s_rdev; + dest->st_nlink = src->s_nlink; + dest->st_uid = src->s_uid; + dest->st_gid = src->s_gid; + dest->st_atime = src->s_atime; + dest->st_mtime = src->s_mtime; + dest->st_ctime = src->s_ctime; + dest->st_blksize = src->s_blksize; + dest->st_blocks = src->s_blocks; +} + +static void stat64_convert(struct SMBW_stat *src, struct stat64 *dest) +{ + memset(dest, '\0', sizeof(*dest)); + dest->st_size = src->s_size; + dest->st_mode = src->s_mode; + dest->st_ino = src->s_ino; + dest->st_dev = src->s_dev; + dest->st_rdev = src->s_rdev; + dest->st_nlink = src->s_nlink; + dest->st_uid = src->s_uid; + dest->st_gid = src->s_gid; + dest->st_atime = src->s_atime; + dest->st_mtime = src->s_mtime; + dest->st_ctime = src->s_ctime; + dest->st_blksize = src->s_blksize; + dest->st_blocks = src->s_blocks; +} + +static void dirent_convert(struct SMBW_dirent *src, struct dirent *dest) +{ + char *p; + + memset(dest, '\0', sizeof(*dest)); + dest->d_ino = src->d_ino; + dest->d_off = src->d_off; + + switch(src->d_type) + { + case SMBC_WORKGROUP: + case SMBC_SERVER: + case SMBC_FILE_SHARE: + case SMBC_DIR: + dest->d_type = DT_DIR; + break; + + case SMBC_FILE: + dest->d_type = DT_REG; + break; + + case SMBC_PRINTER_SHARE: + dest->d_type = DT_CHR; + break; + + case SMBC_COMMS_SHARE: + dest->d_type = DT_SOCK; + break; + + case SMBC_IPC_SHARE: + dest->d_type = DT_FIFO; + break; + + case SMBC_LINK: + dest->d_type = DT_LNK; + break; + } + + dest->d_reclen = src->d_reclen; + strncpy(dest->d_name, src->d_name, sizeof(dest->d_name)); + p = dest->d_name + strlen(dest->d_name) + 1; + strncpy(p, src->d_comment, sizeof(dest->d_name) - (p - dest->d_name)); +} + +static void dirent64_convert(struct SMBW_dirent *src, struct dirent64 *dest) +{ + char *p; + + memset(dest, '\0', sizeof(*dest)); + dest->d_ino = src->d_ino; + dest->d_off = src->d_off; + + switch(src->d_type) + { + case SMBC_WORKGROUP: + case SMBC_SERVER: + case SMBC_FILE_SHARE: + case SMBC_DIR: + dest->d_type = DT_DIR; + break; + + case SMBC_FILE: + dest->d_type = DT_REG; + break; + + case SMBC_PRINTER_SHARE: + dest->d_type = DT_CHR; + break; + + case SMBC_COMMS_SHARE: + dest->d_type = DT_SOCK; + break; + + case SMBC_IPC_SHARE: + dest->d_type = DT_FIFO; + break; + + case SMBC_LINK: + dest->d_type = DT_LNK; + break; + } + + dest->d_reclen = src->d_reclen; + strncpy(dest->d_name, src->d_name, sizeof(dest->d_name)); + p = dest->d_name + strlen(dest->d_name) + 1; + strncpy(p, src->d_comment, sizeof(dest->d_name) - (p - dest->d_name)); +} + +static int openx(char *name, int flags, mode_t mode, int (* f)(char *, int, mode_t)) +{ + if (smbw_path(name)) { + return smbw_open(name, flags, mode); + } + + return (* f)(name, flags, mode); +} + +static int closex(int fd, int (* f)(int fd)) +{ + if (smbw_fd(fd)) { + return smbw_close(fd); + } + + return (* f)(fd); +} + +static int fcntlx(int fd, int cmd, long arg, int (* f)(int, int, long)) +{ + if (smbw_fd(fd)) { + return smbw_fcntl(fd, cmd, arg); + } + + return (* f)(fd, cmd, arg); +} + +static int getdentsx(int fd, struct dirent *external, unsigned int count, int (* f)(int, struct dirent *, unsigned int)) +{ + if (smbw_fd(fd)) { + int i; + int internal_count; + struct SMBW_dirent *internal; + int ret; + int n; + + /* + * LIMITATION: If they pass a count which is not a multiple of + * the size of struct dirent, they will not get a partial + * structure; we ignore the excess count. + */ + n = (count / sizeof(struct dirent)); + + internal_count = sizeof(struct SMBW_dirent) * n; + internal = malloc(internal_count); + if (internal == NULL) { + errno = ENOMEM; + return -1; + } + ret = smbw_getdents(fd, internal, internal_count); + if (ret <= 0) + return ret; + + ret = sizeof(struct dirent) * n; + + for (i = 0; i < n; i++) + dirent_convert(&internal[i], &external[i]); + + return ret; + } + + return (* f)(fd, external, count); +} + +static off_t lseekx(int fd, + off_t offset, + int whence, + off_t (* f)(int, off_t, int)) +{ + off_t ret; + + /* + * We have left the definitions of the smbw_ functions undefined, + * because types such as off_t can differ in meaning betweent his + * function and smbw.c et al. Functions that return other than an + * integer value, however, MUST have their return value defined. + */ + off64_t smbw_lseek(); + + if (smbw_fd(fd)) { + return (off_t) smbw_lseek(fd, offset, whence); + } + + ret = (* f)(fd, offset, whence); + if (smbw_debug) + { + printf("lseekx(%d, 0x%llx) returned 0x%llx\n", + fd, + (unsigned long long) offset, + (unsigned long long) ret); + } + return ret; +} + +static off64_t lseek64x(int fd, + off64_t offset, + int whence, + off64_t (* f)(int, off64_t, int)) +{ + off64_t ret; + + /* + * We have left the definitions of the smbw_ functions undefined, + * because types such as off_t can differ in meaning betweent his + * function and smbw.c et al. Functions that return other than an + * integer value, however, MUST have their return value defined. + */ + off64_t smbw_lseek(); + + if (smbw_fd(fd)) + ret = smbw_lseek(fd, offset, whence); + else + ret = (* f)(fd, offset, whence); + if (smbw_debug) + { + printf("lseek64x(%d, 0x%llx) returned 0x%llx\n", + fd, + (unsigned long long) offset, + (unsigned long long) ret); + } + return ret; +} + +static ssize_t readx(int fd, void *buf, size_t count, ssize_t (* f)(int, void *, size_t)) +{ + if (smbw_fd(fd)) { + return smbw_read(fd, buf, count); + } + + return (* f)(fd, buf, count); +} + +static ssize_t writex(int fd, void *buf, size_t count, ssize_t (* f)(int, void *, size_t)) +{ + if (smbw_fd(fd)) { + return smbw_write(fd, buf, count); + } + + return (* f)(fd, buf, count); +} + + +/** + ** Wrapper Functions + **/ + +int open(__const char *name, int flags, ...) +{ + va_list ap; + mode_t mode; + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + + check_init("open"); + + return openx((char *) name, flags, mode, smbw_libc.open); +} + +int _open(char *name, int flags, mode_t mode) +{ + check_init("open"); + + return openx(name, flags, mode, smbw_libc._open); +} + +int __open(char *name, int flags, mode_t mode) +{ + check_init("open"); + + return openx(name, flags, mode, smbw_libc.__open); +} + +int open64 (__const char *name, int flags, ...) +{ + va_list ap; + mode_t mode; + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + + check_init("open64"); + return openx((char *) name, flags, mode, smbw_libc.open64); +} + +int _open64(char *name, int flags, mode_t mode) +{ + check_init("_open64"); + return openx(name, flags, mode, smbw_libc._open64); +} + +int __open64(char *name, int flags, mode_t mode) +{ + check_init("__open64"); + return openx(name, flags, mode, smbw_libc.__open64); +} + +ssize_t pread(int fd, void *buf, size_t size, off_t ofs) +{ + check_init("pread"); + + if (smbw_fd(fd)) { + return smbw_pread(fd, buf, size, ofs); + } + + return (* smbw_libc.pread)(fd, buf, size, ofs); +} + +ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs) +{ + check_init("pread64"); + + if (smbw_fd(fd)) { + return smbw_pread(fd, buf, size, (off_t) ofs); + } + + return (* smbw_libc.pread64)(fd, buf, size, ofs); +} + +ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) +{ + check_init("pwrite"); + + if (smbw_fd(fd)) { + return smbw_pwrite(fd, (void *) buf, size, ofs); + } + + return (* smbw_libc.pwrite)(fd, (void *) buf, size, ofs); +} + +ssize_t pwrite64(int fd, const void *buf, size_t size, off64_t ofs) +{ + check_init("pwrite64"); + + if (smbw_fd(fd)) { + return smbw_pwrite(fd, (void *) buf, size, (off_t) ofs); + } + + return (* smbw_libc.pwrite64)(fd, (void *) buf, size, ofs); +} + +int chdir(const char *name) +{ + check_init("chdir"); + return smbw_chdir((char *) name);; +} + +int __chdir(char *name) +{ + check_init("__chdir"); + return smbw_chdir(name); +} + +int _chdir(char *name) +{ + check_init("_chdir"); + return smbw_chdir(name); +} + +int close(int fd) +{ + check_init("close"); + return closex(fd, smbw_libc.close); +} + +int __close(int fd) +{ + check_init("__close"); + return closex(fd, smbw_libc.__close); +} + +int _close(int fd) +{ + check_init("_close"); + return closex(fd, smbw_libc._close); +} + +int fchdir(int fd) +{ + check_init("fchdir"); + return smbw_fchdir(fd); +} + +int __fchdir(int fd) +{ + check_init("__fchdir"); + return fchdir(fd); +} + +int _fchdir(int fd) +{ + check_init("_fchdir"); + return fchdir(fd); +} + +int fcntl (int fd, int cmd, ...) +{ + va_list ap; + long arg; + + va_start(ap, cmd); + arg = va_arg(ap, long); + va_end(ap); + + check_init("fcntl"); + return fcntlx(fd, cmd, arg, smbw_libc.fcntl); +} + +int __fcntl(int fd, int cmd, ...) +{ + va_list ap; + long arg; + + va_start(ap, cmd); + arg = va_arg(ap, long); + va_end(ap); + + check_init("__fcntl"); + return fcntlx(fd, cmd, arg, smbw_libc.__fcntl); +} + +int _fcntl(int fd, int cmd, ...) +{ + va_list ap; + long arg; + + va_start(ap, cmd); + arg = va_arg(ap, long); + va_end(ap); + + check_init("_fcntl"); + return fcntlx(fd, cmd, arg, smbw_libc._fcntl); +} + +int getdents(int fd, struct dirent *dirp, unsigned int count) +{ + check_init("getdents"); + return getdentsx(fd, dirp, count, smbw_libc.getdents); +} + +int __getdents(int fd, struct dirent *dirp, unsigned int count) +{ + check_init("__getdents"); + return getdentsx(fd, dirp, count, smbw_libc.__getdents); +} + +int _getdents(int fd, struct dirent *dirp, unsigned int count) +{ + check_init("_getdents"); + return getdentsx(fd, dirp, count, smbw_libc._getdents); +} + +int getdents64(int fd, struct dirent64 *external, unsigned int count) +{ + check_init("getdents64"); + if (smbw_fd(fd)) { + int i; + struct SMBW_dirent *internal; + int ret; + int n; + + /* + * LIMITATION: If they pass a count which is not a multiple of + * the size of struct dirent, they will not get a partial + * structure; we ignore the excess count. + */ + n = (count / sizeof(struct dirent64)); + + internal = malloc(sizeof(struct SMBW_dirent) * n); + if (internal == NULL) { + errno = ENOMEM; + return -1; + } + ret = smbw_getdents(fd, internal, count); + if (ret <= 0) + return ret; + + ret = sizeof(struct dirent) * count; + + for (i = 0; count; i++, count--) + dirent64_convert(&internal[i], &external[i]); + + return ret; + } + + return (* smbw_libc.getdents64)(fd, external, count); +} + +off_t lseek(int fd, off_t offset, int whence) +{ + off_t ret; + check_init("lseek"); + ret = lseekx(fd, offset, whence, smbw_libc.lseek); + if (smbw_debug) + { + printf("lseek(%d, 0x%llx) returned 0x%llx\n", + fd, + (unsigned long long) offset, + (unsigned long long) ret); + } + return ret; +} + +off_t __lseek(int fd, off_t offset, int whence) +{ + off_t ret; + check_init("__lseek"); + ret = lseekx(fd, offset, whence, smbw_libc.__lseek); + if (smbw_debug) + { + printf("__lseek(%d, 0x%llx) returned 0x%llx\n", + fd, + (unsigned long long) offset, + (unsigned long long) ret); + } + return ret; +} + +off_t _lseek(int fd, off_t offset, int whence) +{ + off_t ret; + check_init("_lseek"); + ret = lseekx(fd, offset, whence, smbw_libc._lseek); + if (smbw_debug) + { + printf("_lseek(%d, 0x%llx) returned 0x%llx\n", + fd, + (unsigned long long) offset, + (unsigned long long) ret); + } + return ret; +} + +off64_t lseek64(int fd, off64_t offset, int whence) +{ + off64_t ret; + check_init("lseek64"); + ret = lseek64x(fd, offset, whence, smbw_libc.lseek64); + if (smbw_debug) + { + printf("lseek64(%d, 0x%llx) returned 0x%llx\n", + fd, + (unsigned long long) offset, + (unsigned long long) ret); + } + return ret; +} + +off64_t __lseek64(int fd, off64_t offset, int whence) +{ + check_init("__lseek64"); + return lseek64x(fd, offset, whence, smbw_libc.__lseek64); +} + +off64_t _lseek64(int fd, off64_t offset, int whence) +{ + off64_t ret; + check_init("_lseek64"); + ret = lseek64x(fd, offset, whence, smbw_libc._lseek64); + if (smbw_debug) + { + printf("_lseek64(%d, 0x%llx) returned 0x%llx\n", + fd, + (unsigned long long) offset, + (unsigned long long) ret); + } + return ret; +} + +ssize_t read(int fd, void *buf, size_t count) +{ + check_init("read"); + return readx(fd, buf, count, smbw_libc.read); +} + +ssize_t __read(int fd, void *buf, size_t count) +{ + check_init("__read"); + return readx(fd, buf, count, smbw_libc.__read); +} + +ssize_t _read(int fd, void *buf, size_t count) +{ + check_init("_read"); + return readx(fd, buf, count, smbw_libc._read); +} + +ssize_t write(int fd, const void *buf, size_t count) +{ + check_init("write"); + return writex(fd, (void *) buf, count, smbw_libc.write); +} + +ssize_t __write(int fd, const void *buf, size_t count) +{ + check_init("__write"); + return writex(fd, (void *) buf, count, smbw_libc.__write); +} + +ssize_t _write(int fd, const void *buf, size_t count) +{ + check_init("_write"); + return writex(fd, (void *) buf, count, smbw_libc._write); +} + +int access(const char *name, int mode) +{ + check_init("access"); + + if (smbw_path((char *) name)) { + return smbw_access((char *) name, mode); + } + + return (* smbw_libc.access)((char *) name, mode); +} + +int chmod(const char *name, mode_t mode) +{ + check_init("chmod"); + + if (smbw_path((char *) name)) { + return smbw_chmod((char *) name, mode); + } + + return (* smbw_libc.chmod)((char *) name, mode); +} + +int fchmod(int fd, mode_t mode) +{ + check_init("fchmod"); + + if (smbw_fd(fd)) { + /* Not yet implemented in libsmbclient */ + return ENOTSUP; + } + + return (* smbw_libc.fchmod)(fd, mode); +} + +int chown(const char *name, uid_t owner, gid_t group) +{ + check_init("chown"); + + if (smbw_path((char *) name)) { + return smbw_chown((char *) name, owner, group); + } + + return (* smbw_libc.chown)((char *) name, owner, group); +} + +int fchown(int fd, uid_t owner, gid_t group) +{ + check_init("fchown"); + + if (smbw_fd(fd)) { + /* Not yet implemented in libsmbclient */ + return ENOTSUP; + } + + return (* smbw_libc.fchown)(fd, owner, group); +} + +char *getcwd(char *buf, size_t size) +{ + check_init("getcwd"); + return (char *)smbw_getcwd(buf, size); +} + +int mkdir(const char *name, mode_t mode) +{ + check_init("mkdir"); + + if (smbw_path((char *) name)) { + return smbw_mkdir((char *) name, mode); + } + + return (* smbw_libc.mkdir)((char *) name, mode); +} + +int __fxstat(int vers, int fd, struct stat *st) +{ + check_init("__fxstat"); + + if (smbw_fd(fd)) { + struct SMBW_stat statbuf; + int ret = smbw_fstat(fd, &statbuf); + stat_convert(&statbuf, st); + return ret; + } + + return (* smbw_libc.__fxstat)(vers, fd, st); +} + +int __xstat(int vers, const char *name, struct stat *st) +{ + check_init("__xstat"); + + if (smbw_path((char *) name)) { + struct SMBW_stat statbuf; + int ret = smbw_stat((char *) name, &statbuf); + stat_convert(&statbuf, st); + return ret; + } + + return (* smbw_libc.__xstat)(vers, (char *) name, st); +} + +int __lxstat(int vers, const char *name, struct stat *st) +{ + check_init("__lxstat"); + + if (smbw_path((char *) name)) { + struct SMBW_stat statbuf; + int ret = smbw_stat((char *) name, &statbuf); + stat_convert(&statbuf, st); + return ret; + } + + return (* smbw_libc.__lxstat)(vers, (char *) name, st); +} + +int stat(const char *name, struct stat *st) +{ + check_init("stat"); + + if (smbw_path((char *) name)) { + struct SMBW_stat statbuf; + int ret = smbw_stat((char *) name, &statbuf); + stat_convert(&statbuf, st); + return ret; + } + + return (* smbw_libc.stat)((char *) name, st); +} + +int lstat(const char *name, struct stat *st) +{ + check_init("lstat"); + + if (smbw_path((char *) name)) { + struct SMBW_stat statbuf; + int ret = smbw_stat((char *) name, &statbuf); + stat_convert(&statbuf, st); + return ret; + } + + return (* smbw_libc.lstat)((char *) name, st); +} + +int fstat(int fd, struct stat *st) +{ + check_init("fstat"); + + if (smbw_fd(fd)) { + struct SMBW_stat statbuf; + int ret = smbw_fstat(fd, &statbuf); + stat_convert(&statbuf, st); + return ret; + } + + return (* smbw_libc.fstat)(fd, st); +} + +int unlink(const char *name) +{ + check_init("unlink"); + + if (smbw_path((char *) name)) { + return smbw_unlink((char *) name); + } + + return (* smbw_libc.unlink)((char *) name); +} + +int utime(const char *name, const struct utimbuf *tvp) +{ + check_init("utime"); + + if (smbw_path(name)) { + return smbw_utime(name, (struct utimbuf *) tvp); + } + + return (* smbw_libc.utime)((char *) name, (struct utimbuf *) tvp); +} + +int utimes(const char *name, const struct timeval *tvp) +{ + check_init("utimes"); + + if (smbw_path(name)) { + return smbw_utimes(name, (struct timeval *) tvp); + } + + return (* smbw_libc.utimes)((char *) name, (struct timeval *) tvp); +} + +int readlink(const char *path, char *buf, size_t bufsize) +{ + check_init("readlink"); + + if (smbw_path((char *) path)) { + return smbw_readlink(path, (char *) buf, bufsize); + } + + return (* smbw_libc.readlink)((char *) path, buf, bufsize); +} + +int rename(const char *oldname, const char *newname) +{ + int p1, p2; + + check_init("rename"); + + p1 = smbw_path((char *) oldname); + p2 = smbw_path((char *) newname); + if (p1 ^ p2) { + /* can't cross filesystem boundaries */ + errno = EXDEV; + return -1; + } + if (p1 && p2) { + return smbw_rename((char *) oldname, (char *) newname); + } + + return (* smbw_libc.rename)((char *) oldname, (char *) newname); +} + +int rmdir(const char *name) +{ + check_init("rmdir"); + + if (smbw_path((char *) name)) { + return smbw_rmdir((char *) name); + } + + return (* smbw_libc.rmdir)((char *) name); +} + +int symlink(const char *topath, const char *frompath) +{ + int p1, p2; + + check_init("symlink"); + + p1 = smbw_path((char *) topath); + p2 = smbw_path((char *) frompath); + if (p1 || p2) { + /* can't handle symlinks */ + errno = EPERM; + return -1; + } + + return (* smbw_libc.symlink)((char *) topath, (char *) frompath); +} + +int dup(int fd) +{ + check_init("dup"); + + if (smbw_fd(fd)) { + return smbw_dup(fd); + } + + return (* smbw_libc.dup)(fd); +} + +int dup2(int oldfd, int newfd) +{ + check_init("dup2"); + + if (smbw_fd(newfd)) { + (* smbw_libc.close)(newfd); + } + + if (smbw_fd(oldfd)) { + return smbw_dup2(oldfd, newfd); + } + + return (* smbw_libc.dup2)(oldfd, newfd); +} + + +DIR *opendir(const char *name) +{ + check_init("opendir"); + + if (smbw_path((char *) name)) { + return (void *)smbw_opendir((char *) name); + } + + return (* smbw_libc.opendir)((char *) name); +} + +struct dirent *readdir(DIR *dir) +{ + check_init("readdir"); + + if (smbw_dirp(dir)) { + static struct dirent external; + struct SMBW_dirent * internal = (void *)smbw_readdir(dir); + if (internal != NULL) { + dirent_convert(internal, &external); + return &external; + } + return NULL; + } + return (* smbw_libc.readdir)(dir); +} + +int closedir(DIR *dir) +{ + check_init("closedir"); + + if (smbw_dirp(dir)) { + return smbw_closedir(dir); + } + + return (* smbw_libc.closedir)(dir); +} + +long telldir(DIR *dir) +{ + check_init("telldir"); + + if (smbw_dirp(dir)) { + return (long) smbw_telldir(dir); + } + + return (* smbw_libc.telldir)(dir); +} + +void seekdir(DIR *dir, long offset) +{ + check_init("seekdir"); + + if (smbw_dirp(dir)) { + smbw_seekdir(dir, (long long) offset); + return; + } + + (* smbw_libc.seekdir)(dir, offset); +} + +int creat(const char *path, mode_t mode) +{ + extern int creat_bits; + + check_init("creat"); + return openx((char *) path, creat_bits, mode, smbw_libc.open); +} + +int creat64(const char *path, mode_t mode) +{ + extern int creat_bits; + + check_init("creat64"); + return openx((char *) path, creat_bits, mode, smbw_libc.open64); +} + +int __xstat64 (int ver, const char *name, struct stat64 *st64) +{ + check_init("__xstat64"); + + if (smbw_path((char *) name)) { + struct SMBW_stat statbuf; + int ret = smbw_stat((char *) name, &statbuf); + stat64_convert(&statbuf, st64); + return ret; + } + + return (* smbw_libc.__xstat64)(ver, (char *) name, st64); +} + +int stat64(const char *name, struct stat64 *st64) +{ + check_init("stat64"); + + if (smbw_path((char *) name)) { + struct SMBW_stat statbuf; + int ret = smbw_stat((char *) name, &statbuf); + stat64_convert(&statbuf, st64); + return ret; + } + + return (* smbw_libc.stat64)((char *) name, st64); +} + +int __fxstat64(int ver, int fd, struct stat64 *st64) +{ + check_init("__fxstat64"); + + if (smbw_fd(fd)) { + struct SMBW_stat statbuf; + int ret = smbw_fstat(fd, &statbuf); + stat64_convert(&statbuf, st64); + return ret; + } + + return (* smbw_libc.__fxstat64)(ver, fd, st64); +} + +int fstat64(int fd, struct stat64 *st64) +{ + check_init("fstat64"); + + if (smbw_fd(fd)) { + struct SMBW_stat statbuf; + int ret = smbw_fstat(fd, &statbuf); + stat64_convert(&statbuf, st64); + return ret; + } + + return (* smbw_libc.fstat64)(fd, st64); +} + +int __lxstat64(int ver, const char *name, struct stat64 *st64) +{ + check_init("__lxstat64"); + + if (smbw_path((char *) name)) { + struct SMBW_stat statbuf; + int ret = smbw_stat(name, &statbuf); + stat64_convert(&statbuf, st64); + return ret; + } + + return (* smbw_libc.__lxstat64)(ver, (char *) name, st64); +} + +int lstat64(const char *name, struct stat64 *st64) +{ + check_init("lstat64"); + + if (smbw_path((char *) name)) { + struct SMBW_stat statbuf; + int ret = smbw_stat((char *) name, &statbuf); + stat64_convert(&statbuf, st64); + return ret; + } + + return (* smbw_libc.lstat64)((char *) name, st64); +} + +int _llseek(unsigned int fd, unsigned long offset_high, unsigned long offset_low, loff_t *result, unsigned int whence) +{ + check_init("_llseek"); + + if (smbw_fd(fd)) { + *result = lseek(fd, offset_low, whence); + return (*result < 0 ? -1 : 0); + } + + return (* smbw_libc._llseek)(fd, offset_high, offset_low, result, whence); +} + +struct dirent64 *readdir64(DIR *dir) +{ + check_init("readdir64"); + + if (smbw_dirp(dir)) { + static struct dirent64 external; + struct SMBW_dirent * internal = (void *)smbw_readdir(dir); + if (internal != NULL) { + dirent64_convert(internal, &external); + return &external; + } + return NULL; + } + + return (* smbw_libc.readdir64)(dir); +} + +int readdir_r(DIR *dir, struct dirent *external, struct dirent **result) +{ + check_init("readdir_r"); + + if (smbw_dirp(dir)) { + struct SMBW_dirent internal; + int ret = smbw_readdir_r(dir, &internal, NULL); + if (ret == 0) { + dirent_convert(&internal, external); + *result = external; + } + return ret; + } + + return (* smbw_libc.readdir_r)(dir, external, result); +} + +int readdir64_r(DIR *dir, struct dirent64 *external, struct dirent64 **result) +{ + check_init("readdir64_r"); + + if (smbw_dirp(dir)) { + struct SMBW_dirent internal; + int ret = smbw_readdir_r(dir, &internal, NULL); + if (ret == 0) { + dirent64_convert(&internal, external); + *result = external; + } + return ret; + } + + return (* smbw_libc.readdir64_r)(dir, external, result); +} + +int fork(void) +{ + check_init("fork"); + return smbw_fork(); +} + +int setxattr(const char *fname, + const char *name, + const void *value, + size_t size, + int flags) +{ + if (smbw_path(fname)) { + return smbw_setxattr(fname, name, value, size, flags); + } + + return (* smbw_libc.setxattr)(fname, name, value, size, flags); +} + +int lsetxattr(const char *fname, + const char *name, + const void *value, + size_t size, + int flags) +{ + if (smbw_path(fname)) { + return smbw_lsetxattr(fname, name, value, size, flags); + } + + return (* smbw_libc.lsetxattr)(fname, name, value, size, flags); +} + +int fsetxattr(int fd, + const char *name, + const void *value, + size_t size, + int flags) +{ + if (smbw_fd(fd)) { + return smbw_fsetxattr(fd, name, value, size, flags); + } + + return (* smbw_libc.fsetxattr)(fd, name, value, size, flags); +} + +int getxattr(const char *fname, + const char *name, + const void *value, + size_t size) +{ + if (smbw_path(fname)) { + return smbw_getxattr(fname, name, value, size); + } + + return (* smbw_libc.getxattr)(fname, name, value, size); +} + +int lgetxattr(const char *fname, + const char *name, + const void *value, + size_t size) +{ + if (smbw_path(fname)) { + return smbw_lgetxattr(fname, name, value, size); + } + + return (* smbw_libc.lgetxattr)(fname, name, value, size); +} + +int fgetxattr(int fd, + const char *name, + const void *value, + size_t size) +{ + if (smbw_fd(fd)) { + return smbw_fgetxattr(fd, name, value, size); + } + + return (* smbw_libc.fgetxattr)(fd, name, value, size); +} + +int removexattr(const char *fname, + const char *name) +{ + if (smbw_path(fname)) { + return smbw_removexattr(fname, name); + } + + return (* smbw_libc.removexattr)(fname, name); +} + +int lremovexattr(const char *fname, + const char *name) +{ + if (smbw_path(fname)) { + return smbw_lremovexattr(fname, name); + } + + return (* smbw_libc.lremovexattr)(fname, name); +} + +int fremovexattr(int fd, + const char *name) +{ + if (smbw_fd(fd)) { + return smbw_fremovexattr(fd, name); + } + + return (* smbw_libc.fremovexattr)(fd, name); +} + +int listxattr(const char *fname, + char *list, + size_t size) +{ + if (smbw_path(fname)) { + return smbw_listxattr(fname, list, size); + } + + return (* smbw_libc.listxattr)(fname, list, size); +} + +int llistxattr(const char *fname, + char *list, + size_t size) +{ + if (smbw_path(fname)) { + return smbw_llistxattr(fname, list, size); + } + + return (* smbw_libc.llistxattr)(fname, list, size); +} + +int flistxattr(int fd, + char *list, + size_t size) +{ + if (smbw_fd(fd)) { + return smbw_flistxattr(fd, list, size); + } + + return (* smbw_libc.flistxattr)(fd, list, size); +} + + +/* + * We're ending up with a different implementation of malloc() with smbwrapper + * than without it. The one with it does not support returning a non-NULL + * pointer from a call to malloc(0), and many apps depend on getting a valid + * pointer when requesting zero length (e.g. df, emacs). + * + * Unfortunately, initializing the smbw_libc[] array via the dynamic link + * library (libdl) requires malloc so we can't just do the same type of + * mapping to the C library as we do with everything else. We need to + * implement a different way of allocating memory that ensures that the C + * library version of malloc() gets used. This is the only place where we + * kludge the code to use an undocumented interface to the C library. + * + * If anyone can come up with a way to dynamically link to the C library + * rather than using this undocumented interface, I'd sure love to hear about + * it. Better yet, if you can figure out where the alternate malloc() + * functions are coming from and arrange for them not to be called, that would + * be even better. We should try to avoid wrapping functions that don't + * really require it. + */ + +void *malloc(size_t size) +{ + void *__libc_malloc(size_t size); + return __libc_malloc(size); +} + +void *calloc(size_t nmemb, size_t size) +{ + void *__libc_calloc(size_t nmemb, size_t size); + return __libc_calloc(nmemb, size); +} + +void *realloc(void *ptr, size_t size) +{ + void *__libc_realloc(void *ptr, size_t size); + return __libc_realloc(ptr, size); +} + +void free(void *ptr) +{ + static int in_progress = 0; + void __libc_free(void *ptr); + + if (in_progress) return; + in_progress = 1; + __libc_free(ptr); + in_progress = 0; +} + + +#if 0 /* SELECT */ + +static struct sigaction user_action[_NSIG]; + +static void +smbw_sigaction_handler(int signum, + siginfo_t *info, + void *context) +{ + /* Our entire purpose for trapping signals is to call this! */ + sys_select_signal(); + + /* Call the user's handler */ + if (user_action[signum].sa_handler != SIG_IGN && + user_action[signum].sa_handler != SIG_DFL && + user_action[signum].sa_handler != SIG_ERR) { + (* user_action[signum].sa_sigaction)(signum, info, context); + } +} + + +/* + * Every Samba signal handler must call sys_select_signal() to avoid a race + * condition, so we'll take whatever signal handler is currently assigned, + * call call sys_select_signal() in addition to their call. + */ +static int +do_select(int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout, + int (* select_fn)(int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout)) +{ + int i; + int ret; + int saved_errno; + sigset_t sigset; + struct sigaction new_action; + + saved_errno = errno; + for (i=1; i<_NSIG; i++) { + sigemptyset(&sigset); + new_action.sa_mask = sigset; + new_action.sa_flags = SA_SIGINFO; + new_action.sa_sigaction = smbw_sigaction_handler; + + if (sigaction(i, &new_action, &user_action[i]) < 0) { + if (errno != EINVAL) { + return -1; + } + } + } + errno = saved_errno; + + ret = (* select_fn)(n, readfds, writefds, exceptfds, timeout); + saved_errno = errno; + + for (i=0; i<_NSIG; i++) { + (void) sigaction(i, &user_action[i], NULL); + } + + errno = saved_errno; + return ret; +} + +int +select(int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout) +{ + check_init("select"); + + return do_select(n, readfds, writefds, exceptfds, + timeout, smbw_libc.select); +} + +int +_select(int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout) +{ + check_init("_select"); + + return do_select(n, readfds, writefds, exceptfds, + timeout, smbw_libc._select); +} + +int +__select(int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout) +{ + check_init("__select"); + + return do_select(n, readfds, writefds, exceptfds, + timeout, smbw_libc.__select); +} + +#endif diff --git a/examples/libsmbclient/smbwrapper/wrapper.h b/examples/libsmbclient/smbwrapper/wrapper.h new file mode 100644 index 0000000000..6d0d9f527a --- /dev/null +++ b/examples/libsmbclient/smbwrapper/wrapper.h @@ -0,0 +1,209 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + SMB wrapper functions + Copyright (C) Derrell Lipman 2003-2005 + + 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 __WRAPPER_H__ +#define __WRAPPER_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern int smbw_fd_map[__FD_SETSIZE]; +extern int smbw_ref_count[__FD_SETSIZE]; +extern char smbw_cwd[PATH_MAX]; +extern char smbw_prefix[]; + +typedef struct SMBW_stat { + unsigned long s_dev; /* device */ + unsigned long s_ino; /* inode */ + unsigned long s_mode; /* protection */ + unsigned long s_nlink; /* number of hard links */ + unsigned long s_uid; /* user ID of owner */ + unsigned long s_gid; /* group ID of owner */ + unsigned long s_rdev; /* device type (if inode device) */ + unsigned long long s_size; /* total size, in bytes */ + unsigned long s_blksize; /* blocksize for filesystem I/O */ + unsigned long s_blocks; /* number of blocks allocated */ + unsigned long s_atime; /* time of last access */ + unsigned long s_mtime; /* time of last modification */ + unsigned long s_ctime; /* time of last change */ +} SMBW_stat; + +typedef struct SMBW_dirent { + unsigned long d_ino; /* inode number */ + unsigned long long d_off; /* offset to the next dirent */ + unsigned long d_reclen; /* length of this record */ + unsigned long d_type; /* type of file */ + char d_name[256]; /* filename */ + char d_comment[256]; /* comment */ +} SMBW_dirent; + +struct kernel_sigaction { + __sighandler_t k_sa_handler; + unsigned long sa_flags; + sigset_t sa_mask; +}; + +typedef struct SMBW_libc +{ + /* write() is first, to allow debugging */ + ssize_t (* write)(int fd, void *buf, size_t count); + int (* open)(char *name, int flags, mode_t mode); + int (* _open)(char *name, int flags, mode_t mode) ; + int (* __open)(char *name, int flags, mode_t mode) ; + int (* open64)(char *name, int flags, mode_t mode); + int (* _open64)(char *name, int flags, mode_t mode) ; + int (* __open64)(char *name, int flags, mode_t mode) ; + ssize_t (* pread)(int fd, void *buf, size_t size, off_t ofs); + ssize_t (* pread64)(int fd, void *buf, size_t size, off64_t ofs); + ssize_t (* pwrite)(int fd, void *buf, size_t size, off_t ofs); + ssize_t (* pwrite64)(int fd, void *buf, size_t size, off64_t ofs); + int (* close)(int fd); + int (* __close)(int fd); + int (* _close)(int fd); + int (* fcntl)(int fd, int cmd, long arg); + int (* __fcntl)(int fd, int cmd, long arg); + int (* _fcntl)(int fd, int cmd, long arg); + int (* getdents)(int fd, struct dirent *dirp, unsigned int count); + int (* __getdents)(int fd, struct dirent *dirp, unsigned int count); + int (* _getdents)(int fd, struct dirent *dirp, unsigned int count); + int (* getdents64)(int fd, struct dirent64 *dirp, unsigned int count); + off_t (* lseek)(int fd, off_t offset, int whence); + off_t (* __lseek)(int fd, off_t offset, int whence); + off_t (* _lseek)(int fd, off_t offset, int whence); + off64_t (* lseek64)(int fd, off64_t offset, int whence); + off64_t (* __lseek64)(int fd, off64_t offset, int whence); + off64_t (* _lseek64)(int fd, off64_t offset, int whence); + ssize_t (* read)(int fd, void *buf, size_t count); + ssize_t (* __read)(int fd, void *buf, size_t count); + ssize_t (* _read)(int fd, void *buf, size_t count); + ssize_t (* __write)(int fd, void *buf, size_t count); + ssize_t (* _write)(int fd, void *buf, size_t count); + int (* access)(char *name, int mode); + int (* chmod)(char *name, mode_t mode); + int (* fchmod)(int fd, mode_t mode); + int (* chown)(char *name, uid_t owner, gid_t group); + int (* fchown)(int fd, uid_t owner, gid_t group); + int (* __xstat)(int vers, char *name, struct stat *st); + char * ( *getcwd)(char *buf, size_t size); + int (* mkdir)(char *name, mode_t mode); + int (* __fxstat)(int vers, int fd, struct stat *st); + int (* __lxstat)(int vers, char *name, struct stat *st); + int (* stat)(char *name, struct stat *st); + int (* lstat)(char *name, struct stat *st); + int (* fstat)(int fd, struct stat *st); + int (* unlink)(char *name); + int (* utime)(char *name, struct utimbuf *tvp); + int (* utimes)(char *name, struct timeval *tvp); + int (* readlink)(char *path, char *buf, size_t bufsize); + int (* rename)(char *oldname, char *newname); + int (* rmdir)(char *name); + int (* symlink)(char *topath, char *frompath); + int (* dup)(int fd); + int (* dup2)(int oldfd, int newfd); + DIR * (* opendir)(char *name); + struct dirent * (* readdir)(DIR *dir); + int (* closedir)(DIR *dir); + off_t (* telldir)(DIR *dir); + void (* seekdir)(DIR *dir, off_t offset); + int (* creat)(char *path, mode_t mode); + int (* creat64)(char *path, mode_t mode); + int (* __xstat64)(int ver, char *name, struct stat64 *st64); + int (* stat64)(char *name, struct stat64 *st64); + int (* __fxstat64)(int ver, int fd, struct stat64 *st64); + int (* fstat64)(int fd, struct stat64 *st64); + int (* __lxstat64)(int ver, char *name, struct stat64 *st64); + int (* lstat64)(char *name, struct stat64 *st64); + int (* _llseek)(unsigned int fd, unsigned long offset_high, unsigned long offset_low, loff_t *result, unsigned int whence); + struct dirent64 * (* readdir64)(DIR *dir); + int (* readdir_r)(DIR *dir, struct dirent *entry, struct dirent **result); + int (* readdir64_r)(DIR *dir, struct dirent64 *entry, struct dirent64 **result); + int (* setxattr)(const char *fname, + const char *name, + const void *value, + size_t size, + int flags); + int (* lsetxattr)(const char *fname, + const char *name, + const void *value, + size_t size, + int flags); + int (* fsetxattr)(int smbw_fd, + const char *name, + const void *value, + size_t size, + int flags); + int (* getxattr)(const char *fname, + const char *name, + const void *value, + size_t size); + int (* lgetxattr)(const char *fname, + const char *name, + const void *value, + size_t size); + int (* fgetxattr)(int smbw_fd, + const char *name, + const void *value, + size_t size); + int (* removexattr)(const char *fname, + const char *name); + int (* lremovexattr)(const char *fname, + const char *name); + int (* fremovexattr)(int smbw_fd, + const char *name); + int (* listxattr)(const char *fname, + char *list, + size_t size); + int (* llistxattr)(const char *fname, + char *list, + size_t size); + int (* flistxattr)(int smbw_fd, + char *list, + size_t size); + int (* chdir)(const char *path); + int (* fchdir)(int fd); + pid_t (* fork)(void); + int (* select)(int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout); + int (* _select)(int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout); + int (* __select)(int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout); +} SMBW_libc_pointers; + +extern SMBW_libc_pointers smbw_libc; + +#endif /* __WRAPPER_H__ */ diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index d2472230a2..8122df5e2e 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -1,91 +1,202 @@ -/* - Unix SMB/CIFS implementation. - SMB client library test program for browsing with different master browsers - Copyright (C) Derrell Lipman 2004 - - 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 +#include +#include +#include #include -#include +#include #include -#include -#include +#include #include +#include + +void error_message(char * pMessage) +{ + printf("ERROR: %s\n", pMessage); +} + static void -auth_fn(const char * pServer, - const char * pShare, - char * pWorkgroup, - int workgroup_len, - char * pUsername, - int username_len, - char * pPassword, - int password_len) +get_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) { - strncpy(pUsername, "anonymous", username_len); /* doesn't matter what */ - strncpy(pPassword, "password", password_len); /* ditto */ + char temp[128]; + + printf("Entered get_auth_data_fn\n"); + + fprintf(stdout, "Need password for //%s/%s\n", pServer, pShare); + + fprintf(stdout, "Username: [%s] ", pUsername); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pUsername, temp, maxLenUsername - 1); + } + + strcpy(temp, getpass("Password: ")); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pPassword, temp, maxLenPassword - 1); + } + + fprintf(stdout, "Workgroup: "); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); + } + + putchar('\n'); } int main(int argc, char * argv[]) { - int debug = 4; + int debug = 0; int opt; char * p; + char * q; char buf[1024]; int dir; + struct stat stat; struct smbc_dirent * dirent; - char ** ppUrl; - char * urlList[] = + poptContext pc; + struct poptOption long_options[] = { - "smb://", - "smb://?mb=.any", - "smb://?mb=.all", - "smb://?mb=xx", /* this one is suupposed to fail */ - NULL + POPT_AUTOHELP + { + "debug", 'd', POPT_ARG_INT, &debug, + 0, "Set debug level", "integer" + }, + { + NULL + } }; - if (smbc_init(auth_fn, debug) != 0) + setbuf(stdout, NULL); + + pc = poptGetContext("opendir", argc, (const char **)argv, long_options, 0); + + poptSetOtherOptionHelp(pc, ""); + + while ((opt = poptGetNextOpt(pc)) != -1) { + printf("Got option %d = %c\n", opt, opt); + switch (opt) { + } + } + + if (smbc_init(get_auth_data_fn, debug) != 0) { printf("Could not initialize smbc_ library\n"); return 1; } - for (ppUrl = urlList; *ppUrl != NULL; ppUrl++) + for (fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin); + p != NULL && *p != '\n' && *p != '\0'; + fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin)) { - printf("Opening (%s)...\n", *ppUrl); - - if ((dir = smbc_opendir(*ppUrl)) < 0) + if ((p = strchr(buf, '\n')) != NULL) { - printf("Could not open [%s] (%d:%s)\n", - *ppUrl, errno, strerror(errno)); + *p = '\0'; + } + + printf("Opening (%s)...\n", buf); + + if ((dir = smbc_opendir(buf)) < 0) + { + printf("Could not open directory [%s] (%d:%s)\n", + buf, errno, strerror(errno)); continue; } - + while ((dirent = smbc_readdir(dir)) != NULL) { - printf("%s\n", dirent->name); + printf("%-30s", dirent->name); + printf("%-30s", dirent->comment); + + switch(dirent->smbc_type) + { + case SMBC_WORKGROUP: + printf("WORKGROUP"); + break; + + case SMBC_SERVER: + printf("SERVER"); + break; + + case SMBC_FILE_SHARE: + printf("FILE_SHARE"); + break; + + case SMBC_PRINTER_SHARE: + printf("PRINTER_SHARE"); + break; + + case SMBC_COMMS_SHARE: + printf("COMMS_SHARE"); + break; + + case SMBC_IPC_SHARE: + printf("IPC_SHARE"); + break; + + case SMBC_DIR: + printf("DIR"); + break; + + case SMBC_FILE: + printf("FILE"); + + q = buf + strlen(buf); + strcat(q, "/"); + strcat(q+1, dirent->name); + if (smbc_stat(buf, &stat) < 0) + { + printf(" unknown size (reason %d: %s)", + errno, strerror(errno)); + } + else + { + printf(" size %lu", (unsigned long) stat.st_size); + } + *p = '\0'; + + break; + + case SMBC_LINK: + printf("LINK"); + break; + } + + printf("\n"); } - + smbc_closedir(dir); } - + exit(0); } - diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c index 888a9c0d4f..9f5e6148ee 100644 --- a/examples/libsmbclient/testsmbc.c +++ b/examples/libsmbclient/testsmbc.c @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) ((struct smbc_dirent *)dirp)->comment); dirp += dsize; - (char *)dirc -= dsize; + dirc -= dsize; } diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c index f50b3670cf..d8a69c8d4c 100644 --- a/examples/libsmbclient/tree.c +++ b/examples/libsmbclient/tree.c @@ -294,7 +294,7 @@ static void cb_select_child (GtkWidget *root_tree, GtkWidget *child, gtk_clist_append(GTK_CLIST(clist), rowdata); - (char *)dirp += dirlen; + dirp = (struct smbc_dirent *) ((char *) dirp + dirlen); err -= dirlen; } @@ -429,7 +429,7 @@ static void cb_itemsignal( GtkWidget *item, } - (char *)dirp += dirlen; + dirp = (struct smbc_dirent *) ((char *) dirp + dirlen); err -= dirlen; } @@ -564,7 +564,7 @@ static void cb_wholenet(GtkWidget *item, gchar *signame) gtk_signal_connect(GTK_OBJECT(subtree), "unselect_child", GTK_SIGNAL_FUNC(cb_unselect_child), real_tree); - (char *)dirp += dirlen; + dirp = (struct smbc_dirent *) ((char *) dirp + dirlen); err -= dirlen; } @@ -797,7 +797,7 @@ int main( int argc, gtk_signal_connect (GTK_OBJECT(subtree), "unselect_child", GTK_SIGNAL_FUNC(cb_unselect_child), tree); - (char *)dirp += dirlen; + dirp = (struct smbc_dirent *) ((char *) dirp + dirlen); err -= dirlen; } -- cgit From 7387dab585dadf710dbb72ddd211db1a1ba725c7 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 30 Mar 2005 02:39:22 +0000 Subject: r6126: added utility for testing smbc_stat() (This used to be commit e1df648ea13651e1df3d209937034b351a7f1c2b) --- examples/libsmbclient/Makefile | 19 ++--- examples/libsmbclient/smbwrapper/Makefile | 5 +- examples/libsmbclient/teststat.c | 117 ++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 11 deletions(-) create mode 100644 examples/libsmbclient/teststat.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 6c89fd431e..1e89e7077e 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -6,19 +6,16 @@ EXTLIB_INCL = -I/usr/include/gtk-1.2 \ -I/usr/include/glib-1.2 \ -I/usr/lib/glib/include -CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) +DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE +CFLAGS = -O0 -g -I$(SAMBA_INCL) $(EXTLIB_INCL) $(DEFS) -LDFLAGS = -L/usr/lib +LDFLAGS = -L/usr/local/samba/lib -all: testsmbc tree testacl testbrowse smbsh +all: testsmbc tree testacl testbrowse teststat smbsh testsmbc: testsmbc.o @echo Linking testsmbc - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient -L/usr/local/lib - -testsmbc-static: testsmbc.o - @echo Linking testsmbc - @$(CC) $(CFLAGS) -static $(LDFLAGS) -o $@ $< -lsmbclient -ldl -lnsl + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient tree: tree.o @echo Linking tree @@ -32,9 +29,13 @@ testbrowse: testbrowse.o @echo Linking testbrowse @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< +teststat: teststat.o + @echo Linking teststat + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + smbsh: make -C smbwrapper clean: - @rm -f *.o *~ testsmbc tree testacl testbrowse + @rm -f *.o *~ testsmbc tree testacl testbrowse teststat @make -C smbwrapper clean diff --git a/examples/libsmbclient/smbwrapper/Makefile b/examples/libsmbclient/smbwrapper/Makefile index 099c204986..8e7070cb59 100644 --- a/examples/libsmbclient/smbwrapper/Makefile +++ b/examples/libsmbclient/smbwrapper/Makefile @@ -3,7 +3,7 @@ DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) -LDFLAGS = -L/usr/lib +LDFLAGS = -L/usr/local/samba/lib SMBINCLUDE = -I../../../source/include CFLAGS= -fpic -g -O0 $(DEFS) $(SMBINCLUDE) @@ -22,11 +22,12 @@ $(BIN)/smbwrapper.so: $(SMBWRAPPER_OBJS) --export-all-symbols \ -o $(BIN)/smbwrapper.so \ $(SMBWRAPPER_OBJS) \ + $(LDFLAGS) \ $(LIBS) \ -Wl,-soname=`basename $@` $(BIN)/smbsh: $(SMBSH_OBJS) - $(CC) -g -o $(BIN)/smbsh $(SMBSH_OBJS) $(LIBS) + $(CC) -g -o $(BIN)/smbsh $(SMBSH_OBJS) $(LIBS) $(LDFLAGS) opendir_smbsh: opendir_smbsh.o $(CC) -g -o opendir_smbsh opendir_smbsh.o $(LIBS) $(DMALLOC) diff --git a/examples/libsmbclient/teststat.c b/examples/libsmbclient/teststat.c new file mode 100644 index 0000000000..46eeb13985 --- /dev/null +++ b/examples/libsmbclient/teststat.c @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include + +static void +get_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) + +{ + char temp[128]; + + printf("Entered get_auth_data_fn\n"); + + fprintf(stdout, "Need password for //%s/%s\n", pServer, pShare); + + fprintf(stdout, "Username: [%s] ", pUsername); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pUsername, temp, maxLenUsername - 1); + } + + strcpy(temp, getpass("Password: ")); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pPassword, temp, maxLenPassword - 1); + } + + fprintf(stdout, "Workgroup: "); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); + } + + putchar('\n'); +} + + + +int main(int argc, char * argv[]) +{ + char buffer[16384]; + char * pSmbPath = NULL; + char * pLocalPath = NULL; + struct stat st; + + if (argc == 1) + { + pSmbPath = "smb://RANDOM/Public/small"; + pLocalPath = "/random/home/samba/small"; + } + else if (argc == 2) + { + pSmbPath = argv[1]; + pLocalPath = NULL; + } + else if (argc == 3) + { + pSmbPath = argv[1]; + pLocalPath = argv[2]; + } + else + { + printf("usage: " + "%s [ smb://path/to/file [ /nfs/or/local/path/to/file ] ]\n", + argv[0]); + return 1; + } + + smbc_init(get_auth_data_fn, 0); + + int ret = smbc_stat(pSmbPath, &st); + + 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)); + + if (pLocalPath != NULL) + { + ret = stat(pLocalPath, &st); + + 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)); + } + + return 0; +} -- cgit From 9840db418bad5a39edc4a32a1786f5e2d2c9dff8 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 31 Mar 2005 05:06:04 +0000 Subject: r6149: Fixes bugs #2498 and 2484. 1. using smbc_getxattr() et al, one may now request all access control entities in the ACL without getting all other NT attributes. 2. added the ability to exclude specified attributes from the result set provided by smbc_getxattr() et al, when requesting all attributes, all NT attributes, or all DOS attributes. 3. eliminated all compiler warnings, including when --enable-developer compiler flags are in use. removed -Wcast-qual flag from list, as that is specifically to force warnings in the case of casting away qualifiers. Note: In the process of eliminating compiler warnings, a few nasties were discovered. In the file libads/sasl.c, PRIVATE kerberos interfaces are being used; and in libsmb/clikrb5.c, both PRIAVE and DEPRECATED kerberos interfaces are being used. Someone who knows kerberos should look at these and determine if there is an alternate method of accomplishing the task. (This used to be commit 994694f7f26da5099f071e1381271a70407f33bb) --- examples/libsmbclient/README | 11 ++++++- examples/libsmbclient/testacl.c | 54 +-------------------------------- examples/libsmbclient/testbrowse.c | 62 ++------------------------------------ examples/libsmbclient/testsmbc.c | 37 ++--------------------- examples/libsmbclient/teststat.c | 60 +----------------------------------- 5 files changed, 16 insertions(+), 208 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/README b/examples/libsmbclient/README index d9a9f82917..c45dd8b9d6 100644 --- a/examples/libsmbclient/README +++ b/examples/libsmbclient/README @@ -2,7 +2,16 @@ Some simple example programs for libsmbclient ... testsmbc.c is kinda broken as it has many hardcoded bits in it +testbrowse.c opens a remote folder and displays its contents + +teststat.c allows comparing the results of smbc_stat() against a local stat() of +the same file. + tree.c is an example of how you might do some of these things with GTK+ It needs lots of work but shows you some ways to use libsmbclient. -Richard Sharpe, 17-May-2001 ... +smbwrapper implements the old smbsh/smbwrapper mechanism using libsmbclient, in +such a way that it works on Linux + +Richard Sharpe, 17 May 2001 +Derrell Lipman, 30 Mar 2005 diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c index 47668f7c9c..ce5694b331 100644 --- a/examples/libsmbclient/testacl.c +++ b/examples/libsmbclient/testacl.c @@ -3,6 +3,7 @@ #include #include #include "libsmbclient.h" +#include "get_auth_data_fn.h" enum acl_mode { @@ -15,59 +16,6 @@ enum acl_mode SMB_ACL_CHGRP }; -static void -get_auth_data_fn(const char * pServer, - const char * pShare, - char * pWorkgroup, - int maxLenWorkgroup, - char * pUsername, - int maxLenUsername, - char * pPassword, - int maxLenPassword) - -{ - char temp[128]; - - fprintf(stdout, "Workgroup: [%s] ", pWorkgroup); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); - } - - fprintf(stdout, "Username: [%s] ", pUsername); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pUsername, temp, maxLenUsername - 1); - } - - fprintf(stdout, "Password: "); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pPassword, temp, maxLenPassword - 1); - } -} - int main(int argc, const char *argv[]) { diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 8122df5e2e..27d6a69738 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -5,8 +5,9 @@ #include #include #include -#include #include +#include +#include "get_auth_data_fn.h" void error_message(char * pMessage) { @@ -14,65 +15,6 @@ void error_message(char * pMessage) } -static void -get_auth_data_fn(const char * pServer, - const char * pShare, - char * pWorkgroup, - int maxLenWorkgroup, - char * pUsername, - int maxLenUsername, - char * pPassword, - int maxLenPassword) - -{ - char temp[128]; - - printf("Entered get_auth_data_fn\n"); - - fprintf(stdout, "Need password for //%s/%s\n", pServer, pShare); - - fprintf(stdout, "Username: [%s] ", pUsername); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pUsername, temp, maxLenUsername - 1); - } - - strcpy(temp, getpass("Password: ")); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pPassword, temp, maxLenPassword - 1); - } - - fprintf(stdout, "Workgroup: "); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); - } - - putchar('\n'); -} - - int main(int argc, char * argv[]) { diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c index 9f5e6148ee..45e67bee62 100644 --- a/examples/libsmbclient/testsmbc.c +++ b/examples/libsmbclient/testsmbc.c @@ -27,40 +27,7 @@ #include #include #include - -void auth_fn(const char *server, const char *share, - char *workgroup, int wgmaxlen, char *username, int unmaxlen, - char *password, int pwmaxlen) -{ - char temp[128]; - - fprintf(stdout, "Need password for //%s/%s\n", server, share); - - fprintf(stdout, "Enter workgroup: [%s] ", workgroup); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */ - temp[strlen(temp) - 1] = 0x00; - - if (temp[0]) strncpy(workgroup, temp, wgmaxlen - 1); - - fprintf(stdout, "Enter username: [%s] ", username); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */ - temp[strlen(temp) - 1] = 0x00; - - if (temp[0]) strncpy(username, temp, unmaxlen - 1); - - fprintf(stdout, "Enter password: [%s] ", password); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */ - temp[strlen(temp) - 1] = 0x00; - - if (temp[0]) strncpy(password, temp, pwmaxlen - 1); - -} +#include "get_auth_data_fn.h" int global_id = 0; @@ -84,7 +51,7 @@ int main(int argc, char *argv[]) char *dirp; struct stat st1, st2; - err = smbc_init(auth_fn, 10); /* Initialize things */ + err = smbc_init(get_auth_data_fn, 10); /* Initialize things */ if (err < 0) { diff --git a/examples/libsmbclient/teststat.c b/examples/libsmbclient/teststat.c index 46eeb13985..bea34cfc09 100644 --- a/examples/libsmbclient/teststat.c +++ b/examples/libsmbclient/teststat.c @@ -3,65 +3,7 @@ #include #include #include - -static void -get_auth_data_fn(const char * pServer, - const char * pShare, - char * pWorkgroup, - int maxLenWorkgroup, - char * pUsername, - int maxLenUsername, - char * pPassword, - int maxLenPassword) - -{ - char temp[128]; - - printf("Entered get_auth_data_fn\n"); - - fprintf(stdout, "Need password for //%s/%s\n", pServer, pShare); - - fprintf(stdout, "Username: [%s] ", pUsername); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pUsername, temp, maxLenUsername - 1); - } - - strcpy(temp, getpass("Password: ")); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pPassword, temp, maxLenPassword - 1); - } - - fprintf(stdout, "Workgroup: "); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); - } - - putchar('\n'); -} - +#include "get_auth_data_fn.h" int main(int argc, char * argv[]) -- cgit From 8e6b4b9867b7507c8a1542a5b3389a08ffba722b Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 31 Mar 2005 16:26:15 +0000 Subject: r6151: additional examples/tests for libsmbclient (This used to be commit a3bd496c921dc775b59be4ff2941f4824ffbec03) --- examples/libsmbclient/Makefile | 20 +++++++++-- examples/libsmbclient/testchmod.c | 64 +++++++++++++++++++++++++++++++++ examples/libsmbclient/teststat.c | 31 ++++++++++------ examples/libsmbclient/testutime.c | 76 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 179 insertions(+), 12 deletions(-) create mode 100644 examples/libsmbclient/testchmod.c create mode 100644 examples/libsmbclient/testutime.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 1e89e7077e..4b4919ee7f 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -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 diff --git a/examples/libsmbclient/testchmod.c b/examples/libsmbclient/testchmod.c new file mode 100644 index 0000000000..774daaed59 --- /dev/null +++ b/examples/libsmbclient/testchmod.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#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; +} diff --git a/examples/libsmbclient/teststat.c b/examples/libsmbclient/teststat.c index bea34cfc09..d67f626d78 100644 --- a/examples/libsmbclient/teststat.c +++ b/examples/libsmbclient/teststat.c @@ -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; diff --git a/examples/libsmbclient/testutime.c b/examples/libsmbclient/testutime.c new file mode 100644 index 0000000000..3a1540c654 --- /dev/null +++ b/examples/libsmbclient/testutime.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#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; +} -- cgit From eefc6f0ab4eb9aea426678228b2815c472f79b4a Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 31 Mar 2005 21:17:36 +0000 Subject: r6157: 'editorial changes' to example code (This used to be commit fa0294ddbf7c93c24fca670b7ed52821a0507174) --- examples/libsmbclient/teststat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/teststat.c b/examples/libsmbclient/teststat.c index d67f626d78..29517efb6f 100644 --- a/examples/libsmbclient/teststat.c +++ b/examples/libsmbclient/teststat.c @@ -8,6 +8,7 @@ int main(int argc, char * argv[]) { + int debug = 0; char buffer[16384]; char mtime[32]; char ctime[32]; @@ -39,7 +40,7 @@ int main(int argc, char * argv[]) return 1; } - smbc_init(get_auth_data_fn, 0); + smbc_init(get_auth_data_fn, debug); if (smbc_stat(pSmbPath, &st) < 0) { -- cgit From 7a8ee799259c7c0e3d5d6b3d34ce05195f53d4cb Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 27 Apr 2005 14:05:02 +0000 Subject: r6501: correct deprecated lvalue casts in testsuite/libsmbclient (This used to be commit 6d22c3c3434812d3a6ab7f216bec34cdb3b622a0) --- examples/libsmbclient/testutime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testutime.c b/examples/libsmbclient/testutime.c index 3a1540c654..e94777a0d6 100644 --- a/examples/libsmbclient/testutime.c +++ b/examples/libsmbclient/testutime.c @@ -16,6 +16,7 @@ int main(int argc, char * argv[]) char ctime[32]; char atime[32]; char * pSmbPath = NULL; + struct tm tm; struct stat st; struct utimbuf utimbuf; @@ -53,7 +54,7 @@ int main(int argc, char * argv[]) 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.actime = st.st_atime - 120; /* unchangable (wont change) */ utimbuf.modtime = st.st_mtime - 120; /* this one should succeed */ if (smbc_utime(pSmbPath, &utimbuf) < 0) { -- cgit From 432878c80e1c9d9b4e66235c603401094df665c3 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 31 May 2005 20:12:34 +0000 Subject: r7153: add better test facilities to testutime (This used to be commit d763c739a63894d5f458f61de28b90d840bb8fe4) --- examples/libsmbclient/testutime.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testutime.c b/examples/libsmbclient/testutime.c index e94777a0d6..2ad395f862 100644 --- a/examples/libsmbclient/testutime.c +++ b/examples/libsmbclient/testutime.c @@ -10,12 +10,12 @@ 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; + time_t t = time(NULL); struct tm tm; struct stat st; struct utimbuf utimbuf; @@ -31,12 +31,12 @@ int main(int argc, char * argv[]) else if (argc == 3) { pSmbPath = argv[1]; - mode = (int) strtol(argv[2], NULL, 8); + t = (time_t) strtol(argv[2], NULL, 10); } else { printf("usage: " - "%s [ smb://path/to/file [ octal_mode ] ]\n", + "%s [ smb://path/to/file [ mtime ] ]\n", argv[0]); return 1; } @@ -54,8 +54,8 @@ int main(int argc, char * argv[]) 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 (wont change) */ - utimbuf.modtime = st.st_mtime - 120; /* this one should succeed */ + utimbuf.actime = t; /* unchangable (wont change) */ + utimbuf.modtime = t; /* this one should succeed */ if (smbc_utime(pSmbPath, &utimbuf) < 0) { perror("smbc_utime"); -- cgit From 38c5136ce16ca1f61a0d64a89269ccc556d1d7ea Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 31 May 2005 23:42:29 +0000 Subject: r7156: file was missing; svn isn't smart enough to even notify me. sigh. (This used to be commit fce48fa1b462ded1453520355bf2dce0f607b8dc) --- examples/libsmbclient/get_auth_data_fn.h | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/libsmbclient/get_auth_data_fn.h (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/get_auth_data_fn.h b/examples/libsmbclient/get_auth_data_fn.h new file mode 100644 index 0000000000..2954039f0a --- /dev/null +++ b/examples/libsmbclient/get_auth_data_fn.h @@ -0,0 +1,52 @@ +static void +get_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) + +{ + char temp[128]; + + fprintf(stdout, "Workgroup: [%s] ", pWorkgroup); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); + } + + fprintf(stdout, "Username: [%s] ", pUsername); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pUsername, temp, maxLenUsername - 1); + } + + fprintf(stdout, "Password: "); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pPassword, temp, maxLenPassword - 1); + } +} -- cgit From e317034997bbeab447298070afdb1b78c60e0e69 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 1 Jun 2005 17:40:40 +0000 Subject: r7168: Updating file times from libsmbclient was not working for win98. Although the function that was being used to set attributes is a core protocol function (SMBsetatr = 0x09), it does not appear to work on win98. As a temporary measure, when file times are to be set, this version opens the file and uses SMBsetattrE = 0x22 instead. (The other advantage of this function over the original one is that it supports setting access time as well as modification time.) The next step, the proper solution if it can be made to work, is to write functions that use TRANS2_SET_PATH_INFO instead. (This used to be commit bab0bf7f4f9d2a4b6fcee4429094349302bbeb33) --- examples/libsmbclient/smbwrapper/smbw_stat.c | 51 ++-------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/smbw_stat.c b/examples/libsmbclient/smbwrapper/smbw_stat.c index 70b3064d22..a386c09209 100644 --- a/examples/libsmbclient/smbwrapper/smbw_stat.c +++ b/examples/libsmbclient/smbwrapper/smbw_stat.c @@ -22,53 +22,8 @@ #include "smbw.h" -static int timezone_diff = -1; - -#define TM_YEAR_BASE 1900 - -/******************************************************************* -yield the difference between *A and *B, in seconds, ignoring leap seconds -********************************************************************/ -static int tm_diff(struct tm *a, struct tm *b) -{ - int ay = a->tm_year + (TM_YEAR_BASE - 1); - int by = b->tm_year + (TM_YEAR_BASE - 1); - int intervening_leap_days = - (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); - int years = ay - by; - int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); - int hours = 24*days + (a->tm_hour - b->tm_hour); - int minutes = 60*hours + (a->tm_min - b->tm_min); - int seconds = 60*minutes + (a->tm_sec - b->tm_sec); - - return seconds; -} - -/******************************************************************* - return the UTC offset in seconds west of UTC, or 0 if it cannot be determined - ******************************************************************/ -static int TimeZone(time_t t) -{ - struct tm *tm = gmtime(&t); - struct tm tm_utc; - if (!tm) - return 0; - tm_utc = *tm; - tm = localtime(&t); - if (!tm) - return 0; - return tm_diff(&tm_utc,tm); - -} - - static void copy_stat(struct SMBW_stat *external, struct stat *internal) { - if (timezone_diff < 0) - { - timezone_diff = TimeZone(time(NULL)); - } - external->s_dev = internal->st_dev; external->s_ino = internal->st_ino; external->s_mode = internal->st_mode; @@ -79,9 +34,9 @@ static void copy_stat(struct SMBW_stat *external, struct stat *internal) external->s_size = internal->st_size; external->s_blksize = internal->st_blksize; external->s_blocks = internal->st_blocks; - external->s_atime = internal->st_atime + timezone_diff; - external->s_mtime = internal->st_mtime + timezone_diff; - external->s_ctime = internal->st_ctime + timezone_diff; + external->s_atime = internal->st_atime; + external->s_mtime = internal->st_mtime; + external->s_ctime = internal->st_ctime; } -- cgit From f398183555d91a2adc96350cbeb69a11b42e6a37 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 17 Oct 2005 19:27:19 +0000 Subject: r11129: r10090@cabra: derrell | 2005-10-17 15:26:27 -0400 added example to read a file and test download time (This used to be commit 4fad0c49b5bf7819d0f9782b60369c5d078c5854) --- examples/libsmbclient/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 4b4919ee7f..7e893fd488 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -17,7 +17,8 @@ TESTS= testsmbc \ testbrowse \ teststat \ testchmod \ - testutime + testutime \ + testread all: $(TESTS) smbsh @@ -49,6 +50,10 @@ testutime: testutime.o @echo Linking testutime @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< +testread: testread.o + @echo Linking testread + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + smbsh: make -C smbwrapper -- cgit From 97351bc5fc2c203bde4702c14fc7429fe2d437ba Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 17 Oct 2005 19:29:11 +0000 Subject: r11130: r10092@cabra: derrell | 2005-10-17 15:29:03 -0400 let's now actually add the new test file (This used to be commit b58237f98d924752a45f689d7a9fd2e8e447c100) --- examples/libsmbclient/testread.c | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 examples/libsmbclient/testread.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testread.c b/examples/libsmbclient/testread.c new file mode 100644 index 0000000000..1f1219ca84 --- /dev/null +++ b/examples/libsmbclient/testread.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include +#include "get_auth_data_fn.h" + + +int main(int argc, char * argv[]) +{ + int fd; + int ret; + int debug = 0; + int mode = 0666; + int savedErrno; + char buffer[2048]; + char * pSmbPath = NULL; + 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) + { + perror("smbc_open"); + return 1; + } + + printf("Beginning read loop.\n"); + + do + { + ret = smbc_read(fd, buffer, sizeof(buffer)); + savedErrno = errno; + } while (ret > 0); + + smbc_close(fd); + + if (ret < 0) + { + errno = savedErrno; + perror("read"); + return 1; + } + + t1 = time(NULL); + + printf("Elapsed time: %d seconds\n", t1 - t0); + + return 0; +} -- cgit From a54f9eddcea6497451dd6c720e9804ad5c6f3ad7 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 5 Dec 2005 23:30:40 +0000 Subject: r12080: r10673@cabra: derrell | 2005-12-05 13:22:34 -0500 Correct some memory and file descriptor leaks. This should fix bugs 3257, 3267 and 3273. (This used to be commit c5781c9cf5f1f8297e084fbe2c4a22257420a447) --- examples/libsmbclient/testbrowse.c | 238 +++++++++++++++++++++++++------------ 1 file changed, 163 insertions(+), 75 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 27d6a69738..6fa70eab41 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -9,24 +9,34 @@ #include #include "get_auth_data_fn.h" -void error_message(char * pMessage) -{ - printf("ERROR: %s\n", pMessage); -} +static void +no_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword); + +static void browse(char * path, + int scan, + int indent); + int main(int argc, char * argv[]) { int debug = 0; + int scan = 0; + int iterations = -1; + int again; int opt; char * p; char * q; char buf[1024]; - int dir; - struct stat stat; - struct smbc_dirent * dirent; - poptContext pc; + poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP @@ -34,6 +44,14 @@ main(int argc, char * argv[]) "debug", 'd', POPT_ARG_INT, &debug, 0, "Set debug level", "integer" }, + { + "scan", 's', POPT_ARG_NONE, &scan, + 0, "Scan for servers and shares", "integer" + }, + { + "iterations", 'i', POPT_ARG_INT, &iterations, + 0, "Iterations", "integer" + }, { NULL } @@ -51,94 +69,164 @@ main(int argc, char * argv[]) } } - if (smbc_init(get_auth_data_fn, debug) != 0) + if (scan) { - printf("Could not initialize smbc_ library\n"); - return 1; + if (smbc_init(no_auth_data_fn, debug) != 0) + { + printf("Could not initialize smbc_ library\n"); + return 1; + } + + for (; + iterations == -1 || iterations > 0; + iterations = (iterations == -1 ? iterations : --iterations)) + { + snprintf(buf, sizeof(buf), "smb://"); + browse(buf, scan, 0); + } } - - for (fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin); - p != NULL && *p != '\n' && *p != '\0'; - fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin)) + else { - if ((p = strchr(buf, '\n')) != NULL) + if (smbc_init(get_auth_data_fn, debug) != 0) { - *p = '\0'; + printf("Could not initialize smbc_ library\n"); + return 1; } - - printf("Opening (%s)...\n", buf); - - if ((dir = smbc_opendir(buf)) < 0) + + for (; + iterations == -1 || iterations > 0; + iterations = (iterations == -1 ? iterations : --iterations)) { - printf("Could not open directory [%s] (%d:%s)\n", - buf, errno, strerror(errno)); - continue; + fputs("url: ", stdout); + p = fgets(buf, sizeof(buf), stdin); + if (! p) + { + break; + } + + if ((p = strchr(buf, '\n')) != NULL) + { + *p = '\0'; + } + + browse(buf, scan, 0); } + } - while ((dirent = smbc_readdir(dir)) != NULL) - { - printf("%-30s", dirent->name); - printf("%-30s", dirent->comment); + exit(0); +} - switch(dirent->smbc_type) - { - case SMBC_WORKGROUP: - printf("WORKGROUP"); - break; + +static void +no_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) +{ + return; +} + +static void browse(char * path, int scan, int indent) +{ + char * p; + char buf[1024]; + int dir; + struct stat stat; + struct smbc_dirent * dirent; + + if (! scan) + { + printf("Opening (%s)...\n", path); + } + + if ((dir = smbc_opendir(path)) < 0) + { + printf("Could not open directory [%s] (%d:%s)\n", + path, errno, strerror(errno)); + return; + } + + while ((dirent = smbc_readdir(dir)) != NULL) + { + printf("%*.*s%-30s", indent, indent, "", dirent->name); + + switch(dirent->smbc_type) + { + case SMBC_WORKGROUP: + printf("WORKGROUP"); + break; - case SMBC_SERVER: - printf("SERVER"); - break; + case SMBC_SERVER: + printf("SERVER"); + break; - case SMBC_FILE_SHARE: - printf("FILE_SHARE"); - break; + case SMBC_FILE_SHARE: + printf("FILE_SHARE"); + break; - case SMBC_PRINTER_SHARE: - printf("PRINTER_SHARE"); - break; + case SMBC_PRINTER_SHARE: + printf("PRINTER_SHARE"); + break; - case SMBC_COMMS_SHARE: - printf("COMMS_SHARE"); - break; + case SMBC_COMMS_SHARE: + printf("COMMS_SHARE"); + break; - case SMBC_IPC_SHARE: - printf("IPC_SHARE"); - break; + case SMBC_IPC_SHARE: + printf("IPC_SHARE"); + break; - case SMBC_DIR: - printf("DIR"); - break; + case SMBC_DIR: + printf("DIR"); + break; - case SMBC_FILE: - printf("FILE"); - - q = buf + strlen(buf); - strcat(q, "/"); - strcat(q+1, dirent->name); - if (smbc_stat(buf, &stat) < 0) - { - printf(" unknown size (reason %d: %s)", - errno, strerror(errno)); - } - else - { - printf(" size %lu", (unsigned long) stat.st_size); - } - *p = '\0'; + case SMBC_FILE: + printf("FILE"); - break; - - case SMBC_LINK: - printf("LINK"); - break; + p = path + strlen(path); + strcat(p, "/"); + strcat(p+1, dirent->name); + if (smbc_stat(path, &stat) < 0) + { + printf(" unknown size (reason %d: %s)", + errno, strerror(errno)); } + else + { + printf(" size %lu", (unsigned long) stat.st_size); + } + *p = '\0'; - printf("\n"); + break; + + case SMBC_LINK: + printf("LINK"); + break; } - smbc_closedir(dir); + printf("\n"); + + if (scan && + (dirent->smbc_type == SMBC_WORKGROUP || + dirent->smbc_type == SMBC_SERVER)) + { + /* + * don't append server name to workgroup; what we want is: + * + * smb://workgroup_name + * or + * smb://server_name + * + */ + snprintf(buf, sizeof(buf), "smb://%s", dirent->name); + browse(buf, scan, indent + 2); + } } - exit(0); + smbc_closedir(dir); } + -- cgit From 44293df2aeaeccb1e2cca18bb7d61534a5e07b1a Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 6 Dec 2005 17:09:44 +0000 Subject: r12098: r10797@cabra: derrell | 2005-12-06 12:09:00 -0500 fixed another memory leak and reverted an (incorrect) fix from yesterday (This used to be commit 8a86d7bddc291da094d060fbe185f071ffdbddd8) --- examples/libsmbclient/Makefile | 5 + examples/libsmbclient/testbrowse2.c | 214 ++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 examples/libsmbclient/testbrowse2.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 7e893fd488..c324a578d1 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -15,6 +15,7 @@ TESTS= testsmbc \ tree \ testacl \ testbrowse \ + testbrowse2 \ teststat \ testchmod \ testutime \ @@ -38,6 +39,10 @@ testbrowse: testbrowse.o @echo Linking testbrowse @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< +testbrowse2: testbrowse2.o + @echo Linking testbrowse2 + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< + teststat: teststat.o @echo Linking teststat @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< diff --git a/examples/libsmbclient/testbrowse2.c b/examples/libsmbclient/testbrowse2.c new file mode 100644 index 0000000000..a3d2cf3b8e --- /dev/null +++ b/examples/libsmbclient/testbrowse2.c @@ -0,0 +1,214 @@ +/* + * Alternate testbrowse utility provided by Mikhail Kshevetskiy. + * This version tests use of multiple contexts. + */ + +#include +#include +#include +#include +#include + +int debuglevel = 0; +char *workgroup = "NT"; +char *username = "guest"; +char *password = ""; + +typedef struct smbitem smbitem; +typedef int(*qsort_cmp)(const void *, const void *); + +struct smbitem{ + smbitem *next; + int type; + char name[1]; +}; + +int smbitem_cmp(smbitem *elem1, smbitem *elem2){ + return strcmp(elem1->name, elem2->name); +} + +int smbitem_list_count(smbitem *list){ + int count = 0; + + while(list != NULL){ + list = list->next; + count++; + } + return count; +} + +void smbitem_list_delete(smbitem *list){ + smbitem *elem; + + while(list != NULL){ + elem = list; + list = list->next; + free(elem); + } +} + +smbitem* smbitem_list_sort(smbitem *list){ + smbitem *item, **array; + int count, i; + + if ((count = smbitem_list_count(list)) == 0) return NULL; + if ((array = malloc(count * sizeof(smbitem*))) == NULL){ + smbitem_list_delete(list); + return NULL; + } + + for(i = 0; i < count; i++){ + array[i] = list; + list = list->next; + } + qsort(array, count, sizeof(smbitem*), (qsort_cmp)smbitem_cmp); + + for(i = 0; i < count - 1; i++) array[i]->next = array[i + 1]; + array[count - 1]->next = NULL; + + list = array[0]; + free(array); + return list; +} + +void smbc_auth_fn( + const char *server, + const char *share, + char *wrkgrp, int wrkgrplen, + char *user, int userlen, + char *passwd, int passwdlen){ + + (void) server; + (void) share; + (void) wrkgrp; + (void) wrkgrplen; + + strncpy(wrkgrp, workgroup, wrkgrplen - 1); wrkgrp[wrkgrplen - 1] = 0; + strncpy(user, username, userlen - 1); user[userlen - 1] = 0; + strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0; +} + +SMBCCTX* create_smbctx(){ + SMBCCTX *ctx; + + if ((ctx = smbc_new_context()) == NULL) return NULL; + + ctx->debug = debuglevel; + ctx->callbacks.auth_fn = smbc_auth_fn; + + if (smbc_init_context(ctx) == NULL){ + smbc_free_context(ctx, 1); + return NULL; + } + + return ctx; +} + +void delete_smbctx(SMBCCTX* ctx){ + ctx->callbacks.purge_cached_fn(ctx); + smbc_free_context(ctx, 1); +} + +smbitem* get_smbitem_list(SMBCCTX *ctx, char *smb_path){ + SMBCFILE *fd; + 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 (strcmp(dirent->name, "") == 0) continue; + if (strcmp(dirent->name, ".") == 0) continue; + if (strcmp(dirent->name, "..") == 0) continue; + + if ((item = malloc(sizeof(smbitem) + strlen(dirent->name))) == NULL) + continue; + + item->next = list; + item->type = dirent->smbc_type; + strcpy(item->name, dirent->name); + list = item; + } + ctx->close_fn(ctx, fd); + return /* smbitem_list_sort */ (list); + +} + +void print_smb_path(char *group, char *path){ + if ((strlen(group) == 0) && (strlen(path) == 0)) printf("/\n"); + else if (strlen(path) == 0) printf("/%s\n", group); + else{ + if (strlen(group) == 0) group = "(unknown_group)"; + printf("/%s/%s\n", group, path); + } +} + +void recurse(SMBCCTX *ctx, char *smb_group, char *smb_path, int maxlen){ + int len; + smbitem *list, *item; + SMBCCTX *ctx1; + + len = strlen(smb_path); + + list = get_smbitem_list(ctx, smb_path); + while(list != NULL){ + switch(list->type){ + case SMBC_WORKGROUP: + case SMBC_SERVER: + if (list->type == SMBC_WORKGROUP){ + print_smb_path(list->name, ""); + smb_group = list->name; + } + else print_smb_path(smb_group, list->name); + + if (maxlen < 7 + strlen(list->name)) break; + strcpy(smb_path + 6, list->name); + if ((ctx1 = create_smbctx()) != NULL){ + recurse(ctx1, smb_group, smb_path, maxlen); + delete_smbctx(ctx1); + }else{ + recurse(ctx, smb_group, smb_path, maxlen); + ctx->callbacks.purge_cached_fn(ctx); + } + break; + case SMBC_FILE_SHARE: + case SMBC_DIR: + case SMBC_FILE: + if (maxlen < len + strlen(list->name) + 2) break; + + smb_path[len] = '/'; + strcpy(smb_path + len + 1, list->name); + print_smb_path(smb_group, smb_path + 6); + if (list->type != SMBC_FILE){ + recurse(ctx, smb_group, smb_path, maxlen); + if (list->type == SMBC_FILE_SHARE) + ctx->callbacks.purge_cached_fn(ctx); + } + break; + } + item = list; + list = list->next; + free(item); + } + smb_path[len] = '\0'; +} + +int main(int argc, char *argv[]){ + int i; + SMBCCTX *ctx; + char smb_path[32768] = "smb://"; + + if ((ctx = create_smbctx()) == NULL){ + perror("Cant create samba context."); + return 1; + } + + if (argc == 1) recurse(ctx, "", smb_path, sizeof(smb_path)); + else for(i = 1; i < argc; i++){ + strncpy(smb_path + 6, argv[i], sizeof(smb_path) - 7); + smb_path[sizeof(smb_path) - 1] = '\0'; + recurse(ctx, "", smb_path, sizeof(smb_path)); + } + + delete_smbctx(ctx); + return 0; +} -- cgit From 765daab643c2957297e71b26de515c05b04d244d Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 14 Dec 2005 04:00:58 +0000 Subject: r12225: r11729@cabra: derrell | 2005-12-13 22:59:45 -0500 1. Fix a crash bug which should have reared its ugly head ages ago, but for some reason, remained dormant until recently. The bug pertained to libsmbclient doing a structure assignment of a cli after having opened a pipe. The pipe open code makes a copy of the cli pointer that was passed to it. If the cli is later copied (and that cli pointer that was saved is no longer valid), the pipe code will cause a crash during shutdown or when the copied cli is closed. 2. The 'type' field in enumerated shares was not being set correctly with the new RPC-based mechanism for enumerating shares. (This used to be commit 62a02b8f2a1fcb66881a9c9636e0b27e3049c5a1) --- examples/libsmbclient/testbrowse2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testbrowse2.c b/examples/libsmbclient/testbrowse2.c index a3d2cf3b8e..76d98b9602 100644 --- a/examples/libsmbclient/testbrowse2.c +++ b/examples/libsmbclient/testbrowse2.c @@ -85,7 +85,7 @@ void smbc_auth_fn( strncpy(wrkgrp, workgroup, wrkgrplen - 1); wrkgrp[wrkgrplen - 1] = 0; strncpy(user, username, userlen - 1); user[userlen - 1] = 0; - strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0; + strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0; } SMBCCTX* create_smbctx(){ -- cgit From 9d36d5ee2dc42b55e97ff23f2ee2b9ac11aba116 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 25 Dec 2005 02:00:35 +0000 Subject: r12467: r12029@cabra: derrell | 2005-12-24 20:25:59 -0500 add another libsmbclient test program (This used to be commit 133cd3952b7f5fc9e9ca8d82a33ed1272067a6c8) --- examples/libsmbclient/Makefile | 5 +++++ examples/libsmbclient/teststat.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index c324a578d1..a88f4a240c 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -17,6 +17,7 @@ TESTS= testsmbc \ testbrowse \ testbrowse2 \ teststat \ + teststat2 \ testchmod \ testutime \ testread @@ -47,6 +48,10 @@ teststat: teststat.o @echo Linking teststat @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< +teststat2: teststat2.o + @echo Linking teststat2 + @$(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 $< diff --git a/examples/libsmbclient/teststat.c b/examples/libsmbclient/teststat.c index 29517efb6f..86c69e4e2c 100644 --- a/examples/libsmbclient/teststat.c +++ b/examples/libsmbclient/teststat.c @@ -48,7 +48,7 @@ int main(int argc, char * argv[]) return 1; } - printf("SAMBA\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", + printf("\nSAMBA\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)); -- cgit From 494e332220686c5410aa26b305bc037b400b4b4f Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 25 Dec 2005 02:03:51 +0000 Subject: r12468: r12033@cabra: derrell | 2005-12-24 21:03:45 -0500 actually add the new test program (This used to be commit e3bab0cc437f3c51c74e438d8d76ffd8afe8644c) --- examples/libsmbclient/teststat2.c | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 examples/libsmbclient/teststat2.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/teststat2.c b/examples/libsmbclient/teststat2.c new file mode 100644 index 0000000000..d1cdf28501 --- /dev/null +++ b/examples/libsmbclient/teststat2.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include "get_auth_data_fn.h" + +/* + * This test is intended to ensure that the timestamps returned by + * libsmbclient are the same as timestamps returned by the local system. To + * test this, we assume a working Samba environment, and and access the same + * file via SMB and locally (or NFS). + * + */ + + +static int gettime(const char * pUrl, + const char * pLocalPath); + + +int main(int argc, char* argv[]) +{ + if(argc != 3) + { + printf("usage: %s \n", argv[0]); + return 1; + } + + gettime(argv[1], argv[2]); + return 0; +} + + +static int gettime(const char * pUrl, + const char * pLocalPath) +{ + //char *pSmbPath = 0; + struct stat st; + char mtime[32]; + char ctime[32]; + char atime[32]; + + smbc_init(get_auth_data_fn, 0); + + if (smbc_stat(pUrl, &st) < 0) + { + perror("smbc_stat"); + return 1; + } + + 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)); + + + // check the stat on this file + if (stat(pLocalPath, &st) < 0) + { + perror("stat"); + return 1; + } + + 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; +} + -- cgit From e13d0cb3ec89d83db8893341ca7ae24c07aad1fb Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 29 Dec 2005 16:26:06 +0000 Subject: r12576: r12115@cabra: derrell | 2005-12-29 11:16:03 -0500 bug (enhancement) #2651: add option to log debug messages to stderr instead of stdout (This used to be commit 4182eb99af5b343291a661a87d08edd91fd09a7a) --- examples/libsmbclient/testbrowse.c | 46 ++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 6fa70eab41..eba6fff4eb 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -29,6 +29,7 @@ int main(int argc, char * argv[]) { int debug = 0; + int debug_stderr = 0; int scan = 0; int iterations = -1; int again; @@ -37,6 +38,7 @@ main(int argc, char * argv[]) char * q; char buf[1024]; poptContext pc; + SMBCCTX * context; struct poptOption long_options[] = { POPT_AUTOHELP @@ -44,6 +46,10 @@ main(int argc, char * argv[]) "debug", 'd', POPT_ARG_INT, &debug, 0, "Set debug level", "integer" }, + { + "stderr", 'e', POPT_ARG_NONE, &debug_stderr, + 0, "Debug log to stderr instead of stdout", "integer" + }, { "scan", 's', POPT_ARG_NONE, &scan, 0, "Scan for servers and shares", "integer" @@ -69,14 +75,36 @@ main(int argc, char * argv[]) } } + /* Allocate a new context */ + context = smbc_new_context(); + if (!context) { + printf("Could not allocate new smbc context\n"); + return 1; + } + + /* Set mandatory options (is that a contradiction in terms?) */ + context->debug = debug; + context->callbacks.auth_fn = (scan ? no_auth_data_fn : 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_stderr", NULL); + } + + /* Initialize the context using the previously specified options */ + if (!smbc_init_context(context)) { + smbc_free_context(context, 0); + printf("Could not initialize smbc context\n"); + return 1; + } + + /* Tell the compatibility layer to use this context */ + smbc_set_context(context); + + if (scan) { - if (smbc_init(no_auth_data_fn, debug) != 0) - { - printf("Could not initialize smbc_ library\n"); - return 1; - } - for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) @@ -87,12 +115,6 @@ main(int argc, char * argv[]) } else { - if (smbc_init(get_auth_data_fn, debug) != 0) - { - printf("Could not initialize smbc_ library\n"); - return 1; - } - for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) -- cgit From cbc97b4e5aee1fe6488ef316374b75a58b667ccc Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 29 Dec 2005 17:03:39 +0000 Subject: r12579: r12122@cabra: derrell | 2005-12-29 12:03:00 -0500 allow for arbitrary option value types (This used to be commit 64c8e32b6382e48bce5c1f18179e66ca765a70af) --- examples/libsmbclient/testbrowse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index eba6fff4eb..b5337ae983 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -89,7 +89,7 @@ main(int argc, char * argv[]) /* 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_stderr", NULL); + smbc_option_set(context, "debug_stderr"); } /* Initialize the context using the previously specified options */ -- cgit From 9a8ca1901c7520a140eaf9208e0b056c93d8471c Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 7 Jan 2006 20:43:28 +0000 Subject: r12757: r12126@cabra: derrell | 2006-01-03 15:21:36 -0500 added flag to not request authentication information (This used to be commit 8396c4b26c9911887ed1c1ce17c31af462ee6883) --- examples/libsmbclient/testbrowse.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index b5337ae983..ca126c9510 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -30,6 +30,7 @@ main(int argc, char * argv[]) { int debug = 0; int debug_stderr = 0; + int no_auth = 0; int scan = 0; int iterations = -1; int again; @@ -58,6 +59,10 @@ main(int argc, char * argv[]) "iterations", 'i', POPT_ARG_INT, &iterations, 0, "Iterations", "integer" }, + { + "noauth", 'A', POPT_ARG_NONE, &no_auth, + 0, "Do not request authentication data", "integer" + }, { NULL } @@ -82,9 +87,14 @@ main(int argc, char * argv[]) return 1; } + /* If we're scanning, do no requests for authentication data */ + if (scan) { + no_auth = 1; + } + /* Set mandatory options (is that a contradiction in terms?) */ context->debug = debug; - context->callbacks.auth_fn = (scan ? no_auth_data_fn : get_auth_data_fn); + context->callbacks.auth_fn = (no_auth ? no_auth_data_fn : get_auth_data_fn); /* If we've been asked to log to stderr instead of stdout... */ if (debug_stderr) { @@ -102,7 +112,6 @@ main(int argc, char * argv[]) /* Tell the compatibility layer to use this context */ smbc_set_context(context); - if (scan) { for (; -- cgit From 96d0d186db42c61fa907b9b24f412b834359e2d8 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 7 Jan 2006 20:43:36 +0000 Subject: r12759: r12128@cabra: derrell | 2006-01-07 15:34:01 -0500 Incorporate a number of changes suggested by David Collier-Brown Thanks, David! (This used to be commit 0ae65b9af566e02eece9bb7865047c037468d470) --- examples/libsmbclient/smbwrapper/Makefile | 7 +- examples/libsmbclient/smbwrapper/bsd-strlcat.c | 71 ++++ examples/libsmbclient/smbwrapper/bsd-strlcpy.c | 67 +++ examples/libsmbclient/smbwrapper/bsd-strlfunc.h | 7 + examples/libsmbclient/smbwrapper/smbsh.c | 25 +- examples/libsmbclient/smbwrapper/smbw.c | 37 +- examples/libsmbclient/smbwrapper/smbw.h | 4 + examples/libsmbclient/smbwrapper/smbw_dir.c | 29 +- examples/libsmbclient/smbwrapper/wrapper.c | 515 ++++++++++++------------ examples/libsmbclient/smbwrapper/wrapper.h | 4 + 10 files changed, 479 insertions(+), 287 deletions(-) create mode 100644 examples/libsmbclient/smbwrapper/bsd-strlcat.c create mode 100644 examples/libsmbclient/smbwrapper/bsd-strlcpy.c create mode 100644 examples/libsmbclient/smbwrapper/bsd-strlfunc.h (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/Makefile b/examples/libsmbclient/smbwrapper/Makefile index 8e7070cb59..c94ef8fa6a 100644 --- a/examples/libsmbclient/smbwrapper/Makefile +++ b/examples/libsmbclient/smbwrapper/Makefile @@ -10,8 +10,11 @@ CFLAGS= -fpic -g -O0 $(DEFS) $(SMBINCLUDE) BIN = . -SMBWRAPPER_OBJS = smbw.o smbw_dir.o smbw_stat.o wrapper.o select.o -SMBSH_OBJS = smbsh.o +STRFUNC = bsd-strlcat.o bsd-strlcpy.o + + +SMBWRAPPER_OBJS = smbw.o smbw_dir.o smbw_stat.o wrapper.o select.o $(STRFUNC) +SMBSH_OBJS = smbsh.o $(STRFUNC) all: $(BIN)/smbwrapper.so $(BIN)/smbsh diff --git a/examples/libsmbclient/smbwrapper/bsd-strlcat.c b/examples/libsmbclient/smbwrapper/bsd-strlcat.c new file mode 100644 index 0000000000..d82ced3e8a --- /dev/null +++ b/examples/libsmbclient/smbwrapper/bsd-strlcat.c @@ -0,0 +1,71 @@ +/* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This version has been modified for inclusion in Samba. + * It has been converted to ANSI C from old-style K&R C. + */ + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +smbw_strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/examples/libsmbclient/smbwrapper/bsd-strlcpy.c b/examples/libsmbclient/smbwrapper/bsd-strlcpy.c new file mode 100644 index 0000000000..9f7e55da8e --- /dev/null +++ b/examples/libsmbclient/smbwrapper/bsd-strlcpy.c @@ -0,0 +1,67 @@ +/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This version has been modified for inclusion in Samba. + * It has been converted to ANSI C from old-style K&R C. + */ + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +smbw_strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/examples/libsmbclient/smbwrapper/bsd-strlfunc.h b/examples/libsmbclient/smbwrapper/bsd-strlfunc.h new file mode 100644 index 0000000000..fb3a045ac6 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/bsd-strlfunc.h @@ -0,0 +1,7 @@ +#ifndef __BSD_STRLFUNC_H__ + +extern size_t strlcpy(char *dst, const char *src, size_t siz); +extern size_t strlcat(char *dst, const char *src, size_t siz); + +#define __BSD_STRLFUNC_H__ +#endif diff --git a/examples/libsmbclient/smbwrapper/smbsh.c b/examples/libsmbclient/smbwrapper/smbsh.c index 7b33de766f..23b1ac26c7 100644 --- a/examples/libsmbclient/smbwrapper/smbsh.c +++ b/examples/libsmbclient/smbwrapper/smbsh.c @@ -28,6 +28,7 @@ #include #include #include +#include "bsd-strlfunc.h" #ifndef FALSE # define FALSE (0) @@ -67,13 +68,13 @@ int main(int argc, char *argv[]) switch (opt) { case 'p': /* prepend library before smbwrapper.so */ if (*pre != '\0') - strncat(pre, " ", PATH_MAX - strlen(pre)); - strncat(pre, optarg, PATH_MAX - strlen(pre)); + smbw_strlcat(pre, " ", sizeof(pre)); + smbw_strlcat(pre, optarg, sizeof(pre)); break; case 'a': /* append library after smbwrapper.so */ - strncat(post, " ", PATH_MAX - strlen(post)); - strncat(post, optarg, PATH_MAX - strlen(post)); + smbw_strlcat(post, " ", sizeof(post)); + smbw_strlcat(post, optarg, sizeof(post)); break; case 'd': @@ -121,20 +122,22 @@ int main(int argc, char *argv[]) } } - strncpy(line, pre, PATH_MAX - strlen(line)); - strncat(line, " ", PATH_MAX - strlen(line)); - strncat(line, libd, PATH_MAX - strlen(line)); - strncat(line, "/smbwrapper.so", PATH_MAX - strlen(line)); - strncat(line, post, PATH_MAX - strlen(line)); + smbw_strlcpy(line, pre, PATH_MAX - strlen(line)); + smbw_strlcat(line, " ", sizeof(line)); + smbw_strlcat(line, libd, sizeof(line)); + smbw_strlcat(line, "/smbwrapper.so", sizeof(line)); + smbw_strlcat(line, post, sizeof(line)); setenv("LD_PRELOAD", line, TRUE); setenv("LD_BIND_NOW", "true", TRUE); snprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd); if (stat(line, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) { - snprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd); + snprintf(line, sizeof(line)-1, + "%s/smbwrapper.32.so:DEFAULT", libd); setenv("_RLD_LIST", line, TRUE); - snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); + snprintf(line, sizeof(line)-1, + "%s/smbwrapper.so:DEFAULT", libd); setenv("_RLDN32_LIST", line, TRUE); } else { snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); diff --git a/examples/libsmbclient/smbwrapper/smbw.c b/examples/libsmbclient/smbwrapper/smbw.c index d2f1c18695..a44f2f4046 100644 --- a/examples/libsmbclient/smbwrapper/smbw.c +++ b/examples/libsmbclient/smbwrapper/smbw.c @@ -26,6 +26,13 @@ #include #include #include "smbw.h" +#include "bsd-strlfunc.h" + +typedef enum StartupType +{ + StartupType_Fake, + StartupType_Real +} StartupType; int smbw_fd_map[__FD_SETSIZE]; int smbw_ref_count[__FD_SETSIZE]; @@ -44,6 +51,9 @@ static SMBCCTX *smbw_ctx; extern int smbw_debug; +/***************************************************** +smbw_ref -- manipulate reference counts +******************************************************/ int smbw_ref(int client_fd, Ref_Count_Type type, ...) { va_list ap; @@ -100,9 +110,9 @@ static void get_envvar_auth_data(const char *srv, p = getenv("PASSWORD"); if (p == NULL) p = ""; - strncpy(wg, w, wglen); - strncpy(un, u, unlen); - strncpy(pw, p, pwlen); + smbw_strlcpy(wg, w, wglen); + smbw_strlcpy(un, u, unlen); + smbw_strlcpy(pw, p, pwlen); } static smbc_get_auth_data_fn get_auth_data_fn = get_envvar_auth_data; @@ -130,7 +140,7 @@ static void do_shutdown(void) /***************************************************** initialise structures *******************************************************/ -static void do_init(int is_real_startup) +static void do_init(StartupType startupType) { int i; char *p; @@ -147,7 +157,7 @@ static void do_init(int is_real_startup) /* See if we've been told to start in a particular directory */ if ((p=getenv("SMBW_DIR")) != NULL) { - strncpy(smbw_cwd, p, PATH_MAX); + smbw_strlcpy(smbw_cwd, p, PATH_MAX); /* we don't want the old directory to be busy */ (* smbw_libc.chdir)("/"); @@ -161,6 +171,7 @@ static void do_init(int is_real_startup) } if ((smbw_ctx = smbc_new_context()) == NULL) { + fprintf(stderr, "Could not create a context.\n"); exit(1); } @@ -169,16 +180,16 @@ static void do_init(int is_real_startup) smbw_ctx->options.browse_max_lmb_count = 0; smbw_ctx->options.urlencode_readdir_entries = 1; smbw_ctx->options.one_share_per_server = 1; -// smbw_cache_functions(smbw_ctx); if (smbc_init_context(smbw_ctx) == NULL) { + fprintf(stderr, "Could not initialize context.\n"); exit(1); } smbc_set_context(smbw_ctx); /* if not real startup, exit handler has already been established */ - if (is_real_startup) { + if (startupType == StartupType_Real) { atexit(do_shutdown); } } @@ -188,7 +199,7 @@ initialise structures, real start up vs a fork() *******************************************************/ void smbw_init(void) { - do_init(1); + do_init(StartupType_Real); } @@ -407,6 +418,10 @@ ssize_t smbw_pread(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs) int saved_errno; SMBW_OFF_T old_ofs; + if (count == 0) { + return 0; + } + client_fd = smbw_fd_map[smbw_fd]; if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 || @@ -460,6 +475,10 @@ ssize_t smbw_pwrite(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs) ssize_t ret; SMBW_OFF_T old_ofs; + if (count == 0) { + return 0; + } + client_fd = smbw_fd_map[smbw_fd]; if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 || @@ -731,7 +750,7 @@ int smbw_fork(void) } /* Re-initialize this library for the child */ - do_init(0); + do_init(StartupType_Fake); /* and continue in the child */ return 0; diff --git a/examples/libsmbclient/smbwrapper/smbw.h b/examples/libsmbclient/smbwrapper/smbw.h index 717b5c2f1c..161d57ebbb 100644 --- a/examples/libsmbclient/smbwrapper/smbw.h +++ b/examples/libsmbclient/smbwrapper/smbw.h @@ -34,6 +34,10 @@ #include "libsmbclient.h" #include "wrapper.h" +#ifndef __restrict +# define __restrict +#endif + #undef DEBUG #define DEBUG(level, s) do { if (level <= debug_level) printf s; } while (0) diff --git a/examples/libsmbclient/smbwrapper/smbw_dir.c b/examples/libsmbclient/smbwrapper/smbw_dir.c index f3ec03e5a8..986b7f8220 100644 --- a/examples/libsmbclient/smbwrapper/smbw_dir.c +++ b/examples/libsmbclient/smbwrapper/smbw_dir.c @@ -21,6 +21,7 @@ */ #include "smbw.h" +#include "bsd-strlfunc.h" /***************************************************** determine if a directory handle is a smb one @@ -70,12 +71,12 @@ int smbw_getdents(unsigned int fd_smbw, dirent_external->d_reclen = sizeof(struct SMBW_dirent); dirent_external->d_type = dirent_internal->smbc_type; - strncpy(dirent_external->d_name, - dirent_internal->name, - sizeof(dirent_external->d_name) - 1); - strncpy(dirent_external->d_comment, - dirent_internal->comment, - sizeof(dirent_external->d_comment) - 1); + smbw_strlcpy(dirent_external->d_name, + dirent_internal->name, + sizeof(dirent_external->d_name) - 1); + smbw_strlcpy(dirent_external->d_comment, + dirent_internal->comment, + sizeof(dirent_external->d_comment) - 1); } return(count - remaining); @@ -128,7 +129,7 @@ int smbw_chdir(const char *name) } } - strncpy(smbw_cwd, path, PATH_MAX); + smbw_strlcpy(smbw_cwd, path, PATH_MAX); /* we don't want the old directory to be busy */ (* smbw_libc.chdir)("/"); @@ -196,7 +197,7 @@ char *smbw_getcwd(char *buf, size_t size) } } - strncpy(buf, smbw_cwd, size); + smbw_strlcpy(buf, smbw_cwd, size); buf[size-1] = '\0'; return buf; } @@ -278,12 +279,12 @@ struct SMBW_dirent *smbw_readdir(DIR *dirp) dirent_external.d_off = smbc_telldir(fd_client); dirent_external.d_reclen = sizeof(struct SMBW_dirent); dirent_external.d_type = dirent_internal->smbc_type; - strncpy(dirent_external.d_name, - dirent_internal->name, - sizeof(dirent_external.d_name) - 1); - strncpy(dirent_external.d_comment, - dirent_internal->comment, - sizeof(dirent_external.d_comment) - 1); + smbw_strlcpy(dirent_external.d_name, + dirent_internal->name, + sizeof(dirent_external.d_name) - 1); + smbw_strlcpy(dirent_external.d_comment, + dirent_internal->comment, + sizeof(dirent_external.d_comment) - 1); return &dirent_external; } diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c index 71d6f203ad..12904c3073 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.c +++ b/examples/libsmbclient/smbwrapper/wrapper.c @@ -65,6 +65,7 @@ #include #include #include "libsmbclient.h" +#include "bsd-strlfunc.h" #include "wrapper.h" /* @@ -106,12 +107,12 @@ static int debugFd = 2; if (! initialized) initialize(); \ (* smbw_libc.write)(debugFd, "["buf"]", sizeof(buf)+1); \ errno = saved_errno; \ - } while (0); + } while (0) #else # define check_init(buf) \ do { \ if (! initialized) smbw_initialize(); \ - } while (0); + } while (0) #endif static void initialize(void); @@ -135,17 +136,20 @@ static void initialize(void) #if SMBW_DEBUG & 0x1 char *error; #endif - + saved_errno = errno; if (initialized) { - errno = saved_errno; return; } initialized = 1; if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { +#ifdef RTLD_NEXT + lib = RTLD_NEXT; +#else exit(1); +#endif } #if SMBW_DEBUG & 0x1 @@ -171,117 +175,122 @@ static void initialize(void) * C library doesn't support them, then the wrapper function will * never be called, and the null pointer will never be dereferenced. */ - do { - GETSYM(write, "write"); /* first, to allow debugging */ - GETSYM(open, "open"); - GETSYM(_open, "_open"); - GETSYM(__open, "__open"); - GETSYM(open64, "open64"); - GETSYM(_open64, "_open64"); - GETSYM(__open64, "__open64"); - GETSYM(pread, "pread"); - GETSYM(pread64, "pread64"); - GETSYM(pwrite, "pwrite"); - GETSYM(pwrite64, "pwrite64"); - GETSYM(close, "close"); - GETSYM(__close, "__close"); - GETSYM(_close, "_close"); - GETSYM(fcntl, "fcntl"); - GETSYM(__fcntl, "__fcntl"); - GETSYM(_fcntl, "_fcntl"); - GETSYM(getdents, "getdents"); - GETSYM(__getdents, "__getdents"); - GETSYM(_getdents, "_getdents"); - GETSYM(getdents64, "getdents64"); - GETSYM(lseek, "lseek"); - GETSYM(__lseek, "__lseek"); - GETSYM(_lseek, "_lseek"); - GETSYM(lseek64, "lseek64"); - GETSYM(__lseek64, "__lseek64"); - GETSYM(_lseek64, "_lseek64"); - GETSYM(read, "read"); - GETSYM(__read, "__read"); - GETSYM(_read, "_read"); - GETSYM(__write, "__write"); - GETSYM(_write, "_write"); - GETSYM(access, "access"); - GETSYM(chmod, "chmod"); - GETSYM(fchmod, "fchmod"); - GETSYM(chown, "chown"); - GETSYM(fchown, "fchown"); - GETSYM(__xstat, "__xstat"); - GETSYM(getcwd, "getcwd"); - GETSYM(mkdir, "mkdir"); - GETSYM(__fxstat, "__fxstat"); - GETSYM(__lxstat, "__lxstat"); - GETSYM(stat, "stat"); - GETSYM(lstat, "lstat"); - GETSYM(fstat, "fstat"); - GETSYM(unlink, "unlink"); - GETSYM(utime, "utime"); - GETSYM(utimes, "utimes"); - GETSYM(readlink, "readlink"); - GETSYM(rename, "rename"); - GETSYM(rmdir, "rmdir"); - GETSYM(symlink, "symlink"); - GETSYM(dup, "dup"); - GETSYM(dup2, "dup2"); - GETSYM(opendir, "opendir"); - GETSYM(readdir, "readdir"); - GETSYM(closedir, "closedir"); - GETSYM(telldir, "telldir"); - GETSYM(seekdir, "seekdir"); - GETSYM(creat, "creat"); - GETSYM(creat64, "creat64"); - GETSYM(__xstat64, "__xstat64"); - GETSYM(stat64, "stat64"); - GETSYM(__fxstat64, "__fxstat64"); - GETSYM(fstat64, "fstat64"); - GETSYM(__lxstat64, "__lxstat64"); - GETSYM(lstat64, "lstat64"); - GETSYM(_llseek, "_llseek"); - GETSYM(readdir64, "readdir64"); - GETSYM(readdir_r, "readdir_r"); - GETSYM(readdir64_r, "readdir64_r"); - GETSYM(setxattr, "setxattr"); - GETSYM(lsetxattr, "lsetxattr"); - GETSYM(fsetxattr, "fsetxattr"); - GETSYM(getxattr, "getxattr"); - GETSYM(lgetxattr, "lgetxattr"); - GETSYM(fgetxattr, "fgetxattr"); - GETSYM(removexattr, "removexattr"); - GETSYM(lremovexattr, "lremovexattr"); - GETSYM(fremovexattr, "fremovexattr"); - GETSYM(listxattr, "listxattr"); - GETSYM(llistxattr, "llistxattr"); - GETSYM(flistxattr, "flistxattr"); - GETSYM(chdir, "chdir"); - GETSYM(fchdir, "fchdir"); - GETSYM(fork, "fork"); - GETSYM(select, "select"); - GETSYM(_select, "_select"); - GETSYM(__select, "__select"); - } while (0); + GETSYM(write, "write"); /* first, to allow debugging */ + GETSYM(open, "open"); + GETSYM(_open, "_open"); + GETSYM(__open, "__open"); + GETSYM(open64, "open64"); + GETSYM(_open64, "_open64"); + GETSYM(__open64, "__open64"); + GETSYM(pread, "pread"); + GETSYM(pread64, "pread64"); + GETSYM(pwrite, "pwrite"); + GETSYM(pwrite64, "pwrite64"); + GETSYM(close, "close"); + GETSYM(__close, "__close"); + GETSYM(_close, "_close"); + GETSYM(fcntl, "fcntl"); + GETSYM(__fcntl, "__fcntl"); + GETSYM(_fcntl, "_fcntl"); + GETSYM(getdents, "getdents"); + GETSYM(__getdents, "__getdents"); + GETSYM(_getdents, "_getdents"); + GETSYM(getdents64, "getdents64"); + GETSYM(lseek, "lseek"); + GETSYM(__lseek, "__lseek"); + GETSYM(_lseek, "_lseek"); + GETSYM(lseek64, "lseek64"); + GETSYM(__lseek64, "__lseek64"); + GETSYM(_lseek64, "_lseek64"); + GETSYM(read, "read"); + GETSYM(__read, "__read"); + GETSYM(_read, "_read"); + GETSYM(__write, "__write"); + GETSYM(_write, "_write"); + GETSYM(access, "access"); + GETSYM(chmod, "chmod"); + GETSYM(fchmod, "fchmod"); + GETSYM(chown, "chown"); + GETSYM(fchown, "fchown"); + GETSYM(__xstat, "__xstat"); + GETSYM(getcwd, "getcwd"); + GETSYM(mkdir, "mkdir"); + GETSYM(__fxstat, "__fxstat"); + GETSYM(__lxstat, "__lxstat"); + GETSYM(stat, "stat"); + GETSYM(lstat, "lstat"); + GETSYM(fstat, "fstat"); + GETSYM(unlink, "unlink"); + GETSYM(utime, "utime"); + GETSYM(utimes, "utimes"); + GETSYM(readlink, "readlink"); + GETSYM(rename, "rename"); + GETSYM(rmdir, "rmdir"); + GETSYM(symlink, "symlink"); + GETSYM(dup, "dup"); + GETSYM(dup2, "dup2"); + GETSYM(opendir, "opendir"); + GETSYM(readdir, "readdir"); + GETSYM(closedir, "closedir"); + GETSYM(telldir, "telldir"); + GETSYM(seekdir, "seekdir"); + GETSYM(creat, "creat"); + GETSYM(creat64, "creat64"); + GETSYM(__xstat64, "__xstat64"); + GETSYM(stat64, "stat64"); + GETSYM(__fxstat64, "__fxstat64"); + GETSYM(fstat64, "fstat64"); + GETSYM(__lxstat64, "__lxstat64"); + GETSYM(lstat64, "lstat64"); + GETSYM(_llseek, "_llseek"); + GETSYM(readdir64, "readdir64"); + GETSYM(readdir_r, "readdir_r"); + GETSYM(readdir64_r, "readdir64_r"); + GETSYM(setxattr, "setxattr"); + GETSYM(lsetxattr, "lsetxattr"); + GETSYM(fsetxattr, "fsetxattr"); + GETSYM(getxattr, "getxattr"); + GETSYM(lgetxattr, "lgetxattr"); + GETSYM(fgetxattr, "fgetxattr"); + GETSYM(removexattr, "removexattr"); + GETSYM(lremovexattr, "lremovexattr"); + GETSYM(fremovexattr, "fremovexattr"); + GETSYM(listxattr, "listxattr"); + GETSYM(llistxattr, "llistxattr"); + GETSYM(flistxattr, "flistxattr"); + GETSYM(chdir, "chdir"); + GETSYM(fchdir, "fchdir"); + GETSYM(fork, "fork"); + GETSYM(select, "select"); + GETSYM(_select, "_select"); + GETSYM(__select, "__select"); +#ifdef RTLD_NEXT + if (lib != RTLD_NEXT) { + dlclose(lib); + } +#else dlclose(lib); - +#endif + + /* Ensure that the C library is immediately available */ if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { exit(1); } #if SMBW_DEBUG & 4 { - if ((debugFd = - open(SMBW_DEBUG_FILE, O_WRONLY | O_CREAT | O_APPEND)) < 0) - { + if ((debugFd = + open(SMBW_DEBUG_FILE, O_WRONLY | O_CREAT | O_APPEND)) < 0) + { # define SMBW_MESSAGE "Could not create " SMBW_DEBUG_FILE "\n" - (* smbw_libc.write)(1, SMBW_MESSAGE, sizeof(SMBW_MESSAGE)); + (* smbw_libc.write)(1, SMBW_MESSAGE, sizeof(SMBW_MESSAGE)); # undef SMBW_MESSAGE - exit(1); - } + exit(1); + } } #endif - + errno = saved_errno; } @@ -328,11 +337,11 @@ static void stat64_convert(struct SMBW_stat *src, struct stat64 *dest) static void dirent_convert(struct SMBW_dirent *src, struct dirent *dest) { char *p; - + memset(dest, '\0', sizeof(*dest)); dest->d_ino = src->d_ino; dest->d_off = src->d_off; - + switch(src->d_type) { case SMBC_WORKGROUP: @@ -362,21 +371,23 @@ static void dirent_convert(struct SMBW_dirent *src, struct dirent *dest) dest->d_type = DT_LNK; break; } - + dest->d_reclen = src->d_reclen; - strncpy(dest->d_name, src->d_name, sizeof(dest->d_name)); + smbw_strlcpy(dest->d_name, src->d_name, sizeof(dest->d_name)); p = dest->d_name + strlen(dest->d_name) + 1; - strncpy(p, src->d_comment, sizeof(dest->d_name) - (p - dest->d_name)); + smbw_strlcpy(p, + src->d_comment, + sizeof(dest->d_name) - (p - dest->d_name)); } static void dirent64_convert(struct SMBW_dirent *src, struct dirent64 *dest) { char *p; - + memset(dest, '\0', sizeof(*dest)); dest->d_ino = src->d_ino; dest->d_off = src->d_off; - + switch(src->d_type) { case SMBC_WORKGROUP: @@ -406,11 +417,13 @@ static void dirent64_convert(struct SMBW_dirent *src, struct dirent64 *dest) dest->d_type = DT_LNK; break; } - + dest->d_reclen = src->d_reclen; - strncpy(dest->d_name, src->d_name, sizeof(dest->d_name)); + smbw_strlcpy(dest->d_name, src->d_name, sizeof(dest->d_name)); p = dest->d_name + strlen(dest->d_name) + 1; - strncpy(p, src->d_comment, sizeof(dest->d_name) - (p - dest->d_name)); + smbw_strlcpy(p, + src->d_comment, + sizeof(dest->d_name) - (p - dest->d_name)); } static int openx(char *name, int flags, mode_t mode, int (* f)(char *, int, mode_t)) @@ -418,7 +431,7 @@ static int openx(char *name, int flags, mode_t mode, int (* f)(char *, int, mode if (smbw_path(name)) { return smbw_open(name, flags, mode); } - + return (* f)(name, flags, mode); } @@ -427,7 +440,7 @@ static int closex(int fd, int (* f)(int fd)) if (smbw_fd(fd)) { return smbw_close(fd); } - + return (* f)(fd); } @@ -436,7 +449,7 @@ static int fcntlx(int fd, int cmd, long arg, int (* f)(int, int, long)) if (smbw_fd(fd)) { return smbw_fcntl(fd, cmd, arg); } - + return (* f)(fd, cmd, arg); } @@ -448,14 +461,14 @@ static int getdentsx(int fd, struct dirent *external, unsigned int count, int (* struct SMBW_dirent *internal; int ret; int n; - + /* * LIMITATION: If they pass a count which is not a multiple of * the size of struct dirent, they will not get a partial * structure; we ignore the excess count. */ n = (count / sizeof(struct dirent)); - + internal_count = sizeof(struct SMBW_dirent) * n; internal = malloc(internal_count); if (internal == NULL) { @@ -465,15 +478,15 @@ static int getdentsx(int fd, struct dirent *external, unsigned int count, int (* ret = smbw_getdents(fd, internal, internal_count); if (ret <= 0) return ret; - + ret = sizeof(struct dirent) * n; for (i = 0; i < n; i++) dirent_convert(&internal[i], &external[i]); - + return ret; } - + return (* f)(fd, external, count); } @@ -483,7 +496,7 @@ static off_t lseekx(int fd, off_t (* f)(int, off_t, int)) { off_t ret; - + /* * We have left the definitions of the smbw_ functions undefined, * because types such as off_t can differ in meaning betweent his @@ -491,11 +504,11 @@ static off_t lseekx(int fd, * integer value, however, MUST have their return value defined. */ off64_t smbw_lseek(); - + if (smbw_fd(fd)) { return (off_t) smbw_lseek(fd, offset, whence); } - + ret = (* f)(fd, offset, whence); if (smbw_debug) { @@ -513,7 +526,7 @@ static off64_t lseek64x(int fd, off64_t (* f)(int, off64_t, int)) { off64_t ret; - + /* * We have left the definitions of the smbw_ functions undefined, * because types such as off_t can differ in meaning betweent his @@ -521,7 +534,7 @@ static off64_t lseek64x(int fd, * integer value, however, MUST have their return value defined. */ off64_t smbw_lseek(); - + if (smbw_fd(fd)) ret = smbw_lseek(fd, offset, whence); else @@ -541,7 +554,7 @@ static ssize_t readx(int fd, void *buf, size_t count, ssize_t (* f)(int, void *, if (smbw_fd(fd)) { return smbw_read(fd, buf, count); } - + return (* f)(fd, buf, count); } @@ -550,7 +563,7 @@ static ssize_t writex(int fd, void *buf, size_t count, ssize_t (* f)(int, void * if (smbw_fd(fd)) { return smbw_write(fd, buf, count); } - + return (* f)(fd, buf, count); } @@ -563,27 +576,27 @@ int open(__const char *name, int flags, ...) { va_list ap; mode_t mode; - + va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); - + check_init("open"); - + return openx((char *) name, flags, mode, smbw_libc.open); } int _open(char *name, int flags, mode_t mode) { check_init("open"); - + return openx(name, flags, mode, smbw_libc._open); } int __open(char *name, int flags, mode_t mode) { check_init("open"); - + return openx(name, flags, mode, smbw_libc.__open); } @@ -591,11 +604,11 @@ int open64 (__const char *name, int flags, ...) { va_list ap; mode_t mode; - + va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); - + check_init("open64"); return openx((char *) name, flags, mode, smbw_libc.open64); } @@ -615,44 +628,44 @@ int __open64(char *name, int flags, mode_t mode) ssize_t pread(int fd, void *buf, size_t size, off_t ofs) { check_init("pread"); - + if (smbw_fd(fd)) { return smbw_pread(fd, buf, size, ofs); } - + return (* smbw_libc.pread)(fd, buf, size, ofs); } ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs) { check_init("pread64"); - + if (smbw_fd(fd)) { return smbw_pread(fd, buf, size, (off_t) ofs); } - + return (* smbw_libc.pread64)(fd, buf, size, ofs); } ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) { check_init("pwrite"); - + if (smbw_fd(fd)) { return smbw_pwrite(fd, (void *) buf, size, ofs); } - + return (* smbw_libc.pwrite)(fd, (void *) buf, size, ofs); } ssize_t pwrite64(int fd, const void *buf, size_t size, off64_t ofs) { check_init("pwrite64"); - + if (smbw_fd(fd)) { return smbw_pwrite(fd, (void *) buf, size, (off_t) ofs); } - + return (* smbw_libc.pwrite64)(fd, (void *) buf, size, ofs); } @@ -714,11 +727,11 @@ int fcntl (int fd, int cmd, ...) { va_list ap; long arg; - + va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); - + check_init("fcntl"); return fcntlx(fd, cmd, arg, smbw_libc.fcntl); } @@ -727,11 +740,11 @@ int __fcntl(int fd, int cmd, ...) { va_list ap; long arg; - + va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); - + check_init("__fcntl"); return fcntlx(fd, cmd, arg, smbw_libc.__fcntl); } @@ -740,11 +753,11 @@ int _fcntl(int fd, int cmd, ...) { va_list ap; long arg; - + va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); - + check_init("_fcntl"); return fcntlx(fd, cmd, arg, smbw_libc._fcntl); } @@ -775,14 +788,14 @@ int getdents64(int fd, struct dirent64 *external, unsigned int count) struct SMBW_dirent *internal; int ret; int n; - + /* * LIMITATION: If they pass a count which is not a multiple of * the size of struct dirent, they will not get a partial * structure; we ignore the excess count. */ n = (count / sizeof(struct dirent64)); - + internal = malloc(sizeof(struct SMBW_dirent) * n); if (internal == NULL) { errno = ENOMEM; @@ -791,15 +804,15 @@ int getdents64(int fd, struct dirent64 *external, unsigned int count) ret = smbw_getdents(fd, internal, count); if (ret <= 0) return ret; - + ret = sizeof(struct dirent) * count; for (i = 0; count; i++, count--) dirent64_convert(&internal[i], &external[i]); - + return ret; } - + return (* smbw_libc.getdents64)(fd, external, count); } @@ -923,57 +936,57 @@ ssize_t _write(int fd, const void *buf, size_t count) int access(const char *name, int mode) { check_init("access"); - + if (smbw_path((char *) name)) { return smbw_access((char *) name, mode); } - + return (* smbw_libc.access)((char *) name, mode); } int chmod(const char *name, mode_t mode) { check_init("chmod"); - + if (smbw_path((char *) name)) { return smbw_chmod((char *) name, mode); } - + return (* smbw_libc.chmod)((char *) name, mode); } int fchmod(int fd, mode_t mode) { check_init("fchmod"); - + if (smbw_fd(fd)) { /* Not yet implemented in libsmbclient */ return ENOTSUP; } - + return (* smbw_libc.fchmod)(fd, mode); } int chown(const char *name, uid_t owner, gid_t group) { check_init("chown"); - + if (smbw_path((char *) name)) { return smbw_chown((char *) name, owner, group); } - + return (* smbw_libc.chown)((char *) name, owner, group); } int fchown(int fd, uid_t owner, gid_t group) { check_init("fchown"); - + if (smbw_fd(fd)) { /* Not yet implemented in libsmbclient */ return ENOTSUP; } - + return (* smbw_libc.fchown)(fd, owner, group); } @@ -986,148 +999,148 @@ char *getcwd(char *buf, size_t size) int mkdir(const char *name, mode_t mode) { check_init("mkdir"); - + if (smbw_path((char *) name)) { return smbw_mkdir((char *) name, mode); } - + return (* smbw_libc.mkdir)((char *) name, mode); } int __fxstat(int vers, int fd, struct stat *st) { check_init("__fxstat"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.__fxstat)(vers, fd, st); } int __xstat(int vers, const char *name, struct stat *st) { check_init("__xstat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.__xstat)(vers, (char *) name, st); } int __lxstat(int vers, const char *name, struct stat *st) { check_init("__lxstat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.__lxstat)(vers, (char *) name, st); } int stat(const char *name, struct stat *st) { check_init("stat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.stat)((char *) name, st); } int lstat(const char *name, struct stat *st) { check_init("lstat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.lstat)((char *) name, st); } int fstat(int fd, struct stat *st) { check_init("fstat"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.fstat)(fd, st); } int unlink(const char *name) { check_init("unlink"); - + if (smbw_path((char *) name)) { return smbw_unlink((char *) name); } - + return (* smbw_libc.unlink)((char *) name); } int utime(const char *name, const struct utimbuf *tvp) { check_init("utime"); - + if (smbw_path(name)) { return smbw_utime(name, (struct utimbuf *) tvp); } - + return (* smbw_libc.utime)((char *) name, (struct utimbuf *) tvp); } int utimes(const char *name, const struct timeval *tvp) { check_init("utimes"); - + if (smbw_path(name)) { return smbw_utimes(name, (struct timeval *) tvp); } - + return (* smbw_libc.utimes)((char *) name, (struct timeval *) tvp); } int readlink(const char *path, char *buf, size_t bufsize) { check_init("readlink"); - + if (smbw_path((char *) path)) { return smbw_readlink(path, (char *) buf, bufsize); } - + return (* smbw_libc.readlink)((char *) path, buf, bufsize); } int rename(const char *oldname, const char *newname) { int p1, p2; - + check_init("rename"); - + p1 = smbw_path((char *) oldname); p2 = smbw_path((char *) newname); if (p1 ^ p2) { @@ -1138,27 +1151,27 @@ int rename(const char *oldname, const char *newname) if (p1 && p2) { return smbw_rename((char *) oldname, (char *) newname); } - + return (* smbw_libc.rename)((char *) oldname, (char *) newname); } int rmdir(const char *name) { check_init("rmdir"); - + if (smbw_path((char *) name)) { return smbw_rmdir((char *) name); } - + return (* smbw_libc.rmdir)((char *) name); } int symlink(const char *topath, const char *frompath) { int p1, p2; - + check_init("symlink"); - + p1 = smbw_path((char *) topath); p2 = smbw_path((char *) frompath); if (p1 || p2) { @@ -1166,25 +1179,25 @@ int symlink(const char *topath, const char *frompath) errno = EPERM; return -1; } - + return (* smbw_libc.symlink)((char *) topath, (char *) frompath); } int dup(int fd) { check_init("dup"); - + if (smbw_fd(fd)) { return smbw_dup(fd); } - + return (* smbw_libc.dup)(fd); } int dup2(int oldfd, int newfd) { check_init("dup2"); - + if (smbw_fd(newfd)) { (* smbw_libc.close)(newfd); } @@ -1192,7 +1205,7 @@ int dup2(int oldfd, int newfd) if (smbw_fd(oldfd)) { return smbw_dup2(oldfd, newfd); } - + return (* smbw_libc.dup2)(oldfd, newfd); } @@ -1200,18 +1213,18 @@ int dup2(int oldfd, int newfd) DIR *opendir(const char *name) { check_init("opendir"); - + if (smbw_path((char *) name)) { return (void *)smbw_opendir((char *) name); } - + return (* smbw_libc.opendir)((char *) name); } struct dirent *readdir(DIR *dir) { check_init("readdir"); - + if (smbw_dirp(dir)) { static struct dirent external; struct SMBW_dirent * internal = (void *)smbw_readdir(dir); @@ -1227,41 +1240,41 @@ struct dirent *readdir(DIR *dir) int closedir(DIR *dir) { check_init("closedir"); - + if (smbw_dirp(dir)) { return smbw_closedir(dir); } - + return (* smbw_libc.closedir)(dir); } long telldir(DIR *dir) { check_init("telldir"); - + if (smbw_dirp(dir)) { return (long) smbw_telldir(dir); } - + return (* smbw_libc.telldir)(dir); } void seekdir(DIR *dir, long offset) { check_init("seekdir"); - + if (smbw_dirp(dir)) { smbw_seekdir(dir, (long long) offset); return; } - + (* smbw_libc.seekdir)(dir, offset); } int creat(const char *path, mode_t mode) { extern int creat_bits; - + check_init("creat"); return openx((char *) path, creat_bits, mode, smbw_libc.open); } @@ -1269,7 +1282,7 @@ int creat(const char *path, mode_t mode) int creat64(const char *path, mode_t mode) { extern int creat_bits; - + check_init("creat64"); return openx((char *) path, creat_bits, mode, smbw_libc.open64); } @@ -1277,103 +1290,103 @@ int creat64(const char *path, mode_t mode) int __xstat64 (int ver, const char *name, struct stat64 *st64) { check_init("__xstat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.__xstat64)(ver, (char *) name, st64); } int stat64(const char *name, struct stat64 *st64) { check_init("stat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.stat64)((char *) name, st64); } int __fxstat64(int ver, int fd, struct stat64 *st64) { check_init("__fxstat64"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.__fxstat64)(ver, fd, st64); } int fstat64(int fd, struct stat64 *st64) { check_init("fstat64"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.fstat64)(fd, st64); } int __lxstat64(int ver, const char *name, struct stat64 *st64) { check_init("__lxstat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat(name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.__lxstat64)(ver, (char *) name, st64); } int lstat64(const char *name, struct stat64 *st64) { check_init("lstat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.lstat64)((char *) name, st64); } int _llseek(unsigned int fd, unsigned long offset_high, unsigned long offset_low, loff_t *result, unsigned int whence) { check_init("_llseek"); - + if (smbw_fd(fd)) { *result = lseek(fd, offset_low, whence); return (*result < 0 ? -1 : 0); } - + return (* smbw_libc._llseek)(fd, offset_high, offset_low, result, whence); } struct dirent64 *readdir64(DIR *dir) { check_init("readdir64"); - + if (smbw_dirp(dir)) { static struct dirent64 external; struct SMBW_dirent * internal = (void *)smbw_readdir(dir); @@ -1383,14 +1396,14 @@ struct dirent64 *readdir64(DIR *dir) } return NULL; } - + return (* smbw_libc.readdir64)(dir); } int readdir_r(DIR *dir, struct dirent *external, struct dirent **result) { check_init("readdir_r"); - + if (smbw_dirp(dir)) { struct SMBW_dirent internal; int ret = smbw_readdir_r(dir, &internal, NULL); @@ -1400,14 +1413,14 @@ int readdir_r(DIR *dir, struct dirent *external, struct dirent **result) } return ret; } - + return (* smbw_libc.readdir_r)(dir, external, result); } int readdir64_r(DIR *dir, struct dirent64 *external, struct dirent64 **result) { check_init("readdir64_r"); - + if (smbw_dirp(dir)) { struct SMBW_dirent internal; int ret = smbw_readdir_r(dir, &internal, NULL); @@ -1417,7 +1430,7 @@ int readdir64_r(DIR *dir, struct dirent64 *external, struct dirent64 **result) } return ret; } - + return (* smbw_libc.readdir64_r)(dir, external, result); } @@ -1436,7 +1449,7 @@ int setxattr(const char *fname, if (smbw_path(fname)) { return smbw_setxattr(fname, name, value, size, flags); } - + return (* smbw_libc.setxattr)(fname, name, value, size, flags); } @@ -1449,7 +1462,7 @@ int lsetxattr(const char *fname, if (smbw_path(fname)) { return smbw_lsetxattr(fname, name, value, size, flags); } - + return (* smbw_libc.lsetxattr)(fname, name, value, size, flags); } @@ -1462,7 +1475,7 @@ int fsetxattr(int fd, if (smbw_fd(fd)) { return smbw_fsetxattr(fd, name, value, size, flags); } - + return (* smbw_libc.fsetxattr)(fd, name, value, size, flags); } @@ -1474,7 +1487,7 @@ int getxattr(const char *fname, if (smbw_path(fname)) { return smbw_getxattr(fname, name, value, size); } - + return (* smbw_libc.getxattr)(fname, name, value, size); } @@ -1486,7 +1499,7 @@ int lgetxattr(const char *fname, if (smbw_path(fname)) { return smbw_lgetxattr(fname, name, value, size); } - + return (* smbw_libc.lgetxattr)(fname, name, value, size); } @@ -1498,7 +1511,7 @@ int fgetxattr(int fd, if (smbw_fd(fd)) { return smbw_fgetxattr(fd, name, value, size); } - + return (* smbw_libc.fgetxattr)(fd, name, value, size); } @@ -1508,7 +1521,7 @@ int removexattr(const char *fname, if (smbw_path(fname)) { return smbw_removexattr(fname, name); } - + return (* smbw_libc.removexattr)(fname, name); } @@ -1518,7 +1531,7 @@ int lremovexattr(const char *fname, if (smbw_path(fname)) { return smbw_lremovexattr(fname, name); } - + return (* smbw_libc.lremovexattr)(fname, name); } @@ -1528,7 +1541,7 @@ int fremovexattr(int fd, if (smbw_fd(fd)) { return smbw_fremovexattr(fd, name); } - + return (* smbw_libc.fremovexattr)(fd, name); } @@ -1539,7 +1552,7 @@ int listxattr(const char *fname, if (smbw_path(fname)) { return smbw_listxattr(fname, list, size); } - + return (* smbw_libc.listxattr)(fname, list, size); } @@ -1550,7 +1563,7 @@ int llistxattr(const char *fname, if (smbw_path(fname)) { return smbw_llistxattr(fname, list, size); } - + return (* smbw_libc.llistxattr)(fname, list, size); } @@ -1561,7 +1574,7 @@ int flistxattr(int fd, if (smbw_fd(fd)) { return smbw_flistxattr(fd, list, size); } - + return (* smbw_libc.flistxattr)(fd, list, size); } @@ -1609,7 +1622,7 @@ void free(void *ptr) { static int in_progress = 0; void __libc_free(void *ptr); - + if (in_progress) return; in_progress = 1; __libc_free(ptr); @@ -1628,7 +1641,7 @@ smbw_sigaction_handler(int signum, { /* Our entire purpose for trapping signals is to call this! */ sys_select_signal(); - + /* Call the user's handler */ if (user_action[signum].sa_handler != SIG_IGN && user_action[signum].sa_handler != SIG_DFL && @@ -1660,14 +1673,14 @@ do_select(int n, int saved_errno; sigset_t sigset; struct sigaction new_action; - + saved_errno = errno; for (i=1; i<_NSIG; i++) { sigemptyset(&sigset); new_action.sa_mask = sigset; new_action.sa_flags = SA_SIGINFO; new_action.sa_sigaction = smbw_sigaction_handler; - + if (sigaction(i, &new_action, &user_action[i]) < 0) { if (errno != EINVAL) { return -1; @@ -1675,14 +1688,14 @@ do_select(int n, } } errno = saved_errno; - + ret = (* select_fn)(n, readfds, writefds, exceptfds, timeout); saved_errno = errno; - + for (i=0; i<_NSIG; i++) { (void) sigaction(i, &user_action[i], NULL); } - + errno = saved_errno; return ret; } @@ -1695,7 +1708,7 @@ select(int n, struct timeval *timeout) { check_init("select"); - + return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc.select); } @@ -1708,7 +1721,7 @@ _select(int n, struct timeval *timeout) { check_init("_select"); - + return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc._select); } @@ -1721,7 +1734,7 @@ __select(int n, struct timeval *timeout) { check_init("__select"); - + return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc.__select); } diff --git a/examples/libsmbclient/smbwrapper/wrapper.h b/examples/libsmbclient/smbwrapper/wrapper.h index 6d0d9f527a..5a18b9d76c 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.h +++ b/examples/libsmbclient/smbwrapper/wrapper.h @@ -32,6 +32,10 @@ #include #include +#ifndef __FD_SETSIZE +# define __FD_SETSIZE 256 +#endif + extern int smbw_fd_map[__FD_SETSIZE]; extern int smbw_ref_count[__FD_SETSIZE]; extern char smbw_cwd[PATH_MAX]; -- cgit From 673c3564885fdb57e8f99d64401ee81152134e54 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 11 Jan 2006 18:22:06 +0000 Subject: r12852: r12150@cabra: derrell | 2006-01-11 13:21:14 -0500 Although RTLD_NEXT was not working properly a number of years ago, it seems to be now. Replace dlopen(/lib/libc...) with direct use of RTLD_NEXT (This used to be commit 2b4866500640891fcb1ca7b24997df17f1b077cc) --- examples/libsmbclient/smbwrapper/wrapper.c | 45 ++++++++++-------------------- 1 file changed, 15 insertions(+), 30 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c index 12904c3073..e6f764c16d 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.c +++ b/examples/libsmbclient/smbwrapper/wrapper.c @@ -62,7 +62,14 @@ #include #include #include +#ifdef __USE_GNU +# define SMBW_USE_GNU +#endif +#define __USE_GNU /* need this to have RTLD_NEXT defined */ #include +#ifndef SMBW_USE_GNU +# undef __USE_GNU +#endif #include #include "libsmbclient.h" #include "bsd-strlfunc.h" @@ -131,7 +138,6 @@ void smbw_initialize(void) static void initialize(void) { - void *lib = NULL; int saved_errno; #if SMBW_DEBUG & 0x1 char *error; @@ -144,26 +150,18 @@ static void initialize(void) } initialized = 1; - if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { -#ifdef RTLD_NEXT - lib = RTLD_NEXT; -#else - exit(1); -#endif - } - #if SMBW_DEBUG & 0x1 -# define GETSYM(symname, symstring) \ - if ((smbw_libc.symname = dlsym(lib, symstring)) == NULL) { \ - if (smbw_libc.write != NULL && \ - (error = dlerror()) != NULL) { \ - (* smbw_libc.write)(1, error, strlen(error)); \ - (* smbw_libc.write)(1, "\n", 1); \ - } \ +# define GETSYM(symname, symstring) \ + if ((smbw_libc.symname = dlsym(RTLD_NEXT, symstring)) == NULL) { \ + if (smbw_libc.write != NULL && \ + (error = dlerror()) != NULL) { \ + (* smbw_libc.write)(1, error, strlen(error)); \ + (* smbw_libc.write)(1, "\n", 1); \ + } \ } #else # define GETSYM(symname, symstring) \ - smbw_libc.symname = dlsym(lib, symstring); + smbw_libc.symname = dlsym(RTLD_NEXT, symstring); #endif /* @@ -265,19 +263,6 @@ static void initialize(void) GETSYM(_select, "_select"); GETSYM(__select, "__select"); -#ifdef RTLD_NEXT - if (lib != RTLD_NEXT) { - dlclose(lib); - } -#else - dlclose(lib); -#endif - - /* Ensure that the C library is immediately available */ - if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { - exit(1); - } - #if SMBW_DEBUG & 4 { if ((debugFd = -- cgit From e836508704dd964e22e8bfc0f8e9ec520a2c94f2 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 22 Mar 2006 22:05:19 +0000 Subject: r14664: r13868@cabra: derrell | 2006-03-22 17:04:30 -0500 Implement enhancement request 3505. Two additional features are added here. There is now a method of saving an opaque user data handle in the smbc_ context, and there is now a way to request that the context be passed to the authentication function. See examples/libsmbclient/testbrowse.c for an example of using these features. (This used to be commit 203b4911c16bd7e10198a6f0e63960f2813025ef) --- examples/libsmbclient/get_auth_data_fn.h | 1 - examples/libsmbclient/testbrowse.c | 51 ++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/get_auth_data_fn.h b/examples/libsmbclient/get_auth_data_fn.h index 2954039f0a..eb493885af 100644 --- a/examples/libsmbclient/get_auth_data_fn.h +++ b/examples/libsmbclient/get_auth_data_fn.h @@ -7,7 +7,6 @@ get_auth_data_fn(const char * pServer, int maxLenUsername, char * pPassword, int maxLenPassword) - { char temp[128]; diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index ca126c9510..96f78aad85 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -24,6 +24,16 @@ static void browse(char * path, int indent); +static void +get_auth_data_with_context_fn(SMBCCTX * context, + const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword); int main(int argc, char * argv[]) @@ -31,6 +41,7 @@ main(int argc, char * argv[]) int debug = 0; int debug_stderr = 0; int no_auth = 0; + int context_auth = 0; int scan = 0; int iterations = -1; int again; @@ -63,6 +74,10 @@ main(int argc, char * argv[]) "noauth", 'A', POPT_ARG_NONE, &no_auth, 0, "Do not request authentication data", "integer" }, + { + "contextauth", 'C', POPT_ARG_NONE, &context_auth, + 0, "Use new authentication function with context", "integer" + }, { NULL } @@ -94,12 +109,21 @@ main(int argc, char * argv[]) /* Set mandatory options (is that a contradiction in terms?) */ context->debug = debug; - context->callbacks.auth_fn = (no_auth ? no_auth_data_fn : get_auth_data_fn); + 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"); + } else { + context->callbacks.auth_fn = + (no_auth ? no_auth_data_fn : 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_stderr"); + smbc_option_set(context, "debug_stderr", (void *) 1); } /* Initialize the context using the previously specified options */ @@ -161,6 +185,29 @@ no_auth_data_fn(const char * pServer, return; } + +static void +get_auth_data_with_context_fn(SMBCCTX * context, + const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) +{ + printf("Authenticating with context 0x%lx", context); + if (context != NULL) { + char *user_data = smbc_option_get(context, "user_data"); + printf(" with user data %s", user_data); + } + printf("\n"); + + get_auth_data_fn(pServer, pShare, pWorkgroup, maxLenWorkgroup, + pUsername, maxLenUsername, pPassword, maxLenPassword); +} + static void browse(char * path, int scan, int indent) { char * p; -- cgit From 9718506d35ca14c5233b613c647609bf2589f38b Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 27 Jun 2006 02:30:58 +0000 Subject: r16550: Fix bug 3866. Thanks for the report! Although I've never met a computer or compiler that produced pointers to functions which are a different size than pointers to data, I suppose they probably exist. Assigning a pointer to a function is technically illegal in C anyway. Change casts of the option_value based on the option_name to use of variable argument lists. For binary compatibility, I've maintained but deprecated the old behavior of debug_stderr (which expected to be passed a NULL or non-NULL pointer) and added a new option debug_to_stderr which properly expects a boolean (int) parameter. Derrell (This used to be commit c1b4c510530ca3118d1eccb9615a8cad732c7373) --- examples/libsmbclient/testbrowse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 96f78aad85..562d2c2aeb 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -120,10 +120,10 @@ main(int argc, char * argv[]) (no_auth ? no_auth_data_fn : get_auth_data_fn); } - /* If we've been asked to log to stderr instead of stdout... */ + /* 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_stderr", (void *) 1); + smbc_option_set(context, "debug_to_stderr", 1); } /* Initialize the context using the previously specified options */ -- cgit From 5e44fc4cd47108245c567b9e676a5d8c09787d96 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 2 Sep 2006 21:47:56 +0000 Subject: r18009: Fixes bug 4026. This completes the work Jeremy began last week, disambiguating the meaning of c_time. (In POSIX terminology, c_time means "status Change time", not "create time".) All uses of c_time, a_time and m_time have now been replaced with change_time, access_time, and write_time, and when creation time is intended, create_time is used. Additionally, the capability of setting and retrieving the create time have been added to the smbc_setxattr() and smbc_getxattr() functions. An example of setting all four times can be seen with the program examples/libsmbclient/testacl with the following command line similar to: testacl -f -S "system.*:CREATE_TIME:1000000000,ACCESS_TIME:1000000060,WRITE_TIME:1000000120,CHANGE_TIME:1000000180" 'smb://server/share/testfile.txt' The -f option turns on the new mode which uses full time names in the attribute specification (e.g. ACCESS_TIME vs A_TIME). (This used to be commit 8e119b64f1d92026dda855d904be09912a40601c) --- examples/libsmbclient/testacl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c index ce5694b331..4d327b39a7 100644 --- a/examples/libsmbclient/testacl.c +++ b/examples/libsmbclient/testacl.c @@ -23,6 +23,7 @@ int main(int argc, const char *argv[]) int flags; int debug = 0; int numeric = 0; + int full_time_names = 0; enum acl_mode mode = SMB_ACL_GET; static char *the_acl = NULL; int ret; @@ -42,6 +43,11 @@ int main(int argc, const char *argv[]) "debug", 'd', POPT_ARG_INT, &debug, 0, "Set debug level (0-100)" }, + { + "full_time_names", 'f', POPT_ARG_NONE, &full_time_names, + 1, + "Use new style xattr names, which include CREATE_TIME" + }, { "delete", 'D', POPT_ARG_STRING, NULL, 'D', "Delete an acl", "ACL" @@ -133,6 +139,11 @@ int main(int argc, const char *argv[]) printf("Could not initialize smbc_ library\n"); return 1; } + + if (full_time_names) { + SMBCCTX *context = smbc_set_context(NULL); + smbc_option_set(context, "full_time_names", 1); + } /* Perform requested action */ @@ -143,11 +154,11 @@ int main(int argc, const char *argv[]) { if (numeric) { - the_acl = "system.nt_sec_desc.*"; + the_acl = "system.*"; } else { - the_acl = "system.nt_sec_desc.*+"; + the_acl = "system.*+"; } } ret = smbc_getxattr(path, the_acl, value, sizeof(value)); -- cgit From 40665edf5e6043ad5a8f46731a79ec1d5835b62a Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 3 Sep 2006 00:50:34 +0000 Subject: r18011: Should fix bug 3835. Jeremy: requires your eyes... If the remote connection timed out while cli_list() was retrieving its list of files, the error was not returned to the user, e.g. via smbc_opendir(), so the user didn't have a way to know to set the timeout longer and try again. This problem would occur when a very large directory is being read with a too-small timeout on the cli. Jeremy, although there were a couple of areas that needed to be handled, I needed to make one change that you should bless, in libsmb/clientgen.c. It was setting cli->smb_rw_error = smb_read_error; but smb_read_error is zero, so this had no effect. I'm now doing cli->smb_rw_error = READ_TIMEOUT; instead, and according to the OP, these (cumulative) changes (in a slightly different form) solve the problem. Please confirm this smb_rw_error change will have no other adverse effects that you can see. Derrell (This used to be commit fa664b24b829f973156486896575c1007b6d7b01) --- examples/libsmbclient/Makefile | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index a88f4a240c..11c3b77132 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -6,10 +6,12 @@ EXTLIB_INCL = -I/usr/include/gtk-1.2 \ -I/usr/include/glib-1.2 \ -I/usr/lib/glib/include + DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE CFLAGS = -O0 -g -I$(SAMBA_INCL) $(EXTLIB_INCL) $(DEFS) LDFLAGS = -L/usr/local/samba/lib +LIBSMBCLIENT = /usr/local/samba/lib/libsmbclient.so TESTS= testsmbc \ tree \ @@ -26,43 +28,43 @@ all: $(TESTS) smbsh testsmbc: testsmbc.o @echo Linking testsmbc - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lsmbclient + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) tree: tree.o @echo Linking tree - @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient $< + @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` $(LIBSMBCLIENT) $< testacl: testacl.o @echo Linking testacl - @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` -lsmbclient -lpopt $< + @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` $(LIBSMBCLIENT) -lpopt $< testbrowse: testbrowse.o @echo Linking testbrowse - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< testbrowse2: testbrowse2.o @echo Linking testbrowse2 - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< teststat: teststat.o @echo Linking teststat - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< teststat2: teststat2.o @echo Linking teststat2 - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< testchmod: testchmod.o @echo Linking testchmod - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< testutime: testutime.o @echo Linking testutime - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< testread: testread.o @echo Linking testread - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< smbsh: make -C smbwrapper -- cgit From 44c1504c032ffa0f0b9cc2333fa0e3a05a03bf48 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 3 Sep 2006 01:37:26 +0000 Subject: r18012: Should fix bug 4018. NetApp filers expect paths in Open AndX Request to have a leading slash. Windows clients send the leading slash, so we should too. (This used to be commit fc5b6e4bd8a67994b0c56d1223c74d064164420f) --- examples/libsmbclient/testread.c | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testread.c b/examples/libsmbclient/testread.c index 1f1219ca84..d59fc70ec1 100644 --- a/examples/libsmbclient/testread.c +++ b/examples/libsmbclient/testread.c @@ -55,6 +55,7 @@ int main(int argc, char * argv[]) { ret = smbc_read(fd, buffer, sizeof(buffer)); savedErrno = errno; + if (ret > 0) fwrite(buffer, 1, ret, stdout); } while (ret > 0); smbc_close(fd); -- cgit From a8202531d8c9e077e2af3a12cd17c8e7b7639bf2 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 8 Apr 2007 16:41:24 +0000 Subject: r22130: - Ensure that the libsmbclient example programs link with the libsmbclient library that's part of the current tree, not with whatever happens to have been previously installed. (This used to be commit c65621e0b7690b90beb420f829c769c7d28147f5) --- examples/libsmbclient/Makefile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 11c3b77132..ee117c9fe9 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -11,7 +11,8 @@ DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE CFLAGS = -O0 -g -I$(SAMBA_INCL) $(EXTLIB_INCL) $(DEFS) LDFLAGS = -L/usr/local/samba/lib -LIBSMBCLIENT = /usr/local/samba/lib/libsmbclient.so +#LIBSMBCLIENT = /usr/local/samba/lib/libsmbclient.so +LIBSMBCLIENT = ../../source/bin/libsmbclient.a -ldl -lresolv TESTS= testsmbc \ tree \ @@ -32,39 +33,39 @@ testsmbc: testsmbc.o tree: tree.o @echo Linking tree - @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` $(LIBSMBCLIENT) $< + $(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ $< `gtk-config --libs` $(LIBSMBCLIENT) testacl: testacl.o @echo Linking testacl - @$(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ `gtk-config --libs` $(LIBSMBCLIENT) -lpopt $< + $(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ $< `gtk-config --libs` $(LIBSMBCLIENT) -lpopt testbrowse: testbrowse.o @echo Linking testbrowse - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt testbrowse2: testbrowse2.o @echo Linking testbrowse2 - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt teststat: teststat.o @echo Linking teststat - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt teststat2: teststat2.o @echo Linking teststat2 - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt testchmod: testchmod.o @echo Linking testchmod - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt testutime: testutime.o @echo Linking testutime - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt testread: testread.o @echo Linking testread - @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBSMBCLIENT) -lpopt $< + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt smbsh: make -C smbwrapper -- cgit From 4a413b304369df0650db8999ecdaff119582d5f7 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 15 May 2007 19:10:29 +0000 Subject: r22914: - Fixes bug 4599. A missing if statement forced subseqeuent attempts to set attributes to fail. - I also noticed that missing attributes were setting an invalid return string by getxattr(), e.g. if there was not group, the return string had "GROUP:;" instead of excluding the GROUP attribute entirely as it should. The big problem with the way it was, is that the string could not then be passed to setxattr() and parsed. (This used to be commit 7213b5ebec8cd7f1955f5aa8ee4050c39cd11ed1) --- examples/libsmbclient/Makefile | 5 +++ examples/libsmbclient/testacl2.c | 78 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 examples/libsmbclient/testacl2.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index ee117c9fe9..d44df77b3f 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -17,6 +17,7 @@ LIBSMBCLIENT = ../../source/bin/libsmbclient.a -ldl -lresolv TESTS= testsmbc \ tree \ testacl \ + testacl2 \ testbrowse \ testbrowse2 \ teststat \ @@ -39,6 +40,10 @@ testacl: testacl.o @echo Linking testacl $(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ $< `gtk-config --libs` $(LIBSMBCLIENT) -lpopt +testacl2: testacl2.o + @echo Linking testacl2 + $(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ $< `gtk-config --libs` $(LIBSMBCLIENT) -lpopt + testbrowse: testbrowse.o @echo Linking testbrowse $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt diff --git a/examples/libsmbclient/testacl2.c b/examples/libsmbclient/testacl2.c new file mode 100644 index 0000000000..df38fe208e --- /dev/null +++ b/examples/libsmbclient/testacl2.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include "libsmbclient.h" +#include "get_auth_data_fn.h" + +enum acl_mode +{ + SMB_ACL_GET, + SMB_ACL_SET, + SMB_ACL_DELETE, + SMB_ACL_MODIFY, + SMB_ACL_ADD, + SMB_ACL_CHOWN, + SMB_ACL_CHGRP +}; + + +int main(int argc, const char *argv[]) +{ + int i; + int opt; + int flags; + int debug = 0; + int numeric = 0; + int full_time_names = 0; + enum acl_mode mode = SMB_ACL_GET; + static char *the_acl = NULL; + int ret; + char *p; + char *debugstr; + char value[1024]; + + if (smbc_init(get_auth_data_fn, debug) != 0) + { + printf("Could not initialize smbc_ library\n"); + return 1; + } + + SMBCCTX *context = smbc_set_context(NULL); + smbc_option_set(context, "full_time_names", 1); + + the_acl = strdup("system.nt_sec_desc.*"); + ret = smbc_getxattr(argv[1], the_acl, value, sizeof(value)); + if (ret < 0) + { + printf("Could not get attributes for [%s] %d: %s\n", + argv[1], errno, strerror(errno)); + return 1; + } + + printf("Attributes for [%s] are:\n%s\n", argv[1], value); + + flags = 0; + debugstr = "set attributes (1st time)"; + + ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags); + if (ret < 0) + { + printf("Could not %s for [%s] %d: %s\n", + debugstr, argv[1], errno, strerror(errno)); + return 1; + } + + flags = 0; + debugstr = "set attributes (2nd time)"; + + ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags); + if (ret < 0) + { + printf("Could not %s for [%s] %d: %s\n", + debugstr, argv[1], errno, strerror(errno)); + return 1; + } + + return 0; +} -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- examples/libsmbclient/smbwrapper/select.c | 2 +- examples/libsmbclient/smbwrapper/smbsh.c | 2 +- examples/libsmbclient/smbwrapper/smbw.c | 2 +- examples/libsmbclient/smbwrapper/smbw.h | 2 +- examples/libsmbclient/smbwrapper/smbw_dir.c | 2 +- examples/libsmbclient/smbwrapper/smbw_stat.c | 2 +- examples/libsmbclient/smbwrapper/wrapper.c | 2 +- examples/libsmbclient/smbwrapper/wrapper.h | 2 +- examples/libsmbclient/testsmbc.c | 2 +- examples/libsmbclient/tree.c | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/select.c b/examples/libsmbclient/smbwrapper/select.c index aa90169ee7..c379ebd3da 100644 --- a/examples/libsmbclient/smbwrapper/select.c +++ b/examples/libsmbclient/smbwrapper/select.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/examples/libsmbclient/smbwrapper/smbsh.c b/examples/libsmbclient/smbwrapper/smbsh.c index 23b1ac26c7..f2f3fec18d 100644 --- a/examples/libsmbclient/smbwrapper/smbsh.c +++ b/examples/libsmbclient/smbwrapper/smbsh.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/examples/libsmbclient/smbwrapper/smbw.c b/examples/libsmbclient/smbwrapper/smbw.c index a44f2f4046..9f9f322081 100644 --- a/examples/libsmbclient/smbwrapper/smbw.c +++ b/examples/libsmbclient/smbwrapper/smbw.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/examples/libsmbclient/smbwrapper/smbw.h b/examples/libsmbclient/smbwrapper/smbw.h index 161d57ebbb..c0c284b71c 100644 --- a/examples/libsmbclient/smbwrapper/smbw.h +++ b/examples/libsmbclient/smbwrapper/smbw.h @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/examples/libsmbclient/smbwrapper/smbw_dir.c b/examples/libsmbclient/smbwrapper/smbw_dir.c index 986b7f8220..be734c21af 100644 --- a/examples/libsmbclient/smbwrapper/smbw_dir.c +++ b/examples/libsmbclient/smbwrapper/smbw_dir.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/examples/libsmbclient/smbwrapper/smbw_stat.c b/examples/libsmbclient/smbwrapper/smbw_stat.c index a386c09209..c70496903f 100644 --- a/examples/libsmbclient/smbwrapper/smbw_stat.c +++ b/examples/libsmbclient/smbwrapper/smbw_stat.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c index e6f764c16d..2273338c7e 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.c +++ b/examples/libsmbclient/smbwrapper/wrapper.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/examples/libsmbclient/smbwrapper/wrapper.h b/examples/libsmbclient/smbwrapper/wrapper.h index 5a18b9d76c..0d4d8c3578 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.h +++ b/examples/libsmbclient/smbwrapper/wrapper.h @@ -6,7 +6,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c index 45e67bee62..eee31a378c 100644 --- a/examples/libsmbclient/testsmbc.c +++ b/examples/libsmbclient/testsmbc.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c index d8a69c8d4c..2218b47188 100644 --- a/examples/libsmbclient/tree.c +++ b/examples/libsmbclient/tree.c @@ -8,7 +8,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 58e9534300430fa4f2bcb50fb2d1d2990bdbe636 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:57:11 +0000 Subject: r23785: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit d0e89d246d8e5e64196d6c1d16d39a70579ca42f) --- examples/libsmbclient/smbwrapper/select.c | 3 +-- examples/libsmbclient/smbwrapper/smbsh.c | 3 +-- examples/libsmbclient/smbwrapper/smbw.c | 3 +-- examples/libsmbclient/smbwrapper/smbw.h | 3 +-- examples/libsmbclient/smbwrapper/smbw_dir.c | 3 +-- examples/libsmbclient/smbwrapper/smbw_stat.c | 3 +-- examples/libsmbclient/smbwrapper/wrapper.c | 3 +-- examples/libsmbclient/smbwrapper/wrapper.h | 3 +-- examples/libsmbclient/testsmbc.c | 3 +-- examples/libsmbclient/tree.c | 3 +-- 10 files changed, 10 insertions(+), 20 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/select.c b/examples/libsmbclient/smbwrapper/select.c index c379ebd3da..4e87a2e2e8 100644 --- a/examples/libsmbclient/smbwrapper/select.c +++ b/examples/libsmbclient/smbwrapper/select.c @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ /* diff --git a/examples/libsmbclient/smbwrapper/smbsh.c b/examples/libsmbclient/smbwrapper/smbsh.c index f2f3fec18d..f2b5bf49fb 100644 --- a/examples/libsmbclient/smbwrapper/smbsh.c +++ b/examples/libsmbclient/smbwrapper/smbsh.c @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include diff --git a/examples/libsmbclient/smbwrapper/smbw.c b/examples/libsmbclient/smbwrapper/smbw.c index 9f9f322081..b88290ff6d 100644 --- a/examples/libsmbclient/smbwrapper/smbw.c +++ b/examples/libsmbclient/smbwrapper/smbw.c @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include diff --git a/examples/libsmbclient/smbwrapper/smbw.h b/examples/libsmbclient/smbwrapper/smbw.h index c0c284b71c..8bf1809ec9 100644 --- a/examples/libsmbclient/smbwrapper/smbw.h +++ b/examples/libsmbclient/smbwrapper/smbw.h @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #ifndef _SMBW_H diff --git a/examples/libsmbclient/smbwrapper/smbw_dir.c b/examples/libsmbclient/smbwrapper/smbw_dir.c index be734c21af..6e473bf0a3 100644 --- a/examples/libsmbclient/smbwrapper/smbw_dir.c +++ b/examples/libsmbclient/smbwrapper/smbw_dir.c @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "smbw.h" diff --git a/examples/libsmbclient/smbwrapper/smbw_stat.c b/examples/libsmbclient/smbwrapper/smbw_stat.c index c70496903f..7b2b011282 100644 --- a/examples/libsmbclient/smbwrapper/smbw_stat.c +++ b/examples/libsmbclient/smbwrapper/smbw_stat.c @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "smbw.h" diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c index 2273338c7e..30f9037d53 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.c +++ b/examples/libsmbclient/smbwrapper/wrapper.c @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ /* diff --git a/examples/libsmbclient/smbwrapper/wrapper.h b/examples/libsmbclient/smbwrapper/wrapper.h index 0d4d8c3578..e83bb1ee5d 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.h +++ b/examples/libsmbclient/smbwrapper/wrapper.h @@ -15,8 +15,7 @@ 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. + along with this program. If not, see . */ #ifndef __WRAPPER_H__ diff --git a/examples/libsmbclient/testsmbc.c b/examples/libsmbclient/testsmbc.c index eee31a378c..c506f5fd64 100644 --- a/examples/libsmbclient/testsmbc.c +++ b/examples/libsmbclient/testsmbc.c @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c index 2218b47188..d5a71e2868 100644 --- a/examples/libsmbclient/tree.c +++ b/examples/libsmbclient/tree.c @@ -17,8 +17,7 @@ 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. + along with this program. If not, see . */ /* example-gtk+ application, ripped off from the gtk+ tree.c sample */ -- cgit From 83fc92c82c6d6150661b3054047324f5318bbaa4 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 14 Aug 2007 03:02:34 +0000 Subject: r24388: - ACL retrieval provided incomplete information because the buffer pointer was incremented too far in some circumstances. In these cases, only the first of multiple concatenated strings would be seen. - Working on bug 4649 pertaining to delete an ACL, this fixes the reported crash. It appears to have been an incomplete switchover from malloc to talloc, as the memory was still being freed with SAFE_FREE. Deleting ACLs still doesn't work. Although a valid request is sent to the server and a SUCCESS response is returned, the method that's used in libsmbclient for deleting ACLs seems to be incorrect. In looking at the samba4 torture tests, it appears that we should be turning on the INHERIT flag if we want to delete the ACL. (I could use some assistance on the proper flags to send, from anyone familiar with this stuff.) - Apply patch from SATOH Fumiyasu to fix bug 4750. smbc_telldir_ctx() was not returning a value useful to smbc_lseekdir_ctx(). Derrell (This used to be commit 2ac502e29bd8390252fe4ae8344faab49ca01ff5) --- examples/libsmbclient/Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index d44df77b3f..be383aea67 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -10,12 +10,12 @@ EXTLIB_INCL = -I/usr/include/gtk-1.2 \ DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE CFLAGS = -O0 -g -I$(SAMBA_INCL) $(EXTLIB_INCL) $(DEFS) -LDFLAGS = -L/usr/local/samba/lib +LDFLAGS = -L/usr/local/samba/lib \ + -lldap -lkrb5 -lgssapi_krb5 #LIBSMBCLIENT = /usr/local/samba/lib/libsmbclient.so LIBSMBCLIENT = ../../source/bin/libsmbclient.a -ldl -lresolv TESTS= testsmbc \ - tree \ testacl \ testacl2 \ testbrowse \ @@ -26,6 +26,8 @@ TESTS= testsmbc \ testutime \ testread +# tree \ + all: $(TESTS) smbsh testsmbc: testsmbc.o @@ -38,11 +40,11 @@ tree: tree.o testacl: testacl.o @echo Linking testacl - $(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ $< `gtk-config --libs` $(LIBSMBCLIENT) -lpopt + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt testacl2: testacl2.o @echo Linking testacl2 - $(CC) `gtk-config --cflags` $(CFLAGS) $(LDFLAGS) -o $@ $< `gtk-config --libs` $(LIBSMBCLIENT) -lpopt + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt testbrowse: testbrowse.o @echo Linking testbrowse -- cgit From af02de700da25c964ef54968b89c6a0b11489b27 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Jan 2008 16:57:16 +0100 Subject: Fix build warning for libsmbclient example. Guenther (This used to be commit 8f411753b2130e9c1f260a15d031f57ba07b62a1) --- examples/libsmbclient/tree.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/tree.c b/examples/libsmbclient/tree.c index d5a71e2868..6e34cd0562 100644 --- a/examples/libsmbclient/tree.c +++ b/examples/libsmbclient/tree.c @@ -24,6 +24,8 @@ #include #include +#include +#include #include #include "libsmbclient.h" -- cgit From 83b1751615ef3892d44c7826228fbb3b0826d2b2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 10 Jan 2008 11:13:23 +0100 Subject: Remove unused string. Guenther (This used to be commit 88d6683872f4bb9c3074280f385f73c7af9de784) --- examples/libsmbclient/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index be383aea67..6500707e75 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -5,7 +5,7 @@ SAMBA_INCL = ../../source/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) @@ -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 = ../../source/bin/libsmbclient.a -ldl -lresolv +LIBSMBCLIENT = -lsmbclient -ldl -lresolv TESTS= testsmbc \ testacl \ -- cgit From d49ba81210970e44cc1c7179a959f74351684fdf Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 13 Jan 2008 12:07:18 -0500 Subject: Fix compile and linking errors since last this code was tested (This used to be commit 2f432842442859f98ecd263464ce02821ab10fca) --- examples/libsmbclient/Makefile | 2 +- examples/libsmbclient/smbwrapper/Makefile | 2 +- examples/libsmbclient/smbwrapper/wrapper.c | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient') 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/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/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 #include #include +#include #ifdef __USE_GNU # define SMBW_USE_GNU #endif -- cgit From 011e89c85868ec8f16e475a560a0e5bd41995920 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 13 Jan 2008 17:10:06 -0500 Subject: Fix smbc_listxattr() and friends (bug #5189) When the capability of using full names for DOS attributes was added, a bug was introduced which caused the wrong number of bytes to be returned. This patch to smbc_listxattr_ctx() fixes the problem. Thanks to Jack Schmidt for this patch. Derrell (This used to be commit 913c335d21c503d32b35bf65da7b2bddf0473875) --- examples/libsmbclient/testacl.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient') 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) { -- cgit From 12d31ba2b8b4c0e15567d427abef97a184450b1f Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 16 Jan 2008 14:35:44 +0000 Subject: Add a (very!) trivial cache to the example authentication callback. (This used to be commit 01f6a4cca7a91ae41ff393263418216324502f84) --- examples/libsmbclient/get_auth_data_fn.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient') 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); } -- cgit From 735e98759c0f860727c24c4cdb14235abdeb8879 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 16 Jan 2008 14:37:40 +0000 Subject: Replace GetTimeOfDay() with gettimeofday() in example program. GetTimeOfDay() seems to no longer be exported. For the smbsh example, just use the native gettimeofday() for now. (This used to be commit 296a6783fbc03460e87ac4136a0a9e6d2743b2ff) --- examples/libsmbclient/smbwrapper/select.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'examples/libsmbclient') 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) { -- cgit From 3e494442de5eff6d0619c793eef139c15efe0657 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 16 Jan 2008 14:41:11 +0000 Subject: Modify testread example to loop using same context. There's been a problem seen where open/read/close a number of times causes open failures eventually. This program has been modified to create the context once and then loop requesting file names to open/read/close. This program also demonstrates the current error in cli_read() where it returns an error instead of length 0 upon end of file. Derrell (This used to be commit 9d75ea577b407ccab59196760d376831062a3ab5) --- examples/libsmbclient/testread.c | 76 ++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 42 deletions(-) (limited to 'examples/libsmbclient') 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; } -- cgit From dba2400192e7d3afb9d1c48f52eeccd0c2f660e9 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 17 Jan 2008 09:26:36 -0500 Subject: Add some additional libsmbclient test programs. testwrite: create or truncate a file and write to it. teststat3: compare the results from smbc_stat() and smbc_fstat() Derrell (This used to be commit 5a4a7aec761c3388b741b9b47fa6358fc71a66ce) --- examples/libsmbclient/Makefile | 12 +++++- examples/libsmbclient/teststat3.c | 78 +++++++++++++++++++++++++++++++++++++++ examples/libsmbclient/testwrite.c | 69 ++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 examples/libsmbclient/teststat3.c create mode 100644 examples/libsmbclient/testwrite.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 26b80575fb..9657957c4e 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -22,9 +22,11 @@ TESTS= testsmbc \ testbrowse2 \ teststat \ teststat2 \ + teststat3 \ testchmod \ testutime \ - testread + testread \ + testwrite # tree \ @@ -62,6 +64,10 @@ teststat2: teststat2.o @echo Linking teststat2 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt +teststat3: teststat3.o + @echo Linking teststat3 + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt + testchmod: testchmod.o @echo Linking testchmod $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt @@ -74,6 +80,10 @@ testread: testread.o @echo Linking testread $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt +testwrite: testwrite.o + @echo Linking testwrite + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt + smbsh: make -C smbwrapper diff --git a/examples/libsmbclient/teststat3.c b/examples/libsmbclient/teststat3.c new file mode 100644 index 0000000000..26348b335c --- /dev/null +++ b/examples/libsmbclient/teststat3.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include "get_auth_data_fn.h" + +/* + * This test is intended to ensure that the timestamps returned by + * libsmbclient using smbc_stat() are the same as those returned by + * smbc_fstat(). + */ + + +int main(int argc, char* argv[]) +{ + int fd; + struct stat st1; + struct stat st2; + char mtime[32]; + char ctime[32]; + char atime[32]; + char * pUrl = argv[1]; + + if(argc != 2) + { + printf("usage: %s \n", argv[0]); + return 1; + } + + + smbc_init(get_auth_data_fn, 0); + + if (smbc_stat(pUrl, &st1) < 0) + { + perror("smbc_stat"); + return 1; + } + + if ((fd = smbc_open(pUrl, O_RDONLY, 0)) < 0) + { + perror("smbc_open"); + return 1; + } + + if (smbc_fstat(fd, &st2) < 0) + { + perror("smbc_fstat"); + return 1; + } + + smbc_close(fd); + +#define COMPARE(name, field) \ + if (st1.field != st2.field) \ + { \ + printf("Field " name " MISMATCH: st1=%lu, st2=%lu\n", \ + (unsigned long) st1.field, \ + (unsigned long) st2.field); \ + } + + COMPARE("st_dev", st_dev); + COMPARE("st_ino", st_ino); + COMPARE("st_mode", st_mode); + COMPARE("st_nlink", st_nlink); + COMPARE("st_uid", st_uid); + COMPARE("st_gid", st_gid); + COMPARE("st_rdev", st_rdev); + COMPARE("st_size", st_size); + COMPARE("st_blksize", st_blksize); + COMPARE("st_blocks", st_blocks); + COMPARE("st_atime", st_atime); + COMPARE("st_mtime", st_mtime); + COMPARE("st_ctime", st_ctime); + + return 0; +} + diff --git a/examples/libsmbclient/testwrite.c b/examples/libsmbclient/testwrite.c new file mode 100644 index 0000000000..780f0e95da --- /dev/null +++ b/examples/libsmbclient/testwrite.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include +#include +#include "get_auth_data_fn.h" + + +int main(int argc, char * argv[]) +{ + int i; + int fd; + int ret; + int debug = 0; + int mode = 0666; + int savedErrno; + char buffer[2048]; + char path[2048]; + char * p; + time_t t0; + time_t t1; + struct stat st; + + smbc_init(get_auth_data_fn, debug); + + printf("CAUTION: This program will overwrite a file. " + "Press ENTER to continue."); + fgets(buffer, sizeof(buffer), stdin); + + + for (;;) + { + fprintf(stdout, "\nPath: "); + *path = '\0'; + fgets(path, sizeof(path) - 1, stdin); + if (strlen(path) == 0) + { + return 0; + } + + p = path + strlen(path) - 1; + if (*p == '\n') + { + *p = '\0'; + } + + if ((fd = smbc_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0) + { + perror("smbc_open"); + continue; + } + + strcpy(buffer, "Hello world\n"); + + ret = smbc_write(fd, buffer, strlen(buffer)); + savedErrno = errno; + smbc_close(fd); + + if (ret < 0) + { + errno = savedErrno; + perror("write"); + } + } + + return 0; +} -- cgit From 76b5c674e70dff0d37409e64d53cda41ef9731a6 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 17 Jan 2008 11:46:41 -0500 Subject: Add a program to test repeated calls to smbc_getxattr(). (This used to be commit f5f46de404dba2e4a03d205a62cd5cf7ea4e075a) --- examples/libsmbclient/Makefile | 5 ++++ examples/libsmbclient/testacl3.c | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 examples/libsmbclient/testacl3.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 9657957c4e..6c70659661 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -18,6 +18,7 @@ LIBSMBCLIENT = -lwbclient -lsmbclient -ldl -lresolv TESTS= testsmbc \ testacl \ testacl2 \ + testacl3 \ testbrowse \ testbrowse2 \ teststat \ @@ -48,6 +49,10 @@ testacl2: testacl2.o @echo Linking testacl2 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt +testacl3: testacl3.o + @echo Linking testacl3 + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt + testbrowse: testbrowse.o @echo Linking testbrowse $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt diff --git a/examples/libsmbclient/testacl3.c b/examples/libsmbclient/testacl3.c new file mode 100644 index 0000000000..9102405659 --- /dev/null +++ b/examples/libsmbclient/testacl3.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include +#include "get_auth_data_fn.h" + + +int main(int argc, char * argv[]) +{ + int i; + int fd; + int ret; + int debug = 0; + int mode = 0666; + int savedErrno; + char value[2048]; + char path[2048]; + char * the_acl; + char * p; + time_t t0; + time_t t1; + struct stat st; + SMBCCTX * context; + + smbc_init(get_auth_data_fn, debug); + + context = smbc_set_context(NULL); + smbc_option_set(context, "full_time_names", 1); + + for (;;) + { + fprintf(stdout, "Path: "); + *path = '\0'; + fgets(path, sizeof(path) - 1, stdin); + if (strlen(path) == 0) + { + return 0; + } + + p = path + strlen(path) - 1; + if (*p == '\n') + { + *p = '\0'; + } + + the_acl = strdup("system.nt_sec_desc.*+"); + ret = smbc_getxattr(path, the_acl, value, sizeof(value)); + if (ret < 0) + { + printf("Could not get attributes for [%s] %d: %s\n", + path, errno, strerror(errno)); + return 1; + } + + printf("Attributes for [%s] are:\n%s\n", path, value); + } + + return 0; +} -- cgit From ab9afdd311c85fec023abb716e8465bb6b444bd3 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 26 Feb 2008 21:46:08 -0500 Subject: add a test program for the new ftruncate functionality (This used to be commit df995eddbddec80a0d9d4659bbb9c6ca8a45d02b) --- examples/libsmbclient/Makefile | 5 +++ examples/libsmbclient/testtruncate.c | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 examples/libsmbclient/testtruncate.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 6c70659661..e2d8b6895f 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -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/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 +#include +#include +#include +#include +#include +#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; +} -- cgit From 257b7b09298f7cb983b2f31b87fc5e46e0f62f0c Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 28 Feb 2008 11:23:20 -0500 Subject: Initial revamp of the libsmbclient interface. The libsmbclient interface has suffered from difficulty of improvement and feature enrichment without causing ABI breakage. Although there were a number of issues, the primary ones were: (a) the user of the library would manually manipulate the context structure members, meaning that nothing in the context structure could change other than adding stuff at the end; (b) there were three methods of setting options: setting bits in a flags field within the context structure, setting explicit options variables within an options structure in the context structure, and by calling the smbc_option_set() function; (c) the authentication callback did not traditionally provide enough information to the callee which required adding an option for a callback with a different signature, and now there are requests for even more information at the callback, requiring yet a third signature and option to set it (if we implement that feature). This commit provides a reorganization of the code which fixes (a) and (b). The context structure is now entirely opaque, and there are setter and getter functions for manipulating it. This makes maintaining ABI consistency much, much easier. Additionally, the options setting/getting has been unified into a single mechanism using smbc_option_set() and smbc_option_get(). Yet to be completed is a refactoring of the authentication callback (c). The test programs in examples/libsmbclient have been modified (if necessary; some applications require no changes at all) for the new API and a few have been minimally tested. Derrell (This used to be commit d4b4bae8ded824d06ad5ab0e219f71187ee5c771) --- examples/libsmbclient/smbwrapper/smbw.c | 10 +++++----- examples/libsmbclient/testbrowse.c | 8 +++++++- examples/libsmbclient/testbrowse2.c | 17 +++++++++-------- 3 files changed, 21 insertions(+), 14 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/smbw.c b/examples/libsmbclient/smbwrapper/smbw.c index b88290ff6d..d3439e436d 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_option_set(smbw_ctx, "browse_max_lmb_count", 0); + smbc_option_set(smbw_ctx, "urlencode_readdir_entries", 1); + smbc_option_set(smbw_ctx, "one_share_per_server", 1); if (smbc_init_context(smbw_ctx) == NULL) { fprintf(stderr, "Could not initialize context.\n"); diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 562d2c2aeb..495cf0fbec 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -108,7 +108,8 @@ main(int argc, char * argv[]) } /* Set mandatory options (is that a contradiction in terms?) */ - context->debug = debug; + smbc_setDebug(context, debug); +#if 0 if (context_auth) { context->callbacks.auth_fn = NULL; smbc_option_set(context, @@ -119,6 +120,11 @@ main(int argc, char * argv[]) context->callbacks.auth_fn = (no_auth ? no_auth_data_fn : get_auth_data_fn); } +#else +#warning "temporarily remove setting alternate auth function" + smbc_setFunctionAuthData(context, + (no_auth ? no_auth_data_fn : get_auth_data_fn)); +#endif /* If we've been asked to log to stderr instead of stdout, ... */ if (debug_stderr) { 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; } -- cgit From 223940d9a887c5b98a5c873797302a6a9407ad7f Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 1 Mar 2008 20:44:21 -0500 Subject: Additional revamped libsmbclient documentation - Ensured that all public functions have documentation in libsmbclient.h - Reformatted for "proper" indentation - Re-added temporarily-disabled alternate authentication function capability Derrell (This used to be commit 64b7150d92849a1e1e2416b9dcc12fae8d6bea99) --- examples/libsmbclient/testbrowse.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 495cf0fbec..1b0b54f9f0 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -109,22 +109,13 @@ main(int argc, char * argv[]) /* Set mandatory options (is that a contradiction in terms?) */ smbc_setDebug(context, debug); -#if 0 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); } -#else -#warning "temporarily remove setting alternate auth function" - smbc_setFunctionAuthData(context, - (no_auth ? no_auth_data_fn : get_auth_data_fn)); -#endif /* If we've been asked to log to stderr instead of stdout, ... */ if (debug_stderr) { -- cgit From 8a05c0a8843c001bdb4ac31e9ea382dd89716b55 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 2 Mar 2008 16:21:48 -0500 Subject: Remove use of deprecated function (This used to be commit 93580bce833453ba512ee436d6dfdbdcd2c53777) --- examples/libsmbclient/smbwrapper/smbw.c | 6 +++--- examples/libsmbclient/testacl.c | 2 +- examples/libsmbclient/testacl2.c | 2 +- examples/libsmbclient/testacl3.c | 2 +- examples/libsmbclient/testbrowse.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/smbw.c b/examples/libsmbclient/smbwrapper/smbw.c index d3439e436d..e2e44c1f0f 100644 --- a/examples/libsmbclient/smbwrapper/smbw.c +++ b/examples/libsmbclient/smbwrapper/smbw.c @@ -176,9 +176,9 @@ static void do_init(StartupType startupType) smbc_setDebug(smbw_ctx, debug_level); smbc_setFunctionAuthData(smbw_ctx, get_auth_data_fn); - smbc_option_set(smbw_ctx, "browse_max_lmb_count", 0); - smbc_option_set(smbw_ctx, "urlencode_readdir_entries", 1); - smbc_option_set(smbw_ctx, "one_share_per_server", 1); + 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 1b0b54f9f0..c4ca6667e0 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -120,7 +120,7 @@ main(int argc, char * argv[]) /* 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 */ @@ -196,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"); -- cgit From 1363ee9d65965704f716965c6cbcfc0693ca2401 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 3 Mar 2008 18:13:33 -0500 Subject: Continued revamping of libsmbclient. - James suggested using gcc's "deprecated" attribute to mark the context structure fields to generate warnings. This creates a scenario with the best of all worlds. I'm able to move to an organization that more easily allows future enhancements, while avoiding any mandatory changes by applications. Thanks, James! - Updated WHATSNEW.txt so that it accurately reflects the current state of affairs. Derrell (This used to be commit a67f96fbe9683b46c2149f7cb439d13f7f0e6ecd) --- examples/libsmbclient/Makefile | 4 ++-- examples/libsmbclient/testsmbc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index e2d8b6895f..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 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 #include #include -#include +#include "libsmbclient.h" #include "get_auth_data_fn.h" int global_id = 0; -- cgit From ee45d0d6630624b735a7ea07639ffa0d774a337c Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 3 Mar 2008 18:25:49 -0500 Subject: Missed a few 'deprecated' markers (This used to be commit 76ba37ac46b4a77fe228ca90635fa19140541ccd) --- examples/libsmbclient/testbrowse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index c4ca6667e0..a7eda365af 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -122,7 +122,7 @@ main(int argc, char * argv[]) /* ... then set the option to do so */ smbc_setOptionDebugToStderr(context, 1); } - + /* Initialize the context using the previously specified options */ if (!smbc_init_context(context)) { smbc_free_context(context, 0); -- cgit From cf4b2f4d24a69234cbc62f367dece28446b6bac5 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Fri, 30 May 2008 10:24:55 -0400 Subject: Update libsmbclient examples to match new libraries - talloc and tdb have been moved to separate libraries. Link with those. Derrell (This used to be commit e4060ad864ec9d4e9092a832c3c664ee31b6125a) --- examples/libsmbclient/Makefile | 2 +- examples/libsmbclient/smbwrapper/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index a50e80a918..7415f4f07e 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -13,7 +13,7 @@ CFLAGS = -O0 -g $(SAMBA_INCL) $(EXTLIB_INCL) $(DEFS) LDFLAGS = -L/usr/local/samba/lib \ -lldap -lkrb5 -lgssapi_krb5 #LIBSMBCLIENT = /usr/local/samba/lib/libsmbclient.so -LIBSMBCLIENT = -lwbclient -lsmbclient -ldl -lresolv +LIBSMBCLIENT = -lwbclient -lsmbclient -ltalloc -ltdb -ldl -lresolv TESTS= testsmbc \ testacl \ diff --git a/examples/libsmbclient/smbwrapper/Makefile b/examples/libsmbclient/smbwrapper/Makefile index 726435319f..7f5c17c79f 100644 --- a/examples/libsmbclient/smbwrapper/Makefile +++ b/examples/libsmbclient/smbwrapper/Makefile @@ -1,4 +1,4 @@ -LIBS = -lwbclient -lsmbclient -ldl +LIBS = -lwbclient -lsmbclient -ltalloc -ltdb -ldl DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) -- cgit From 3e20aeb18e418a5a1a7821fd8c3f0d0bc5169489 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Fri, 30 May 2008 10:38:35 -0400 Subject: Working on bug #5475 - Add code to test whether smbc_stat() munges future smbc_getxattr() results. Derrell (This used to be commit 5f6b301f92e9e9d5ee1dab9ef8eca2cc77e12941) --- examples/libsmbclient/testacl.c | 48 +++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c index 00e1c2c9da..a57dd4a499 100644 --- a/examples/libsmbclient/testacl.c +++ b/examples/libsmbclient/testacl.c @@ -24,6 +24,7 @@ int main(int argc, const char *argv[]) int flags; int debug = 0; int numeric = 0; + int stat_and_retry = 0; int full_time_names = 0; enum acl_mode mode = SMB_ACL_LIST; static char *the_acl = NULL; @@ -33,6 +34,7 @@ int main(int argc, const char *argv[]) char path[1024]; char value[1024]; poptContext pc; + struct stat st; struct poptOption long_options[] = { POPT_AUTOHELP @@ -77,6 +79,10 @@ int main(int argc, const char *argv[]) "get", 'g', POPT_ARG_STRING, NULL, 'g', "Get a specific acl attribute", "ACL" }, + { + "stat_and_retry", 'R', POPT_ARG_NONE, &stat_and_retry, + 1, "After 'get' do 'stat' and another 'get'" + }, { NULL } @@ -175,26 +181,40 @@ int main(int argc, const char *argv[]) break; case SMB_ACL_GET: - if (the_acl == NULL) + do { - if (numeric) + if (the_acl == NULL) { - the_acl = "system.*"; + if (numeric) + { + the_acl = "system.*"; + } + else + { + the_acl = "system.*+"; + } } - else + ret = smbc_getxattr(path, the_acl, value, sizeof(value)); + if (ret < 0) { - the_acl = "system.*+"; + printf("Could not get attributes for [%s] %d: %s\n", + path, errno, strerror(errno)); + return 1; } - } - ret = smbc_getxattr(path, the_acl, value, sizeof(value)); - if (ret < 0) - { - printf("Could not get attributes for [%s] %d: %s\n", - path, errno, strerror(errno)); - return 1; - } - printf("Attributes for [%s] are:\n%s\n", path, value); + printf("Attributes for [%s] are:\n%s\n", path, value); + + if (stat_and_retry) + { + if (smbc_stat(path, &st) < 0) + { + perror("smbc_stat"); + return 1; + } + } + + --stat_and_retry; + } while (stat_and_retry >= 0); break; case SMB_ACL_ADD: -- cgit From f21058d61ee6f0661f58c998af84419ee642cbf5 Mon Sep 17 00:00:00 2001 From: Karolin Seeger Date: Tue, 17 Jun 2008 13:18:17 +0200 Subject: man pages: Move 'smbsh' man page to the examples directory. smbsh.c is located in the examples directory. It does not make sense to install a man page without installing the tool itself. This fixes bug #4724. Karolin (This used to be commit 797ed744b15c94fa4831d9796b40bb0ab5df55b7) --- examples/libsmbclient/smbwrapper/smbsh.1 | 203 ++++++++++++++++++++++++++ examples/libsmbclient/smbwrapper/smbsh.1.html | 108 ++++++++++++++ examples/libsmbclient/smbwrapper/smbsh.1.xml | 164 +++++++++++++++++++++ 3 files changed, 475 insertions(+) create mode 100644 examples/libsmbclient/smbwrapper/smbsh.1 create mode 100644 examples/libsmbclient/smbwrapper/smbsh.1.html create mode 100644 examples/libsmbclient/smbwrapper/smbsh.1.xml (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/smbsh.1 b/examples/libsmbclient/smbwrapper/smbsh.1 new file mode 100644 index 0000000000..368a245e17 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/smbsh.1 @@ -0,0 +1,203 @@ +.\" Title: smbsh +.\" Author: +.\" Generator: DocBook XSL Stylesheets v1.73.1 +.\" Date: 06/12/2008 +.\" Manual: User Commands +.\" Source: Samba 3.2 +.\" +.TH "SMBSH" "1" "06/12/2008" "Samba 3\.2" "User Commands" +.\" disable hyphenation +.nh +.\" disable justification (adjust text to left margin only) +.ad l +.SH "NAME" +smbsh - Allows access to remote SMB shares using UNIX commands +.SH "SYNOPSIS" +.HP 1 +smbsh [\-W\ workgroup] [\-U\ username] [\-P\ prefix] [\-R\ ] [\-d\ ] [\-l\ logdir] [\-L\ libdir] +.SH "DESCRIPTION" +.PP +This tool is part of the +\fBsamba\fR(7) +suite\. +.PP +smbsh +allows you to access an NT filesystem using UNIX commands such as +ls, +egrep, and +rcp\. You must use a shell that is dynamically linked in order for +smbsh +to work correctly\. +.SH "OPTIONS" +.PP +\-W WORKGROUP +.RS 4 +Override the default workgroup specified in the workgroup parameter of the +\fBsmb.conf\fR(5) +file for this session\. This may be needed to connect to some servers\. +.RE +.PP +\-U username[%pass] +.RS 4 +Sets the SMB username or username and password\. If this option is not specified, the user will be prompted for both the username and the password\. If %pass is not specified, the user will be prompted for the password\. +.RE +.PP +\-P prefix +.RS 4 +This option allows the user to set the directory prefix for SMB access\. The default value if this option is not specified is +\fIsmb\fR\. +.RE +.PP +\-s +.RS 4 +The file specified contains the configuration details required by the server\. The information in this file includes server\-specific information such as what printcap file to use, as well as descriptions of all the services that the server is to provide\. See +\fIsmb\.conf\fR +for more information\. The default configuration file name is determined at compile time\. +.RE +.PP +\-d|\-\-debuglevel=level +.RS 4 +\fIlevel\fR +is an integer from 0 to 10\. The default value if this parameter is not specified is 0\. +.sp +The higher this value, the more detail will be logged to the log files about the activities of the server\. At level 0, only critical errors and serious warnings will be logged\. Level 1 is a reasonable level for day\-to\-day running \- it generates a small amount of information about operations carried out\. +.sp +Levels above 1 will generate considerable amounts of log data, and should only be used when investigating a problem\. Levels above 3 are designed for use only by developers and generate HUGE amounts of log data, most of which is extremely cryptic\. +.sp +Note that specifying this parameter here will override the +\fIlog level\fR +parameter in the +\fIsmb\.conf\fR +file\. +.RE +.PP +\-R +.RS 4 +This option is used to determine what naming services and in what order to resolve host names to IP addresses\. The option takes a space\-separated string of different name resolution options\. +.sp +The options are: "lmhosts", "host", "wins" and "bcast"\. They cause names to be resolved as follows : +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} +\fBlmhosts\fR: Lookup an IP address in the Samba lmhosts file\. If the line in lmhosts has no name type attached to the NetBIOS name (see the +\fBlmhosts\fR(5) +for details) then any name type matches for lookup\. +.RE +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} +\fBhost\fR: Do a standard host name to IP address resolution, using the system +\fI/etc/hosts\fR, NIS, or DNS lookups\. This method of name resolution is operating system dependent, for instance on IRIX or Solaris this may be controlled by the +\fI/etc/nsswitch\.conf \fR +file)\. Note that this method is only used if the NetBIOS name type being queried is the 0x20 (server) name type, otherwise it is ignored\. +.RE +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} +\fBwins\fR: Query a name with the IP address listed in the +\fIwins server\fR +parameter\. If no WINS server has been specified this method will be ignored\. +.RE +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} +\fBbcast\fR: Do a broadcast on each of the known local interfaces listed in the +\fIinterfaces\fR +parameter\. This is the least reliable of the name resolution methods as it depends on the target host being on a locally connected subnet\. +.sp +.RE +If this parameter is not set then the name resolve order defined in the +\fIsmb\.conf\fR +file parameter (\fIname resolve order\fR) will be used\. +.sp +The default order is lmhosts, host, wins, bcast\. Without this parameter or any entry in the +\fIname resolve order\fR +parameter of the +\fIsmb\.conf\fR +file, the name resolution methods will be attempted in this order\. +.RE +.PP +\-L libdir +.RS 4 +This parameter specifies the location of the shared libraries used by +smbsh\. The default value is specified at compile time\. +.RE +.SH "EXAMPLES" +.PP +To use the +smbsh +command, execute +smbsh +from the prompt and enter the username and password that authenticates you to the machine running the Windows NT operating system\. +.sp +.RS 4 +.nf +system% \fBsmbsh\fR +Username: \fBuser\fR +Password: \fBXXXXXXX\fR +.fi +.RE +.PP +Any dynamically linked command you execute from this shell will access the +\fI/smb\fR +directory using the smb protocol\. For example, the command +ls /smb +will show a list of workgroups\. The command +ls /smb/MYGROUP +will show all the machines in the workgroup MYGROUP\. The command +ls /smb/MYGROUP/ +will show the share names for that machine\. You could then, for example, use the +cd +command to change directories, +vi +to edit files, and +rcp +to copy files\. +.SH "VERSION" +.PP +This man page is correct for version 3 of the Samba suite\. +.SH "BUGS" +.PP +smbsh +works by intercepting the standard libc calls with the dynamically loaded versions in +\fI smbwrapper\.o\fR\. Not all calls have been "wrapped", so some programs may not function correctly under +smbsh\. +.PP +Programs which are not dynamically linked cannot make use of +smbsh\'s functionality\. Most versions of UNIX have a +file +command that will describe how a program was linked\. +.SH "SEE ALSO" +.PP +\fBsmbd\fR(8), +\fBsmb.conf\fR(5) +.SH "AUTHOR" +.PP +The original Samba software and related utilities were created by Andrew Tridgell\. Samba is now developed by the Samba Team as an Open Source project similar to the way the Linux kernel is developed\. +.PP +The original Samba man pages were written by Karl Auer\. The man page sources were converted to YODL format (another excellent piece of Open Source software, available at +ftp://ftp\.icce\.rug\.nl/pub/unix/) and updated for the Samba 2\.0 release by Jeremy Allison\. The conversion to DocBook for Samba 2\.2 was done by Gerald Carter\. The conversion to DocBook XML 4\.2 for Samba 3\.0 was done by Alexander Bokovoy\. diff --git a/examples/libsmbclient/smbwrapper/smbsh.1.html b/examples/libsmbclient/smbwrapper/smbsh.1.html new file mode 100644 index 0000000000..a13451149d --- /dev/null +++ b/examples/libsmbclient/smbwrapper/smbsh.1.html @@ -0,0 +1,108 @@ +smbsh

Name

smbsh — Allows access to remote SMB shares + using UNIX commands

Synopsis

smbsh [-W workgroup] [-U username] [-P prefix] [-R <name resolve order>] [-d <debug level>] [-l logdir] [-L libdir]

DESCRIPTION

This tool is part of the samba(7) suite.

smbsh allows you to access an NT filesystem + using UNIX commands such as ls, + egrep, and rcp. You must use a + shell that is dynamically linked in order for smbsh + to work correctly.

OPTIONS

-W WORKGROUP

Override the default workgroup specified in the + workgroup parameter of the smb.conf(5) file + for this session. This may be needed to connect to some + servers.

-U username[%pass]

Sets the SMB username or username and password. + If this option is not specified, the user will be prompted for + both the username and the password. If %pass is not specified, + the user will be prompted for the password. +

-P prefix

This option allows + the user to set the directory prefix for SMB access. The + default value if this option is not specified is + smb. +

-s <configuration file>

The file specified contains the +configuration details required by the server. The +information in this file includes server-specific +information such as what printcap file to use, as well +as descriptions of all the services that the server is +to provide. See smb.conf for more information. +The default configuration file name is determined at +compile time.

-d|--debuglevel=level

level is an integer +from 0 to 10. The default value if this parameter is +not specified is 0.

The higher this value, the more detail will be +logged to the log files about the activities of the +server. At level 0, only critical errors and serious +warnings will be logged. Level 1 is a reasonable level for +day-to-day running - it generates a small amount of +information about operations carried out.

Levels above 1 will generate considerable +amounts of log data, and should only be used when +investigating a problem. Levels above 3 are designed for +use only by developers and generate HUGE amounts of log +data, most of which is extremely cryptic.

Note that specifying this parameter here will +override the log level parameter +in the smb.conf file.

-R <name resolve order>

This option is used to determine what naming +services and in what order to resolve +host names to IP addresses. The option takes a space-separated +string of different name resolution options.

The options are: "lmhosts", "host", "wins" and "bcast". +They cause names to be resolved as follows :

  • lmhosts: +Lookup an IP address in the Samba lmhosts file. If the +line in lmhosts has no name type attached to the +NetBIOS name +(see the lmhosts(5) for details) +then any name type matches for lookup. +

  • host: +Do a standard host name to IP address resolution, using +the system /etc/hosts, NIS, or DNS +lookups. This method of name resolution is operating +system dependent, for instance on IRIX or Solaris this +may be controlled by the /etc/nsswitch.conf + file). Note that this method is only used +if the NetBIOS name type being queried is the 0x20 +(server) name type, otherwise it is ignored. +

  • wins: +Query a name with the IP address listed in the +wins server parameter. If no +WINS server has been specified this method will be +ignored. +

  • bcast: +Do a broadcast on each of the known local interfaces +listed in the interfaces +parameter. This is the least reliable of the name +resolution methods as it depends on the target host +being on a locally connected subnet. +

If this parameter is not set then the name resolve order +defined in the smb.conf file parameter +(name resolve order) will be used. +

The default order is lmhosts, host, wins, bcast. Without +this parameter or any entry in the name resolve order parameter of the smb.conf file, the name +resolution methods will be attempted in this order.

-L libdir

This parameter specifies the location of the + shared libraries used by smbsh. The default + value is specified at compile time. +

EXAMPLES

To use the smbsh command, execute + smbsh from the prompt and enter the username and password + that authenticates you to the machine running the Windows NT + operating system. +

+system% smbsh
+Username: user
+Password: XXXXXXX
+

Any dynamically linked command you execute from + this shell will access the /smb directory + using the smb protocol. For example, the command ls /smb + will show a list of workgroups. The command + ls /smb/MYGROUP will show all the machines in + the workgroup MYGROUP. The command + ls /smb/MYGROUP/<machine-name> will show the share + names for that machine. You could then, for example, use the + cd command to change directories, vi to + edit files, and rcp to copy files.

VERSION

This man page is correct for version 3 of the Samba suite.

BUGS

smbsh works by intercepting the standard + libc calls with the dynamically loaded versions in + smbwrapper.o. Not all calls have been "wrapped", so + some programs may not function correctly under smbsh + .

Programs which are not dynamically linked cannot make + use of smbsh's functionality. Most versions + of UNIX have a file command that will + describe how a program was linked.

AUTHOR

The original Samba software and related utilities + were created by Andrew Tridgell. Samba is now developed + by the Samba Team as an Open Source project similar + to the way the Linux kernel is developed.

The original Samba man pages were written by Karl Auer. + The man page sources were converted to YODL format (another + excellent piece of Open Source software, available at + ftp://ftp.icce.rug.nl/pub/unix/) and updated for the Samba 2.0 + release by Jeremy Allison. The conversion to DocBook for + Samba 2.2 was done by Gerald Carter. The conversion to DocBook XML 4.2 + for Samba 3.0 was done by Alexander Bokovoy.

diff --git a/examples/libsmbclient/smbwrapper/smbsh.1.xml b/examples/libsmbclient/smbwrapper/smbsh.1.xml new file mode 100644 index 0000000000..5494f351c3 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/smbsh.1.xml @@ -0,0 +1,164 @@ + + + + + + smbsh + 1 + Samba + User Commands + 3.2 + + + + + smbsh + Allows access to remote SMB shares + using UNIX commands + + + + + smbsh + -W workgroup + -U username + -P prefix + -R <name resolve order> + -d <debug level> + -l logdir + -L libdir + + + + + DESCRIPTION + + This tool is part of the samba + 7 suite. + + smbsh allows you to access an NT filesystem + using UNIX commands such as ls, + egrep, and rcp. You must use a + shell that is dynamically linked in order for smbsh + to work correctly. + + + + OPTIONS + + + + -W WORKGROUP + Override the default workgroup specified in the + workgroup parameter of the smb.conf + 5 file + for this session. This may be needed to connect to some + servers. + + + + -U username[%pass] + Sets the SMB username or username and password. + If this option is not specified, the user will be prompted for + both the username and the password. If %pass is not specified, + the user will be prompted for the password. + + + + + -P prefix + This option allows + the user to set the directory prefix for SMB access. The + default value if this option is not specified is + smb. + + + + &stdarg.configfile; + &stdarg.server.debug; + &stdarg.resolve.order; + + + -L libdir + This parameter specifies the location of the + shared libraries used by smbsh. The default + value is specified at compile time. + + + + + + + + EXAMPLES + + To use the smbsh command, execute + smbsh from the prompt and enter the username and password + that authenticates you to the machine running the Windows NT + operating system. + +system% smbsh +Username: user +Password: XXXXXXX + + + + Any dynamically linked command you execute from + this shell will access the /smb directory + using the smb protocol. For example, the command ls /smb + will show a list of workgroups. The command + ls /smb/MYGROUP will show all the machines in + the workgroup MYGROUP. The command + ls /smb/MYGROUP/<machine-name> will show the share + names for that machine. You could then, for example, use the + cd command to change directories, vi to + edit files, and rcp to copy files. + + + + VERSION + + This man page is correct for version 3 of the Samba suite. + + + + BUGS + + smbsh works by intercepting the standard + libc calls with the dynamically loaded versions in + smbwrapper.o. Not all calls have been "wrapped", so + some programs may not function correctly under smbsh + . + + Programs which are not dynamically linked cannot make + use of smbsh's functionality. Most versions + of UNIX have a file command that will + describe how a program was linked. + + + + + SEE ALSO + smbd + 8, smb.conf + 5 + + + + AUTHOR + + The original Samba software and related utilities + were created by Andrew Tridgell. Samba is now developed + by the Samba Team as an Open Source project similar + to the way the Linux kernel is developed. + + The original Samba man pages were written by Karl Auer. + The man page sources were converted to YODL format (another + excellent piece of Open Source software, available at + ftp://ftp.icce.rug.nl/pub/unix/) and updated for the Samba 2.0 + release by Jeremy Allison. The conversion to DocBook for + Samba 2.2 was done by Gerald Carter. The conversion to DocBook XML 4.2 + for Samba 3.0 was done by Alexander Bokovoy. + + + -- cgit From ef0a7b0b94cfb9b57d634b083d2b2652bb88865d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 23 Jun 2008 11:00:20 +0200 Subject: Add krb5 support for the testbrowse example. Signed-off-by: Andreas Schneider Signed-off-by: Derrell Lipman (This used to be commit 84b1ea39a4f27ebcf06a2bafed78396c7353df0e) --- examples/libsmbclient/get_auth_data_fn.h | 13 ++++++++++++- examples/libsmbclient/testbrowse.c | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/get_auth_data_fn.h b/examples/libsmbclient/get_auth_data_fn.h index b1d36c8bea..6b91c97337 100644 --- a/examples/libsmbclient/get_auth_data_fn.h +++ b/examples/libsmbclient/get_auth_data_fn.h @@ -1,3 +1,5 @@ +#include + static void get_auth_data_fn(const char * pServer, const char * pShare, @@ -15,6 +17,8 @@ get_auth_data_fn(const char * pServer, char username[256] = { '\0' }; char password[256] = { '\0' }; + static int krb5_set = 1; + if (strcmp(server, pServer) == 0 && strcmp(share, pShare) == 0 && *workgroup != '\0' && @@ -25,7 +29,12 @@ get_auth_data_fn(const char * pServer, strncpy(pPassword, password, maxLenPassword - 1); return; } - + + if (krb5_set && getenv("KRB5CCNAME")) { + krb5_set = 0; + return; + } + fprintf(stdout, "Workgroup: [%s] ", pWorkgroup); fgets(temp, sizeof(temp), stdin); @@ -68,4 +77,6 @@ get_auth_data_fn(const char * pServer, strncpy(workgroup, pWorkgroup, sizeof(workgroup) - 1); strncpy(username, pUsername, sizeof(username) - 1); strncpy(password, pPassword, sizeof(password) - 1); + + krb5_set = 1; } diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index a7eda365af..a6e6395078 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -117,6 +117,9 @@ main(int argc, char * argv[]) smbc_setFunctionAuthData(context, get_auth_data_fn); } + smbc_setOptionUseKerberos(context, 1); + smbc_setOptionFallbackAfterKerberos(context, 1); + /* If we've been asked to log to stderr instead of stdout, ... */ if (debug_stderr) { /* ... then set the option to do so */ -- cgit From 03991ab0734ecbb87a75238d1356fbe0e5b1d38d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Aug 2008 13:35:15 -0700 Subject: Fix bug 5686 - libsmbclient segfaults with more than one SMBCCTX. Here is a patch to allow many subsystems to be re-initialized. The only functional change I made was to remove the null context tracking, as the memory allocated here is designed to be left for the complete lifetime of the program. Freeing this early (when all smb contexts are destroyed) could crash other users of talloc. Jeremy. (This used to be commit 8c630efd25cf17aff59448ca05c1b44a41964b16) --- examples/libsmbclient/Makefile | 4 ++++ examples/libsmbclient/testctx.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 examples/libsmbclient/testctx.c (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 7415f4f07e..047addc8f7 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -94,6 +94,10 @@ testwrite: testwrite.o @echo Linking testwrite $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt +testctx: testctx.o + @echo Linking testctx + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBSMBCLIENT) -lpopt + smbsh: make -C smbwrapper diff --git a/examples/libsmbclient/testctx.c b/examples/libsmbclient/testctx.c new file mode 100644 index 0000000000..8820bc8342 --- /dev/null +++ b/examples/libsmbclient/testctx.c @@ -0,0 +1,17 @@ +#include + +void create_and_destroy_context (void) +{ + SMBCCTX *ctx; + ctx = smbc_new_context (); + smbc_init_context (ctx); + + smbc_free_context (ctx, 1); +} + +int main (int argc, char **argv) +{ + create_and_destroy_context (); + create_and_destroy_context (); + return 0; +} -- cgit From f1a45e3b6b2b9f3ebeec7163fbedc027702eb1a2 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 21 Aug 2008 10:41:11 +0200 Subject: libsmbclient examples: fix prototype for readlink Michael (This used to be commit 28688cfd57c322937f2c63087380c377bd961018) --- examples/libsmbclient/smbwrapper/wrapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c index 958e00636e..3811b04356 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.c +++ b/examples/libsmbclient/smbwrapper/wrapper.c @@ -1109,7 +1109,7 @@ int utimes(const char *name, const struct timeval *tvp) return (* smbw_libc.utimes)((char *) name, (struct timeval *) tvp); } -int readlink(const char *path, char *buf, size_t bufsize) +ssize_t readlink(const char *path, char *buf, size_t bufsize) { check_init("readlink"); -- cgit From f14e833c53cffc51439013930fd78c2e9fe47a2d Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 21 Aug 2008 10:48:44 +0200 Subject: libsmbclient examples: add Makefile.internal.in for building from a samba source Without needing to install libsmbclient to /usr/local/samba first. Michael (This used to be commit f0e47bce2e98131812e96fb88cc3d1fe939e8d6c) --- examples/libsmbclient/Makefile.internal.in | 138 +++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 examples/libsmbclient/Makefile.internal.in (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/Makefile.internal.in b/examples/libsmbclient/Makefile.internal.in new file mode 100644 index 0000000000..dd4518f212 --- /dev/null +++ b/examples/libsmbclient/Makefile.internal.in @@ -0,0 +1,138 @@ +# Makefile.internal.in for building the libsmbclient examples +# from within a samba build. +# +# Use Makfile for building the examples with a libsmbclient +# installed to /usr/local/samba + +CC = @CC@ + +SAMBA_DIR = ../../source +SAMBA_INCLUDES = -I$(SAMBA_DIR)/include +SAMBA_LIBPATH = -L$(SAMBA_DIR)/bin + +GTK_CFLAGS = `gtk-config --cflags` +GTK_LIBS = `gtk-config --libs` + +#GTK_CFLAGS = `pkg-config gtk+-2.0 --cflags` +#GTK_LIBS = `pkg-config gtk+-2.0 --libs` + +FLAGS = @CPPFLAGS@ @CFLAGS@ $(GTK_CFLAGS) $(SAMBA_INCLUDES) + +PICFLAG=@PICFLAG@ +LDFLAGS= $(SAMBA_LIBPATH) @PIE_LDFLAGS@ @LDFLAGS@ + +EXTERNAL_LIBS = @LIBS@ @LDAP_LIBS@ @KRB5_LIBS@ @NSCD_LIBS@ +LIBSMBCLIENT_LIBS = -lwbclient -lsmbclient -ltalloc -ltdb -ldl -lresolv +CMDLINE_LIBS = @POPTLIBS@ +LIBS = $(EXTERNAL_LIBS) $(LIBSMBCLIENT_LIBS) + +# Compile a source file. (.c --> .o) +COMPILE_CC = $(CC) -I. $(FLAGS) $(PICFLAG) -c $< -o $@ +COMPILE = $(COMPILE_CC) + +MAKEDIR = || exec false; \ + if test -d "$$dir"; then :; else \ + echo mkdir "$$dir"; \ + mkdir -p "$$dir" >/dev/null 2>&1 || \ + test -d "$$dir" || \ + mkdir "$$dir" || \ + exec false; fi || exec false + +TESTS= testsmbc \ + testacl \ + testacl2 \ + testacl3 \ + testbrowse \ + testbrowse2 \ + teststat \ + teststat2 \ + teststat3 \ + testtruncate \ + testchmod \ + testutime \ + testread \ + testwrite + +# tree \ + +all: $(TESTS) smbsh + +.c.o: + @if (: >> $@ || : > $@) >/dev/null 2>&1; then rm -f $@; else \ + dir=`echo $@ | sed 's,/[^/]*$$,,;s,^$$,.,'` $(MAKEDIR); fi + @echo Compiling $*.c + @$(COMPILE) && exit 0;\ + echo "The following command failed:" 1>&2;\ + echo "$(COMPILE_CC)" 1>&2;\ + $(COMPILE_CC) >/dev/null 2>&1 + +testsmbc: testsmbc.o + @echo Linking testsmbc + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) + +tree: tree.o + @echo Linking tree + @$(CC) $(GTK_CFLAGS) $(FLAGS) $(LDFLAGS) -o $@ $< $(GTK_LIBS) $(LIBS) + +testacl: testacl.o + @echo Linking testacl + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testacl2: testacl2.o + @echo Linking testacl2 + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testacl3: testacl3.o + @echo Linking testacl3 + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testbrowse: testbrowse.o + @echo Linking testbrowse + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testbrowse2: testbrowse2.o + @echo Linking testbrowse2 + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +teststat: teststat.o + @echo Linking teststat + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +teststat2: teststat2.o + @echo Linking teststat2 + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +teststat3: teststat3.o + @echo Linking teststat3 + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testtruncate: testtruncate.o + @echo Linking testtruncate + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testchmod: testchmod.o + @echo Linking testchmod + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testutime: testutime.o + @echo Linking testutime + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testread: testread.o + @echo Linking testread + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testwrite: testwrite.o + @echo Linking testwrite + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +testctx: testctx.o + @echo Linking testctx + @$(CC) $(FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(CMDLINE_LIBS) + +smbsh: + make -C smbwrapper + +clean: + @rm -f *.o *~ $(TESTS) + @make -C smbwrapper clean -- cgit From fb0b833001d203dc43bb9f415e9792812194655a Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 21 Aug 2008 10:49:57 +0200 Subject: libsmbclient examples: source/bin to the library search path for smbwrapper build Michael (This used to be commit fe62098666a16b31b025867f273d407e77152c4c) --- examples/libsmbclient/smbwrapper/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient') diff --git a/examples/libsmbclient/smbwrapper/Makefile b/examples/libsmbclient/smbwrapper/Makefile index 7f5c17c79f..eb470056e1 100644 --- a/examples/libsmbclient/smbwrapper/Makefile +++ b/examples/libsmbclient/smbwrapper/Makefile @@ -3,7 +3,7 @@ DEFS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE CFLAGS = -I$(SAMBA_INCL) $(EXTLIB_INCL) -LDFLAGS = -L/usr/local/samba/lib +LDFLAGS = -L/usr/local/samba/lib -L../../../source/bin SMBINCLUDE = -I../../../source/include CFLAGS= -fpic -g -O0 $(DEFS) $(SMBINCLUDE) -- cgit