2 Unix SMB/Netbios implementation.
4 SMB wrapper functions - frontend
5 Copyright (C) Andrew Tridgell 1998
6 Copyright (C) Derrell Lipman 2003-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/types.h>
29 #include <libsmbclient.h>
30 #include "bsd-strlfunc.h"
34 # define TRUE (! FALSE)
37 static void smbsh_usage(void)
39 printf("smbsh [options] [command [args] ...]\n\n");
40 printf(" -p prepend library name\n");
41 printf(" -a append library name\n");
43 printf(" -W workgroup\n");
44 printf(" -U username\n");
45 printf(" -P prefix\n");
46 printf(" -R resolve order\n");
47 printf(" -d debug level\n");
48 printf(" -l logfile\n");
49 printf(" -L libdir\n");
53 int main(int argc, char *argv[])
57 char line[PATH_MAX], pre[PATH_MAX], post[PATH_MAX];
66 while ((opt = getopt(argc, argv, "p:a:d:nL:W:U:h")) != -1) {
68 case 'p': /* prepend library before smbwrapper.so */
70 smbw_strlcat(pre, " ", sizeof(pre));
71 smbw_strlcat(pre, optarg, sizeof(pre));
74 case 'a': /* append library after smbwrapper.so */
75 smbw_strlcat(post, " ", sizeof(post));
76 smbw_strlcat(post, optarg, sizeof(post));
80 setenv("DEBUG", optarg, TRUE);
83 case 'n': /* don't ask for username/password */
92 setenv("WORKGROUP", optarg, TRUE);
96 p = strchr(optarg,'%');
99 setenv("PASSWORD", p+1, TRUE);
101 setenv("USER", optarg, TRUE);
112 if (!getenv("USER")) {
113 printf("Username: ");
114 u = fgets(line, sizeof(line)-1, stdin);
115 setenv("USER", u, TRUE);
118 if (!getenv("PASSWORD")) {
119 p = getpass("Password: ");
120 setenv("PASSWORD", p, TRUE);
124 smbw_strlcpy(line, pre, PATH_MAX - strlen(line));
125 smbw_strlcat(line, " ", sizeof(line));
126 smbw_strlcat(line, libd, sizeof(line));
127 smbw_strlcat(line, "/smbwrapper.so", sizeof(line));
128 smbw_strlcat(line, post, sizeof(line));
129 setenv("LD_PRELOAD", line, TRUE);
130 setenv("LD_BIND_NOW", "true", TRUE);
132 snprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd);
134 if (stat(line, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
135 snprintf(line, sizeof(line)-1,
136 "%s/smbwrapper.32.so:DEFAULT", libd);
137 setenv("_RLD_LIST", line, TRUE);
138 snprintf(line, sizeof(line)-1,
139 "%s/smbwrapper.so:DEFAULT", libd);
140 setenv("_RLDN32_LIST", line, TRUE);
142 snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd);
143 setenv("_RLD_LIST", line, TRUE);
147 execvp(argv[optind], &argv[optind]);
149 char *shellpath = getenv("SHELL");
151 setenv("PS1", "smbsh$ ", TRUE);
154 execl(shellpath,"smbsh", NULL);
156 setenv("SHELL", "/bin/sh", TRUE);
157 execl("/bin/sh", "smbsh", NULL);
160 printf("launch failed!\n");