static char sccsid
[] = "%W% (Berkeley) %G%";
/* cntrl 2.7 5/24/79 21:37:36 */
* with fix below - mcg 1/24/82
static char SiD
[] = "@(#)cntrl 2.7";
extern int gturnon(), gturnoff();
extern int grdmsg(), grddata();
extern int gwrmsg(), gwrdata();
'g', gturnon
, grdmsg
, gwrmsg
, grddata
, gwrdata
, gturnoff
,
int (*Rdmsg
)()=imsg
, (*Rddata
)();
int (*Wrmsg
)()=omsg
, (*Wrdata
)();
int (*Turnon
)(), (*Turnoff
)();
#define EM_LOCACC "N1" /* local access to file denied */
#define EM_RMTACC "N2" /* remote access to file/path denied */
#define EM_BADUUCP "N3" /* a bad uucp command was generated */
#define EM_NOTMP "N4" /* remote error - can't create temp */
#define EM_RMTCP "N5" /* can't copy to remote directory - file in public */
#define EM_LOCCP "N6" /* can't copy on local system */
"COPY FAILED (reason not given by remote)",
"local access to file denied",
"remote access to path/file denied",
"system error - bad uucp command generated",
"remote system can't create temp file",
"can't copy to file/directory - file left in PUBDIR/user/file",
"can't copy to file/directory - file left in PUBDIR/user/file"
#define XUUCP 'X' /* execute uucp (string) */
#define SLTPTCL 'P' /* select protocol (string) */
#define USEPTCL 'U' /* use protocol (character) */
#define RCVFILE 'R' /* receive file (string) */
#define SNDFILE 'S' /* send file (string) */
#define RQSTCMPT 'C' /* request complete (string - yes | no) */
#define HUP 'H' /* ready to hangup (string - yes | no) */
#define W_FILE1 wrkvec[1]
#define W_FILE2 wrkvec[2]
#define W_OPTNS wrkvec[4]
#define W_DFILE wrkvec[5]
#define RMESG(m, s) if (rmesg(m, s) != 0) {(*Turnoff)(); return(FAIL);}
#define RAMESG(s) if (rmesg('\0', s) != 0) {(*Turnoff)(); return(FAIL);}
#define WMESG(m, s) if(wmesg(m, s) != 0) {(*Turnoff)(); return(FAIL);}
char Wfile
[MAXFULLNAME
] = {'\0'};
* cntrl - this routine will execute the conversation
* between the two machines after both programs are
char msg
[BUFSIZ
], rqstr
[BUFSIZ
];
char filename
[MAXFULLNAME
], wrktype
, *wrkvec
[20];
extern (*Rdmsg
)(), (*Wrmsg
)();
extern char *index(), *lastpart();
static int pnum
, tmpnum
= 0;
DEBUG(4, "*** TOP *** - role=%d, ", role
);
strcpy(spoolsubdir
, Spool
);
strcat(spoolsubdir
, "/C.");
/* asw: 8/3/81: fixed to initialize wrkvec at top of loop */
/* set wrkvec array to known state */
/* installed by S. McGeady at azure 1/26/82 */
for (i
= 0; i
< (sizeof wrkvec
/sizeof wrkvec
[0]); i
++)
if ((i
= gtwvec(Wfile
, spoolsubdir
, wkpre
, wrkvec
)) == 0) {
mailopt
= index(W_OPTNS
, 'm') != NULL
;
DEBUG(4, "wrktype %c, ", wrktype
);
for (n
= 1; n
< i
; n
++) {
sprintf(rqstr
, "X %s", msg
);
logent(rqstr
, "REQUEST");
ASSERT(i
> 4, "ARG COUNT - %d\n", i
);
sprintf(msg
, " %s %s %s %s %s %s",
W_FILE1
, W_FILE2
, W_USER
,
W_OPTNS
, W_DFILE
, i
>5 ? W_MODE
: "");
ASSERT(strlen(User
) <= 10, "User - %s\n", User
);
ASSERT(strlen(User
) <= 14, "User - %s\n", User
);
sprintf(rqstr
, "%s %s %s %s", W_TYPE
, W_FILE1
,
logent(rqstr
, "REQUEST");
DEBUG(4, "User - %s\n", User
);
if (wrktype
== SNDFILE
) {
strcpy(filename
, W_FILE1
);
if (chkpth(User
, "", filename
) || anyread(filename
)) {
logent("DENIED", "ACCESS");
lnotify(User
, filename
, "access denied");
if (index(W_OPTNS
, 'c') == NULL
)
(fp
= fopen(filename
, "r")) == NULL
) {
/* can not read data file */
logent("CAN'T READ DATA", "FAILED");
lnotify(User
, filename
, "can't access");
if (wrktype
== RCVFILE
) {
strcpy(filename
, W_FILE2
);
if (chkpth(User
, "", filename
)
|| chkperm(filename
, User
, index(W_OPTNS
, 'd'))) {
logent("DENIED", "ACCESS");
lnotify(User
, filename
, "access denied");
sprintf(Dfile
, "%s/TM.%05d.%03d", Spool
, pnum
, tmpnum
++);
if ((fp
= fopen(Dfile
, "w")) == NULL
) {
/* can not create temp */
logent("CAN'T CREATE TM", "FAILED");
DEBUG(4, "wrktype - %c, ", wrktype
);
DEBUG(4, " fileno - %d\n", fileno(fp
));
ultouch(); /* touch all lock files */
DEBUG(4, " PROCESS: msg - %s\n", msg
);
DEBUG(4, "%s\n", "RQSTCMPT:");
logent(msg
, "REQUESTED");
notify(mailopt
, W_USER
, W_FILE1
, Rmtname
, &msg
[1]);
DEBUG(4, "%s\n", "HUP:");
if (!iswrk(Wfile
, "chk", spoolsubdir
, wkpre
)) {
i
= getargs(msg
, wrkvec
);
strcpy(filename
, W_FILE1
);
if (index(filename
, ';') != NULL
|| index(W_FILE2
, ';') != NULL
if (chkpth("", Rmtname
, filename
)) {
logent("XUUCP DENIED", filename
);
sprintf(rqstr
, "%s %s", filename
, W_FILE2
);
/* MASTER section of SNDFILE */
DEBUG(4, "%s\n", "SNDFILE:");
logent(Em_msg
[i
], "REQUEST");
notify(mailopt
, W_USER
, W_FILE1
, Rmtname
, &msg
[1]);
ret
= (*Wrdata
)(fp
, Ofn
);
/* SLAVE section of SNDFILE */
/* request to receive file */
i
= getargs(msg
, wrkvec
);
ASSERT(i
> 4, "ARG COUNT - %d\n", i
);
sprintf(rqstr
, "%s %s %s %s", W_TYPE
, W_FILE1
,
logent(rqstr
, "REQUESTED");
DEBUG(4, "msg - %s\n", msg
);
DEBUG(4, "W_FILE2 - %s\n", W_FILE2
);
strcpy(filename
, W_FILE2
);
if (chkpth("", Rmtname
, filename
)
|| chkperm(filename
, Loginuser
, index(W_OPTNS
, 'd'))) {
WMESG(SNDFILE
, EM_RMTACC
);
logent("DENIED", "PERMISSION");
strcat(filename
, lastpart(W_FILE1
));
ASSERT(strlen(User
) <= 10, "User - %s\n", User
);
ASSERT(strlen(User
) <= 14, "User - %s\n", User
);
DEBUG(4, "chkpth ok Rmtname - %s\n", Rmtname
);
sprintf(Dfile
, "%s/TM.%05d.%03d", Spool
, pnum
, tmpnum
++);
if((fp
= fopen(Dfile
, "w")) == NULL
) {
WMESG(SNDFILE
, EM_NOTMP
);
logent("CAN'T OPEN", "DENIED");
ret
= (*Rddata
)(Ifn
, fp
);
/* copy to user directory */
status
= xmv(Dfile
, filename
);
WMESG(RQSTCMPT
, status
? EM_RMTCP
: YES
);
logent(status
? "FAILED" : "SUCCEEDED", "COPY");
sscanf(W_MODE
, "%o", &filemode
);
DEBUG(4, "mode - %o\n", filemode
);
chmod(filename
, filemode
| 0666);
putinpub(filename
, Dfile
, W_USER
);
/* MASTER section of RCVFILE */
DEBUG(4, "%s\n", "RCVFILE:");
logent(Em_msg
[i
], "REQUEST");
notify(mailopt
, W_USER
, W_FILE1
, Rmtname
, &msg
[1]);
ret
= (*Rddata
)(Ifn
, fp
);
/* copy to user directory */
strcat(filename
, lastpart(W_FILE1
));
status
= xmv(Dfile
, filename
);
WMESG(RQSTCMPT
, status
? EM_RMTCP
: YES
);
logent(status
? "FAILED" : "SUCCEEDED", "COPY");
notify(mailopt
, W_USER
, filename
, Rmtname
,
status
? EM_LOCCP
: YES
);
sscanf(&msg
[2], "%o", &filemode
);
DEBUG(4, "mode - %o\n", filemode
);
chmod(filename
, filemode
| 0666);
putinpub(filename
, Dfile
, W_USER
);
/* SLAVE section of RCVFILE */
/* request to send file */
logent(rqstr
, "REQUESTED");
i
= getargs(msg
, wrkvec
);
ASSERT(i
> 3, "ARG COUNT - %d\n", i
);
DEBUG(4, "msg - %s\n", msg
);
DEBUG(4, "W_FILE1 - %s\n", W_FILE1
);
strcpy(filename
, W_FILE1
);
strcat(filename
, lastpart(W_FILE2
));
ASSERT(strlen(User
) <= 10, "User - %s\n", User
);
ASSERT(strlen(User
) <= 14, "User - %s\n", User
);
if (chkpth("", Rmtname
, filename
) || anyread(filename
)) {
WMESG(RCVFILE
, EM_RMTACC
);
logent("DENIED", "PERMISSION");
DEBUG(4, "chkpth ok Rmtname - %s\n", Rmtname
);
if ((fp
= fopen(filename
, "r")) == NULL
) {
WMESG(RCVFILE
, EM_RMTACC
);
logent("CAN'T OPEN", "DENIED");
ret
= stat(filename
, &stbuf
);
ASSERT(ret
!= -1, "STAT FAILED %s", filename
);
sprintf(msg
, "%s %o", YES
, stbuf
.st_mode
& 0777);
ret
= (*Wrdata
)(fp
, Ofn
);
* rmesg(c, msg) read message 'c'
DEBUG(4, "rmesg - '%c' ", c
);
if ((*Rdmsg
)(msg
, Ifn
) != 0) {
DEBUG(4, "got %s\n", "FAIL");
sprintf(str
, "expected '%c' got FAIL", c
);
if (c
!= '\0' && msg
[0] != c
) {
DEBUG(4, "got %s\n", msg
);
sprintf(str
, "expected '%c' got %.25s", c
, msg
);
DEBUG(4, "got %.25s\n", msg
);
* wmesg(m, s) write a message (type m)
* return codes: 0 - ok | FAIL - ng
DEBUG(4, "wmesg '%c'", m
);
return((*Wrmsg
)(m
, s
, Ofn
));
* notify mail results of command
notify(mailopt
, user
, file
, sys
, msgcode
)
char *user
, *file
, *sys
, *msgcode
;
if (!mailopt
&& *msgcode
== 'Y')
sprintf(str
, "file %s, system %s\n%s\n",
* lnotify(user, file, mesg) - local notify
lnotify(user
, file
, mesg
)
char *user
, *file
, *mesg
;
sprintf(mbuf
, "file %s on %s\n%s\n", file
, Myname
, mesg
);
* startup - this routine will converse with the remote
* machine, agree upon a protocol (if possible) and start the
* SUCCESS - successful protocol selection
* FAIL - can't find common or open failed
extern (*Rdmsg
)(), (*Wrmsg
)();
extern char *blptcl(), fptcl();
char msg
[BUFSIZ
], str
[BUFSIZ
];
if ((str
[0] = fptcl(&msg
[1])) == NULL
) {
DEBUG(4, "protocol %s\n", str
);
WMESG(SLTPTCL
, blptcl(str
));
if (stptcl(&msg
[1]) != 0)
DEBUG(4, "Protocol %s\n", msg
);
* fptcl - this routine will choose a protocol from
* the input string (str) and return the found letter.
* '\0' - no acceptable protocol
* any character - the chosen protocol
for (p
= Ptbl
; p
->P_id
!= '\0'; p
++) {
if (index(str
, p
->P_id
) != NULL
) {
* blptcl - this will build a string of the
* letters of the available protocols and return
* a pointer to string (str)
for (p
= Ptbl
, s
= str
; (*s
++ = p
->P_id
) != '\0'; p
++);
* stptcl - this routine will set up the six routines
* (Rdmsg, Wrmsg, Rddata, Wrdata, Turnon, Turnoff) for the
* FAIL - no find or failed to open
for (p
= Ptbl
; p
->P_id
!= '\0'; p
++) {
/* found protocol - set routines */
DEBUG(4, "Proto started %c\n", *c
);
DEBUG(4, "Proto start-fail %c\n", *c
);
* putinpub put file in public place
putinpub(file
, tmp
, user
)
char fullname
[MAXFULLNAME
];
sprintf(fullname
, "%s/%s/", PUBDIR
, user
);
if (mkdirs(fullname
) != 0) {
/* can not make directories */
strcat(fullname
, lastpart(file
));
* unlinkdf(file) - unlink D. file