Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/cs/vcs_src/ifs_rsh.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
/*
21
* File: ifs_rsh.c
22
*/
23
24
#include "ifs_agent.h"
25
#include <stdio.h>
26
27
struct {
28
int version;
29
} rsh_data;
30
31
/*
32
* name: RshGetFile
33
* get a file/directory from remote host
34
*/
35
int
36
RshGetFile( srv )
37
struct server_info *srv;
38
{
39
struct mount_item *mitem;
40
char cmd[ STRLEN ];
41
char tmpfile[ STRLEN ], buf[ STRLEN ];
42
char *lpath, *rpath, *hostid, *userid;
43
FILE *fp;
44
int fd;
45
46
lpath = srv->lpath;
47
rpath = srv->rpath;
48
mitem = srv->mitem;
49
hostid = mitem->host;
50
userid = mitem->user;
51
if( *rpath == '\0' || DashD( lpath ) ) {
52
if( *rpath == '\0' ) rpath = "/";
53
if( userid == NULL || *userid == '\0' ) {
54
sfsprintf( cmd, sizeof(cmd), "rsh %s", hostid );
55
} else {
56
sfsprintf( cmd, sizeof(cmd), "rsh -l %s %s", userid, hostid );
57
}
58
sfsprintf( buf, sizeof(buf), "%s /bin/ls -alL %s", cmd, rpath );
59
logit( buf );
60
logit( "\n" );
61
if( (fp = popen( buf, "rw" )) == NULL )
62
return -1;
63
MakeTmpFile( lpath, tmpfile, sizeof(tmpfile) );
64
if( (fd = open( tmpfile, O_WRONLY|O_CREAT, 0644 )) < 0 ) {
65
cserrno = E_DATAXFER;
66
return -1;
67
}
68
while( fgets( buf, sizeof(buf), fp ) != NULL )
69
write( fd, buf, strlen(buf) );
70
close( fd );
71
fclose( fp );
72
sfsprintf( buf, sizeof(buf), "%s/._dir", lpath );
73
MakePath( buf );
74
chdir( lpath );
75
ftp_makedents( tmpfile );
76
rename( tmpfile, "._dir" );
77
symlink( mitem->timeout, "._cache_time" );
78
} else {
79
if( userid == NULL || *userid == '\0' ) {
80
sfsprintf( cmd, sizeof(cmd), "%s", hostid );
81
} else {
82
sfsprintf( cmd, sizeof(cmd), "%s@%s", userid, hostid );
83
}
84
MakeTmpFile( lpath, tmpfile, sizeof(tmpfile) );
85
sfsprintf( buf, sizeof(buf), "rcp %s:%s %s", cmd, rpath, tmpfile );
86
logit( buf );
87
logit( "\n" );
88
if( (fp = popen( buf, "rw" )) == NULL )
89
return -1;
90
fclose( fp );
91
if( !DashF( tmpfile ) )
92
return -1;
93
MakePath( lpath );
94
rename( tmpfile, lpath );
95
}
96
return 0;
97
}
98
99
/*
100
* name: RshPutFile
101
* put a file/directory to remote host
102
*/
103
int
104
RshPutFile( srv )
105
struct server_info *srv;
106
{
107
return -1;
108
}
109
110
/*
111
* name: RshNop
112
* unimplement command
113
*/
114
int
115
RshNop()
116
{
117
return 0;
118
}
119
120
int
121
RshInit( tbl )
122
struct agent_item *tbl;
123
{
124
tbl->localdata = (char *) &rsh_data;
125
tbl->connect = RshNop;
126
tbl->disconnect = RshNop;
127
tbl->listdents = RshGetFile;
128
tbl->getfile = RshGetFile;
129
tbl->putfile = RshPutFile;
130
tbl->userdef = RshNop;
131
return 0;
132
}
133
134
135