This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.
[kai/samba-autobuild/.git] / source / smbwrapper / smbsh.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB wrapper functions - frontend
4    Copyright (C) Andrew Tridgell 1998
5    
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.
10    
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.
15    
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.
19 */
20
21 #include "includes.h"
22
23 static void smbsh_usage(void)
24 {
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);
34 }
35
36 int main(int argc, char *argv[])
37 {
38         char *p, *u;
39         char *libd = dyn_BINDIR;
40         pstring line, wd;
41         int opt;
42         extern char *optarg;
43         extern int optind;
44
45         dbf = x_stdout;
46         smbw_setup_shared();
47
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);
70                         }
71                         smbw_setshared("USER", optarg);
72                         break;
73                 case 'R':
74                         smbw_setshared("RESOLVE_ORDER",optarg);
75                         break;
76
77                 case 'h':
78                 default:
79                         smbsh_usage();
80                 }
81         }
82
83
84         if (!smbw_getshared("USER")) {
85                 printf("Username: ");
86                 u = fgets_slash(line, sizeof(line)-1, x_stdin);
87                 smbw_setshared("USER", u);
88         }
89
90         if (!smbw_getshared("PASSWORD")) {
91                 p = getpass("Password: ");
92                 smbw_setshared("PASSWORD", p);
93         }
94
95         smbw_setenv("PS1", "smbsh$ ");
96
97         sys_getwd(wd);
98
99         slprintf(line,sizeof(line)-1,"PWD_%d", (int)getpid());
100
101         smbw_setshared(line, wd);
102
103         slprintf(line,sizeof(line)-1,"%s/smbwrapper.so", libd);
104         smbw_setenv("LD_PRELOAD", line);
105
106         slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd);
107
108         if (file_exist(line, NULL)) {
109                 slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd);
110                 smbw_setenv("_RLD_LIST", line);
111                 slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd);
112                 smbw_setenv("_RLDN32_LIST", line);
113         } else {
114                 slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd);
115                 smbw_setenv("_RLD_LIST", line);
116         }
117
118         {
119         char *shellpath = getenv("SHELL");
120                 if(shellpath)
121                         execl(shellpath,"smbsh",NULL);
122                 else
123                         execl("/bin/sh","smbsh",NULL);
124         }
125         printf("launch failed!\n");
126         return 1;
127 }