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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <sys/types.h>
30 #include <libsmbclient.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 strncat(pre, " ", PATH_MAX - strlen(pre));
71 strncat(pre, optarg, PATH_MAX - strlen(pre));
74 case 'a': /* append library after smbwrapper.so */
75 strncat(post, " ", PATH_MAX - strlen(post));
76 strncat(post, optarg, PATH_MAX - strlen(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 strncpy(line, pre, PATH_MAX - strlen(line));
125 strncat(line, " ", PATH_MAX - strlen(line));
126 strncat(line, libd, PATH_MAX - strlen(line));
127 strncat(line, "/smbwrapper.so", PATH_MAX - strlen(line));
128 strncat(line, post, PATH_MAX - strlen(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,"%s/smbwrapper.32.so:DEFAULT", libd);
136 setenv("_RLD_LIST", line, TRUE);
137 snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd);
138 setenv("_RLDN32_LIST", line, TRUE);
140 snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd);
141 setenv("_RLD_LIST", line, TRUE);
145 execvp(argv[optind], &argv[optind]);
147 char *shellpath = getenv("SHELL");
149 setenv("PS1", "smbsh$ ", TRUE);
152 execl(shellpath,"smbsh", NULL);
154 setenv("SHELL", "/bin/sh", TRUE);
155 execl("/bin/sh", "smbsh", NULL);
158 printf("launch failed!\n");