A fix to allow configure to find iconv on a number of systems including those
[Samba/gebeck_regimport.git] / source3 / smbwrapper / smbsh.c
blob221c6d87c2283eab306f4c35bf40fb6701990bb5
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_BINDIR;
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 u = fgets_slash(line, sizeof(line)-1, x_stdin);
87 smbw_setshared("USER", u);
90 if (!smbw_getshared("PASSWORD")) {
91 p = getpass("Password: ");
92 smbw_setshared("PASSWORD", p);
95 setenv("PS1", "smbsh$ ", 1);
97 sys_getwd(wd);
99 slprintf(line,sizeof(line)-1,"PWD_%d", (int)getpid());
101 smbw_setshared(line, wd);
103 slprintf(line,sizeof(line)-1,"%s/smbwrapper.so", libd);
104 setenv("LD_PRELOAD", line, 1);
106 slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd);
108 if (file_exist(line, NULL)) {
109 slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd);
110 setenv("_RLD_LIST", line, 1);
111 slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd);
112 setenv("_RLDN32_LIST", line, 1);
113 } else {
114 slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd);
115 setenv("_RLD_LIST", line, 1);
119 char *shellpath = getenv("SHELL");
120 if(shellpath)
121 execl(shellpath,"smbsh",NULL);
122 else
123 execl("/bin/sh","smbsh",NULL);
125 printf("launch failed!\n");
126 return 1;