Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/cs/vcs_src/mnt_mount.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "mnt_imount.h"
21
22
#include <ctype.h>
23
24
#define USAGE "mount [-f mount_file]\
25
[mount-point prot:/[user[:pass]@]host[:port][/remote-path]]"
26
27
char* getpass();
28
29
/*
30
* prot:/user:pass@host:port/remote-path
31
*/
32
33
char* checkfs(data, buf, size)
34
char* data;
35
char* buf;
36
int size;
37
{
38
register char* s;
39
register char* t;
40
char psbuf[1024];
41
char* pass;
42
43
if (!(s = strchr(data, '-')) || s[1] != '@') {
44
strcpy(buf, data);
45
return(buf);
46
}
47
t = strchr( s, '/' );
48
if( t ) *t = '\0';
49
sfsprintf( psbuf, sizeof(psbuf), "passwd (%s): ", data );
50
if( t ) *t = '/';
51
pass = getpass(psbuf);
52
*s = '\0';
53
sfsprintf( buf, size, "%s%s%s", data, pass, s+1 );
54
*s = '-';
55
return( buf );
56
}
57
58
59
int im_mount_help(s)
60
char* s;
61
{
62
printf("\t%s # mount a remote file server\n", USAGE);
63
return (0);
64
}
65
66
int im_mount(argc, argv)
67
int argc;
68
register char** argv;
69
{
70
register char* s;
71
register int n;
72
char buf[1024 * 2];
73
char reply[1024 * 2];
74
char mfsbuf[1024 * 2];
75
int fd;
76
char* mpoint;
77
char* mfs;
78
FILE* mfd = NULL;
79
80
error_info.id = argv[0];
81
memset(buf, 0, sizeof(buf));
82
memset(reply, 0, sizeof(reply));
83
memset(mfsbuf, 0, sizeof(mfsbuf));
84
85
opt_info.index = 1;
86
while (n = optget(argv, "s:[server]f:[mount-file] [mount-point prot,host,user,pass,time:remote-path]"))
87
switch (n)
88
{
89
case 's':
90
s = opt_info.arg;
91
if ((fd = csopen(s, CS_OPEN_READ)) < 0)
92
{
93
printf("cannot connect cs server %s\n", s);
94
return (-1);
95
}
96
istate.cs_svc = strdup(s);
97
istate.fd = fd;
98
break;
99
case 'f':
100
if ((mfd = fopen(opt_info.arg, "r")) == NULL)
101
{
102
printf("cannot connect file %s\n", opt_info.arg);
103
return(1);
104
}
105
break;
106
case '?':
107
case ':':
108
printf("%s\n", USAGE);
109
return (1);
110
}
111
112
113
114
argv += opt_info.index;
115
argc -= opt_info.index;
116
117
if (mfd == NULL)
118
{
119
if (argc < 2)
120
{
121
printf("%s\n", USAGE);
122
return (1);
123
}
124
mpoint = argv[0];
125
if ((mfs = checkfs(argv[1], buf, sizeof(buf))) == NULL)
126
{
127
printf("ERROR: %s\n", USAGE);
128
return (1);
129
}
130
if (callmount(fd, mpoint, mfs, reply) == 0)
131
{
132
printmtmsg(reply);
133
return (0);
134
}
135
else
136
{
137
printf("ERROR: %s", reply);
138
return (1);
139
}
140
}
141
142
/* mfd != NULL */
143
144
while((fgets(buf, 2048, mfd)))
145
{
146
if ((s = strchr(buf, '#')) != NULL)
147
*s = '\0';
148
for (s = buf; *s && isspace(*s); s++);
149
if (*s == '\0')
150
continue;
151
mpoint = s;
152
for (; *s && !isspace(*s); s++);
153
if (*s == '\0')
154
continue;
155
*s = '\0';
156
for (s++; *s && isspace(*s); s++);
157
if (*s == '\0')
158
continue;
159
mfs = s;
160
for (s; *s && !isspace(*s); s++);
161
*s = '\0';
162
if ((mfs = checkfs(mfs, mfsbuf, sizeof(mfsbuf))) == NULL)
163
{
164
printf("ERROR: %s\n", USAGE);
165
continue;
166
}
167
if (callmount(fd, mpoint, mfs, reply) == 0)
168
{
169
printmtmsg(reply);
170
continue;
171
}
172
}
173
return(0);
174
}
175
176
177
int callmount(fd, mpoint, mfs, reply)
178
int fd;
179
char* mpoint;
180
char* mfs;
181
char* reply;
182
{
183
char buf[1024];
184
185
memset(buf, 0, sizeof(buf));
186
187
if (mfs == NULL)
188
sfsprintf(buf, sizeof(buf), "m - %s\n", mpoint);
189
else
190
sfsprintf(buf, sizeof(buf), "m %s %s\n", mfs, mpoint);
191
if (vcs_write(buf) <= 0 || vcs_read(reply, 1024) <= 0)
192
return (-1);
193
if (strstr(reply, "ok ") != NULL)
194
(void)add_entry(mpoint, buf);
195
return (0);
196
}
197
198
199