Routines to handle work requests.
Copyright (C) 1991, 1992 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The author of the program may be contacted at ian@airs.com or
c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
const char xcmd_rcsid
[] = "$Id: xcmd.c,v 1.1 1993/08/04 19:36:35 jtc Exp $";
static boolean flocal_xcmd_request
P((struct stransfer
*qtrans
,
struct sdaemon
*qdaemon
));
static boolean flocal_xcmd_await_reply
P((struct stransfer
*qtrans
,
const char *zdata
, size_t cdata
));
static boolean fremote_xcmd_reply
P((struct stransfer
*qtrans
,
struct sdaemon
*qdaemon
));
/* Handle a local work request. We just set up the request for
flocal_xcmd_init (qdaemon
, qcmd
)
struct stransfer
*qtrans
;
qtrans
= qtransalc (qcmd
);
qtrans
->psendfn
= flocal_xcmd_request
;
return fqueue_local (qdaemon
, qtrans
);
/* Send the execution request to the remote system. */
flocal_xcmd_request (qtrans
, qdaemon
)
struct stransfer
*qtrans
;
ulog (LOG_NORMAL
, "Requesting work: %s to %s", qtrans
->s
.zfrom
,
We put a dash in front of options. */
clen
= (strlen (qtrans
->s
.zfrom
) + strlen (qtrans
->s
.zto
)
+ strlen (qtrans
->s
.zuser
) + strlen (qtrans
->s
.zoptions
) + 7);
sprintf (zsend
, "X %s %s %s -%s", qtrans
->s
.zfrom
, qtrans
->s
.zto
,
qtrans
->s
.zuser
, qtrans
->s
.zoptions
);
fret
= (*qdaemon
->qproto
->pfsendcmd
) (qdaemon
, zsend
, qtrans
->ilocal
,
qtrans
->precfn
= flocal_xcmd_await_reply
;
return fqueue_receive (qdaemon
, qtrans
);
/* Get a reply to an execution request from the remote system. */
flocal_xcmd_await_reply (qtrans
, qdaemon
, zdata
, cdata
)
struct stransfer
*qtrans
;
|| (zdata
[1] != 'Y' && zdata
[1] != 'N'))
ulog (LOG_ERROR
, "Bad response to work request");
ulog (LOG_ERROR
, "%s: work request denied", qtrans
->s
.zfrom
);
(void) fmail_transfer (FALSE
, qtrans
->s
.zuser
, (const char *) NULL
,
qtrans
->s
.zfrom
, qdaemon
->qsys
->uuconf_zname
,
qtrans
->s
.zto
, (const char *) NULL
,
(void) fsysdep_did_work (qtrans
->s
.pseq
);
/* Handle a remote work request. This just queues up the requests for
fremote_xcmd_init (qdaemon
, qcmd
, iremote
)
const struct uuconf_system
*qsys
;
const struct uuconf_system
*qdestsys
;
struct uuconf_system sdestsys
;
struct stransfer
*qtrans
;
ulog (LOG_NORMAL
, "Work requested: %s to %s", qcmd
->zfrom
,
zexclam
= strchr (qcmd
->zto
, '!');
|| strncmp (qdaemon
->zlocalname
, qcmd
->zto
,
(size_t) (zexclam
- qcmd
->zto
)) == 0)
/* The files are supposed to be copied to the local system. */
zdestfile
= zsysdep_local_file (zconst
, qsys
->uuconf_zpubdir
);
fmkdirs
= strchr (qcmd
->zoptions
, 'f') != NULL
;
clen
= zexclam
- qcmd
->zto
;
zcopy
= zbufalc (clen
+ 1);
memcpy (zcopy
, qcmd
->zto
, clen
);
iuuconf
= uuconf_system_info (qdaemon
->puuconf
, zcopy
, &sdestsys
);
if (iuuconf
== UUCONF_NOT_FOUND
)
if (! funknown_system (qdaemon
->puuconf
, zcopy
, &sdestsys
))
ulog (LOG_ERROR
, "%s: System not found", zcopy
);
qtrans
= qtransalc (qcmd
);
qtrans
->psendfn
= fremote_xcmd_reply
;
qtrans
->pinfo
= (pointer
) "XN";
qtrans
->iremote
= iremote
;
return fqueue_remote (qdaemon
, qtrans
);
else if (iuuconf
!= UUCONF_SUCCESS
)
ulog_uuconf (LOG_ERROR
, qdaemon
->puuconf
, iuuconf
);
zdestfile
= zbufcpy (zexclam
+ 1);
zuser
= zbufalc (strlen (qdestsys
->uuconf_zname
)
+ strlen (qcmd
->zuser
) + sizeof "!");
sprintf (zuser
, "%s!%s", qdestsys
->uuconf_zname
, qcmd
->zuser
);
if (strchr (qcmd
->zoptions
, 'd') != NULL
)
if (strchr (qcmd
->zoptions
, 'm') != NULL
)
/* At this point we prepare to confirm the remote request. We could
actually fork here and let the child spool up the requests. */
qtrans
= qtransalc (qcmd
);
qtrans
->psendfn
= fremote_xcmd_reply
;
qtrans
->pinfo
= (pointer
) "XY";
qtrans
->iremote
= iremote
;
if (! fqueue_remote (qdaemon
, qtrans
))
/* Now we have to process each source file. The source
specification may or may use wildcards. */
zfrom
= zsysdep_local_file (qcmd
->zfrom
, qsys
->uuconf_zpubdir
);
if (! fsysdep_wildcard_start (zfrom
))
while ((zfile
= zsysdep_wildcard (zfrom
)) != NULL
)
char abtname
[CFILE_NAME_LEN
];
if (! fsysdep_file_exists (zfile
))
ulog (LOG_ERROR
, "%s: no such file", zfile
);
/* Make sure the remote system is permitted to read the
if (! fin_directory_list (zfile
, qsys
->uuconf_pzremote_send
,
qsys
->uuconf_zpubdir
, TRUE
, TRUE
,
ulog (LOG_ERROR
, "%s: not permitted to send", zfile
);
/* We really should get the original grade here. */
zto
= zsysdep_data_file_name (qdestsys
, qdaemon
->zlocalname
,
BDEFAULT_UUCP_GRADE
, FALSE
,
zto
= zsysdep_add_base (zdestfile
, zfile
);
/* We only accept a local destination if the remote system
has the right to create files there. */
if (! fin_directory_list (zto
, qsys
->uuconf_pzremote_receive
,
qsys
->uuconf_zpubdir
, TRUE
, FALSE
,
ulog (LOG_ERROR
, "%s: not permitted to receive", zto
);
/* Copy the file either to the final destination or to the
if (! fcopy_file (zfile
, zto
, qdestsys
== NULL
, fmkdirs
))
/* If there is a destination system, queue it up. */
ssend
.zoptions
= aboptions
;
ssend
.imode
= ixsysdep_file_mode (zfile
);
zjobid
= zsysdep_spool_commands (qdestsys
, BDEFAULT_UUCP_GRADE
,
(void) fsysdep_wildcard_end ();
(void) uuconf_system_free (qdaemon
->puuconf
, &sdestsys
);
/* Reply to a remote work request. */
fremote_xcmd_reply (qtrans
, qdaemon
)
struct stransfer
*qtrans
;
fret
= (*qdaemon
->qproto
->pfsendcmd
) (qdaemon
,
(const char *) qtrans
->pinfo
,