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>
31 #include "bsd-strlfunc.h"
35 # define TRUE (! FALSE)
38 static void smbsh_usage(void)
40 printf("smbsh [options] [command [args] ...]\n\n");
41 printf(" -p prepend library name\n");
42 printf(" -a append library name\n");
44 printf(" -W workgroup\n");
45 printf(" -U username\n");
46 printf(" -P prefix\n");
47 printf(" -R resolve order\n");
48 printf(" -d debug level\n");
49 printf(" -l logfile\n");
50 printf(" -L libdir\n");
54 int main(int argc
, char *argv
[])
58 char line
[PATH_MAX
], pre
[PATH_MAX
], post
[PATH_MAX
];
67 while ((opt
= getopt(argc
, argv
, "p:a:d:nL:W:U:h")) != -1) {
69 case 'p': /* prepend library before smbwrapper.so */
71 smbw_strlcat(pre
, " ", sizeof(pre
));
72 smbw_strlcat(pre
, optarg
, sizeof(pre
));
75 case 'a': /* append library after smbwrapper.so */
76 smbw_strlcat(post
, " ", sizeof(post
));
77 smbw_strlcat(post
, optarg
, sizeof(post
));
81 setenv("DEBUG", optarg
, TRUE
);
84 case 'n': /* don't ask for username/password */
93 setenv("WORKGROUP", optarg
, TRUE
);
97 p
= strchr(optarg
,'%');
100 setenv("PASSWORD", p
+1, TRUE
);
102 setenv("USER", optarg
, TRUE
);
113 if (!getenv("USER")) {
114 printf("Username: ");
115 u
= fgets(line
, sizeof(line
)-1, stdin
);
116 setenv("USER", u
, TRUE
);
119 if (!getenv("PASSWORD")) {
120 p
= getpass("Password: ");
121 setenv("PASSWORD", p
, TRUE
);
125 smbw_strlcpy(line
, pre
, PATH_MAX
- strlen(line
));
126 smbw_strlcat(line
, " ", sizeof(line
));
127 smbw_strlcat(line
, libd
, sizeof(line
));
128 smbw_strlcat(line
, "/smbwrapper.so", sizeof(line
));
129 smbw_strlcat(line
, post
, sizeof(line
));
130 setenv("LD_PRELOAD", line
, TRUE
);
131 setenv("LD_BIND_NOW", "true", TRUE
);
133 snprintf(line
,sizeof(line
)-1,"%s/smbwrapper.32.so", libd
);
135 if (stat(line
, &statbuf
) == 0 && S_ISREG(statbuf
.st_mode
)) {
136 snprintf(line
, sizeof(line
)-1,
137 "%s/smbwrapper.32.so:DEFAULT", libd
);
138 setenv("_RLD_LIST", line
, TRUE
);
139 snprintf(line
, sizeof(line
)-1,
140 "%s/smbwrapper.so:DEFAULT", libd
);
141 setenv("_RLDN32_LIST", line
, TRUE
);
143 snprintf(line
,sizeof(line
)-1,"%s/smbwrapper.so:DEFAULT", libd
);
144 setenv("_RLD_LIST", line
, TRUE
);
148 execvp(argv
[optind
], &argv
[optind
]);
150 char *shellpath
= getenv("SHELL");
152 setenv("PS1", "smbsh$ ", TRUE
);
155 execl(shellpath
,"smbsh", NULL
);
157 setenv("SHELL", "/bin/sh", TRUE
);
158 execl("/bin/sh", "smbsh", NULL
);
161 printf("launch failed!\n");