r21400: fix version to 3.0.24 (Thanks Karolin)
[Samba.git] / source / smbwrapper / smbsh.c
blob8c9d971bbe266288b31b411dc3b2b14e8daa3cca
1 /*
2 Unix SMB/CIFS implementation.
3 SMB wrapper functions - frontend
4 Copyright (C) Andrew Tridgell 1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
23 static void smbsh_usage(void)
25 printf("smbsh [options]\n\n");
26 printf(" -W workgroup\n");
27 printf(" -U username\n");
28 printf(" -P prefix\n");
29 printf(" -R resolve order\n");
30 printf(" -d debug level\n");
31 printf(" -l logfile\n");
32 printf(" -L libdir\n");
33 exit(0);
36 int main(int argc, char *argv[])
38 char *p, *u;
39 const char *libd = dyn_LIBDIR;
40 pstring line, wd;
41 int opt;
42 extern char *optarg;
43 extern int optind;
45 dbf = x_stdout;
46 smbw_setup_shared();
48 while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) {
49 switch (opt) {
50 case 'L':
51 libd = optarg;
52 break;
53 case 'W':
54 smbw_setshared("WORKGROUP", optarg);
55 break;
56 case 'l':
57 smbw_setshared("LOGFILE", optarg);
58 break;
59 case 'P':
60 smbw_setshared("PREFIX", optarg);
61 break;
62 case 'd':
63 smbw_setshared("DEBUG", optarg);
64 break;
65 case 'U':
66 p = strchr_m(optarg,'%');
67 if (p) {
68 *p=0;
69 smbw_setshared("PASSWORD",p+1);
71 smbw_setshared("USER", optarg);
72 break;
73 case 'R':
74 smbw_setshared("RESOLVE_ORDER",optarg);
75 break;
77 case 'h':
78 default:
79 smbsh_usage();
84 if (!smbw_getshared("USER")) {
85 printf("Username: ");
86 fflush(stdout);
87 u = fgets_slash(line, sizeof(line)-1, x_stdin);
88 smbw_setshared("USER", u);
91 if (!smbw_getshared("PASSWORD")) {
92 p = getpass("Password: ");
93 smbw_setshared("PASSWORD", p);
96 setenv("PS1", "smbsh$ ", 1);
98 sys_getwd(wd);
100 slprintf(line,sizeof(line)-1,"PWD_%d", (int)getpid());
102 smbw_setshared(line, wd);
104 slprintf(line,sizeof(line)-1,"%s/smbwrapper.so", libd);
105 setenv("LD_PRELOAD", line, 1);
107 slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd);
109 if (file_exist(line, NULL)) {
110 slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd);
111 setenv("_RLD_LIST", line, 1);
112 slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd);
113 setenv("_RLDN32_LIST", line, 1);
114 } else {
115 slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd);
116 setenv("_RLD_LIST", line, 1);
120 char *shellpath = getenv("SHELL");
121 if(shellpath)
122 execl(shellpath,"smbsh",NULL);
123 else
124 execl("/bin/sh","smbsh",NULL);
126 printf("launch failed!\n");
127 return 1;