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/smbwrapper/smbsh.c | 160 +++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 examples/libsmbclient/smbwrapper/smbsh.c (limited to 'examples/libsmbclient/smbwrapper/smbsh.c') 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; +} -- 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/smbsh.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'examples/libsmbclient/smbwrapper/smbsh.c') 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); -- 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/smbsh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient/smbwrapper/smbsh.c') 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, -- 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/smbsh.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/libsmbclient/smbwrapper/smbsh.c') 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 -- cgit