summaryrefslogtreecommitdiff
path: root/gnu/libexec
diff options
context:
space:
mode:
authorjtc <jtc@NetBSD.org>1993-08-04 19:33:45 +0000
committerjtc <jtc@NetBSD.org>1993-08-04 19:33:45 +0000
commit084e4c267272780020086600732e87dda9bc9580 (patch)
treea05c4109479f86bb5203f8eece43d7ae635d2e2e /gnu/libexec
parent67dfce6728f61cb2682af6907c007d385a8e0695 (diff)
Upgrade to Taylor UUCP 1.04
Diffstat (limited to 'gnu/libexec')
-rw-r--r--gnu/libexec/uucp/libuuconf/calout.c93
-rw-r--r--gnu/libexec/uucp/libuuconf/chatc.c202
-rw-r--r--gnu/libexec/uucp/libuuconf/cmdarg.c185
-rw-r--r--gnu/libexec/uucp/libuuconf/cmdfil.c103
-rw-r--r--gnu/libexec/uucp/libuuconf/cmdlin.c142
-rw-r--r--gnu/libexec/uucp/libuuconf/debfil.c43
-rw-r--r--gnu/libexec/uucp/libuuconf/deblev.c43
-rw-r--r--gnu/libexec/uucp/libuuconf/diacod.c129
-rw-r--r--gnu/libexec/uucp/libuuconf/dial.c61
-rw-r--r--gnu/libexec/uucp/libuuconf/diasub.c63
-rw-r--r--gnu/libexec/uucp/libuuconf/dnams.c103
-rw-r--r--gnu/libexec/uucp/libuuconf/errno.c46
-rw-r--r--gnu/libexec/uucp/libuuconf/errstr.c241
-rw-r--r--gnu/libexec/uucp/libuuconf/filnam.c44
-rw-r--r--gnu/libexec/uucp/libuuconf/freblk.c63
-rw-r--r--gnu/libexec/uucp/libuuconf/fredia.c44
-rw-r--r--gnu/libexec/uucp/libuuconf/free.c68
-rw-r--r--gnu/libexec/uucp/libuuconf/freprt.c44
-rw-r--r--gnu/libexec/uucp/libuuconf/fresys.c44
-rw-r--r--gnu/libexec/uucp/libuuconf/grdcmp.c76
-rw-r--r--gnu/libexec/uucp/libuuconf/hdial.c187
-rw-r--r--gnu/libexec/uucp/libuuconf/hdnams.c109
-rw-r--r--gnu/libexec/uucp/libuuconf/hinit.c295
-rw-r--r--gnu/libexec/uucp/libuuconf/hlocnm.c84
-rw-r--r--gnu/libexec/uucp/libuuconf/hport.c368
-rw-r--r--gnu/libexec/uucp/libuuconf/hrmunk.c55
-rw-r--r--gnu/libexec/uucp/libuuconf/hsinfo.c625
-rw-r--r--gnu/libexec/uucp/libuuconf/hsnams.c142
-rw-r--r--gnu/libexec/uucp/libuuconf/hsys.c49
-rw-r--r--gnu/libexec/uucp/libuuconf/hunk.c142
-rw-r--r--gnu/libexec/uucp/libuuconf/iniglb.c177
-rw-r--r--gnu/libexec/uucp/libuuconf/init.c74
-rw-r--r--gnu/libexec/uucp/libuuconf/int.c59
-rw-r--r--gnu/libexec/uucp/libuuconf/lckdir.c43
-rw-r--r--gnu/libexec/uucp/libuuconf/lineno.c44
-rw-r--r--gnu/libexec/uucp/libuuconf/llocnm.c70
-rw-r--r--gnu/libexec/uucp/libuuconf/local.c70
-rw-r--r--gnu/libexec/uucp/libuuconf/locnm.c46
-rw-r--r--gnu/libexec/uucp/libuuconf/logfil.c43
-rw-r--r--gnu/libexec/uucp/libuuconf/maxuxq.c86
-rw-r--r--gnu/libexec/uucp/libuuconf/mrgblk.c50
-rw-r--r--gnu/libexec/uucp/libuuconf/paramc.c175
-rw-r--r--gnu/libexec/uucp/libuuconf/port.c77
-rw-r--r--gnu/libexec/uucp/libuuconf/prtsub.c54
-rw-r--r--gnu/libexec/uucp/libuuconf/pubdir.c43
-rw-r--r--gnu/libexec/uucp/libuuconf/rdlocs.c305
-rw-r--r--gnu/libexec/uucp/libuuconf/rdperm.c446
-rw-r--r--gnu/libexec/uucp/libuuconf/reliab.c123
-rw-r--r--gnu/libexec/uucp/libuuconf/remunk.c45
-rw-r--r--gnu/libexec/uucp/libuuconf/sinfo.c112
-rw-r--r--gnu/libexec/uucp/libuuconf/snams.c133
-rw-r--r--gnu/libexec/uucp/libuuconf/split.c106
-rw-r--r--gnu/libexec/uucp/libuuconf/spool.c43
-rw-r--r--gnu/libexec/uucp/libuuconf/stafil.c43
-rw-r--r--gnu/libexec/uucp/libuuconf/syshdr.h106
-rw-r--r--gnu/libexec/uucp/libuuconf/syssub.c458
-rw-r--r--gnu/libexec/uucp/libuuconf/tcalou.c201
-rw-r--r--gnu/libexec/uucp/libuuconf/tdial.c227
-rw-r--r--gnu/libexec/uucp/libuuconf/tdialc.c211
-rw-r--r--gnu/libexec/uucp/libuuconf/tdnams.c119
-rw-r--r--gnu/libexec/uucp/libuuconf/tgcmp.c42
-rw-r--r--gnu/libexec/uucp/libuuconf/thread.c70
-rw-r--r--gnu/libexec/uucp/libuuconf/time.c406
-rw-r--r--gnu/libexec/uucp/libuuconf/tinit.c370
-rw-r--r--gnu/libexec/uucp/libuuconf/tlocnm.c112
-rw-r--r--gnu/libexec/uucp/libuuconf/tport.c295
-rw-r--r--gnu/libexec/uucp/libuuconf/tportc.c465
-rw-r--r--gnu/libexec/uucp/libuuconf/tsinfo.c922
-rw-r--r--gnu/libexec/uucp/libuuconf/tsnams.c84
-rw-r--r--gnu/libexec/uucp/libuuconf/tsys.c49
-rw-r--r--gnu/libexec/uucp/libuuconf/tval.c71
-rw-r--r--gnu/libexec/uucp/libuuconf/ugtlin.c110
-rw-r--r--gnu/libexec/uucp/libuuconf/unk.c70
-rw-r--r--gnu/libexec/uucp/libuuconf/uucnfi.h368
-rw-r--r--gnu/libexec/uucp/libuuconf/val.c46
-rw-r--r--gnu/libexec/uucp/libuuconf/vinit.c112
-rw-r--r--gnu/libexec/uucp/libuuconf/vport.c251
-rw-r--r--gnu/libexec/uucp/libuuconf/vsinfo.c575
-rw-r--r--gnu/libexec/uucp/libuuconf/vsnams.c106
-rw-r--r--gnu/libexec/uucp/libuuconf/vsys.c49
-rw-r--r--gnu/libexec/uucp/libuucp/MANIFEST27
-rw-r--r--gnu/libexec/uucp/libuucp/Makefile13
-rw-r--r--gnu/libexec/uucp/libuucp/bsrch.c54
-rw-r--r--gnu/libexec/uucp/libuucp/buffer.c109
-rw-r--r--gnu/libexec/uucp/libuucp/bzero.c15
-rw-r--r--gnu/libexec/uucp/libuucp/crc.c112
-rw-r--r--gnu/libexec/uucp/libuucp/debug.c165
-rw-r--r--gnu/libexec/uucp/libuucp/escape.c98
-rw-r--r--gnu/libexec/uucp/libuucp/getlin.c81
-rw-r--r--gnu/libexec/uucp/libuucp/getop1.c144
-rw-r--r--gnu/libexec/uucp/libuucp/getopt.c621
-rw-r--r--gnu/libexec/uucp/libuucp/memchr.c149
-rw-r--r--gnu/libexec/uucp/libuucp/memcmp.c19
-rw-r--r--gnu/libexec/uucp/libuucp/memcpy.c18
-rw-r--r--gnu/libexec/uucp/libuucp/parse.c207
-rw-r--r--gnu/libexec/uucp/libuucp/spool.c30
-rw-r--r--gnu/libexec/uucp/libuucp/status.c20
-rw-r--r--gnu/libexec/uucp/libuucp/strcas.c33
-rw-r--r--gnu/libexec/uucp/libuucp/strchr.c16
-rw-r--r--gnu/libexec/uucp/libuucp/strdup.c18
-rw-r--r--gnu/libexec/uucp/libuucp/strncs.c39
-rw-r--r--gnu/libexec/uucp/libuucp/strrch.c24
-rw-r--r--gnu/libexec/uucp/libuucp/strstr.c55
-rw-r--r--gnu/libexec/uucp/libuucp/strtol.c175
-rw-r--r--gnu/libexec/uucp/libuucp/xfree.c15
-rw-r--r--gnu/libexec/uucp/libuucp/xmall.c18
-rw-r--r--gnu/libexec/uucp/libuucp/xreall.c23
-rw-r--r--gnu/libexec/uucp/sample/call20
-rw-r--r--gnu/libexec/uucp/sample/config88
-rw-r--r--gnu/libexec/uucp/sample/dial35
-rw-r--r--gnu/libexec/uucp/sample/dialcode19
-rw-r--r--gnu/libexec/uucp/sample/passwd18
-rw-r--r--gnu/libexec/uucp/sample/port41
-rw-r--r--gnu/libexec/uucp/sample/sys144
-rw-r--r--gnu/libexec/uucp/sample/sys251
-rw-r--r--gnu/libexec/uucp/uuchk/Makefile15
-rw-r--r--gnu/libexec/uucp/uuchk/uuchk.c856
-rw-r--r--gnu/libexec/uucp/uucico/Makefile19
-rw-r--r--gnu/libexec/uucp/uucico/prote.c387
-rw-r--r--gnu/libexec/uucp/uucico/protf.c842
-rw-r--r--gnu/libexec/uucp/uucico/protg.c1933
-rw-r--r--gnu/libexec/uucp/uucico/proti.c1563
-rw-r--r--gnu/libexec/uucp/uucico/protj.c671
-rw-r--r--gnu/libexec/uucp/uucico/prott.c330
-rw-r--r--gnu/libexec/uucp/uucico/protz.c2626
-rw-r--r--gnu/libexec/uucp/uucico/rec.c1162
-rw-r--r--gnu/libexec/uucp/uucico/send.c1273
-rw-r--r--gnu/libexec/uucp/uucico/time.c130
-rw-r--r--gnu/libexec/uucp/uucico/trans.c1439
-rw-r--r--gnu/libexec/uucp/uucico/uucico.8225
-rw-r--r--gnu/libexec/uucp/uucico/uucico.c2618
-rw-r--r--gnu/libexec/uucp/uucico/xcmd.c396
-rw-r--r--gnu/libexec/uucp/uuconv/Makefile16
-rw-r--r--gnu/libexec/uucp/uuconv/uuconv.c2012
-rw-r--r--gnu/libexec/uucp/uucp/Makefile15
-rw-r--r--gnu/libexec/uucp/uucp/uucp.1175
-rw-r--r--gnu/libexec/uucp/uucp/uucp.c1181
-rw-r--r--gnu/libexec/uucp/uulog/Makefile15
-rw-r--r--gnu/libexec/uucp/uulog/uulog.c444
-rw-r--r--gnu/libexec/uucp/uuname/Makefile17
-rw-r--r--gnu/libexec/uucp/uuname/uuname.c192
-rw-r--r--gnu/libexec/uucp/uupick/Makefile15
-rw-r--r--gnu/libexec/uucp/uupick/uupick.c323
-rw-r--r--gnu/libexec/uucp/uusched/Makefile14
-rw-r--r--gnu/libexec/uucp/uusched/uusched.in13
-rw-r--r--gnu/libexec/uucp/uustat/Makefile16
-rw-r--r--gnu/libexec/uucp/uustat/uustat.1380
-rw-r--r--gnu/libexec/uucp/uustat/uustat.c2241
-rw-r--r--gnu/libexec/uucp/uuto/Makefile13
-rw-r--r--gnu/libexec/uucp/uuto/uuto.in16
-rw-r--r--gnu/libexec/uucp/uux/Makefile15
-rw-r--r--gnu/libexec/uucp/uux/uux.1234
-rw-r--r--gnu/libexec/uucp/uux/uux.c1502
-rw-r--r--gnu/libexec/uucp/uuxqt/Makefile17
-rw-r--r--gnu/libexec/uucp/uuxqt/uuxqt.892
-rw-r--r--gnu/libexec/uucp/uuxqt/uuxqt.c1549
156 files changed, 41861 insertions, 0 deletions
diff --git a/gnu/libexec/uucp/libuuconf/calout.c b/gnu/libexec/uucp/libuuconf/calout.c
new file mode 100644
index 00000000000..957833ebc31
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/calout.c
@@ -0,0 +1,93 @@
+/* calout.c
+ Find callout login name and password for a system.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_calout_rcsid[] = "$Id: calout.c,v 1.1 1993/08/04 19:33:45 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Find callout login name and password for a system. */
+
+/*ARGSUSED*/
+int
+uuconf_callout (pglobal, qsys, pzlog, pzpass)
+ pointer pglobal;
+ const struct uuconf_system *qsys;
+ char **pzlog;
+ char **pzpass;
+{
+#if HAVE_TAYLOR_CONFIG
+
+ return uuconf_taylor_callout (pglobal, qsys, pzlog, pzpass);
+
+#else /* ! HAVE_TAYLOR_CONFIG */
+
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pzlog = NULL;
+ *pzpass = NULL;
+
+ if (qsys->uuconf_zcall_login == NULL
+ && qsys->uuconf_zcall_password == NULL)
+ return UUCONF_NOT_FOUND;
+
+ if ((qsys->uuconf_zcall_login != NULL
+ && strcmp (qsys->uuconf_zcall_login, "*") == 0)
+ || (qsys->uuconf_zcall_password != NULL
+ && strcmp (qsys->uuconf_zcall_password, "*") == 0))
+ return UUCONF_NOT_FOUND;
+
+ if (qsys->uuconf_zcall_login != NULL)
+ {
+ *pzlog = strdup (qsys->uuconf_zcall_login);
+ if (*pzlog == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ }
+
+ if (qsys->uuconf_zcall_password != NULL)
+ {
+ *pzpass = strdup (qsys->uuconf_zcall_password);
+ if (*pzpass == NULL)
+ {
+ qglobal->ierrno = errno;
+ if (*pzlog != NULL)
+ {
+ free ((pointer) *pzlog);
+ *pzlog = NULL;
+ }
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ }
+
+ return UUCONF_SUCCESS;
+
+#endif /* ! HAVE_TAYLOR_CONFIG */
+}
diff --git a/gnu/libexec/uucp/libuuconf/chatc.c b/gnu/libexec/uucp/libuuconf/chatc.c
new file mode 100644
index 00000000000..f29481b59a9
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/chatc.c
@@ -0,0 +1,202 @@
+/* chatc.c
+ Subroutines to handle chat script commands.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_chatc_rcsid[] = "$Id: chatc.c,v 1.1 1993/08/04 19:33:48 jtc Exp $";
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+static int icchat P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int icchat_fail P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int icunknown P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+
+/* The chat script commands. */
+
+static const struct cmdtab_offset asChat_cmds[] =
+{
+ { "chat", UUCONF_CMDTABTYPE_FN,
+ offsetof (struct uuconf_chat, uuconf_pzchat), icchat },
+ { "chat-program", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_chat, uuconf_pzprogram), NULL },
+ { "chat-timeout", UUCONF_CMDTABTYPE_INT,
+ offsetof (struct uuconf_chat, uuconf_ctimeout), NULL },
+ { "chat-fail", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct uuconf_chat, uuconf_pzfail), icchat_fail },
+ { "chat-seven-bit", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_chat, uuconf_fstrip), NULL },
+ { NULL, 0, 0, NULL }
+};
+
+#define CCHAT_CMDS (sizeof asChat_cmds / sizeof asChat_cmds[0])
+
+/* Handle a chat script command. The chat script commands are entered
+ as UUCONF_CMDTABTYPE_PREFIX, and the commands are routed to this
+ function. We copy the command table onto the stack and repoint it
+ at qchat in order to make the function reentrant. The return value
+ can include UUCONF_CMDTABRET_KEEP, but should not include
+ UUCONF_CMDTABRET_EXIT. */
+
+int
+_uuconf_ichat_cmd (qglobal, argc, argv, qchat, pblock)
+ struct sglobal *qglobal;
+ int argc;
+ char **argv;
+ struct uuconf_chat *qchat;
+ pointer pblock;
+{
+ char *zchat;
+ struct uuconf_cmdtab as[CCHAT_CMDS];
+ int iret;
+
+ /* This is only invoked when argv[0] will contain the string "chat";
+ the specific chat script command comes after that point. */
+ for (zchat = argv[0]; *zchat != '\0'; zchat++)
+ if ((*zchat == 'c' || *zchat == 'C')
+ && strncasecmp (zchat, "chat", sizeof "chat" - 1) == 0)
+ break;
+ if (*zchat == '\0')
+ return UUCONF_SYNTAX_ERROR;
+ argv[0] = zchat;
+
+ _uuconf_ucmdtab_base (asChat_cmds, CCHAT_CMDS, (char *) qchat, as);
+
+ iret = uuconf_cmd_args ((pointer) qglobal, argc, argv, as, pblock,
+ icunknown, 0, pblock);
+ return iret &~ UUCONF_CMDTABRET_EXIT;
+}
+
+/* Handle the "chat" command. This breaks up substrings in expect
+ strings, and sticks the arguments into a NULL terminated array. */
+
+static int
+icchat (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char ***ppz = (char ***) pvar;
+ pointer pblock = pinfo;
+ int i;
+
+ *ppz = NULL;
+
+ for (i = 1; i < argc; i += 2)
+ {
+ char *z, *zdash;
+ int iret;
+
+ /* Break the expect string into substrings. */
+ z = argv[i];
+ zdash = strchr (z, '-');
+ while (zdash != NULL)
+ {
+ *zdash = '\0';
+ iret = _uuconf_iadd_string (qglobal, z, TRUE, FALSE, ppz,
+ pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ *zdash = '-';
+ z = zdash;
+ zdash = strchr (z + 1, '-');
+ }
+
+ iret = _uuconf_iadd_string (qglobal, z, FALSE, FALSE, ppz, pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+
+ /* Add the send string without breaking it up. If it starts
+ with a dash we must replace it with an escape sequence, to
+ prevent it from being interpreted as a subsend. */
+
+ if (i + 1 < argc)
+ {
+ if (argv[i + 1][0] != '-')
+ iret = _uuconf_iadd_string (qglobal, argv[i + 1], FALSE,
+ FALSE, ppz, pblock);
+ else
+ {
+ size_t clen;
+
+ clen = strlen (argv[i + 1]);
+ z = uuconf_malloc (pblock, clen + 2);
+ if (z == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ z[0] = '\\';
+ memcpy ((pointer) (z + 1), (pointer) argv[i + 1], clen + 1);
+ iret = _uuconf_iadd_string (qglobal, z, FALSE, FALSE, ppz,
+ pblock);
+ }
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ }
+
+ return UUCONF_CMDTABRET_KEEP;
+}
+
+/* Add a new chat failure string. */
+
+/*ARGSUSED*/
+static int
+icchat_fail (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char ***ppz = (char ***) pvar;
+ pointer pblock = pinfo;
+
+ return _uuconf_iadd_string (qglobal, argv[1], TRUE, FALSE, ppz, pblock);
+}
+
+/* Return a syntax error for an unknown command. */
+
+/*ARGSUSED*/
+static int
+icunknown (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ return UUCONF_SYNTAX_ERROR;
+}
diff --git a/gnu/libexec/uucp/libuuconf/cmdarg.c b/gnu/libexec/uucp/libuuconf/cmdarg.c
new file mode 100644
index 00000000000..2020ea91a9f
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/cmdarg.c
@@ -0,0 +1,185 @@
+/* cmdarg.c
+ Look up a command with arguments in a command table.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_cmdarg_rcsid[] = "$Id: cmdarg.c,v 1.1 1993/08/04 19:33:50 jtc Exp $";
+#endif
+
+#include <ctype.h>
+
+#undef strcmp
+#if HAVE_STRCASECMP
+#undef strcasecmp
+#endif
+extern int strcmp (), strcasecmp ();
+
+/* Look up a command with arguments in a table and execute it. */
+
+int
+uuconf_cmd_args (pglobal, cargs, pzargs, qtab, pinfo, pfiunknown, iflags,
+ pblock)
+ pointer pglobal;
+ int cargs;
+ char **pzargs;
+ const struct uuconf_cmdtab *qtab;
+ pointer pinfo;
+ int (*pfiunknown) P((pointer, int, char **, pointer, pointer));
+ int iflags;
+ pointer pblock;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int bfirstu, bfirstl;
+ int (*pficmp) P((const char *, const char *));
+ register const struct uuconf_cmdtab *q;
+ int itype;
+ int callowed;
+
+ bfirstu = bfirstl = pzargs[0][0];
+ if ((iflags & UUCONF_CMDTABFLAG_CASE) != 0)
+ pficmp = strcmp;
+ else
+ {
+ if (islower (bfirstu))
+ bfirstu = toupper (bfirstu);
+ if (isupper (bfirstl))
+ bfirstl = tolower (bfirstl);
+ pficmp = strcasecmp;
+ }
+
+ itype = 0;
+
+ for (q = qtab; q->uuconf_zcmd != NULL; q++)
+ {
+ int bfirst;
+
+ bfirst = q->uuconf_zcmd[0];
+ if (bfirst != bfirstu && bfirst != bfirstl)
+ continue;
+
+ itype = UUCONF_TTYPE_CMDTABTYPE (q->uuconf_itype);
+ if (itype != UUCONF_CMDTABTYPE_PREFIX)
+ {
+ if ((*pficmp) (q->uuconf_zcmd, pzargs[0]) == 0)
+ break;
+ }
+ else
+ {
+ size_t clen;
+
+ clen = strlen (q->uuconf_zcmd);
+ if ((iflags & UUCONF_CMDTABFLAG_CASE) != 0)
+ {
+ if (strncmp (q->uuconf_zcmd, pzargs[0], clen) == 0)
+ break;
+ }
+ else
+ {
+ if (strncasecmp (q->uuconf_zcmd, pzargs[0], clen) == 0)
+ break;
+ }
+ }
+ }
+
+ if (q->uuconf_zcmd == NULL)
+ {
+ if (pfiunknown == NULL)
+ return UUCONF_CMDTABRET_CONTINUE;
+ return (*pfiunknown) (pglobal, cargs, pzargs, (pointer) NULL, pinfo);
+ }
+
+ callowed = UUCONF_CARGS_CMDTABTYPE (q->uuconf_itype);
+ if (callowed != 0 && callowed != cargs)
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ switch (itype)
+ {
+ case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_STRING):
+ if (cargs == 1)
+ *(char **) q->uuconf_pvar = (char *) "";
+ else if (cargs == 2)
+ *(char **) q->uuconf_pvar = pzargs[1];
+ else
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ return UUCONF_CMDTABRET_KEEP;
+
+ case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_INT):
+ return _uuconf_iint (qglobal, pzargs[1], q->uuconf_pvar, TRUE);
+
+ case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_LONG):
+ return _uuconf_iint (qglobal, pzargs[1], q->uuconf_pvar, FALSE);
+
+ case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_BOOLEAN):
+ return _uuconf_iboolean (qglobal, pzargs[1], (int *) q->uuconf_pvar);
+
+ case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_FULLSTRING):
+ if (cargs == 1)
+ {
+ char ***ppz = (char ***) q->uuconf_pvar;
+ int iret;
+
+ *ppz = NULL;
+ iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
+ ppz, pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret | UUCONF_CMDTABRET_EXIT;
+
+ return UUCONF_CMDTABRET_CONTINUE;
+ }
+ else
+ {
+ char ***ppz = (char ***) q->uuconf_pvar;
+ int i;
+
+ *ppz = NULL;
+ for (i = 1; i < cargs; i++)
+ {
+ int iret;
+
+ iret = _uuconf_iadd_string (qglobal, pzargs[i], FALSE, FALSE,
+ ppz, pblock);
+ if (iret != UUCONF_SUCCESS)
+ {
+ *ppz = NULL;
+ return iret | UUCONF_CMDTABRET_EXIT;
+ }
+ }
+
+ return UUCONF_CMDTABRET_KEEP;
+ }
+
+ case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_FN):
+ case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_PREFIX):
+ return (*q->uuconf_pifn) (pglobal, cargs, pzargs, q->uuconf_pvar,
+ pinfo);
+
+ default:
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+ }
+
+ /*NOTREACHED*/
+}
diff --git a/gnu/libexec/uucp/libuuconf/cmdfil.c b/gnu/libexec/uucp/libuuconf/cmdfil.c
new file mode 100644
index 00000000000..333a4bf3764
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/cmdfil.c
@@ -0,0 +1,103 @@
+/* cmdfil.c
+ Read and parse commands from a file.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_cmdfil_rcsid[] = "$Id: cmdfil.c,v 1.1 1993/08/04 19:33:51 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Read and parse commands from a file, updating uuconf_lineno as
+ appropriate. */
+
+int
+uuconf_cmd_file (pglobal, e, qtab, pinfo, pfiunknown, iflags, pblock)
+ pointer pglobal;
+ FILE *e;
+ const struct uuconf_cmdtab *qtab;
+ pointer pinfo;
+ int (*pfiunknown) P((pointer, int, char **, pointer, pointer));
+ int iflags;
+ pointer pblock;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ boolean fcont;
+ char *zline;
+ size_t cline;
+ int iret;
+
+ fcont = (iflags & UUCONF_CMDTABFLAG_BACKSLASH) != 0;
+
+ zline = NULL;
+ cline = 0;
+
+ iret = UUCONF_SUCCESS;
+
+ qglobal->ilineno = 0;
+
+ while ((fcont
+ ? _uuconf_getline (qglobal, &zline, &cline, e)
+ : getline (&zline, &cline, e)) > 0)
+ {
+ ++qglobal->ilineno;
+
+ iret = uuconf_cmd_line (pglobal, zline, qtab, pinfo, pfiunknown,
+ iflags, pblock);
+
+ if ((iret & UUCONF_CMDTABRET_KEEP) != 0)
+ {
+ iret &=~ UUCONF_CMDTABRET_KEEP;
+
+ if (pblock != NULL)
+ {
+ if (uuconf_add_block (pblock, zline) != 0)
+ {
+ qglobal->ierrno = errno;
+ iret = (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_ERROR_LINENO);
+ break;
+ }
+ }
+
+ zline = NULL;
+ cline = 0;
+ }
+
+ if ((iret & UUCONF_CMDTABRET_EXIT) != 0)
+ {
+ iret &=~ UUCONF_CMDTABRET_EXIT;
+ if (iret != UUCONF_SUCCESS)
+ iret |= UUCONF_ERROR_LINENO;
+ break;
+ }
+
+ iret = UUCONF_SUCCESS;
+ }
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/cmdlin.c b/gnu/libexec/uucp/libuuconf/cmdlin.c
new file mode 100644
index 00000000000..63e95646731
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/cmdlin.c
@@ -0,0 +1,142 @@
+/* cmdlin.c
+ Parse a command line.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_cmdlin_rcsid[] = "$Id: cmdlin.c,v 1.1 1993/08/04 19:33:52 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+/* Parse a command line into fields and process it via a command
+ table. The command table functions may keep the memory allocated
+ for the line, but they may not keep the memory allocated for the
+ argv list. This function strips # comments. */
+
+#define CSTACK (16)
+
+int
+uuconf_cmd_line (pglobal, zline, qtab, pinfo, pfiunknown, iflags, pblock)
+ pointer pglobal;
+ char *zline;
+ const struct uuconf_cmdtab *qtab;
+ pointer pinfo;
+ int (*pfiunknown) P((pointer, int, char **, pointer, pointer));
+ int iflags;
+ pointer pblock;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char *z;
+ int cargs;
+ char *azargs[CSTACK];
+ char **pzargs;
+ int iret;
+
+ /* Any # not preceeded by a backslash starts a comment. */
+ z = zline;
+ while ((z = strchr (z, '#')) != NULL)
+ {
+ if (z == zline || *(z - 1) != '\\')
+ {
+ *z = '\0';
+ break;
+ }
+ /* Remove the backslash. */
+ while ((*(z - 1) = *z) != '\0')
+ ++z;
+ }
+
+ /* Parse the first CSTACK arguments by hand to avoid malloc. */
+
+ z = zline;
+ cargs = 0;
+ pzargs = azargs;
+ while (TRUE)
+ {
+ while (*z != '\0' && isspace (BUCHAR (*z)))
+ ++z;
+
+ if (*z == '\0')
+ break;
+
+ if (cargs >= CSTACK)
+ {
+ char **pzsplit;
+ size_t csplit;
+ int cmore;
+
+ pzsplit = NULL;
+ csplit = 0;
+ cmore = _uuconf_istrsplit (z, '\0', &pzsplit, &csplit);
+ if (cmore < 0)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ pzargs = (char **) malloc ((cmore + CSTACK) * sizeof (char *));
+ if (pzargs == NULL)
+ {
+ qglobal->ierrno = errno;
+ free ((pointer) pzsplit);
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ memcpy ((pointer) pzargs, (pointer) azargs,
+ CSTACK * sizeof (char *));
+ memcpy ((pointer) (pzargs + CSTACK), (pointer) pzsplit,
+ cmore * sizeof (char *));
+ cargs = cmore + CSTACK;
+
+ free ((pointer) pzsplit);
+
+ break;
+ }
+
+ azargs[cargs] = z;
+ ++cargs;
+
+ while (*z != '\0' && ! isspace (BUCHAR (*z)))
+ z++;
+
+ if (*z == '\0')
+ break;
+
+ *z++ = '\0';
+ }
+
+ if (cargs <= 0)
+ return UUCONF_CMDTABRET_CONTINUE;
+
+ iret = uuconf_cmd_args (pglobal, cargs, pzargs, qtab, pinfo, pfiunknown,
+ iflags, pblock);
+
+ if (pzargs != azargs)
+ free ((pointer) pzargs);
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/debfil.c b/gnu/libexec/uucp/libuuconf/debfil.c
new file mode 100644
index 00000000000..3be5381e5df
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/debfil.c
@@ -0,0 +1,43 @@
+/* debfil.c
+ Get the name of the UUCP debugging file.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_debfil_rcsid[] = "$Id: debfil.c,v 1.1 1993/08/04 19:33:53 jtc Exp $";
+#endif
+
+/* Get the name of the UUCP debugging file. */
+
+int
+uuconf_debugfile (pglobal, pzdebug)
+ pointer pglobal;
+ const char **pzdebug;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pzdebug = qglobal->qprocess->zdebugfile;
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/deblev.c b/gnu/libexec/uucp/libuuconf/deblev.c
new file mode 100644
index 00000000000..40cf763b100
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/deblev.c
@@ -0,0 +1,43 @@
+/* deblev.c
+ Get the UUCP debugging level.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_deblev_rcsid[] = "$Id: deblev.c,v 1.1 1993/08/04 19:33:54 jtc Exp $";
+#endif
+
+/* Get the UUCP debugging level. */
+
+int
+uuconf_debuglevel (pglobal, pzdebug)
+ pointer pglobal;
+ const char **pzdebug;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pzdebug = qglobal->qprocess->zdebug;
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/diacod.c b/gnu/libexec/uucp/libuuconf/diacod.c
new file mode 100644
index 00000000000..823239d953b
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/diacod.c
@@ -0,0 +1,129 @@
+/* diacod.c
+ Translate a dialcode.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_diacod_rcsid[] = "$Id: diacod.c,v 1.1 1993/08/04 19:33:55 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+static int idcode P((pointer pglobal, int argc, char **argv,
+ pointer pinfo, pointer pvar));
+
+/* Get the name of the UUCP log file. */
+
+int
+uuconf_dialcode (pglobal, zdial, pznum)
+ pointer pglobal;
+ const char *zdial;
+ char **pznum;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_cmdtab as[2];
+ char **pz;
+ int iret;
+
+ as[0].uuconf_zcmd = zdial;
+ as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 0;
+ as[0].uuconf_pvar = (pointer) pznum;
+ as[0].uuconf_pifn = idcode;
+
+ as[1].uuconf_zcmd = NULL;
+
+ *pznum = NULL;
+
+ iret = UUCONF_SUCCESS;
+
+ for (pz = qglobal->qprocess->pzdialcodefiles; *pz != NULL; pz++)
+ {
+ FILE *e;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ iret = uuconf_cmd_file (pglobal, e, as, (pointer) NULL,
+ (uuconf_cmdtabfn) NULL, 0, (pointer) NULL);
+ (void) fclose (e);
+
+ if (iret != UUCONF_SUCCESS || *pznum != NULL)
+ break;
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = *pz;
+ iret |= UUCONF_ERROR_FILENAME;
+ }
+ else if (*pznum == NULL)
+ iret = UUCONF_NOT_FOUND;
+
+ return iret;
+}
+
+/* This is called if the dialcode is found. It copies the number into
+ the heap and gets out of reading the file. */
+
+/*ARGSUSED*/
+static int
+idcode (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char **pznum = (char **) pvar;
+
+ if (argc == 1)
+ {
+ *pznum = malloc (1);
+ if (*pznum != NULL)
+ **pznum = '\0';
+ }
+ else if (argc == 2)
+ *pznum = strdup (argv[1]);
+ else
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ if (*pznum == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ return UUCONF_CMDTABRET_EXIT;
+}
diff --git a/gnu/libexec/uucp/libuuconf/dial.c b/gnu/libexec/uucp/libuuconf/dial.c
new file mode 100644
index 00000000000..efdef538c32
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/dial.c
@@ -0,0 +1,61 @@
+/* dial.c
+ Find a dialer.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_dial_rcsid[] = "$Id: dial.c,v 1.1 1993/08/04 19:33:57 jtc Exp $";
+#endif
+
+/* Find a dialer by name. */
+
+int
+uuconf_dialer_info (pglobal, zdialer, qdialer)
+ pointer pglobal;
+ const char *zdialer;
+ struct uuconf_dialer *qdialer;
+{
+#if HAVE_HDB_CONFIG
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+#endif
+ int iret;
+
+#if HAVE_TAYLOR_CONFIG
+ iret = uuconf_taylor_dialer_info (pglobal, zdialer, qdialer);
+ if (iret != UUCONF_NOT_FOUND)
+ return iret;
+#endif
+
+#if HAVE_HDB_CONFIG
+ if (qglobal->qprocess->fhdb)
+ {
+ iret = uuconf_hdb_dialer_info (pglobal, zdialer, qdialer);
+ if (iret != UUCONF_NOT_FOUND)
+ return iret;
+ }
+#endif
+
+ return UUCONF_NOT_FOUND;
+}
diff --git a/gnu/libexec/uucp/libuuconf/diasub.c b/gnu/libexec/uucp/libuuconf/diasub.c
new file mode 100644
index 00000000000..7979d0ebd21
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/diasub.c
@@ -0,0 +1,63 @@
+/* diasub.c
+ Dialer information subroutines.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_diasub_rcsid[] = "$Id: diasub.c,v 1.1 1993/08/04 19:33:58 jtc Exp $";
+#endif
+
+/* Clear the information in a dialer. */
+
+#define INIT_CHAT(q) \
+ ((q)->uuconf_pzchat = NULL, \
+ (q)->uuconf_pzprogram = NULL, \
+ (q)->uuconf_ctimeout = 60, \
+ (q)->uuconf_pzfail = NULL, \
+ (q)->uuconf_fstrip = TRUE)
+
+void
+_uuconf_uclear_dialer (qdialer)
+ struct uuconf_dialer *qdialer;
+{
+ qdialer->uuconf_zname = NULL;
+ INIT_CHAT (&qdialer->uuconf_schat);
+ qdialer->uuconf_zdialtone = (char *) ",";
+ qdialer->uuconf_zpause = (char *) ",";
+ qdialer->uuconf_fcarrier = TRUE;
+ qdialer->uuconf_ccarrier_wait = 60;
+ qdialer->uuconf_fdtr_toggle = FALSE;
+ qdialer->uuconf_fdtr_toggle_wait = FALSE;
+ INIT_CHAT (&qdialer->uuconf_scomplete);
+ INIT_CHAT (&qdialer->uuconf_sabort);
+ qdialer->uuconf_qproto_params = NULL;
+ /* Note that we do not set RELIABLE_SPECIFIED; this just sets
+ defaults, so that ``seven-bit true'' does not imply ``reliable
+ false''. */
+ qdialer->uuconf_ireliable = (UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT
+ | UUCONF_RELIABLE_FULLDUPLEX);
+ qdialer->uuconf_palloc = NULL;
+}
diff --git a/gnu/libexec/uucp/libuuconf/dnams.c b/gnu/libexec/uucp/libuuconf/dnams.c
new file mode 100644
index 00000000000..6a10ada811a
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/dnams.c
@@ -0,0 +1,103 @@
+/* dnams.c
+ Get all known dialer names.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_dnams_rcsid[] = "$Id: dnams.c,v 1.1 1993/08/04 19:33:59 jtc Exp $";
+#endif
+
+/* Get all known dialer names. */
+
+int
+uuconf_dialer_names (pglobal, ppzdialers)
+ pointer pglobal;
+ char ***ppzdialers;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char **pztaylor;
+ char **pzhdb;
+ int iret;
+
+ *ppzdialers = NULL;
+ pztaylor = NULL;
+ pzhdb = NULL;
+
+#if HAVE_TAYLOR_CONFIG
+ iret = uuconf_taylor_dialer_names (pglobal, &pztaylor);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+#endif
+
+#if HAVE_HDB_CONFIG
+ if (qglobal->qprocess->fhdb)
+ {
+ iret = uuconf_hdb_dialer_names (pglobal, &pzhdb);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+#endif
+
+ if (pzhdb == NULL)
+ *ppzdialers = pztaylor;
+ else if (pztaylor == NULL)
+ *ppzdialers = pzhdb;
+ else
+ {
+ char **pz;
+
+ iret = UUCONF_SUCCESS;
+
+ for (pz = pztaylor; *pz != NULL; pz++)
+ {
+ iret = _uuconf_iadd_string (qglobal, *pz, FALSE, TRUE,
+ ppzdialers, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+
+ if (iret == UUCONF_SUCCESS)
+ {
+ for (pz = pzhdb; *pz != NULL; pz++)
+ {
+ iret = _uuconf_iadd_string (qglobal, *pz, FALSE, TRUE,
+ ppzdialers, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+ }
+
+ if (pztaylor != NULL)
+ free ((pointer) pztaylor);
+ if (pzhdb != NULL)
+ free ((pointer) pzhdb);
+ }
+
+ if (iret == UUCONF_SUCCESS && *ppzdialers == NULL)
+ iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
+ ppzdialers, (pointer) NULL);
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/errno.c b/gnu/libexec/uucp/libuuconf/errno.c
new file mode 100644
index 00000000000..d1def82ca3c
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/errno.c
@@ -0,0 +1,46 @@
+/* errno.c
+ Return the saved errno value.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_errno_rcsid[] = "$Id: errno.c,v 1.1 1993/08/04 19:34:01 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Return the saved errno value. */
+
+int
+uuconf_error_errno (pglobal)
+ pointer pglobal;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ if (qglobal == NULL)
+ return errno;
+ else
+ return qglobal->ierrno;
+}
diff --git a/gnu/libexec/uucp/libuuconf/errstr.c b/gnu/libexec/uucp/libuuconf/errstr.c
new file mode 100644
index 00000000000..2bed403f258
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/errstr.c
@@ -0,0 +1,241 @@
+/* errstr.c
+ Return a string for a uuconf error.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_errstr_rcsid[] = "$Id: errstr.c,v 1.1 1993/08/04 19:34:02 jtc Exp $";
+#endif
+
+static char *zeprint_num P((char *zbuf, size_t cbuf, int ival));
+
+/* Return an error string for a uuconf error. This does not return a
+ uuconf error code, but instead returns the total buffer length. */
+
+int
+uuconf_error_string (pglobal, ierr, zbuf, cbuf)
+ pointer pglobal;
+ int ierr;
+ char *zbuf;
+ size_t cbuf;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ const char *zfile;
+ size_t cfile;
+ const char *zlineno;
+ char ablineno[100];
+ size_t clineno;
+ const char *zmsg;
+ char abmsg[100];
+ size_t cmsg;
+ const char *zerrno;
+ size_t cerrno;
+ size_t cret;
+ size_t ccopy;
+
+ /* The format of the message is
+
+ filename:lineno: message: errno
+
+ If there is no filename, the trailing colon is not output. If
+ there is no linenumber, the trailing colon is not output. If
+ there is no filename, the linenumber is not output, and neither
+ is the space before message. If there is no errno, the
+ preceeding colon and space are not output. */
+
+ /* Get the filename to put in the error message, if any. */
+ if ((ierr & UUCONF_ERROR_FILENAME) == 0
+ || qglobal == NULL
+ || qglobal->zfilename == NULL)
+ {
+ zfile = "";
+ cfile = 0;
+ }
+ else
+ {
+ zfile = qglobal->zfilename;
+ cfile = strlen (zfile) + 1;
+ }
+
+ /* Get the line number to put in the error message, if any. */
+ if (cfile == 0
+ || (ierr & UUCONF_ERROR_LINENO) == 0
+ || qglobal == NULL
+ || qglobal->ilineno <= 0)
+ {
+ zlineno = "";
+ clineno = 0;
+ }
+ else
+ {
+ zlineno = zeprint_num (ablineno, sizeof ablineno, qglobal->ilineno);
+ clineno = strlen (zlineno) + 1;
+ }
+
+ /* Get the main message. */
+ switch (UUCONF_ERROR_VALUE (ierr))
+ {
+ case UUCONF_SUCCESS:
+ zmsg = "no error";
+ break;
+ case UUCONF_NOT_FOUND:
+ zmsg = "not found";
+ break;
+ case UUCONF_FOPEN_FAILED:
+ zmsg = "fopen";
+ break;
+ case UUCONF_FSEEK_FAILED:
+ zmsg = "fseek";
+ break;
+ case UUCONF_MALLOC_FAILED:
+ zmsg = "malloc";
+ break;
+ case UUCONF_SYNTAX_ERROR:
+ zmsg = "syntax error";
+ break;
+ default:
+ zmsg = zeprint_num (abmsg, sizeof abmsg, UUCONF_ERROR_VALUE (ierr));
+ zmsg -= sizeof "error " - 1;
+ memcpy ((pointer) zmsg, (pointer) "error ", sizeof "error " - 1);
+ break;
+ }
+
+ cmsg = strlen (zmsg);
+ if (cfile > 0)
+ ++cmsg;
+
+ /* Get the errno string. Note that strerror is not necessarily
+ reentrant. */
+ if ((ierr & UUCONF_ERROR_ERRNO) == 0
+ || qglobal == NULL)
+ {
+ zerrno = "";
+ cerrno = 0;
+ }
+ else
+ {
+ zerrno = strerror (qglobal->ierrno);
+ cerrno = strlen (zerrno) + 2;
+ }
+
+ cret = cfile + clineno + cmsg + cerrno + 1;
+
+ if (cbuf == 0)
+ return cret;
+
+ /* Leave room for the null byte. */
+ --cbuf;
+
+ if (cfile > 0)
+ {
+ ccopy = cfile - 1;
+ if (ccopy > cbuf)
+ ccopy = cbuf;
+ memcpy ((pointer) zbuf, (pointer) zfile, ccopy);
+ zbuf += ccopy;
+ cbuf -= ccopy;
+ if (cbuf > 0)
+ {
+ *zbuf++ = ':';
+ --cbuf;
+ }
+ }
+
+ if (clineno > 0)
+ {
+ ccopy = clineno - 1;
+ if (ccopy > cbuf)
+ ccopy = cbuf;
+ memcpy ((pointer) zbuf, (pointer) zlineno, ccopy);
+ zbuf += ccopy;
+ cbuf -= ccopy;
+ if (cbuf > 0)
+ {
+ *zbuf++ = ':';
+ --cbuf;
+ }
+ }
+
+ if (cbuf > 0 && cfile > 0)
+ {
+ *zbuf++ = ' ';
+ --cbuf;
+ --cmsg;
+ }
+ ccopy = cmsg;
+ if (ccopy > cbuf)
+ ccopy = cbuf;
+ memcpy ((pointer) zbuf, (pointer) zmsg, ccopy);
+ zbuf += ccopy;
+ cbuf -= ccopy;
+
+ if (cerrno > 0)
+ {
+ if (cbuf > 0)
+ {
+ *zbuf++ = ':';
+ --cbuf;
+ }
+ if (cbuf > 0)
+ {
+ *zbuf++ = ' ';
+ --cbuf;
+ }
+ ccopy = cerrno - 2;
+ if (ccopy > cbuf)
+ ccopy = cbuf;
+ memcpy ((pointer) zbuf, (pointer) zerrno, ccopy);
+ zbuf += ccopy;
+ cbuf -= ccopy;
+ }
+
+ *zbuf = '\0';
+
+ return cret;
+}
+
+/* Turn a number into a string. This should really call sprintf, but
+ since nothing else in the uuconf library calls any print routine,
+ it's more interesting to not call it here either. */
+
+static char *
+zeprint_num (ab, c, i)
+ char *ab;
+ size_t c;
+ register int i;
+{
+ register char *z;
+
+ z = ab + c;
+ *--z = '\0';
+ do
+ {
+ *--z = i % 10 + '0';
+ i /= 10;
+ }
+ while (i != 0);
+
+ return z;
+}
diff --git a/gnu/libexec/uucp/libuuconf/filnam.c b/gnu/libexec/uucp/libuuconf/filnam.c
new file mode 100644
index 00000000000..ab1b76a51d2
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/filnam.c
@@ -0,0 +1,44 @@
+/* filnam.c
+ Return the saved file name.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_filnam_rcsid[] = "$Id: filnam.c,v 1.1 1993/08/04 19:34:03 jtc Exp $";
+#endif
+
+/* Return the saved file name. */
+
+const char *
+uuconf_error_filename (pglobal)
+ pointer pglobal;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ if (qglobal == NULL)
+ return "";
+ else
+ return qglobal->zfilename;
+}
diff --git a/gnu/libexec/uucp/libuuconf/freblk.c b/gnu/libexec/uucp/libuuconf/freblk.c
new file mode 100644
index 00000000000..cb27d115c05
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/freblk.c
@@ -0,0 +1,63 @@
+/* freblk.c
+ Free up an entire memory block.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_freblk_rcsid[] = "$Id: freblk.c,v 1.1 1993/08/04 19:34:05 jtc Exp $";
+#endif
+
+#include "alloc.h"
+
+/* Free up an entire memory block. */
+
+#if UUCONF_ANSI_C
+void
+#endif
+uuconf_free_block (pblock)
+ pointer pblock;
+{
+ struct sblock *q = (struct sblock *) pblock;
+ struct sblock *qloop;
+
+ /* We have to free the added blocks first because the list may link
+ into blocks that are earlier on the list. */
+ for (qloop = q; qloop != NULL; qloop = qloop->qnext)
+ {
+ struct sadded *qadd;
+
+ for (qadd = qloop->qadded; qadd != NULL; qadd = qadd->qnext)
+ free (qadd->padded);
+ }
+
+ while (q != NULL)
+ {
+ struct sblock *qnext;
+
+ qnext = q->qnext;
+ free ((pointer) q);
+ q = qnext;
+ }
+}
diff --git a/gnu/libexec/uucp/libuuconf/fredia.c b/gnu/libexec/uucp/libuuconf/fredia.c
new file mode 100644
index 00000000000..60b00b7cf88
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/fredia.c
@@ -0,0 +1,44 @@
+/* fredia.c
+ Free dialer information.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_fredia_rcsid[] = "$Id: fredia.c,v 1.1 1993/08/04 19:34:08 jtc Exp $";
+#endif
+
+/* Free the memory allocated for a dialer. */
+
+#undef uuconf_dialer_free
+
+/*ARGSUSED*/
+int
+uuconf_dialer_free (pglobal, qdialer)
+ pointer pglobal;
+ struct uuconf_dialer *qdialer;
+{
+ uuconf_free_block (qdialer->uuconf_palloc);
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/free.c b/gnu/libexec/uucp/libuuconf/free.c
new file mode 100644
index 00000000000..91916f1d3ca
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/free.c
@@ -0,0 +1,68 @@
+/* free.c
+ Free a buffer from within a memory block.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_free_rcsid[] = "$Id: free.c,v 1.1 1993/08/04 19:34:10 jtc Exp $";
+#endif
+
+#include "alloc.h"
+
+/* Free memory allocated by uuconf_malloc. If the memory block is
+ NULL, this just calls free; this is convenient for a number of
+ routines. Otherwise, this will only do something if this was the
+ last buffer allocated for one of the memory blocks in the list; in
+ other cases, the memory is lost until the entire memory block is
+ freed. */
+
+#if UUCONF_ANSI_C
+void
+#endif
+uuconf_free (pblock, pbuf)
+ pointer pblock;
+ pointer pbuf;
+{
+ struct sblock *q = (struct sblock *) pblock;
+
+ if (pbuf == NULL)
+ return;
+
+ if (q == NULL)
+ {
+ free (pbuf);
+ return;
+ }
+
+ for (; q != NULL; q = q->qnext)
+ {
+ if (q->plast == pbuf)
+ {
+ q->ifree = (char *) pbuf - q->u.ab;
+ /* We could reset q->plast here, but it doesn't matter. */
+ return;
+ }
+ }
+}
diff --git a/gnu/libexec/uucp/libuuconf/freprt.c b/gnu/libexec/uucp/libuuconf/freprt.c
new file mode 100644
index 00000000000..2906b9dc836
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/freprt.c
@@ -0,0 +1,44 @@
+/* freprt.c
+ Free port information.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_freprt_rcsid[] = "$Id: freprt.c,v 1.1 1993/08/04 19:34:12 jtc Exp $";
+#endif
+
+/* Free the memory allocated for a port. */
+
+#undef uuconf_port_free
+
+/*ARGSUSED*/
+int
+uuconf_port_free (pglobal, qport)
+ pointer pglobal;
+ struct uuconf_port *qport;
+{
+ uuconf_free_block (qport->uuconf_palloc);
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/fresys.c b/gnu/libexec/uucp/libuuconf/fresys.c
new file mode 100644
index 00000000000..a73f4c1bc8c
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/fresys.c
@@ -0,0 +1,44 @@
+/* fresys.c
+ Free system information.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_fresys_rcsid[] = "$Id: fresys.c,v 1.1 1993/08/04 19:34:13 jtc Exp $";
+#endif
+
+/* Free the memory allocated for a system. */
+
+#undef uuconf_system_free
+
+/*ARGSUSED*/
+int
+uuconf_system_free (pglobal, qsys)
+ pointer pglobal;
+ struct uuconf_system *qsys;
+{
+ uuconf_free_block (qsys->uuconf_palloc);
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/grdcmp.c b/gnu/libexec/uucp/libuuconf/grdcmp.c
new file mode 100644
index 00000000000..8b02ff9963a
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/grdcmp.c
@@ -0,0 +1,76 @@
+/* grdcmp.c
+ Compare two grades.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_grdcmp_rcsid[] = "$Id: grdcmp.c,v 1.1 1993/08/04 19:34:14 jtc Exp $";
+#endif
+
+#include <ctype.h>
+
+/* Compare two grades, returning < 0 if b1 should be executed before
+ b2, == 0 if they are the same, or > 0 if b1 should be executed
+ after b2. This can not fail, and does not return a standard uuconf
+ error code.
+
+ This implementation assumes that the upper case letters are in
+ sequence, and that the lower case letters are in sequence. */
+
+int
+uuconf_grade_cmp (barg1, barg2)
+ int barg1;
+ int barg2;
+{
+ int b1, b2;
+
+ /* Make sure the arguments are unsigned. */
+ b1 = (int) BUCHAR (barg1);
+ b2 = (int) BUCHAR (barg2);
+
+ if (isdigit (b1))
+ {
+ if (isdigit (b2))
+ return b1 - b2;
+ else
+ return -1;
+ }
+ else if (isupper (b1))
+ {
+ if (isdigit (b2))
+ return 1;
+ else if (isupper (b2))
+ return b1 - b2;
+ else
+ return -1;
+ }
+ else
+ {
+ if (! islower (b2))
+ return 1;
+ else
+ return b1 - b2;
+ }
+}
diff --git a/gnu/libexec/uucp/libuuconf/hdial.c b/gnu/libexec/uucp/libuuconf/hdial.c
new file mode 100644
index 00000000000..666cc7f62ee
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hdial.c
@@ -0,0 +1,187 @@
+/* hdial.c
+ Find a dialer in the HDB configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hdial_rcsid[] = "$Id: hdial.c,v 1.1 1993/08/04 19:34:15 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+/* Find a dialer in the HDB configuration files by name. */
+
+int
+uuconf_hdb_dialer_info (pglobal, zname, qdialer)
+ pointer pglobal;
+ const char *zname;
+ struct uuconf_dialer *qdialer;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char **pz;
+ char *zline;
+ size_t cline;
+ char **pzsplit;
+ size_t csplit;
+ int iret;
+
+ zline = NULL;
+ cline = 0;
+ pzsplit = NULL;
+ csplit = 0;
+
+ iret = UUCONF_NOT_FOUND;
+
+ for (pz = qglobal->qprocess->pzhdb_dialers; *pz != NULL; pz++)
+ {
+ FILE *e;
+ int cchars;
+
+ qglobal->ilineno = 0;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ while ((cchars = _uuconf_getline (qglobal, &zline, &cline, e)) > 0)
+ {
+ int ctoks;
+ pointer pblock;
+
+ ++qglobal->ilineno;
+
+ --cchars;
+ if (zline[cchars] == '\n')
+ zline[cchars] = '\0';
+ if (isspace (BUCHAR (zline[0])) || zline[0] == '#')
+ continue;
+
+ ctoks = _uuconf_istrsplit (zline, '\0', &pzsplit, &csplit);
+ if (ctoks < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ if (ctoks < 1)
+ continue;
+
+ if (strcmp (zname, pzsplit[0]) != 0)
+ continue;
+
+ /* We found the dialer. */
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ if (uuconf_add_block (pblock, zline) != 0)
+ {
+ qglobal->ierrno = errno;
+ uuconf_free_block (pblock);
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ zline = NULL;
+
+ _uuconf_uclear_dialer (qdialer);
+ qdialer->uuconf_zname = pzsplit[0];
+ qdialer->uuconf_palloc = pblock;
+
+ if (ctoks > 1)
+ {
+ /* The second field is characters to send instead of "="
+ and "-" in phone numbers. */
+ if (strcmp (pzsplit[1], "\"\"") == 0)
+ {
+ char *zsubs;
+ char bnext;
+
+ zsubs = pzsplit[1];
+ bnext = *zsubs;
+ while (bnext != '\0')
+ {
+ if (bnext == '=')
+ qdialer->uuconf_zdialtone = zsubs + 1;
+ else if (bnext == '-')
+ qdialer->uuconf_zpause = zsubs + 1;
+ if (zsubs[1] == '\0')
+ break;
+ zsubs += 2;
+ bnext = *zsubs;
+ *zsubs = '\0';
+ }
+ }
+
+ /* Any remaining fields form a chat script. */
+ if (ctoks > 2)
+ {
+ pzsplit[1] = (char *) "chat";
+ iret = _uuconf_ichat_cmd (qglobal, ctoks - 1,
+ pzsplit + 1,
+ &qdialer->uuconf_schat,
+ pblock);
+ iret &=~ UUCONF_CMDTABRET_KEEP;
+ if (iret != UUCONF_SUCCESS)
+ {
+ uuconf_free_block (pblock);
+ break;
+ }
+ }
+ }
+
+ iret = UUCONF_SUCCESS;
+ break;
+ }
+
+ (void) fclose (e);
+
+ if (iret != UUCONF_NOT_FOUND)
+ break;
+ }
+
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+
+ if (iret != UUCONF_SUCCESS && iret != UUCONF_NOT_FOUND)
+ {
+ qglobal->zfilename = *pz;
+ iret |= UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ }
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/hdnams.c b/gnu/libexec/uucp/libuuconf/hdnams.c
new file mode 100644
index 00000000000..0806059214e
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hdnams.c
@@ -0,0 +1,109 @@
+/* hdnams.c
+ Get all known dialer names from the HDB configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hdnams_rcsid[] = "$Id: hdnams.c,v 1.1 1993/08/04 19:34:16 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+/* Get all the dialer names from the HDB Dialers file. */
+
+int
+uuconf_hdb_dialer_names (pglobal, ppzdialers)
+ pointer pglobal;
+ char ***ppzdialers;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+ char *zline;
+ size_t cline;
+ char **pz;
+
+ *ppzdialers = NULL;
+
+ iret = UUCONF_SUCCESS;
+
+ zline = NULL;
+ cline = 0;
+
+ for (pz = qglobal->qprocess->pzhdb_dialers; *pz != NULL; pz++)
+ {
+ FILE *e;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ qglobal->ilineno = 0;
+
+ while (_uuconf_getline (qglobal, &zline, &cline, e) > 0)
+ {
+ ++qglobal->ilineno;
+
+ /* Lines beginning with whitespace are treated as comments.
+ No dialer name can contain a '#', which is another
+ comment character, so eliminating the first '#' does no
+ harm and catches comments. */
+ zline[strcspn (zline, " \t#\n")] = '\0';
+ if (*zline == '\0')
+ continue;
+
+ iret = _uuconf_iadd_string (qglobal, zline, TRUE, TRUE,
+ ppzdialers, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ {
+ iret |= UUCONF_ERROR_LINENO;
+ break;
+ }
+ }
+
+ (void) fclose (e);
+ }
+
+ if (zline != NULL)
+ free ((pointer) zline);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = *pz;
+ return iret | UUCONF_ERROR_FILENAME;
+ }
+
+ if (*ppzdialers == NULL)
+ iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
+ ppzdialers, (pointer) NULL);
+
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/hinit.c b/gnu/libexec/uucp/libuuconf/hinit.c
new file mode 100644
index 00000000000..2b1c1cc6fa3
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hinit.c
@@ -0,0 +1,295 @@
+/* hinit.c
+ Initialize for reading HDB configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hinit_rcsid[] = "$Id: hinit.c,v 1.1 1993/08/04 19:34:17 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+/* Avoid replicating OLDCONFIGLIB several times if not necessary. */
+static const char abHoldconfiglib[] = OLDCONFIGLIB;
+
+/* Initialize the routines which read HDB configuration files. */
+
+int
+uuconf_hdb_init (ppglobal, zprogram)
+ pointer *ppglobal;
+ const char *zprogram;
+{
+ struct sglobal **pqglobal = (struct sglobal **) ppglobal;
+ int iret;
+ struct sglobal *qglobal;
+ pointer pblock;
+ char abdialcodes[sizeof OLDCONFIGLIB + sizeof HDB_DIALCODES - 1];
+ char *zsys;
+ FILE *e;
+
+ if (*pqglobal == NULL)
+ {
+ iret = _uuconf_iinit_global (pqglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ qglobal = *pqglobal;
+ pblock = qglobal->pblock;
+
+ if (zprogram == NULL
+ || strcmp (zprogram, "uucp") == 0)
+ zprogram = "uucico";
+
+ /* Add the Dialcodes file to the global list. */
+ memcpy ((pointer) abdialcodes, (pointer) abHoldconfiglib,
+ sizeof OLDCONFIGLIB - 1);
+ memcpy ((pointer) (abdialcodes + sizeof OLDCONFIGLIB - 1),
+ (pointer) HDB_DIALCODES, sizeof HDB_DIALCODES);
+ iret = _uuconf_iadd_string (qglobal, abdialcodes, TRUE, FALSE,
+ &qglobal->qprocess->pzdialcodefiles,
+ pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+
+ /* Read the Sysfiles file. We allocate the name on the heap rather
+ than the stack so that we can return it in
+ qerr->uuconf_zfilename. */
+
+ zsys = uuconf_malloc (pblock,
+ sizeof OLDCONFIGLIB + sizeof HDB_SYSFILES - 1);
+ if (zsys == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ memcpy ((pointer) zsys, (pointer) abHoldconfiglib, sizeof OLDCONFIGLIB - 1);
+ memcpy ((pointer) (zsys + sizeof OLDCONFIGLIB - 1), (pointer) HDB_SYSFILES,
+ sizeof HDB_SYSFILES);
+
+ iret = UUCONF_SUCCESS;
+
+ e = fopen (zsys, "r");
+ if (e == NULL)
+ uuconf_free (pblock, zsys);
+ else
+ {
+ char *zline;
+ size_t cline;
+ char **pzargs;
+ size_t cargs;
+ char **pzcolon;
+ size_t ccolon;
+ int cchars;
+
+ zline = NULL;
+ cline = 0;
+ pzargs = NULL;
+ cargs = 0;
+ pzcolon = NULL;
+ ccolon = 0;
+
+ qglobal->ilineno = 0;
+
+ while (iret == UUCONF_SUCCESS
+ && (cchars = _uuconf_getline (qglobal, &zline, &cline, e)) > 0)
+ {
+ int ctypes, cnames;
+ int i;
+
+ ++qglobal->ilineno;
+
+ --cchars;
+ if (zline[cchars] == '\n')
+ zline[cchars] = '\0';
+ if (isspace (BUCHAR (zline[0])) || zline[0] == '#')
+ continue;
+
+ ctypes = _uuconf_istrsplit (zline, '\0', &pzargs, &cargs);
+ if (ctypes < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ if (ctypes == 0)
+ continue;
+
+ if (strncmp (pzargs[0], "service=", sizeof "service=" - 1) != 0)
+ {
+ iret = UUCONF_SYNTAX_ERROR;
+ break;
+ }
+ pzargs[0] += sizeof "service=" - 1;
+
+ cnames = _uuconf_istrsplit (pzargs[0], ':', &pzcolon, &ccolon);
+ if (cnames < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ for (i = 0; i < cnames; i++)
+ if (strcmp (zprogram, pzcolon[i]) == 0)
+ break;
+
+ if (i >= cnames)
+ continue;
+
+ for (i = 1; i < ctypes && iret == UUCONF_SUCCESS; i++)
+ {
+ char ***ppz;
+ int cfiles, ifile;
+
+ if (strncmp (pzargs[i], "systems=", sizeof "systems=" - 1)
+ == 0)
+ {
+ ppz = &qglobal->qprocess->pzhdb_systems;
+ pzargs[i] += sizeof "systems=" - 1;
+ }
+ else if (strncmp (pzargs[i], "devices=", sizeof "devices=" - 1)
+ == 0)
+ {
+ ppz = &qglobal->qprocess->pzhdb_devices;
+ pzargs[i] += sizeof "devices=" - 1;
+ }
+ else if (strncmp (pzargs[i], "dialers=", sizeof "dialers=" - 1)
+ == 0)
+ {
+ ppz = &qglobal->qprocess->pzhdb_dialers;
+ pzargs[i] += sizeof "dialers=" - 1;
+ }
+ else
+ {
+ iret = UUCONF_SYNTAX_ERROR;
+ break;
+ }
+
+ cfiles = _uuconf_istrsplit (pzargs[i], ':', &pzcolon, &ccolon);
+ if (cfiles < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ for (ifile = 0;
+ ifile < cfiles && iret == UUCONF_SUCCESS;
+ ifile++)
+ {
+ /* Looking for a leading '/' is Unix dependent, and
+ should probably be changed. */
+ if (pzcolon[ifile][0] == '/')
+ iret = _uuconf_iadd_string (qglobal, pzcolon[ifile], TRUE,
+ FALSE, ppz, pblock);
+ else
+ {
+ char *zdir;
+ size_t clen;
+
+ clen = strlen (pzcolon[ifile]);
+ zdir = (char *) uuconf_malloc (pblock,
+ (sizeof OLDCONFIGLIB
+ + sizeof HDB_SEPARATOR
+ + clen
+ - 1));
+ if (zdir == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ memcpy ((pointer) zdir, (pointer) abHoldconfiglib,
+ sizeof OLDCONFIGLIB - 1);
+ memcpy ((pointer) (zdir + sizeof OLDCONFIGLIB - 1),
+ HDB_SEPARATOR, sizeof HDB_SEPARATOR - 1);
+ memcpy ((pointer) (zdir
+ + sizeof OLDCONFIGLIB - 1
+ + sizeof HDB_SEPARATOR - 1),
+ (pointer) pzcolon[ifile], clen + 1);
+ iret = _uuconf_iadd_string (qglobal, zdir, FALSE, FALSE,
+ ppz, pblock);
+ }
+ }
+ }
+ }
+
+ (void) fclose (e);
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzargs != NULL)
+ free ((pointer) pzargs);
+ if (pzcolon != NULL)
+ free ((pointer) pzcolon);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = zsys;
+ return iret | UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ }
+ }
+
+ if (qglobal->qprocess->pzhdb_systems == NULL)
+ {
+ char ab[sizeof OLDCONFIGLIB + sizeof HDB_SYSTEMS - 1];
+
+ memcpy ((pointer) ab, (pointer) abHoldconfiglib,
+ sizeof OLDCONFIGLIB - 1);
+ memcpy ((pointer) (ab + sizeof OLDCONFIGLIB - 1),
+ (pointer) HDB_SYSTEMS, sizeof HDB_SYSTEMS);
+ iret = _uuconf_iadd_string (qglobal, ab, TRUE, FALSE,
+ &qglobal->qprocess->pzhdb_systems,
+ pblock);
+ }
+ if (qglobal->qprocess->pzhdb_devices == NULL && iret == UUCONF_SUCCESS)
+ {
+ char ab[sizeof OLDCONFIGLIB + sizeof HDB_DEVICES - 1];
+
+ memcpy ((pointer) ab, (pointer) abHoldconfiglib,
+ sizeof OLDCONFIGLIB - 1);
+ memcpy ((pointer) (ab + sizeof OLDCONFIGLIB - 1),
+ (pointer) HDB_DEVICES, sizeof HDB_DEVICES);
+ iret = _uuconf_iadd_string (qglobal, ab, TRUE, FALSE,
+ &qglobal->qprocess->pzhdb_devices,
+ pblock);
+ }
+ if (qglobal->qprocess->pzhdb_dialers == NULL && iret == UUCONF_SUCCESS)
+ {
+ char ab[sizeof OLDCONFIGLIB + sizeof HDB_DIALERS - 1];
+
+ memcpy ((pointer) ab, (pointer) abHoldconfiglib,
+ sizeof OLDCONFIGLIB - 1);
+ memcpy ((pointer) (ab + sizeof OLDCONFIGLIB - 1),
+ (pointer) HDB_DIALERS, sizeof HDB_DIALERS);
+ iret = _uuconf_iadd_string (qglobal, ab, TRUE, FALSE,
+ &qglobal->qprocess->pzhdb_dialers,
+ pblock);
+ }
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/hlocnm.c b/gnu/libexec/uucp/libuuconf/hlocnm.c
new file mode 100644
index 00000000000..9af4d7e7a51
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hlocnm.c
@@ -0,0 +1,84 @@
+/* hlocnm.c
+ Get the local name to use from the HDB configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hlocnm_rcsid[] = "$Id: hlocnm.c,v 1.1 1993/08/04 19:34:18 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Get the local name to use, based on the login name, from the HDB
+ configuration files. */
+
+int
+uuconf_hdb_login_localname (pglobal, zlogin, pzname)
+ pointer pglobal;
+ const char *zlogin;
+ char **pzname;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct shpermissions *qperm;
+
+ if (! qglobal->qprocess->fhdb_read_permissions)
+ {
+ int iret;
+
+ iret = _uuconf_ihread_permissions (qglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ for (qperm = qglobal->qprocess->qhdb_permissions;
+ qperm != NULL;
+ qperm = qperm->qnext)
+ {
+ if (qperm->zmyname != NULL
+ && qperm->zmyname != (char *) &_uuconf_unset
+ && qperm->pzlogname != NULL
+ && qperm->pzlogname != (char **) &_uuconf_unset)
+ {
+ char **pz;
+
+ for (pz = qperm->pzlogname; *pz != NULL; pz++)
+ {
+ if (strcmp (*pz, zlogin) == 0)
+ {
+ *pzname = strdup (qperm->zmyname);
+ if (*pzname == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ return UUCONF_SUCCESS;
+ }
+ }
+ }
+ }
+
+ *pzname = NULL;
+ return UUCONF_NOT_FOUND;
+}
diff --git a/gnu/libexec/uucp/libuuconf/hport.c b/gnu/libexec/uucp/libuuconf/hport.c
new file mode 100644
index 00000000000..690de91fc24
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hport.c
@@ -0,0 +1,368 @@
+/* hport.c
+ Find a port in the HDB configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hport_rcsid[] = "$Id: hport.c,v 1.1 1993/08/04 19:34:20 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+/* Find a port in the HDB configuration files by name, baud rate, and
+ special purpose function. */
+
+int
+uuconf_hdb_find_port (pglobal, zname, ibaud, ihighbaud, pifn, pinfo, qport)
+ pointer pglobal;
+ const char *zname;
+ long ibaud;
+ long ihighbaud;
+ int (*pifn) P((struct uuconf_port *, pointer));
+ pointer pinfo;
+ struct uuconf_port *qport;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char *zline;
+ size_t cline;
+ char **pzsplit;
+ size_t csplit;
+ int iret;
+ char **pz;
+
+ zline = NULL;
+ cline = 0;
+ pzsplit = NULL;
+ csplit = 0;
+
+ iret = UUCONF_NOT_FOUND;
+
+ for (pz = qglobal->qprocess->pzhdb_devices; *pz != NULL; pz++)
+ {
+ FILE *e;
+ int cchars;
+
+ qglobal->ilineno = 0;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ iret = UUCONF_NOT_FOUND;
+
+ while ((cchars = _uuconf_getline (qglobal, &zline, &cline, e)) > 0)
+ {
+ int ctoks;
+ char *z, *zprotos, *zport;
+ long ilow, ihigh;
+ pointer pblock;
+
+ ++qglobal->ilineno;
+
+ iret = UUCONF_NOT_FOUND;
+
+ --cchars;
+ if (zline[cchars] == '\n')
+ zline[cchars] = '\0';
+ if (isspace (BUCHAR (zline[0])) || zline[0] == '#')
+ continue;
+
+ ctoks = _uuconf_istrsplit (zline, '\0', &pzsplit, &csplit);
+ if (ctoks < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ /* An entry in Devices is
+
+ type device dial-device baud dialer-token pairs
+
+ The type (normally "ACU") is treated as the name. */
+
+ /* If there aren't enough entries, ignore the line; this
+ should probably do something more useful. */
+ if (ctoks < 4)
+ continue;
+
+ /* There may be a comma separated list of protocols after
+ the name. */
+ zprotos = strchr (pzsplit[0], ',');
+ if (zprotos != NULL)
+ {
+ *zprotos = '\0';
+ ++zprotos;
+ }
+
+ zport = pzsplit[0];
+
+ /* Get any modem class, and pick up the baud rate while
+ we're at it. The modem class will be appended to the
+ name, so we need to get it before we see if we've found
+ the port with the right name. */
+ z = pzsplit[3];
+ if (strcasecmp (z, "Any") == 0
+ || strcmp (z, "-") == 0)
+ {
+ ilow = 0L;
+ ihigh = 0L;
+ }
+ else
+ {
+ char *zend;
+
+ while (*z != '\0' && ! isdigit (BUCHAR (*z)))
+ ++z;
+
+ ilow = strtol (z, &zend, 10);
+ if (*zend == '-')
+ ihigh = strtol (zend + 1, (char **) NULL, 10);
+ else
+ ihigh = ilow;
+
+ if (z != pzsplit[3])
+ {
+ size_t cclass, cport;
+
+ cclass = z - pzsplit[3];
+ cport = strlen (pzsplit[0]);
+ zport = malloc (cport + cclass + 1);
+ if (zport == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ memcpy ((pointer) zport, (pointer) pzsplit[0], cport);
+ memcpy ((pointer) (zport + cport), (pointer) pzsplit[3],
+ cclass);
+ zport[cport + cclass] = '\0';
+ }
+ }
+
+ /* Make sure the name and baud rate match any argument. */
+ if ((zname != NULL
+ && strcmp (zport, zname) != 0)
+ || (ibaud != 0
+ && ilow != 0
+ && (ilow > ibaud || ihigh < ibaud)))
+ {
+ if (zport != pzsplit[0])
+ free ((pointer) zport);
+ continue;
+ }
+
+ /* Some systems permit ,M after the device name. This means
+ to open the port with O_NDELAY and then change it. We
+ just ignore this flag, although perhaps we should record
+ it somewhere. */
+ pzsplit[1][strcspn (pzsplit[1], ",")] = '\0';
+
+ /* Now we must construct the port information, so that we
+ can pass it to pifn. The port type is determined by its
+ name, unfortunately. The name "Direct" is used for a
+ direct port, "TCP" for a TCP port, and anything else for
+ a modem port. */
+ pblock = NULL;
+ _uuconf_uclear_port (qport);
+ qport->uuconf_zname = zport;
+ qport->uuconf_zprotocols = zprotos;
+ if (strcmp (pzsplit[0], "Direct") == 0)
+ {
+ qport->uuconf_ttype = UUCONF_PORTTYPE_DIRECT;
+ qport->uuconf_u.uuconf_sdirect.uuconf_zdevice = pzsplit[1];
+ qport->uuconf_u.uuconf_sdirect.uuconf_ibaud = ilow;
+ }
+ else if (strcmp (pzsplit[0], "TCP") == 0)
+ {
+ /* For a TCP port, the device name is taken as the TCP
+ port to use. */
+ qport->uuconf_ttype = UUCONF_PORTTYPE_TCP;
+ qport->uuconf_ireliable
+ = (UUCONF_RELIABLE_ENDTOEND | UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT | UUCONF_RELIABLE_FULLDUPLEX
+ | UUCONF_RELIABLE_SPECIFIED);
+ qport->uuconf_u.uuconf_stcp.uuconf_zport = pzsplit[1];
+ }
+ else if (ctoks >= 5
+ && (strcmp (pzsplit[4], "TLI") == 0
+ || strcmp (pzsplit[4], "TLIS") == 0))
+ {
+ size_t c;
+ char **pzd;
+
+ qport->uuconf_ttype = UUCONF_PORTTYPE_TLI;
+ qport->uuconf_u.uuconf_stli.uuconf_zdevice = pzsplit[1];
+ qport->uuconf_u.uuconf_stli.uuconf_fstream
+ = strcmp (pzsplit[4], "TLIS") == 0;
+ qport->uuconf_u.uuconf_stli.uuconf_pzpush = NULL;
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ c = (ctoks - 4) * sizeof (char *);
+ pzd = (char **) uuconf_malloc (pblock, c + sizeof (char *));
+ if (pzd == NULL)
+ {
+ qglobal->ierrno = errno;
+ uuconf_free_block (pblock);
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ memcpy ((pointer) pzd, (pointer) (pzsplit + 4), c);
+ pzd[ctoks - 4] = NULL;
+ qport->uuconf_u.uuconf_stli.uuconf_pzdialer = pzd;
+ qport->uuconf_u.uuconf_stli.uuconf_zservaddr = NULL;
+ qport->uuconf_ireliable
+ = (UUCONF_RELIABLE_ENDTOEND | UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT | UUCONF_RELIABLE_FULLDUPLEX
+ | UUCONF_RELIABLE_SPECIFIED);
+ }
+ else
+ {
+ qport->uuconf_ttype = UUCONF_PORTTYPE_MODEM;
+ qport->uuconf_u.uuconf_smodem.uuconf_zdevice = pzsplit[1];
+ if (strcmp (pzsplit[2], "-") != 0)
+ qport->uuconf_u.uuconf_smodem.uuconf_zdial_device =
+ pzsplit[2];
+ else
+ qport->uuconf_u.uuconf_smodem.uuconf_zdial_device = NULL;
+ if (ilow == ihigh)
+ {
+ qport->uuconf_u.uuconf_smodem.uuconf_ibaud = ilow;
+ qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud = 0L;
+ qport->uuconf_u.uuconf_smodem.uuconf_ihighbaud = 0L;
+ }
+ else
+ {
+ qport->uuconf_u.uuconf_smodem.uuconf_ibaud = 0L;
+ qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud = ilow;
+ qport->uuconf_u.uuconf_smodem.uuconf_ihighbaud = ihigh;
+ }
+ qport->uuconf_u.uuconf_smodem.uuconf_fcarrier = TRUE;
+ if (ctoks < 5)
+ qport->uuconf_u.uuconf_smodem.uuconf_pzdialer = NULL;
+ else
+ {
+ size_t c;
+ char **pzd;
+
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ c = (ctoks - 4) * sizeof (char *);
+ pzd = (char **) uuconf_malloc (pblock, c + sizeof (char *));
+ if (pzd == NULL)
+ {
+ qglobal->ierrno = errno;
+ uuconf_free_block (pblock);
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ memcpy ((pointer) pzd, (pointer) (pzsplit + 4), c);
+ pzd[ctoks - 4] = NULL;
+
+ qport->uuconf_u.uuconf_smodem.uuconf_pzdialer = pzd;
+ }
+ qport->uuconf_u.uuconf_smodem.uuconf_qdialer = NULL;
+ }
+
+ if (pifn != NULL)
+ {
+ iret = (*pifn) (qport, pinfo);
+ if (iret != UUCONF_SUCCESS)
+ {
+ if (zport != pzsplit[0])
+ free ((pointer) zport);
+ if (pblock != NULL)
+ uuconf_free_block (pblock);
+ if (iret != UUCONF_NOT_FOUND)
+ break;
+ continue;
+ }
+ }
+
+ /* This is the port we want. */
+ if (pblock == NULL)
+ {
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ }
+
+ if (uuconf_add_block (pblock, zline) != 0
+ || (zport != pzsplit[0]
+ && uuconf_add_block (pblock, zport) != 0))
+ {
+ qglobal->ierrno = errno;
+ uuconf_free_block (pblock);
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ zline = NULL;
+
+ qport->uuconf_palloc = pblock;
+
+ break;
+ }
+
+ (void) fclose (e);
+
+ if (iret != UUCONF_NOT_FOUND)
+ break;
+ }
+
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+
+ if (iret != UUCONF_SUCCESS && iret != UUCONF_NOT_FOUND)
+ {
+ qglobal->zfilename = *pz;
+ iret |= UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ }
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/hrmunk.c b/gnu/libexec/uucp/libuuconf/hrmunk.c
new file mode 100644
index 00000000000..e7516f7e784
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hrmunk.c
@@ -0,0 +1,55 @@
+/* remunk.c
+ Get the name of the HDB remote.unknown shell script.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hrmunk_rcsid[] = "$Id: hrmunk.c,v 1.1 1993/08/04 19:34:22 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Get the name of the HDB remote.unknown shell script. */
+
+int
+uuconf_hdb_remote_unknown (pglobal, pzname)
+ pointer pglobal;
+ char **pzname;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ size_t csize;
+
+ csize = sizeof OLDCONFIGLIB + sizeof HDB_REMOTE_UNKNOWN - 1;
+ *pzname = malloc (csize);
+ if (*pzname == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ memcpy (*pzname, OLDCONFIGLIB, sizeof OLDCONFIGLIB - 1);
+ memcpy (*pzname + sizeof OLDCONFIGLIB - 1, HDB_REMOTE_UNKNOWN,
+ sizeof HDB_REMOTE_UNKNOWN);
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/hsinfo.c b/gnu/libexec/uucp/libuuconf/hsinfo.c
new file mode 100644
index 00000000000..83129a3e706
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hsinfo.c
@@ -0,0 +1,625 @@
+/* hsinfo.c
+ Get information about a system from the HDB configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hsinfo_rcsid[] = "$Id: hsinfo.c,v 1.1 1993/08/04 19:34:24 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+static int ihadd_machine_perm P((struct sglobal *qglobal,
+ struct uuconf_system *qsys,
+ struct shpermissions *qperm));
+static int ihadd_logname_perm P((struct sglobal *qglobal,
+ struct uuconf_system *qsys,
+ struct shpermissions *qperm));
+
+/* Get the information for a particular system from the HDB
+ configuration files. This does not make sure that all the default
+ values are set. */
+
+int
+_uuconf_ihdb_system_internal (qglobal, zsystem, qsys)
+ struct sglobal *qglobal;
+ const char *zsystem;
+ struct uuconf_system *qsys;
+{
+ int iret;
+ struct shpermissions *qperm;
+ char *zline;
+ size_t cline;
+ char **pzsplit;
+ size_t csplit;
+ char **pzcomma;
+ size_t ccomma;
+ pointer pblock;
+ char **pz;
+ boolean ffound_machine, ffound_login;
+ struct shpermissions *qother_machine;
+ struct uuconf_system *qalt;
+
+ if (! qglobal->qprocess->fhdb_read_permissions)
+ {
+ iret = _uuconf_ihread_permissions (qglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ /* First look through the Permissions information to see if this is
+ an alias for some system. I assume that an alias applies to the
+ first name in the corresponding MACHINE entry. */
+
+ for (qperm = qglobal->qprocess->qhdb_permissions;
+ qperm != NULL;
+ qperm = qperm->qnext)
+ {
+ if (qperm->pzalias == NULL
+ || qperm->pzmachine == NULL
+ || qperm->pzalias == (char **) &_uuconf_unset
+ || qperm->pzmachine == (char **) &_uuconf_unset)
+ continue;
+
+ for (pz = qperm->pzalias; *pz != NULL; pz++)
+ {
+ if (strcmp (*pz, zsystem) == 0)
+ {
+ zsystem = qperm->pzmachine[0];
+ break;
+ }
+ }
+ if (*pz != NULL)
+ break;
+ }
+
+ zline = NULL;
+ cline = 0;
+ pzsplit = NULL;
+ csplit = 0;
+ pzcomma = NULL;
+ ccomma = 0;
+
+ pblock = NULL;
+
+ iret = UUCONF_SUCCESS;
+
+ for (pz = qglobal->qprocess->pzhdb_systems; *pz != NULL; pz++)
+ {
+ FILE *e;
+ int cchars;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ qglobal->ilineno = 0;
+
+ while ((cchars = _uuconf_getline (qglobal, &zline, &cline, e)) > 0)
+ {
+ int ctoks, ctimes, i;
+ struct uuconf_system *qset;
+ char *z, *zretry;
+ int cretry;
+
+ ++qglobal->ilineno;
+
+ --cchars;
+ if (zline[cchars] == '\n')
+ zline[cchars] = '\0';
+ if (isspace (BUCHAR (zline[0])) || zline[0] == '#')
+ continue;
+
+ ctoks = _uuconf_istrsplit (zline, '\0', &pzsplit, &csplit);
+ if (ctoks < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ /* If this isn't the system we're looking for, keep reading
+ the file. */
+ if (ctoks < 1
+ || strcmp (zsystem, pzsplit[0]) != 0)
+ continue;
+
+ /* If this is the first time we've found the system, we want
+ to set *qsys directly. Otherwise, we allocate a new
+ alternate. */
+ if (pblock == NULL)
+ {
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ _uuconf_uclear_system (qsys);
+ qsys->uuconf_palloc = pblock;
+ qset = qsys;
+ }
+ else
+ {
+ struct uuconf_system **pq;
+
+ qset = ((struct uuconf_system *)
+ uuconf_malloc (pblock, sizeof (struct uuconf_system)));
+ if (qset == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ _uuconf_uclear_system (qset);
+ for (pq = &qsys->uuconf_qalternate;
+ *pq != NULL;
+ pq = &(*pq)->uuconf_qalternate)
+ ;
+ *pq = qset;
+ }
+
+ /* Add this line to the memory block we are building for the
+ system. */
+ if (uuconf_add_block (pblock, zline) != 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ zline = NULL;
+ cline = 0;
+
+ /* The format of a line in Systems is
+ system time device speed phone chat
+ For example,
+ airs Any ACU 9600 5551212 ogin: foo pass: bar
+ */
+
+ /* Get the system name. */
+
+ qset->uuconf_zname = pzsplit[0];
+ qset->uuconf_fcall = TRUE;
+ qset->uuconf_fcalled = FALSE;
+
+ if (ctoks < 2)
+ continue;
+
+ /* A time string is "time/grade,time/grade;retry". A
+ missing grade is taken as BGRADE_LOW. */
+ zretry = strchr (pzsplit[1], ';');
+ if (zretry == NULL)
+ cretry = 0;
+ else
+ {
+ *zretry = '\0';
+ cretry = (int) strtol (zretry + 1, (char **) NULL, 10);
+ }
+
+ ctimes = _uuconf_istrsplit (pzsplit[1], ',', &pzcomma, &ccomma);
+ if (ctimes < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ for (i = 0; i < ctimes; i++)
+ {
+ char *zslash;
+ char bgrade;
+
+ z = pzcomma[i];
+ zslash = strchr (z, '/');
+ if (zslash == NULL)
+ bgrade = UUCONF_GRADE_LOW;
+ else
+ {
+ *zslash = '\0';
+ bgrade = zslash[1];
+ if (! UUCONF_GRADE_LEGAL (bgrade))
+ bgrade = UUCONF_GRADE_LOW;
+ }
+
+ iret = _uuconf_itime_parse (qglobal, z, (long) bgrade,
+ cretry, _uuconf_itime_grade_cmp,
+ &qset->uuconf_qtimegrade,
+ pblock);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ break;
+
+ if (ctoks < 3)
+ continue;
+
+ /* Pick up the device name. It can be followed by a comma
+ and a list of protocols. */
+ qset->uuconf_zport = pzsplit[2];
+ z = strchr (pzsplit[2], ',');
+ if (z != NULL)
+ {
+ qset->uuconf_zprotocols = z + 1;
+ *z = '\0';
+ }
+
+ if (ctoks < 4)
+ continue;
+
+ /* The speed entry can be a numeric speed, or a range of
+ speeds, or "Any", or "-". If it starts with a letter,
+ the initial nonnumeric prefix is a modem class, which
+ gets appended to the port name. */
+ z = pzsplit[3];
+ if (strcasecmp (z, "Any") != 0
+ && strcmp (z, "-") != 0)
+ {
+ char *zend;
+
+ while (*z != '\0' && ! isdigit (BUCHAR (*z)))
+ ++z;
+
+ qset->uuconf_ibaud = strtol (z, &zend, 10);
+ if (*zend == '-')
+ qset->uuconf_ihighbaud = strtol (zend + 1, (char **) NULL,
+ 10);
+
+ if (z != pzsplit[3])
+ {
+ size_t cport, cclass;
+
+ cport = strlen (pzsplit[2]);
+ cclass = z - pzsplit[3];
+ qset->uuconf_zport = uuconf_malloc (pblock,
+ cport + cclass + 1);
+ if (qset->uuconf_zport == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ memcpy ((pointer) qset->uuconf_zport, (pointer) pzsplit[2],
+ cport);
+ memcpy ((pointer) (qset->uuconf_zport + cport),
+ (pointer) pzsplit[3], cclass);
+ qset->uuconf_zport[cport + cclass] = '\0';
+ }
+ }
+
+ if (ctoks < 5)
+ continue;
+
+ /* Get the phone number. */
+ qset->uuconf_zphone = pzsplit[4];
+
+ if (ctoks < 6)
+ continue;
+
+ /* Get the chat script. We just hand this off to the chat
+ script processor, so that it will parse subsend and
+ subexpect strings correctly. */
+ pzsplit[4] = (char *) "chat";
+ iret = _uuconf_ichat_cmd (qglobal, ctoks - 4, pzsplit + 4,
+ &qset->uuconf_schat, pblock);
+ iret &=~ UUCONF_CMDTABRET_KEEP;
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+
+ (void) fclose (e);
+
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+ if (pzcomma != NULL)
+ free ((pointer) pzcomma);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = *pz;
+ return iret | UUCONF_ERROR_FILENAME;
+ }
+
+ if (pblock == NULL)
+ return UUCONF_NOT_FOUND;
+
+ /* Now we have to put in the Permissions information. The relevant
+ Permissions entries are those with this system in the MACHINE
+ list and (if this system does not have a VALIDATE entry) those
+ with a LOGNAME list but no MACHINE list. If no entry is found
+ with this system in the MACHINE list, then we must look for an
+ entry with "OTHER" in the MACHINE list. */
+ ffound_machine = FALSE;
+ ffound_login = FALSE;
+ qother_machine = NULL;
+ for (qperm = qglobal->qprocess->qhdb_permissions;
+ qperm != NULL;
+ qperm = qperm->qnext)
+ {
+ boolean fmachine;
+
+ /* MACHINE=OTHER is recognized specially. It appears that OTHER
+ need only be recognized by itself, not when combined with
+ other machine names. */
+ if (qother_machine == NULL
+ && qperm->pzmachine != NULL
+ && qperm->pzmachine != (char **) &_uuconf_unset
+ && qperm->pzmachine[0][0] == 'O'
+ && strcmp (qperm->pzmachine[0], "OTHER") == 0)
+ qother_machine = qperm;
+
+ /* If this system is named in a MACHINE entry, we must add the
+ appropriate information to every alternate that could be used
+ for calling out. */
+ fmachine = FALSE;
+ if (! ffound_machine
+ && qperm->pzmachine != NULL
+ && qperm->pzmachine != (char **) &_uuconf_unset)
+ {
+ for (pz = qperm->pzmachine; *pz != NULL; pz++)
+ {
+ if ((*pz)[0] == zsystem[0]
+ && strcmp (*pz, zsystem) == 0)
+ {
+ for (qalt = qsys;
+ qalt != NULL;
+ qalt = qalt->uuconf_qalternate)
+ {
+ if (qalt->uuconf_fcall)
+ {
+ iret = ihadd_machine_perm (qglobal, qalt, qperm);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ }
+
+ fmachine = TRUE;
+ ffound_machine = TRUE;
+
+ break;
+ }
+ }
+ }
+
+ /* A LOGNAME line applies to this machine if it is listed in the
+ corresponding VALIDATE entry, or if it is not listed in any
+ VALIDATE entry. On this pass through the Permissions entry
+ we pick up the information if the system appears in a
+ VALIDATE entry; if it does not, we make another pass to put
+ in all the LOGNAME lines. */
+ if (qperm->pzlogname != NULL
+ && qperm->pzlogname != (char **) &_uuconf_unset
+ && qperm->pzvalidate != NULL
+ && qperm->pzvalidate != (char **) &_uuconf_unset)
+ {
+ for (pz = qperm->pzvalidate; *pz != NULL; ++pz)
+ if ((*pz)[0] == zsystem[0]
+ && strcmp (*pz, zsystem) == 0)
+ break;
+ if (*pz != NULL)
+ {
+ for (pz = qperm->pzlogname; *pz != NULL; ++pz)
+ {
+ /* If this LOGNAME line is also a matching MACHINE
+ line, we can add the LOGNAME permissions to the
+ first alternate. Otherwise, we must create a new
+ alternate. We cannot put a LOGNAME line in the
+ first alternate if MACHINE does not match,
+ because certain permissions (e.g. READ) may be
+ specified by both types of lines, and we must use
+ LOGNAME entries only when accepting calls and
+ MACHINE entries only when placing calls. */
+ if (fmachine
+ && (qsys->uuconf_zcalled_login == NULL
+ || (qsys->uuconf_zcalled_login
+ == (char *) &_uuconf_unset)))
+ {
+ qsys->uuconf_zcalled_login = *pz;
+ iret = ihadd_logname_perm (qglobal, qsys, qperm);
+ }
+ else
+ {
+ struct uuconf_system *qnew;
+ struct uuconf_system **pq;
+
+ qnew = ((struct uuconf_system *)
+ uuconf_malloc (pblock,
+ sizeof (struct uuconf_system)));
+ if (qnew == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ *qnew = *qsys;
+ qnew->uuconf_qalternate = NULL;
+ for (pq = &qsys->uuconf_qalternate;
+ *pq != NULL;
+ pq = &(*pq)->uuconf_qalternate)
+ ;
+ *pq = qnew;
+
+ qnew->uuconf_zcalled_login = *pz;
+ qnew->uuconf_fcall = FALSE;
+ iret = ihadd_logname_perm (qglobal, qnew, qperm);
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ ffound_login = TRUE;
+ }
+ }
+ }
+
+ /* If we didn't find an entry for the machine, we must use the
+ MACHINE=OTHER entry, if any. */
+ if (! ffound_machine && qother_machine != NULL)
+ {
+ for (qalt = qsys; qalt != NULL; qalt = qalt->uuconf_qalternate)
+ {
+ if (qalt->uuconf_fcall)
+ {
+ iret = ihadd_machine_perm (qglobal, qalt, qother_machine);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ }
+ }
+
+ /* If this system was not listed in any VALIDATE entry, then we must
+ add a called-login for each LOGNAME entry in Permissions. */
+ if (! ffound_login)
+ {
+ for (qperm = qglobal->qprocess->qhdb_permissions;
+ qperm != NULL;
+ qperm = qperm->qnext)
+ {
+ if (qperm->pzlogname == NULL
+ || qperm->pzlogname == (char **) &_uuconf_unset)
+ continue;
+
+ for (pz = qperm->pzlogname; *pz != NULL; pz++)
+ {
+ struct uuconf_system *qnew;
+ struct uuconf_system **pq;
+
+ qnew = ((struct uuconf_system *)
+ uuconf_malloc (pblock,
+ sizeof (struct uuconf_system)));
+ if (qnew == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ *qnew = *qsys;
+ qnew->uuconf_qalternate = NULL;
+ for (pq = &qsys->uuconf_qalternate;
+ *pq != NULL;
+ pq = &(*pq)->uuconf_qalternate)
+ ;
+ *pq = qnew;
+
+ /* We recognize LOGNAME=OTHER specially, although this
+ appears to be an SCO innovation. */
+ if (strcmp (*pz, "OTHER") == 0)
+ qnew->uuconf_zcalled_login = (char *) "ANY";
+ else
+ qnew->uuconf_zcalled_login = *pz;
+ qnew->uuconf_fcall = FALSE;
+ iret = ihadd_logname_perm (qglobal, qnew, qperm);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ }
+ }
+
+ /* HDB permits local requests to receive to any directory, which is
+ not the default put in by _uuconf_isystem_basic_default. We set
+ it here instead. */
+ for (qalt = qsys; qalt != NULL; qalt = qalt->uuconf_qalternate)
+ {
+ iret = _uuconf_iadd_string (qglobal, (char *) ZROOTDIR,
+ FALSE, FALSE,
+ &qalt->uuconf_pzlocal_receive,
+ pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ /* HDB does not have a maximum number of retries if a retry time is
+ given in the time field. */
+ if (qsys->uuconf_qtimegrade != NULL
+ && qsys->uuconf_qtimegrade != (struct uuconf_timespan *) &_uuconf_unset
+ && qsys->uuconf_qtimegrade->uuconf_cretry > 0)
+ qsys->uuconf_cmax_retries = 0;
+
+ return UUCONF_SUCCESS;
+}
+
+/* Add the settings of a MACHINE line in Permissions to a system. */
+
+/*ARGSIGNORED*/
+static int
+ihadd_machine_perm (qglobal, qsys, qperm)
+ struct sglobal *qglobal;
+ struct uuconf_system *qsys;
+ struct shpermissions *qperm;
+{
+ if (qperm->frequest >= 0)
+ qsys->uuconf_fsend_request = qperm->frequest;
+ else
+ qsys->uuconf_fsend_request = FALSE;
+ qsys->uuconf_pzremote_send = qperm->pzread;
+ qsys->uuconf_pzremote_receive = qperm->pzwrite;
+ qsys->uuconf_pzcmds = qperm->pzcommands;
+ qsys->uuconf_zlocalname = qperm->zmyname;
+ qsys->uuconf_zpubdir = qperm->zpubdir;
+ qsys->uuconf_pzalias = qperm->pzalias;
+
+ return UUCONF_SUCCESS;
+}
+
+/* Add the settings of a LOGNAME line in Permissions to a system. */
+
+/*ARGSIGNORED*/
+static int
+ihadd_logname_perm (qglobal, qsys, qperm)
+ struct sglobal *qglobal;
+ struct uuconf_system *qsys;
+ struct shpermissions *qperm;
+{
+ qsys->uuconf_fcalled = TRUE;
+ if (qperm->frequest >= 0)
+ qsys->uuconf_fsend_request = qperm->frequest;
+ else
+ qsys->uuconf_fsend_request = FALSE;
+ qsys->uuconf_fcalled_transfer = qperm->fsendfiles;
+ qsys->uuconf_pzremote_send = qperm->pzread;
+ qsys->uuconf_pzremote_receive = qperm->pzwrite;
+ qsys->uuconf_fcallback = qperm->fcallback;
+ qsys->uuconf_zlocalname = qperm->zmyname;
+ qsys->uuconf_zpubdir = qperm->zpubdir;
+
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/hsnams.c b/gnu/libexec/uucp/libuuconf/hsnams.c
new file mode 100644
index 00000000000..de003a3ec5e
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hsnams.c
@@ -0,0 +1,142 @@
+/* hsnams.c
+ Get all known system names from the HDB configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hsnams_rcsid[] = "$Id: hsnams.c,v 1.1 1993/08/04 19:34:26 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+/* Get all the system names from the HDB Systems file. We have to
+ read the Permissions file in order to support aliases. */
+
+int
+uuconf_hdb_system_names (pglobal, ppzsystems, falias)
+ pointer pglobal;
+ char ***ppzsystems;
+ int falias;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+ char *zline;
+ size_t cline;
+ char **pz;
+
+ *ppzsystems = NULL;
+
+ iret = UUCONF_SUCCESS;
+
+ zline = NULL;
+ cline = 0;
+
+ for (pz = qglobal->qprocess->pzhdb_systems; *pz != NULL; pz++)
+ {
+ FILE *e;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ qglobal->ilineno = 0;
+
+ while (_uuconf_getline (qglobal, &zline, &cline, e) > 0)
+ {
+ ++qglobal->ilineno;
+
+ /* Lines beginning with whitespace are treated as comments.
+ No system name can contain a '#', which is another
+ comment character, so eliminating the first '#' does no
+ harm and catches comments. */
+ zline[strcspn (zline, " \t#\n")] = '\0';
+ if (*zline == '\0')
+ continue;
+
+ iret = _uuconf_iadd_string (qglobal, zline, TRUE, TRUE,
+ ppzsystems, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ {
+ iret |= UUCONF_ERROR_LINENO;
+ break;
+ }
+ }
+
+ (void) fclose (e);
+ }
+
+ if (zline != NULL)
+ free ((pointer) zline);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = *pz;
+ return iret | UUCONF_ERROR_FILENAME;
+ }
+
+ /* If we are supposed to return aliases, we must read the
+ Permissions file. */
+ if (falias)
+ {
+ struct shpermissions *q;
+
+ if (! qglobal->qprocess->fhdb_read_permissions)
+ {
+ iret = _uuconf_ihread_permissions (qglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ for (q = qglobal->qprocess->qhdb_permissions;
+ q != NULL;
+ q = q->qnext)
+ {
+ pz = q->pzalias;
+ if (pz == NULL || pz == (char **) &_uuconf_unset)
+ continue;
+
+ for (; *pz != NULL; pz++)
+ {
+ iret = _uuconf_iadd_string (qglobal, *pz, TRUE, TRUE,
+ ppzsystems, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ }
+ }
+
+ if (*ppzsystems == NULL)
+ iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
+ ppzsystems, (pointer) NULL);
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/hsys.c b/gnu/libexec/uucp/libuuconf/hsys.c
new file mode 100644
index 00000000000..676c20ff0e3
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hsys.c
@@ -0,0 +1,49 @@
+/* hsys.c
+ User function to get a system from the HDB configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hsys_rcsid[] = "$Id: hsys.c,v 1.1 1993/08/04 19:34:29 jtc Exp $";
+#endif
+
+/* Get system information from the HDB configuration files. This is a
+ wrapper for the internal function which makes sure that every field
+ gets a default value. */
+
+int
+uuconf_hdb_system_info (pglobal, zsystem, qsys)
+ pointer pglobal;
+ const char *zsystem;
+ struct uuconf_system *qsys;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+
+ iret = _uuconf_ihdb_system_internal (qglobal, zsystem, qsys);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ return _uuconf_isystem_basic_default (qglobal, qsys);
+}
diff --git a/gnu/libexec/uucp/libuuconf/hunk.c b/gnu/libexec/uucp/libuuconf/hunk.c
new file mode 100644
index 00000000000..8e997d0b710
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/hunk.c
@@ -0,0 +1,142 @@
+/* hunk.c
+ Get information about an unknown system from the HDB Permissions file.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_hunk_rcsid[] = "$Id: hunk.c,v 1.1 1993/08/04 19:34:31 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Get information about an unknown system from the HDB Permissions
+ file. This doesn't run the remote.unknown shell script, because
+ that's too system dependent. */
+
+int
+uuconf_hdb_system_unknown (pglobal, qsys)
+ pointer pglobal;
+ struct uuconf_system *qsys;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+ boolean ffirst;
+ struct shpermissions *qperm;
+ struct uuconf_system *qalt;
+
+ if (! qglobal->qprocess->fhdb_read_permissions)
+ {
+ iret = _uuconf_ihread_permissions (qglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ _uuconf_uclear_system (qsys);
+ qsys->uuconf_palloc = uuconf_malloc_block ();
+ if (qsys->uuconf_palloc == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ ffirst = TRUE;
+
+ for (qperm = qglobal->qprocess->qhdb_permissions;
+ qperm != NULL;
+ qperm = qperm->qnext)
+ {
+ char **pz;
+
+ if (qperm->pzlogname == NULL
+ || qperm->pzlogname == (char **) &_uuconf_unset)
+ continue;
+
+ for (pz = qperm->pzlogname; *pz != NULL; pz++)
+ {
+ if (ffirst)
+ {
+ qalt = qsys;
+ ffirst = FALSE;
+ }
+ else
+ {
+ struct uuconf_system **pq;
+
+ qalt = ((struct uuconf_system *)
+ uuconf_malloc (qsys->uuconf_palloc,
+ sizeof (struct uuconf_system)));
+ if (qalt == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ _uuconf_uclear_system (qalt);
+ for (pq = &qsys->uuconf_qalternate;
+ *pq != NULL;
+ pq = &(*pq)->uuconf_qalternate)
+ ;
+ *pq = qalt;
+ }
+
+ /* We recognize LOGNAME=OTHER specially, although this
+ appears to be an SCO innovation. */
+ if (strcmp (*pz, "OTHER") == 0)
+ qalt->uuconf_zcalled_login = (char *) "ANY";
+ else
+ qalt->uuconf_zcalled_login = *pz;
+ qalt->uuconf_fcall = FALSE;
+ qsys->uuconf_fcalled = TRUE;
+ if (qperm->frequest >= 0)
+ qsys->uuconf_fsend_request = qperm->frequest;
+ else
+ qsys->uuconf_fsend_request = FALSE;
+ qsys->uuconf_fcalled_transfer = qperm->fsendfiles;
+ qsys->uuconf_pzremote_send = qperm->pzread;
+ qsys->uuconf_pzremote_receive = qperm->pzwrite;
+ qsys->uuconf_fcallback = qperm->fcallback;
+ qsys->uuconf_zlocalname = qperm->zmyname;
+ qsys->uuconf_zpubdir = qperm->zpubdir;
+ }
+ }
+
+ if (ffirst)
+ return UUCONF_NOT_FOUND;
+
+ /* HDB permits local requests to receive to any directory, which is
+ not the default put in by _uuconf_isystem_basic_default. We set
+ it here instead. */
+ for (qalt = qsys; qalt != NULL; qalt = qalt->uuconf_qalternate)
+ {
+ iret = _uuconf_iadd_string (qglobal, (char *) ZROOTDIR,
+ FALSE, FALSE,
+ &qalt->uuconf_pzlocal_receive,
+ qsys->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ return _uuconf_isystem_basic_default (qglobal, qsys);
+}
diff --git a/gnu/libexec/uucp/libuuconf/iniglb.c b/gnu/libexec/uucp/libuuconf/iniglb.c
new file mode 100644
index 00000000000..2422656efc4
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/iniglb.c
@@ -0,0 +1,177 @@
+/* iniglb.c
+ Initialize the global information structure.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_iniglb_rcsid[] = "$Id: iniglb.c,v 1.1 1993/08/04 19:34:33 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Initialize the global information structure. */
+
+int
+_uuconf_iinit_global (pqglobal)
+ struct sglobal **pqglobal;
+{
+ pointer pblock;
+ register struct sprocess *qprocess;
+ char *azargs[3];
+ int iret;
+
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ return UUCONF_MALLOC_FAILED;
+
+ *pqglobal = (struct sglobal *) uuconf_malloc (pblock,
+ sizeof (struct sglobal));
+ if (*pqglobal == NULL)
+ {
+ uuconf_free_block (pblock);
+ return UUCONF_MALLOC_FAILED;
+ }
+
+ (*pqglobal)->qprocess = ((struct sprocess *)
+ uuconf_malloc (pblock,
+ sizeof (struct sprocess)));
+ if ((*pqglobal)->qprocess == NULL)
+ {
+ uuconf_free_block (pblock);
+ *pqglobal = NULL;
+ return UUCONF_MALLOC_FAILED;
+ }
+
+ (*pqglobal)->pblock = pblock;
+ (*pqglobal)->ierrno = 0;
+ (*pqglobal)->ilineno = 0;
+ (*pqglobal)->zfilename = NULL;
+
+ qprocess = (*pqglobal)->qprocess;
+
+ qprocess->zlocalname = NULL;
+ qprocess->zspooldir = SPOOLDIR;
+ qprocess->zpubdir = PUBDIR;
+#ifdef LOCKDIR
+ qprocess->zlockdir = LOCKDIR;
+#else
+ qprocess->zlockdir = SPOOLDIR;
+#endif
+ qprocess->zlogfile = LOGFILE;
+ qprocess->zstatsfile = STATFILE;
+ qprocess->zdebugfile = DEBUGFILE;
+ qprocess->zdebug = "";
+ qprocess->cmaxuuxqts = 0;
+ qprocess->fv2 = TRUE;
+ qprocess->fhdb = TRUE;
+ qprocess->pzdialcodefiles = NULL;
+ qprocess->pztimetables = NULL;
+ qprocess->zconfigfile = NULL;
+ qprocess->pzsysfiles = NULL;
+ qprocess->pzportfiles = NULL;
+ qprocess->pzdialfiles = NULL;
+ qprocess->pzpwdfiles = NULL;
+ qprocess->pzcallfiles = NULL;
+ qprocess->qunknown = NULL;
+ qprocess->fread_syslocs = FALSE;
+ qprocess->qsyslocs = NULL;
+ qprocess->qvalidate = NULL;
+ qprocess->fuses_myname = FALSE;
+ qprocess->zv2systems = NULL;
+ qprocess->zv2devices = NULL;
+ qprocess->zv2userfile = NULL;
+ qprocess->zv2cmds = NULL;
+ qprocess->pzhdb_systems = NULL;
+ qprocess->pzhdb_devices = NULL;
+ qprocess->pzhdb_dialers = NULL;
+ qprocess->fhdb_read_permissions = FALSE;
+ qprocess->qhdb_permissions = NULL;
+
+ azargs[0] = NULL;
+ azargs[1] = (char *) "Evening";
+ azargs[2] = (char *) "Wk1705-0755,Sa,Su";
+ iret = _uuconf_itimetable ((pointer) *pqglobal, 3, azargs,
+ (pointer) NULL, (pointer) NULL);
+ if (UUCONF_ERROR_VALUE (iret) == UUCONF_SUCCESS)
+ {
+ azargs[1] = (char *) "Night";
+ azargs[2] = (char *) "Wk2305-0755,Sa,Su2305-1655";
+ iret = _uuconf_itimetable ((pointer) *pqglobal, 3, azargs,
+ (pointer) NULL, (pointer) NULL);
+ }
+ if (UUCONF_ERROR_VALUE (iret) == UUCONF_SUCCESS)
+ {
+ azargs[1] = (char *) "NonPeak";
+ azargs[2] = (char *) "Wk1805-0655,Sa,Su";
+ iret = _uuconf_itimetable ((pointer) *pqglobal, 3, azargs,
+ (pointer) NULL, (pointer) NULL);
+ }
+ if (UUCONF_ERROR_VALUE (iret) != UUCONF_SUCCESS)
+ {
+ uuconf_free_block (pblock);
+ *pqglobal = NULL;
+
+ /* Strip off any special bits, since there's no global
+ structure. */
+ return UUCONF_ERROR_VALUE (iret);
+ }
+
+ return UUCONF_SUCCESS;
+}
+
+/* Add a timetable. This is also called by the Taylor UUCP
+ initialization code, as well as by the Taylor UUCP sys file code
+ (although the latter is obsolete). There's no point in putting
+ this in a separate file, since everything must call
+ _uuconf_init_global. There is a race condition here if this is
+ called by two different threads on a sys file command, but the sys
+ file command is obsolete anyhow. */
+
+/*ARGSUSED*/
+int
+_uuconf_itimetable (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+
+ iret = _uuconf_iadd_string (qglobal, argv[1], FALSE, FALSE,
+ &qglobal->qprocess->pztimetables,
+ qglobal->pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret | UUCONF_CMDTABRET_EXIT;
+
+ iret = _uuconf_iadd_string (qglobal, argv[2], FALSE, FALSE,
+ &qglobal->qprocess->pztimetables,
+ qglobal->pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret | UUCONF_CMDTABRET_EXIT;
+
+ return UUCONF_CMDTABRET_KEEP;
+}
diff --git a/gnu/libexec/uucp/libuuconf/init.c b/gnu/libexec/uucp/libuuconf/init.c
new file mode 100644
index 00000000000..ef252a78245
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/init.c
@@ -0,0 +1,74 @@
+/* init.c
+ Initialize for reading UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_init_rcsid[] = "$Id: init.c,v 1.1 1993/08/04 19:34:35 jtc Exp $";
+#endif
+
+/* Initialize the UUCP configuration file reading routines. This is
+ just a generic routine which calls the type specific routines. */
+
+/*ARGSUSED*/
+int
+uuconf_init (ppglobal, zprogram, zname)
+ pointer *ppglobal;
+ const char *zprogram;
+ const char *zname;
+{
+ struct sglobal **pqglob = (struct sglobal **) ppglobal;
+ int iret;
+
+ iret = UUCONF_NOT_FOUND;
+
+ *pqglob = NULL;
+
+#if HAVE_TAYLOR_CONFIG
+ iret = uuconf_taylor_init (ppglobal, zprogram, zname);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+#endif
+
+#if HAVE_V2_CONFIG
+ if (*pqglob == NULL || (*pqglob)->qprocess->fv2)
+ {
+ iret = uuconf_v2_init (ppglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+#endif
+
+#if HAVE_HDB_CONFIG
+ if (*pqglob == NULL || (*pqglob)->qprocess->fhdb)
+ {
+ iret = uuconf_hdb_init (ppglobal, zprogram);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+#endif
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/int.c b/gnu/libexec/uucp/libuuconf/int.c
new file mode 100644
index 00000000000..b0047ee6c09
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/int.c
@@ -0,0 +1,59 @@
+/* int.c
+ Parse a string into an int or a long.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_int_rcsid[] = "$Id: int.c,v 1.1 1993/08/04 19:34:37 jtc Exp $";
+#endif
+
+/* Parse a string into a variable. This is called by uuconf_cmd_args,
+ as well as other functions. The parsing is done in a single place
+ to make it easy to change. This should return an error code,
+ including both UUCONF_CMDTABRET_KEEP and UUCONF_CMDTABRET_EXIT if
+ appropriate. */
+
+/*ARGSIGNORED*/
+int
+_uuconf_iint (qglobal, zval, p, fint)
+ struct sglobal *qglobal;
+ const char *zval;
+ pointer p;
+ boolean fint;
+{
+ long i;
+ char *zend;
+
+ i = strtol ((char *) zval, &zend, 10);
+ if (*zend != '\0')
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ if (fint)
+ *(int *) p = (int) i;
+ else
+ *(long *) p = i;
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
diff --git a/gnu/libexec/uucp/libuuconf/lckdir.c b/gnu/libexec/uucp/libuuconf/lckdir.c
new file mode 100644
index 00000000000..52d1a9fc733
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/lckdir.c
@@ -0,0 +1,43 @@
+/* lckdir.c
+ Get the name of the UUCP lock directory.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_lckdir_rcsid[] = "$Id: lckdir.c,v 1.1 1993/08/04 19:34:39 jtc Exp $";
+#endif
+
+/* Get the name of the UUCP lock directory. */
+
+int
+uuconf_lockdir (pglobal, pzlock)
+ pointer pglobal;
+ const char **pzlock;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pzlock = qglobal->qprocess->zlockdir;
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/lineno.c b/gnu/libexec/uucp/libuuconf/lineno.c
new file mode 100644
index 00000000000..77839f6ede4
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/lineno.c
@@ -0,0 +1,44 @@
+/* lineno.c
+ Return the saved line number.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_lineno_rcsid[] = "$Id: lineno.c,v 1.1 1993/08/04 19:34:41 jtc Exp $";
+#endif
+
+/* Return the saved line number. */
+
+int
+uuconf_error_lineno (pglobal)
+ pointer pglobal;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ if (qglobal == NULL)
+ return 0;
+ else
+ return qglobal->ilineno;
+}
diff --git a/gnu/libexec/uucp/libuuconf/llocnm.c b/gnu/libexec/uucp/libuuconf/llocnm.c
new file mode 100644
index 00000000000..272d6237e97
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/llocnm.c
@@ -0,0 +1,70 @@
+/* llocnm.c
+ Get the local name to use, given a login name.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_llocnm_rcsid[] = "$Id: llocnm.c,v 1.1 1993/08/04 19:34:43 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Get the local name to use, given a login name. */
+
+int
+uuconf_login_localname (pglobal, zlogin, pzname)
+ pointer pglobal;
+ const char *zlogin;
+ char **pzname;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+
+#if HAVE_TAYLOR_CONFIG
+ iret = uuconf_taylor_login_localname (pglobal, zlogin, pzname);
+ if (iret != UUCONF_NOT_FOUND)
+ return iret;
+#endif
+
+#if HAVE_HDB_CONFIG
+ iret = uuconf_hdb_login_localname (pglobal, zlogin, pzname);
+ if (iret != UUCONF_NOT_FOUND)
+ return iret;
+#endif
+
+ if (qglobal->qprocess->zlocalname != NULL)
+ {
+ *pzname = strdup ((char *) qglobal->qprocess->zlocalname);
+ if (*pzname == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ return UUCONF_SUCCESS;
+ }
+
+ *pzname = NULL;
+ return UUCONF_NOT_FOUND;
+}
diff --git a/gnu/libexec/uucp/libuuconf/local.c b/gnu/libexec/uucp/libuuconf/local.c
new file mode 100644
index 00000000000..33adda40b0c
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/local.c
@@ -0,0 +1,70 @@
+/* local.c
+ Get default information for the local system.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_local_rcsid[] = "$Id: local.c,v 1.1 1993/08/04 19:34:45 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Get default information about the local system. */
+
+int
+uuconf_system_local (pglobal, qsys)
+ pointer pglobal;
+ struct uuconf_system *qsys;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+
+ _uuconf_uclear_system (qsys);
+ qsys->uuconf_palloc = uuconf_malloc_block ();
+ if (qsys->uuconf_palloc == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ qsys->uuconf_zname = (char *) qglobal->qprocess->zlocalname;
+
+ /* By default, we permit the local system to forward to and from any
+ system. */
+ iret = _uuconf_iadd_string (qglobal, (char *) "ANY", FALSE, FALSE,
+ &qsys->uuconf_pzforward_from,
+ qsys->uuconf_palloc);
+ if (iret == UUCONF_SUCCESS)
+ iret = _uuconf_iadd_string (qglobal, (char *) "ANY", FALSE, FALSE,
+ &qsys->uuconf_pzforward_to,
+ qsys->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ {
+ uuconf_free_block (qsys->uuconf_palloc);
+ return iret;
+ }
+
+ return _uuconf_isystem_basic_default (qglobal, qsys);
+}
diff --git a/gnu/libexec/uucp/libuuconf/locnm.c b/gnu/libexec/uucp/libuuconf/locnm.c
new file mode 100644
index 00000000000..1bc165b73f9
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/locnm.c
@@ -0,0 +1,46 @@
+/* locnm.c
+ Get the local node name.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_locnm_rcsid[] = "$Id: locnm.c,v 1.1 1993/08/04 19:34:47 jtc Exp $";
+#endif
+
+/* Get the local node name. */
+
+int
+uuconf_localname (pglobal, pzname)
+ pointer pglobal;
+ const char **pzname;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pzname = qglobal->qprocess->zlocalname;
+ if (*pzname != NULL)
+ return UUCONF_SUCCESS;
+ else
+ return UUCONF_NOT_FOUND;
+}
diff --git a/gnu/libexec/uucp/libuuconf/logfil.c b/gnu/libexec/uucp/libuuconf/logfil.c
new file mode 100644
index 00000000000..6d76764faa9
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/logfil.c
@@ -0,0 +1,43 @@
+/* logfil.c
+ Get the name of the UUCP log file.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_logfil_rcsid[] = "$Id: logfil.c,v 1.1 1993/08/04 19:34:48 jtc Exp $";
+#endif
+
+/* Get the name of the UUCP log file. */
+
+int
+uuconf_logfile (pglobal, pzlog)
+ pointer pglobal;
+ const char **pzlog;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pzlog = qglobal->qprocess->zlogfile;
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/maxuxq.c b/gnu/libexec/uucp/libuuconf/maxuxq.c
new file mode 100644
index 00000000000..8b5e9e7064b
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/maxuxq.c
@@ -0,0 +1,86 @@
+/* maxuxq.c
+ Get the maximum number of simultaneous uuxqt executions.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_maxuxq_rcsid[] = "$Id: maxuxq.c,v 1.1 1993/08/04 19:34:49 jtc Exp $";
+#endif
+
+/* Get the maximum number of simultaneous uuxqt executions. When
+ using TAYLOR_CONFIG, this is from the ``max-uuxqts'' command in
+ config. Otherwise, when using HDB_CONFIG, we read the file
+ Maxuuxqts. */
+
+int
+uuconf_maxuuxqts (pglobal, pcmax)
+ pointer pglobal;
+ int *pcmax;
+{
+#if HAVE_TAYLOR_CONFIG
+ {
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pcmax = qglobal->qprocess->cmaxuuxqts;
+ return UUCONF_SUCCESS;
+ }
+#else /* ! HAVE_TAYLOR_CONFIG */
+#if HAVE_HDB_CONFIG
+ {
+ char ab[sizeof OLDCONFIGLIB + sizeof HDB_MAXUUXQTS - 1];
+ FILE *e;
+
+ *pcmax = 0;
+
+ memcpy ((pointer) ab, (constpointer) OLDCONFIGLIB,
+ sizeof OLDCONFIGLIB - 1);
+ memcpy ((pointer) (ab + sizeof OLDCONFIGLIB - 1),
+ (constpointer) HDB_MAXUUXQTS, sizeof HDB_MAXUUXQTS);
+ e = fopen (ab, "r");
+ if (e != NULL)
+ {
+ char *z;
+ size_t c;
+
+ z = NULL;
+ c = 0;
+ if (getline (&z, &c, e) > 0)
+ {
+ *pcmax = (int) strtol (z, (char **) NULL, 10);
+ if (*pcmax < 0)
+ *pcmax = 0;
+ free ((pointer) z);
+ }
+ (void) fclose (e);
+ }
+
+ return UUCONF_SUCCESS;
+ }
+#else /* ! HAVE_HDB_CONFIG */
+ *pcmax = 0;
+ return UUCONF_SUCCESS;
+#endif /* ! HAVE_HDB_CONFIG */
+#endif /* ! HAVE_TAYLOR_CONFIG */
+}
diff --git a/gnu/libexec/uucp/libuuconf/mrgblk.c b/gnu/libexec/uucp/libuuconf/mrgblk.c
new file mode 100644
index 00000000000..4b2ea1c5744
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/mrgblk.c
@@ -0,0 +1,50 @@
+/* mrgblk.c
+ Merge two memory blocks together.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_mrgblk_rcsid[] = "$Id: mrgblk.c,v 1.1 1993/08/04 19:34:50 jtc Exp $";
+#endif
+
+#include "alloc.h"
+
+/* Merge one memory block into another one, returning the combined
+ memory block. */
+
+pointer
+_uuconf_pmalloc_block_merge (p1, p2)
+ pointer p1;
+ pointer p2;
+{
+ struct sblock *q1 = (struct sblock *) p1;
+ struct sblock *q2 = (struct sblock *) p2;
+ struct sblock **pq;
+
+ for (pq = &q1; *pq != NULL; pq = &(*pq)->qnext)
+ ;
+ *pq = q2;
+ return (pointer) q1;
+}
diff --git a/gnu/libexec/uucp/libuuconf/paramc.c b/gnu/libexec/uucp/libuuconf/paramc.c
new file mode 100644
index 00000000000..bcc9a0be7b2
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/paramc.c
@@ -0,0 +1,175 @@
+/* paramc.c
+ Handle protocol-parameter commands.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_paramc_rcsid[] = "$Id: paramc.c,v 1.1 1993/08/04 19:34:51 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Handle protocol-parameter commands by inserting them into an array
+ of structures. The return value may include UUCONF_CMDTABRET_KEEP
+ and UUCONF_CMDTABRET_EXIT, if appropriate. */
+
+int
+_uuconf_iadd_proto_param (qglobal, argc, argv, pqparam, pblock)
+ struct sglobal *qglobal;
+ int argc;
+ char **argv;
+ struct uuconf_proto_param **pqparam;
+ pointer pblock;
+{
+ struct uuconf_proto_param *q;
+ size_t c;
+ struct uuconf_proto_param_entry *qentry;
+
+ if (argc < 2)
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ /* The first argument is the protocol character. */
+ if (argv[0][1] != '\0')
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ if (*pqparam == NULL)
+ {
+ *pqparam = ((struct uuconf_proto_param *)
+ uuconf_malloc (pblock,
+ 2 * sizeof (struct uuconf_proto_param)));
+ if (*pqparam == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+ (*pqparam)[1].uuconf_bproto = '\0';
+ q = *pqparam;
+ q->uuconf_bproto = argv[0][0];
+ q->uuconf_qentries = NULL;
+ }
+ else
+ {
+ c = 0;
+ for (q = *pqparam; q->uuconf_bproto != '\0'; q++)
+ {
+ if (q->uuconf_bproto == argv[0][0])
+ break;
+ ++c;
+ }
+
+ if (q->uuconf_bproto == '\0')
+ {
+ struct uuconf_proto_param *qnew;
+
+ qnew = ((struct uuconf_proto_param *)
+ uuconf_malloc (pblock,
+ ((c + 2)
+ * sizeof (struct uuconf_proto_param))));
+ if (qnew == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ memcpy ((pointer) qnew, (pointer) *pqparam,
+ c * sizeof (struct uuconf_proto_param));
+ qnew[c + 1].uuconf_bproto = '\0';
+
+ uuconf_free (pblock, *pqparam);
+ *pqparam = qnew;
+
+ q = qnew + c;
+ q->uuconf_bproto = argv[0][0];
+ q->uuconf_qentries = NULL;
+ }
+ }
+
+ if (q->uuconf_qentries == NULL)
+ {
+ qentry = ((struct uuconf_proto_param_entry *)
+ uuconf_malloc (pblock,
+ 2 * sizeof (struct uuconf_proto_param_entry)));
+ if (qentry == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ qentry[1].uuconf_cargs = 0;
+ q->uuconf_qentries = qentry;
+ }
+ else
+ {
+ struct uuconf_proto_param_entry *qnewent;
+
+ c = 0;
+ for (qentry = q->uuconf_qentries; qentry->uuconf_cargs != 0; qentry++)
+ ++c;
+
+ qnewent = ((struct uuconf_proto_param_entry *)
+ uuconf_malloc (pblock,
+ ((c + 2) *
+ sizeof (struct uuconf_proto_param_entry))));
+ if (qnewent == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ memcpy ((pointer) qnewent, (pointer) q->uuconf_qentries,
+ c * sizeof (struct uuconf_proto_param_entry));
+ qnewent[c + 1].uuconf_cargs = 0;
+
+ uuconf_free (pblock, q->uuconf_qentries);
+ q->uuconf_qentries = qnewent;
+
+ qentry = qnewent + c;
+ }
+
+ qentry->uuconf_cargs = argc - 1;
+ qentry->uuconf_pzargs = (char **) uuconf_malloc (pblock,
+ ((argc - 1)
+ * sizeof (char *)));
+ if (qentry->uuconf_pzargs == NULL)
+ {
+ qglobal->ierrno = errno;
+ qentry->uuconf_cargs = 0;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+ memcpy ((pointer) qentry->uuconf_pzargs, (pointer) (argv + 1),
+ (argc - 1) * sizeof (char *));
+
+ return UUCONF_CMDTABRET_KEEP;
+}
diff --git a/gnu/libexec/uucp/libuuconf/port.c b/gnu/libexec/uucp/libuuconf/port.c
new file mode 100644
index 00000000000..586c2269442
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/port.c
@@ -0,0 +1,77 @@
+/* port.c
+ Find a port.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_port_rcsid[] = "$Id: port.c,v 1.1 1993/08/04 19:34:52 jtc Exp $";
+#endif
+
+/* Find a port by name, baud rate, and special purpose function. */
+
+int
+uuconf_find_port (pglobal, zname, ibaud, ihighbaud, pifn, pinfo, qport)
+ pointer pglobal;
+ const char *zname;
+ long ibaud;
+ long ihighbaud;
+ int (*pifn) P((struct uuconf_port *, pointer));
+ pointer pinfo;
+ struct uuconf_port *qport;
+{
+#if HAVE_V2_CONFIG || HAVE_HDB_CONFIG
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+#endif
+ int iret;
+
+#if HAVE_TAYLOR_CONFIG
+ iret = uuconf_taylor_find_port (pglobal, zname, ibaud, ihighbaud, pifn,
+ pinfo, qport);
+ if (iret != UUCONF_NOT_FOUND)
+ return iret;
+#endif
+
+#if HAVE_V2_CONFIG
+ if (qglobal->qprocess->fv2)
+ {
+ iret = uuconf_v2_find_port (pglobal, zname, ibaud, ihighbaud, pifn,
+ pinfo, qport);
+ if (iret != UUCONF_NOT_FOUND)
+ return iret;
+ }
+#endif
+
+#if HAVE_HDB_CONFIG
+ if (qglobal->qprocess->fhdb)
+ {
+ iret = uuconf_hdb_find_port (pglobal, zname, ibaud, ihighbaud, pifn,
+ pinfo, qport);
+ if (iret != UUCONF_NOT_FOUND)
+ return iret;
+ }
+#endif
+
+ return UUCONF_NOT_FOUND;
+}
diff --git a/gnu/libexec/uucp/libuuconf/prtsub.c b/gnu/libexec/uucp/libuuconf/prtsub.c
new file mode 100644
index 00000000000..682f38e6873
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/prtsub.c
@@ -0,0 +1,54 @@
+/* prtsub.c
+ Port information subroutines.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_prtsub_rcsid[] = "$Id: prtsub.c,v 1.1 1993/08/04 19:34:53 jtc Exp $";
+#endif
+
+/* Clear the information in a port. This can only clear the type
+ independent information; the port type specific information is
+ cleared when the type of the port is set. */
+
+void
+_uuconf_uclear_port (qport)
+ struct uuconf_port *qport;
+{
+ qport->uuconf_zname = NULL;
+ qport->uuconf_ttype = UUCONF_PORTTYPE_UNKNOWN;
+ qport->uuconf_zprotocols = NULL;
+ qport->uuconf_qproto_params = NULL;
+
+ /* Note that we do not set RELIABLE_SPECIFIED; this just sets
+ defaults, so that ``seven-bit true'' does not imply ``reliable
+ false''. */
+ qport->uuconf_ireliable = (UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT
+ | UUCONF_RELIABLE_FULLDUPLEX);
+
+ qport->uuconf_zlockname = NULL;
+ qport->uuconf_palloc = NULL;
+}
diff --git a/gnu/libexec/uucp/libuuconf/pubdir.c b/gnu/libexec/uucp/libuuconf/pubdir.c
new file mode 100644
index 00000000000..0c4714d466f
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/pubdir.c
@@ -0,0 +1,43 @@
+/* pubdir.c
+ Get the name of the UUCP public directory.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_pubdir_rcsid[] = "$Id: pubdir.c,v 1.1 1993/08/04 19:34:54 jtc Exp $";
+#endif
+
+/* Get the name of the UUCP public directory. */
+
+int
+uuconf_pubdir (pglobal, pzpub)
+ pointer pglobal;
+ const char **pzpub;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pzpub = qglobal->qprocess->zpubdir;
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/rdlocs.c b/gnu/libexec/uucp/libuuconf/rdlocs.c
new file mode 100644
index 00000000000..ba8365fd7bf
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/rdlocs.c
@@ -0,0 +1,305 @@
+/* rdlocs.c
+ Get the locations of systems in the Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_rdlocs_rcsid[] = "$Id: rdlocs.c,v 1.1 1993/08/04 19:34:55 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+static int itsystem P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int itcalled_login P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int itmyname P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+
+/* This code scans through the Taylor UUCP system files in order to
+ locate each system and to gather the login restrictions (since this
+ information is held in additional arguments to the "called-login"
+ command, it can appear anywhere in the systems files). It also
+ records whether any "myname" appears, as an optimization for
+ uuconf_taylor_localname.
+
+ This table is used to dispatch the appropriate commands. Most
+ commands are simply ignored. Note that this is a uuconf_cmdtab,
+ not a cmdtab_offset. */
+
+static const struct uuconf_cmdtab asTcmds[] =
+{
+ { "system", UUCONF_CMDTABTYPE_FN | 2, NULL, itsystem },
+ { "alias", UUCONF_CMDTABTYPE_FN | 2, (pointer) asTcmds, itsystem },
+ { "called-login", UUCONF_CMDTABTYPE_FN | 0, NULL, itcalled_login },
+ { "myname", UUCONF_CMDTABTYPE_FN | 2, NULL, itmyname },
+ { NULL, 0, NULL, NULL }
+};
+
+/* This structure is used to pass information into the command table
+ functions. */
+
+struct sinfo
+{
+ /* The sys file name. */
+ const char *zname;
+ /* The open sys file. */
+ FILE *e;
+ /* The list of locations we are building. */
+ struct stsysloc *qlocs;
+ /* The list of validation restrictions we are building. */
+ struct svalidate *qvals;
+};
+
+/* Look through the sys files to find the location and names of all
+ the systems. Since we're scanning the sys files, we also record
+ the validation information specified by the additional arguments to
+ the called-login command. We don't use uuconf_cmd_file to avoid
+ the overhead of breaking the line up into arguments if not
+ necessary. */
+
+int
+_uuconf_iread_locations (qglobal)
+ struct sglobal *qglobal;
+{
+ char *zline;
+ size_t cline;
+ struct sinfo si;
+ int iret;
+ char **pz;
+
+ if (qglobal->qprocess->fread_syslocs)
+ return UUCONF_SUCCESS;
+
+ zline = NULL;
+ cline = 0;
+
+ si.qlocs = NULL;
+ si.qvals = NULL;
+
+ iret = UUCONF_SUCCESS;
+
+ for (pz = qglobal->qprocess->pzsysfiles; *pz != NULL; pz++)
+ {
+ FILE *e;
+ int cchars;
+
+ qglobal->ilineno = 0;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+#ifdef CLOSE_ON_EXEC
+ CLOSE_ON_EXEC (e);
+#endif
+
+ si.zname = *pz;
+ si.e = e;
+
+ while ((cchars = _uuconf_getline (qglobal, &zline, &cline, e)) > 0)
+ {
+ char *zcmd;
+
+ ++qglobal->ilineno;
+
+ zcmd = zline + strspn (zline, " \t");
+ if (strncasecmp (zcmd, "system", sizeof "system" - 1) == 0
+ || strncasecmp (zcmd, "alias", sizeof "alias" - 1) == 0
+ || strncasecmp (zcmd, "called-login",
+ sizeof "called-login" - 1) == 0
+ || strncasecmp (zcmd, "myname", sizeof "myname" - 1) == 0)
+ {
+ iret = uuconf_cmd_line ((pointer) qglobal, zline, asTcmds,
+ (pointer) &si, (uuconf_cmdtabfn) NULL,
+ 0, qglobal->pblock);
+ if ((iret & UUCONF_CMDTABRET_KEEP) != 0)
+ {
+ iret &=~ UUCONF_CMDTABRET_KEEP;
+ zline = NULL;
+ cline = 0;
+ }
+ if (iret != UUCONF_SUCCESS)
+ {
+ iret &=~ UUCONF_CMDTABRET_EXIT;
+ break;
+ }
+ }
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+
+ if (zline != NULL)
+ free ((pointer) zline);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = *pz;
+ iret |= UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ if (UUCONF_ERROR_VALUE (iret) != UUCONF_MALLOC_FAILED)
+ qglobal->qprocess->fread_syslocs = TRUE;
+ }
+ else
+ {
+ qglobal->qprocess->qsyslocs = si.qlocs;
+ qglobal->qprocess->qvalidate = si.qvals;
+ qglobal->qprocess->fread_syslocs = TRUE;
+ }
+
+ return iret;
+}
+
+/* Handle a "system" or "alias" command by recording the file and
+ location. If pvar is not NULL, this is an "alias" command. */
+
+/*ARGSUSED*/
+static int
+itsystem (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+ struct stsysloc *q;
+ size_t csize;
+
+ q = (struct stsysloc *) uuconf_malloc (qglobal->pblock,
+ sizeof (struct stsysloc));
+ if (q == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ csize = strlen (argv[1]) + 1;
+ q->zname = uuconf_malloc (qglobal->pblock, csize);
+ if (q->zname == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ q->qnext = qinfo->qlocs;
+ memcpy ((pointer) q->zname, (pointer) argv[1], csize);
+ q->falias = pvar != NULL;
+ q->zfile = qinfo->zname;
+ q->e = qinfo->e;
+ q->iloc = ftell (qinfo->e);
+ q->ilineno = qglobal->ilineno;
+
+ qinfo->qlocs = q;
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Handle the "called-login" command. This just records any extra
+ arguments, so that uuconf_validate can check them later if
+ necessary. */
+
+/*ARGSUSED*/
+static int
+itcalled_login (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+ register struct svalidate *qval;
+ int i;
+
+ if (argc <= 2)
+ return UUCONF_CMDTABRET_CONTINUE;
+
+ for (qval = qinfo->qvals; qval != NULL; qval = qval->qnext)
+ if (strcmp (argv[1], qval->zlogname) == 0)
+ break;
+
+ if (qval == NULL)
+ {
+ qval = (struct svalidate *) uuconf_malloc (qglobal->pblock,
+ sizeof (struct svalidate));
+ if (qval == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ qval->qnext = qinfo->qvals;
+ qval->zlogname = argv[1];
+ qval->pzmachines = NULL;
+
+ qinfo->qvals = qval;
+ }
+
+ for (i = 2; i < argc; i++)
+ {
+ int iret;
+
+ iret = _uuconf_iadd_string (qglobal, argv[i], FALSE, TRUE,
+ &qval->pzmachines, qglobal->pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret | UUCONF_CMDTABRET_EXIT;
+ }
+
+ return UUCONF_CMDTABRET_KEEP;
+}
+
+/* Handle the "myname" command by simply recording that it appears.
+ This information is used by uuconf_taylor_localname. */
+
+/*ARGSUSED*/
+static int
+itmyname (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ qglobal->qprocess->fuses_myname = TRUE;
+ return UUCONF_CMDTABRET_CONTINUE;
+}
diff --git a/gnu/libexec/uucp/libuuconf/rdperm.c b/gnu/libexec/uucp/libuuconf/rdperm.c
new file mode 100644
index 00000000000..dd481c1a8e5
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/rdperm.c
@@ -0,0 +1,446 @@
+/* rdperm.c
+ Read the HDB Permissions file.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_rdperm_rcsid[] = "$Id: rdperm.c,v 1.1 1993/08/04 19:34:57 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+static int ihcolon P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int ihsendfiles P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int ihunknownperm P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int ihadd_norw P((struct sglobal *qglobal, char ***ppz, char **pzno));
+
+/* These routines reads in the HDB Permissions file. We store the
+ entries in a linked list of shpermissions structures, so we only
+ have to actually read the file once. */
+
+/* This command table and static structure are used to parse a line
+ from Permissions. The entries are parsed as follows:
+
+ Multiple strings separated by colons: LOGNAME, MACHINE, READ,
+ WRITE, NOREAD, NOWRITE, COMMANDS, VALIDATE, ALIAS.
+
+ Boolean values: REQUEST, CALLBACK.
+
+ Simple strings: MYNAME, PUBDIR.
+
+ "Yes" or "call": SENDFILES.
+
+ The NOREAD and NOWRITE entries are merged into the READ and WRITE
+ entries, rather than being permanently stored. They are handled
+ specially in the uuconf_cmdtab table. */
+
+static const struct cmdtab_offset asHperm_cmds[] =
+{
+ { "NOREAD", UUCONF_CMDTABTYPE_FN | 2, (size_t) -1, ihcolon },
+ { "NOWRITE", UUCONF_CMDTABTYPE_FN | 2, (size_t) -1, ihcolon },
+ { "LOGNAME", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct shpermissions, pzlogname), ihcolon },
+ { "MACHINE", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct shpermissions, pzmachine), ihcolon },
+ { "REQUEST", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct shpermissions, frequest), NULL },
+ { "SENDFILES", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct shpermissions, fsendfiles), ihsendfiles },
+ { "READ", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct shpermissions, pzread), ihcolon },
+ { "WRITE", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct shpermissions, pzwrite), ihcolon },
+ { "CALLBACK", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct shpermissions, fcallback), NULL },
+ { "COMMANDS", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct shpermissions, pzcommands), ihcolon },
+ { "VALIDATE", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct shpermissions, pzvalidate), ihcolon },
+ { "MYNAME", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct shpermissions, zmyname), NULL },
+ { "PUBDIR", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct shpermissions, zpubdir), NULL },
+ { "ALIAS", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct shpermissions, pzalias), ihcolon },
+ { NULL, 0, 0, NULL }
+};
+
+#define CHPERM_CMDS (sizeof asHperm_cmds / sizeof asHperm_cmds[0])
+
+/* Actually read the Permissions file into a linked list of
+ structures. */
+
+int
+_uuconf_ihread_permissions (qglobal)
+ struct sglobal *qglobal;
+{
+ char *zperm;
+ FILE *e;
+ int iret;
+ struct uuconf_cmdtab as[CHPERM_CMDS];
+ char **pznoread, **pznowrite;
+ struct shpermissions shperm;
+ char *zline;
+ size_t cline;
+ char **pzsplit;
+ size_t csplit;
+ int cchars;
+ struct shpermissions *qlist, **pq;
+
+ if (qglobal->qprocess->fhdb_read_permissions)
+ return UUCONF_SUCCESS;
+
+ zperm = (char *) uuconf_malloc (qglobal->pblock,
+ (sizeof OLDCONFIGLIB
+ + sizeof HDB_PERMISSIONS - 1));
+ if (zperm == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ memcpy ((pointer) zperm, (pointer) OLDCONFIGLIB,
+ sizeof OLDCONFIGLIB - 1);
+ memcpy ((pointer) (zperm + sizeof OLDCONFIGLIB - 1),
+ (pointer) HDB_PERMISSIONS, sizeof HDB_PERMISSIONS);
+
+ e = fopen (zperm, "r");
+ if (e == NULL)
+ {
+ uuconf_free (qglobal->pblock, zperm);
+ qglobal->qprocess->fhdb_read_permissions = TRUE;
+ return UUCONF_SUCCESS;
+ }
+
+ _uuconf_ucmdtab_base (asHperm_cmds, CHPERM_CMDS, (char *) &shperm, as);
+ as[0].uuconf_pvar = (pointer) &pznoread;
+ as[1].uuconf_pvar = (pointer) &pznowrite;
+
+ zline = NULL;
+ cline = 0;
+ pzsplit = NULL;
+ csplit = 0;
+
+ qlist = NULL;
+ pq = &qlist;
+
+ qglobal->ilineno = 0;
+
+ iret = UUCONF_SUCCESS;
+
+ while ((cchars = _uuconf_getline (qglobal, &zline, &cline, e)) > 0)
+ {
+ int centries;
+ struct shpermissions *qnew;
+ int i;
+
+ ++qglobal->ilineno;
+
+ --cchars;
+ if (zline[cchars] == '\n')
+ zline[cchars] = '\0';
+ if (isspace (BUCHAR (zline[0])) || zline[0] == '#')
+ continue;
+
+ centries = _uuconf_istrsplit (zline, '\0', &pzsplit, &csplit);
+ if (centries < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ if (centries == 0)
+ continue;
+
+ shperm.pzlogname = (char **) &_uuconf_unset;
+ shperm.pzmachine = (char **) &_uuconf_unset;
+ shperm.frequest = -1;
+ shperm.fsendfiles = -1;
+ shperm.pzread = (char **) &_uuconf_unset;
+ shperm.pzwrite = (char **) &_uuconf_unset;
+ shperm.fcallback = -1;
+ shperm.pzcommands = (char **) &_uuconf_unset;
+ shperm.pzvalidate = (char **) &_uuconf_unset;
+ shperm.zmyname = (char *) &_uuconf_unset;
+ shperm.zpubdir = (char *) &_uuconf_unset;
+ shperm.pzalias = (char **) &_uuconf_unset;
+ pznoread = (char **) &_uuconf_unset;
+ pznowrite = (char **) &_uuconf_unset;
+
+ for (i = 0; i < centries; i++)
+ {
+ char *zeq;
+ char *azargs[2];
+
+ zeq = strchr (pzsplit[i], '=');
+ if (zeq == NULL)
+ {
+ iret = UUCONF_SYNTAX_ERROR;
+ qglobal->qprocess->fhdb_read_permissions = TRUE;
+ break;
+ }
+ *zeq = '\0';
+
+ azargs[0] = pzsplit[i];
+ azargs[1] = zeq + 1;
+
+ iret = uuconf_cmd_args (qglobal, 2, azargs, as, (pointer) NULL,
+ ihunknownperm, 0, qglobal->pblock);
+ if ((iret & UUCONF_CMDTABRET_KEEP) != 0)
+ {
+ iret &=~ UUCONF_CMDTABRET_KEEP;
+
+ if (uuconf_add_block (qglobal->pblock, zline) != 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ zline = NULL;
+ cline = 0;
+ }
+ if ((iret & UUCONF_CMDTABRET_EXIT) != 0)
+ {
+ iret &=~ UUCONF_CMDTABRET_EXIT;
+ break;
+ }
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ break;
+
+ if (shperm.pzmachine == (char **) &_uuconf_unset
+ && shperm.pzlogname == (char **) &_uuconf_unset)
+ {
+ iret = UUCONF_SYNTAX_ERROR;
+ qglobal->qprocess->fhdb_read_permissions = TRUE;
+ break;
+ }
+
+ /* Attach any NOREAD or NOWRITE entries to the corresponding
+ READ or WRITE entries in the format expected for the
+ pzlocal_receive, etc., fields in uuconf_system. */
+ if (pznoread != NULL)
+ {
+ iret = ihadd_norw (qglobal, &shperm.pzread, pznoread);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ uuconf_free (qglobal->pblock, pznoread);
+ }
+
+ if (pznowrite != NULL)
+ {
+ iret = ihadd_norw (qglobal, &shperm.pzwrite, pznowrite);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ uuconf_free (qglobal->pblock, pznowrite);
+ }
+
+ qnew = ((struct shpermissions *)
+ uuconf_malloc (qglobal->pblock,
+ sizeof (struct shpermissions)));
+ if (qnew == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ *qnew = shperm;
+ *pq = qnew;
+ pq = &qnew->qnext;
+ *pq = NULL;
+ }
+
+ (void) fclose (e);
+
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+
+ if (iret == UUCONF_SUCCESS)
+ {
+ qglobal->qprocess->qhdb_permissions = qlist;
+ qglobal->qprocess->fhdb_read_permissions = TRUE;
+ }
+ else
+ {
+ qglobal->zfilename = zperm;
+ iret |= UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ }
+
+ return iret;
+}
+
+/* Split the argument into colon separated strings, and assign a NULL
+ terminated array of strings to pvar. */
+
+/*ARGSUSED*/
+static int
+ihcolon (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char ***ppz = (char ***) pvar;
+ char **pzsplit;
+ size_t csplit;
+ int centries;
+ int i;
+ int iret;
+
+ *ppz = NULL;
+
+ pzsplit = NULL;
+ csplit = 0;
+
+ centries = _uuconf_istrsplit (argv[1], ':', &pzsplit, &csplit);
+ if (centries < 0)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ if (centries == 0)
+ {
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+ return UUCONF_CMDTABRET_CONTINUE;
+ }
+
+ iret = UUCONF_SUCCESS;
+
+ for (i = 0; i < centries; i++)
+ {
+ iret = _uuconf_iadd_string (qglobal, pzsplit[i], FALSE, FALSE,
+ ppz, qglobal->pblock);
+ if (iret != UUCONF_SUCCESS)
+ {
+ iret |= UUCONF_CMDTABRET_EXIT;
+ break;
+ }
+ }
+
+ free ((pointer) pzsplit);
+
+ return UUCONF_CMDTABRET_KEEP;
+}
+
+/* Handle the SENDFILES parameter, which can take "yes" or "call" or
+ "no" as an argument. The string "call" is equivalent to "no". */
+
+/*ARGSUSED*/
+static int
+ihsendfiles (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ int *pi = (int *) pvar;
+
+ switch (argv[1][0])
+ {
+ case 'C':
+ case 'c':
+ case 'N':
+ case 'n':
+ *pi = FALSE;
+ break;
+ case 'Y':
+ case 'y':
+ *pi = TRUE;
+ break;
+ default:
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+ }
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* If there is an unknown Permissions entry, return a syntax error.
+ This should probably be more clever. */
+
+/*ARGSUSED*/
+static int
+ihunknownperm (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+}
+
+/* Add a NOREAD or NOWRITE entry to a READ or WRITE entry. */
+
+static int
+ihadd_norw (qglobal, ppz, pzno)
+ struct sglobal *qglobal;
+ char ***ppz;
+ char **pzno;
+{
+ register char **pz;
+
+ if (pzno == (char **) &_uuconf_unset)
+ return UUCONF_SUCCESS;
+
+ for (pz = pzno; *pz != NULL; pz++)
+ {
+ size_t csize;
+ char *znew;
+ int iret;
+
+ csize = strlen (*pz) + 1;
+ znew = (char *) uuconf_malloc (qglobal->pblock, csize + 1);
+ if (znew == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ znew[0] = '!';
+ memcpy ((pointer) (znew + 1), (pointer) *pz, csize);
+ iret = _uuconf_iadd_string (qglobal, znew, FALSE, FALSE, ppz,
+ qglobal->pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/reliab.c b/gnu/libexec/uucp/libuuconf/reliab.c
new file mode 100644
index 00000000000..13517d49f34
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/reliab.c
@@ -0,0 +1,123 @@
+/* reliab.c
+ Subroutines to handle reliability commands for ports and dialers.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_reliab_rcsid[] = "$Id: reliab.c,v 1.1 1993/08/04 19:34:58 jtc Exp $";
+#endif
+
+/* Handle the "seven-bit" command for a port or a dialer. The pvar
+ argument points to an integer which should be set to hold
+ reliability information. */
+
+/*ARGSUSED*/
+int
+_uuconf_iseven_bit (pglobal,argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int *pi = (int *) pvar;
+ int fval;
+ int iret;
+
+ iret = _uuconf_iboolean (qglobal, argv[1], &fval);
+ if ((iret &~ UUCONF_CMDTABRET_KEEP) != UUCONF_SUCCESS)
+ return iret;
+
+ *pi |= UUCONF_RELIABLE_SPECIFIED;
+ if (fval)
+ *pi &=~ UUCONF_RELIABLE_EIGHT;
+ else
+ *pi |= UUCONF_RELIABLE_EIGHT;
+
+ return iret;
+}
+
+/* Handle the "reliable" command for a port or a dialer. The pvar
+ argument points to an integer which should be set to hold
+ reliability information. */
+
+/*ARGSUSED*/
+int
+_uuconf_ireliable (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int *pi = (int *) pvar;
+ int fval;
+ int iret;
+
+ iret = _uuconf_iboolean (qglobal, argv[1], &fval);
+ if ((iret &~ UUCONF_CMDTABRET_KEEP) != UUCONF_SUCCESS)
+ return iret;
+
+ *pi |= UUCONF_RELIABLE_SPECIFIED;
+ if (fval)
+ *pi |= UUCONF_RELIABLE_RELIABLE;
+ else
+ *pi &=~ UUCONF_RELIABLE_RELIABLE;
+
+ return iret;
+}
+
+/* Handle the "half-duplex" command for a port or a dialer. The pvar
+ argument points to an integer which should be set to hold
+ reliability information. */
+
+/*ARGSUSED*/
+int
+_uuconf_ihalf_duplex (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int *pi = (int *) pvar;
+ int fval;
+ int iret;
+
+ iret = _uuconf_iboolean (qglobal, argv[1], &fval);
+ if ((iret &~ UUCONF_CMDTABRET_KEEP) != UUCONF_SUCCESS)
+ return iret;
+
+ *pi |= UUCONF_RELIABLE_SPECIFIED;
+ if (fval)
+ *pi &=~ UUCONF_RELIABLE_FULLDUPLEX;
+ else
+ *pi |= UUCONF_RELIABLE_FULLDUPLEX;
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/remunk.c b/gnu/libexec/uucp/libuuconf/remunk.c
new file mode 100644
index 00000000000..85297b0212f
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/remunk.c
@@ -0,0 +1,45 @@
+/* remunk.c
+ Get the name of the remote.unknown shell script.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_remunk_rcsid[] = "$Id: remunk.c,v 1.1 1993/08/04 19:34:59 jtc Exp $";
+#endif
+
+/* Get the name of the remote.unknown shell script. */
+
+/*ARGSUSED*/
+int
+uuconf_remote_unknown (pglobal, pzname)
+ pointer pglobal;
+ char **pzname;
+{
+#if HAVE_TAYLOR_CONFIG || ! HAVE_HDB_CONFIG
+ return UUCONF_NOT_FOUND;
+#else
+ return uuconf_hdb_remote_unknown (pglobal, pzname);
+#endif
+}
diff --git a/gnu/libexec/uucp/libuuconf/sinfo.c b/gnu/libexec/uucp/libuuconf/sinfo.c
new file mode 100644
index 00000000000..f73851f84ab
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/sinfo.c
@@ -0,0 +1,112 @@
+/* sinfo.c
+ Get information about a system.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_sinfo_rcsid[] = "$Id: sinfo.c,v 1.1 1993/08/04 19:35:00 jtc Exp $";
+#endif
+
+/* Get information about a particular system. We combine the
+ definitions for this system from each type of configuration file,
+ by passing what we have so far into each one. */
+
+int
+uuconf_system_info (pglobal, zsystem, qsys)
+ pointer pglobal;
+ const char *zsystem;
+ struct uuconf_system *qsys;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+ boolean fgot;
+
+ fgot = FALSE;
+
+#if HAVE_TAYLOR_CONFIG
+ iret = _uuconf_itaylor_system_internal (qglobal, zsystem, qsys);
+ if (iret == UUCONF_SUCCESS)
+ fgot = TRUE;
+ else if (iret != UUCONF_NOT_FOUND)
+ return iret;
+#endif
+
+#if HAVE_V2_CONFIG
+ if (qglobal->qprocess->fv2)
+ {
+ struct uuconf_system *q;
+ struct uuconf_system sv2;
+
+ if (fgot)
+ q = &sv2;
+ else
+ q = qsys;
+ iret = _uuconf_iv2_system_internal (qglobal, zsystem, q);
+ if (iret == UUCONF_SUCCESS)
+ {
+ if (fgot)
+ {
+ iret = _uuconf_isystem_default (qglobal, qsys, &sv2, TRUE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ fgot = TRUE;
+ }
+ else if (iret != UUCONF_NOT_FOUND)
+ return iret;
+ }
+#endif
+
+#if HAVE_HDB_CONFIG
+ if (qglobal->qprocess->fhdb)
+ {
+ struct uuconf_system *q;
+ struct uuconf_system shdb;
+
+ if (fgot)
+ q = &shdb;
+ else
+ q = qsys;
+ iret = _uuconf_ihdb_system_internal (qglobal, zsystem, q);
+ if (iret == UUCONF_SUCCESS)
+ {
+ if (fgot)
+ {
+ iret = _uuconf_isystem_default (qglobal, qsys, &shdb, TRUE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ fgot = TRUE;
+ }
+ else if (iret != UUCONF_NOT_FOUND)
+ return iret;
+ }
+#endif
+
+ if (! fgot)
+ return UUCONF_NOT_FOUND;
+
+ return _uuconf_isystem_basic_default (qglobal, qsys);
+}
diff --git a/gnu/libexec/uucp/libuuconf/snams.c b/gnu/libexec/uucp/libuuconf/snams.c
new file mode 100644
index 00000000000..d239b10e083
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/snams.c
@@ -0,0 +1,133 @@
+/* snams.c
+ Get all known system names.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_snams_rcsid[] = "$Id: snams.c,v 1.1 1993/08/04 19:35:01 jtc Exp $";
+#endif
+
+/* Get all known system names. */
+
+int
+uuconf_system_names (pglobal, ppzsystems, falias)
+ pointer pglobal;
+ char ***ppzsystems;
+ int falias;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char **pztaylor;
+ char **pzv2;
+ char **pzhdb;
+ int iret;
+
+ *ppzsystems = NULL;
+ pztaylor = NULL;
+ pzv2 = NULL;
+ pzhdb = NULL;
+
+#if HAVE_TAYLOR_CONFIG
+ iret = uuconf_taylor_system_names (pglobal, &pztaylor, falias);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+#endif
+
+#if HAVE_V2_CONFIG
+ if (qglobal->qprocess->fv2)
+ {
+ iret = uuconf_v2_system_names (pglobal, &pzv2, falias);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+#endif
+
+#if HAVE_HDB_CONFIG
+ if (qglobal->qprocess->fhdb)
+ {
+ iret = uuconf_hdb_system_names (pglobal, &pzhdb, falias);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+#endif
+
+ if (pzv2 == NULL && pzhdb == NULL)
+ *ppzsystems = pztaylor;
+ else if (pztaylor == NULL && pzhdb == NULL)
+ *ppzsystems = pzv2;
+ else if (pztaylor == NULL && pzv2 == NULL)
+ *ppzsystems = pzhdb;
+ else
+ {
+ char **pz;
+
+ iret = UUCONF_SUCCESS;
+
+ if (pztaylor != NULL)
+ {
+ for (pz = pztaylor; *pz != NULL; pz++)
+ {
+ iret = _uuconf_iadd_string (qglobal, *pz, FALSE, TRUE,
+ ppzsystems, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+ }
+
+ if (pzv2 != NULL && iret == UUCONF_SUCCESS)
+ {
+ for (pz = pzv2; *pz != NULL; pz++)
+ {
+ iret = _uuconf_iadd_string (qglobal, *pz, FALSE, TRUE,
+ ppzsystems, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+ }
+
+ if (pzhdb != NULL && iret == UUCONF_SUCCESS)
+ {
+ for (pz = pzhdb; *pz != NULL; pz++)
+ {
+ iret = _uuconf_iadd_string (qglobal, *pz, FALSE, TRUE,
+ ppzsystems, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+ }
+
+ if (pztaylor != NULL)
+ free ((pointer) pztaylor);
+ if (pzv2 != NULL)
+ free ((pointer) pzv2);
+ if (pzhdb != NULL)
+ free ((pointer) pzhdb);
+ }
+
+ if (iret == UUCONF_SUCCESS && *ppzsystems == NULL)
+ iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
+ ppzsystems, (pointer) NULL);
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/split.c b/gnu/libexec/uucp/libuuconf/split.c
new file mode 100644
index 00000000000..76cc5e8d360
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/split.c
@@ -0,0 +1,106 @@
+/* split.c
+ Split a string into tokens.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_split_rcsid[] = "$Id: split.c,v 1.1 1993/08/04 19:35:02 jtc Exp $";
+#endif
+
+#include <ctype.h>
+
+/* Split a string into tokens. The bsep argument is the separator to
+ use. If it is the null byte, white space is used as the separator,
+ and leading white space is discarded. Otherwise, each occurrence
+ of the separator character delimits a field (and thus some fields
+ may be empty). The array and size arguments may be used to reuse
+ the same memory. This function is not tied to uuconf; the only way
+ it can fail is if malloc or realloc fails. */
+
+int
+_uuconf_istrsplit (zline, bsep, ppzsplit, pcsplit)
+ register char *zline;
+ int bsep;
+ char ***ppzsplit;
+ size_t *pcsplit;
+{
+ size_t i;
+
+ i = 0;
+
+ while (TRUE)
+ {
+ if (bsep == '\0')
+ {
+ while (isspace (BUCHAR (*zline)))
+ ++zline;
+ if (*zline == '\0')
+ break;
+ }
+
+ if (i >= *pcsplit)
+ {
+ char **pznew;
+ size_t cnew;
+
+ if (*pcsplit == 0)
+ {
+ cnew = 8;
+ pznew = (char **) malloc (cnew * sizeof (char *));
+ }
+ else
+ {
+ cnew = *pcsplit * 2;
+ pznew = (char **) realloc ((pointer) *ppzsplit,
+ cnew * sizeof (char *));
+ }
+ if (pznew == NULL)
+ return -1;
+ *ppzsplit = pznew;
+ *pcsplit = cnew;
+ }
+
+ (*ppzsplit)[i] = zline;
+ ++i;
+
+ if (bsep == '\0')
+ {
+ while (*zline != '\0' && ! isspace (BUCHAR (*zline)))
+ ++zline;
+ }
+ else
+ {
+ while (*zline != '\0' && *zline != bsep)
+ ++zline;
+ }
+
+ if (*zline == '\0')
+ break;
+
+ *zline++ = '\0';
+ }
+
+ return i;
+}
diff --git a/gnu/libexec/uucp/libuuconf/spool.c b/gnu/libexec/uucp/libuuconf/spool.c
new file mode 100644
index 00000000000..e9c13f072cb
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/spool.c
@@ -0,0 +1,43 @@
+/* spool.c
+ Get the name of the UUCP spool directory.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_spool_rcsid[] = "$Id: spool.c,v 1.1 1993/08/04 19:35:03 jtc Exp $";
+#endif
+
+/* Get the name of the UUCP spool directory. */
+
+int
+uuconf_spooldir (pglobal, pzspool)
+ pointer pglobal;
+ const char **pzspool;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pzspool = qglobal->qprocess->zspooldir;
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/stafil.c b/gnu/libexec/uucp/libuuconf/stafil.c
new file mode 100644
index 00000000000..bcea0bffd6c
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/stafil.c
@@ -0,0 +1,43 @@
+/* stafil.c
+ Get the name of the UUCP statistics file.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_stafil_rcsid[] = "$Id: stafil.c,v 1.1 1993/08/04 19:35:04 jtc Exp $";
+#endif
+
+/* Get the name of the UUCP statistics file. */
+
+int
+uuconf_statsfile (pglobal, pzstats)
+ pointer pglobal;
+ const char **pzstats;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ *pzstats = qglobal->qprocess->zstatsfile;
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/syshdr.h b/gnu/libexec/uucp/libuuconf/syshdr.h
new file mode 100644
index 00000000000..8ff18a6ca49
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/syshdr.h
@@ -0,0 +1,106 @@
+/* syshdr.unx -*- C -*-
+ Unix system header for the uuconf library.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+/* The root directory (used when setting local-send and local-receive
+ values). */
+#define ZROOTDIR "/"
+
+/* The current directory (used by uuconv as a prefix for the newly
+ created file names). */
+#define ZCURDIR "."
+
+/* The names of the Taylor UUCP configuration files. These are
+ appended to NEWCONFIGLIB which is defined in Makefile. */
+#define CONFIGFILE "/config"
+#define SYSFILE "/sys"
+#define PORTFILE "/port"
+#define DIALFILE "/dial"
+#define CALLFILE "/call"
+#define PASSWDFILE "/passwd"
+#define DIALCODEFILE "/dialcode"
+
+/* The names of the various V2 configuration files. These are
+ appended to OLDCONFIGLIB which is defined in Makefile. */
+#define V2_SYSTEMS "/L.sys"
+#define V2_DEVICES "/L-devices"
+#define V2_USERFILE "/USERFILE"
+#define V2_CMDS "/L.cmds"
+#define V2_DIALCODES "/L-dialcodes"
+
+/* The names of the HDB configuration files. These are appended to
+ OLDCONFIGLIB which is defined in Makefile. */
+#define HDB_SYSFILES "/Sysfiles"
+#define HDB_SYSTEMS "/Systems"
+#define HDB_PERMISSIONS "/Permissions"
+#define HDB_DEVICES "/Devices"
+#define HDB_DIALERS "/Dialers"
+#define HDB_DIALCODES "/Dialcodes"
+#define HDB_MAXUUXQTS "/Maxuuxqts"
+#define HDB_REMOTE_UNKNOWN "/remote.unknown"
+
+/* A string which is inserted between the value of OLDCONFIGLIB
+ (defined in the Makefile) and any names specified in the HDB
+ Sysfiles file. */
+#define HDB_SEPARATOR "/"
+
+/* A macro to check whether fopen failed because the file did not
+ exist. */
+#define FNO_SUCH_FILE() (errno == ENOENT)
+
+#if ! HAVE_STRERROR
+
+/* We need a definition for strerror; normally the function in the
+ unix directory is used, but we want to be independent of that
+ library. This macro evaluates its argument multiple times. */
+extern int sys_nerr;
+extern char *sys_errlist[];
+
+#define strerror(ierr) \
+ ((ierr) >= 0 && (ierr) < sys_nerr ? sys_errlist[ierr] : "unknown error")
+
+#endif /* ! HAVE_STRERROR */
+
+/* We want to be able to mark the Taylor UUCP system files as close on
+ exec. */
+#if HAVE_FCNTL_H
+#include <fcntl.h>
+#else
+#if HAVE_SYS_FILE_H
+#include <sys/file.h>
+#endif
+#endif
+
+#ifndef FD_CLOEXEC
+#define FD_CLOEXEC 1
+#endif
+
+#define CLOSE_ON_EXEC(e) \
+ do \
+ { \
+ int cle_i = fileno (e); \
+ \
+ fcntl (cle_i, F_SETFD, fcntl (cle_i, F_GETFD, 0) | FD_CLOEXEC); \
+ } \
+ while (0)
diff --git a/gnu/libexec/uucp/libuuconf/syssub.c b/gnu/libexec/uucp/libuuconf/syssub.c
new file mode 100644
index 00000000000..f9b52c13fed
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/syssub.c
@@ -0,0 +1,458 @@
+/* syssub.c
+ System information subroutines.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_syssub_rcsid[] = "$Id: syssub.c,v 1.1 1993/08/04 19:35:06 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* This macro operates on every string (char *) field in struct
+ uuconf_system. */
+#define SYSTEM_STRINGS(OP) \
+ do \
+ { \
+ OP (uuconf_zname); \
+ OP (uuconf_zalternate); \
+ OP (uuconf_zdebug); \
+ OP (uuconf_zmax_remote_debug); \
+ OP (uuconf_zphone); \
+ OP (uuconf_zcall_login); \
+ OP (uuconf_zcall_password); \
+ OP (uuconf_zcalled_login); \
+ OP (uuconf_zprotocols); \
+ OP (uuconf_zpubdir); \
+ OP (uuconf_zlocalname); \
+ } \
+ while (0)
+
+/* This macro operates on every string array (char **) field in struct
+ uuconf_system. */
+#define SYSTEM_STRING_ARRAYS(OP) \
+ do \
+ { \
+ OP (uuconf_pzalias); \
+ OP (uuconf_pzlocal_send); \
+ OP (uuconf_pzremote_send); \
+ OP (uuconf_pzlocal_receive); \
+ OP (uuconf_pzremote_receive); \
+ OP (uuconf_pzpath); \
+ OP (uuconf_pzcmds); \
+ OP (uuconf_pzforward_from); \
+ OP (uuconf_pzforward_to); \
+ OP (uuconf_schat.uuconf_pzchat); \
+ OP (uuconf_schat.uuconf_pzprogram); \
+ OP (uuconf_schat.uuconf_pzfail); \
+ OP (uuconf_scalled_chat.uuconf_pzchat); \
+ OP (uuconf_scalled_chat.uuconf_pzprogram); \
+ OP (uuconf_scalled_chat.uuconf_pzfail); \
+ } \
+ while (0)
+
+/* This macro operations on every timespan pointer (struct
+ uuconf_timespan *) in struct uuconf_system. */
+#define SYSTEM_TIMESPANS(OP) \
+ do \
+ { \
+ OP (uuconf_qtimegrade); \
+ OP (uuconf_qcalltimegrade); \
+ OP (uuconf_qcall_local_size); \
+ OP (uuconf_qcall_remote_size); \
+ OP (uuconf_qcalled_local_size); \
+ OP (uuconf_qcalled_remote_size); \
+ } \
+ while (0)
+
+/* This macro operates on every boolean value (of type int, although
+ some type int are not boolean) field in uuconf_system. */
+#define SYSTEM_BOOLEANS(OP) \
+ do \
+ { \
+ OP (uuconf_fcall); \
+ OP (uuconf_fcalled); \
+ OP (uuconf_fcallback); \
+ OP (uuconf_fsequence); \
+ OP (uuconf_fsend_request); \
+ OP (uuconf_frec_request); \
+ OP (uuconf_fcall_transfer); \
+ OP (uuconf_fcalled_transfer); \
+ OP (uuconf_schat.uuconf_fstrip); \
+ OP (uuconf_scalled_chat.uuconf_fstrip); \
+ } \
+ while (0)
+
+/* This macro operates on every generic integer (type int or long) in
+ uuconf_system. */
+#define SYSTEM_INTEGERS(OP) \
+ do \
+ { \
+ OP (uuconf_cmax_retries); \
+ OP (uuconf_csuccess_wait); \
+ OP (uuconf_ibaud); \
+ OP (uuconf_ihighbaud); \
+ OP (uuconf_cfree_space); \
+ OP (uuconf_schat.uuconf_ctimeout); \
+ OP (uuconf_scalled_chat.uuconf_ctimeout); \
+ } \
+ while (0)
+
+/* There is no macro for uuconf_qalternate, uuconf_zport,
+ uuconf_qport, uuconf_qproto_params, or uuconf_palloc. */
+
+/* Clear the contents of a struct uuconf_system. */
+
+void
+_uuconf_uclear_system (q)
+ struct uuconf_system *q;
+{
+#define CLEAR(x) q->x = (char *) &_uuconf_unset
+ SYSTEM_STRINGS (CLEAR);
+#undef CLEAR
+#define CLEAR(x) q->x = (char **) &_uuconf_unset
+ SYSTEM_STRING_ARRAYS (CLEAR);
+#undef CLEAR
+#define CLEAR(x) q->x = (struct uuconf_timespan *) &_uuconf_unset
+ SYSTEM_TIMESPANS (CLEAR);
+#undef CLEAR
+#define CLEAR(x) q->x = -1
+ SYSTEM_BOOLEANS (CLEAR);
+ SYSTEM_INTEGERS (CLEAR);
+#undef CLEAR
+ q->uuconf_qalternate = NULL;
+ q->uuconf_zport = (char *) &_uuconf_unset;
+ q->uuconf_qport = (struct uuconf_port *) &_uuconf_unset;
+ q->uuconf_qproto_params = (struct uuconf_proto_param *) &_uuconf_unset;
+ q->uuconf_palloc = NULL;
+}
+
+/* Default the contents of one struct uuconf_system to the contents of
+ another. This default alternate by alternate. Any additional
+ alternates in q default to the last alternate of qdefault. If the
+ faddalternates arguments is TRUE, additional alternates or qdefault
+ are added to q; these alternates are copies of the first alternate
+ of q, and defaults are set from the additional alternates of
+ qdefault. */
+
+int
+_uuconf_isystem_default (qglobal, qset, qdefault, faddalternates)
+ struct sglobal *qglobal;
+ struct uuconf_system *qset;
+ struct uuconf_system *qdefault;
+ boolean faddalternates;
+{
+ struct uuconf_system *qalt;
+
+ if (qset->uuconf_palloc != qdefault->uuconf_palloc)
+ qset->uuconf_palloc =
+ _uuconf_pmalloc_block_merge (qset->uuconf_palloc,
+ qdefault->uuconf_palloc);
+
+ /* If we are adding alternates from the default, make sure we have
+ at least as many alternates in qset as we do in qdefault. Each
+ new alternate we create gets initialized to the first alternate
+ of the system. */
+ if (faddalternates)
+ {
+ struct uuconf_system **pq, *qdef;
+
+ for (qdef = qdefault, pq = &qset;
+ qdef != NULL;
+ qdef = qdef->uuconf_qalternate, pq = &(*pq)->uuconf_qalternate)
+ {
+ if (*pq == NULL)
+ {
+ *pq = ((struct uuconf_system *)
+ uuconf_malloc (qset->uuconf_palloc,
+ sizeof (struct uuconf_system)));
+ if (*pq == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ **pq = *qset;
+ (*pq)->uuconf_qalternate = NULL;
+ }
+ }
+ }
+
+ for (qalt = qset; qalt != NULL; qalt = qalt->uuconf_qalternate)
+ {
+#define DEFAULT(x) \
+ if (qalt->x == (char *) &_uuconf_unset) qalt->x = qdefault->x
+ SYSTEM_STRINGS (DEFAULT);
+#undef DEFAULT
+#define DEFAULT(x) \
+ if (qalt->x == (char **) &_uuconf_unset) qalt->x = qdefault->x
+ SYSTEM_STRING_ARRAYS (DEFAULT);
+#undef DEFAULT
+#define DEFAULT(x) \
+ if (qalt->x == (struct uuconf_timespan *) &_uuconf_unset) \
+ qalt->x = qdefault->x
+ SYSTEM_TIMESPANS (DEFAULT);
+#undef DEFAULT
+#define DEFAULT(x) if (qalt->x < 0) qalt->x = qdefault->x
+ SYSTEM_BOOLEANS (DEFAULT);
+ SYSTEM_INTEGERS (DEFAULT);
+#undef DEFAULT
+
+ /* We only copy over zport if both zport and qport are NULL,
+ because otherwise a default zport would override a specific
+ qport. */
+ if (qalt->uuconf_zport == (char *) &_uuconf_unset
+ && qalt->uuconf_qport == (struct uuconf_port *) &_uuconf_unset)
+ qalt->uuconf_zport = qdefault->uuconf_zport;
+ if (qalt->uuconf_qport == (struct uuconf_port *) &_uuconf_unset)
+ qalt->uuconf_qport = qdefault->uuconf_qport;
+
+ if (qalt->uuconf_qproto_params
+ == (struct uuconf_proto_param *) &_uuconf_unset)
+ qalt->uuconf_qproto_params = qdefault->uuconf_qproto_params;
+
+ if (qdefault->uuconf_qalternate != NULL)
+ qdefault = qdefault->uuconf_qalternate;
+ }
+
+ return UUCONF_SUCCESS;
+}
+
+/* Put in the basic defaults. This ensures that the fields are valid
+ on every uuconf_system structure. */
+
+int
+_uuconf_isystem_basic_default (qglobal, q)
+ struct sglobal *qglobal;
+ register struct uuconf_system *q;
+{
+ int iret;
+
+ iret = UUCONF_SUCCESS;
+
+ for (; q != NULL && iret == UUCONF_SUCCESS; q = q->uuconf_qalternate)
+ {
+ /* The default of 26 allowable retries is traditional. */
+ if (q->uuconf_cmax_retries < 0)
+ q->uuconf_cmax_retries = 26;
+ if (q->uuconf_schat.uuconf_pzchat == (char **) &_uuconf_unset)
+ {
+ q->uuconf_schat.uuconf_pzchat = NULL;
+ iret = _uuconf_iadd_string (qglobal, (char *) "\"\"", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = _uuconf_iadd_string (qglobal, (char *) "\\r\\c", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = _uuconf_iadd_string (qglobal, (char *) "ogin:", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = _uuconf_iadd_string (qglobal, (char *) "-BREAK", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = _uuconf_iadd_string (qglobal, (char *) "-ogin:", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = _uuconf_iadd_string (qglobal, (char *) "-BREAK", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = _uuconf_iadd_string (qglobal, (char *) "-ogin:", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = _uuconf_iadd_string (qglobal, (char *) "\\L", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = _uuconf_iadd_string (qglobal, (char *) "word:", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = _uuconf_iadd_string (qglobal, (char *) "\\P", FALSE,
+ FALSE,
+ &q->uuconf_schat.uuconf_pzchat,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ if (q->uuconf_schat.uuconf_ctimeout < 0)
+ q->uuconf_schat.uuconf_ctimeout = 10;
+ if (q->uuconf_schat.uuconf_fstrip < 0)
+ q->uuconf_schat.uuconf_fstrip = TRUE;
+ if (q->uuconf_scalled_chat.uuconf_ctimeout < 0)
+ q->uuconf_scalled_chat.uuconf_ctimeout = 60;
+ if (q->uuconf_scalled_chat.uuconf_fstrip < 0)
+ q->uuconf_scalled_chat.uuconf_fstrip = TRUE;
+ if (q->uuconf_fsend_request < 0)
+ q->uuconf_fsend_request = TRUE;
+ if (q->uuconf_frec_request < 0)
+ q->uuconf_frec_request = TRUE;
+ if (q->uuconf_fcall_transfer < 0)
+ q->uuconf_fcall_transfer = TRUE;
+ if (q->uuconf_fcalled_transfer < 0)
+ q->uuconf_fcalled_transfer = TRUE;
+ if (q->uuconf_pzlocal_send == (char **) &_uuconf_unset)
+ {
+ q->uuconf_pzlocal_send = NULL;
+ iret = _uuconf_iadd_string (qglobal, (char *) ZROOTDIR, FALSE,
+ FALSE, &q->uuconf_pzlocal_send,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ if (q->uuconf_pzremote_send == (char **) &_uuconf_unset)
+ {
+ q->uuconf_pzremote_send = NULL;
+ iret = _uuconf_iadd_string (qglobal, (char *) "~", FALSE, FALSE,
+ &q->uuconf_pzremote_send,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ if (q->uuconf_pzlocal_receive == (char **) &_uuconf_unset)
+ {
+ q->uuconf_pzlocal_receive = NULL;
+ iret = _uuconf_iadd_string (qglobal, (char *) "~", FALSE, FALSE,
+ &q->uuconf_pzlocal_receive,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ if (q->uuconf_pzremote_receive == (char **) &_uuconf_unset)
+ {
+ q->uuconf_pzremote_receive = NULL;
+ iret = _uuconf_iadd_string (qglobal, (char *) "~", FALSE, FALSE,
+ &q->uuconf_pzremote_receive,
+ q->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ if (q->uuconf_pzpath == (char **) &_uuconf_unset)
+ {
+ char *zdup;
+ char **pz;
+ size_t csplit;
+ int c;
+
+ zdup = (char *) uuconf_malloc (q->uuconf_palloc, sizeof CMDPATH);
+ if (zdup == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ memcpy ((pointer) zdup, (pointer) CMDPATH, sizeof CMDPATH);
+ pz = NULL;
+ csplit = 0;
+ if ((c = _uuconf_istrsplit (zdup, '\0', &pz, &csplit)) < 0)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ q->uuconf_pzpath = (char **) uuconf_malloc (q->uuconf_palloc,
+ ((c + 1)
+ * sizeof (char *)));
+ if (q->uuconf_pzpath == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ memcpy ((pointer) q->uuconf_pzpath, (pointer) pz,
+ c * sizeof (char *));
+ q->uuconf_pzpath[c] = NULL;
+ free ((pointer) pz);
+ }
+
+ if (q->uuconf_pzcmds == (char **) &_uuconf_unset)
+ {
+ q->uuconf_pzcmds = ((char **)
+ uuconf_malloc (q->uuconf_palloc,
+ 3 * sizeof (const char *)));
+ if (q->uuconf_pzcmds == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ q->uuconf_pzcmds[0] = (char *) "rnews";
+ q->uuconf_pzcmds[1] = (char *) "rmail";
+ q->uuconf_pzcmds[2] = NULL;
+ }
+
+ if (q->uuconf_cfree_space < 0)
+ q->uuconf_cfree_space = DEFAULT_FREE_SPACE;
+
+ if (q->uuconf_zpubdir == (const char *) &_uuconf_unset)
+ q->uuconf_zpubdir = qglobal->qprocess->zpubdir;
+
+#define SET(x) if (q->x == (char *) &_uuconf_unset) q->x = NULL
+ SYSTEM_STRINGS(SET);
+#undef SET
+#define SET(x) if (q->x == (char **) &_uuconf_unset) q->x = NULL
+ SYSTEM_STRING_ARRAYS(SET);
+#undef SET
+#define SET(x) \
+ if (q->x == (struct uuconf_timespan *) &_uuconf_unset) q->x = NULL
+ SYSTEM_TIMESPANS (SET);
+#undef SET
+#define SET(x) if (q->x < 0) q->x = 0
+ SYSTEM_BOOLEANS (SET);
+ SYSTEM_INTEGERS (SET);
+#undef SET
+
+ if (q->uuconf_zport == (char *) &_uuconf_unset)
+ q->uuconf_zport = NULL;
+ if (q->uuconf_qport == (struct uuconf_port *) &_uuconf_unset)
+ q->uuconf_qport = NULL;
+ if (q->uuconf_qproto_params
+ == (struct uuconf_proto_param *) &_uuconf_unset)
+ q->uuconf_qproto_params = NULL;
+ }
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/tcalou.c b/gnu/libexec/uucp/libuuconf/tcalou.c
new file mode 100644
index 00000000000..8eb627eb334
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tcalou.c
@@ -0,0 +1,201 @@
+/* tcalou.c
+ Find callout login name and password from Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tcalou_rcsid[] = "$Id: tcalou.c,v 1.1 1993/08/04 19:35:07 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+static int icsys P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+
+/* Find the callout login name and password for a system from the
+ Taylor UUCP configuration files. */
+
+int
+uuconf_taylor_callout (pglobal, qsys, pzlog, pzpass)
+ pointer pglobal;
+ const struct uuconf_system *qsys;
+ char **pzlog;
+ char **pzpass;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ boolean flookup;
+ struct uuconf_cmdtab as[2];
+ char **pz;
+ int iret;
+ pointer pinfo;
+
+ *pzlog = NULL;
+ *pzpass = NULL;
+
+ flookup = FALSE;
+
+ if (qsys->uuconf_zcall_login != NULL)
+ {
+ if (strcmp (qsys->uuconf_zcall_login, "*") == 0)
+ flookup = TRUE;
+ else
+ {
+ *pzlog = strdup (qsys->uuconf_zcall_login);
+ if (*pzlog == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ }
+ }
+
+ if (qsys->uuconf_zcall_password != NULL)
+ {
+ if (strcmp (qsys->uuconf_zcall_password, "*") == 0)
+ flookup = TRUE;
+ else
+ {
+ *pzpass = strdup (qsys->uuconf_zcall_password);
+ if (*pzpass == NULL)
+ {
+ qglobal->ierrno = errno;
+ if (*pzlog != NULL)
+ {
+ free ((pointer) *pzlog);
+ *pzlog = NULL;
+ }
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ }
+ }
+
+ if (! flookup)
+ {
+ if (*pzlog == NULL && *pzpass == NULL)
+ return UUCONF_NOT_FOUND;
+ return UUCONF_SUCCESS;
+ }
+
+ as[0].uuconf_zcmd = qsys->uuconf_zname;
+ as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 3;
+ if (*pzlog == NULL)
+ as[0].uuconf_pvar = (pointer) pzlog;
+ else
+ as[0].uuconf_pvar = NULL;
+ as[0].uuconf_pifn = icsys;
+
+ as[1].uuconf_zcmd = NULL;
+
+ if (*pzpass == NULL)
+ pinfo = (pointer) pzpass;
+ else
+ pinfo = NULL;
+
+ iret = UUCONF_SUCCESS;
+
+ for (pz = qglobal->qprocess->pzcallfiles; *pz != NULL; pz++)
+ {
+ FILE *e;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ iret = uuconf_cmd_file (pglobal, e, as, pinfo,
+ (uuconf_cmdtabfn) NULL, 0,
+ qsys->uuconf_palloc);
+ (void) fclose (e);
+
+ if (iret != UUCONF_SUCCESS)
+ break;
+ if (*pzlog != NULL)
+ break;
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = *pz;
+ return iret | UUCONF_ERROR_FILENAME;
+ }
+
+ if (*pzlog == NULL && *pzpass == NULL)
+ return UUCONF_NOT_FOUND;
+
+ return UUCONF_SUCCESS;
+}
+
+/* Copy the login name and password onto the heap and set the
+ pointers. The pzlog argument is passed in pvar, and the pzpass
+ argument is passed in pinfo. */
+
+static int
+icsys (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char **pzlog = (char **) pvar;
+ char **pzpass = (char **) pinfo;
+
+ if (pzlog != NULL)
+ {
+ *pzlog = strdup (argv[1]);
+ if (*pzlog == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+ }
+
+ if (pzpass != NULL)
+ {
+ *pzpass = strdup (argv[2]);
+ if (*pzpass == NULL)
+ {
+ qglobal->ierrno = errno;
+ if (pzlog != NULL)
+ {
+ free ((pointer) *pzlog);
+ *pzlog = NULL;
+ }
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+ }
+
+ return UUCONF_CMDTABRET_EXIT;
+}
diff --git a/gnu/libexec/uucp/libuuconf/tdial.c b/gnu/libexec/uucp/libuuconf/tdial.c
new file mode 100644
index 00000000000..f13c92998ab
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tdial.c
@@ -0,0 +1,227 @@
+/* tdial.c
+ Find a dialer in the Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tdial_rcsid[] = "$Id: tdial.c,v 1.1 1993/08/04 19:35:08 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+static int iddialer P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int idunknown P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+
+/* Find a dialer in the Taylor UUCP configuration files by name. */
+
+int
+uuconf_taylor_dialer_info (pglobal, zname, qdialer)
+ pointer pglobal;
+ const char *zname;
+ struct uuconf_dialer *qdialer;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ FILE *e;
+ pointer pblock;
+ int iret;
+ char **pz;
+
+ e = NULL;
+ pblock = NULL;
+ iret = UUCONF_NOT_FOUND;
+
+ for (pz = qglobal->qprocess->pzdialfiles; *pz != NULL; pz++)
+ {
+ struct uuconf_cmdtab as[2];
+ char *zdialer;
+ struct uuconf_dialer sdefault;
+ int ilineno;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ qglobal->ilineno = 0;
+
+ /* Gather the default information from the top of the file. We
+ do this by handling the "dialer" command ourselves and
+ passing every other command to _uuconf_idialer_cmd via
+ idunknown. The value of zdialer will be an malloc block. */
+ as[0].uuconf_zcmd = "dialer";
+ as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 2;
+ as[0].uuconf_pvar = (pointer) &zdialer;
+ as[0].uuconf_pifn = iddialer;
+
+ as[1].uuconf_zcmd = NULL;
+
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ _uuconf_uclear_dialer (&sdefault);
+ sdefault.uuconf_palloc = pblock;
+ zdialer = NULL;
+ iret = uuconf_cmd_file (pglobal, e, as, (pointer) &sdefault,
+ idunknown, UUCONF_CMDTABFLAG_BACKSLASH,
+ pblock);
+
+ /* Now skip until we find a dialer with a matching name. */
+ while (iret == UUCONF_SUCCESS
+ && zdialer != NULL
+ && strcmp (zname, zdialer) != 0)
+ {
+ free ((pointer) zdialer);
+ zdialer = NULL;
+ ilineno = qglobal->ilineno;
+ iret = uuconf_cmd_file (pglobal, e, as, (pointer) NULL,
+ (uuconf_cmdtabfn) NULL,
+ UUCONF_CMDTABFLAG_BACKSLASH,
+ pblock);
+ qglobal->ilineno += ilineno;
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ if (zdialer != NULL)
+ free ((pointer) zdialer);
+ break;
+ }
+
+ if (zdialer != NULL)
+ {
+ size_t csize;
+
+ /* We've found the dialer we're looking for. Read the rest
+ of the commands for it. */
+ as[0].uuconf_pvar = NULL;
+
+ *qdialer = sdefault;
+ csize = strlen (zdialer) + 1;
+ qdialer->uuconf_zname = uuconf_malloc (pblock, csize);
+ if (qdialer->uuconf_zname == NULL)
+ {
+ qglobal->ierrno = errno;
+ free ((pointer) zdialer);
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ memcpy ((pointer) qdialer->uuconf_zname, (pointer) zdialer,
+ csize);
+ free ((pointer) zdialer);
+
+ ilineno = qglobal->ilineno;
+ iret = uuconf_cmd_file (pglobal, e, as, qdialer, idunknown,
+ UUCONF_CMDTABFLAG_BACKSLASH, pblock);
+ qglobal->ilineno += ilineno;
+ break;
+ }
+
+ (void) fclose (e);
+ e = NULL;
+ uuconf_free_block (pblock);
+ pblock = NULL;
+
+ iret = UUCONF_NOT_FOUND;
+ }
+
+ if (e != NULL)
+ (void) fclose (e);
+ if (iret != UUCONF_SUCCESS && pblock != NULL)
+ uuconf_free_block (pblock);
+
+ if (iret != UUCONF_SUCCESS && iret != UUCONF_NOT_FOUND)
+ {
+ qglobal->zfilename = *pz;
+ iret |= UUCONF_ERROR_FILENAME;
+ }
+
+ return iret;
+}
+
+/* Handle a "dialer" command. This copies the string onto the heap
+ and returns the pointer in *pvar, unless pvar is NULL. It returns
+ UUCONF_CMDTABRET_EXIT to force _uuconf_icmd_file_internal to stop
+ reading and return to the code above, which will then check the
+ dialer name just read to see if it matches. */
+
+/*ARGSUSED*/
+static int
+iddialer (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char **pz = (char **) pvar;
+
+ if (pz != NULL)
+ {
+ size_t csize;
+
+ csize = strlen (argv[1]) + 1;
+ *pz = malloc (csize);
+ if (*pz == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+ memcpy ((pointer) *pz, (pointer) argv[1], csize);
+ }
+ return UUCONF_CMDTABRET_EXIT;
+}
+
+/* Handle an unknown command by passing it on to _uuconf_idialer_cmd,
+ which will parse it into the dialer structure. */
+
+/*ARGSUSED*/
+static int
+idunknown (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_dialer *qdialer = (struct uuconf_dialer *) pinfo;
+
+ return _uuconf_idialer_cmd (qglobal, argc, argv, qdialer);
+}
diff --git a/gnu/libexec/uucp/libuuconf/tdialc.c b/gnu/libexec/uucp/libuuconf/tdialc.c
new file mode 100644
index 00000000000..e70090f3bb0
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tdialc.c
@@ -0,0 +1,211 @@
+/* tdialc.c
+ Handle a Taylor UUCP dialer command.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tdialc_rcsid[] = "$Id: tdialc.c,v 1.1 1993/08/04 19:35:09 jtc Exp $";
+#endif
+
+static int idchat P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int iddtr_toggle P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int idcomplete P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int idproto_param P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int idcunknown P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+
+/* The command table for dialer commands. The "dialer" command is
+ handled specially. */
+static const struct cmdtab_offset asDialer_cmds[] =
+{
+ { "chat", UUCONF_CMDTABTYPE_PREFIX | 0,
+ offsetof (struct uuconf_dialer, uuconf_schat), idchat },
+ { "dialtone", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_dialer, uuconf_zdialtone), NULL },
+ { "pause", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_dialer, uuconf_zpause), NULL },
+ { "carrier", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_dialer, uuconf_fcarrier), NULL },
+ { "carrier-wait", UUCONF_CMDTABTYPE_INT,
+ offsetof (struct uuconf_dialer, uuconf_ccarrier_wait), NULL },
+ { "dtr-toggle", UUCONF_CMDTABTYPE_FN | 0, (size_t) -1, iddtr_toggle },
+ { "complete", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct uuconf_dialer, uuconf_scomplete), idcomplete },
+ { "complete-chat", UUCONF_CMDTABTYPE_PREFIX,
+ offsetof (struct uuconf_dialer, uuconf_scomplete), idchat },
+ { "abort", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct uuconf_dialer, uuconf_sabort), idcomplete },
+ { "abort-chat", UUCONF_CMDTABTYPE_PREFIX,
+ offsetof (struct uuconf_dialer, uuconf_sabort), idchat },
+ { "protocol-parameter", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct uuconf_dialer, uuconf_qproto_params), idproto_param },
+ { "seven-bit", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct uuconf_dialer, uuconf_ireliable), _uuconf_iseven_bit },
+ { "reliable", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct uuconf_dialer, uuconf_ireliable), _uuconf_ireliable },
+ { "half-duplex", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct uuconf_dialer, uuconf_ireliable),
+ _uuconf_ihalf_duplex },
+ { NULL, 0, 0, NULL }
+};
+
+#define CDIALER_CMDS (sizeof asDialer_cmds / sizeof asDialer_cmds[0])
+
+/* Handle a command passed to a dialer from a Taylor UUCP
+ configuration file. This can be called when reading the dialer
+ file, the port file, or the sys file. The return value may have
+ UUCONF_CMDTABRET_KEEP set, but not UUCONF_CMDTABRET_EXIT. It
+ assigns values to the elements of qdialer. The first time this is
+ called, qdialer->uuconf_palloc should be set. This will not set
+ qdialer->uuconf_zname. */
+
+int
+_uuconf_idialer_cmd (qglobal, argc, argv, qdialer)
+ struct sglobal *qglobal;
+ int argc;
+ char **argv;
+ struct uuconf_dialer *qdialer;
+{
+ struct uuconf_cmdtab as[CDIALER_CMDS];
+ int iret;
+
+ _uuconf_ucmdtab_base (asDialer_cmds, CDIALER_CMDS, (char *) qdialer, as);
+
+ iret = uuconf_cmd_args ((pointer) qglobal, argc, argv, as,
+ (pointer) qdialer, idcunknown, 0,
+ qdialer->uuconf_palloc);
+
+ return iret &~ UUCONF_CMDTABRET_EXIT;
+}
+
+/* Reroute a chat script command. */
+
+static int
+idchat (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_chat *qchat = (struct uuconf_chat *) pvar;
+ struct uuconf_dialer *qdialer = (struct uuconf_dialer *) pinfo;
+
+ return _uuconf_ichat_cmd (qglobal, argc, argv, qchat,
+ qdialer->uuconf_palloc);
+}
+
+/* Handle the "dtr-toggle" command, which may take two arguments. */
+
+/*ARGSUSED*/
+static int
+iddtr_toggle (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_dialer *qdialer = (struct uuconf_dialer *) pinfo;
+ int iret;
+
+ if (argc < 2 || argc > 3)
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ iret = _uuconf_iboolean (qglobal, argv[1], &qdialer->uuconf_fdtr_toggle);
+ if ((iret &~ UUCONF_CMDTABRET_KEEP) != UUCONF_SUCCESS)
+ return iret;
+
+ if (argc < 3)
+ return iret;
+
+ iret |= _uuconf_iboolean (qglobal, argv[2],
+ &qdialer->uuconf_fdtr_toggle_wait);
+
+ return iret;
+}
+
+/* Handle the "complete" and "abort" commands. These just turn a
+ string into a trivial chat script. */
+
+/*ARGSUSED*/
+static int
+idcomplete (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_chat *qchat = (struct uuconf_chat *) pvar;
+ struct uuconf_dialer *qdialer = (struct uuconf_dialer *) pinfo;
+ char *azargs[3];
+
+ azargs[0] = (char *) "complete-chat";
+ azargs[1] = (char *) "\"\"";
+ azargs[2] = (char *) argv[1];
+
+ return _uuconf_ichat_cmd (qglobal, 3, azargs, qchat,
+ qdialer->uuconf_palloc);
+}
+
+/* Handle the "protocol-parameter" command. */
+
+static int
+idproto_param (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_proto_param **pqparam = (struct uuconf_proto_param **) pvar;
+ struct uuconf_dialer *qdialer = (struct uuconf_dialer *) pinfo;
+
+ return _uuconf_iadd_proto_param (qglobal, argc - 1, argv + 1, pqparam,
+ qdialer->uuconf_palloc);
+}
+
+/* Give an error for an unknown dialer command. */
+
+/*ARGSUSED*/
+static int
+idcunknown (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+}
diff --git a/gnu/libexec/uucp/libuuconf/tdnams.c b/gnu/libexec/uucp/libuuconf/tdnams.c
new file mode 100644
index 00000000000..d9e4b0d7e38
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tdnams.c
@@ -0,0 +1,119 @@
+/* tdnams.c
+ Get all known dialer names from the Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tdnams_rcsid[] = "$Id: tdnams.c,v 1.1 1993/08/04 19:35:10 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+static int indialer P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+
+/* Get the names of all the dialers from the Taylor UUCP configuration
+ files. */
+
+int
+uuconf_taylor_dialer_names (pglobal, ppzdialers)
+ pointer pglobal;
+ char ***ppzdialers;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_cmdtab as[2];
+ char **pz;
+ int iret;
+
+ *ppzdialers = NULL;
+
+ as[0].uuconf_zcmd = "dialer";
+ as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 2;
+ as[0].uuconf_pvar = (pointer) ppzdialers;
+ as[0].uuconf_pifn = indialer;
+
+ as[1].uuconf_zcmd = NULL;
+
+ iret = UUCONF_SUCCESS;
+
+ for (pz = qglobal->qprocess->pzdialfiles; *pz != NULL; pz++)
+ {
+ FILE *e;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ iret = uuconf_cmd_file (pglobal, e, as, (pointer) NULL,
+ (uuconf_cmdtabfn) NULL,
+ UUCONF_CMDTABFLAG_BACKSLASH,
+ (pointer) NULL);
+
+ (void) fclose (e);
+
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = *pz;
+ return iret | UUCONF_ERROR_FILENAME;
+ }
+
+ if (*ppzdialers == NULL)
+ iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
+ ppzdialers, (pointer) NULL);
+
+ return UUCONF_SUCCESS;
+}
+
+/* Add a dialer name to the list. */
+
+/*ARGSUSED*/
+static int
+indialer (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char ***ppzdialers = (char ***) pvar;
+ int iret;
+
+ iret = _uuconf_iadd_string (qglobal, argv[1], TRUE, TRUE, ppzdialers,
+ (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ iret |= UUCONF_CMDTABRET_EXIT;
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/tgcmp.c b/gnu/libexec/uucp/libuuconf/tgcmp.c
new file mode 100644
index 00000000000..9bc8de2b5f4
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tgcmp.c
@@ -0,0 +1,42 @@
+/* tgcmp.c
+ A comparison function for grades for _uuconf_time_parse.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tgcmp_rcsid[] = "$Id: tgcmp.c,v 1.1 1993/08/04 19:35:11 jtc Exp $";
+#endif
+
+/* A comparison function to pass to _uuconf_itime_parse. This
+ compares grades. We can't just pass uuconf_grade_cmp, since
+ _uuconf_itime_parse wants a function takes longs as arguments. */
+
+int
+_uuconf_itime_grade_cmp (i1, i2)
+ long i1;
+ long i2;
+{
+ return UUCONF_GRADE_CMP ((int) i1, (int) i2);
+}
diff --git a/gnu/libexec/uucp/libuuconf/thread.c b/gnu/libexec/uucp/libuuconf/thread.c
new file mode 100644
index 00000000000..92f100bba20
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/thread.c
@@ -0,0 +1,70 @@
+/* thread.c
+ Initialize for a new thread.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_thread_rcsid[] = "$Id: thread.c,v 1.1 1993/08/04 19:35:11 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Initialize for a new thread, by allocating a new sglobal structure
+ which points to the same sprocess structure. */
+
+int
+uuconf_init_thread (ppglobal)
+ pointer *ppglobal;
+{
+ struct sglobal **pqglob = (struct sglobal **) ppglobal;
+ pointer pblock;
+ struct sglobal *qnew;
+
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ (*pqglob)->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ qnew = (struct sglobal *) uuconf_malloc (pblock,
+ sizeof (struct sglobal));
+ if (qnew == NULL)
+ {
+ (*pqglob)->ierrno = errno;
+ uuconf_free_block (pblock);
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ qnew->pblock = pblock;
+ qnew->ierrno = 0;
+ qnew->ilineno = 0;
+ qnew->zfilename = NULL;
+ qnew->qprocess = (*pqglob)->qprocess;
+
+ *pqglob = qnew;
+
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/time.c b/gnu/libexec/uucp/libuuconf/time.c
new file mode 100644
index 00000000000..6f316828a38
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/time.c
@@ -0,0 +1,406 @@
+/* time.c
+ Parse a time string into a uuconf_timespan structure.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_time_rcsid[] = "$Id: time.c,v 1.1 1993/08/04 19:35:12 jtc Exp $";
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+static int itadd_span P((struct sglobal *qglobal, int istart, int iend,
+ long ival, int cretry,
+ int (*picmp) P((long, long)),
+ struct uuconf_timespan **pqspan,
+ pointer pblock));
+static int itnew P((struct sglobal *qglobal, struct uuconf_timespan **pqset,
+ struct uuconf_timespan *qnext, int istart, int iend,
+ long ival, int cretry, pointer pblock));
+
+/* An array of weekday abbreviations. The code below assumes that
+ each one starts with a lower case letter. */
+
+static const struct
+{
+ const char *zname;
+ int imin;
+ int imax;
+} asTdays[] =
+{
+ { "any", 0, 6 },
+ { "wk", 1, 5 },
+ { "su", 0, 0 },
+ { "mo", 1, 1 },
+ { "tu", 2, 2 },
+ { "we", 3, 3 },
+ { "th", 4, 4 },
+ { "fr", 5, 5 },
+ { "sa", 6, 6 },
+ { "never", -1, -2 },
+ { NULL, 0, 0 }
+};
+
+/* Parse a time string and add it to a span list. This function is
+ given the value, the retry time, and the comparison function to
+ use. */
+
+int
+_uuconf_itime_parse (qglobal, ztime, ival, cretry, picmp, pqspan, pblock)
+ struct sglobal *qglobal;
+ char *ztime;
+ long ival;
+ int cretry;
+ int (*picmp) P((long, long));
+ struct uuconf_timespan **pqspan;
+ pointer pblock;
+{
+ struct uuconf_timespan *qlist;
+ char bfirst;
+ const char *z;
+
+ qlist = *pqspan;
+ if (qlist == (struct uuconf_timespan *) &_uuconf_unset)
+ qlist = NULL;
+
+ /* Expand the string using a timetable. Keep rechecking the string
+ until it does not match. */
+ while (TRUE)
+ {
+ char **pz;
+ char *zfound;
+
+ bfirst = *ztime;
+ if (isupper (BUCHAR (bfirst)))
+ bfirst = tolower (BUCHAR (bfirst));
+
+ zfound = NULL;
+ pz = qglobal->qprocess->pztimetables;
+
+ /* We want the last timetable to have been defined with this
+ name, so we always look through the entire table. */
+ while (*pz != NULL)
+ {
+ if ((bfirst == (*pz)[0]
+ || (isupper (BUCHAR ((*pz)[0]))
+ && bfirst == tolower (BUCHAR ((*pz)[0]))))
+ && strcasecmp (ztime, *pz) == 0)
+ zfound = pz[1];
+ pz += 2;
+ }
+ if (zfound == NULL)
+ break;
+ ztime = zfound;
+ }
+
+ /* Look through the time string. */
+ z = ztime;
+ while (*z != '\0')
+ {
+ int iday;
+ boolean afday[7];
+ int istart, iend;
+
+ if (*z == ',' || *z == '|')
+ ++z;
+ if (*z == '\0' || *z == ';')
+ break;
+
+ for (iday = 0; iday < 7; iday++)
+ afday[iday] = FALSE;
+
+ /* Get the days. */
+ do
+ {
+ bfirst = *z;
+ if (isupper (BUCHAR (bfirst)))
+ bfirst = tolower (BUCHAR (bfirst));
+ for (iday = 0; asTdays[iday].zname != NULL; iday++)
+ {
+ size_t clen;
+
+ if (bfirst != asTdays[iday].zname[0])
+ continue;
+
+ clen = strlen (asTdays[iday].zname);
+ if (strncasecmp (z, asTdays[iday].zname, clen) == 0)
+ {
+ int iset;
+
+ for (iset = asTdays[iday].imin;
+ iset <= asTdays[iday].imax;
+ iset++)
+ afday[iset] = TRUE;
+ z += clen;
+ break;
+ }
+ }
+ if (asTdays[iday].zname == NULL)
+ return UUCONF_SYNTAX_ERROR;
+ }
+ while (isalpha (BUCHAR (*z)));
+
+ /* Get the hours. */
+ if (! isdigit (BUCHAR (*z)))
+ {
+ istart = 0;
+ iend = 24 * 60;
+ }
+ else
+ {
+ char *zendnum;
+
+ istart = (int) strtol ((char *) z, &zendnum, 10);
+ if (*zendnum != '-' || ! isdigit (BUCHAR (zendnum[1])))
+ return UUCONF_SYNTAX_ERROR;
+ z = zendnum + 1;
+ iend = (int) strtol ((char *) z, &zendnum, 10);
+ z = zendnum;
+
+ istart = (istart / 100) * 60 + istart % 100;
+ iend = (iend / 100) * 60 + iend % 100;
+ }
+
+ /* Add the times we've found onto the list. */
+ for (iday = 0; iday < 7; iday++)
+ {
+ if (afday[iday])
+ {
+ int iminute, iret;
+
+ iminute = iday * 24 * 60;
+ if (istart < iend)
+ iret = itadd_span (qglobal, iminute + istart,
+ iminute + iend, ival, cretry, picmp,
+ &qlist, pblock);
+ else
+ {
+ /* Wrap around midnight. */
+ iret = itadd_span (qglobal, iminute, iminute + iend,
+ ival, cretry, picmp, &qlist, pblock);
+ if (iret == UUCONF_SUCCESS)
+ iret = itadd_span (qglobal, iminute + istart,
+ iminute + 24 * 60, ival, cretry,
+ picmp, &qlist, pblock);
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ }
+ }
+
+ *pqspan = qlist;
+
+ return UUCONF_SUCCESS;
+}
+
+/* Add a time span to an existing list of time spans. We keep the
+ list sorted by time to make this operation easier. This modifies
+ the existing list, and returns the modified version. It takes a
+ comparison function which should return < 0 if the first argument
+ should take precedence over the second argument and == 0 if they
+ are the same (for grades this is igradecmp; for sizes it is minus
+ (the binary operator)). */
+
+static int
+itadd_span (qglobal, istart, iend, ival, cretry, picmp, pqspan, pblock)
+ struct sglobal *qglobal;
+ int istart;
+ int iend;
+ long ival;
+ int cretry;
+ int (*picmp) P((long, long));
+ struct uuconf_timespan **pqspan;
+ pointer pblock;
+{
+ struct uuconf_timespan **pq;
+ int iret;
+
+ /* istart < iend */
+ for (pq = pqspan; *pq != NULL; pq = &(*pq)->uuconf_qnext)
+ {
+ int icmp;
+
+ /* Invariant: PREV (*pq) == NULL || PREV (*pq)->iend <= istart */
+ /* istart < iend && (*pq)->istart < (*pq)->iend */
+
+ if (iend <= (*pq)->uuconf_istart)
+ {
+ /* istart < iend <= (*pq)->istart < (*pq)->iend */
+ /* No overlap, and we're at the right spot. See if we can
+ combine these spans. */
+ if (iend == (*pq)->uuconf_istart
+ && cretry == (*pq)->uuconf_cretry
+ && (*picmp) (ival, (*pq)->uuconf_ival) == 0)
+ {
+ (*pq)->uuconf_istart = istart;
+ return UUCONF_SUCCESS;
+ }
+ /* We couldn't combine them. */
+ break;
+ }
+
+ if ((*pq)->uuconf_iend <= istart)
+ {
+ /* (*pq)->istart < (*pq)->iend <= istart < iend */
+ /* No overlap. Try attaching this span. */
+ if ((*pq)->uuconf_iend == istart
+ && (*pq)->uuconf_cretry == cretry
+ && ((*pq)->uuconf_qnext == NULL
+ || iend <= (*pq)->uuconf_qnext->uuconf_istart)
+ && (*picmp) (ival, (*pq)->uuconf_ival) == 0)
+ {
+ (*pq)->uuconf_iend = iend;
+ return UUCONF_SUCCESS;
+ }
+ /* Couldn't attach; keep looking for the right spot. We
+ might be able to combine part of the new span onto an
+ existing span, but it's probably not worth it. */
+ continue;
+ }
+
+ /* istart < iend
+ && (*pq)->istart < (*pq)->iend
+ && istart < (*pq)->iend
+ && (*pq)->istart < iend */
+ /* Overlap. */
+
+ icmp = (*picmp) (ival, (*pq)->uuconf_ival);
+
+ if (icmp == 0)
+ {
+ /* Just expand the old span to include the new span. */
+ if (istart < (*pq)->uuconf_istart)
+ (*pq)->uuconf_istart = istart;
+ if ((*pq)->uuconf_iend >= iend)
+ return UUCONF_SUCCESS;
+ if ((*pq)->uuconf_qnext == NULL
+ || iend <= (*pq)->uuconf_qnext->uuconf_istart)
+ {
+ (*pq)->uuconf_iend = iend;
+ return UUCONF_SUCCESS;
+ }
+ /* The span we are adding overlaps the next span as well.
+ Expand the old span up to the next old span, and keep
+ trying to add the new span. */
+ (*pq)->uuconf_iend = (*pq)->uuconf_qnext->uuconf_istart;
+ istart = (*pq)->uuconf_iend;
+ }
+ else if (icmp < 0)
+ {
+ /* Replace the old span with the new span. */
+ if ((*pq)->uuconf_istart < istart)
+ {
+ /* Save the initial portion of the old span. */
+ iret = itnew (qglobal, pq, *pq, (*pq)->uuconf_istart, istart,
+ (*pq)->uuconf_ival, (*pq)->uuconf_cretry,
+ pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ pq = &(*pq)->uuconf_qnext;
+ }
+ if (iend < (*pq)->uuconf_iend)
+ {
+ /* Save the final portion of the old span. */
+ iret = itnew (qglobal, &(*pq)->uuconf_qnext,
+ (*pq)->uuconf_qnext, iend, (*pq)->uuconf_iend,
+ (*pq)->uuconf_ival, (*pq)->uuconf_cretry,
+ pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ (*pq)->uuconf_ival = ival;
+ (*pq)->uuconf_istart = istart;
+ (*pq)->uuconf_cretry = cretry;
+ if ((*pq)->uuconf_qnext == NULL
+ || iend <= (*pq)->uuconf_qnext->uuconf_istart)
+ {
+ (*pq)->uuconf_iend = iend;
+ return UUCONF_SUCCESS;
+ }
+ /* Move this span up to the next one, and keep trying to add
+ the new span. */
+ (*pq)->uuconf_iend = (*pq)->uuconf_qnext->uuconf_istart;
+ istart = (*pq)->uuconf_iend;
+ }
+ else
+ {
+ /* Leave the old span untouched. */
+ if (istart < (*pq)->uuconf_istart)
+ {
+ /* Put in the initial portion of the new span. */
+ iret = itnew (qglobal, pq, *pq, istart, (*pq)->uuconf_istart,
+ ival, cretry, pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ pq = &(*pq)->uuconf_qnext;
+ }
+ if (iend <= (*pq)->uuconf_iend)
+ return UUCONF_SUCCESS;
+ /* Keep trying to add the new span. */
+ istart = (*pq)->uuconf_iend;
+ }
+ }
+
+ /* This is the spot for the new span, and there's no overlap. */
+
+ return itnew (qglobal, pq, *pq, istart, iend, ival, cretry, pblock);
+}
+
+/* A utility function to create a new uuconf_timespan structure. */
+
+static int
+itnew (qglobal, pqset, qnext, istart, iend, ival, cretry, pblock)
+ struct sglobal *qglobal;
+ struct uuconf_timespan **pqset;
+ struct uuconf_timespan *qnext;
+ int istart;
+ int iend;
+ long ival;
+ int cretry;
+ pointer pblock;
+{
+ register struct uuconf_timespan *qnew;
+
+ qnew = ((struct uuconf_timespan *)
+ uuconf_malloc (pblock, sizeof (struct uuconf_timespan)));
+ if (qnew == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ qnew->uuconf_qnext = qnext;
+ qnew->uuconf_istart = istart;
+ qnew->uuconf_iend = iend;
+ qnew->uuconf_ival = ival;
+ qnew->uuconf_cretry = cretry;
+
+ *pqset = qnew;
+
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/tinit.c b/gnu/libexec/uucp/libuuconf/tinit.c
new file mode 100644
index 00000000000..829fd12285e
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tinit.c
@@ -0,0 +1,370 @@
+/* tinit.c
+ Initialize for reading Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tinit_rcsid[] = "$Id: tinit.c,v 1.1 1993/08/04 19:35:14 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Local functions. */
+
+static int itset_default P((struct sglobal *qglobal, char ***ppzvar,
+ const char *zfile));
+static int itadd P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int itunknown P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int itprogram P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+
+static const struct cmdtab_offset asCmds[] =
+{
+ { "nodename", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zlocalname), NULL },
+ { "hostname", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zlocalname), NULL },
+ { "uuname", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zlocalname), NULL },
+ { "spool", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zspooldir), NULL },
+ { "pubdir", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zpubdir), NULL },
+ { "lockdir", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zlockdir), NULL },
+ { "logfile", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zlogfile), NULL },
+ { "statfile", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zstatsfile), NULL },
+ { "debugfile", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zdebugfile), NULL },
+ { "debug", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct sprocess, zdebug), NULL },
+ { "max-uuxqts", UUCONF_CMDTABTYPE_INT,
+ offsetof (struct sprocess, cmaxuuxqts), NULL },
+ { "sysfile", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct sprocess, pzsysfiles), itadd },
+ { "portfile", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct sprocess, pzportfiles), itadd },
+ { "dialfile", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct sprocess, pzdialfiles), itadd },
+ { "dialcodefile", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct sprocess, pzdialcodefiles), itadd },
+ { "callfile", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct sprocess, pzcallfiles), itadd },
+ { "passwdfile", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct sprocess, pzpwdfiles), itadd },
+ { "unknown", UUCONF_CMDTABTYPE_FN, offsetof (struct sprocess, qunknown),
+ itunknown },
+ { "v2-files", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct sprocess, fv2), NULL },
+ { "hdb-files", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct sprocess, fhdb), NULL },
+ { "bnu-files", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct sprocess, fhdb), NULL },
+ { "timetable", UUCONF_CMDTABTYPE_FN | 3,
+ offsetof (struct sprocess, pztimetables), _uuconf_itimetable },
+ { NULL, 0, 0, NULL }
+};
+
+#define CCMDS (sizeof asCmds / sizeof asCmds[0])
+
+/* This structure is used to pass information into the command table
+ functions. */
+
+struct sinfo
+{
+ /* The program name. */
+ const char *zname;
+ /* A pointer to the command table being used, passed to isystem so
+ it can call uuconf_cmd_args. */
+ struct uuconf_cmdtab *qcmds;
+};
+
+/* Initialize the routines which read the Taylor UUCP configuration
+ files. */
+
+int
+uuconf_taylor_init (ppglobal, zprogram, zname)
+ pointer *ppglobal;
+ const char *zprogram;
+ const char *zname;
+{
+ struct sglobal **pqglobal = (struct sglobal **) ppglobal;
+ int iret;
+ char *zcopy;
+ struct sglobal *qglobal;
+ boolean fdefault;
+ FILE *e;
+ struct sinfo si;
+
+ if (*pqglobal == NULL)
+ {
+ iret = _uuconf_iinit_global (pqglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ qglobal = *pqglobal;
+
+ if (zname != NULL)
+ {
+ size_t csize;
+
+ csize = strlen (zname) + 1;
+ zcopy = uuconf_malloc (qglobal->pblock, csize);
+ if (zcopy == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ memcpy ((pointer) zcopy, (pointer) zname, csize);
+ fdefault = FALSE;
+ }
+ else
+ {
+ zcopy = uuconf_malloc (qglobal->pblock,
+ sizeof NEWCONFIGLIB + sizeof CONFIGFILE - 1);
+ if (zcopy == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ memcpy ((pointer) zcopy, (pointer) NEWCONFIGLIB,
+ sizeof NEWCONFIGLIB - 1);
+ memcpy ((pointer) (zcopy + sizeof NEWCONFIGLIB - 1),
+ (pointer) CONFIGFILE, sizeof CONFIGFILE);
+ fdefault = TRUE;
+ }
+
+ qglobal->qprocess->zconfigfile = zcopy;
+
+ e = fopen (zcopy, "r");
+ if (e == NULL)
+ {
+ if (! fdefault)
+ {
+ qglobal->ierrno = errno;
+ qglobal->zfilename = zcopy;
+ return (UUCONF_FOPEN_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_ERROR_FILENAME);
+ }
+
+ /* There is no config file, so just use the default values. */
+ }
+ else
+ {
+ struct uuconf_cmdtab as[CCMDS];
+
+ _uuconf_ucmdtab_base (asCmds, CCMDS, (char *) qglobal->qprocess,
+ as);
+
+ if (zprogram == NULL)
+ zprogram = "uucp";
+
+ si.zname = zprogram;
+ si.qcmds = as;
+ iret = uuconf_cmd_file (qglobal, e, as, (pointer) &si, itprogram,
+ UUCONF_CMDTABFLAG_BACKSLASH,
+ qglobal->pblock);
+
+ (void) fclose (e);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = zcopy;
+ return iret | UUCONF_ERROR_FILENAME;
+ }
+ }
+
+ /* Get the defaults for the file names. */
+
+ iret = itset_default (qglobal, &qglobal->qprocess->pzsysfiles, SYSFILE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = itset_default (qglobal, &qglobal->qprocess->pzportfiles, PORTFILE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = itset_default (qglobal, &qglobal->qprocess->pzdialfiles, DIALFILE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = itset_default (qglobal, &qglobal->qprocess->pzdialcodefiles,
+ DIALCODEFILE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = itset_default (qglobal, &qglobal->qprocess->pzpwdfiles, PASSWDFILE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = itset_default (qglobal, &qglobal->qprocess->pzcallfiles, CALLFILE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+
+ return UUCONF_SUCCESS;
+}
+
+/* Add new strings to a variable. */
+
+/*ARGSUSED*/
+static int
+itadd (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char ***ppz = (char ***) pvar;
+ int i;
+ int iret;
+
+ if (argc == 1)
+ {
+ iret = _uuconf_iadd_string (qglobal, NULL, FALSE, FALSE, ppz,
+ qglobal->pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ else
+ {
+ for (i = 1; i < argc; i++)
+ {
+ iret = _uuconf_iadd_string (qglobal, argv[i], TRUE, FALSE, ppz,
+ qglobal->pblock);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+ }
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Handle an "unknown" command. We accumulate this into a linked
+ list, and only parse them later in uuconf_unknown_system_info. */
+
+/*ARGSUSED*/
+static int
+itunknown (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sunknown **pq = (struct sunknown **) pvar;
+ struct sunknown *q;
+
+ q = (struct sunknown *) uuconf_malloc (qglobal->pblock,
+ sizeof (struct sunknown));
+ if (q == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+ q->qnext = NULL;
+ q->ilineno = qglobal->ilineno;
+ q->cargs = argc - 1;
+ q->pzargs = (char **) uuconf_malloc (qglobal->pblock,
+ (argc - 1) * sizeof (char *));
+ if (q->pzargs == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+ memcpy ((pointer) q->pzargs, (pointer) (argv + 1),
+ (argc - 1) * sizeof (char *));
+
+ while (*pq != NULL)
+ pq = &(*pq)->qnext;
+
+ *pq = q;
+
+ return UUCONF_CMDTABRET_KEEP;
+}
+
+/* If we encounter an unknown command, see if it is the program with
+ which we were invoked. If it was, pass the remaining arguments
+ back through the table. */
+
+/*ARGSUSED*/
+static int
+itprogram (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+
+ if (argc <= 1
+ || strcasecmp (qinfo->zname, argv[0]) != 0)
+ return UUCONF_CMDTABRET_CONTINUE;
+
+ return uuconf_cmd_args (pglobal, argc - 1, argv + 1, qinfo->qcmds,
+ (pointer) NULL, (uuconf_cmdtabfn) NULL, 0,
+ qglobal->pblock);
+}
+
+/* If a filename was not set by the configuration file, add in the
+ default value. */
+
+static int
+itset_default (qglobal, ppzvar, zfile)
+ struct sglobal *qglobal;
+ char ***ppzvar;
+ const char *zfile;
+{
+ size_t clen;
+ char *zadd;
+
+ if (*ppzvar != NULL)
+ return UUCONF_SUCCESS;
+
+ clen = strlen (zfile);
+ zadd = (char *) uuconf_malloc (qglobal->pblock,
+ sizeof NEWCONFIGLIB + clen);
+ if (zadd == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ memcpy ((pointer) zadd, (pointer) NEWCONFIGLIB, sizeof NEWCONFIGLIB - 1);
+ memcpy ((pointer) (zadd + sizeof NEWCONFIGLIB - 1), (pointer) zfile,
+ clen + 1);
+
+ return _uuconf_iadd_string (qglobal, zadd, FALSE, FALSE, ppzvar,
+ qglobal->pblock);
+}
diff --git a/gnu/libexec/uucp/libuuconf/tlocnm.c b/gnu/libexec/uucp/libuuconf/tlocnm.c
new file mode 100644
index 00000000000..bf09446e8f6
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tlocnm.c
@@ -0,0 +1,112 @@
+/* tlocnm.c
+ Get the local name to use from the Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tlocnm_rcsid[] = "$Id: tlocnm.c,v 1.1 1993/08/04 19:35:14 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Get the local name to use, based on the login name, from the Taylor
+ UUCP configuration files. This could probably be done in a
+ slightly more intelligent fashion, but no matter what it has to
+ read the systems files. */
+
+int
+uuconf_taylor_login_localname (pglobal, zlogin, pzname)
+ pointer pglobal;
+ const char *zlogin;
+ char **pzname;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char **pznames, **pz;
+ int iret;
+
+ if (! qglobal->qprocess->fread_syslocs)
+ {
+ iret = _uuconf_iread_locations (qglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ /* As a simple optimization, if there is no "myname" command we can
+ simply return immediately. */
+ if (! qglobal->qprocess->fuses_myname)
+ {
+ *pzname = NULL;
+ return UUCONF_NOT_FOUND;
+ }
+
+ iret = uuconf_taylor_system_names (pglobal, &pznames, 0);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+
+ *pzname = NULL;
+ iret = UUCONF_NOT_FOUND;
+
+ for (pz = pznames; *pz != NULL; pz++)
+ {
+ struct uuconf_system ssys;
+ struct uuconf_system *qsys;
+
+ iret = uuconf_system_info (pglobal, *pz, &ssys);
+ if (iret != UUCONF_SUCCESS)
+ break;
+
+ for (qsys = &ssys; qsys != NULL; qsys = qsys->uuconf_qalternate)
+ {
+ if (qsys->uuconf_zlocalname != NULL
+ && qsys->uuconf_fcalled
+ && qsys->uuconf_zcalled_login != NULL
+ && strcmp (qsys->uuconf_zcalled_login, zlogin) == 0)
+ {
+ *pzname = strdup (qsys->uuconf_zlocalname);
+ if (*pzname != NULL)
+ iret = UUCONF_SUCCESS;
+ else
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ break;
+ }
+ }
+
+ (void) uuconf_system_free (pglobal, &ssys);
+
+ if (qsys != NULL)
+ break;
+
+ iret = UUCONF_NOT_FOUND;
+ }
+
+ for (pz = pznames; *pz != NULL; pz++)
+ free ((pointer) *pz);
+ free ((pointer) pznames);
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/tport.c b/gnu/libexec/uucp/libuuconf/tport.c
new file mode 100644
index 00000000000..0a94a81c112
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tport.c
@@ -0,0 +1,295 @@
+/* tport.c
+ Find a port in the Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tport_rcsid[] = "$Id: tport.c,v 1.1 1993/08/04 19:35:15 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+static int ipport P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int ipunknown P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+
+/* Find a port in the Taylor UUCP configuration files by name, baud
+ rate, and special purpose function. */
+
+int
+uuconf_taylor_find_port (pglobal, zname, ibaud, ihighbaud, pifn, pinfo,
+ qport)
+ pointer pglobal;
+ const char *zname;
+ long ibaud;
+ long ihighbaud;
+ int (*pifn) P((struct uuconf_port *, pointer));
+ pointer pinfo;
+ struct uuconf_port *qport;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ FILE *e;
+ pointer pblock;
+ char *zfree;
+ int iret;
+ char **pz;
+
+ if (ihighbaud == 0L)
+ ihighbaud = ibaud;
+
+ e = NULL;
+ pblock = NULL;
+ zfree = NULL;
+ iret = UUCONF_NOT_FOUND;
+
+ for (pz = qglobal->qprocess->pzportfiles; *pz != NULL; pz++)
+ {
+ struct uuconf_cmdtab as[2];
+ char *zport;
+ struct uuconf_port sdefault;
+ int ilineno;
+
+ e = fopen (*pz, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ continue;
+ qglobal->ierrno = errno;
+ iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ qglobal->ilineno = 0;
+
+ /* Gather the default information from the top of the file. We
+ do this by handling the "port" command ourselves and passing
+ every other command to _uuconf_iport_cmd via ipunknown. The
+ value of zport will be an malloc block. */
+ as[0].uuconf_zcmd = "port";
+ as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 2;
+ as[0].uuconf_pvar = (pointer) &zport;
+ as[0].uuconf_pifn = ipport;
+
+ as[1].uuconf_zcmd = NULL;
+
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ _uuconf_uclear_port (&sdefault);
+ sdefault.uuconf_palloc = pblock;
+ zport = NULL;
+ iret = uuconf_cmd_file (pglobal, e, as, (pointer) &sdefault,
+ ipunknown, UUCONF_CMDTABFLAG_BACKSLASH,
+ pblock);
+ if (iret != UUCONF_SUCCESS)
+ {
+ zfree = zport;
+ break;
+ }
+
+ /* Now skip until we find a port with a matching name. If the
+ zname argument is NULL, we will have to read every port. */
+ iret = UUCONF_NOT_FOUND;
+ while (zport != NULL)
+ {
+ uuconf_cmdtabfn piunknown;
+ boolean fmatch;
+
+ if (zname == NULL || strcmp (zname, zport) == 0)
+ {
+ piunknown = ipunknown;
+ *qport = sdefault;
+ qport->uuconf_zname = zport;
+ zfree = zport;
+ fmatch = TRUE;
+ }
+ else
+ {
+ piunknown = NULL;
+ free ((pointer) zport);
+ fmatch = FALSE;
+ }
+
+ zport = NULL;
+ ilineno = qglobal->ilineno;
+ iret = uuconf_cmd_file (pglobal, e, as, (pointer) qport,
+ piunknown, UUCONF_CMDTABFLAG_BACKSLASH,
+ pblock);
+ qglobal->ilineno += ilineno;
+ if (iret != UUCONF_SUCCESS)
+ break;
+ iret = UUCONF_NOT_FOUND;
+
+ /* We may have just gathered information about a port. See
+ if it matches the name, the baud rate and the special
+ function. */
+ if (fmatch)
+ {
+ if (ibaud != 0)
+ {
+ if (qport->uuconf_ttype == UUCONF_PORTTYPE_MODEM)
+ {
+ long imbaud, imhigh, imlow;
+
+ imbaud = qport->uuconf_u.uuconf_smodem.uuconf_ibaud;
+ imhigh = qport->uuconf_u.uuconf_smodem.uuconf_ihighbaud;
+ imlow = qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud;
+
+ if (imbaud == 0 && imlow == 0)
+ ;
+ else if (ibaud <= imbaud && imbaud <= ihighbaud)
+ ;
+ else if (imlow != 0
+ && imlow <= ihighbaud
+ && imhigh >= ibaud)
+ ;
+ else
+ fmatch = FALSE;
+ }
+ else if (qport->uuconf_ttype == UUCONF_PORTTYPE_DIRECT)
+ {
+ long idbaud;
+
+ idbaud = qport->uuconf_u.uuconf_sdirect.uuconf_ibaud;
+ if (idbaud != 0 && idbaud != ibaud)
+ fmatch = FALSE;
+ }
+ }
+ }
+
+ if (fmatch)
+ {
+ if (pifn != NULL)
+ {
+ iret = (*pifn) (qport, pinfo);
+ if (iret == UUCONF_NOT_FOUND)
+ fmatch = FALSE;
+ else if (iret != UUCONF_SUCCESS)
+ break;
+ }
+ }
+
+ if (fmatch)
+ {
+ if (uuconf_add_block (pblock, zfree) == 0)
+ {
+ zfree = NULL;
+ iret = UUCONF_SUCCESS;
+ }
+ else
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ break;
+ }
+
+ if (zfree != NULL)
+ {
+ free ((pointer) zfree);
+ zfree = NULL;
+ }
+ }
+
+ (void) fclose (e);
+ e = NULL;
+
+ if (iret != UUCONF_NOT_FOUND)
+ break;
+
+ uuconf_free_block (pblock);
+ pblock = NULL;
+ }
+
+ if (e != NULL)
+ (void) fclose (e);
+ if (zfree != NULL)
+ free ((pointer) zfree);
+ if (iret != UUCONF_SUCCESS && pblock != NULL)
+ uuconf_free_block (pblock);
+
+ if (iret != UUCONF_SUCCESS && iret != UUCONF_NOT_FOUND)
+ {
+ qglobal->zfilename = *pz;
+ iret |= UUCONF_ERROR_FILENAME;
+ }
+
+ return iret;
+}
+
+/* Handle a "port" command. This copies the string onto the heap and
+ returns the pointer in *pvar. It returns UUCONF_CMDTABRET_EXIT to
+ force uuconf_cmd_file to stop reading and return to the code above,
+ which will then check the port just read to see if it matches. */
+
+/*ARGSUSED*/
+static int
+ipport (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ char **pz = (char **) pvar;
+ size_t csize;
+
+ csize = strlen (argv[1]) + 1;
+ *pz = malloc (csize);
+ if (*pz == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+ memcpy ((pointer) *pz, (pointer) argv[1], csize);
+ return UUCONF_CMDTABRET_EXIT;
+}
+
+/* Handle an unknown command by passing it on to _uuconf_iport_cmd,
+ which will parse it into the port structure. */
+
+/*ARGSUSED*/
+static int
+ipunknown (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_port *qport = (struct uuconf_port *) pinfo;
+
+ return _uuconf_iport_cmd (qglobal, argc, argv, qport);
+}
diff --git a/gnu/libexec/uucp/libuuconf/tportc.c b/gnu/libexec/uucp/libuuconf/tportc.c
new file mode 100644
index 00000000000..7b796eacb09
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tportc.c
@@ -0,0 +1,465 @@
+/* tportc.c
+ Handle a Taylor UUCP port command.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tportc_rcsid[] = "$Id: tportc.c,v 1.1 1993/08/04 19:35:16 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+static int ipproto_param P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int ipbaud_range P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int ipdialer P((pointer pglobal, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int ipcunknown P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+
+/* The string names of the port types. This array corresponds to the
+ uuconf_porttype enumeration. */
+
+static const char * const azPtype_names[] =
+{
+ NULL,
+ "stdin",
+ "modem",
+ "direct",
+ "tcp",
+ "tli"
+};
+
+#define CPORT_TYPES (sizeof azPtype_names / sizeof azPtype_names[0])
+
+/* The command table for generic port commands. The "port" and "type"
+ commands are handled specially. */
+static const struct cmdtab_offset asPort_cmds[] =
+{
+ { "protocol", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_port, uuconf_zprotocols), NULL },
+ { "protocol-parameter", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct uuconf_port, uuconf_qproto_params), ipproto_param },
+ { "seven-bit", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct uuconf_port, uuconf_ireliable), _uuconf_iseven_bit },
+ { "reliable", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct uuconf_port, uuconf_ireliable), _uuconf_ireliable },
+ { "half-duplex", UUCONF_CMDTABTYPE_FN | 2,
+ offsetof (struct uuconf_port, uuconf_ireliable),
+ _uuconf_ihalf_duplex },
+ { "lockname", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_port, uuconf_zlockname), NULL },
+ { NULL, 0, 0, NULL }
+};
+
+#define CPORT_CMDS (sizeof asPort_cmds / sizeof asPort_cmds[0])
+
+/* The stdin port command table. */
+static const struct cmdtab_offset asPstdin_cmds[] =
+{
+ { NULL, 0, 0, NULL }
+};
+
+#define CSTDIN_CMDS (sizeof asPstdin_cmds / sizeof asPstdin_cmds[0])
+
+/* The modem port command table. */
+static const struct cmdtab_offset asPmodem_cmds[] =
+{
+ { "device", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_smodem.uuconf_zdevice),
+ NULL },
+ { "baud", UUCONF_CMDTABTYPE_LONG,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_smodem.uuconf_ibaud),
+ NULL },
+ { "speed", UUCONF_CMDTABTYPE_LONG,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_smodem.uuconf_ibaud),
+ NULL },
+ { "baud-range", UUCONF_CMDTABTYPE_FN | 3,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_smodem), ipbaud_range },
+ { "speed-range", UUCONF_CMDTABTYPE_FN | 3,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_smodem), ipbaud_range },
+ { "carrier", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_smodem.uuconf_fcarrier),
+ NULL },
+ { "dial-device", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_port,
+ uuconf_u.uuconf_smodem.uuconf_zdial_device),
+ NULL },
+ { "dialer", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_smodem), ipdialer },
+ { "dialer-sequence", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_smodem.uuconf_pzdialer),
+ NULL },
+ { NULL, 0, 0, NULL }
+};
+
+#define CMODEM_CMDS (sizeof asPmodem_cmds / sizeof asPmodem_cmds[0])
+
+/* The direct port command table. */
+static const struct cmdtab_offset asPdirect_cmds[] =
+{
+ { "device", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_sdirect.uuconf_zdevice),
+ NULL },
+ { "baud", UUCONF_CMDTABTYPE_LONG,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_sdirect.uuconf_ibaud),
+ NULL },
+ { "speed", UUCONF_CMDTABTYPE_LONG,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_sdirect.uuconf_ibaud),
+ NULL },
+ { NULL, 0, 0, NULL }
+};
+
+#define CDIRECT_CMDS (sizeof asPdirect_cmds / sizeof asPdirect_cmds[0])
+
+/* The TCP port command table. */
+static const struct cmdtab_offset asPtcp_cmds[] =
+{
+ { "service", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_stcp.uuconf_zport),
+ NULL },
+ { NULL, 0, 0, NULL }
+};
+
+#define CTCP_CMDS (sizeof asPtcp_cmds / sizeof asPtcp_cmds[0])
+
+/* The TLI port command table. */
+static const struct cmdtab_offset asPtli_cmds[] =
+{
+ { "device", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_stli.uuconf_zdevice),
+ NULL },
+ { "stream", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_stli.uuconf_fstream),
+ NULL },
+ { "push", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_stli.uuconf_pzpush),
+ NULL },
+ { "dialer-sequence", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_stli.uuconf_pzdialer),
+ NULL },
+ { "server-address", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_port, uuconf_u.uuconf_stli.uuconf_zservaddr),
+ NULL },
+ { NULL, 0, 0, NULL }
+};
+
+#define CTLI_CMDS (sizeof asPtli_cmds / sizeof asPtli_cmds[0])
+
+#undef max
+#define max(i1, i2) ((i1) > (i2) ? (i1) : (i2))
+#define CCMDS \
+ max (max (max (CPORT_CMDS, CSTDIN_CMDS), CMODEM_CMDS), \
+ max (max (CDIRECT_CMDS, CTCP_CMDS), CTLI_CMDS))
+
+/* Handle a command passed to a port from a Taylor UUCP configuration
+ file. This can be called when reading either the port file or the
+ sys file. The return value may have UUCONF_CMDTABRET_KEEP set, but
+ not UUCONF_CMDTABRET_EXIT. It assigns values to the elements of
+ qport. The first time this is called, qport->uuconf_zname and
+ qport->uuconf_palloc should be set and qport->uuconf_ttype should
+ be UUCONF_PORTTYPE_UNKNOWN. */
+
+int
+_uuconf_iport_cmd (qglobal, argc, argv, qport)
+ struct sglobal *qglobal;
+ int argc;
+ char **argv;
+ struct uuconf_port *qport;
+{
+ boolean fgottype;
+ const struct cmdtab_offset *qcmds;
+ size_t ccmds;
+ struct uuconf_cmdtab as[CCMDS];
+ int i;
+ int iret;
+
+ fgottype = strcasecmp (argv[0], "type") == 0;
+
+ if (fgottype || qport->uuconf_ttype == UUCONF_PORTTYPE_UNKNOWN)
+ {
+ enum uuconf_porttype ttype;
+
+ /* We either just got a "type" command, or this is an
+ uninitialized port. If the first command to a port is not
+ "type", it is assumed to be a modem port. This
+ implementation will actually permit "type" at any point, but
+ will effectively discard any type specific information that
+ appears before the "type" command. This supports defaults,
+ in that the default may be of a specific type while future
+ ports in the same file may be of other types. */
+ if (! fgottype)
+ ttype = UUCONF_PORTTYPE_MODEM;
+ else
+ {
+ if (argc != 2)
+ return UUCONF_SYNTAX_ERROR;
+
+ for (i = 0; i < CPORT_TYPES; i++)
+ if (azPtype_names[i] != NULL
+ && strcasecmp (argv[1], azPtype_names[i]) == 0)
+ break;
+
+ if (i >= CPORT_TYPES)
+ return UUCONF_SYNTAX_ERROR;
+
+ ttype = (enum uuconf_porttype) i;
+ }
+
+ qport->uuconf_ttype = ttype;
+
+ switch (ttype)
+ {
+ default:
+ case UUCONF_PORTTYPE_STDIN:
+ break;
+ case UUCONF_PORTTYPE_MODEM:
+ qport->uuconf_u.uuconf_smodem.uuconf_zdevice = NULL;
+ qport->uuconf_u.uuconf_smodem.uuconf_zdial_device = NULL;
+ qport->uuconf_u.uuconf_smodem.uuconf_ibaud = 0L;
+ qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud = 0L;
+ qport->uuconf_u.uuconf_smodem.uuconf_ihighbaud = 0L;
+ qport->uuconf_u.uuconf_smodem.uuconf_fcarrier = TRUE;
+ qport->uuconf_u.uuconf_smodem.uuconf_pzdialer = NULL;
+ qport->uuconf_u.uuconf_smodem.uuconf_qdialer = NULL;
+ break;
+ case UUCONF_PORTTYPE_DIRECT:
+ qport->uuconf_u.uuconf_sdirect.uuconf_zdevice = NULL;
+ qport->uuconf_u.uuconf_sdirect.uuconf_ibaud = -1;
+ break;
+ case UUCONF_PORTTYPE_TCP:
+ qport->uuconf_u.uuconf_stcp.uuconf_zport = (char *) "uucp";
+ qport->uuconf_ireliable = (UUCONF_RELIABLE_SPECIFIED
+ | UUCONF_RELIABLE_ENDTOEND
+ | UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT
+ | UUCONF_RELIABLE_FULLDUPLEX);
+ break;
+ case UUCONF_PORTTYPE_TLI:
+ qport->uuconf_u.uuconf_stli.uuconf_zdevice = NULL;
+ qport->uuconf_u.uuconf_stli.uuconf_fstream = FALSE;
+ qport->uuconf_u.uuconf_stli.uuconf_pzpush = NULL;
+ qport->uuconf_u.uuconf_stli.uuconf_pzdialer = NULL;
+ qport->uuconf_u.uuconf_stli.uuconf_zservaddr = NULL;
+ qport->uuconf_ireliable = (UUCONF_RELIABLE_SPECIFIED
+ | UUCONF_RELIABLE_ENDTOEND
+ | UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT
+ | UUCONF_RELIABLE_FULLDUPLEX);
+ break;
+ }
+
+ if (fgottype)
+ return UUCONF_CMDTABRET_CONTINUE;
+ }
+
+ /* See if this command is one of the generic ones. */
+ qcmds = asPort_cmds;
+ ccmds = CPORT_CMDS;
+
+ for (i = 0; i < CPORT_CMDS - 1; i++)
+ if (strcasecmp (argv[0], asPort_cmds[i].zcmd) == 0)
+ break;
+
+ if (i >= CPORT_CMDS - 1)
+ {
+ /* It's not a generic command, so we must check the type
+ specific commands. */
+ switch (qport->uuconf_ttype)
+ {
+ case UUCONF_PORTTYPE_STDIN:
+ qcmds = asPstdin_cmds;
+ ccmds = CSTDIN_CMDS;
+ break;
+ case UUCONF_PORTTYPE_MODEM:
+ qcmds = asPmodem_cmds;
+ ccmds = CMODEM_CMDS;
+ break;
+ case UUCONF_PORTTYPE_DIRECT:
+ qcmds = asPdirect_cmds;
+ ccmds = CDIRECT_CMDS;
+ break;
+ case UUCONF_PORTTYPE_TCP:
+ qcmds = asPtcp_cmds;
+ ccmds = CTCP_CMDS;
+ break;
+ case UUCONF_PORTTYPE_TLI:
+ qcmds = asPtli_cmds;
+ ccmds = CTLI_CMDS;
+ break;
+ default:
+ return UUCONF_SYNTAX_ERROR;
+ }
+ }
+
+ /* Copy the command table onto the stack and modify it to point to
+ qport. */
+ _uuconf_ucmdtab_base (qcmds, ccmds, (char *) qport, as);
+
+ iret = uuconf_cmd_args ((pointer) qglobal, argc, argv, as,
+ (pointer) qport, ipcunknown, 0,
+ qport->uuconf_palloc);
+
+ return iret &~ UUCONF_CMDTABRET_EXIT;
+}
+
+/* Handle the "protocol-parameter" command. */
+
+static int
+ipproto_param (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_proto_param **pqparam = (struct uuconf_proto_param **) pvar;
+ struct uuconf_port *qport = (struct uuconf_port *) pinfo;
+
+ return _uuconf_iadd_proto_param (qglobal, argc - 1, argv + 1, pqparam,
+ qport->uuconf_palloc);
+}
+
+/* Handle the "baud-range" command. */
+
+/*ARGSUSED*/
+static int
+ipbaud_range (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_modem_port *qmodem = (struct uuconf_modem_port *) pvar;
+ int iret;
+
+ iret = _uuconf_iint (qglobal, argv[1],
+ (pointer) &qmodem->uuconf_ilowbaud, FALSE);
+ if ((iret &~ UUCONF_CMDTABRET_KEEP) != UUCONF_SUCCESS)
+ return iret;
+
+ iret |= _uuconf_iint (qglobal, argv[2],
+ (pointer) &qmodem->uuconf_ihighbaud, FALSE);
+
+ return iret;
+}
+
+/* Handle the "dialer" command. If there is one argument, this names
+ a dialer. Otherwise, the remaining arguments form a command
+ describing the dialer. */
+
+static int
+ipdialer (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_modem_port *qmodem = (struct uuconf_modem_port *) pvar;
+ struct uuconf_port *qport = (struct uuconf_port *) pinfo;
+ int iret;
+
+ if (argc < 2)
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ if (argc > 2)
+ {
+ if (qmodem->uuconf_qdialer == NULL)
+ {
+ struct uuconf_dialer *qnew;
+ size_t clen;
+
+ qnew = ((struct uuconf_dialer *)
+ uuconf_malloc (qport->uuconf_palloc,
+ sizeof (struct uuconf_dialer)));
+ if (qnew == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ _uuconf_uclear_dialer (qnew);
+
+ clen = strlen (qport->uuconf_zname);
+ qnew->uuconf_zname = (char *) uuconf_malloc (qport->uuconf_palloc,
+ (clen
+ + sizeof " dialer"));
+ if (qnew->uuconf_zname == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ memcpy ((pointer) qnew->uuconf_zname,
+ (pointer) qport->uuconf_zname, clen);
+ memcpy ((pointer) (qnew->uuconf_zname + clen), (pointer) " dialer",
+ sizeof " dialer");
+
+ qnew->uuconf_palloc = qport->uuconf_palloc;
+
+ qmodem->uuconf_qdialer = qnew;
+ }
+
+ iret = _uuconf_idialer_cmd (qglobal, argc - 1, argv + 1,
+ qmodem->uuconf_qdialer);
+ if ((iret &~ UUCONF_CMDTABRET_KEEP) != UUCONF_SUCCESS)
+ iret |= UUCONF_CMDTABRET_EXIT;
+ return iret;
+ }
+ else
+ {
+ qmodem->uuconf_pzdialer = NULL;
+ iret = _uuconf_iadd_string (qglobal, argv[1], TRUE, FALSE,
+ &qmodem->uuconf_pzdialer,
+ qport->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ iret |= UUCONF_CMDTABRET_EXIT;
+ return iret;
+ }
+}
+
+/* Give an error for an unknown port command. */
+
+/*ARGSUSED*/
+static int
+ipcunknown (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+}
diff --git a/gnu/libexec/uucp/libuuconf/tsinfo.c b/gnu/libexec/uucp/libuuconf/tsinfo.c
new file mode 100644
index 00000000000..5e31ca2c2d3
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tsinfo.c
@@ -0,0 +1,922 @@
+/* tsinfo.c
+ Get information about a system from the Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tsinfo_rcsid[] = "$Id: tsinfo.c,v 1.1 1993/08/04 19:35:18 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+
+static void uiset_call P((struct uuconf_system *qsys));
+static int iisizecmp P((long i1, long i2));
+
+/* Local functions needed to parse the system information file. */
+
+#define CMDTABFN(z) \
+ static int z P((pointer, int, char **, pointer, pointer))
+
+CMDTABFN (iisystem);
+CMDTABFN (iialias);
+CMDTABFN (iialternate);
+CMDTABFN (iidefault_alternates);
+CMDTABFN (iitime);
+CMDTABFN (iitimegrade);
+CMDTABFN (iisize);
+CMDTABFN (iibaud_range);
+CMDTABFN (iiport);
+CMDTABFN (iichat);
+CMDTABFN (iicalled_login);
+CMDTABFN (iiproto_param);
+CMDTABFN (iirequest);
+CMDTABFN (iitransfer);
+CMDTABFN (iiforward);
+CMDTABFN (iiunknown);
+
+#undef CMDTABFN
+
+/* We have to pass a fair amount of information in and out of the
+ various system commands. Using global variables would make the
+ code non-reentrant, so we instead pass a pointer to single
+ structure as the pinfo argument to the system commands. */
+
+struct sinfo
+{
+ /* The system information we're building up. */
+ struct uuconf_system *qsys;
+ /* Whether any alternates have been used. */
+ boolean falternates;
+ /* A list of the previous alternates. */
+ struct uuconf_system salternate;
+ /* Whether to use extra alternates from the file wide defaults. */
+ int fdefault_alternates;
+};
+
+/* The command table for system commands. */
+static const struct cmdtab_offset asIcmds[] =
+{
+ { "system", UUCONF_CMDTABTYPE_FN | 2, (size_t) -1, iisystem },
+ { "alias", UUCONF_CMDTABTYPE_FN | 2, (size_t) -1, iialias },
+ { "alternate", UUCONF_CMDTABTYPE_FN | 0, (size_t) -1, iialternate },
+ { "default-alternates", UUCONF_CMDTABTYPE_FN | 2, (size_t) -1,
+ iidefault_alternates },
+ { "time", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct uuconf_system, uuconf_qtimegrade), iitime },
+ { "timegrade", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct uuconf_system, uuconf_qtimegrade), iitimegrade },
+ { "max-retries", UUCONF_CMDTABTYPE_INT,
+ offsetof (struct uuconf_system, uuconf_cmax_retries), NULL },
+ { "success-wait", UUCONF_CMDTABTYPE_INT,
+ offsetof (struct uuconf_system, uuconf_csuccess_wait), NULL },
+ { "call-timegrade", UUCONF_CMDTABTYPE_FN | 3,
+ offsetof (struct uuconf_system, uuconf_qcalltimegrade), iitimegrade },
+ { "call-local-size", UUCONF_CMDTABTYPE_FN | 3,
+ offsetof (struct uuconf_system, uuconf_qcall_local_size), iisize },
+ { "call-remote-size", UUCONF_CMDTABTYPE_FN | 3,
+ offsetof (struct uuconf_system, uuconf_qcall_remote_size), iisize },
+ { "called-local-size", UUCONF_CMDTABTYPE_FN | 3,
+ offsetof (struct uuconf_system, uuconf_qcalled_local_size), iisize },
+ { "called-remote-size", UUCONF_CMDTABTYPE_FN | 3,
+ offsetof (struct uuconf_system, uuconf_qcalled_remote_size), iisize },
+ { "timetable", UUCONF_CMDTABTYPE_FN | 3, (size_t) -1, _uuconf_itimetable },
+ { "baud", UUCONF_CMDTABTYPE_LONG,
+ offsetof (struct uuconf_system, uuconf_ibaud), NULL },
+ { "speed", UUCONF_CMDTABTYPE_LONG,
+ offsetof (struct uuconf_system, uuconf_ibaud), NULL },
+ { "baud-range", UUCONF_CMDTABTYPE_FN | 3, 0, iibaud_range },
+ { "speed-range", UUCONF_CMDTABTYPE_FN | 3, 0, iibaud_range },
+ { "port", UUCONF_CMDTABTYPE_FN | 0, (size_t) -1, iiport },
+ { "phone", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_system, uuconf_zphone), NULL },
+ { "address", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_system, uuconf_zphone), NULL },
+ { "chat", UUCONF_CMDTABTYPE_PREFIX | 0,
+ offsetof (struct uuconf_system, uuconf_schat), iichat },
+ { "call-login", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_system, uuconf_zcall_login), NULL },
+ { "call-password", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_system, uuconf_zcall_password), NULL },
+ { "called-login", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct uuconf_system, uuconf_zcalled_login), iicalled_login },
+ { "callback", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_system, uuconf_fcallback), NULL },
+ { "sequence", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_system, uuconf_fsequence), NULL },
+ { "protocol", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_system, uuconf_zprotocols), NULL },
+ { "protocol-parameter", UUCONF_CMDTABTYPE_FN | 0,
+ offsetof (struct uuconf_system, uuconf_qproto_params), iiproto_param },
+ { "called-chat", UUCONF_CMDTABTYPE_PREFIX | 0,
+ offsetof (struct uuconf_system, uuconf_scalled_chat), iichat },
+ { "debug", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_system, uuconf_zdebug), NULL },
+ { "max-remote-debug", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_system, uuconf_zmax_remote_debug), NULL },
+ { "send-request", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_system, uuconf_fsend_request), NULL },
+ { "receive-request", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_system, uuconf_frec_request), NULL },
+ { "request", UUCONF_CMDTABTYPE_FN | 2, (size_t) -1, iirequest },
+ { "call-transfer", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_system, uuconf_fcall_transfer), NULL },
+ { "called-transfer", UUCONF_CMDTABTYPE_BOOLEAN,
+ offsetof (struct uuconf_system, uuconf_fcalled_transfer), NULL },
+ { "transfer", UUCONF_CMDTABTYPE_FN | 2, (size_t) -1, iitransfer },
+ { "local-send", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_system, uuconf_pzlocal_send), NULL },
+ { "remote-send", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_system, uuconf_pzremote_send), NULL },
+ { "local-receive", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_system, uuconf_pzlocal_receive), NULL },
+ { "remote-receive", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_system, uuconf_pzremote_receive), NULL },
+ { "command-path", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_system, uuconf_pzpath), NULL },
+ { "commands", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_system, uuconf_pzcmds), NULL },
+ { "free-space", UUCONF_CMDTABTYPE_LONG,
+ offsetof (struct uuconf_system, uuconf_cfree_space), NULL },
+ { "forward-from", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_system, uuconf_pzforward_from), NULL },
+ { "forward-to", UUCONF_CMDTABTYPE_FULLSTRING,
+ offsetof (struct uuconf_system, uuconf_pzforward_to), NULL },
+ { "forward", UUCONF_CMDTABTYPE_FN | 0, (size_t) -1, iiforward },
+ { "pubdir", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_system, uuconf_zpubdir), NULL },
+ { "myname", UUCONF_CMDTABTYPE_STRING,
+ offsetof (struct uuconf_system, uuconf_zlocalname), NULL },
+ { NULL, 0, 0, NULL }
+};
+
+#define CSYSTEM_CMDS (sizeof asIcmds / sizeof asIcmds[0])
+
+/* Get information about the system zsystem from the Taylor UUCP
+ configuration files. Sets *qsys. This does not ensure that all
+ default information is set. */
+
+int
+_uuconf_itaylor_system_internal (qglobal, zsystem, qsys)
+ struct sglobal *qglobal;
+ const char *zsystem;
+ struct uuconf_system *qsys;
+{
+ int iret;
+ struct stsysloc *qloc;
+ struct uuconf_cmdtab as[CSYSTEM_CMDS];
+ struct sinfo si;
+ struct uuconf_system sdefaults;
+
+ if (! qglobal->qprocess->fread_syslocs)
+ {
+ iret = _uuconf_iread_locations (qglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ /* Find the system in the list of locations. */
+ for (qloc = qglobal->qprocess->qsyslocs; qloc != NULL; qloc = qloc->qnext)
+ if (qloc->zname[0] == zsystem[0]
+ && strcmp (qloc->zname, zsystem) == 0)
+ break;
+ if (qloc == NULL)
+ return UUCONF_NOT_FOUND;
+
+ /* If this is an alias, then the real system is the next non-alias
+ in the list. */
+ while (qloc->falias)
+ {
+ qloc = qloc->qnext;
+ if (qloc == NULL)
+ return UUCONF_NOT_FOUND;
+ }
+
+ _uuconf_ucmdtab_base (asIcmds, CSYSTEM_CMDS, (char *) qsys, as);
+
+ rewind (qloc->e);
+
+ /* Read the file wide defaults from the start of the file. */
+ _uuconf_uclear_system (qsys);
+
+ si.qsys = qsys;
+ si.falternates = FALSE;
+ si.fdefault_alternates = TRUE;
+ qsys->uuconf_palloc = uuconf_malloc_block ();
+ if (qsys->uuconf_palloc == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ iret = uuconf_cmd_file ((pointer) qglobal, qloc->e, as, (pointer) &si,
+ iiunknown, UUCONF_CMDTABFLAG_BACKSLASH,
+ qsys->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = qloc->zfile;
+ return iret | UUCONF_ERROR_FILENAME;
+ }
+
+ if (! si.falternates)
+ uiset_call (qsys);
+ else
+ {
+ /* Attach the final alternate. */
+ iret = iialternate ((pointer) qglobal, 0, (char **) NULL,
+ (pointer) NULL, (pointer) &si);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ /* Save off the defaults. */
+ sdefaults = *qsys;
+
+ /* Advance to the information for the system we want. */
+ if (fseek (qloc->e, qloc->iloc, SEEK_SET) != 0)
+ {
+ qglobal->ierrno = errno;
+ qglobal->zfilename = qloc->zfile;
+ return (UUCONF_FSEEK_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_ERROR_FILENAME);
+ }
+
+ /* Read in the system we want. */
+ _uuconf_uclear_system (qsys);
+ qsys->uuconf_zname = (char *) qloc->zname;
+ qsys->uuconf_palloc = sdefaults.uuconf_palloc;
+
+ si.falternates = FALSE;
+
+ iret = uuconf_cmd_file (qglobal, qloc->e, as, (pointer) &si, iiunknown,
+ UUCONF_CMDTABFLAG_BACKSLASH, qsys->uuconf_palloc);
+ qglobal->ilineno += qloc->ilineno;
+
+ if (iret == UUCONF_SUCCESS)
+ {
+ if (! si.falternates)
+ uiset_call (qsys);
+ else
+ iret = iialternate ((pointer) qglobal, 0, (char **) NULL,
+ (pointer) NULL, (pointer) &si);
+ }
+
+ /* Merge in the defaults. */
+ if (iret == UUCONF_SUCCESS)
+ iret = _uuconf_isystem_default (qglobal, qsys, &sdefaults,
+ si.fdefault_alternates);
+
+ /* The first alternate is always available for calling in. */
+ if (iret == UUCONF_SUCCESS)
+ qsys->uuconf_fcalled = TRUE;
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = qloc->zfile;
+ iret |= UUCONF_ERROR_FILENAME;
+ }
+
+ return iret;
+}
+
+/* Set the fcall and fcalled field for the system. This marks a
+ particular alternate for use when calling out or calling in. This
+ is where we implement the semantics described in the documentation:
+ a change to a relevant field implies that the alternate is used.
+ If all the relevant fields are unchanged, the alternate is not
+ used. */
+
+static void
+uiset_call (qsys)
+ struct uuconf_system *qsys;
+{
+ qsys->uuconf_fcall =
+ (qsys->uuconf_qtimegrade != (struct uuconf_timespan *) &_uuconf_unset
+ || qsys->uuconf_zport != (char *) &_uuconf_unset
+ || qsys->uuconf_qport != (struct uuconf_port *) &_uuconf_unset
+ || qsys->uuconf_ibaud >= 0
+ || qsys->uuconf_zphone != (char *) &_uuconf_unset
+ || qsys->uuconf_schat.uuconf_pzchat != (char **) &_uuconf_unset
+ || qsys->uuconf_schat.uuconf_pzprogram != (char **) &_uuconf_unset);
+
+ qsys->uuconf_fcalled =
+ qsys->uuconf_zcalled_login != (char *) &_uuconf_unset;
+}
+
+/* Handle the "system" command. Because we skip directly to the
+ system we want to read, a "system" command means we've reached the
+ end of it. */
+
+static int
+iisystem (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ return UUCONF_CMDTABRET_EXIT;
+}
+
+/* Handle the "alias" command. */
+
+/*ARGSUSED*/
+static int
+iialias (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+ int iret;
+
+ iret = _uuconf_iadd_string (qglobal, argv[1], TRUE, FALSE,
+ &qinfo->qsys->uuconf_pzalias,
+ qinfo->qsys->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ iret |= UUCONF_CMDTABRET_EXIT;
+ return iret;
+}
+
+/* Handle the "alternate" command. The information just read is in
+ sIhold. If this is the first "alternate" command for this system,
+ we save off the current information in sIalternate. Otherwise we
+ default this information to sIalternate, and then add it to the end
+ of the list of alternates in sIalternate. */
+
+static int
+iialternate (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+
+ uiset_call (qinfo->qsys);
+
+ if (! qinfo->falternates)
+ {
+ qinfo->salternate = *qinfo->qsys;
+ qinfo->falternates = TRUE;
+ }
+ else
+ {
+ int iret;
+ struct uuconf_system *qnew, **pq;
+
+ iret = _uuconf_isystem_default (qglobal, qinfo->qsys,
+ &qinfo->salternate, FALSE);
+ if (iret != UUCONF_SUCCESS)
+ return iret | UUCONF_CMDTABRET_EXIT;
+ qnew = ((struct uuconf_system *)
+ uuconf_malloc (qinfo->qsys->uuconf_palloc,
+ sizeof (struct uuconf_system)));
+ if (qnew == NULL)
+ {
+ qglobal->ierrno = errno;;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+ *qnew = *qinfo->qsys;
+ for (pq = &qinfo->salternate.uuconf_qalternate;
+ *pq != NULL;
+ pq = &(*pq)->uuconf_qalternate)
+ ;
+ *pq = qnew;
+ }
+
+ /* If this is the last alternate command, move the information back
+ to qinfo->qsys. */
+ if (argc == 0)
+ *qinfo->qsys = qinfo->salternate;
+ else
+ {
+ _uuconf_uclear_system (qinfo->qsys);
+ qinfo->qsys->uuconf_zname = qinfo->salternate.uuconf_zname;
+ qinfo->qsys->uuconf_palloc = qinfo->salternate.uuconf_palloc;
+ if (argc > 1)
+ {
+ qinfo->qsys->uuconf_zalternate = argv[1];
+ return UUCONF_CMDTABRET_KEEP;
+ }
+ }
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Handle the "default-alternates" command. This just takes a boolean
+ argument which is used to set the fdefault_alternates field of the
+ sinfo structure. */
+
+/*ARGSUSED*/
+static int
+iidefault_alternates (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+
+ return _uuconf_iboolean (qglobal, argv[1], &qinfo->fdefault_alternates);
+}
+
+/* Handle the "time" command. We do this by turning it into a
+ "timegrade" command with a grade of BGRADE_LOW. The first argument
+ is a time string, and the optional second argument is the retry
+ time. */
+
+/*ARGSUSED*/
+static int
+iitime (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ char *aznew[4];
+ char ab[2];
+
+ if (argc != 2 && argc != 3)
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ aznew[0] = argv[0];
+ ab[0] = UUCONF_GRADE_LOW;
+ ab[1] = '\0';
+ aznew[1] = ab;
+ aznew[2] = argv[1];
+ if (argc > 2)
+ aznew[3] = argv[2];
+
+ return iitimegrade (pglobal, argc + 1, aznew, pvar, pinfo);
+}
+
+/* Handle the "timegrade" command by calling _uuconf_itime_parse with
+ appropriate ival (the work grade) and cretry (the retry time)
+ arguments. */
+
+static int
+iitimegrade (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_timespan **pqspan = (struct uuconf_timespan **) pvar;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+ int cretry;
+ int iret;
+
+ if (argc < 3 || argc > 4)
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ if (argv[1][1] != '\0' || ! UUCONF_GRADE_LEGAL (argv[1][0]))
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+
+ if (argc == 3)
+ cretry = 0;
+ else
+ {
+ iret = _uuconf_iint (qglobal, argv[3], (pointer) &cretry, TRUE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ iret = _uuconf_itime_parse (qglobal, argv[2], (long) argv[1][0],
+ cretry, _uuconf_itime_grade_cmp, pqspan,
+ qinfo->qsys->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ iret |= UUCONF_CMDTABRET_EXIT;
+ return iret;
+}
+
+/* Handle the "baud-range" command, also known as "speed-range". */
+
+static int
+iibaud_range (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_system *qsys = (struct uuconf_system *) pvar;
+ int iret;
+
+ iret = _uuconf_iint (qglobal, argv[1], (pointer) &qsys->uuconf_ibaud,
+ FALSE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ return _uuconf_iint (qglobal, argv[2], (pointer) &qsys->uuconf_ihighbaud,
+ FALSE);
+}
+
+/* Handle one of the size commands ("call-local-size", etc.). The
+ first argument is a number of bytes, and the second argument is a
+ time string. The pvar argument points to the string array to which
+ we add this new string. */
+
+/*ARGSUSED*/
+static int
+iisize (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_timespan **pqspan = (struct uuconf_timespan **) pvar;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+ long ival;
+ int iret;
+
+ iret = _uuconf_iint (qglobal, argv[1], (pointer) &ival, FALSE);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+
+ iret = _uuconf_itime_parse (qglobal, argv[2], ival, 0, iisizecmp,
+ pqspan, qinfo->qsys->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ iret |= UUCONF_CMDTABRET_EXIT;
+ return iret;
+}
+
+/* A comparison function for sizes to pass to _uuconf_itime_parse. */
+
+static int
+iisizecmp (i1, i2)
+ long i1;
+ long i2;
+{
+ /* We can't just return i1 - i2 because that would be a long. */
+ if (i1 < i2)
+ return -1;
+ else if (i1 == i2)
+ return 0;
+ else
+ return 1;
+}
+
+/* Handle the "port" command. If there is one argument, this names a
+ port. Otherwise, the remaining arguments form a command describing
+ the port. */
+
+/*ARGSUSED*/
+static int
+iiport (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+
+ if (argc < 2)
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+ else if (argc == 2)
+ {
+ qinfo->qsys->uuconf_zport = argv[1];
+ return UUCONF_CMDTABRET_KEEP;
+ }
+ else
+ {
+ int iret;
+
+ if (qinfo->qsys->uuconf_qport
+ == (struct uuconf_port *) &_uuconf_unset)
+ {
+ struct uuconf_port *qnew;
+
+ qnew = ((struct uuconf_port *)
+ uuconf_malloc (qinfo->qsys->uuconf_palloc,
+ sizeof (struct uuconf_port)));
+ if (qnew == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ _uuconf_uclear_port (qnew);
+
+ if (qinfo->qsys->uuconf_zname == NULL)
+ qnew->uuconf_zname = (char *) "default system file port";
+ else
+ {
+ char *zname;
+ size_t clen;
+
+ clen = strlen (qinfo->qsys->uuconf_zname);
+ zname = (char *) uuconf_malloc (qinfo->qsys->uuconf_palloc,
+ clen + sizeof "system port");
+ if (zname == NULL)
+ {
+ qglobal->ierrno = errno;
+ return (UUCONF_MALLOC_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_CMDTABRET_EXIT);
+ }
+
+ memcpy ((pointer) zname, (pointer) "system ",
+ sizeof "system " - 1);
+ memcpy ((pointer) (zname + sizeof "system " - 1),
+ (pointer) qinfo->qsys->uuconf_zname,
+ clen);
+ memcpy ((pointer) (zname + sizeof "system " - 1 + clen),
+ (pointer) " port", sizeof " port");
+
+ qnew->uuconf_zname = zname;
+ }
+
+ qnew->uuconf_palloc = qinfo->qsys->uuconf_palloc;
+
+ qinfo->qsys->uuconf_qport = qnew;
+ }
+
+ iret = _uuconf_iport_cmd (qglobal, argc - 1, argv + 1,
+ qinfo->qsys->uuconf_qport);
+ if (UUCONF_ERROR_VALUE (iret) != UUCONF_SUCCESS)
+ iret |= UUCONF_CMDTABRET_EXIT;
+ return iret;
+ }
+}
+
+/* Handle the "chat" and "called-chat" set of commands. These just
+ hand off to the generic chat script function. */
+
+static int
+iichat (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+ struct uuconf_chat *qchat = (struct uuconf_chat *) pvar;
+ int iret;
+
+ iret = _uuconf_ichat_cmd (qglobal, argc, argv, qchat,
+ qinfo->qsys->uuconf_palloc);
+ if (UUCONF_ERROR_VALUE (iret) != UUCONF_SUCCESS)
+ iret |= UUCONF_CMDTABRET_EXIT;
+ return iret;
+}
+
+/* Handle the "called-login" command. This only needs to be in a
+ function because there can be additional arguments listing the
+ remote systems which are permitted to use this login name. The
+ additional arguments are not actually handled here; they are
+ handled by uuconf_taylor_system_names, which already has to go
+ through all the system files. */
+
+/*ARGSUSED*/
+static int
+iicalled_login (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ char **pz = (char **) pvar;
+
+ if (argc < 2)
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+ *pz = argv[1];
+ return UUCONF_CMDTABRET_KEEP;
+}
+
+/* Handle the "protocol-parameter" command. This just hands off to
+ the generic protocol parameter handler. */
+
+static int
+iiproto_param (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_proto_param **pqparam = (struct uuconf_proto_param **) pvar;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+
+ if (*pqparam == (struct uuconf_proto_param *) &_uuconf_unset)
+ *pqparam = NULL;
+ return _uuconf_iadd_proto_param (qglobal, argc - 1, argv + 1, pqparam,
+ qinfo->qsys->uuconf_palloc);
+}
+
+/* Handle the "request" command. This is equivalent to specifying
+ both "call-request" and "called-request". */
+
+/*ARGSUSED*/
+static int
+iirequest (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+ int iret;
+
+ iret = _uuconf_iboolean (qglobal, argv[1],
+ &qinfo->qsys->uuconf_fsend_request);
+ if (UUCONF_ERROR_VALUE (iret) == UUCONF_SUCCESS)
+ qinfo->qsys->uuconf_frec_request = qinfo->qsys->uuconf_fsend_request;
+
+ return iret;
+}
+
+/* Handle the "transfer" command. This is equivalent to specifying
+ both "call-transfer" and "called-transfer". */
+
+/*ARGSUSED*/
+static int
+iitransfer (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+ int iret;
+
+ iret = _uuconf_iboolean (qglobal, argv[1],
+ &qinfo->qsys->uuconf_fcall_transfer);
+ if (UUCONF_ERROR_VALUE (iret) == UUCONF_SUCCESS)
+ qinfo->qsys->uuconf_fcalled_transfer = qinfo->qsys->uuconf_fcall_transfer;
+
+ return iret;
+}
+
+/* Handle the "forward" command. This is equivalent to specifying
+ both "forward-from" and "forward-to". */
+
+/*ARGSUSED*/
+static int
+iiforward (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct sinfo *qinfo = (struct sinfo *) pinfo;
+ struct uuconf_system *qsys;
+ int i;
+ int iret;
+
+ qsys = qinfo->qsys;
+ qsys->uuconf_pzforward_from = NULL;
+ qsys->uuconf_pzforward_to = NULL;
+ for (i = 1; i < argc; i++)
+ {
+ iret = _uuconf_iadd_string (qglobal, argv[i], FALSE, FALSE,
+ &qsys->uuconf_pzforward_to,
+ qsys->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret | UUCONF_CMDTABRET_KEEP | UUCONF_CMDTABRET_EXIT;
+ iret = _uuconf_iadd_string (qglobal, argv[i], FALSE, FALSE,
+ &qsys->uuconf_pzforward_from,
+ qsys->uuconf_palloc);
+ if (iret != UUCONF_SUCCESS)
+ return iret | UUCONF_CMDTABRET_KEEP | UUCONF_CMDTABRET_EXIT;
+ }
+
+ return UUCONF_CMDTABRET_KEEP;
+}
+
+/* Handle an unknown command. This should probably be done more
+ intelligently. */
+
+/*ARGSUSED*/
+static int
+iiunknown (pglobal, argc, argv, pvar, pinfo)
+ pointer pglobal;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
+}
+
+/* Return information for an unknown system. It would be better to
+ put this in a different file, but it would require breaking several
+ functions out of this file. Perhaps I will do it sometime. */
+
+int
+uuconf_taylor_system_unknown (pglobal, qsys)
+ pointer pglobal;
+ struct uuconf_system *qsys;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct uuconf_cmdtab as[CSYSTEM_CMDS];
+ struct sinfo si;
+ struct sunknown *q;
+ int iret;
+
+ if (qglobal->qprocess->qunknown == NULL)
+ return UUCONF_NOT_FOUND;
+
+ _uuconf_ucmdtab_base (asIcmds, CSYSTEM_CMDS, (char *) qsys, as);
+
+ _uuconf_uclear_system (qsys);
+
+ si.qsys = qsys;
+ si.falternates = FALSE;
+ si.fdefault_alternates = TRUE;
+ qsys->uuconf_palloc = uuconf_malloc_block ();
+ if (qsys->uuconf_palloc == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ for (q = qglobal->qprocess->qunknown; q != NULL; q = q->qnext)
+ {
+ iret = uuconf_cmd_args (pglobal, q->cargs, q->pzargs, as,
+ (pointer) &si, iiunknown,
+ UUCONF_CMDTABFLAG_BACKSLASH,
+ qsys->uuconf_palloc);
+ iret &=~ UUCONF_CMDTABRET_KEEP;
+ if (UUCONF_ERROR_VALUE (iret) != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = qglobal->qprocess->zconfigfile;
+ qglobal->ilineno = q->ilineno;
+ return ((iret &~ UUCONF_CMDTABRET_EXIT)
+ | UUCONF_ERROR_FILENAME
+ | UUCONF_ERROR_LINENO);
+ }
+ if ((iret & UUCONF_CMDTABRET_EXIT) != 0)
+ break;
+ }
+
+ if (! si.falternates)
+ uiset_call (qsys);
+ else
+ {
+ iret = iialternate (pglobal, 0, (char **) NULL, (pointer) NULL,
+ (pointer) &si);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ /* The first alternate is always available for calling in. */
+ qsys->uuconf_fcalled = TRUE;
+
+ return _uuconf_isystem_basic_default (qglobal, qsys);
+}
diff --git a/gnu/libexec/uucp/libuuconf/tsnams.c b/gnu/libexec/uucp/libuuconf/tsnams.c
new file mode 100644
index 00000000000..c0f96e53f61
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tsnams.c
@@ -0,0 +1,84 @@
+/* tsnams.c
+ Get all known system names from the Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tsnams_rcsid[] = "$Id: tsnams.c,v 1.1 1993/08/04 19:35:19 jtc Exp $";
+#endif
+
+/* Get all the system names from the Taylor UUCP configuration files.
+ These were actually already recorded by uuconf_taylor_init, so this
+ function is pretty simple. */
+
+int
+uuconf_taylor_system_names (pglobal, ppzsystems, falias)
+ pointer pglobal;
+ char ***ppzsystems;
+ int falias;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+ register struct stsysloc *q;
+ char **pz;
+ int c, i;
+
+ if (! qglobal->qprocess->fread_syslocs)
+ {
+ iret = _uuconf_iread_locations (qglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ *ppzsystems = NULL;
+ c = 0;
+
+ for (q = qglobal->qprocess->qsyslocs; q != NULL; q = q->qnext)
+ {
+ if (! falias && q->falias)
+ continue;
+
+ iret = _uuconf_iadd_string (qglobal, (char *) q->zname, TRUE, FALSE,
+ ppzsystems, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ ++c;
+ }
+
+ /* The order of the qSyslocs list is reversed from the list in the
+ configuration files. Reverse the returned list in order to make
+ uuname output more intuitive. */
+ pz = *ppzsystems;
+ for (i = c / 2 - 1; i >= 0; i--)
+ {
+ char *zhold;
+
+ zhold = pz[i];
+ pz[i] = pz[c - i - 1];
+ pz[c - i - 1] = zhold;
+ }
+
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/tsys.c b/gnu/libexec/uucp/libuuconf/tsys.c
new file mode 100644
index 00000000000..6a1f6621092
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tsys.c
@@ -0,0 +1,49 @@
+/* tsys.c
+ User function to get a system from the Taylor UUCP configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tsys_rcsid[] = "$Id: tsys.c,v 1.1 1993/08/04 19:35:20 jtc Exp $";
+#endif
+
+/* Get system information from the Taylor UUCP configuration files.
+ This is a wrapper for the internal function which makes sure that
+ every field gets a default value. */
+
+int
+uuconf_taylor_system_info (pglobal, zsystem, qsys)
+ pointer pglobal;
+ const char *zsystem;
+ struct uuconf_system *qsys;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+
+ iret = _uuconf_itaylor_system_internal (qglobal, zsystem, qsys);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ return _uuconf_isystem_basic_default (qglobal, qsys);
+}
diff --git a/gnu/libexec/uucp/libuuconf/tval.c b/gnu/libexec/uucp/libuuconf/tval.c
new file mode 100644
index 00000000000..be8769612dd
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/tval.c
@@ -0,0 +1,71 @@
+/* tval.c
+ Validate a login name for a system using Taylor UUCP files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_tval_rcsid[] = "$Id: tval.c,v 1.1 1993/08/04 19:35:21 jtc Exp $";
+#endif
+
+/* Validate a login name for a system using Taylor UUCP configuration
+ files. This assumes that the zcalled_login field is either NULL or
+ "ANY". If makes sure that the login name does not appear in some
+ other "called-login" command listing systems not including this
+ one. */
+
+int
+uuconf_taylor_validate (pglobal, qsys, zlogin)
+ pointer pglobal;
+ const struct uuconf_system *qsys;
+ const char *zlogin;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ struct svalidate *q;
+
+ if (! qglobal->qprocess->fread_syslocs)
+ {
+ int iret;
+
+ iret = _uuconf_iread_locations (qglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ for (q = qglobal->qprocess->qvalidate; q != NULL; q = q->qnext)
+ {
+ if (strcmp (q->zlogname, zlogin) == 0)
+ {
+ char **pz;
+
+ for (pz = q->pzmachines; *pz != NULL; pz++)
+ if (strcmp (*pz, qsys->uuconf_zname) == 0)
+ return UUCONF_SUCCESS;
+
+ return UUCONF_NOT_FOUND;
+ }
+ }
+
+ return UUCONF_SUCCESS;
+}
diff --git a/gnu/libexec/uucp/libuuconf/ugtlin.c b/gnu/libexec/uucp/libuuconf/ugtlin.c
new file mode 100644
index 00000000000..88ca3507384
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/ugtlin.c
@@ -0,0 +1,110 @@
+/* ugtlin.c
+ Read a line with backslash continuations.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_ugtlin_rcsid[] = "$Id: ugtlin.c,v 1.1 1993/08/04 19:35:22 jtc Exp $";
+#endif
+
+/* Read a line from a file with backslash continuations. This updates
+ the qglobal->ilineno count for each additional line it reads. */
+
+int
+_uuconf_getline (qglobal, pzline, pcline, e)
+ struct sglobal *qglobal;
+ char **pzline;
+ size_t *pcline;
+ FILE *e;
+{
+ int ctot;
+ char *zline;
+ size_t cline;
+
+ ctot = -1;
+
+ zline = NULL;
+ cline = 0;
+
+ while (TRUE)
+ {
+ int cchars;
+
+ if (ctot < 0)
+ cchars = getline (pzline, pcline, e);
+ else
+ cchars = getline (&zline, &cline, e);
+ if (cchars < 0)
+ {
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (ctot >= 0)
+ return ctot;
+ else
+ return cchars;
+ }
+
+ if (ctot < 0)
+ ctot = cchars;
+ else
+ {
+ if (*pcline <= ctot + cchars)
+ {
+ char *znew;
+
+ if (*pcline > 0)
+ znew = (char *) realloc ((pointer) *pzline,
+ (size_t) (ctot + cchars + 1));
+ else
+ znew = (char *) malloc ((size_t) (ctot + cchars + 1));
+ if (znew == NULL)
+ {
+ free ((pointer) zline);
+ return -1;
+ }
+ *pzline = znew;
+ *pcline = ctot + cchars + 1;
+ }
+
+ memcpy ((pointer) ((*pzline) + ctot), (pointer) zline,
+ (size_t) (cchars + 1));
+ ctot += cchars;
+ }
+
+ if (ctot < 2
+ || (*pzline)[ctot - 1] != '\n'
+ || (*pzline)[ctot - 2] != '\\')
+ {
+ if (zline != NULL)
+ free ((pointer) zline);
+ return ctot;
+ }
+
+ ++qglobal->ilineno;
+
+ ctot -= 2;
+ (*pzline)[ctot] = '\0';
+ }
+}
diff --git a/gnu/libexec/uucp/libuuconf/unk.c b/gnu/libexec/uucp/libuuconf/unk.c
new file mode 100644
index 00000000000..565dd270f25
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/unk.c
@@ -0,0 +1,70 @@
+/* unk.c
+ Get information about an unknown system.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_unk_rcsid[] = "$Id: unk.c,v 1.1 1993/08/04 19:35:22 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Get information about an unknown system. If we are using
+ HAVE_TAYLOR_CONFIG, we just use it. Otherwise if we are using
+ HAVE_HDB_CONFIG, we use it. Otherwise we return a default system.
+ This isn't right for HAVE_V2_CONFIG, because it is possible to
+ specify default directories to read and write in USERFILE.
+ However, I'm not going to bother to write that code unless somebody
+ actually wants it. */
+
+/*ARGSUSED*/
+int
+uuconf_system_unknown (pglobal, qsys)
+ pointer pglobal;
+ struct uuconf_system *qsys;
+{
+#if HAVE_TAYLOR_CONFIG
+ return uuconf_taylor_system_unknown (pglobal, qsys);
+#else /* ! HAVE_TAYLOR_CONFIG */
+#if HAVE_HDB_CONFIG
+ return uuconf_hdb_system_unknown (pglobal, qsys);
+#else /* ! HAVE_HDB_CONFIG */
+#if HAVE_V2_CONFIG
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+
+ _uuconf_uclear_system (qsys);
+ qsys->uuconf_palloc = uuconf_malloc_block ();
+ if (qsys->uuconf_palloc == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ return _uuconf_isystem_basic_default (qglobal, qsys);
+#else /* ! HAVE_V2_CONFIG */
+ return UUCONF_NOT_FOUND;
+#endif /* ! HAVE_V2_CONFIG */
+#endif /* ! HAVE_HDB_CONFIG */
+#endif /* ! HAVE_TAYLOR_CONFIG */
+}
diff --git a/gnu/libexec/uucp/libuuconf/uucnfi.h b/gnu/libexec/uucp/libuuconf/uucnfi.h
new file mode 100644
index 00000000000..9ce6a62dc76
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/uucnfi.h
@@ -0,0 +1,368 @@
+/* uucnfi.h
+ Internal header file for the uuconf package.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+/* This is the internal header file for the uuconf package. It should
+ not be included by anything other than the uuconf code itself. */
+
+/* Get all the general definitions. */
+#include "uucp.h"
+
+/* Get the uuconf header file itself. */
+#include "uuconf.h"
+
+/* We need the system dependent header file. */
+#include "syshdr.h"
+
+/* This is the generic information structure. This holds all the
+ per-thread global information needed by the uuconf code. The
+ per-process global information is held in an sprocess structure,
+ which this structure points to. This permits the code to not have
+ any global variables at all. */
+
+struct sglobal
+{
+ /* A pointer to the per-process global information. */
+ struct sprocess *qprocess;
+ /* A memory block in which all the memory for these fields is
+ allocated. */
+ pointer pblock;
+ /* The value of errno after an error. */
+ int ierrno;
+ /* The filename for which an error occurred. */
+ const char *zfilename;
+ /* The line number at which an error occurred. */
+ int ilineno;
+};
+
+/* This is the per-process information structure. This essentially
+ holds all the global variables used by uuconf. */
+
+struct sprocess
+{
+ /* The name of the local machine. This will be NULL if it is not
+ specified in a configuration file. */
+ const char *zlocalname;
+ /* The spool directory. */
+ const char *zspooldir;
+ /* The default public directory. */
+ const char *zpubdir;
+ /* The lock directory. */
+ const char *zlockdir;
+ /* The log file. */
+ const char *zlogfile;
+ /* The statistics file. */
+ const char *zstatsfile;
+ /* The debugging file. */
+ const char *zdebugfile;
+ /* The default debugging level. */
+ const char *zdebug;
+ /* The maximum number of simultaneously executing uuxqts. */
+ int cmaxuuxqts;
+ /* Whether we are reading the V2 configuration files. */
+ boolean fv2;
+ /* Whether we are reading the HDB configuration files. */
+ boolean fhdb;
+ /* The names of the dialcode files. */
+ char **pzdialcodefiles;
+ /* Timetables. These are in pairs. The first element is the name,
+ the second is the time string. */
+ char **pztimetables;
+
+ /* Taylor UUCP config file name. */
+ char *zconfigfile;
+ /* Taylor UUCP sys file names. */
+ char **pzsysfiles;
+ /* Taylor UUCP port file names. */
+ char **pzportfiles;
+ /* Taylor UUCP dial file names. */
+ char **pzdialfiles;
+ /* Taylor UUCP passwd file names. */
+ char **pzpwdfiles;
+ /* Taylor UUCP call file names. */
+ char **pzcallfiles;
+ /* List of "unknown" commands from config file. */
+ struct sunknown *qunknown;
+ /* Whether the Taylor UUCP system information locations have been
+ read. */
+ boolean fread_syslocs;
+ /* Taylor UUCP system information locations. */
+ struct stsysloc *qsyslocs;
+ /* Taylor UUCP validation restrictions. */
+ struct svalidate *qvalidate;
+ /* Whether the "myname" command is used in a Taylor UUCP file. */
+ boolean fuses_myname;
+
+ /* V2 system file name (L.sys). */
+ char *zv2systems;
+ /* V2 device file name (L-devices). */
+ char *zv2devices;
+ /* V2 user permissions file name (USERFILE). */
+ char *zv2userfile;
+ /* V2 user permitted commands file (L.cmds). */
+ char *zv2cmds;
+
+ /* HDB system file names (Systems). */
+ char **pzhdb_systems;
+ /* HDB device file names (Devices). */
+ char **pzhdb_devices;
+ /* HDB dialer file names (Dialers). */
+ char **pzhdb_dialers;
+ /* Whether the HDB Permissions file has been read. */
+ boolean fhdb_read_permissions;
+ /* The HDB Permissions file entries. */
+ struct shpermissions *qhdb_permissions;
+};
+
+/* This structure is used to hold the "unknown" commands from the
+ Taylor UUCP config file before they have been parsed. */
+
+struct sunknown
+{
+ /* Next element in linked list. */
+ struct sunknown *qnext;
+ /* Line number in config file. */
+ int ilineno;
+ /* Number of arguments. */
+ int cargs;
+ /* Arguments. */
+ char **pzargs;
+};
+
+/* This structure is used to hold the locations of systems within the
+ Taylor UUCP sys files. */
+
+struct stsysloc
+{
+ /* Next element in linked list. */
+ struct stsysloc *qnext;
+ /* System name. */
+ const char *zname;
+ /* Whether system is an alias or a real system. If this is an
+ alias, the real system is the next entry in the linked list which
+ is not an alias. */
+ boolean falias;
+ /* File name (one of the sys files). */
+ const char *zfile;
+ /* Open file. */
+ FILE *e;
+ /* Location within file (from ftell). */
+ long iloc;
+ /* Line number within file. */
+ int ilineno;
+};
+
+/* This structure is used to hold validation restrictions. This is a
+ list of machines which are permitted to use a particular login
+ name. If a machine logs in, and there is no called login entry for
+ it, the login name and machine name must be passed to
+ uuconf_validate to confirm that either there is no entry for this
+ login name or that the machine name appears on the entry. */
+
+struct svalidate
+{
+ /* Next element in linked list. */
+ struct svalidate *qnext;
+ /* Login name. */
+ const char *zlogname;
+ /* NULL terminated list of machine names. */
+ char **pzmachines;
+};
+
+/* This structure is used to hold a linked list of HDB Permissions
+ file entries. */
+
+struct shpermissions
+{
+ /* Next entry in linked list. */
+ struct shpermissions *qnext;
+ /* NULL terminated array of LOGNAME values. */
+ char **pzlogname;
+ /* NULL terminated array of MACHINE values. */
+ char **pzmachine;
+ /* Boolean REQUEST value. */
+ int frequest;
+ /* Boolean SENDFILES value ("call" is taken as "no"). */
+ int fsendfiles;
+ /* NULL terminated array of READ values. */
+ char **pzread;
+ /* NULL terminated array of WRITE values. */
+ char **pzwrite;
+ /* Boolean CALLBACK value. */
+ int fcallback;
+ /* NULL terminated array of COMMANDS values. */
+ char **pzcommands;
+ /* NULL terminated array of VALIDATE values. */
+ char **pzvalidate;
+ /* String MYNAME value. */
+ char *zmyname;
+ /* String PUBDIR value. */
+ const char *zpubdir;
+ /* NULL terminated array of ALIAS values. */
+ char **pzalias;
+};
+
+/* This structure is used to build reentrant uuconf_cmdtab tables.
+ The ioff field is either (size_t) -1 or an offsetof macro. The
+ table is then copied into a uuconf_cmdtab, except that offsets of
+ (size_t) -1 are converted to pvar elements of NULL, and other
+ offsets are converted to an offset off some base address. */
+
+struct cmdtab_offset
+{
+ const char *zcmd;
+ int itype;
+ size_t ioff;
+ uuconf_cmdtabfn pifn;
+};
+
+/* A value in a uuconf_system structure which holds the address of
+ this special variable is known to be uninitialized. */
+extern char *_uuconf_unset;
+
+/* Internal function to read a system from the Taylor UUCP
+ configuration files. This does not apply the basic defaults. */
+extern int _uuconf_itaylor_system_internal P((struct sglobal *qglobal,
+ const char *zsystem,
+ struct uuconf_system *qsys));
+
+/* Read the system locations and validation information from the
+ Taylor UUCP configuration files. This sets the qsyslocs,
+ qvalidate, and fread_syslocs elements of the global structure. */
+extern int _uuconf_iread_locations P((struct sglobal *qglobal));
+
+/* Process a command for a port from a Taylor UUCP file. */
+extern int _uuconf_iport_cmd P((struct sglobal *qglobal, int argc,
+ char **argv, struct uuconf_port *qport));
+
+/* Process a command for a dialer from a Taylor UUCP file. */
+extern int _uuconf_idialer_cmd P((struct sglobal *qglobal, int argc,
+ char **argv,
+ struct uuconf_dialer *qdialer));
+
+/* Process a command for a chat script from a Taylor UUCP file; this
+ is also called for HDB or V2 files, with a made up command. */
+extern int _uuconf_ichat_cmd P((struct sglobal *qglobal, int argc,
+ char **argv, struct uuconf_chat *qchat,
+ pointer pblock));
+
+/* Process a protocol-parameter command from a Taylor UUCP file. */
+extern int _uuconf_iadd_proto_param P((struct sglobal *qglobal,
+ int argc, char **argv,
+ struct uuconf_proto_param **pq,
+ pointer pblock));
+
+/* Handle a "seven-bit", "reliable", or "half-duplex" command from a
+ Taylor UUCP port or dialer file. The pvar field should point to
+ the ireliable element of the structure. */
+extern int _uuconf_iseven_bit P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+extern int _uuconf_ireliable P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+extern int _uuconf_ihalf_duplex P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+
+/* Internal function to read a system from the V2 configuration files.
+ This does not apply the basic defaults. */
+extern int _uuconf_iv2_system_internal P((struct sglobal *qglobal,
+ const char *zsystem,
+ struct uuconf_system *qsys));
+
+/* Internal function to read a system from the HDB configuration
+ files. This does not apply the basic defaults. */
+extern int _uuconf_ihdb_system_internal P((struct sglobal *qglobal,
+ const char *zsystem,
+ struct uuconf_system *qsys));
+
+/* Read the HDB Permissions file. */
+extern int _uuconf_ihread_permissions P((struct sglobal *qglobal));
+
+/* Initialize the global information structure. */
+extern int _uuconf_iinit_global P((struct sglobal **pqglobal));
+
+/* Clear system information. */
+extern void _uuconf_uclear_system P((struct uuconf_system *qsys));
+
+/* Default unset aspects of one system to the contents of another. */
+extern int _uuconf_isystem_default P((struct sglobal *qglobal,
+ struct uuconf_system *q,
+ struct uuconf_system *qdefault,
+ boolean faddalternates));
+
+/* Put in the basic system defaults. */
+extern int _uuconf_isystem_basic_default P((struct sglobal *qglobal,
+ struct uuconf_system *qsys));
+
+/* Clear port information. */
+extern void _uuconf_uclear_port P((struct uuconf_port *qport));
+
+/* Clear dialer information. */
+extern void _uuconf_uclear_dialer P((struct uuconf_dialer *qdialer));
+
+/* Add a timetable. */
+extern int _uuconf_itimetable P((pointer pglobal, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+
+/* Parse a time string. */
+extern int _uuconf_itime_parse P((struct sglobal *qglobal, char *ztime,
+ long ival, int cretry,
+ int (*picmp) P((long, long)),
+ struct uuconf_timespan **pqspan,
+ pointer pblock));
+
+/* A grade comparison function to pass to _uuconf_itime_parse. */
+extern int _uuconf_itime_grade_cmp P((long, long));
+
+/* Add a string to a NULL terminated list of strings. */
+extern int _uuconf_iadd_string P((struct sglobal *qglobal,
+ char *zadd, boolean fcopy,
+ boolean fdupcheck, char ***ppzstrings,
+ pointer pblock));
+
+/* Parse a string into a boolean value. */
+extern int _uuconf_iboolean P((struct sglobal *qglobal, const char *zval,
+ int *pi));
+
+/* Parse a string into an integer value. The argument p is either an
+ int * or a long *, according to the argument fint. */
+extern int _uuconf_iint P((struct sglobal *qglobal, const char *zval,
+ pointer p, boolean fint));
+
+/* Turn a cmdtab_offset table into a uuconf_cmdtab table. */
+extern void _uuconf_ucmdtab_base P((const struct cmdtab_offset *qoff,
+ size_t celes, char *pbase,
+ struct uuconf_cmdtab *qset));
+
+/* Merge two memory blocks into one. This cannot fail. */
+extern pointer _uuconf_pmalloc_block_merge P((pointer, pointer));
+
+/* A wrapper for getline that continues lines if they end in a
+ backslash. It needs qglobal so that it can increment ilineno
+ correctly. */
+extern int _uuconf_getline P((struct sglobal *qglobal,
+ char **, size_t *, FILE *));
+
+/* Split a string into tokens. */
+extern int _uuconf_istrsplit P((char *zline, int bsep,
+ char ***ppzsplit, size_t *csplit));
diff --git a/gnu/libexec/uucp/libuuconf/val.c b/gnu/libexec/uucp/libuuconf/val.c
new file mode 100644
index 00000000000..a4eb30fb67b
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/val.c
@@ -0,0 +1,46 @@
+/* val.c
+ Validate a login name for a system.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_val_rcsid[] = "$Id: val.c,v 1.1 1993/08/04 19:35:25 jtc Exp $";
+#endif
+
+/* Validate a login name for a system. */
+
+/*ARGSUSED*/
+int
+uuconf_validate (pglobal, qsys, zlogin)
+ pointer pglobal;
+ const struct uuconf_system *qsys;
+ const char *zlogin;
+{
+#if HAVE_TAYLOR_CONFIG
+ return uuconf_taylor_validate (pglobal, qsys, zlogin);
+#else
+ return UUCONF_SUCCESS;
+#endif
+}
diff --git a/gnu/libexec/uucp/libuuconf/vinit.c b/gnu/libexec/uucp/libuuconf/vinit.c
new file mode 100644
index 00000000000..20ff5bcb1b7
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/vinit.c
@@ -0,0 +1,112 @@
+/* vinit.c
+ Initialize for reading V2 configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_vinit_rcsid[] = "$Id: vinit.c,v 1.1 1993/08/04 19:35:25 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+static int ivinlib P((struct sglobal *qglobal, const char *z, size_t csize,
+ char **pz));
+
+/* Return an allocated buffer holding a file name in OLDCONFIGLIB.
+ The c argument is the size of z including the trailing null byte,
+ since this is convenient for both the caller and this function. */
+
+static int
+ivinlib (qglobal, z, c, pz)
+ struct sglobal *qglobal;
+ const char *z;
+ size_t c;
+ char **pz;
+{
+ char *zalc;
+
+ zalc = uuconf_malloc (qglobal->pblock, sizeof OLDCONFIGLIB - 1 + c);
+ if (zalc == NULL)
+ {
+ qglobal->ierrno = errno;
+ return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ memcpy ((pointer) zalc, (pointer) OLDCONFIGLIB,
+ sizeof OLDCONFIGLIB - 1);
+ memcpy ((pointer) (zalc + sizeof OLDCONFIGLIB - 1), (pointer) z, c);
+
+ *pz = zalc;
+
+ return UUCONF_SUCCESS;
+}
+
+/* Initialize the routines which read V2 configuration files. The
+ only thing we do here is allocate the file names. */
+
+int
+uuconf_v2_init (ppglobal)
+ pointer *ppglobal;
+{
+ struct sglobal **pqglobal = (struct sglobal **) ppglobal;
+ int iret;
+ struct sglobal *qglobal;
+ char *zdialcodes;
+
+ if (*pqglobal == NULL)
+ {
+ iret = _uuconf_iinit_global (pqglobal);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ }
+
+ qglobal = *pqglobal;
+
+ iret = ivinlib (qglobal, V2_SYSTEMS, sizeof V2_SYSTEMS,
+ &qglobal->qprocess->zv2systems);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = ivinlib (qglobal, V2_DEVICES, sizeof V2_DEVICES,
+ &qglobal->qprocess->zv2devices);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = ivinlib (qglobal, V2_USERFILE, sizeof V2_USERFILE,
+ &qglobal->qprocess->zv2userfile);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ iret = ivinlib (qglobal, V2_CMDS, sizeof V2_CMDS,
+ &qglobal->qprocess->zv2cmds);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+
+ iret = ivinlib (qglobal, V2_DIALCODES, sizeof V2_DIALCODES,
+ &zdialcodes);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+
+ return _uuconf_iadd_string (qglobal, zdialcodes, FALSE, FALSE,
+ &qglobal->qprocess->pzdialcodefiles,
+ qglobal->pblock);
+}
diff --git a/gnu/libexec/uucp/libuuconf/vport.c b/gnu/libexec/uucp/libuuconf/vport.c
new file mode 100644
index 00000000000..b9382a38614
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/vport.c
@@ -0,0 +1,251 @@
+/* vport.c
+ Find a port in the V2 configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_vport_rcsid[] = "$Id: vport.c,v 1.1 1993/08/04 19:35:27 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+/* Find a port in the V2 configuration files by name, baud rate, and
+ special purpose function. */
+
+int
+uuconf_v2_find_port (pglobal, zname, ibaud, ihighbaud, pifn, pinfo, qport)
+ pointer pglobal;
+ const char *zname;
+ long ibaud;
+ long ihighbaud;
+ int (*pifn) P((struct uuconf_port *, pointer));
+ pointer pinfo;
+ struct uuconf_port *qport;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ FILE *e;
+ char *zline;
+ size_t cline;
+ char **pzsplit;
+ size_t csplit;
+ int iret;
+ int cchars;
+
+ e = fopen (qglobal->qprocess->zv2devices, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ return UUCONF_NOT_FOUND;
+ qglobal->ierrno = errno;
+ qglobal->zfilename = qglobal->qprocess->zv2devices;
+ return (UUCONF_FOPEN_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_ERROR_FILENAME);
+ }
+
+ zline = NULL;
+ cline = 0;
+ pzsplit = NULL;
+ csplit = 0;
+
+ iret = UUCONF_NOT_FOUND;
+
+ qglobal->ilineno = 0;
+
+ while ((cchars = getline (&zline, &cline, e)) > 0)
+ {
+ int ctoks;
+ char *zend;
+ long ilow, ihigh;
+ pointer pblock;
+
+ ++qglobal->ilineno;
+
+ iret = UUCONF_NOT_FOUND;
+
+ --cchars;
+ if (zline[cchars] == '\n')
+ zline[cchars] = '\0';
+ zline[strcspn (zline, "#")] = '\0';
+
+ ctoks = _uuconf_istrsplit (zline, '\0', &pzsplit, &csplit);
+ if (ctoks < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ /* An entry in L-devices is
+
+ type device dial-device baud dialer
+
+ The type (normally "ACU") is treated as the name. */
+
+ /* If there aren't enough entries, ignore the line; this
+ should probably do something more useful. */
+ if (ctoks < 4)
+ continue;
+
+ /* Make sure the name matches any argument. */
+ if (zname != NULL
+ && strcmp (pzsplit[0], zname) != 0)
+ continue;
+
+ /* Get the baud rate. */
+ ilow = strtol (pzsplit[3], &zend, 10);
+ if (*zend == '-')
+ ihigh = strtol (zend + 1, (char **) NULL, 10);
+ else
+ ihigh = ilow;
+
+ /* Make sure the baud rate matches any argument. */
+ if (ibaud != 0
+ && ilow != 0
+ && (ilow > ibaud || ihigh < ibaud))
+ continue;
+
+ /* Now we must construct the port information, so that we can
+ pass it to pifn. The port type is determined by it's name,
+ unfortunately. The name "DIR" is used for a direct port, and
+ anything else for a modem port. */
+ pblock = NULL;
+ _uuconf_uclear_port (qport);
+ qport->uuconf_zname = pzsplit[0];
+ if (strcmp (pzsplit[0], "DIR") == 0)
+ {
+ qport->uuconf_ttype = UUCONF_PORTTYPE_DIRECT;
+ qport->uuconf_u.uuconf_sdirect.uuconf_zdevice = pzsplit[1];
+ qport->uuconf_u.uuconf_sdirect.uuconf_ibaud = ilow;
+ }
+ else
+ {
+ qport->uuconf_ttype = UUCONF_PORTTYPE_MODEM;
+ qport->uuconf_u.uuconf_smodem.uuconf_zdevice = pzsplit[1];
+ if (strcmp (pzsplit[2], "-") != 0)
+ qport->uuconf_u.uuconf_smodem.uuconf_zdial_device = pzsplit[2];
+ else
+ qport->uuconf_u.uuconf_smodem.uuconf_zdial_device = NULL;
+ if (ilow == ihigh)
+ {
+ qport->uuconf_u.uuconf_smodem.uuconf_ibaud = ilow;
+ qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud = 0L;
+ qport->uuconf_u.uuconf_smodem.uuconf_ihighbaud = 0L;
+ }
+ else
+ {
+ qport->uuconf_u.uuconf_smodem.uuconf_ibaud = 0L;
+ qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud = ilow;
+ qport->uuconf_u.uuconf_smodem.uuconf_ihighbaud = ihigh;
+ }
+ qport->uuconf_u.uuconf_smodem.uuconf_fcarrier = TRUE;
+ if (ctoks < 5)
+ qport->uuconf_u.uuconf_smodem.uuconf_pzdialer = NULL;
+ else
+ {
+ size_t c;
+ char **pzd;
+
+ /* We support dialer/token pairs, although normal V2
+ doesn't. */
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ c = (ctoks - 4) * sizeof (char *);
+ pzd = (char **) uuconf_malloc (pblock, c + sizeof (char *));
+ if (pzd == NULL)
+ {
+ qglobal->ierrno = errno;
+ uuconf_free_block (pblock);
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ memcpy ((pointer) pzd, (pointer) (pzsplit + 4), c);
+ pzd[ctoks - 4] = NULL;
+
+ qport->uuconf_u.uuconf_smodem.uuconf_pzdialer = pzd;
+ }
+ qport->uuconf_u.uuconf_smodem.uuconf_qdialer = NULL;
+ }
+
+ if (pifn != NULL)
+ {
+ iret = (*pifn) (qport, pinfo);
+ if (iret != UUCONF_SUCCESS)
+ {
+ if (pblock != NULL)
+ uuconf_free_block (pblock);
+ if (iret != UUCONF_NOT_FOUND)
+ break;
+ continue;
+ }
+ }
+
+ /* This is the port we want. */
+ if (pblock == NULL)
+ {
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ }
+
+ if (uuconf_add_block (pblock, zline) != 0)
+ {
+ qglobal->ierrno = errno;
+ uuconf_free_block (pblock);
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ zline = NULL;
+
+ qport->uuconf_palloc = pblock;
+
+ break;
+ }
+
+ (void) fclose (e);
+
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+
+ if (iret != UUCONF_SUCCESS && iret != UUCONF_NOT_FOUND)
+ {
+ qglobal->zfilename = qglobal->qprocess->zv2devices;
+ iret |= UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ }
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/vsinfo.c b/gnu/libexec/uucp/libuuconf/vsinfo.c
new file mode 100644
index 00000000000..c528ce35012
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/vsinfo.c
@@ -0,0 +1,575 @@
+/* vsinfo.c
+ Get information about a system from the V2 configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_vsinfo_rcsid[] = "$Id: vsinfo.c,v 1.1 1993/08/04 19:35:28 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+/* Get the information for a particular system from the V2
+ configuration files. This does not make sure that all the default
+ values are set. */
+
+int
+_uuconf_iv2_system_internal (qglobal, zsystem, qsys)
+ struct sglobal *qglobal;
+ const char *zsystem;
+ struct uuconf_system *qsys;
+{
+ char *zline;
+ size_t cline;
+ char **pzsplit;
+ size_t csplit;
+ char **pzcomma;
+ size_t ccomma;
+ FILE *e;
+ int cchars;
+ pointer pblock;
+ int iret;
+
+ e = fopen (qglobal->qprocess->zv2systems, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ return UUCONF_NOT_FOUND;
+ qglobal->ierrno = errno;
+ qglobal->zfilename = qglobal->qprocess->zv2systems;
+ return (UUCONF_FOPEN_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_ERROR_FILENAME);
+ }
+
+ zline = NULL;
+ cline = 0;
+ pzsplit = NULL;
+ csplit = 0;
+ pzcomma = NULL;
+ ccomma = 0;
+
+ pblock = NULL;
+ iret = UUCONF_SUCCESS;
+
+ qglobal->ilineno = 0;
+
+ while ((cchars = getline (&zline, &cline, e)) > 0)
+ {
+ int ctoks, ctimes, i;
+ struct uuconf_system *qset;
+ char *z, *zretry;
+ int cretry;
+
+ ++qglobal->ilineno;
+
+ --cchars;
+ if (zline[cchars] == '\n')
+ zline[cchars] = '\0';
+ zline[strcspn (zline, "#")] = '\0';
+
+ ctoks = _uuconf_istrsplit (zline, '\0', &pzsplit, &csplit);
+ if (ctoks < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ /* If this isn't the system we're looking for, keep reading
+ the file. */
+ if (ctoks < 1
+ || strcmp (zsystem, pzsplit[0]) != 0)
+ continue;
+
+ /* If this is the first time we've found the system, we want
+ to set *qsys directly. Otherwise, we allocate a new
+ alternate. */
+ if (pblock == NULL)
+ {
+ pblock = uuconf_malloc_block ();
+ if (pblock == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ _uuconf_uclear_system (qsys);
+ qsys->uuconf_palloc = pblock;
+ qset = qsys;
+ }
+ else
+ {
+ struct uuconf_system **pq;
+
+ qset = ((struct uuconf_system *)
+ uuconf_malloc (pblock, sizeof (struct uuconf_system)));
+ if (qset == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ _uuconf_uclear_system (qset);
+ for (pq = &qsys->uuconf_qalternate;
+ *pq != NULL;
+ pq = &(*pq)->uuconf_qalternate)
+ ;
+ *pq = qset;
+ }
+
+ /* Add this line to the memory block we are building for the
+ system. */
+ if (uuconf_add_block (pblock, zline) != 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ zline = NULL;
+ cline = 0;
+
+ /* The format of a line in Systems is
+ system time device speed phone chat
+ For example,
+ airs Any ACU 9600 5551212 ogin: foo pass: bar
+ */
+
+ /* Get the system name. */
+
+ qset->uuconf_zname = pzsplit[0];
+ qset->uuconf_fcall = TRUE;
+ qset->uuconf_fcalled = TRUE;
+
+ if (ctoks < 2)
+ continue;
+
+ /* A time string is "time/grade,time/grade;retry". A missing
+ grade is taken as BGRADE_LOW. On some versions the retry
+ time is actually separated by a comma, which won't work right
+ here. */
+ zretry = strchr (pzsplit[1], ';');
+ if (zretry == NULL)
+ cretry = 0;
+ else
+ {
+ *zretry = '\0';
+ cretry = (int) strtol (zretry + 1, (char **) NULL, 10);
+ }
+
+ ctimes = _uuconf_istrsplit (pzsplit[1], ',', &pzcomma, &ccomma);
+ if (ctimes < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ for (i = 0; i < ctimes; i++)
+ {
+ char *zslash;
+ char bgrade;
+
+ z = pzcomma[i];
+ zslash = strchr (z, '/');
+ if (zslash == NULL)
+ bgrade = UUCONF_GRADE_LOW;
+ else
+ {
+ *zslash = '\0';
+ bgrade = zslash[1];
+ if (! UUCONF_GRADE_LEGAL (bgrade))
+ bgrade = UUCONF_GRADE_LOW;
+ }
+
+ iret = _uuconf_itime_parse (qglobal, z, (long) bgrade, cretry,
+ _uuconf_itime_grade_cmp,
+ &qset->uuconf_qtimegrade,
+ pblock);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+
+ if (iret != UUCONF_SUCCESS)
+ break;
+
+ if (ctoks < 3)
+ continue;
+
+ /* Pick up the device name. It can be followed by a comma and a
+ list of protocols (this is not actually supported by most V2
+ systems, but it should be compatible). */
+ qset->uuconf_zport = pzsplit[2];
+ z = strchr (pzsplit[2], ',');
+ if (z != NULL)
+ {
+ qset->uuconf_zprotocols = z + 1;
+ *z = '\0';
+ }
+
+ /* If the port is "TCP", we set up a system specific port. The
+ baud rate becomes the service number and the phone number
+ becomes the address (still stored in qsys->zphone). */
+ if (strcmp (qset->uuconf_zport, "TCP") == 0)
+ {
+ qset->uuconf_zport = NULL;
+ qset->uuconf_qport = ((struct uuconf_port *)
+ uuconf_malloc (pblock,
+ sizeof (struct uuconf_port)));
+ if (qset->uuconf_qport == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ _uuconf_uclear_port (qset->uuconf_qport);
+ qset->uuconf_qport->uuconf_zname = (char *) "TCP";
+ qset->uuconf_qport->uuconf_ttype = UUCONF_PORTTYPE_TCP;
+ qset->uuconf_qport->uuconf_ireliable
+ = (UUCONF_RELIABLE_ENDTOEND | UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT | UUCONF_RELIABLE_FULLDUPLEX
+ | UUCONF_RELIABLE_SPECIFIED);
+ if (ctoks < 4)
+ qset->uuconf_qport->uuconf_u.uuconf_stcp.uuconf_zport
+ = (char *) "uucp";
+ else
+ qset->uuconf_qport->uuconf_u.uuconf_stcp.uuconf_zport
+ = pzsplit[3];
+ }
+
+ if (ctoks < 4)
+ continue;
+
+ qset->uuconf_ibaud = strtol (pzsplit[3], (char **) NULL, 10);
+
+ if (ctoks < 5)
+ continue;
+
+ /* Get the phone number. */
+ qset->uuconf_zphone = pzsplit[4];
+
+ if (ctoks < 6)
+ continue;
+
+ /* Get the chat script. We just hand this off to the chat
+ script processor, so that it will parse subsend and
+ subexpect strings correctly. */
+ pzsplit[4] = (char *) "chat";
+ iret = _uuconf_ichat_cmd (qglobal, ctoks - 4, pzsplit + 4,
+ &qset->uuconf_schat, pblock);
+ iret &=~ UUCONF_CMDTABRET_KEEP;
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+
+ (void) fclose (e);
+
+ if (pzcomma != NULL)
+ free ((pointer) pzcomma);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+ qglobal->zfilename = qglobal->qprocess->zv2systems;
+ return iret | UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ }
+
+ if (pblock == NULL)
+ {
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+ return UUCONF_NOT_FOUND;
+ }
+
+ /* Now read USERFILE and L.cmds to get permissions. We can't fully
+ handle USERFILE since that specifies permissions based on local
+ users which we do not support. */
+ {
+ e = fopen (qglobal->qprocess->zv2userfile, "r");
+ if (e != NULL)
+ {
+ char **pzlocal, **pzremote;
+ boolean fdefault_callback;
+ char *zdefault_login;
+ struct uuconf_system *q;
+
+ pzlocal = NULL;
+ pzremote = NULL;
+ fdefault_callback = FALSE;
+ zdefault_login = NULL;
+
+ qglobal->ilineno = 0;
+
+ while ((cchars = getline (&zline, &cline, e)) > 0)
+ {
+ int ctoks;
+ char *zcomma;
+ boolean fcallback;
+ char **pzlist, **pznew;
+
+ ++qglobal->ilineno;
+
+ --cchars;
+ if (zline[cchars] == '\n')
+ zline[cchars] = '\0';
+ zline[strcspn (zline, "#")] = '\0';
+
+ ctoks = _uuconf_istrsplit (zline, '\0', &pzsplit, &csplit);
+ if (ctoks < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+
+ if (ctoks == 0)
+ continue;
+
+ /* The first field is username,machinename */
+ zcomma = strchr (pzsplit[0], ',');
+ if (zcomma == NULL)
+ continue;
+
+ *zcomma++ = '\0';
+
+ /* The rest of the line is the list of directories, except
+ that if the first directory is "c" we must call the
+ system back. */
+ fcallback = FALSE;
+ pzlist = pzsplit + 1;
+ --ctoks;
+ if (ctoks > 0
+ && pzsplit[1][0] == 'c'
+ && pzsplit[1][1] == '\0')
+ {
+ fcallback = TRUE;
+ pzlist = pzsplit + 2;
+ --ctoks;
+ }
+
+ /* Now pzsplit[0] is the user name, zcomma is the system
+ name, fcallback indicates whether a call back is
+ required, ctoks is the number of directories and pzlist
+ points to the directories. If the system name matches,
+ then the user name is the name that the system must use
+ to log in, and the list of directories is what may be
+ transferred in by either local or remote request.
+ Otherwise, if no system name matches, then the first
+ line with no user name gives the list of directories
+ that may be transferred by local request, and the first
+ line with no system name gives the list of directories
+ that may be transferred by remote request. */
+ if ((pzsplit[0][0] != '\0' || pzlocal != NULL)
+ && (zcomma[0] != '\0' || pzremote != NULL)
+ && strcmp (zcomma, zsystem) != 0)
+ continue;
+
+ /* NULL terminate the list of directories. */
+ pznew = (char **) uuconf_malloc (pblock,
+ (ctoks + 1) * sizeof (char *));
+ if (pznew == NULL)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ memcpy ((pointer) pznew, (pointer) pzlist,
+ ctoks * sizeof (char *));
+ pznew[ctoks] = NULL;
+
+ if (uuconf_add_block (pblock, zline) != 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ break;
+ }
+ zline = NULL;
+ cline = 0;
+
+ if (pzsplit[0][0] == '\0')
+ {
+ pzlocal = pznew;
+ fdefault_callback = fcallback;
+ }
+ else if (zcomma[0] == '\0')
+ {
+ pzremote = pznew;
+ zdefault_login = pzsplit[0];
+ }
+ else
+ {
+ /* Both the login name and the machine name were
+ listed; require the machine to be logged in under
+ this name. This is not fully backward compatible,
+ and perhaps should be changed. On the other hand,
+ it is more useful. */
+ for (q = qsys; q != NULL; q = q->uuconf_qalternate)
+ {
+ q->uuconf_zcalled_login = pzsplit[0];
+ q->uuconf_fcallback = fcallback;
+ q->uuconf_pzlocal_send = pznew;
+ q->uuconf_pzlocal_receive = pznew;
+ q->uuconf_pzremote_send = pznew;
+ q->uuconf_pzremote_receive = pznew;
+ }
+
+ break;
+ }
+ }
+
+ (void) fclose (e);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+ qglobal->zfilename = qglobal->qprocess->zv2userfile;
+ return iret | UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ }
+
+ if (qsys->uuconf_pzlocal_send == (char **) &_uuconf_unset
+ && pzlocal != NULL)
+ {
+ for (q = qsys; q != NULL; q = q->uuconf_qalternate)
+ {
+ q->uuconf_fcallback = fdefault_callback;
+ q->uuconf_pzlocal_send = pzlocal;
+ q->uuconf_pzlocal_receive = pzlocal;
+ }
+ }
+
+ if (qsys->uuconf_pzremote_send == (char **) &_uuconf_unset
+ && pzremote != NULL)
+ {
+ for (q = qsys; q != NULL; q = q->uuconf_qalternate)
+ {
+ q->uuconf_zcalled_login = zdefault_login;
+ q->uuconf_pzremote_send = pzremote;
+ q->uuconf_pzremote_receive = pzremote;
+ }
+ }
+ }
+ }
+
+ /* Now we must read L.cmds to determine which commands may be
+ executed. */
+ {
+ e = fopen (qglobal->qprocess->zv2cmds, "r");
+ if (e != NULL)
+ {
+ qglobal->ilineno = 0;
+
+ if (getline (&zline, &cline, e) > 0)
+ {
+ ++qglobal->ilineno;
+
+ zline[strcspn (zline, "#\n")] = '\0';
+ if (strncmp (zline, "PATH=", sizeof "PATH=" - 1) == 0)
+ {
+ int ctoks;
+ char **pznew;
+
+ zline += sizeof "PATH=" - 1;
+ ctoks = _uuconf_istrsplit (zline, ':', &pzsplit, &csplit);
+ if (ctoks < 0)
+ {
+ qglobal->ierrno = errno;
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+
+ pznew = NULL;
+ if (iret == UUCONF_SUCCESS)
+ {
+ pznew = ((char **)
+ uuconf_malloc (pblock,
+ (ctoks + 1) * sizeof (char *)));
+ if (pznew == NULL)
+ iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
+ }
+ if (iret == UUCONF_SUCCESS)
+ {
+ memcpy ((pointer) pznew, (pointer) pzsplit,
+ ctoks * sizeof (char *));
+ pznew[ctoks] = NULL;
+ qsys->uuconf_pzpath = pznew;
+ zline = NULL;
+ cline = 0;
+ }
+
+ if (getline (&zline, &cline, e) < 0)
+ {
+ if (zline != NULL)
+ {
+ free ((pointer) zline);
+ zline = NULL;
+ }
+ }
+ else
+ ++qglobal->ilineno;
+ }
+ }
+
+ if (iret == UUCONF_SUCCESS && zline != NULL)
+ {
+ while (TRUE)
+ {
+ zline[strcspn (zline, "#\n")] = '\0';
+ iret = _uuconf_iadd_string (qglobal, zline, TRUE, FALSE,
+ &qsys->uuconf_pzcmds,
+ pblock);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ if (getline (&zline, &cline, e) < 0)
+ break;
+ ++qglobal->ilineno;
+ }
+ }
+
+ (void) fclose (e);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = qglobal->qprocess->zv2cmds;
+ iret |= UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ }
+ }
+ }
+
+ if (zline != NULL)
+ free ((pointer) zline);
+ if (pzsplit != NULL)
+ free ((pointer) pzsplit);
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/vsnams.c b/gnu/libexec/uucp/libuuconf/vsnams.c
new file mode 100644
index 00000000000..0bf04b581d8
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/vsnams.c
@@ -0,0 +1,106 @@
+/* vsnams.c
+ Get all known system names from the V2 configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_vsnams_rcsid[] = "$Id: vsnams.c,v 1.1 1993/08/04 19:35:29 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+/* Get all the system names from the V2 L.sys file. This code does
+ not support aliases, although some V2 versions do have an L-aliases
+ file. */
+
+/*ARGSUSED*/
+int
+uuconf_v2_system_names (pglobal, ppzsystems, falias)
+ pointer pglobal;
+ char ***ppzsystems;
+ int falias;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ FILE *e;
+ int iret;
+ char *zline;
+ size_t cline;
+
+ *ppzsystems = NULL;
+
+ e = fopen (qglobal->qprocess->zv2systems, "r");
+ if (e == NULL)
+ {
+ if (FNO_SUCH_FILE ())
+ return _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
+ ppzsystems, (pointer) NULL);
+ qglobal->ierrno = errno;
+ qglobal->zfilename = qglobal->qprocess->zv2systems;
+ return (UUCONF_FOPEN_FAILED
+ | UUCONF_ERROR_ERRNO
+ | UUCONF_ERROR_FILENAME);
+ }
+
+ qglobal->ilineno = 0;
+ iret = UUCONF_SUCCESS;
+
+ zline = NULL;
+ cline = 0;
+ while (getline (&zline, &cline, e) > 0)
+ {
+ char *zname;
+
+ ++qglobal->ilineno;
+
+ /* Skip leading whitespace to get to the system name. Then cut
+ the system name off at the first whitespace, comment, or
+ newline. */
+ zname = zline + strspn (zline, " \t");
+ zname[strcspn (zname, " \t#\n")] = '\0';
+ if (*zname == '\0')
+ continue;
+
+ iret = _uuconf_iadd_string (qglobal, zname, TRUE, TRUE, ppzsystems,
+ (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ break;
+ }
+
+ (void) fclose (e);
+ if (zline != NULL)
+ free ((pointer) zline);
+
+ if (iret != UUCONF_SUCCESS)
+ {
+ qglobal->zfilename = qglobal->qprocess->zv2systems;
+ return iret | UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
+ }
+
+ if (*ppzsystems == NULL)
+ iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
+ ppzsystems, (pointer) NULL);
+
+ return iret;
+}
diff --git a/gnu/libexec/uucp/libuuconf/vsys.c b/gnu/libexec/uucp/libuuconf/vsys.c
new file mode 100644
index 00000000000..c0280cce3f1
--- /dev/null
+++ b/gnu/libexec/uucp/libuuconf/vsys.c
@@ -0,0 +1,49 @@
+/* vsys.c
+ User function to get a system from the V2 configuration files.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of the Taylor UUCP uuconf library.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char _uuconf_vsys_rcsid[] = "$Id: vsys.c,v 1.1 1993/08/04 19:35:30 jtc Exp $";
+#endif
+
+/* Get system information from the V2 configuration files. This is a
+ wrapper for the internal function which makes sure that every field
+ gets a default value. */
+
+int
+uuconf_v2_system_info (pglobal, zsystem, qsys)
+ pointer pglobal;
+ const char *zsystem;
+ struct uuconf_system *qsys;
+{
+ struct sglobal *qglobal = (struct sglobal *) pglobal;
+ int iret;
+
+ iret = _uuconf_iv2_system_internal (qglobal, zsystem, qsys);
+ if (iret != UUCONF_SUCCESS)
+ return iret;
+ return _uuconf_isystem_basic_default (qglobal, qsys);
+}
diff --git a/gnu/libexec/uucp/libuucp/MANIFEST b/gnu/libexec/uucp/libuucp/MANIFEST
new file mode 100644
index 00000000000..093924858ea
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/MANIFEST
@@ -0,0 +1,27 @@
+Makefile.in
+MANIFEST
+bsrch.c
+buffer.c
+bzero.c
+crc.c
+debug.c
+escape.c
+getlin.c
+getopt.c
+getop1.c
+memchr.c
+memcmp.c
+memcpy.c
+parse.c
+spool.c
+status.c
+strcas.c
+strchr.c
+strdup.c
+strncs.c
+strrch.c
+strstr.c
+strtol.c
+xfree.c
+xmall.c
+xreall.c
diff --git a/gnu/libexec/uucp/libuucp/Makefile b/gnu/libexec/uucp/libuucp/Makefile
new file mode 100644
index 00000000000..8a97d2a6cbf
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/Makefile
@@ -0,0 +1,13 @@
+# This is the Makefile for the libuucp subdirectory of Taylor UUCP
+
+LIB= uucp
+SRCS= buffer.o crc.o debug.o escape.o getopt.o getop1.o parse.o \
+ spool.o status.o xfree.o xmall.o xreall.o getlin.o
+CFLAGS+= -I$(.CURDIR)/../common_sources
+
+NOMAN= noman
+NOPROFILE= noprofile
+
+install:
+
+.include <bsd.lib.mk>
diff --git a/gnu/libexec/uucp/libuucp/bsrch.c b/gnu/libexec/uucp/libuucp/bsrch.c
new file mode 100644
index 00000000000..3b1a61c170c
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/bsrch.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.
+
+This file was modified slightly by Ian Lance Taylor, May 1992, for
+Taylor UUCP. */
+
+#include "uucp.h"
+
+/* Perform a binary search for KEY in BASE which has NMEMB elements
+ of SIZE bytes each. The comparisons are done by (*COMPAR)(). */
+pointer
+bsearch (key, base, nmemb, size, compar)
+ register constpointer key;
+ register constpointer base;
+ size_t nmemb;
+ register size_t size;
+ register int (*compar) P((constpointer, constpointer));
+{
+ register size_t l, u, idx;
+ register constpointer p;
+ register int comparison;
+
+ l = 0;
+ u = nmemb;
+ while (l < u)
+ {
+ idx = (l + u) / 2;
+ p = (constpointer) (((const char *) base) + (idx * size));
+ comparison = (*compar)(key, p);
+ if (comparison < 0)
+ u = idx;
+ else if (comparison > 0)
+ l = idx + 1;
+ else
+ return (pointer) p;
+ }
+
+ return NULL;
+}
diff --git a/gnu/libexec/uucp/libuucp/buffer.c b/gnu/libexec/uucp/libuucp/buffer.c
new file mode 100644
index 00000000000..c44fa451394
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/buffer.c
@@ -0,0 +1,109 @@
+/* buffer.c
+ Manipulate buffers used to hold strings.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of Taylor UUCP.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucp.h"
+
+#include "uudefs.h"
+
+/* We keep a linked list of buffers. The union is a hack because the
+ default definition of offsetof, in uucp.h, takes the address of the
+ field, and some C compilers will not let you take the address of an
+ array. */
+
+struct sbuf
+{
+ struct sbuf *qnext;
+ size_t c;
+ union
+ {
+ char ab[4];
+ char bdummy;
+ }
+ u;
+};
+
+static struct sbuf *qBlist;
+
+/* Get a buffer of a given size. The buffer is returned with the
+ ubuffree function. */
+
+char *
+zbufalc (c)
+ size_t c;
+{
+ register struct sbuf *q;
+
+ if (qBlist == NULL)
+ {
+ q = (struct sbuf *) xmalloc (sizeof (struct sbuf) + c - 4);
+ q->c = c;
+ }
+ else
+ {
+ q = qBlist;
+ qBlist = q->qnext;
+ if (q->c < c)
+ {
+ q = (struct sbuf *) xrealloc ((pointer) q,
+ sizeof (struct sbuf) + c - 4);
+ q->c = c;
+ }
+ }
+ return q->u.ab;
+}
+
+/* Get a buffer holding a given string. */
+
+char *
+zbufcpy (z)
+ const char *z;
+{
+ size_t csize;
+ char *zret;
+
+ if (z == NULL)
+ return NULL;
+ csize = strlen (z) + 1;
+ zret = zbufalc (csize);
+ memcpy (zret, z, csize);
+ return zret;
+}
+
+/* Free up a buffer back onto the linked list. */
+
+void
+ubuffree (z)
+ char *z;
+{
+ size_t ioff;
+ struct sbuf *q;
+
+ if (z == NULL)
+ return;
+ ioff = offsetof (struct sbuf, u);
+ q = (struct sbuf *) (pointer) (z - ioff);
+ q->qnext = qBlist;
+ qBlist = q;
+}
diff --git a/gnu/libexec/uucp/libuucp/bzero.c b/gnu/libexec/uucp/libuucp/bzero.c
new file mode 100644
index 00000000000..098e5515728
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/bzero.c
@@ -0,0 +1,15 @@
+/* bzero.c
+ Zero out a buffer. */
+
+#include "uucp.h"
+
+void
+bzero (parg, c)
+ pointer parg;
+ int c;
+{
+ char *p = (char *) parg;
+
+ while (c-- != 0)
+ *p++ = 0;
+}
diff --git a/gnu/libexec/uucp/libuucp/crc.c b/gnu/libexec/uucp/libuucp/crc.c
new file mode 100644
index 00000000000..fc9687b57cf
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/crc.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 1986 Gary S. Brown. You may use this program, or
+ * code or tables extracted from it, as desired without restriction.
+ */
+
+/* Modified slightly by Ian Lance Taylor, ian@airs.com, for use with
+ Taylor UUCP. */
+
+#include "uucp.h"
+#include "prot.h"
+
+/* First, the polynomial itself and its table of feedback terms. The */
+/* polynomial is */
+/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
+/* Note that we take it "backwards" and put the highest-order term in */
+/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */
+/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */
+/* the MSB being 1. */
+
+/* Note that the usual hardware shift register implementation, which */
+/* is what we're using (we're merely optimizing it by doing eight-bit */
+/* chunks at a time) shifts bits into the lowest-order term. In our */
+/* implementation, that means shifting towards the right. Why do we */
+/* do it this way? Because the calculated CRC must be transmitted in */
+/* order from highest-order term to lowest-order term. UARTs transmit */
+/* characters in order from LSB to MSB. By storing the CRC this way, */
+/* we hand it to the UART in the order low-byte to high-byte; the UART */
+/* sends each low-bit to hight-bit; and the result is transmission bit */
+/* by bit from highest- to lowest-order term without requiring any bit */
+/* shuffling on our part. Reception works similarly. */
+
+/* The feedback terms table consists of 256, 32-bit entries. Notes: */
+/* */
+/* The table can be generated at runtime if desired; code to do so */
+/* is shown later. It might not be obvious, but the feedback */
+/* terms simply represent the results of eight shift/xor opera- */
+/* tions for all combinations of data and CRC register values. */
+/* [this code is no longer present--ian] */
+/* */
+/* The values must be right-shifted by eight bits by the "updcrc" */
+/* logic; the shift must be unsigned (bring in zeroes). On some */
+/* hardware you could probably optimize the shift in assembler by */
+/* using byte-swap instructions. */
+
+static const unsigned long aicrc32tab[] = { /* CRC polynomial 0xedb88320 */
+0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
+0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
+0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
+0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
+0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
+0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
+0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
+0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
+0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
+0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
+0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
+0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
+0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
+0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
+0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
+0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
+0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
+0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
+0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
+0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
+0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
+0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
+0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
+0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
+0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
+0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
+0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
+0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
+0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
+0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
+0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
+0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL
+};
+
+/*
+ * IUPDC32 macro derived from article Copyright (C) 1986 Stephen Satchell.
+ * NOTE: First argument must be in range 0 to 255.
+ * Second argument is referenced twice.
+ *
+ * Programmers may incorporate any or all code into their programs,
+ * giving proper credit within the source. Publication of the
+ * source routines is permitted so long as proper credit is given
+ * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
+ * Omen Technology.
+ */
+
+#define IUPDC32(b, ick) \
+ (aicrc32tab[((int) (ick) ^ (b)) & 0xff] ^ (((ick) >> 8) & 0x00ffffffL))
+
+unsigned long
+icrc (z, c, ick)
+ const char *z;
+ size_t c;
+ unsigned long ick;
+{
+ while (c > 4)
+ {
+ ick = IUPDC32 (*z++, ick);
+ ick = IUPDC32 (*z++, ick);
+ ick = IUPDC32 (*z++, ick);
+ ick = IUPDC32 (*z++, ick);
+ c -= 4;
+ }
+ while (c-- != 0)
+ ick = IUPDC32 (*z++, ick);
+ return ick;
+}
diff --git a/gnu/libexec/uucp/libuucp/debug.c b/gnu/libexec/uucp/libuucp/debug.c
new file mode 100644
index 00000000000..86f784154ab
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/debug.c
@@ -0,0 +1,165 @@
+/* debug.c
+ UUCP debugging functions.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#include <ctype.h>
+
+#include "uudefs.h"
+
+/* The debugging level. */
+int iDebug;
+
+/* Parse a debugging string. This may be a simple number, which sets
+ the given number of bits in iDebug, or it may be a series of single
+ letters. */
+
+static const char * const azDebug_names[] = DEBUG_NAMES;
+
+int
+idebug_parse (z)
+ const char *z;
+{
+ char *zend;
+ int i, iret;
+ char *zcopy, *ztok;
+
+ if (strncasecmp (z, DEBUG_NONE, sizeof DEBUG_NONE - 1) == 0)
+ return 0;
+
+ i = (int) strtol ((char *) z, &zend, 0);
+ if (*zend == '\0')
+ {
+ if (i > 15)
+ i = 15;
+ else if (i < 0)
+ i = 0;
+ return (1 << i) - 1;
+ }
+
+ zcopy = zbufcpy (z);
+
+ iret = 0;
+
+ for (ztok = strtok (zcopy, ",");
+ ztok != NULL;
+ ztok = strtok ((char *) NULL, ","))
+ {
+ if (strcasecmp (ztok, "all") == 0)
+ {
+ iret = DEBUG_MAX;
+ break;
+ }
+ for (i = 0; azDebug_names[i] != NULL; i++)
+ {
+ if (strncasecmp (ztok, azDebug_names[i],
+ strlen (azDebug_names[i])) == 0)
+ {
+ iret |= 1 << i;
+ break;
+ }
+ }
+ if (azDebug_names[i] == NULL)
+ ulog (LOG_ERROR, "Unrecognized debugging option \"%s\"",
+ ztok);
+ }
+
+ ubuffree (zcopy);
+
+ return iret;
+}
+
+/* A debugging routine used when displaying buffers. */
+
+size_t
+cdebug_char (z, ichar)
+ char *z;
+ int ichar;
+{
+ char b;
+
+ if (isprint (BUCHAR (ichar))
+ && ichar != '\"'
+ && ichar != '\\')
+ {
+ *z++ = (char) ichar;
+ *z = '\0';
+ return 1;
+ }
+
+ *z++ = '\\';
+
+ switch (ichar)
+ {
+ case '\n':
+ b = 'n';
+ break;
+ case '\r':
+ b = 'r';
+ break;
+ case '\"':
+ b = '\"';
+ break;
+ case '\\':
+ b = '\\';
+ break;
+ default:
+ sprintf (z, "%03o", (unsigned int) BUCHAR (ichar));
+ return strlen (z) + 1;
+ }
+
+ *z++ = b;
+ *z = '\0';
+ return 2;
+}
+
+/* Display a buffer when debugging. */
+
+void
+udebug_buffer (zhdr, zbuf, clen)
+ const char *zhdr;
+ const char *zbuf;
+ size_t clen;
+{
+ char *z, *zalc;
+ int i;
+
+ zalc = zbufalc (clen * 4 + 1);
+
+ z = zalc;
+ for (i = 0; i < clen && i < 80; i++)
+ z += cdebug_char (z, zbuf[i]);
+ if (i < clen)
+ {
+ *z++ = '.';
+ *z++ = '.';
+ *z++ = '.';
+ }
+ *z = '\0';
+
+ ulog (LOG_DEBUG, "%s %lu \"%s\"", zhdr, (unsigned long) clen, zalc);
+
+ ubuffree (zalc);
+}
diff --git a/gnu/libexec/uucp/libuucp/escape.c b/gnu/libexec/uucp/libuucp/escape.c
new file mode 100644
index 00000000000..646b787d6e4
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/escape.c
@@ -0,0 +1,98 @@
+/* escape.c
+ Translate escape sequences. */
+
+#include "uucp.h"
+
+#include <ctype.h>
+
+#include "uudefs.h"
+
+size_t
+cescape (z)
+ char *z;
+{
+ char *zto, *zfrom;
+
+ zto = z;
+ zfrom = z;
+ while (*zfrom != '\0')
+ {
+ if (*zfrom != '\\')
+ {
+ *zto++ = *zfrom++;
+ continue;
+ }
+ ++zfrom;
+ switch (*zfrom)
+ {
+ case '-':
+ *zto++ = '-';
+ break;
+ case 'b':
+ *zto++ = '\b';
+ break;
+ case 'n':
+ *zto++ = '\n';
+ break;
+ case 'N':
+ *zto++ = '\0';
+ break;
+ case 'r':
+ *zto++ = '\r';
+ break;
+ case 's':
+ *zto++ = ' ';
+ break;
+ case 't':
+ *zto++ = '\t';
+ break;
+ case '\0':
+ --zfrom;
+ /* Fall through. */
+ case '\\':
+ *zto++ = '\\';
+ break;
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ {
+ int i;
+
+ i = *zfrom - '0';
+ if (zfrom[1] >= '0' && zfrom[1] <= '7')
+ i = 8 * i + *++zfrom - '0';
+ if (zfrom[1] >= '0' && zfrom[1] <= '7')
+ i = 8 * i + *++zfrom - '0';
+ *zto++ = (char) i;
+ }
+ break;
+ case 'x':
+ {
+ int i;
+
+ i = 0;
+ while (isxdigit (BUCHAR (zfrom[1])))
+ {
+ if (isdigit (BUCHAR (zfrom[1])))
+ i = 16 * i + *++zfrom - '0';
+ else if (isupper (BUCHAR (zfrom[1])))
+ i = 16 * i + *++zfrom - 'A' + 10;
+ else
+ i = 16 * i + *++zfrom - 'a' + 10;
+ }
+ *zto++ = (char) i;
+ }
+ break;
+ default:
+ ulog (LOG_ERROR, "Unrecognized escape sequence \\%c",
+ *zfrom);
+ *zto++ = *zfrom;
+ break;
+ }
+
+ ++zfrom;
+ }
+
+ *zto = '\0';
+
+ return (size_t) (zto - z);
+}
diff --git a/gnu/libexec/uucp/libuucp/getlin.c b/gnu/libexec/uucp/libuucp/getlin.c
new file mode 100644
index 00000000000..1c204e74ee3
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/getlin.c
@@ -0,0 +1,81 @@
+/* getlin.c
+ Replacement for getline.
+
+ Copyright (C) 1992 Ian Lance Taylor
+
+ This file is part of Taylor UUCP.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License
+ as published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; 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.
+ */
+
+#include "uucp.h"
+
+/* Read a line from a file, returning the number of characters read.
+ This should really return ssize_t. Returns -1 on error. */
+
+#define CGETLINE_DEFAULT (63)
+
+int
+getline (pzline, pcline, e)
+ char **pzline;
+ size_t *pcline;
+ FILE *e;
+{
+ char *zput, *zend;
+ int bchar;
+
+ if (*pzline == NULL)
+ {
+ *pzline = (char *) malloc (CGETLINE_DEFAULT);
+ if (*pzline == NULL)
+ return -1;
+ *pcline = CGETLINE_DEFAULT;
+ }
+
+ zput = *pzline;
+ zend = *pzline + *pcline - 1;
+
+ while ((bchar = getc (e)) != EOF)
+ {
+ if (zput >= zend)
+ {
+ size_t cnew;
+ char *znew;
+
+ cnew = *pcline * 2 + 1;
+ znew = (char *) realloc ((pointer) *pzline, cnew);
+ if (znew == NULL)
+ return -1;
+ zput = znew + *pcline - 1;
+ zend = znew + cnew - 1;
+ *pzline = znew;
+ *pcline = cnew;
+ }
+
+ *zput++ = bchar;
+
+ if (bchar == '\n')
+ break;
+ }
+
+ if (zput == *pzline)
+ return -1;
+
+ *zput = '\0';
+ return zput - *pzline;
+}
diff --git a/gnu/libexec/uucp/libuucp/getop1.c b/gnu/libexec/uucp/libuucp/getop1.c
new file mode 100644
index 00000000000..c3ebc08bb3f
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/getop1.c
@@ -0,0 +1,144 @@
+/* Getopt for GNU.
+ Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
+
+ 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, 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ This file was modified slightly by Ian Lance Taylor, June 1992, for
+ Taylor UUCP. */
+
+#include "uucp.h"
+
+#include "getopt.h"
+
+int
+getopt_long (argc, argv, options, long_options, opt_index)
+ int argc;
+ char *const *argv;
+ const char *options;
+ const struct option *long_options;
+ int *opt_index;
+{
+ return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
+}
+
+/* Like getopt_long, but '-' as well as '--' can indicate a long option.
+ If an option that starts with '-' (not '--') doesn't match a long option,
+ but does match a short option, it is parsed as a short option
+ instead. */
+
+int
+getopt_long_only (argc, argv, options, long_options, opt_index)
+ int argc;
+ char *const *argv;
+ const char *options;
+ const struct option *long_options;
+ int *opt_index;
+{
+ return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
+}
+
+#ifdef TEST
+
+#include <stdio.h>
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+ int option_index = 0;
+ static struct option long_options[] =
+ {
+ {"add", 1, 0, 0},
+ {"append", 0, 0, 0},
+ {"delete", 1, 0, 0},
+ {"verbose", 0, 0, 0},
+ {"create", 0, 0, 0},
+ {"file", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long (argc, argv, "abc:d:0123456789",
+ long_options, &option_index);
+ if (c == EOF)
+ break;
+
+ switch (c)
+ {
+ case 0:
+ printf ("option %s", long_options[option_index].name);
+ if (optarg)
+ printf (" with arg %s", optarg);
+ printf ("\n");
+ break;
+
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\n");
+ break;
+
+ case 'b':
+ printf ("option b\n");
+ break;
+
+ case 'c':
+ printf ("option c with value `%s'\n", optarg);
+ break;
+
+ case 'd':
+ printf ("option d with value `%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\n");
+ }
+
+ exit (0);
+}
+
+#endif /* TEST */
diff --git a/gnu/libexec/uucp/libuucp/getopt.c b/gnu/libexec/uucp/libuucp/getopt.c
new file mode 100644
index 00000000000..f97c64eda54
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/getopt.c
@@ -0,0 +1,621 @@
+/* Getopt for GNU.
+ NOTE: getopt is now part of the C library, so if you don't know what
+ "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
+ before changing it!
+
+ Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
+
+ 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, 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ This file was modified slightly by Ian Lance Taylor, June 1992, for
+ Taylor UUCP. */
+
+#include "uucp.h"
+#include "uudefs.h"
+
+/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
+ long-named option. Because this is not POSIX.2 compliant, it is
+ being phased out. */
+#undef GETOPT_COMPAT
+
+/* This version of `getopt' appears to the caller like standard Unix `getopt'
+ but it behaves differently for the user, since it allows the user
+ to intersperse the options with the other arguments.
+
+ As `getopt' works, it permutes the elements of ARGV so that,
+ when it is done, all the options precede everything else. Thus
+ all application programs are extended to handle flexible argument order.
+
+ Setting the environment variable POSIXLY_CORRECT disables permutation.
+ Then the behavior is completely standard.
+
+ GNU application programs can use a third alternative mode in which
+ they can distinguish the relative order of options and other arguments. */
+
+#include "getopt.h"
+
+/* For communication from `getopt' to the caller.
+ When `getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when `ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+char *optarg = 0;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to `getopt'.
+
+ On entry to `getopt', zero means this is the first call; initialize.
+
+ When `getopt' returns EOF, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, `optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+int optind = 0;
+
+/* The next char to be scanned in the option-element
+ in which the last option character we returned was found.
+ This allows us to pick up the scan where we left off.
+
+ If this is zero, or a null string, it means resume the scan
+ by advancing to the next ARGV-element. */
+
+static char *nextchar;
+
+/* Callers store zero here to inhibit the error message
+ for unrecognized options. */
+
+int opterr = 1;
+
+/* Describe how to deal with options that follow non-option ARGV-elements.
+
+ If the caller did not specify anything,
+ the default is REQUIRE_ORDER if the environment variable
+ POSIXLY_CORRECT is defined, PERMUTE otherwise.
+
+ REQUIRE_ORDER means don't recognize them as options;
+ stop option processing when the first non-option is seen.
+ This is what Unix does.
+ This mode of operation is selected by either setting the environment
+ variable POSIXLY_CORRECT, or using `+' as the first character
+ of the list of option characters.
+
+ PERMUTE is the default. We permute the contents of ARGV as we scan,
+ so that eventually all the non-options are at the end. This allows options
+ to be given in any order, even with programs that were not written to
+ expect this.
+
+ RETURN_IN_ORDER is an option available to programs that were written
+ to expect options and other ARGV-elements in any order and that care about
+ the ordering of the two. We describe each non-option ARGV-element
+ as if it were the argument of an option with character code 1.
+ Using `-' as the first character of the list of option characters
+ selects this mode of operation.
+
+ The special argument `--' forces an end of option-scanning regardless
+ of the value of `ordering'. In the case of RETURN_IN_ORDER, only
+ `--' can cause `getopt' to return EOF with `optind' != ARGC. */
+
+static enum
+{
+ REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+} ordering;
+
+#define my_index strchr
+#define my_bcopy(src, dst, n) memcpy ((dst), (src), (n))
+
+/* Handle permutation of arguments. */
+
+/* Describe the part of ARGV that contains non-options that have
+ been skipped. `first_nonopt' is the index in ARGV of the first of them;
+ `last_nonopt' is the index after the last of them. */
+
+static int first_nonopt;
+static int last_nonopt;
+
+/* Exchange two adjacent subsequences of ARGV.
+ One subsequence is elements [first_nonopt,last_nonopt)
+ which contains all the non-options that have been skipped so far.
+ The other is elements [last_nonopt,optind), which contains all
+ the options processed since those non-options were skipped.
+
+ `first_nonopt' and `last_nonopt' are relocated so that they describe
+ the new indices of the non-options in ARGV after they are moved. */
+
+static void
+exchange (argv)
+ char **argv;
+{
+ size_t nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
+ char **temp = (char **) malloc (nonopts_size);
+
+ if (temp == NULL)
+ abort ();
+
+ /* Interchange the two blocks of data in ARGV. */
+
+ my_bcopy ((char *) &argv[first_nonopt], (char *) temp, nonopts_size);
+ my_bcopy ((char *) &argv[last_nonopt], (char *) &argv[first_nonopt],
+ (optind - last_nonopt) * sizeof (char *));
+ my_bcopy ((char *) temp,
+ (char *) &argv[first_nonopt + optind - last_nonopt],
+ nonopts_size);
+
+ xfree (temp);
+
+ /* Update records for the slots the non-options now occupy. */
+
+ first_nonopt += (optind - last_nonopt);
+ last_nonopt = optind;
+}
+
+/* Scan elements of ARGV (whose length is ARGC) for option characters
+ given in OPTSTRING.
+
+ If an element of ARGV starts with '-', and is not exactly "-" or "--",
+ then it is an option element. The characters of this element
+ (aside from the initial '-') are option characters. If `getopt'
+ is called repeatedly, it returns successively each of the option characters
+ from each of the option elements.
+
+ If `getopt' finds another option character, it returns that character,
+ updating `optind' and `nextchar' so that the next call to `getopt' can
+ resume the scan with the following option character or ARGV-element.
+
+ If there are no more option characters, `getopt' returns `EOF'.
+ Then `optind' is the index in ARGV of the first ARGV-element
+ that is not an option. (The ARGV-elements have been permuted
+ so that those that are not options now come last.)
+
+ OPTSTRING is a string containing the legitimate option characters.
+ If an option character is seen that is not listed in OPTSTRING,
+ return '?' after printing an error message. If you set `opterr' to
+ zero, the error message is suppressed but we still return '?'.
+
+ If a char in OPTSTRING is followed by a colon, that means it wants an arg,
+ so the following text in the same ARGV-element, or the text of the following
+ ARGV-element, is returned in `optarg'. Two colons mean an option that
+ wants an optional arg; if there is text in the current ARGV-element,
+ it is returned in `optarg', otherwise `optarg' is set to zero.
+
+ If OPTSTRING starts with `-' or `+', it requests different methods of
+ handling the non-option ARGV-elements.
+ See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
+
+ Long-named options begin with `--' instead of `-'.
+ Their names may be abbreviated as long as the abbreviation is unique
+ or is an exact match for some defined option. If they have an
+ argument, it follows the option name in the same ARGV-element, separated
+ from the option name by a `=', or else the in next ARGV-element.
+ When `getopt' finds a long-named option, it returns 0 if that option's
+ `flag' field is nonzero, the value of the option's `val' field
+ if the `flag' field is zero.
+
+ The elements of ARGV aren't really const, because we permute them.
+ But we pretend they're const in the prototype to be compatible
+ with other systems.
+
+ LONGOPTS is a vector of `struct option' terminated by an
+ element containing a name which is zero.
+
+ LONGIND returns the index in LONGOPT of the long-named option found.
+ It is only valid when a long-named option has been found by the most
+ recent call.
+
+ If LONG_ONLY is nonzero, '-' as well as '--' can introduce
+ long-named options. */
+
+int
+_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
+ int argc;
+ char *const *argv;
+ const char *optstring;
+ const struct option *longopts;
+ int *longind;
+ int long_only;
+{
+ int option_index;
+
+ optarg = 0;
+
+ /* Initialize the internal data when the first call is made.
+ Start processing options with ARGV-element 1 (since ARGV-element 0
+ is the program name); the sequence of previously skipped
+ non-option ARGV-elements is empty. */
+
+ if (optind == 0)
+ {
+ first_nonopt = last_nonopt = optind = 1;
+
+ nextchar = NULL;
+
+ /* Determine how to handle the ordering of options and nonoptions. */
+
+ if (optstring[0] == '-')
+ {
+ ordering = RETURN_IN_ORDER;
+ ++optstring;
+ }
+ else if (optstring[0] == '+')
+ {
+ ordering = REQUIRE_ORDER;
+ ++optstring;
+ }
+ else if (getenv ("POSIXLY_CORRECT") != NULL)
+ ordering = REQUIRE_ORDER;
+ else
+ ordering = PERMUTE;
+ }
+
+ if (nextchar == NULL || *nextchar == '\0')
+ {
+ if (ordering == PERMUTE)
+ {
+ /* If we have just processed some options following some non-options,
+ exchange them so that the options come first. */
+
+ if (first_nonopt != last_nonopt && last_nonopt != optind)
+ exchange ((char **) argv);
+ else if (last_nonopt != optind)
+ first_nonopt = optind;
+
+ /* Now skip any additional non-options
+ and extend the range of non-options previously skipped. */
+
+ while (optind < argc
+ && (argv[optind][0] != '-' || argv[optind][1] == '\0')
+#ifdef GETOPT_COMPAT
+ && (longopts == NULL
+ || argv[optind][0] != '+' || argv[optind][1] == '\0')
+#endif /* GETOPT_COMPAT */
+ )
+ optind++;
+ last_nonopt = optind;
+ }
+
+ /* Special ARGV-element `--' means premature end of options.
+ Skip it like a null option,
+ then exchange with previous non-options as if it were an option,
+ then skip everything else like a non-option. */
+
+ if (optind != argc && !strcmp (argv[optind], "--"))
+ {
+ optind++;
+
+ if (first_nonopt != last_nonopt && last_nonopt != optind)
+ exchange ((char **) argv);
+ else if (first_nonopt == last_nonopt)
+ first_nonopt = optind;
+ last_nonopt = argc;
+
+ optind = argc;
+ }
+
+ /* If we have done all the ARGV-elements, stop the scan
+ and back over any non-options that we skipped and permuted. */
+
+ if (optind == argc)
+ {
+ /* Set the next-arg-index to point at the non-options
+ that we previously skipped, so the caller will digest them. */
+ if (first_nonopt != last_nonopt)
+ optind = first_nonopt;
+ return EOF;
+ }
+
+ /* If we have come to a non-option and did not permute it,
+ either stop the scan or describe it to the caller and pass it by. */
+
+ if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
+#ifdef GETOPT_COMPAT
+ && (longopts == NULL
+ || argv[optind][0] != '+' || argv[optind][1] == '\0')
+#endif /* GETOPT_COMPAT */
+ )
+ {
+ if (ordering == REQUIRE_ORDER)
+ return EOF;
+ optarg = argv[optind++];
+ return 1;
+ }
+
+ /* We have found another option-ARGV-element.
+ Start decoding its characters. */
+
+ nextchar = (argv[optind] + 1
+ + (longopts != NULL && argv[optind][1] == '-'));
+ }
+
+ if (longopts != NULL
+ && ((argv[optind][0] == '-'
+ && (argv[optind][1] == '-' || long_only))
+#ifdef GETOPT_COMPAT
+ || argv[optind][0] == '+'
+#endif /* GETOPT_COMPAT */
+ ))
+ {
+ const struct option *p;
+ char *s = nextchar;
+ int exact = 0;
+ int ambig = 0;
+ const struct option *pfound = NULL;
+ int indfound = 0;
+
+ while (*s && *s != '=')
+ s++;
+
+ /* Test all options for either exact match or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name;
+ p++, option_index++)
+ if (!strncmp (p->name, nextchar, (size_t) (s - nextchar)))
+ {
+ if (s - nextchar == strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else
+ /* Second nonexact match found. */
+ ambig = 1;
+ }
+
+ if (ambig && !exact)
+ {
+ if (opterr)
+ fprintf (stderr, "%s: option `%s' is ambiguous\n",
+ argv[0], argv[optind]);
+ nextchar += strlen (nextchar);
+ optind++;
+ return '?';
+ }
+
+ if (pfound != NULL)
+ {
+ option_index = indfound;
+ optind++;
+ if (*s)
+ {
+ /* Don't test has_arg with >, because some C compilers don't
+ allow it to be used on enums. */
+ if (pfound->has_arg)
+ optarg = s + 1;
+ else
+ {
+ if (opterr)
+ {
+ if (argv[optind - 1][1] == '-')
+ /* --option */
+ fprintf (stderr,
+ "%s: option `--%s' doesn't allow an argument\n",
+ argv[0], pfound->name);
+ else
+ /* +option or -option */
+ fprintf (stderr,
+ "%s: option `%c%s' doesn't allow an argument\n",
+ argv[0], argv[optind - 1][0], pfound->name);
+ }
+ nextchar += strlen (nextchar);
+ return '?';
+ }
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (optind < argc)
+ optarg = argv[optind++];
+ else
+ {
+ if (opterr)
+ fprintf (stderr, "%s: option `%s' requires an argument\n",
+ argv[0], argv[optind - 1]);
+ nextchar += strlen (nextchar);
+ return '?';
+ }
+ }
+ nextchar += strlen (nextchar);
+ if (longind != NULL)
+ *longind = option_index;
+ if (pfound->flag)
+ {
+ *(pfound->flag) = pfound->val;
+ return 0;
+ }
+ return pfound->val;
+ }
+ /* Can't find it as a long option. If this is not getopt_long_only,
+ or the option starts with '--' or is not a valid short
+ option, then it's an error.
+ Otherwise interpret it as a short option. */
+ if (!long_only || argv[optind][1] == '-'
+#ifdef GETOPT_COMPAT
+ || argv[optind][0] == '+'
+#endif /* GETOPT_COMPAT */
+ || my_index (optstring, *nextchar) == NULL)
+ {
+ if (opterr)
+ {
+ if (argv[optind][1] == '-')
+ /* --option */
+ fprintf (stderr, "%s: unrecognized option `--%s'\n",
+ argv[0], nextchar);
+ else
+ /* +option or -option */
+ fprintf (stderr, "%s: unrecognized option `%c%s'\n",
+ argv[0], argv[optind][0], nextchar);
+ }
+ nextchar = (char *) "";
+ optind++;
+ return '?';
+ }
+ }
+
+ /* Look at and handle the next option-character. */
+
+ {
+ char c = *nextchar++;
+ char *temp = my_index (optstring, c);
+
+ /* Increment `optind' when we start to process its last character. */
+ if (*nextchar == '\0')
+ ++optind;
+
+ if (temp == NULL || c == ':')
+ {
+ if (opterr)
+ {
+ if (c < 040 || c >= 0177)
+ fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
+ argv[0], (unsigned int) c);
+ else
+ fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
+ }
+ return '?';
+ }
+ if (temp[1] == ':')
+ {
+ if (temp[2] == ':')
+ {
+ /* This is an option that accepts an argument optionally. */
+ if (*nextchar != '\0')
+ {
+ optarg = nextchar;
+ optind++;
+ }
+ else
+ optarg = 0;
+ nextchar = NULL;
+ }
+ else
+ {
+ /* This is an option that requires an argument. */
+ if (*nextchar != '\0')
+ {
+ optarg = nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ we must advance to the next element now. */
+ optind++;
+ }
+ else if (optind == argc)
+ {
+ if (opterr)
+ fprintf (stderr, "%s: option `-%c' requires an argument\n",
+ argv[0], c);
+ c = '?';
+ }
+ else
+ /* We already incremented `optind' once;
+ increment it again when taking next ARGV-elt as argument. */
+ optarg = argv[optind++];
+ nextchar = NULL;
+ }
+ }
+ return c;
+ }
+}
+
+int
+getopt (argc, argv, optstring)
+ int argc;
+ char *const *argv;
+ const char *optstring;
+{
+ return _getopt_internal (argc, argv, optstring,
+ (const struct option *) 0,
+ (int *) 0,
+ 0);
+}
+
+#ifdef TEST
+
+/* Compile with -DTEST to make an executable for use in testing
+ the above definition of `getopt'. */
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+
+ c = getopt (argc, argv, "abc:d:0123456789");
+ if (c == EOF)
+ break;
+
+ switch (c)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\n");
+ break;
+
+ case 'b':
+ printf ("option b\n");
+ break;
+
+ case 'c':
+ printf ("option c with value `%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\n");
+ }
+
+ exit (0);
+}
+
+#endif /* TEST */
diff --git a/gnu/libexec/uucp/libuucp/memchr.c b/gnu/libexec/uucp/libuucp/memchr.c
new file mode 100644
index 00000000000..e1f399afeb3
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/memchr.c
@@ -0,0 +1,149 @@
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+ Based on strlen implemention by Torbjorn Granlund (tege@sics.se),
+ with help from Dan Sahlin (dan@sics.se) and
+ commentary by Jim Blandy (jimb@ai.mit.edu);
+ adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
+ and implemented by Roland McGrath (roland@ai.mit.edu).
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.
+
+This file was modified slightly by Ian Lance Taylor, May 1992, for
+Taylor UUCP. It assumes 32 bit longs. I'm willing to trust that any
+system which does not have 32 bit longs will have its own
+implementation of memchr. */
+
+#include "uucp.h"
+
+/* Search no more than N bytes of S for C. */
+
+pointer
+memchr (s, c, n)
+ constpointer s;
+ int c;
+ size_t n;
+{
+ const char *char_ptr;
+ const unsigned long int *longword_ptr;
+ unsigned long int longword, magic_bits, charmask;
+
+ c = BUCHAR (c);
+
+ /* Handle the first few characters by reading one character at a time.
+ Do this until CHAR_PTR is aligned on a 4-byte border. */
+ for (char_ptr = s; n > 0 && ((unsigned long int) char_ptr & 3) != 0;
+ --n, ++char_ptr)
+ if (BUCHAR (*char_ptr) == c)
+ return (pointer) char_ptr;
+
+ longword_ptr = (unsigned long int *) char_ptr;
+
+ /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits
+ the "holes." Note that there is a hole just to the left of
+ each byte, with an extra at the end:
+
+ bits: 01111110 11111110 11111110 11111111
+ bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
+
+ The 1-bits make sure that carries propagate to the next 0-bit.
+ The 0-bits provide holes for carries to fall into. */
+ magic_bits = 0x7efefeff;
+
+ /* Set up a longword, each of whose bytes is C. */
+ charmask = c | (c << 8);
+ charmask |= charmask << 16;
+
+ /* Instead of the traditional loop which tests each character,
+ we will test a longword at a time. The tricky part is testing
+ if *any of the four* bytes in the longword in question are zero. */
+ while (n >= 4)
+ {
+ /* We tentatively exit the loop if adding MAGIC_BITS to
+ LONGWORD fails to change any of the hole bits of LONGWORD.
+
+ 1) Is this safe? Will it catch all the zero bytes?
+ Suppose there is a byte with all zeros. Any carry bits
+ propagating from its left will fall into the hole at its
+ least significant bit and stop. Since there will be no
+ carry from its most significant bit, the LSB of the
+ byte to the left will be unchanged, and the zero will be
+ detected.
+
+ 2) Is this worthwhile? Will it ignore everything except
+ zero bytes? Suppose every byte of LONGWORD has a bit set
+ somewhere. There will be a carry into bit 8. If bit 8
+ is set, this will carry into bit 16. If bit 8 is clear,
+ one of bits 9-15 must be set, so there will be a carry
+ into bit 16. Similarly, there will be a carry into bit
+ 24. If one of bits 24-30 is set, there will be a carry
+ into bit 31, so all of the hole bits will be changed.
+
+ The one misfire occurs when bits 24-30 are clear and bit
+ 31 is set; in this case, the hole at bit 31 is not
+ changed. If we had access to the processor carry flag,
+ we could close this loophole by putting the fourth hole
+ at bit 32!
+
+ So it ignores everything except 128's, when they're aligned
+ properly.
+
+ 3) But wait! Aren't we looking for C, not zero?
+ Good point. So what we do is XOR LONGWORD with a longword,
+ each of whose bytes is C. This turns each byte that is C
+ into a zero. */
+
+ longword = *longword_ptr++ ^ charmask;
+
+ /* Add MAGIC_BITS to LONGWORD. */
+ if ((((longword + magic_bits)
+
+ /* Set those bits that were unchanged by the addition. */
+ ^ ~longword)
+
+ /* Look at only the hole bits. If any of the hole bits
+ are unchanged, most likely one of the bytes was a
+ zero. */
+ & ~magic_bits) != 0)
+ {
+ /* Which of the bytes was C? If none of them were, it was
+ a misfire; continue the search. */
+
+ const char *cp = (const char *) (longword_ptr - 1);
+
+ if (BUCHAR (cp[0]) == c)
+ return (pointer) cp;
+ if (BUCHAR (cp[1]) == c)
+ return (pointer) &cp[1];
+ if (BUCHAR (cp[2]) == c)
+ return (pointer) &cp[2];
+ if (BUCHAR (cp[3]) == c)
+ return (pointer) &cp[3];
+ }
+
+ n -= 4;
+ }
+
+ char_ptr = (const char *) longword_ptr;
+
+ while (n-- > 0)
+ {
+ if (BUCHAR (*char_ptr) == c)
+ return (pointer) char_ptr;
+ else
+ ++char_ptr;
+ }
+
+ return NULL;
+}
diff --git a/gnu/libexec/uucp/libuucp/memcmp.c b/gnu/libexec/uucp/libuucp/memcmp.c
new file mode 100644
index 00000000000..b61578a4af1
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/memcmp.c
@@ -0,0 +1,19 @@
+/* memcmp.c
+ Compare two memory buffers. */
+
+#include "uucp.h"
+
+int
+memcmp (p1arg, p2arg, c)
+ constpointer p1arg;
+ constpointer p2arg;
+ size_t c;
+{
+ const char *p1 = (const char *) p1arg;
+ const char *p2 = (const char *) p2arg;
+
+ while (c-- != 0)
+ if (*p1++ != *p2++)
+ return BUCHAR (*--p1) - BUCHAR (*--p2);
+ return 0;
+}
diff --git a/gnu/libexec/uucp/libuucp/memcpy.c b/gnu/libexec/uucp/libuucp/memcpy.c
new file mode 100644
index 00000000000..2258123752a
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/memcpy.c
@@ -0,0 +1,18 @@
+/* memcpy.c
+ Copy one memory buffer to another. */
+
+#include "uucp.h"
+
+pointer
+memcpy (ptoarg, pfromarg, c)
+ pointer ptoarg;
+ constpointer pfromarg;
+ size_t c;
+{
+ char *pto = (char *) ptoarg;
+ const char *pfrom = (const char *) pfromarg;
+
+ while (c-- != 0)
+ *pto++ = *pfrom++;
+ return ptoarg;
+}
diff --git a/gnu/libexec/uucp/libuucp/parse.c b/gnu/libexec/uucp/libuucp/parse.c
new file mode 100644
index 00000000000..6b928a4eed4
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/parse.c
@@ -0,0 +1,207 @@
+/* parse.c
+ Parse a UUCP command string.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char parse_rcsid[] = "$Id: parse.c,v 1.1 1993/08/04 19:35:49 jtc Exp $";
+#endif
+
+#include "uudefs.h"
+
+/* Parse a UUCP command string into an scmd structure. This is called
+ by the 'g' protocol and the UNIX command file reading routines. It
+ destroys the string it is passed, and the scmd string pointers are
+ left pointing into it. For the convenience of the Unix work file
+ routines, it will parse "P" into a simple 'P' command (representing
+ a poll file). It returns TRUE if the string is successfully
+ parsed, FALSE otherwise. */
+
+boolean
+fparse_cmd (zcmd, qcmd)
+ char *zcmd;
+ struct scmd *qcmd;
+{
+ char *z, *zend;
+
+ z = strtok (zcmd, " \t\n");
+ if (z == NULL)
+ return FALSE;
+
+ qcmd->bcmd = *z;
+ if (qcmd->bcmd != 'S'
+ && qcmd->bcmd != 'R'
+ && qcmd->bcmd != 'X'
+ && qcmd->bcmd != 'E'
+ && qcmd->bcmd != 'H'
+ && qcmd->bcmd != 'P')
+ return FALSE;
+
+ qcmd->pseq = NULL;
+ qcmd->zfrom = NULL;
+ qcmd->zto = NULL;
+ qcmd->zuser = NULL;
+ qcmd->zoptions = NULL;
+ qcmd->ztemp = NULL;
+ qcmd->imode = 0666;
+ qcmd->znotify = NULL;
+ qcmd->cbytes = -1;
+ qcmd->zcmd = NULL;
+ qcmd->ipos = 0;
+
+ /* Handle hangup commands specially. If it's just "H", return
+ the command 'H' to indicate a hangup request. If it's "HY"
+ return 'Y' and if it's "HN" return 'N'. */
+ if (qcmd->bcmd == 'H')
+ {
+ if (z[1] != '\0')
+ {
+ if (z[1] == 'Y')
+ qcmd->bcmd = 'Y';
+ else if (z[1] == 'N')
+ qcmd->bcmd = 'N';
+ else
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+ if (qcmd->bcmd == 'P')
+ return TRUE;
+
+ if (z[1] != '\0')
+ return FALSE;
+
+ z = strtok ((char *) NULL, " \t\n");
+ if (z == NULL)
+ return FALSE;
+ qcmd->zfrom = z;
+
+ z = strtok ((char *) NULL, " \t\n");
+ if (z == NULL)
+ return FALSE;
+ qcmd->zto = z;
+
+ z = strtok ((char *) NULL, " \t\n");
+ if (z == NULL)
+ return FALSE;
+ qcmd->zuser = z;
+
+ z = strtok ((char *) NULL, " \t\n");
+ if (z == NULL || *z != '-')
+ return FALSE;
+ qcmd->zoptions = z + 1;
+
+ if (qcmd->bcmd == 'X')
+ return TRUE;
+
+ if (qcmd->bcmd == 'R')
+ {
+ z = strtok ((char *) NULL, " \t\n");
+ if (z != NULL)
+ {
+ if (strcmp (z, "dummy") != 0)
+ {
+ /* This may be the maximum number of bytes the remote
+ system wants to receive, if it using Taylor UUCP size
+ negotiation. */
+ qcmd->cbytes = strtol (z, &zend, 0);
+ if (*zend != '\0')
+ qcmd->cbytes = -1;
+ }
+ else
+ {
+ /* This is from an SVR4 system, and may include the
+ position at which to start sending the file. The
+ next fields are the mode bits, the remote owner (?),
+ the remote temporary file name, and finally the
+ restart position. */
+ if (strtok ((char *) NULL, " \t\n") != NULL
+ && strtok ((char *) NULL, " \t\n") != NULL
+ && strtok ((char *) NULL, " \t\n") != NULL)
+ {
+ z = strtok ((char *) NULL, " \t\n");
+ if (z != NULL)
+ {
+ qcmd->ipos = strtol (z, &zend, 0);
+ if (*zend != '\0')
+ qcmd->ipos = 0;
+ }
+ }
+ }
+ }
+
+ return TRUE;
+ }
+
+ z = strtok ((char *) NULL, " \t\n");
+ if (z == NULL)
+ return FALSE;
+ qcmd->ztemp = z;
+
+ z = strtok ((char *) NULL, " \t\n");
+ if (z == NULL)
+ return FALSE;
+ qcmd->imode = (int) strtol (z, &zend, 8);
+ if (*zend != '\0')
+ return FALSE;
+
+ z = strtok ((char *) NULL, " \t\n");
+ if (qcmd->bcmd == 'E' && z == NULL)
+ return FALSE;
+ qcmd->znotify = z;
+
+ /* SVR4 UUCP will send the string "dummy" after the notify string
+ but before the size. I do not know when it sends anything other
+ than "dummy". Fortunately, it doesn't really hurt to not get the
+ file size. */
+ if (z != NULL && strcmp (z, "dummy") == 0)
+ z = strtok ((char *) NULL, " \t\n");
+
+ if (z != NULL)
+ {
+ z = strtok ((char *) NULL, " \t\n");
+ if (z != NULL)
+ {
+ qcmd->cbytes = strtol (z, &zend, 0);
+ if (*zend != '\0')
+ qcmd->cbytes = -1;
+ }
+ else if (qcmd->bcmd == 'E')
+ return FALSE;
+
+ if (z != NULL)
+ {
+ z = strtok ((char *) NULL, "");
+ if (z != NULL)
+ z[strcspn (z, "\n")] = '\0';
+ if (qcmd->bcmd == 'E' && z == NULL)
+ return FALSE;
+ qcmd->zcmd = z;
+ }
+ }
+
+ return TRUE;
+}
diff --git a/gnu/libexec/uucp/libuucp/spool.c b/gnu/libexec/uucp/libuucp/spool.c
new file mode 100644
index 00000000000..52223fb585a
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/spool.c
@@ -0,0 +1,30 @@
+/* spool.c
+ See whether a filename is legal for the spool directory. */
+
+#include "uucp.h"
+
+#include <ctype.h>
+
+#include "uudefs.h"
+
+/* See whether a file is a spool file. Spool file names are specially
+ crafted to hand around to other UUCP packages. They always begin
+ with 'C', 'D' or 'X', and the second character is always a period.
+ The remaining characters may be any printable characters, since
+ they may include a grade set by another system. */
+
+boolean
+fspool_file (zfile)
+ const char *zfile;
+{
+ const char *z;
+
+ if (*zfile != 'C' && *zfile != 'D' && *zfile != 'X')
+ return FALSE;
+ if (zfile[1] != '.')
+ return FALSE;
+ for (z = zfile + 2; *z != '\0'; z++)
+ if (*z == '/' || ! isprint (BUCHAR (*z)) || isspace (BUCHAR (*z)))
+ return FALSE;
+ return TRUE;
+}
diff --git a/gnu/libexec/uucp/libuucp/status.c b/gnu/libexec/uucp/libuucp/status.c
new file mode 100644
index 00000000000..bee5f83dd08
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/status.c
@@ -0,0 +1,20 @@
+/* status.c
+ Strings for status codes. */
+
+#include "uucp.h"
+
+#include "uudefs.h"
+
+/* Status strings. These must match enum tstatus_type. */
+
+const char *azStatus[] =
+{
+ "Conversation complete",
+ "Port unavailable",
+ "Dial failed",
+ "Login failed",
+ "Handshake failed",
+ "Call failed",
+ "Talking",
+ "Wrong time to call"
+};
diff --git a/gnu/libexec/uucp/libuucp/strcas.c b/gnu/libexec/uucp/libuucp/strcas.c
new file mode 100644
index 00000000000..4bb22511292
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/strcas.c
@@ -0,0 +1,33 @@
+/* strcas.c
+ Compare two strings case insensitively. */
+
+#include "uucp.h"
+#include <ctype.h>
+
+int
+strcasecmp (z1, z2)
+ const char *z1;
+ const char *z2;
+{
+ char b1, b2;
+
+ while ((b1 = *z1++) != '\0')
+ {
+ b2 = *z2++;
+ if (b2 == '\0')
+ return 1;
+ if (b1 != b2)
+ {
+ if (isupper (BUCHAR (b1)))
+ b1 = tolower (BUCHAR (b1));
+ if (isupper (BUCHAR (b2)))
+ b2 = tolower (BUCHAR (b2));
+ if (b1 != b2)
+ return b1 - b2;
+ }
+ }
+ if (*z2 == '\0')
+ return 0;
+ else
+ return -1;
+}
diff --git a/gnu/libexec/uucp/libuucp/strchr.c b/gnu/libexec/uucp/libuucp/strchr.c
new file mode 100644
index 00000000000..ca8d8e9b1bd
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/strchr.c
@@ -0,0 +1,16 @@
+/* strchr.c
+ Look for a character in a string. This works for a null byte. */
+
+#include "uucp.h"
+
+char *
+strchr (z, b)
+ const char *z;
+ int b;
+{
+ b = (char) b;
+ while (*z != b)
+ if (*z++ == '\0')
+ return NULL;
+ return (char *) z;
+}
diff --git a/gnu/libexec/uucp/libuucp/strdup.c b/gnu/libexec/uucp/libuucp/strdup.c
new file mode 100644
index 00000000000..231e35b3f61
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/strdup.c
@@ -0,0 +1,18 @@
+/* strdup.c
+ Duplicate a string into memory. */
+
+#include "uucp.h"
+
+char *
+strdup (z)
+ const char *z;
+{
+ size_t csize;
+ char *zret;
+
+ csize = strlen (z) + 1;
+ zret = malloc (csize);
+ if (zret != NULL)
+ memcpy (zret, z, csize);
+ return zret;
+}
diff --git a/gnu/libexec/uucp/libuucp/strncs.c b/gnu/libexec/uucp/libuucp/strncs.c
new file mode 100644
index 00000000000..6959d625d6d
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/strncs.c
@@ -0,0 +1,39 @@
+/* strncs.c
+ Compare two strings case insensitively up to a point. */
+
+#include "uucp.h"
+#include <ctype.h>
+
+int
+strncasecmp (z1, z2, c)
+ const char *z1;
+ const char *z2;
+ size_t c;
+{
+ char b1, b2;
+
+ if (c == 0)
+ return 0;
+ while ((b1 = *z1++) != '\0')
+ {
+ b2 = *z2++;
+ if (b2 == '\0')
+ return 1;
+ if (b1 != b2)
+ {
+ if (isupper (BUCHAR (b1)))
+ b1 = tolower (BUCHAR (b1));
+ if (isupper (BUCHAR (b2)))
+ b2 = tolower (BUCHAR (b2));
+ if (b1 != b2)
+ return b1 - b2;
+ }
+ --c;
+ if (c == 0)
+ return 0;
+ }
+ if (*z2 == '\0')
+ return 0;
+ else
+ return -1;
+}
diff --git a/gnu/libexec/uucp/libuucp/strrch.c b/gnu/libexec/uucp/libuucp/strrch.c
new file mode 100644
index 00000000000..a88e4b4358b
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/strrch.c
@@ -0,0 +1,24 @@
+/* strrch.c
+ Look for the last occurrence of a character in a string. This is
+ supposed to work for a null byte, although we never actually call
+ it with one. */
+
+#include "uucp.h"
+
+char *
+strrchr (z, b)
+ const char *z;
+ int b;
+{
+ char *zret;
+
+ b = (char) b;
+ zret = NULL;
+ do
+ {
+ if (*z == b)
+ zret = (char *) z;
+ }
+ while (*z++ != '\0');
+ return zret;
+}
diff --git a/gnu/libexec/uucp/libuucp/strstr.c b/gnu/libexec/uucp/libuucp/strstr.c
new file mode 100644
index 00000000000..111460b11d3
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/strstr.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.
+
+This file was modified slightly by Ian Lance Taylor, May 1992, for
+Taylor UUCP. */
+
+#include "uucp.h"
+
+/* Return the first ocurrence of NEEDLE in HAYSTACK. */
+char *
+strstr (haystack, needle)
+ const char *const haystack;
+ const char *const needle;
+{
+ register const char *const needle_end = strchr(needle, '\0');
+ register const char *const haystack_end = strchr(haystack, '\0');
+ register const size_t needle_len = needle_end - needle;
+ register const size_t needle_last = needle_len - 1;
+ register const char *begin;
+
+ if (needle_len == 0)
+ return (char *) haystack_end;
+ if ((size_t) (haystack_end - haystack) < needle_len)
+ return NULL;
+
+ for (begin = &haystack[needle_last]; begin < haystack_end; ++begin)
+ {
+ register const char *n = &needle[needle_last];
+ register const char *h = begin;
+ do
+ if (*h != *n)
+ goto loop;
+ while (--n >= needle && --h >= haystack);
+
+ return (char *) h;
+ loop:;
+ }
+
+ return NULL;
+}
diff --git a/gnu/libexec/uucp/libuucp/strtol.c b/gnu/libexec/uucp/libuucp/strtol.c
new file mode 100644
index 00000000000..f663994bf9f
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/strtol.c
@@ -0,0 +1,175 @@
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.
+
+This file was modified slightly by Ian Lance Taylor, May 1992, for
+Taylor UUCP. */
+
+#include "uucp.h"
+
+#include <ctype.h>
+#include <errno.h>
+
+#if HAVE_LIMITS_H
+#include <limits.h>
+#else
+#define ULONG_MAX 4294967295
+#define LONG_MIN (- LONG_MAX - 1)
+#define LONG_MAX 2147483647
+#endif
+
+#ifndef UNSIGNED
+#define UNSIGNED 0
+#endif
+
+/* Convert NPTR to an `unsigned long int' or `long int' in base BASE.
+ If BASE is 0 the base is determined by the presence of a leading
+ zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal.
+ If BASE is < 2 or > 36, it is reset to 10.
+ If ENDPTR is not NULL, a pointer to the character after the last
+ one converted is stored in *ENDPTR. */
+#if UNSIGNED
+unsigned long int
+#define strtol strtoul
+#else
+long int
+#endif
+strtol (nptr, endptr, base)
+ const char *nptr;
+ char **endptr;
+ int base;
+{
+ int negative;
+ register unsigned long int cutoff;
+ register unsigned int cutlim;
+ register unsigned long int i;
+ register const char *s;
+ register unsigned int c;
+ const char *save;
+ int overflow;
+
+ if (base < 0 || base == 1 || base > 36)
+ base = 10;
+
+ s = nptr;
+
+ /* Skip white space. */
+ while (isspace(BUCHAR (*s)))
+ ++s;
+ if (*s == '\0')
+ goto noconv;
+
+ /* Check for a sign. */
+ if (*s == '-')
+ {
+ negative = 1;
+ ++s;
+ }
+ else if (*s == '+')
+ {
+ negative = 0;
+ ++s;
+ }
+ else
+ negative = 0;
+
+ if (base == 16
+ && s[0] == '0'
+ && (s[1] == 'x' || s[1] == 'X'))
+ s += 2;
+
+ /* If BASE is zero, figure it out ourselves. */
+ if (base == 0)
+ if (*s == '0')
+ {
+ if (s[1] == 'x' || s[1] == 'X')
+ {
+ s += 2;
+ base = 16;
+ }
+ else
+ base = 8;
+ }
+ else
+ base = 10;
+
+ /* Save the pointer so we can check later if anything happened. */
+ save = s;
+
+ cutoff = ULONG_MAX / (unsigned long int) base;
+ cutlim = ULONG_MAX % (unsigned long int) base;
+
+ overflow = 0;
+ i = 0;
+ for (c = BUCHAR (*s); c != '\0'; c = BUCHAR (*++s))
+ {
+ if (isdigit(c))
+ c -= '0';
+ else if (islower(c))
+ c = c - 'a' + 10;
+ else if (isupper(c))
+ c = c - 'A' + 10;
+ else
+ break;
+ if (c >= base)
+ break;
+ /* Check for overflow. */
+ if (i > cutoff || (i == cutoff && c > cutlim))
+ overflow = 1;
+ else
+ {
+ i *= (unsigned long int) base;
+ i += c;
+ }
+ }
+
+ /* Check if anything actually happened. */
+ if (s == save)
+ goto noconv;
+
+ /* Store in ENDPTR the address of one character
+ past the last character we converted. */
+ if (endptr != NULL)
+ *endptr = (char *) s;
+
+#if !UNSIGNED
+ /* Check for a value that is within the range of
+ `unsigned long int', but outside the range of `long int'. */
+ if (i > (negative ?
+ - (unsigned long int) LONG_MIN : (unsigned long int) LONG_MAX))
+ overflow = 1;
+#endif
+
+ if (overflow)
+ {
+ errno = ERANGE;
+#if UNSIGNED
+ return ULONG_MAX;
+#else
+ return negative ? LONG_MIN : LONG_MAX;
+#endif
+ }
+
+ /* Return the result of the appropriate sign. */
+ return (negative ? - i : i);
+
+ noconv:
+ /* There was no number to convert. */
+ if (endptr != NULL)
+ *endptr = (char *) nptr;
+ return 0L;
+}
diff --git a/gnu/libexec/uucp/libuucp/xfree.c b/gnu/libexec/uucp/libuucp/xfree.c
new file mode 100644
index 00000000000..239b015db21
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/xfree.c
@@ -0,0 +1,15 @@
+/* xfree.c
+ Some versions of free (like the one in SCO Unix 3.2.2) don't handle
+ null pointers correctly, so we go through our own routine. */
+
+#include "uucp.h"
+
+#include "uudefs.h"
+
+void
+xfree (p)
+ pointer p;
+{
+ if (p != NULL)
+ free (p);
+}
diff --git a/gnu/libexec/uucp/libuucp/xmall.c b/gnu/libexec/uucp/libuucp/xmall.c
new file mode 100644
index 00000000000..4aac23748c8
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/xmall.c
@@ -0,0 +1,18 @@
+/* xmalloc.c
+ Allocate a block of memory without fail. */
+
+#include "uucp.h"
+
+#include "uudefs.h"
+
+pointer
+xmalloc (c)
+ size_t c;
+{
+ pointer pret;
+
+ pret = malloc (c);
+ if (pret == NULL && c != 0)
+ ulog (LOG_FATAL, "Out of memory");
+ return pret;
+}
diff --git a/gnu/libexec/uucp/libuucp/xreall.c b/gnu/libexec/uucp/libuucp/xreall.c
new file mode 100644
index 00000000000..36ae313a508
--- /dev/null
+++ b/gnu/libexec/uucp/libuucp/xreall.c
@@ -0,0 +1,23 @@
+/* xreall.c
+ Realloc a block of memory without fail. Supposedly some versions of
+ realloc can't handle a NULL first argument, so we check for that
+ here. */
+
+#include "uucp.h"
+
+#include "uudefs.h"
+
+pointer
+xrealloc (p, c)
+ pointer p;
+ size_t c;
+{
+ pointer pret;
+
+ if (p == NULL)
+ return xmalloc (c);
+ pret = realloc (p, c);
+ if (pret == NULL && c != 0)
+ ulog (LOG_FATAL, "Out of memory");
+ return pret;
+}
diff --git a/gnu/libexec/uucp/sample/call b/gnu/libexec/uucp/sample/call
new file mode 100644
index 00000000000..de4190ce612
--- /dev/null
+++ b/gnu/libexec/uucp/sample/call
@@ -0,0 +1,20 @@
+# This is an example of call, the call out password file for Taylor
+# UUCP. To use it, you must compile the package with
+# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy
+# this file to newconfigdir as set in Makefile.in (the default is
+# /usr/local/conf/uucp), and edit it as appropriate for your system.
+
+# Everything after a '#' character is a comment. To uncomment any of
+# the sample lines below, just delete the '#'.
+
+# This file is used when the ``call-login'' or ``call-password''
+# commands are used in the sys file with a "*" argument (e.g.,
+# ``call-login *''). The system name is looked up in this file, and
+# the login name and password are used.
+
+# The point of this is that the sys file may then be publically
+# readable, while still concealing the login names and passwords used
+# to connect to the remote system.
+
+# The format is just system-name login-name password.
+uunet Uairs foobar
diff --git a/gnu/libexec/uucp/sample/config b/gnu/libexec/uucp/sample/config
new file mode 100644
index 00000000000..e7d683bb036
--- /dev/null
+++ b/gnu/libexec/uucp/sample/config
@@ -0,0 +1,88 @@
+# This is an example of config, the main configuration file for Taylor
+# UUCP. To use it, you must compile the package with
+# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy
+# this file to newconfigdir as set in Makefile.in (the default is
+# /usr/local/conf/uucp), and edit it as appropriate for your system.
+
+# You need not use this file at all; all the important commands have
+# defaults which will be used if this file can not be found.
+
+# Everything after a '#' character is a comment. To uncomment any of
+# the sample lines below, just delete the '#'.
+
+# You must choose a UUCP name. If your system is going to be
+# communicating with other systems outside your organization, the name
+# must be unique in the entire world. The usual method is to pick a
+# name, and then search the UUCP maps (in the newsgroup
+# comp.mail.maps) to see whether it has already been taken. See the
+# README posting in comp.mail.maps for more information. If the name
+# of your system as returned by "uuname -n" or "hostname" is the name
+# you want to use, you do not need to set the name in this file.
+# Otherwise uncomment and edit the following line.
+# nodename uucp # The UUCP name of this system
+
+# The default spool directory is set in policy.h (the default is
+# /usr/spool/uucp). All UUCP jobs and status information are kept in
+# the spool directory. If you wish to change it, use the spool
+# command.
+# spool /usr/spool/uucp # The UUCP spool directory
+
+# The default public directory is set in policy.h (the default is
+# /usr/spool/uucppublic). Remote systems may refer to a file in this
+# directory using "~/FILE". By default, the public directory is the
+# only directory which remote systems may transfer files in and out
+# of. If you wish to change the public directory, use the pubdir
+# command.
+# pubdir /usr/spool/uucppublic # The UUCP public directory
+
+# The names of the UUCP log files are set in policy.h. The default
+# names depend on the logging option you have chosen. If
+# HAVE_TAYLOR_LOGGING is set in policy.h, the default log file name is
+# /usr/spool/uucp/Log, the default statistics file name is
+# /usr/spool/uucp/Stats, and the default debugging file name is
+# /usr/spool/uucp/Debug. These file names may be set by the following
+# commands.
+# logfile /usr/spool/uucp/Log # The UUCP log file
+# statfile /usr/spool/uucp/Stats # The UUCP statistics file
+# debugfile /usr/spool/uucp/Debug # The UUCP debugging file
+
+# uuxqt is the program which executes UUCP requests from other
+# systems. Normally one is started after each run of uucico, the
+# communications daemon. You may control the maximum number of uuxqt
+# programs run at the same time with the following command. The
+# default is to have no maximum.
+# max-uuxqts 1 # The maximum number of uuxqts
+
+# There are several files that uucico uses. By default it looks for
+# them in newconfigdir, as set in Makefile.in. You may name one or
+# more of each type of file using the following commands.
+# sysfile FILES # Default "sys"
+# portfile FILES # Default "port"
+# dialfile FILES # Default "dial"
+# dialcodefile FILES # Default "dialcode"
+# callfile FILES # Default "call"
+# passwdfile FILES # Default "passwd"
+
+# The ``timetable'' command may be used to declare timetables. These
+# may then be referred to in time strings in the other files.
+# timetable Day Wk0905-1655
+
+# The ``unknown'' command is followed by any command which may appear
+# in a sys file. These commands are taken together to describe what
+# is permitted to a system which is not listed in any sys file. If
+# the ``unknown'' command, then unknown systems are not permitted to
+# connect.
+
+# Here is an example which permits unknown systems to download files
+# from /usr/spool/anonymous, and to upload them to
+# /usr/spool/anonymous/upload.
+#
+# No commands may be executed (the list of permitted commands is empty)
+# unknown commands
+# The public directory is /usr/spool/anonymous
+# unknown pubdir /usr/spool/anonymous
+# Only files in the public directory may be sent; users may not download
+# files from the upload directory
+# unknown remote-send ~ !~/upload
+# May only upload files into /usr/spool/anonymous/upload
+# unknown remote-receive ~/upload
diff --git a/gnu/libexec/uucp/sample/dial b/gnu/libexec/uucp/sample/dial
new file mode 100644
index 00000000000..f0d4bdd8aa5
--- /dev/null
+++ b/gnu/libexec/uucp/sample/dial
@@ -0,0 +1,35 @@
+# This is an example of dial, the dialer configuration file for Taylor
+# UUCP. To use it, you must compile the package with
+# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy
+# this file to newconfigdir as set in Makefile.in (the default is
+# /usr/local/conf/uucp), and edit it as appropriate for your system.
+
+# Everything after a '#' character is a comment. To uncomment any of
+# the sample lines below, just delete the '#'.
+
+# All dialers named in the port (or sys) file must be described in the
+# dial file. It is also possible to describe a dialer directly in the
+# port (or sys) file.
+
+# This is a typical Hayes modem definition.
+dialer hayes
+
+# The chat script used to dial the phone.
+# This means:
+# 1) expect nothing (i.e., continue with step 2)
+# 2) send "ATZ", then a carriage return, then sleep for 1 to 2
+# seconds. The \c means to not send a final carriage return.
+# 3) wait until the modem echoes "OK"
+# 4) send "ATDT", then the telephone number (after translating any
+# dialcodes).
+# 5) wait until the modem echoes "CONNECT"
+chat "" ATZ\r\d\c OK ATDT\T CONNECT
+
+# If we get "BUSY" or "NO CARRIER" during the dial chat script we
+# abort the dial immediately.
+chat-fail BUSY
+chat-fail NO\sCARRIER
+
+# When the call is over, we make sure we hangup the modem.
+complete \d\d+++\d\dATH\r\c
+abort \d\d+++\d\dATH\r\c
diff --git a/gnu/libexec/uucp/sample/dialcode b/gnu/libexec/uucp/sample/dialcode
new file mode 100644
index 00000000000..710a07bf734
--- /dev/null
+++ b/gnu/libexec/uucp/sample/dialcode
@@ -0,0 +1,19 @@
+# This is an example of dialcode, the dialcode configuration file for
+# Taylor UUCP. To use it, you must compile the package with
+# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy
+# this file to newconfigdir as set in Makefile.in (the default is
+# /usr/local/conf/uucp), and edit it as appropriate for your system.
+
+# Everything after a '#' character is a comment. To uncomment any of
+# the sample lines below, just delete the '#'.
+
+# The dialcode file is used if \T is used in the dialer chat script
+# and the telephone number begins with alphabetic characters. The
+# alphabetic characters are looked up and translated in dialcode.
+
+# Here are a couple of sample dialcodes.
+MA 617
+CA 415
+
+# For example, if the phone number (from the sys file) is MA7389449,
+# then the string sent to the modem will be 6177389449.
diff --git a/gnu/libexec/uucp/sample/passwd b/gnu/libexec/uucp/sample/passwd
new file mode 100644
index 00000000000..2b04e13a343
--- /dev/null
+++ b/gnu/libexec/uucp/sample/passwd
@@ -0,0 +1,18 @@
+# This is an example of passwd, the call in password file for Taylor
+# UUCP. To use it, you must compile the package with
+# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy
+# this file to newconfigdir as set in Makefile.in (the default is
+# /usr/local/conf/uucp), and edit it as appropriate for your system.
+
+# Everything after a '#' character is a comment. To uncomment any of
+# the sample lines below, just delete the '#'.
+
+# This file is used when uucico is invoked with the -l or -e argument.
+# uucico will then prompt for a login name and password. The login
+# name is looked up in this file to check the password (the system
+# password file, /etc/passwd, is not checked). This permits uucico to
+# completely take over a port, allowing UUCP access to remote systems
+# but not permitting remote users to actually log in to the system.
+
+# The format is just login-name password.
+Uairs foobar
diff --git a/gnu/libexec/uucp/sample/port b/gnu/libexec/uucp/sample/port
new file mode 100644
index 00000000000..8e481869b56
--- /dev/null
+++ b/gnu/libexec/uucp/sample/port
@@ -0,0 +1,41 @@
+# This is an example of port, the port configuration file for Taylor
+# UUCP. To use it, you must compile the package with
+# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy
+# this file to newconfigdir as set in Makefile.in (the default is
+# /usr/local/conf/uucp), and edit it as appropriate for your system.
+
+# Everything after a '#' character is a comment. To uncomment any of
+# the sample lines below, just delete the '#'.
+
+# All ports named in the sys file must be described in a port file.
+# It is also possible to describe the port directly in the sys file.
+
+# Commands that appears before the first ``port'' command are defaults
+# for all ports that appear later in the file. In this case all ports
+# will default to being modems (other possible types are direct, tcp
+# and tli).
+type modem
+
+# Now we describe two ports.
+
+# This is the name of the port. This name may be used in the sys file
+# to select the port, or the sys file may just specify a baud rate in
+# which case the first matching unlocked port will be used.
+port port1
+
+# This is the device name to open to dial out.
+device /dev/ttyd0
+
+# This is the dialer to use, as described in the dialer file.
+dialer hayes
+
+# This is the baud rate to dial out at.
+speed 2400
+
+# Here is a second port. This is like the first, except that it uses
+# a different device. It also permits a range of speeds, which is
+# mainly useful if the system specifies a particular baud rate.
+port port2
+device /dev/ttyd1
+dialer hayes
+speed-range 2400 9600
diff --git a/gnu/libexec/uucp/sample/sys1 b/gnu/libexec/uucp/sample/sys1
new file mode 100644
index 00000000000..fa9e7709e1c
--- /dev/null
+++ b/gnu/libexec/uucp/sample/sys1
@@ -0,0 +1,44 @@
+# This is an example of a sys file, the file(s) which describe remote
+# systems for Taylor UUCP. To use it, you must compile the package
+# with HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default),
+# copy this file to newconfigdir as set in Makefile.in (the default is
+# /usr/local/conf/uucp), and edit it as appropriate for your system.
+
+# If you do not use the ``unknown'' command in the config file, then
+# each system that you communicate with must be listed in a sys file.
+
+# Everything after a '#' character is a comment. To uncomment any of
+# the sample lines below, just delete the '#'.
+
+# This is a sample sys file that might be used in a leaf system. A
+# leaf system is one that only contacts one other system. sys2
+# provides another example.
+
+# The name of the remote system that we call.
+system uunet
+
+# The login name and password are kept in the callout password file
+# (by default this is the file "call" in newconfigdir).
+call-login *
+call-password *
+
+# We can send anything at any time.
+time any
+
+# During the day we only accept grade 'Z' or above; at other times
+# (not mentioned here) we accept all grades. uunet queues up news
+# at grade 'd', which is lower than 'Z'.
+call-timegrade Z Wk0755-2305,Su1655-2305
+
+# The phone number to call.
+phone 7389449
+
+# uunet tends to be slow, so we increase the timeout
+chat-timeout 120
+
+# The port we use to dial out.
+port serial
+
+# Increase the timeout and the number of retries.
+protocol-parameter g timeout 20
+protocol-parameter g retries 10
diff --git a/gnu/libexec/uucp/sample/sys2 b/gnu/libexec/uucp/sample/sys2
new file mode 100644
index 00000000000..856529a500a
--- /dev/null
+++ b/gnu/libexec/uucp/sample/sys2
@@ -0,0 +1,51 @@
+# This is an example of a sys file, the file(s) which describe remote
+# systems for Taylor UUCP. To use it, you must compile the package
+# with HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default),
+# copy this file to newconfigdir as set in Makefile.in (the default is
+# /usr/local/conf/uucp), and edit it as appropriate for your system.
+
+# If you do not use the ``unknown'' command in the config file, then
+# each system that you communicate with must be listed in a sys file.
+
+# Everything after a '#' character is a comment. To uncomment any of
+# the sample lines below, just delete the '#'.
+
+# This is a sample sys file that might be used by a system that
+# contacts a couple of other systems, both of which are treated the
+# same. sys1 provides another example.
+
+# Commands that appear before the first ``system'' commands are
+# defaults for all systems listed in the file.
+
+# Get the login name and password to use from the call-out file. By
+# default this is the file "call" in newconfigdir.
+call-login *
+call-password *
+
+# The systems must use a particular login
+called-login Ulocal
+
+# Permit local users to send any world readable file
+local-send /
+
+# Permit local uses to request into any world writable directory
+local-receive /
+
+# Call at any time
+time any
+
+# Use port1, then port2
+port port1
+
+alternate
+
+port port2
+
+# Now define the systems themselves. Because of all the defaults we
+# used, there is very little to specify for the systems themselves.
+
+system comton
+phone 5551212
+
+system bugs
+phone 5552424
diff --git a/gnu/libexec/uucp/uuchk/Makefile b/gnu/libexec/uucp/uuchk/Makefile
new file mode 100644
index 00000000000..0582f9ff1b6
--- /dev/null
+++ b/gnu/libexec/uucp/uuchk/Makefile
@@ -0,0 +1,15 @@
+# Makefile for uuchk
+
+BINDIR= $(sbindir)
+BINOWN= $(owner)
+
+PROG= uuchk
+SRCS= uuchk.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -DVERSION=\"$(VERSION)\"
+
+NOMAN= noman
+
+.include <bsd.prog.mk>
diff --git a/gnu/libexec/uucp/uuchk/uuchk.c b/gnu/libexec/uucp/uuchk/uuchk.c
new file mode 100644
index 00000000000..41021defb80
--- /dev/null
+++ b/gnu/libexec/uucp/uuchk/uuchk.c
@@ -0,0 +1,856 @@
+/* uuchk.c
+ Display what we think the permissions of systems are.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char uuchk_rcsid[] = "$Id: uuchk.c,v 1.1 1993/08/04 19:36:14 jtc Exp $";
+#endif
+
+#include "getopt.h"
+
+#include "uuconf.h"
+
+/* Local functions. */
+
+static void ukusage P((void));
+static void ukshow P((const struct uuconf_system *qsys,
+ pointer puuconf));
+static int ikshow_port P((struct uuconf_port *qport, pointer pinfo));
+static void ukshow_dialer P((struct uuconf_dialer *qdial));
+static void ukshow_chat P((const struct uuconf_chat *qchat,
+ const char *zhdr));
+static void ukshow_size P((struct uuconf_timespan *q, boolean fcall,
+ boolean flocal));
+static void ukshow_proto_params P((struct uuconf_proto_param *pas,
+ int cindent));
+static void ukshow_time P((const struct uuconf_timespan *));
+static struct uuconf_timespan *qcompress_span P((struct uuconf_timespan *));
+static void ukuuconf_error P((pointer puuconf, int iret));
+
+/* Structure used to pass uuconf pointer into ikshow_port and also let
+ it record whether any ports were found. */
+struct sinfo
+{
+ /* The uuconf global pointer. */
+ pointer puuconf;
+ /* The system. */
+ const struct uuconf_system *qsys;
+ /* Whether any ports were seen. */
+ boolean fgot;
+};
+
+/* Long getopt options. */
+static const struct option asKlongopts[] = { { NULL, 0, NULL, 0 } };
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int iopt;
+ /* The configuration file name. */
+ const char *zconfig = NULL;
+ int iret;
+ pointer puuconf;
+ char **pzsystems;
+
+ while ((iopt = getopt_long (argc, argv, "I:x:", asKlongopts,
+ (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 'I':
+ /* Set the configuration file name. */
+ zconfig = optarg;
+ break;
+
+ case 'x':
+ /* Set the debugging level. There is actually no debugging
+ information for this program. */
+ break;
+
+ case 0:
+ /* Long option found and flag set. */
+ break;
+
+ default:
+ ukusage ();
+ break;
+ }
+ }
+
+ if (optind != argc)
+ ukusage ();
+
+ iret = uuconf_init (&puuconf, (const char *) NULL, zconfig);
+ if (iret != UUCONF_SUCCESS)
+ ukuuconf_error (puuconf, iret);
+
+ iret = uuconf_system_names (puuconf, &pzsystems, FALSE);
+ if (iret != UUCONF_SUCCESS)
+ ukuuconf_error (puuconf, iret);
+
+ while (*pzsystems != NULL)
+ {
+ struct uuconf_system ssys;
+
+ iret = uuconf_system_info (puuconf, *pzsystems, &ssys);
+ if (iret != UUCONF_SUCCESS)
+ ukuuconf_error (puuconf, iret);
+ else
+ ukshow (&ssys, puuconf);
+ (void) uuconf_system_free (puuconf, &ssys);
+ ++pzsystems;
+ if (*pzsystems != NULL)
+ printf ("\n");
+ }
+
+ exit (EXIT_SUCCESS);
+
+ /* Avoid errors about not returning a value. */
+ return 0;
+}
+
+/* Print a usage message and die. */
+
+static void
+ukusage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uuchk [-I file]\n");
+ fprintf (stderr,
+ " -I file: Set configuration file to use\n");
+ exit (EXIT_FAILURE);
+}
+
+/* Dump out the information for a system. */
+
+static void
+ukshow (qsys, puuconf)
+ const struct uuconf_system *qsys;
+ pointer puuconf;
+{
+ char **pz;
+ int i;
+ int iret;
+
+ printf ("System: %s", qsys->uuconf_zname);
+ if (qsys->uuconf_pzalias != NULL)
+ {
+ printf (" (");
+ for (pz = qsys->uuconf_pzalias; *pz != NULL; pz++)
+ {
+ printf ("%s", *pz);
+ if (pz[1] != NULL)
+ printf (" ");
+ }
+ printf (")");
+ }
+ printf ("\n");
+
+ for (i = 0; qsys != NULL; qsys = qsys->uuconf_qalternate, i++)
+ {
+ boolean fcall, fcalled;
+ struct uuconf_timespan *qtime, *qspan;
+
+ if (i != 0 || qsys->uuconf_qalternate != NULL)
+ {
+ printf ("Alternate %d", i);
+ if (qsys->uuconf_zalternate != NULL)
+ printf (" (%s)", qsys->uuconf_zalternate);
+ printf ("\n");
+ }
+
+ /* See if this alternate could be used when calling out. */
+ fcall = qsys->uuconf_fcall;
+ if (qsys->uuconf_qtimegrade == NULL)
+ fcall = FALSE;
+
+ /* See if this alternate could be used when calling in. */
+ fcalled = qsys->uuconf_fcalled;
+
+ if (! fcall && ! fcalled)
+ {
+ printf (" This alternate is never used\n");
+ continue;
+ }
+
+ if (fcalled)
+ {
+ if (qsys->uuconf_zcalled_login != NULL
+ && strcmp (qsys->uuconf_zcalled_login, "ANY") != 0)
+ {
+ if (i == 0 && qsys->uuconf_qalternate == NULL)
+ printf (" Caller must log in as %s\n",
+ qsys->uuconf_zcalled_login);
+ else
+ printf (" When called using login name %s\n",
+ qsys->uuconf_zcalled_login);
+ }
+ else
+ printf (" When called using any login name\n");
+
+ if (qsys->uuconf_zlocalname != NULL)
+ printf (" Will use %s as name of local system\n",
+ qsys->uuconf_zlocalname);
+ }
+
+ if (fcalled && qsys->uuconf_fcallback)
+ {
+ printf (" If called, will call back\n");
+ fcalled = FALSE;
+ }
+
+ if (fcall)
+ {
+ struct sinfo si;
+
+ if (i == 0 && qsys->uuconf_qalternate == NULL)
+ printf (" Call out");
+ else
+ printf (" This alternate applies when calling");
+
+ if (qsys->uuconf_zport != NULL || qsys->uuconf_qport != NULL)
+ {
+ printf (" using ");
+ if (qsys->uuconf_zport != NULL)
+ printf ("port %s", qsys->uuconf_zport);
+ else
+ printf ("a specially defined port");
+ if (qsys->uuconf_ibaud != 0)
+ {
+ printf (" at speed %ld", qsys->uuconf_ibaud);
+ if (qsys->uuconf_ihighbaud != 0)
+ printf (" to %ld", qsys->uuconf_ihighbaud);
+ }
+ printf ("\n");
+ }
+ else if (qsys->uuconf_ibaud != 0)
+ {
+ printf (" at speed %ld", qsys->uuconf_ibaud);
+ if (qsys->uuconf_ihighbaud != 0)
+ printf (" to %ld", qsys->uuconf_ihighbaud);
+ printf ("\n");
+ }
+ else
+ printf (" using any port\n");
+
+ si.puuconf = puuconf;
+ si.qsys = qsys;
+ si.fgot = FALSE;
+
+ if (qsys->uuconf_qport != NULL)
+ {
+ printf (" The port is defined as:\n");
+ (void) ikshow_port (qsys->uuconf_qport, (pointer) &si);
+ }
+ else
+ {
+ struct uuconf_port sdummy;
+
+ printf (" The possible ports are:\n");
+ iret = uuconf_find_port (puuconf, qsys->uuconf_zport,
+ qsys->uuconf_ibaud,
+ qsys->uuconf_ihighbaud,
+ ikshow_port, (pointer) &si,
+ &sdummy);
+ if (iret != UUCONF_NOT_FOUND)
+ ukuuconf_error (puuconf, iret);
+ if (! si.fgot)
+ printf (" *** There are no matching ports\n");
+ }
+
+ if (qsys->uuconf_zphone != NULL)
+ {
+ if ((qsys->uuconf_zport != NULL
+ && strcmp (qsys->uuconf_zport, "TCP") == 0)
+ || (qsys->uuconf_qport != NULL
+ && (qsys->uuconf_qport->uuconf_ttype
+ == UUCONF_PORTTYPE_TCP
+ || qsys->uuconf_qport->uuconf_ttype
+ == UUCONF_PORTTYPE_TLI)))
+ printf (" Remote address %s\n", qsys->uuconf_zphone);
+ else
+ printf (" Phone number %s\n", qsys->uuconf_zphone);
+ }
+
+ ukshow_chat (&qsys->uuconf_schat, " Chat");
+
+ if (qsys->uuconf_zcall_login != NULL
+ || qsys->uuconf_zcall_password != NULL)
+ {
+ char *zlogin, *zpass;
+
+ iret = uuconf_callout (puuconf, qsys, &zlogin, &zpass);
+ if (iret == UUCONF_NOT_FOUND)
+ printf (" Can not determine login name or password\n");
+ else if (iret != UUCONF_SUCCESS)
+ ukuuconf_error (puuconf, iret);
+ else
+ {
+ if (zlogin != NULL)
+ {
+ printf (" Login name %s\n", zlogin);
+ free ((pointer) zlogin);
+ }
+ if (zpass != NULL)
+ {
+ printf (" Password %s\n", zpass);
+ free ((pointer) zpass);
+ }
+ }
+ }
+
+ qtime = qcompress_span (qsys->uuconf_qtimegrade);
+
+ for (qspan = qtime; qspan != NULL; qspan = qspan->uuconf_qnext)
+ {
+ printf (" ");
+ ukshow_time (qspan);
+ printf (" may call if ");
+ if ((char) qspan->uuconf_ival == UUCONF_GRADE_LOW)
+ printf ("any work");
+ else
+ printf ("work grade %c or higher", (char) qspan->uuconf_ival);
+ if (qspan->uuconf_cretry != 0)
+ printf (" (retry %d)", qspan->uuconf_cretry);
+ printf ("\n");
+ }
+
+ if (qsys->uuconf_qcalltimegrade != NULL)
+ {
+ boolean fprint, fother;
+
+ qtime = qcompress_span (qsys->uuconf_qcalltimegrade);
+ fprint = FALSE;
+ fother = FALSE;
+ if (qtime->uuconf_istart != 0)
+ fother = TRUE;
+ for (qspan = qtime; qspan != NULL; qspan = qspan->uuconf_qnext)
+ {
+ if ((char) qspan->uuconf_ival == UUCONF_GRADE_LOW)
+ {
+ fother = TRUE;
+ continue;
+ }
+ fprint = TRUE;
+ printf (" ");
+ ukshow_time (qspan);
+ printf (" may accept work grade %c or higher\n",
+ (char) qspan->uuconf_ival);
+ if (qspan->uuconf_qnext == NULL)
+ {
+ if (qspan->uuconf_iend != 7 * 24 * 60)
+ fother = TRUE;
+ }
+ else
+ {
+ if (qspan->uuconf_iend
+ != qspan->uuconf_qnext->uuconf_istart)
+ fother = TRUE;
+ }
+ }
+ if (fprint && fother)
+ printf (" (At other times may accept any work)\n");
+ }
+ }
+
+ if (qsys->uuconf_fsequence)
+ printf (" Sequence numbers are used\n");
+
+ if (fcalled)
+ ukshow_chat (&qsys->uuconf_scalled_chat, " When called, chat");
+
+ if (qsys->uuconf_zdebug != NULL)
+ printf (" Debugging level %s\n", qsys->uuconf_zdebug);
+ if (qsys->uuconf_zmax_remote_debug != NULL)
+ printf (" Max remote debugging level %s\n",
+ qsys->uuconf_zmax_remote_debug);
+
+ if (fcall)
+ {
+ ukshow_size (qsys->uuconf_qcall_local_size, TRUE, TRUE);
+ ukshow_size (qsys->uuconf_qcall_remote_size, TRUE, FALSE);
+ }
+ if (fcalled)
+ {
+ ukshow_size (qsys->uuconf_qcalled_local_size, FALSE, TRUE);
+ ukshow_size (qsys->uuconf_qcalled_remote_size, FALSE, TRUE);
+ }
+
+ if (fcall)
+ printf (" May %smake local requests when calling\n",
+ qsys->uuconf_fcall_transfer ? "" : "not ");
+
+ if (fcalled)
+ printf (" May %smake local requests when called\n",
+ qsys->uuconf_fcalled_transfer ? "" : "not ");
+
+ if (qsys->uuconf_fcall_transfer || qsys->uuconf_fcalled_transfer)
+ {
+ printf (" May send by local request:");
+ for (pz = qsys->uuconf_pzlocal_send; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+ if (! qsys->uuconf_fsend_request)
+ printf (" May not send files by remote request\n");
+ else
+ {
+ printf (" May send by remote request:");
+ for (pz = qsys->uuconf_pzremote_send; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+ if (qsys->uuconf_fcall_transfer || qsys->uuconf_fcalled_transfer)
+ {
+ printf (" May accept by local request:");
+ for (pz = qsys->uuconf_pzlocal_receive; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+ if (! qsys->uuconf_frec_request)
+ printf (" May not receive files by remote request\n");
+ else
+ {
+ printf (" May receive by remote request:");
+ for (pz = qsys->uuconf_pzremote_receive; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+
+ printf (" May execute");
+ for (pz = qsys->uuconf_pzcmds; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+
+ printf (" Execution path");
+ for (pz = qsys->uuconf_pzpath; *pz != NULL; pz++)
+ printf (" %s" , *pz);
+ printf ("\n");
+
+ if (qsys->uuconf_cfree_space != 0)
+ printf (" Will leave %ld bytes available\n", qsys->uuconf_cfree_space);
+
+ if (qsys->uuconf_zpubdir != NULL)
+ printf (" Public directory is %s\n", qsys->uuconf_zpubdir);
+
+ if (qsys->uuconf_pzforward_from != NULL)
+ {
+ printf (" May forward from");
+ for (pz = qsys->uuconf_pzforward_from; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+
+ if (qsys->uuconf_pzforward_to != NULL)
+ {
+ printf (" May forward to");
+ for (pz = qsys->uuconf_pzforward_to; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+
+ if (qsys->uuconf_zprotocols != NULL)
+ printf (" Will use protocols %s\n", qsys->uuconf_zprotocols);
+ else
+ printf (" Will use any known protocol\n");
+
+ if (qsys->uuconf_qproto_params != NULL)
+ ukshow_proto_params (qsys->uuconf_qproto_params, 1);
+ }
+}
+
+/* Show information about a port. */
+
+/*ARGSUSED*/
+static int
+ikshow_port (qport, pinfo)
+ struct uuconf_port *qport;
+ pointer pinfo;
+{
+ struct sinfo *qi = (struct sinfo *) pinfo;
+ char **pz;
+ struct uuconf_modem_port *qmodem;
+ struct uuconf_tli_port *qtli;
+
+ qi->fgot = TRUE;
+
+ printf (" Port name %s\n", qport->uuconf_zname);
+ switch (qport->uuconf_ttype)
+ {
+ case UUCONF_PORTTYPE_STDIN:
+ printf (" Port type stdin\n");
+ break;
+ case UUCONF_PORTTYPE_DIRECT:
+ printf (" Port type direct\n");
+ if (qport->uuconf_u.uuconf_sdirect.uuconf_zdevice != NULL)
+ printf (" Device %s\n",
+ qport->uuconf_u.uuconf_sdirect.uuconf_zdevice);
+ printf (" Speed %ld\n", qport->uuconf_u.uuconf_sdirect.uuconf_ibaud);
+ break;
+ case UUCONF_PORTTYPE_MODEM:
+ qmodem = &qport->uuconf_u.uuconf_smodem;
+ printf (" Port type modem\n");
+ if (qmodem->uuconf_zdevice != NULL)
+ printf (" Device %s\n", qmodem->uuconf_zdevice);
+ if (qmodem->uuconf_zdial_device != NULL)
+ printf (" Dial device %s\n", qmodem->uuconf_zdial_device);
+ printf (" Speed %ld\n", qmodem->uuconf_ibaud);
+ if (qmodem->uuconf_ilowbaud != qmodem->uuconf_ihighbaud)
+ printf (" Speed range %ld to %ld\n", qmodem->uuconf_ilowbaud,
+ qmodem->uuconf_ihighbaud);
+ printf (" Carrier %savailable\n",
+ qmodem->uuconf_fcarrier ? "" : "not ");
+ if (qmodem->uuconf_qdialer != NULL)
+ {
+ printf (" Specially defined dialer\n");
+ ukshow_dialer (qmodem->uuconf_qdialer);
+ }
+ else if (qmodem->uuconf_pzdialer != NULL
+ && qmodem->uuconf_pzdialer[0] != NULL)
+ {
+ struct uuconf_dialer sdial;
+ int iret;
+
+ /* This might be a single dialer name, or it might be a
+ sequence of dialer/token pairs. */
+
+ if (qmodem->uuconf_pzdialer[1] == NULL
+ || qmodem->uuconf_pzdialer[2] == NULL)
+ {
+ iret = uuconf_dialer_info (qi->puuconf,
+ qmodem->uuconf_pzdialer[0],
+ &sdial);
+ if (iret == UUCONF_NOT_FOUND)
+ printf (" *** No dialer %s\n", qmodem->uuconf_pzdialer[0]);
+ else if (iret != UUCONF_SUCCESS)
+ ukuuconf_error (qi->puuconf, iret);
+ else
+ {
+ printf (" Dialer %s\n", qmodem->uuconf_pzdialer[0]);
+ ukshow_dialer (&sdial);
+ if (qmodem->uuconf_pzdialer[1] != NULL)
+ printf (" Token %s\n", qmodem->uuconf_pzdialer[1]);
+ }
+ }
+ else
+ {
+ pz = qmodem->uuconf_pzdialer;
+ while (*pz != NULL)
+ {
+ iret = uuconf_dialer_info (qi->puuconf, *pz, &sdial);
+ if (iret == UUCONF_NOT_FOUND)
+ printf (" *** No dialer %s\n", *pz);
+ else if (iret != UUCONF_SUCCESS)
+ ukuuconf_error (qi->puuconf, iret);
+ else
+ {
+ printf (" Dialer %s\n", *pz);
+ ukshow_dialer (&sdial);
+ }
+
+ ++pz;
+ if (*pz != NULL)
+ {
+ printf (" Token %s\n", *pz);
+ ++pz;
+ }
+ }
+ }
+ }
+ else
+ printf (" *** No dialer information\n");
+ break;
+ case UUCONF_PORTTYPE_TCP:
+ printf (" Port type tcp\n");
+ printf (" TCP service %s\n",
+ qport->uuconf_u.uuconf_stcp.uuconf_zport);
+ break;
+ case UUCONF_PORTTYPE_TLI:
+ qtli = &qport->uuconf_u.uuconf_stli;
+ printf (" Port type TLI%s\n",
+ qtli->uuconf_fstream ? "S" : "");
+ if (qtli->uuconf_zdevice != NULL)
+ printf (" Device %s\n", qtli->uuconf_zdevice);
+ if (qtli->uuconf_pzpush != NULL)
+ {
+ printf (" Push");
+ for (pz = qtli->uuconf_pzpush; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+ if (qtli->uuconf_pzdialer != NULL
+ && qtli->uuconf_pzdialer[0] != NULL)
+ {
+ printf (" Dialer sequence");
+ for (pz = qtli->uuconf_pzdialer; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+ if (qtli->uuconf_zservaddr != NULL)
+ printf (" Server address %s\n", qtli->uuconf_zservaddr);
+ break;
+ default:
+ fprintf (stderr, " CAN'T HAPPEN\n");
+ break;
+ }
+
+ if (qport->uuconf_zprotocols != NULL)
+ printf (" Will use protocols %s\n", qport->uuconf_zprotocols);
+
+ if (qport->uuconf_zlockname != NULL)
+ printf (" Will use lockname %s\n", qport->uuconf_zlockname);
+
+ if (qport->uuconf_qproto_params != NULL)
+ ukshow_proto_params (qport->uuconf_qproto_params, 3);
+
+ /* Return NOT_FOUND to force find_port to continue searching. */
+ return UUCONF_NOT_FOUND;
+}
+
+/* Show information about a dialer. */
+
+static void
+ukshow_dialer (q)
+ struct uuconf_dialer *q;
+{
+ ukshow_chat (&q->uuconf_schat, " Chat");
+ printf (" Wait for dialtone %s\n", q->uuconf_zdialtone);
+ printf (" Pause while dialing %s\n", q->uuconf_zpause);
+ printf (" Carrier %savailable\n", q->uuconf_fcarrier ? "" : "not ");
+ if (q->uuconf_fcarrier)
+ printf (" Wait %d seconds for carrier\n", q->uuconf_ccarrier_wait);
+ if (q->uuconf_fdtr_toggle)
+ {
+ printf (" Toggle DTR");
+ if (q->uuconf_fdtr_toggle_wait)
+ printf (" and wait");
+ printf ("\n");
+ }
+ ukshow_chat (&q->uuconf_scomplete, " When complete chat");
+ ukshow_chat (&q->uuconf_sabort, " When aborting chat");
+ if (q->uuconf_qproto_params != NULL)
+ ukshow_proto_params (q->uuconf_qproto_params, 4);
+}
+
+/* Show a chat script. */
+
+static void
+ukshow_chat (qchat, zhdr)
+ const struct uuconf_chat *qchat;
+ const char *zhdr;
+{
+ char **pz;
+
+ if (qchat->uuconf_pzprogram != NULL)
+ {
+ printf ("%s program", zhdr);
+ for (pz = qchat->uuconf_pzprogram; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+
+ if (qchat->uuconf_pzchat != NULL)
+ {
+
+ printf ("%s script", zhdr);
+ for (pz = qchat->uuconf_pzchat; *pz != NULL; pz++)
+ {
+ if ((*pz)[0] != '-' || pz == qchat->uuconf_pzchat)
+ printf (" ");
+ printf ("%s", *pz);
+ }
+ printf ("\n");
+ printf ("%s script timeout %d\n", zhdr, qchat->uuconf_ctimeout);
+ if (qchat->uuconf_pzfail != NULL)
+ {
+ printf ("%s failure strings", zhdr);
+ for (pz = qchat->uuconf_pzfail; *pz != NULL; pz++)
+ printf (" %s", *pz);
+ printf ("\n");
+ }
+ if (qchat->uuconf_fstrip)
+ printf ("%s script incoming bytes stripped to seven bits\n", zhdr);
+ }
+}
+
+/* Show a size/time restriction. */
+
+static void
+ukshow_size (qspan, fcall, flocal)
+ struct uuconf_timespan *qspan;
+ boolean fcall;
+ boolean flocal;
+{
+ struct uuconf_timespan *q;
+ boolean fother;
+
+ qspan = qcompress_span (qspan);
+ if (qspan == NULL)
+ return;
+
+ printf (" If call%s the following applies to a %s request:\n",
+ fcall ? "ing" : "ed", flocal ? "local" : "remote");
+
+ fother = FALSE;
+ if (qspan->uuconf_istart >= 60)
+ fother = TRUE;
+
+ for (q = qspan; q != NULL; q = q->uuconf_qnext)
+ {
+ printf (" ");
+ ukshow_time (q);
+ printf (" may transfer files %ld bytes or smaller\n", q->uuconf_ival);
+ if (q->uuconf_qnext == NULL)
+ {
+ if (q->uuconf_iend <= 6 * 24 * 60 + 23 * 60)
+ fother = TRUE;
+ }
+ else
+ {
+ if (q->uuconf_iend + 60 <= q->uuconf_qnext->uuconf_istart)
+ fother = TRUE;
+ }
+ }
+
+ if (fother)
+ printf (" (At other times may send files of any size)\n");
+}
+
+/* Show protocol parameters. */
+
+static void
+ukshow_proto_params (pas, cindent)
+ struct uuconf_proto_param *pas;
+ int cindent;
+{
+ struct uuconf_proto_param *q;
+
+ for (q = pas; q->uuconf_bproto != '\0'; q++)
+ {
+ int i;
+ struct uuconf_proto_param_entry *qe;
+
+ for (i = 0; i < cindent; i++)
+ printf (" ");
+ printf ("For protocol %c will use the following parameters\n",
+ q->uuconf_bproto);
+ for (qe = q->uuconf_qentries; qe->uuconf_cargs > 0; qe++)
+ {
+ int ia;
+
+ for (i = 0; i < cindent; i++)
+ printf (" ");
+ for (ia = 0; ia < qe->uuconf_cargs; ia++)
+ printf (" %s", qe->uuconf_pzargs[ia]);
+ printf ("\n");
+ }
+ }
+}
+
+/* Display a time span. */
+
+static void
+ukshow_time (q)
+ const struct uuconf_timespan *q;
+{
+ int idaystart, idayend;
+ int ihourstart, ihourend;
+ int iminutestart, iminuteend;
+ const char * const zdays = "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat\0Sun";
+
+ if (q->uuconf_istart == 0 && q->uuconf_iend == 7 * 24 * 60)
+ {
+ printf ("At any time");
+ return;
+ }
+
+ idaystart = q->uuconf_istart / (24 * 60);
+ ihourstart = (q->uuconf_istart % (24 * 60)) / 60;
+ iminutestart = q->uuconf_istart % 60;
+ idayend = q->uuconf_iend / (24 * 60);
+ ihourend = (q->uuconf_iend % (24 * 60)) / 60;
+ iminuteend = q->uuconf_iend % 60;
+
+ if (idaystart == idayend)
+ printf ("%s from %02d:%02d to %02d:%02d", zdays + idaystart * 4,
+ ihourstart, iminutestart, ihourend, iminuteend);
+ else
+ printf ("From %s %02d:%02d to %s %02d:%02d",
+ zdays + idaystart * 4, ihourstart, iminutestart,
+ zdays + idayend * 4, ihourend, iminuteend);
+}
+
+/* Compress a time span by merging any two adjacent spans with
+ identical values. This isn't necessary for uucico, but it looks
+ nicer when printed out. */
+
+static struct uuconf_timespan *
+qcompress_span (qlist)
+ struct uuconf_timespan *qlist;
+{
+ struct uuconf_timespan **pq;
+
+ pq = &qlist;
+ while (*pq != NULL)
+ {
+ if ((*pq)->uuconf_qnext != NULL
+ && (*pq)->uuconf_iend == (*pq)->uuconf_qnext->uuconf_istart
+ && (*pq)->uuconf_ival == (*pq)->uuconf_qnext->uuconf_ival)
+ {
+ struct uuconf_timespan *qnext;
+
+ qnext = (*pq)->uuconf_qnext;
+ (*pq)->uuconf_qnext = qnext->uuconf_qnext;
+ (*pq)->uuconf_iend = qnext->uuconf_iend;
+ }
+ else
+ pq = &(*pq)->uuconf_qnext;
+ }
+
+ return qlist;
+}
+
+/* Display a uuconf error and exit. */
+
+static void
+ukuuconf_error (puuconf, iret)
+ pointer puuconf;
+ int iret;
+{
+ char ab[512];
+
+ (void) uuconf_error_string (puuconf, iret, ab, sizeof ab);
+ if ((iret & UUCONF_ERROR_FILENAME) == 0)
+ fprintf (stderr, "uuchk: %s\n", ab);
+ else
+ fprintf (stderr, "uuchk:%s\n", ab);
+ exit (EXIT_FAILURE);
+}
diff --git a/gnu/libexec/uucp/uucico/Makefile b/gnu/libexec/uucp/uucico/Makefile
new file mode 100644
index 00000000000..57b937c65ef
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/Makefile
@@ -0,0 +1,19 @@
+# Makefile for uucico
+
+BINDIR= $(sbindir)
+BINOWN= $(owner)
+BINMODE= 4555
+
+PROG= uucico
+SRCS= uucico.c trans.c send.c rec.c xcmd.c prot.c protg.c protf.c \
+ prott.c prote.c proti.c protj.c protz.c time.c chat.c \
+ conn.c copy.c log.c tcp.c tli.c util.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -DVERSION=\"$(VERSION)\"
+
+MAN8= uucico.0
+
+.include <bsd.prog.mk>
+.PATH: $(.CURDIR)/../common_sources
diff --git a/gnu/libexec/uucp/uucico/prote.c b/gnu/libexec/uucp/uucico/prote.c
new file mode 100644
index 00000000000..2d2e77e1d8e
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/prote.c
@@ -0,0 +1,387 @@
+/* prote.c
+ The 'e' protocol.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char prote_rcsid[] = "$Id: prote.c,v 1.1 1993/08/04 19:36:18 jtc Exp $";
+#endif
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "conn.h"
+#include "trans.h"
+#include "system.h"
+#include "prot.h"
+
+/* This implementation is based on my implementation of the 't'
+ protocol, which is fairly similar. The main difference between the
+ protocols seems to be that 't' breaks the file into packets and
+ transmits the size of the packet with each packet, whereas 'e'
+ sends the size of the entire file and then sends all the data in a
+ single enormous packet.
+
+ The 'e' protocol does no error checking whatsoever and thus
+ requires an end-to-end verified eight bit communication line, such
+ as is provided by TCP. Using it with a modem is inadvisable, since
+ errors can occur between the modem and the computer. */
+
+/* The buffer size we use. */
+#define CEBUFSIZE (CRECBUFLEN / 2)
+
+/* The size of the initial file size message. */
+#define CEFRAMELEN (20)
+
+/* A pointer to the buffer we will use. */
+static char *zEbuf;
+
+/* True if we are receiving a file. */
+static boolean fEfile;
+
+/* The number of bytes we have left to send or receive. */
+static long cEbytes;
+
+/* The timeout we use. */
+static int cEtimeout = 120;
+
+struct uuconf_cmdtab asEproto_params[] =
+{
+ { "timeout", UUCONF_CMDTABTYPE_INT, (pointer) &cEtimeout, NULL },
+ { NULL, 0, NULL, NULL }
+};
+
+/* Local function. */
+
+static boolean feprocess_data P((struct sdaemon *qdaemon, boolean *pfexit,
+ size_t *pcneed));
+
+/* Start the protocol. */
+
+boolean
+festart (qdaemon, pzlog)
+ struct sdaemon *qdaemon;
+ char **pzlog;
+{
+ *pzlog = NULL;
+ if (! fconn_set (qdaemon->qconn, PARITYSETTING_NONE,
+ STRIPSETTING_EIGHTBITS, XONXOFF_OFF))
+ return FALSE;
+ zEbuf = (char *) xmalloc (CEBUFSIZE);
+ fEfile = FALSE;
+ usysdep_sleep (2);
+ return TRUE;
+}
+
+/* Stop the protocol. */
+
+/*ARGSUSED*/
+boolean
+feshutdown (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ xfree ((pointer) zEbuf);
+ zEbuf = NULL;
+ cEtimeout = 120;
+ return TRUE;
+}
+
+/* Send a command string. We send everything up to and including the
+ null byte. */
+
+/*ARGSUSED*/
+boolean
+fesendcmd (qdaemon, z, ilocal, iremote)
+ struct sdaemon *qdaemon;
+ const char *z;
+ int ilocal;
+ int iremote;
+{
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO, "fesendcmd: Sending command \"%s\"", z);
+
+ return fsend_data (qdaemon->qconn, z, strlen (z) + 1, TRUE);
+}
+
+/* Get space to be filled with data. We provide a buffer which has
+ 20 bytes at the start available to hold the length. */
+
+/*ARGSUSED*/
+char *
+zegetspace (qdaemon, pclen)
+ struct sdaemon *qdaemon;
+ size_t *pclen;
+{
+ *pclen = CEBUFSIZE;
+ return zEbuf;
+}
+
+/* Send out some data. We are allowed to modify the 20 bytes
+ preceding the buffer. This allows us to send the entire block with
+ header bytes in a single call. */
+
+/*ARGSIGNORED*/
+boolean
+fesenddata (qdaemon, zdata, cdata, ilocal, iremote, ipos)
+ struct sdaemon *qdaemon;
+ char *zdata;
+ size_t cdata;
+ int ilocal;
+ int iremote;
+ long ipos;
+{
+#if DEBUG > 0
+ /* Keep track of the number of bytes we send out to make sure it all
+ adds up. */
+ cEbytes -= cdata;
+ if (cEbytes < 0)
+ {
+ ulog (LOG_ERROR, "Protocol 'e' internal error");
+ return FALSE;
+ }
+#endif
+
+ /* We pass FALSE to fsend_data since we don't expect the other side
+ to be sending us anything just now. */
+ return fsend_data (qdaemon->qconn, zdata, cdata, FALSE);
+}
+
+/* Process data and return the amount we need in *pfneed. */
+
+static boolean
+feprocess_data (qdaemon, pfexit, pcneed)
+ struct sdaemon *qdaemon;
+ boolean *pfexit;
+ size_t *pcneed;
+{
+ int cinbuf, cfirst, clen;
+
+ *pfexit = FALSE;
+
+ cinbuf = iPrecend - iPrecstart;
+ if (cinbuf < 0)
+ cinbuf += CRECBUFLEN;
+
+ if (! fEfile)
+ {
+ /* We are not receiving a file. Commands continue up to a null
+ byte. */
+ while (cinbuf > 0)
+ {
+ char *pnull;
+
+ cfirst = CRECBUFLEN - iPrecstart;
+ if (cfirst > cinbuf)
+ cfirst = cinbuf;
+
+ pnull = memchr (abPrecbuf + iPrecstart, '\0', (size_t) cfirst);
+ if (pnull != NULL)
+ cfirst = pnull - (abPrecbuf + iPrecstart) + 1;
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "feprocess_data: Got %d command bytes",
+ cfirst);
+
+ if (! fgot_data (qdaemon, abPrecbuf + iPrecstart,
+ (size_t) cfirst, (const char *) NULL, (size_t) 0,
+ -1, -1, (long) -1, TRUE, pfexit))
+ return FALSE;
+
+ iPrecstart = (iPrecstart + cfirst) % CRECBUFLEN;
+
+ if (*pfexit)
+ return TRUE;
+
+ cinbuf = iPrecend - iPrecstart;
+ if (cinbuf < 0)
+ cinbuf += CRECBUFLEN;
+ }
+
+ if (pcneed != NULL)
+ *pcneed = 1;
+
+ return TRUE;
+ }
+
+ /* Here we are receiving a file. We want cEbytes in total. If we
+ don't have cEbytes yet, we have to get it first. */
+
+ if (cEbytes == -1)
+ {
+ char ab[CEFRAMELEN + 1];
+
+ if (cinbuf < CEFRAMELEN)
+ {
+ if (pcneed != NULL)
+ *pcneed = CEFRAMELEN - cinbuf;
+ return TRUE;
+ }
+
+ cfirst = CRECBUFLEN - iPrecstart;
+ if (cfirst >= CEFRAMELEN)
+ memcpy (ab, abPrecbuf + iPrecstart, (size_t) CEFRAMELEN);
+ else
+ {
+ memcpy (ab, abPrecbuf + iPrecstart, (size_t) cfirst);
+ memcpy (ab + cfirst, abPrecbuf, (size_t) CEFRAMELEN - cfirst);
+ }
+
+ ab[CEFRAMELEN] = '\0';
+ cEbytes = strtol (ab, (char **) NULL, 10);
+
+ iPrecstart = (iPrecstart + CEFRAMELEN) % CRECBUFLEN;
+
+ cinbuf = iPrecend - iPrecstart;
+ if (cinbuf < 0)
+ cinbuf += CRECBUFLEN;
+ }
+
+ /* Here we can read real data for the file. */
+
+ while (cinbuf > 0)
+ {
+ clen = cinbuf;
+ if ((long) clen > cEbytes)
+ clen = (int) cEbytes;
+
+ cfirst = CRECBUFLEN - iPrecstart;
+ if (cfirst > clen)
+ cfirst = clen;
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "feprocess_data: Got %d data bytes",
+ clen);
+
+ if (! fgot_data (qdaemon, abPrecbuf + iPrecstart,
+ (size_t) cfirst, abPrecbuf, (size_t) (clen - cfirst),
+ -1, -1, (long) -1, TRUE, pfexit))
+ return FALSE;
+
+ iPrecstart = (iPrecstart + clen) % CRECBUFLEN;
+ cEbytes -= clen;
+
+ if (cEbytes == 0)
+ {
+ if (! fgot_data (qdaemon, abPrecbuf, (size_t) 0,
+ (const char *) NULL, (size_t) 0,
+ -1, -1, (long) -1, TRUE, pfexit))
+ return FALSE;
+ if (*pfexit)
+ return TRUE;
+ }
+
+ cinbuf -= clen;
+ }
+
+ if (pcneed != NULL)
+ {
+ if (cEbytes > CRECBUFLEN / 2)
+ *pcneed = CRECBUFLEN / 2;
+ else
+ *pcneed = (int) cEbytes;
+ }
+
+ return TRUE;
+}
+
+/* Wait for data to come in and process it until we've reached the end
+ of a command or a file. */
+
+boolean
+fewait (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ while (TRUE)
+ {
+ boolean fexit;
+ size_t cneed, crec;
+
+ if (! feprocess_data (qdaemon, &fexit, &cneed))
+ return FALSE;
+ if (fexit)
+ return TRUE;
+
+ if (! freceive_data (qdaemon->qconn, cneed, &crec, cEtimeout, TRUE))
+ return FALSE;
+
+ if (crec == 0)
+ {
+ ulog (LOG_ERROR, "Timed out waiting for data");
+ return FALSE;
+ }
+ }
+}
+
+/* File level routine, to handle transferring the amount of data and
+ to set fEfile correctly. */
+
+boolean
+fefile (qdaemon, qtrans, fstart, fsend, cbytes, pfhandled)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+ boolean fstart;
+ boolean fsend;
+ long cbytes;
+ boolean *pfhandled;
+{
+ *pfhandled = FALSE;
+
+ if (fstart)
+ {
+ if (fsend)
+ {
+ char ab[CEFRAMELEN];
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "Protocol 'e' starting to send %ld bytes",
+ cbytes);
+
+ bzero (ab, (size_t) CEFRAMELEN);
+ sprintf (ab, "%ld", cbytes);
+ if (! fsend_data (qdaemon->qconn, ab, (size_t) CEFRAMELEN, TRUE))
+ return FALSE;
+ cEbytes = cbytes;
+ }
+ else
+ {
+ cEbytes = -1;
+ fEfile = TRUE;
+ }
+ }
+ else
+ {
+ if (! fsend)
+ fEfile = FALSE;
+#if DEBUG > 0
+ if (cEbytes != 0)
+ {
+ ulog (LOG_ERROR,
+ "Protocol 'e' internal error: %ld bytes left over",
+ cEbytes);
+ return FALSE;
+ }
+#endif
+ }
+
+ return TRUE;
+}
diff --git a/gnu/libexec/uucp/uucico/protf.c b/gnu/libexec/uucp/uucico/protf.c
new file mode 100644
index 00000000000..3cdacef25ee
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/protf.c
@@ -0,0 +1,842 @@
+/* protf.c
+ The 'f' protocol.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char protf_rcsid[] = "$Id: protf.c,v 1.1 1993/08/04 19:36:19 jtc Exp $";
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "conn.h"
+#include "trans.h"
+#include "system.h"
+#include "prot.h"
+
+/* This implementation is based on code by Piet Beertema, CWI,
+ Amsterdam, Sep 1984.
+
+ This code implements the 'f' protocol, which requires a
+ flow-controlled error-free seven-bit data path. It does check for
+ errors, but only at the end of each file transmission, so a noisy
+ line without error correcting modems will be unusable.
+
+ The conversion to seven bit data is done as follows, where b
+ represents the character to convert:
+
+ 0 <= b <= 037: 0172, b + 0100 (0100 to 0137)
+ 040 <= b <= 0171: b ( 040 to 0171)
+ 0172 <= b <= 0177: 0173, b - 0100 ( 072 to 077)
+ 0200 <= b <= 0237: 0174, b - 0100 (0100 to 0137)
+ 0240 <= b <= 0371: 0175, b - 0200 ( 040 to 0171)
+ 0372 <= b <= 0377: 0176, b - 0300 ( 072 to 077)
+
+ This causes all output bytes to be in the range 040 to 0176; these
+ are the printable ASCII characters. */
+
+/* This structure is used to hold information when dealing with the
+ end of file acknowledgement. */
+
+struct sfinfo
+{
+ /* The functions from the generic code. */
+ boolean (*psendfn) P((struct stransfer *qtrans, struct sdaemon *qdaemon));
+ boolean (*precfn) P((struct stransfer *qtrans, struct sdaemon *qdaemon,
+ const char *zdata, size_t cdata));
+ /* The info pointer from the generic code. */
+ pointer pinfo;
+ /* The character to send after receiving the checksum. */
+ char bsend;
+};
+
+/* Internal functions. */
+static boolean ffprocess_data P((struct sdaemon *qdaemon,
+ boolean *pfexit, size_t *pcneed));
+static boolean ffawait_ack P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon,
+ const char *zdata, size_t cdata));
+static boolean ffawait_cksum P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon,
+ const char *zdata, size_t cdata));
+static boolean ffsend_ack P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+
+/* The size of the buffer we allocate to store outgoing data in. */
+#define CFBUFSIZE (256)
+
+/* The timeout to wait for data to arrive before giving up. */
+static int cFtimeout = 120;
+
+/* The maximum number of retries. */
+static int cFmaxretries = 2;
+
+/* The buffer we allocate for outgoing data. */
+static char *zFbuf;
+
+/* TRUE if we are receiving a file rather than a command. */
+static boolean fFfile;
+
+/* The checksum so far. */
+static unsigned int iFcheck;
+
+/* The last special byte (0172 to 0176) or 0 if none. */
+static char bFspecial;
+
+/* The number of times we have retried this file. */
+static int cFretries;
+
+/* Whether this file has been acknowledged. */
+static boolean fFacked;
+
+struct uuconf_cmdtab asFproto_params[] =
+{
+ { "timeout", UUCONF_CMDTABTYPE_INT, (pointer) &cFtimeout, NULL },
+ { "retries", UUCONF_CMDTABTYPE_INT, (pointer) &cFmaxretries, NULL },
+ { NULL, 0, NULL, NULL }
+};
+
+/* Statistics. */
+
+/* The number of data bytes sent in files. */
+static long cFsent_data;
+
+/* The number of actual bytes sent in files. */
+static long cFsent_bytes;
+
+/* The number of data bytes received in files. */
+static long cFrec_data;
+
+/* The number of actual bytes received in files. */
+static long cFrec_bytes;
+
+/* The number of file retries when sending. */
+static long cFsend_retries;
+
+/* The number of file retries when receiving. */
+static long cFrec_retries;
+
+/* Start the protocol. */
+
+boolean
+ffstart (qdaemon, pzlog)
+ struct sdaemon *qdaemon;
+ char **pzlog;
+{
+ *pzlog = NULL;
+
+ cFsent_data = 0;
+ cFsent_bytes = 0;
+ cFrec_data = 0;
+ cFrec_bytes = 0;
+ cFsend_retries = 0;
+ cFrec_retries = 0;
+
+ /* Use XON/XOFF handshaking. */
+ if (! fconn_set (qdaemon->qconn, PARITYSETTING_DEFAULT,
+ STRIPSETTING_SEVENBITS, XONXOFF_ON))
+ return FALSE;
+
+ /* We sleep to allow the other side to reset the terminal; this is
+ what Mr. Beertema's code does. */
+ usysdep_sleep (2);
+
+ return TRUE;
+}
+
+/* Shutdown the protocol. */
+
+/*ARGSIGNORED*/
+boolean
+ffshutdown (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ xfree ((pointer) zFbuf);
+ zFbuf = NULL;
+ ulog (LOG_NORMAL,
+ "Protocol 'f': sent %ld bytes for %ld, received %ld bytes for %ld",
+ cFsent_bytes, cFsent_data, cFrec_bytes, cFrec_data);
+ if (cFsend_retries != 0 || cFrec_retries != 0)
+ ulog (LOG_NORMAL, "Protocol 'f' file retries: %ld sending, %ld receiving",
+ cFsend_retries, cFrec_retries);
+ cFtimeout = 120;
+ cFmaxretries = 2;
+ return TRUE;
+}
+
+/* Send a command string. We just send the string followed by a carriage
+ return. */
+
+/*ARGSUSED*/
+boolean
+ffsendcmd (qdaemon, z, ilocal, iremote)
+ struct sdaemon *qdaemon;
+ const char *z;
+ int ilocal;
+ int iremote;
+{
+ size_t clen;
+ char *zalc;
+ boolean fret;
+
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO, "ffsendcmd: Sending command \"%s\"", z);
+
+ clen = strlen (z);
+ zalc = zbufalc (clen + 2);
+ memcpy (zalc, z, clen);
+ zalc[clen] = '\r';
+ zalc[clen + 1] = '\0';
+ fret = fsend_data (qdaemon->qconn, zalc, clen + 1, TRUE);
+ ubuffree (zalc);
+ return fret;
+}
+
+/* Get space to be filled with data. We allocate the space from the
+ heap. */
+
+/*ARGSIGNORED*/
+char *
+zfgetspace (qdaemon, pclen)
+ struct sdaemon *qdaemon;
+ size_t *pclen;
+{
+ *pclen = CFBUFSIZE;
+ if (zFbuf == NULL)
+ zFbuf = (char *) xmalloc (CFBUFSIZE);
+ return zFbuf;
+}
+
+/* Send out a data packet. We have to encode the data into seven bits
+ and accumulate a checksum. */
+
+/*ARGSIGNORED*/
+boolean
+ffsenddata (qdaemon, zdata, cdata, ilocal, iremote, ipos)
+ struct sdaemon *qdaemon;
+ char *zdata;
+ size_t cdata;
+ int ilocal;
+ int iremote;
+ long ipos;
+{
+ char ab[CFBUFSIZE * 2];
+ char *ze;
+ register unsigned int itmpchk;
+
+ cFsent_data += cdata;
+
+ ze = ab;
+ itmpchk = iFcheck;
+ while (cdata-- > 0)
+ {
+ register int b;
+
+ /* Rotate the checksum left. */
+ if ((itmpchk & 0x8000) == 0)
+ itmpchk <<= 1;
+ else
+ {
+ itmpchk <<= 1;
+ ++itmpchk;
+ }
+
+ /* Add the next byte into the checksum. */
+ b = *zdata++ & 0xff;
+ itmpchk += b;
+
+ /* Encode the byte. */
+ if (b <= 0177)
+ {
+ if (b <= 037)
+ {
+ *ze++ = '\172';
+ *ze++ = (char) (b + 0100);
+ }
+ else if (b <= 0171)
+ *ze++ = (char) b;
+ else
+ {
+ *ze++ = '\173';
+ *ze++ = (char) (b - 0100);
+ }
+ }
+ else
+ {
+ if (b <= 0237)
+ {
+ *ze++ = '\174';
+ *ze++ = (char) (b - 0100);
+ }
+ else if (b <= 0371)
+ {
+ *ze++ = '\175';
+ *ze++ = (char) (b - 0200);
+ }
+ else
+ {
+ *ze++ = '\176';
+ *ze++ = (char) (b - 0300);
+ }
+ }
+ }
+
+ iFcheck = itmpchk;
+
+ cFsent_bytes += ze - ab;
+
+ /* Passing FALSE tells fsend_data not to bother looking for incoming
+ information, since we really don't expect any. */
+ return fsend_data (qdaemon->qconn, ab, (size_t) (ze - ab), FALSE);
+}
+
+/* Process data and return the amount of data we are looking for in
+ *pcneed. The 'f' protocol doesn't really reveal this, but when
+ transferring file we know that we need at least seven characters
+ for the checksum. */
+
+static boolean
+ffprocess_data (qdaemon, pfexit, pcneed)
+ struct sdaemon *qdaemon;
+ boolean *pfexit;
+ size_t *pcneed;
+{
+ int i;
+ register unsigned int itmpchk;
+
+ *pfexit = FALSE;
+ if (pcneed != NULL)
+ *pcneed = 1;
+
+ if (! fFfile)
+ {
+ /* A command continues until a '\r' character, which we turn
+ into '\0' before calling fgot_data. */
+ while (iPrecstart != iPrecend)
+ {
+ for (i = iPrecstart; i < CRECBUFLEN && i != iPrecend; i++)
+ {
+ if (abPrecbuf[i] == '\r')
+ {
+ int istart;
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "ffprocess_data: Got %d command bytes",
+ i - iPrecstart + 1);
+
+ abPrecbuf[i] = '\0';
+ istart = iPrecstart;
+ iPrecstart = (i + 1) % CRECBUFLEN;
+ if (pcneed != NULL)
+ *pcneed = 0;
+ return fgot_data (qdaemon, abPrecbuf + istart,
+ (size_t) (i - istart + 1),
+ (const char *) NULL, (size_t) 0,
+ -1, -1, (long) -1, TRUE, pfexit);
+ }
+ }
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "ffprocess_data: Got %d command bytes",
+ i - iPrecstart);
+
+ if (! fgot_data (qdaemon, abPrecbuf + iPrecstart,
+ (size_t) (i - iPrecstart),
+ (const char *) NULL, (size_t) 0,
+ -1, -1, (long) -1, TRUE, pfexit))
+ return FALSE;
+
+ iPrecstart = i % CRECBUFLEN;
+ }
+
+ return TRUE;
+ }
+
+ /* Here the data is destined for a file, and we must decode it. */
+
+ itmpchk = iFcheck;
+
+ while (iPrecstart != iPrecend)
+ {
+ char *zstart, *zto, *zfrom;
+ int c;
+
+ zto = zfrom = zstart = abPrecbuf + iPrecstart;
+
+ c = iPrecend - iPrecstart;
+ if (c < 0)
+ c = CRECBUFLEN - iPrecstart;
+
+ while (c-- != 0)
+ {
+ int b;
+
+ b = *zfrom++ & 0xff;
+ if (b < 040 || b > 0176)
+ {
+ ulog (LOG_ERROR, "Illegal byte %d", b);
+ continue;
+ }
+
+ /* Characters >= 0172 are always special characters. The
+ only legal pair of consecutive special characters
+ are 0176 0176 which immediately precede the four
+ digit checksum. */
+ if (b >= 0172)
+ {
+ if (bFspecial != 0)
+ {
+ if (bFspecial != 0176 || b != 0176)
+ {
+ ulog (LOG_ERROR, "Illegal bytes %d %d",
+ bFspecial, b);
+ bFspecial = 0;
+ continue;
+ }
+
+ /* Pass any initial data. */
+ if (zto != zstart)
+ {
+ /* Don't count the checksum in the received bytes. */
+ cFrec_bytes += zfrom - zstart - 2;
+ cFrec_data += zto - zstart;
+ if (! fgot_data (qdaemon, zstart,
+ (size_t) (zto - zstart),
+ (const char *) NULL, (size_t) 0,
+ -1, -1, (long) -1, TRUE, pfexit))
+ return FALSE;
+ }
+
+ /* The next characters we want to read are the
+ checksum, so skip the second 0176. */
+ iPrecstart = (iPrecstart + zfrom - zstart) % CRECBUFLEN;
+
+ iFcheck = itmpchk;
+
+ /* Tell fgot_data that we've read the entire file by
+ passing 0 length data. This will wind up calling
+ fffile to verify the checksum. We set *pcneed to
+ 0 because we don't want to read any more data
+ from the port, since we may have already read the
+ checksum. */
+ if (pcneed != NULL)
+ *pcneed = 0;
+ return fgot_data (qdaemon, (const char *) NULL,
+ (size_t) 0, (const char *) NULL,
+ (size_t) 0, -1, -1, (long) -1,
+ TRUE, pfexit);
+ }
+
+ /* Here we have encountered a special character that
+ does not follow another special character. */
+ bFspecial = (char) b;
+ }
+ else
+ {
+ int bnext;
+
+ /* Here we have encountered a nonspecial character. */
+
+ switch (bFspecial)
+ {
+ default:
+ bnext = b;
+ break;
+ case 0172:
+ bnext = b - 0100;
+ break;
+ case 0173:
+ case 0174:
+ bnext = b + 0100;
+ break;
+ case 0175:
+ bnext = b + 0200;
+ break;
+ case 0176:
+ bnext = b + 0300;
+ break;
+ }
+
+ *zto++ = (char) bnext;
+ bFspecial = 0;
+
+ /* Rotate the checksum left. */
+ if ((itmpchk & 0x8000) == 0)
+ itmpchk <<= 1;
+ else
+ {
+ itmpchk <<= 1;
+ ++itmpchk;
+ }
+
+ /* Add the next byte into the checksum. */
+ itmpchk += bnext;
+ }
+ }
+
+ if (zto != zstart)
+ {
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "ffprocess_data: Got %d bytes",
+ zto - zstart);
+
+ cFrec_data += zto - zstart;
+ if (! fgot_data (qdaemon, zstart, (size_t) (zto - zstart),
+ (const char *) NULL, (size_t) 0,
+ -1, -1, (long) -1, TRUE, pfexit))
+ return FALSE;
+ }
+
+ cFrec_bytes += zfrom - zstart;
+
+ iPrecstart = (iPrecstart + zfrom - zstart) % CRECBUFLEN;
+ }
+
+ iFcheck = itmpchk;
+
+ if (pcneed != NULL)
+ {
+ /* At this point we may have seen the first 0176 in the checksum
+ but not the second. The checksum is at least seven
+ characters long (0176 0176 a b c d \r). This won't help
+ much, but reading seven characters is a lot better than
+ reading two, which is what I saw in a 2400 baud log file. */
+ if (bFspecial == 0176)
+ *pcneed = 6;
+ else
+ *pcneed = 7;
+ }
+
+ return TRUE;
+}
+
+/* Wait for data to come in and process it until we've finished a
+ command or a file. */
+
+boolean
+ffwait (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ while (TRUE)
+ {
+ boolean fexit;
+ size_t cneed, crec;
+
+ if (! ffprocess_data (qdaemon, &fexit, &cneed))
+ return FALSE;
+ if (fexit)
+ return TRUE;
+
+ if (cneed > 0)
+ {
+ /* We really want to do something like get all available
+ characters, then sleep for half a second and get all
+ available characters again, and keep this up until we
+ don't get anything after sleeping. */
+ if (! freceive_data (qdaemon->qconn, cneed, &crec, cFtimeout, TRUE))
+ return FALSE;
+ if (crec == 0)
+ {
+ ulog (LOG_ERROR, "Timed out waiting for data");
+ return FALSE;
+ }
+ }
+ }
+}
+
+/* File level operations. Reset the checksums when starting to send
+ or receive a file, and output the checksum when we've finished
+ sending a file. */
+
+/*ARGSUSED*/
+boolean
+fffile (qdaemon, qtrans, fstart, fsend, cbytes, pfhandled)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+ boolean fstart;
+ boolean fsend;
+ long cbytes;
+ boolean *pfhandled;
+{
+ DEBUG_MESSAGE3 (DEBUG_PROTO, "fffile: fstart %s; fsend %s; fFacked %s",
+ fstart ? "true" : "false", fsend ? "true" : "false",
+ fFacked ? "true" : "false");
+
+ *pfhandled = FALSE;
+
+ if (fstart)
+ {
+ iFcheck = 0xffff;
+ cFretries = 0;
+ fFacked = FALSE;
+ if (! fsend)
+ {
+ bFspecial = 0;
+ fFfile = TRUE;
+ }
+ return TRUE;
+ }
+ else
+ {
+ struct sfinfo *qinfo;
+
+ /* We need to handle the checksum and the acknowledgement. If
+ we get a successful ACK, we set fFacked to TRUE and call the
+ send or receive function by hand. This will wind up calling
+ here again, so if fFacked is TRUE we just return out and let
+ the send or receive function do whatever it does. This is a
+ bit of a hack. */
+ if (fFacked)
+ {
+ fFacked = FALSE;
+ return TRUE;
+ }
+
+ if (fsend)
+ {
+ char ab[sizeof "\176\176ABCD\r"];
+
+ /* Send the final checksum. */
+ sprintf (ab, "\176\176%04x\r", iFcheck & 0xffff);
+ if (! fsend_data (qdaemon->qconn, ab, (size_t) 7, TRUE))
+ return FALSE;
+
+ /* Now wait for the acknowledgement. */
+ fFfile = FALSE;
+ qinfo = (struct sfinfo *) xmalloc (sizeof (struct sfinfo));
+ qinfo->psendfn = qtrans->psendfn;
+ qinfo->precfn = qtrans->precfn;
+ qinfo->pinfo = qtrans->pinfo;
+ qtrans->psendfn = NULL;
+ qtrans->precfn = ffawait_ack;
+ qtrans->pinfo = (pointer) qinfo;
+ qtrans->fcmd = TRUE;
+
+ *pfhandled = TRUE;
+
+ return fqueue_receive (qdaemon, qtrans);
+ }
+ else
+ {
+ /* Wait for the checksum. */
+ fFfile = FALSE;
+ qinfo = (struct sfinfo *) xmalloc (sizeof (struct sfinfo));
+ qinfo->psendfn = qtrans->psendfn;
+ qinfo->precfn = qtrans->precfn;
+ qinfo->pinfo = qtrans->pinfo;
+ qtrans->psendfn = NULL;
+ qtrans->precfn = ffawait_cksum;
+ qtrans->pinfo = (pointer) qinfo;
+ qtrans->fcmd = TRUE;
+
+ *pfhandled = TRUE;
+
+ return fqueue_receive (qdaemon, qtrans);
+ }
+ }
+}
+
+/* Wait for the ack after sending a file and the checksum. */
+
+static boolean
+ffawait_ack (qtrans, qdaemon, zdata, cdata)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+ const char *zdata;
+ size_t cdata;
+{
+ struct sfinfo *qinfo = (struct sfinfo *) qtrans->pinfo;
+
+ qtrans->precfn = NULL;
+
+ /* An R means to retry sending the file. */
+ if (*zdata == 'R')
+ {
+ if (! ffileisopen (qtrans->e))
+ {
+ ulog (LOG_ERROR, "Request to resent non-file");
+ return FALSE;
+ }
+
+ ++cFretries;
+ if (cFretries > cFmaxretries)
+ {
+ ulog (LOG_ERROR, "Too many retries");
+ return FALSE;
+ }
+
+ ulog (LOG_NORMAL, "Resending file");
+ if (! ffilerewind (qtrans->e))
+ {
+ ulog (LOG_ERROR, "rewind: %s", strerror (errno));
+ return FALSE;
+ }
+ qtrans->ipos = (long) 0;
+
+ iFcheck = 0xffff;
+ ++cFsend_retries;
+
+ qtrans->psendfn = qinfo->psendfn;
+ qtrans->precfn = qinfo->precfn;
+ qtrans->pinfo = qinfo->pinfo;
+ xfree ((pointer) qinfo);
+ qtrans->fsendfile = TRUE;
+
+ return fqueue_send (qdaemon, qtrans);
+ }
+
+ if (*zdata != 'G')
+ {
+ DEBUG_MESSAGE1 (DEBUG_PROTO, "fffile: Got \"%s\"", zdata);
+ ulog (LOG_ERROR, "File send failed");
+ return FALSE;
+ }
+
+ qtrans->psendfn = qinfo->psendfn;
+ qtrans->precfn = qinfo->precfn;
+ qtrans->pinfo = qinfo->pinfo;
+ xfree ((pointer) qinfo);
+
+ /* Now call the send function by hand after setting fFacked to TRUE.
+ Since fFacked is true fffile will simply return out, and the send
+ function can do whatever it what was going to do. */
+ fFacked = TRUE;
+ return (*qtrans->psendfn) (qtrans, qdaemon);
+}
+
+/* This function is called when the checksum arrives. */
+
+/*ARGSUSED*/
+static boolean
+ffawait_cksum (qtrans, qdaemon, zdata, cdata)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+ const char *zdata;
+ size_t cdata;
+{
+ struct sfinfo *qinfo = (struct sfinfo *) qtrans->pinfo;
+ unsigned int icheck;
+
+ qtrans->precfn = NULL;
+
+ if (! isxdigit (zdata[0])
+ || ! isxdigit (zdata[1])
+ || ! isxdigit (zdata[2])
+ || ! isxdigit (zdata[3])
+ || zdata[4] != '\0')
+ {
+ ulog (LOG_ERROR, "Bad checksum format");
+ xfree (qtrans->pinfo);
+ return FALSE;
+ }
+
+ icheck = (unsigned int) strtol ((char *) zdata, (char **) NULL, 16);
+
+ if (icheck != (iFcheck & 0xffff))
+ {
+ DEBUG_MESSAGE2 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "Checksum failed; calculated 0x%x, got 0x%x",
+ iFcheck & 0xffff, icheck);
+
+ if (! ffileisopen (qtrans->e))
+ {
+ ulog (LOG_ERROR, "Failed to get non-file");
+ return FALSE;
+ }
+
+ ++cFretries;
+ if (cFretries > cFmaxretries)
+ {
+ ulog (LOG_ERROR, "Too many retries");
+ qinfo->bsend = 'Q';
+ }
+ else
+ {
+ ulog (LOG_NORMAL, "File being resent");
+
+ /* This bit of code relies on the receive code setting
+ qtrans->s.ztemp to the full name of the temporary file
+ being used. */
+ qtrans->e = esysdep_truncate (qtrans->e, qtrans->s.ztemp);
+ if (! ffileisopen (qtrans->e))
+ return FALSE;
+ qtrans->ipos = (long) 0;
+
+ iFcheck = 0xffff;
+ bFspecial = 0;
+ fFfile = TRUE;
+ ++cFrec_retries;
+
+ /* Send an R to tell the other side to resend the file. */
+ qinfo->bsend = 'R';
+ }
+ }
+ else
+ {
+ /* Send a G to tell the other side the file was received
+ correctly. */
+ qinfo->bsend = 'G';
+ }
+
+ qtrans->psendfn = ffsend_ack;
+
+ return fqueue_send (qdaemon, qtrans);
+}
+
+/* Send the acknowledgement, and then possible wait for the resent
+ file. */
+
+static boolean
+ffsend_ack (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct sfinfo *qinfo = (struct sfinfo *) qtrans->pinfo;
+ char ab[2];
+
+ ab[0] = qinfo->bsend;
+ ab[1] = '\0';
+ if (! ffsendcmd (qdaemon, ab, 0, 0))
+ return FALSE;
+
+ qtrans->psendfn = qinfo->psendfn;
+ qtrans->precfn = qinfo->precfn;
+ qtrans->pinfo = qinfo->pinfo;
+ xfree ((pointer) qinfo);
+
+ if (ab[0] == 'Q')
+ return FALSE;
+ if (ab[0] == 'R')
+ {
+ qtrans->frecfile = TRUE;
+ return fqueue_receive (qdaemon, qtrans);
+ }
+
+ fFacked = TRUE;
+ return (*qtrans->precfn) (qtrans, qdaemon, (const char *) NULL,
+ (size_t) 0);
+}
diff --git a/gnu/libexec/uucp/uucico/protg.c b/gnu/libexec/uucp/uucico/protg.c
new file mode 100644
index 00000000000..e9eaeb04906
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/protg.c
@@ -0,0 +1,1933 @@
+/* protg.c
+ The 'g' protocol.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char protg_rcsid[] = "$Id: protg.c,v 1.1 1993/08/04 19:36:20 jtc Exp $";
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "conn.h"
+#include "trans.h"
+#include "system.h"
+#include "prot.h"
+
+/* Each 'g' protocol packet begins with six bytes. They are:
+
+ <DLE><k><c0><c1><C><x>
+
+ <DLE> is the ASCII DLE character (^P or '\020').
+ if 1 <= <k> <= 8, the packet is followed by 2 ** (k + 4) bytes of data;
+ if <k> == 9, these six bytes are a complete control packet;
+ other value of <k> are illegal.
+ <c0> is the low byte of a checksum.
+ <c1> is the high byte of a checksum.
+ <C> is a control byte (see below).
+ <x> is <k> ^ <c0> ^ <c1> ^ <C>.
+
+ The control byte <C> is divided into three bitfields:
+
+ t t x x x y y y
+
+ The two bit field tt is the packet type.
+ The three bit field xxx is the control type for a control packet, or
+ the sequence number for a data packet.
+ The three bit field yyy is a value for a control packet, or the
+ sequence number of the last packet received for a data packet.
+
+ For all successfully recieved packets, the control byte is stored
+ into iGpacket_control. */
+
+/* Names for the bytes in the frame header. */
+#define IFRAME_DLE (0)
+#define IFRAME_K (1)
+#define IFRAME_CHECKLOW (2)
+#define IFRAME_CHECKHIGH (3)
+#define IFRAME_CONTROL (4)
+#define IFRAME_XOR (5)
+
+/* Length of the frame header. */
+#define CFRAMELEN (6)
+
+/* Macros to break apart the control bytes. */
+#define CONTROL_TT(b) ((int)(((b) >> 6) & 03))
+#define CONTROL_XXX(b) ((int)(((b) >> 3) & 07))
+#define CONTROL_YYY(b) ((int)((b) & 07))
+
+/* DLE value. */
+#define DLE ('\020')
+
+/* Get the length of a packet given a pointer to the header. */
+#define CPACKLEN(z) ((size_t) (1 << ((z)[IFRAME_K] + 4)))
+
+/* <k> field value for a control message. */
+#define KCONTROL (9)
+
+/* Get the next sequence number given a sequence number. */
+#define INEXTSEQ(i) ((i + 1) & 07)
+
+/* Compute i1 - i2 modulo 8. */
+#define CSEQDIFF(i1, i2) (((i1) + 8 - (i2)) & 07)
+
+/* Packet types. These are from the tt field.
+ CONTROL -- control packet
+ ALTCHAN -- alternate channel; not used by UUCP
+ DATA -- full data segment
+ SHORTDATA -- less than full data segment (all the bytes specified by
+ the packet length <k> are always transferred). Let <u> be the number
+ of bytes in the data segment not to be used. If <u> <= 0x7f, the first
+ byte of the data segment is <u> and the data follows. If <u> > 0x7f,
+ the first byte of the data segment is 0x80 | (<u> & 0x7f), the second
+ byte of the data segment is <u> >> 7, and the data follows. The
+ maximum possible data segment size is 2**12, so this handles all
+ possible cases. */
+#define CONTROL (0)
+#define ALTCHAN (1)
+#define DATA (2)
+#define SHORTDATA (3)
+
+/* Control types. These are from the xxx field if the type (tt field)
+ is CONTROL.
+
+ CLOSE -- close the connection
+ RJ -- reject; packet yyy last to be received correctly
+ SRJ -- selective reject; reject only packet yyy (not used by UUCP)
+ RR -- receiver ready; packet yyy received correctly
+ INITC -- third step of initialization; yyy holds window size
+ INITB -- second step of initialization; yyy holds maximum <k> value - 1
+ INITA -- first step of initialization; yyy holds window size.
+
+ The yyy value for RR is the same as the yyy value for an ordinary
+ data packet. */
+#define CLOSE (1)
+#define RJ (2)
+#define SRJ (3)
+#define RR (4)
+#define INITC (5)
+#define INITB (6)
+#define INITA (7)
+
+/* Maximum amount of data in a single packet. This is set by the <k>
+ field in the header; the amount of data in a packet is
+ 2 ** (<k> + 4). <k> ranges from 1 to 8. */
+
+#define CMAXDATAINDEX (8)
+
+#define CMAXDATA (1 << (CMAXDATAINDEX + 4))
+
+/* Maximum window size. */
+#define CMAXWINDOW (7)
+
+/* Defaults for the protocol parameters. These may all be changed by
+ using the ``protocol-parameter g'' command, so there is no
+ particular reason to change the values given here. */
+
+/* The desired window size. This is what we tell the other system to
+ use. It must be between 1 and 7, and there's no reason to use less
+ than 7. Protocol parameter ``window''. */
+#define IWINDOW (7)
+
+/* The desired packet size. Many implementations only support 64 byte
+ packets. Protocol parameter ``packet-size''. */
+#define IPACKSIZE (64)
+
+/* The number of times to retry the exchange of INIT packets when
+ starting the protocol. Protocol parameter ``startup-retries''. */
+#define CSTARTUP_RETRIES (8)
+
+/* The timeout to use when waiting for an INIT packet when starting up
+ the protocol. Protocol parameter ``init-timeout''. */
+#define CEXCHANGE_INIT_TIMEOUT (10)
+
+/* The number of times to retry sending and waiting for a single INIT
+ packet when starting the protocol. This controls a single INIT
+ packet, while CSTARTUP_RETRIES controls how many times to try the
+ entire INIT sequence. Protocol parameter ``init-retries''. */
+#define CEXCHANGE_INIT_RETRIES (4)
+
+/* The timeout to use when waiting for a packet. Protocol parameter
+ ``timeout''. */
+#define CTIMEOUT (10)
+
+/* The number of times to retry waiting for a packet. Each time the
+ timeout fails we send a copy of our last data packet or a reject
+ message for the packet we expect from the other side, depending on
+ whether we are waiting for an acknowledgement or a data packet.
+ This is the number of times we try doing that and then waiting
+ again. Protocol parameter ``retries''. */
+#define CRETRIES (6)
+
+/* If we see more than this much unrecognized data, we drop the
+ connection. This must be larger than a single packet size, which
+ means it must be larger than 4096 (the largest possible packet
+ size). Protocol parameter ``garbage''. */
+#define CGARBAGE (10000)
+
+/* If we see more than this many protocol errors, we drop the
+ connection. Protocol parameter ``errors''. */
+#define CERRORS (100)
+
+/* Default decay rate. Each time we send or receive this many packets
+ succesfully, we decrement the error level by one (protocol
+ parameter ``error-decay''). */
+#define CERROR_DECAY (10)
+
+/* If this value is non-zero, it will be used as the remote window
+ size regardless of what the other side requested. This can be
+ useful for dealing with some particularly flawed packages. This
+ default value should always be 0, and protocol parameter
+ ``remote-window'' should be used for the affected systems. */
+#define IREMOTE_WINDOW (0)
+
+/* If this value is non-zero, it will be used as the packet size to
+ send to the remote system regardless of what it requested. It's
+ difficult to imagine any circumstances where you would want to set
+ this. Protocol parameter ``remote-packet-size''. */
+#define IREMOTE_PACKSIZE (0)
+
+/* Local variables. */
+
+/* Next sequence number to send. */
+static int iGsendseq;
+
+/* Last sequence number that has been acked. */
+static int iGremote_ack;
+
+/* Last sequence number to be retransmitted. */
+static int iGretransmit_seq;
+
+/* Last sequence number we have received. */
+static int iGrecseq;
+
+/* Last sequence number we have acked. */
+static int iGlocal_ack;
+
+/* Window size to request (protocol parameter ``window''). */
+static int iGrequest_winsize = IWINDOW;
+
+/* Packet size to request (protocol parameter ``packet-size''). */
+static int iGrequest_packsize = IPACKSIZE;
+
+/* Remote window size (set during handshake). */
+static int iGremote_winsize;
+
+/* Forced remote window size (protocol parameter ``remote-window''). */
+static int iGforced_remote_winsize = IREMOTE_WINDOW;
+
+/* Remote segment size (set during handshake). This is one less than
+ the value in a packet header. */
+static int iGremote_segsize;
+
+/* Remote packet size (set based on iGremote_segsize). */
+static size_t iGremote_packsize;
+
+/* Forced remote packet size (protocol parameter
+ ``remote-packet-size''). */
+static int iGforced_remote_packsize = IREMOTE_PACKSIZE;
+
+/* Recieved control byte. */
+static int iGpacket_control;
+
+/* Number of times to retry the initial handshake. Protocol parameter
+ ``startup-retries''. */
+static int cGstartup_retries = CSTARTUP_RETRIES;
+
+/* Number of times to retry sending an initial control packet.
+ Protocol parameter ``init-retries''. */
+static int cGexchange_init_retries = CEXCHANGE_INIT_RETRIES;
+
+/* Timeout (seconds) for receiving an initial control packet.
+ Protocol parameter ``init-timeout''. */
+static int cGexchange_init_timeout = CEXCHANGE_INIT_TIMEOUT;
+
+/* Timeout (seconds) for receiving a data packet. Protocol parameter
+ ``timeout''. */
+static int cGtimeout = CTIMEOUT;
+
+/* Maximum number of timeouts when receiving a data packet or
+ acknowledgement. Protocol parameter ``retries''. */
+static int cGretries = CRETRIES;
+
+/* Amount of garbage data we are prepared to see before giving up.
+ Protocol parameter ``garbage''. */
+static int cGgarbage_data = CGARBAGE;
+
+/* Maximum number of errors we are prepared to see before giving up.
+ Protocol parameter ``errors''. */
+static int cGmax_errors = CERRORS;
+
+/* Each time we receive this many packets succesfully, we decrement
+ the error level by one (protocol parameter ``error-decay''). */
+static int cGerror_decay = CERROR_DECAY;
+
+/* Whether to use shorter packets when possible. Protocol parameter
+ ``short-packets''. */
+static boolean fGshort_packets = TRUE;
+
+/* Protocol parameter commands. */
+struct uuconf_cmdtab asGproto_params[] =
+{
+ { "window", UUCONF_CMDTABTYPE_INT, (pointer) &iGrequest_winsize, NULL },
+ { "packet-size", UUCONF_CMDTABTYPE_INT, (pointer) &iGrequest_packsize,
+ NULL },
+ { "startup-retries", UUCONF_CMDTABTYPE_INT, (pointer) &cGstartup_retries,
+ NULL },
+ { "init-timeout", UUCONF_CMDTABTYPE_INT, (pointer) &cGexchange_init_timeout,
+ NULL },
+ { "init-retries", UUCONF_CMDTABTYPE_INT, (pointer) &cGexchange_init_retries,
+ NULL },
+ { "timeout", UUCONF_CMDTABTYPE_INT, (pointer) &cGtimeout, NULL },
+ { "retries", UUCONF_CMDTABTYPE_INT, (pointer) &cGretries, NULL },
+ { "garbage", UUCONF_CMDTABTYPE_INT, (pointer) &cGgarbage_data, NULL },
+ { "errors", UUCONF_CMDTABTYPE_INT, (pointer) &cGmax_errors, NULL },
+ { "error-decay", UUCONF_CMDTABTYPE_INT, (pointer) &cGerror_decay, NULL },
+ { "remote-window", UUCONF_CMDTABTYPE_INT,
+ (pointer) &iGforced_remote_winsize, NULL },
+ { "remote-packet-size", UUCONF_CMDTABTYPE_INT,
+ (pointer) &iGforced_remote_packsize, NULL },
+ { "short-packets", UUCONF_CMDTABTYPE_BOOLEAN, (pointer) &fGshort_packets,
+ NULL },
+ { NULL, 0, NULL, NULL }
+};
+
+/* Statistics. */
+
+/* Number of packets we have sent. */
+static long cGsent_packets;
+
+/* Number of packets we have resent (these are not included in
+ cGsent_packets). */
+static long cGresent_packets;
+
+/* Number of packets we have delayed sending (these should not be
+ counted in cGresent_packets). */
+static long cGdelayed_packets;
+
+/* Number of packets we have received. */
+static long cGrec_packets;
+
+/* Number of packets rejected because the header was bad. */
+static long cGbad_hdr;
+
+/* Number of packets rejected because the checksum was bad. */
+static long cGbad_checksum;
+
+/* Number of packets received out of order. */
+static long cGbad_order;
+
+/* Number of packets rejected by receiver (number of RJ packets
+ received). */
+static long cGremote_rejects;
+
+/* The error level. This is the total number of errors as adjusted by
+ cGerror_decay. */
+static long cGerror_level;
+
+/* Each time we send an RJ, we can expect several out of order of
+ packets, because the other side will probably have sent a full
+ window by the time it sees the RJ. This variable keeps track of
+ the number of out of order packets we expect to see. We don't
+ count expected out of order packets against the error level. This
+ is reset to 0 when an in order packet is received. */
+static int cGexpect_bad_order;
+
+#if DEBUG > 1
+/* Control packet names used for debugging. */
+static const char * const azGcontrol[] =
+{"?0?", "CLOSE", "RJ", "SRJ", "RR", "INITC", "INITB", "INITA"};
+#endif
+
+/* Local functions. */
+static boolean fgexchange_init P((struct sdaemon *qdaemon, int ictl,
+ int ival, int *piset));
+static boolean fgsend_control P((struct sdaemon *qdaemon, int ictl,
+ int ival));
+static char *zgadjust_ack P((int iseq));
+static boolean fgwait_for_packet P((struct sdaemon *qdaemon,
+ boolean freturncontrol, int ctimeout,
+ int cretries));
+static boolean fgsend_acks P((struct sdaemon *qdaemon));
+static boolean fggot_ack P((struct sdaemon *qdaemon, int iack));
+static boolean fgprocess_data P((struct sdaemon *qdaemon, boolean fdoacks,
+ boolean freturncontrol,
+ boolean *pfexit, size_t *pcneed,
+ boolean *pffound));
+static boolean fginit_sendbuffers P((boolean fallocate));
+static boolean fgcheck_errors P((struct sdaemon *qdaemon));
+static int igchecksum P((const char *zdata, size_t clen));
+static int igchecksum2 P((const char *zfirst, size_t cfirst,
+ const char *zsecond, size_t csecond));
+
+/* Start the protocol. This requires a three way handshake. Both sides
+ must send and receive an INITA packet, an INITB packet, and an INITC
+ packet. The INITA and INITC packets contain the window size, and the
+ INITB packet contains the packet size. */
+
+boolean
+fgstart (qdaemon, pzlog)
+ struct sdaemon *qdaemon;
+ char **pzlog;
+{
+ int iseg;
+ int i;
+ boolean fgota, fgotb;
+
+ *pzlog = NULL;
+
+ /* The 'g' protocol requires a full eight bit interface. */
+ if (! fconn_set (qdaemon->qconn, PARITYSETTING_NONE,
+ STRIPSETTING_EIGHTBITS, XONXOFF_OFF))
+ return FALSE;
+
+ iGsendseq = 1;
+ iGremote_ack = 0;
+ iGretransmit_seq = -1;
+ iGrecseq = 0;
+ iGlocal_ack = 0;
+ cGsent_packets = 0;
+ cGresent_packets = 0;
+ cGdelayed_packets = 0;
+ cGrec_packets = 0;
+ cGbad_hdr = 0;
+ cGbad_checksum = 0;
+ cGbad_order = 0;
+ cGremote_rejects = 0;
+ cGerror_level = 0;
+ cGexpect_bad_order = 0;
+
+ /* We must determine the segment size based on the packet size
+ which may have been modified by a protocol parameter command.
+ A segment size of 2^n is passed as n - 5. */
+ i = iGrequest_packsize;
+ iseg = -1;
+ while (i > 0)
+ {
+ ++iseg;
+ i >>= 1;
+ }
+ iseg -= 5;
+ if (iseg < 0 || iseg > 7)
+ {
+ ulog (LOG_ERROR, "Illegal packet size %d for '%c' protocol",
+ iGrequest_packsize, qdaemon->qproto->bname);
+ iseg = 1;
+ }
+
+ fgota = FALSE;
+ fgotb = FALSE;
+ for (i = 0; i < cGstartup_retries; i++)
+ {
+ if (fgota)
+ {
+ if (! fgsend_control (qdaemon, INITA, iGrequest_winsize))
+ return FALSE;
+ }
+ else
+ {
+ if (! fgexchange_init (qdaemon, INITA, iGrequest_winsize,
+ &iGremote_winsize))
+ continue;
+ }
+ fgota = TRUE;
+
+ if (fgotb)
+ {
+ if (! fgsend_control (qdaemon, INITB, iseg))
+ return FALSE;
+ }
+ else
+ {
+ if (! fgexchange_init (qdaemon, INITB, iseg, &iGremote_segsize))
+ continue;
+ }
+ fgotb = TRUE;
+
+ if (! fgexchange_init (qdaemon, INITC, iGrequest_winsize,
+ &iGremote_winsize))
+ continue;
+
+ /* We have succesfully connected. Determine the remote packet
+ size. */
+ iGremote_packsize = 1 << (iGremote_segsize + 5);
+
+ /* If the user requested us to force specific remote window and
+ packet sizes, do so now. */
+ if (iGforced_remote_winsize > 0
+ && iGforced_remote_winsize <= CMAXWINDOW)
+ iGremote_winsize = iGforced_remote_winsize;
+
+ if (iGforced_remote_packsize >= 32
+ && iGforced_remote_packsize <= 4096)
+ {
+ /* Force the value to a power of two. */
+ i = iGforced_remote_packsize;
+ iseg = -1;
+ while (i > 0)
+ {
+ ++iseg;
+ i >>= 1;
+ }
+ iGremote_packsize = 1 << iseg;
+ iGremote_segsize = iseg - 5;
+ }
+
+ /* Set up packet buffers to use. We don't do this until we know
+ the maximum packet size we are going to send. */
+ if (! fginit_sendbuffers (TRUE))
+ return FALSE;
+
+ *pzlog = zbufalc (sizeof "protocol '' packet size window " + 50);
+ sprintf (*pzlog, "protocol '%c' packet size %d window %d",
+ qdaemon->qproto->bname, (int) iGremote_packsize,
+ (int) iGremote_winsize);
+
+ return TRUE;
+ }
+
+ DEBUG_MESSAGE0 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgstart: Protocol startup failed");
+
+ return FALSE;
+}
+
+/* The 'G' protocol is identical to the 'g' protocol, except that
+ short packets are never supported. */
+
+boolean
+fbiggstart (qdaemon, pzlog)
+ struct sdaemon *qdaemon;
+ char **pzlog;
+{
+ fGshort_packets = FALSE;
+ return fgstart (qdaemon, pzlog);
+}
+
+/* Exchange initialization messages with the other system.
+
+ A problem:
+
+ We send INITA; it gets received
+ We receive INITA
+ We send INITB; it gets garbled
+ We receive INITB
+
+ We have seen and sent INITB, so we start to send INITC. The other
+ side as sent INITB but not seen it, so it times out and resends
+ INITB. We will continue sending INITC and the other side will
+ continue sending INITB until both sides give up and start again
+ with INITA.
+
+ It might seem as though if we are sending INITC and receive INITB,
+ we should resend our INITB, but this could cause infinite echoing
+ of INITB on a long-latency line. Rather than risk that, I have
+ implemented a fast drop-back procedure. If we are sending INITB and
+ receive INITC, the other side has gotten ahead of us. We immediately
+ fail and begin again with INITA. For the other side, if we are
+ sending INITC and see INITA, we also immediately fail back to INITA.
+
+ Unfortunately, this doesn't work for the other case, in which we
+ are sending INITB but the other side has not yet seen INITA. As
+ far as I can see, if this happens we just have to wait until we
+ time out and resend INITA. */
+
+static boolean
+fgexchange_init (qdaemon, ictl, ival, piset)
+ struct sdaemon *qdaemon;
+ int ictl;
+ int ival;
+ int *piset;
+{
+ int i;
+
+ /* The three-way handshake should be independent of who initializes
+ it, but it seems that some versions of uucico assume that the
+ caller sends first and the callee responds. This only matters if
+ we are the callee and the first packet is garbled. If we send a
+ packet, the other side will assume that we must have seen the
+ packet they sent and will never time out and send it again.
+ Therefore, if we are the callee we don't send a packet the first
+ time through the loop. This can still fail, but should usually
+ work, and, after all, if the initialization packets are received
+ correctly there will be no problem no matter what we do. */
+ for (i = 0; i < cGexchange_init_retries; i++)
+ {
+ long itime;
+ int ctimeout;
+
+ if (qdaemon->fcaller || i > 0)
+ {
+ if (! fgsend_control (qdaemon, ictl, ival))
+ return FALSE;
+ }
+
+ itime = ixsysdep_time ((long *) NULL);
+ ctimeout = cGexchange_init_timeout;
+
+ do
+ {
+ long inewtime;
+
+ /* We pass 0 as the retry count to fgwait_for_packet because
+ we want to handle retries here and because if it retried
+ it would send a packet, which would be bad. */
+ if (! fgwait_for_packet (qdaemon, TRUE, ctimeout, 0))
+ break;
+
+ if (CONTROL_TT (iGpacket_control) == CONTROL)
+ {
+ if (CONTROL_XXX (iGpacket_control) == ictl)
+ {
+ *piset = CONTROL_YYY (iGpacket_control);
+
+ /* If we didn't already send our initialization
+ packet, send it now. */
+ if (! qdaemon->fcaller && i == 0)
+ {
+ if (! fgsend_control (qdaemon, ictl, ival))
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ /* If the other side is farther along than we are,
+ we have lost a packet. Fail immediately back to
+ INITA (but don't fail if we are already doing INITA,
+ since that would count against cStart_retries more
+ than it should). */
+ if (CONTROL_XXX (iGpacket_control) < ictl && ictl != INITA)
+ return FALSE;
+
+ /* If we are sending INITC and we receive an INITA, the other
+ side has failed back (we know this because we have
+ seen an INITB from them). Fail back ourselves to
+ start the whole handshake over again. */
+ if (CONTROL_XXX (iGpacket_control) == INITA && ictl == INITC)
+ return FALSE;
+
+ /* As a special hack, if we are sending INITC and we
+ receive INITB, we update the segment size from the
+ packet. This permits a second INITB to override the
+ first one. It would be nice to do this in a cleaner
+ way. */
+ if (CONTROL_XXX (iGpacket_control) == INITB && ictl == INITC)
+ iGremote_segsize = CONTROL_YYY (iGpacket_control);
+ }
+
+ inewtime = ixsysdep_time ((long *) NULL);
+ ctimeout -= inewtime - itime;
+ }
+ while (ctimeout > 0);
+ }
+
+ return FALSE;
+}
+
+/* Shut down the protocol. */
+
+boolean
+fgshutdown (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ (void) fgsend_control (qdaemon, CLOSE, 0);
+ (void) fgsend_control (qdaemon, CLOSE, 0);
+ (void) fginit_sendbuffers (FALSE);
+
+ /* The count of sent packets may not be accurate, because some of
+ them may have not been sent yet if the connection failed in the
+ middle (the ones that counted for cGdelayed_packets). I don't
+ think it's worth being precise. */
+ ulog (LOG_NORMAL,
+ "Protocol '%c' packets: sent %ld, resent %ld, received %ld",
+ qdaemon->qproto->bname, cGsent_packets,
+ cGresent_packets - cGdelayed_packets, cGrec_packets);
+ if (cGbad_hdr != 0
+ || cGbad_checksum != 0
+ || cGbad_order != 0
+ || cGremote_rejects != 0)
+ ulog (LOG_NORMAL,
+ "Errors: header %ld, checksum %ld, order %ld, remote rejects %ld",
+ cGbad_hdr, cGbad_checksum, cGbad_order, cGremote_rejects);
+
+ /* Reset all the parameters to their default values, so that the
+ protocol parameters used for this connection do not affect the
+ next one. */
+ iGrequest_winsize = IWINDOW;
+ iGrequest_packsize = IPACKSIZE;
+ cGstartup_retries = CSTARTUP_RETRIES;
+ cGexchange_init_timeout = CEXCHANGE_INIT_TIMEOUT;
+ cGexchange_init_retries = CEXCHANGE_INIT_RETRIES;
+ cGtimeout = CTIMEOUT;
+ cGretries = CRETRIES;
+ cGgarbage_data = CGARBAGE;
+ cGmax_errors = CERRORS;
+ cGerror_decay = CERROR_DECAY;
+ iGforced_remote_winsize = IREMOTE_WINDOW;
+ iGforced_remote_packsize = IREMOTE_PACKSIZE;
+ fGshort_packets = TRUE;
+
+ return TRUE;
+}
+
+/* Send a command string. We send packets containing the string until
+ the entire string has been sent. Each packet is full. */
+
+/*ARGSUSED*/
+boolean
+fgsendcmd (qdaemon, z, ilocal, iremote)
+ struct sdaemon *qdaemon;
+ const char *z;
+ int ilocal;
+ int iremote;
+{
+ size_t clen;
+ boolean fagain;
+
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO, "fgsendcmd: Sending command \"%s\"", z);
+
+ clen = strlen (z);
+
+ do
+ {
+ char *zpacket;
+ size_t cdummy;
+
+ zpacket = zggetspace (qdaemon, &cdummy);
+
+ if (clen < iGremote_packsize)
+ {
+ size_t csize;
+
+ /* If the remote packet size is larger than 64 (the default,
+ which may indicate an older UUCP package), try to fit
+ this command into a smaller packet. We still always send
+ a complete packet, though. */
+ if (iGremote_packsize <= 64 || ! fGshort_packets)
+ csize = iGremote_packsize;
+ else
+ {
+ csize = 32;
+ while (csize <= clen)
+ csize <<= 1;
+ }
+
+ memcpy (zpacket, z, clen);
+ bzero (zpacket + clen, csize - clen);
+ fagain = FALSE;
+
+ if (! fgsenddata (qdaemon, zpacket, csize, 0, 0, (long) 0))
+ return FALSE;
+ }
+ else
+ {
+ memcpy (zpacket, z, iGremote_packsize);
+ z += iGremote_packsize;
+ clen -= iGremote_packsize;
+ fagain = TRUE;
+
+ if (! fgsenddata (qdaemon, zpacket, iGremote_packsize,
+ 0, 0, (long) 0))
+ return FALSE;
+ }
+ }
+ while (fagain);
+
+ return TRUE;
+}
+
+/* We keep an array of buffers to retransmit as necessary. Rather
+ than waste static space on large buffer sizes, we allocate the
+ buffers once we know how large the other system expects them to be.
+ The sequence numbers used in the 'g' protocol are only three bits
+ long, so we allocate eight buffers and maintain a correspondence
+ between buffer index and sequence number. This always wastes some
+ buffer space, but it's easy to implement.
+
+ We leave room at the front of the buffer for the frame header and
+ two additional bytes. The two extra bytes are used for short
+ packets, which essentially use a longer header and shorter data.
+ We do this to avoid moving the data. We zero out any unused bytes
+ before the frame, so we can locate the real header given a buffer
+ by finding the first non-zero byte (which will be one of the first
+ three bytes in the buffer). */
+
+#define CSENDBUFFERS (CMAXWINDOW + 1)
+
+static char *azGsendbuffers[CSENDBUFFERS];
+
+static boolean
+fginit_sendbuffers (fallocate)
+ boolean fallocate;
+{
+ int i;
+
+ /* Free up any remaining old buffers. */
+ for (i = 0; i < CSENDBUFFERS; i++)
+ {
+ xfree ((pointer) azGsendbuffers[i]);
+ if (fallocate)
+ {
+ azGsendbuffers[i] = (char *) malloc (CFRAMELEN + 2
+ + iGremote_packsize);
+ if (azGsendbuffers[i] == NULL)
+ return FALSE;
+
+ /* This bzero might not seem necessary, since before we send
+ out each packet we zero out any non-data bytes. However,
+ if we receive an SRJ at the start of the conversation, we
+ will send out the packet before it has been set to
+ anything, thus sending the contents of our heap. We
+ avoid this by using bzero. */
+ bzero (azGsendbuffers[i], CFRAMELEN + 2 + iGremote_packsize);
+ }
+ else
+ azGsendbuffers[i] = NULL;
+ }
+ return TRUE;
+}
+
+/* Allocate a packet to send out. The return value of this function
+ must be filled in and passed to fgsenddata, or discarded. This
+ will ensure that the buffers and iGsendseq stay in synch. Set
+ *pclen to the amount of data to place in the buffer. */
+
+/*ARGSUSED*/
+char *
+zggetspace (qdaemon, pclen)
+ struct sdaemon *qdaemon;
+ size_t *pclen;
+{
+ *pclen = iGremote_packsize;
+ return azGsendbuffers[iGsendseq] + CFRAMELEN + 2;
+}
+
+/* Send out a data packet. This computes the checksum, sets up the
+ header, and sends the packet out. The argument zdata should point
+ to the return value of zggetspace. */
+
+/*ARGSIGNORED*/
+boolean
+fgsenddata (qdaemon, zdata, cdata, ilocal, iremote, ipos)
+ struct sdaemon *qdaemon;
+ char *zdata;
+ size_t cdata;
+ int ilocal;
+ int iremote;
+ long ipos;
+{
+ char *z;
+ int itt, iseg;
+ size_t csize;
+ int iclr1, iclr2;
+ unsigned short icheck;
+
+ /* Set the initial length bytes. See the description at the definition
+ of SHORTDATA, above. */
+ itt = DATA;
+ csize = iGremote_packsize;
+ iseg = iGremote_segsize + 1;
+
+#if DEBUG > 0
+ if (cdata > csize)
+ ulog (LOG_FATAL, "fgsend_packet: Packet size too large");
+#endif
+
+ iclr1 = -1;
+ iclr2 = -2;
+ if (cdata < csize)
+ {
+ /* If the remote packet size is larger than 64, the default, we
+ can assume they can handle a smaller packet as well, which
+ will be more efficient to send. */
+ if (iGremote_packsize > 64 && fGshort_packets)
+ {
+ /* The packet size is 1 << (iseg + 4). */
+ iseg = 1;
+ csize = 32;
+ while (csize < cdata)
+ {
+ csize <<= 1;
+ ++iseg;
+ }
+ }
+
+ if (csize != cdata)
+ {
+ size_t cshort;
+
+ /* We have to add bytes which indicate how short the packet
+ is. We do this by pushing the header backward, which we
+ can do because we allocated two extra bytes for this
+ purpose. */
+ iclr2 = 0;
+ itt = SHORTDATA;
+ cshort = csize - cdata;
+ if (cshort <= 127)
+ {
+ --zdata;
+ zdata[0] = (char) cshort;
+ zdata[-1] = '\0';
+ bzero (zdata + cdata + 1, cshort - 1);
+ }
+ else
+ {
+ zdata -= 2;
+ zdata[0] = (char) (0x80 | (cshort & 0x7f));
+ zdata[1] = (char) (cshort >> 7);
+ bzero (zdata + cdata + 2, cshort - 2);
+ iclr1 = 0;
+ }
+ }
+ }
+
+ z = zdata - CFRAMELEN;
+
+ /* Zero out the preceding bytes, in case the last time this buffer
+ was used those bytes were used. We need to zero out the initial
+ bytes so that we can find the true start of the packet in
+ zgadjust_ack. */
+ z[iclr1] = '\0';
+ z[iclr2] = '\0';
+
+ z[IFRAME_DLE] = DLE;
+ z[IFRAME_K] = (char) iseg;
+
+ icheck = (unsigned short) igchecksum (zdata, csize);
+
+ /* We're just about ready to go. Wait until there is room in the
+ receiver's window for us to send the packet. We do this now so
+ that we send the correct value for the last packet received.
+ Note that if iGsendseq == iGremote_ack, this means that the
+ sequence numbers are actually 8 apart, since the packet could not
+ have been acknowledged before it was sent; this can happen when
+ the window size is 7. */
+ while (iGsendseq == iGremote_ack
+ || CSEQDIFF (iGsendseq, iGremote_ack) > iGremote_winsize)
+ {
+ if (! fgwait_for_packet (qdaemon, TRUE, cGtimeout, cGretries))
+ return FALSE;
+ }
+
+ /* Ack all packets up to the next one, since the UUCP protocol
+ requires that all packets be acked in order. */
+ while (CSEQDIFF (iGrecseq, iGlocal_ack) > 1)
+ {
+ iGlocal_ack = INEXTSEQ (iGlocal_ack);
+ if (! fgsend_control (qdaemon, RR, iGlocal_ack))
+ return FALSE;
+ }
+ iGlocal_ack = iGrecseq;
+
+ z[IFRAME_CONTROL] = (char) ((itt << 6) | (iGsendseq << 3) | iGrecseq);
+
+ iGsendseq = INEXTSEQ (iGsendseq);
+
+ icheck = ((unsigned short)
+ ((0xaaaa - (icheck ^ (z[IFRAME_CONTROL] & 0xff))) & 0xffff));
+ z[IFRAME_CHECKLOW] = (char) (icheck & 0xff);
+ z[IFRAME_CHECKHIGH] = (char) (icheck >> 8);
+
+ z[IFRAME_XOR] = (char) (z[IFRAME_K] ^ z[IFRAME_CHECKLOW]
+ ^ z[IFRAME_CHECKHIGH] ^ z[IFRAME_CONTROL]);
+
+ /* If we're waiting for acks of retransmitted packets, then don't
+ send this packet yet. The other side may not be ready for it
+ yet. Instead, code in fggot_ack will send the outstanding
+ packets when an ack is received. */
+ ++cGsent_packets;
+
+ if (iGretransmit_seq != -1)
+ {
+ ++cGdelayed_packets;
+ return TRUE;
+ }
+
+ DEBUG_MESSAGE2 (DEBUG_PROTO,
+ "fgsenddata: Sending packet %d (%d bytes)",
+ CONTROL_XXX (z[IFRAME_CONTROL]), cdata);
+
+ return fsend_data (qdaemon->qconn, z, CFRAMELEN + csize, TRUE);
+}
+
+/* Recompute the control byte and checksum of a packet so that it
+ includes the correct packet acknowledgement. This is called when a
+ packet is retransmitted to make sure the retransmission does not
+ confuse the other side. It returns a pointer to the start of the
+ packet, skipping the bytes that may be unused at the start of
+ azGsendbuffers[iseq]. */
+
+static char *
+zgadjust_ack (iseq)
+ int iseq;
+{
+ register char *z;
+ unsigned short icheck;
+
+ z = azGsendbuffers[iseq];
+ if (*z == '\0')
+ ++z;
+ if (*z == '\0')
+ ++z;
+
+ /* If the received packet number is the same, there is nothing
+ to do. */
+ if (CONTROL_YYY (z[IFRAME_CONTROL]) == iGrecseq)
+ return z;
+
+ /* Get the old checksum. */
+ icheck = (unsigned short) (((z[IFRAME_CHECKHIGH] & 0xff) << 8)
+ | (z[IFRAME_CHECKLOW] & 0xff));
+ icheck = ((unsigned short)
+ (((0xaaaa - icheck) ^ (z[IFRAME_CONTROL] & 0xff)) & 0xffff));
+
+ /* Update the control byte. */
+ z[IFRAME_CONTROL] = (char) ((z[IFRAME_CONTROL] &~ 07) | iGrecseq);
+
+ /* Create the new checksum. */
+ icheck = ((unsigned short)
+ ((0xaaaa - (icheck ^ (z[IFRAME_CONTROL] & 0xff))) & 0xffff));
+ z[IFRAME_CHECKLOW] = (char) (icheck & 0xff);
+ z[IFRAME_CHECKHIGH] = (char) (icheck >> 8);
+
+ /* Update the XOR byte. */
+ z[IFRAME_XOR] = (char) (z[IFRAME_K] ^ z[IFRAME_CHECKLOW]
+ ^ z[IFRAME_CHECKHIGH] ^ z[IFRAME_CONTROL]);
+
+ return z;
+}
+
+/* Send a control packet. These are fairly simple to construct. It
+ seems reasonable to me that we should be able to send a control
+ packet at any time, even if the receive window is closed. In
+ particular, we don't want to delay when sending a CLOSE control
+ message. If I'm wrong, it can be changed easily enough. */
+
+static boolean
+fgsend_control (qdaemon, ixxx, iyyy)
+ struct sdaemon *qdaemon;
+ int ixxx;
+ int iyyy;
+{
+ char ab[CFRAMELEN];
+ int ictl;
+ unsigned short icheck;
+
+#if DEBUG > 1
+ if (FDEBUGGING (DEBUG_PROTO) ||
+ (FDEBUGGING (DEBUG_ABNORMAL) && ixxx != RR))
+ ulog (LOG_DEBUG, "fgsend_control: Sending control %s %d",
+ azGcontrol[ixxx], iyyy);
+#endif
+
+ ab[IFRAME_DLE] = DLE;
+ ab[IFRAME_K] = KCONTROL;
+
+ ictl = (CONTROL << 6) | (ixxx << 3) | iyyy;
+ icheck = (unsigned short) (0xaaaa - ictl);
+ ab[IFRAME_CHECKLOW] = (char) (icheck & 0xff);
+ ab[IFRAME_CHECKHIGH] = (char) (icheck >> 8);
+
+ ab[IFRAME_CONTROL] = (char) ictl;
+
+ ab[IFRAME_XOR] = (char) (ab[IFRAME_K] ^ ab[IFRAME_CHECKLOW]
+ ^ ab[IFRAME_CHECKHIGH] ^ ab[IFRAME_CONTROL]);
+
+ return fsend_data (qdaemon->qconn, ab, (size_t) CFRAMELEN, TRUE);
+}
+
+/* Wait for data to come in. This continues processing until a
+ complete file or command has been received. */
+
+boolean
+fgwait (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ return fgwait_for_packet (qdaemon, FALSE, cGtimeout, cGretries);
+}
+
+/* Get a packet. This is called when we have nothing to send, but
+ want to wait for a packet to come in. If freturncontrol is TRUE,
+ this will return after getting any control packet. Otherwise, it
+ will continue to receive packets until a complete file or a
+ complete command has been received. The timeout and the number of
+ retries are specified as arguments. The function returns FALSE if
+ an error occurs or if cretries timeouts of ctimeout seconds were
+ exceeded. */
+
+static boolean
+fgwait_for_packet (qdaemon, freturncontrol, ctimeout, cretries)
+ struct sdaemon *qdaemon;
+ boolean freturncontrol;
+ int ctimeout;
+ int cretries;
+{
+ int ctimeouts;
+ int cgarbage;
+ int cshort;
+
+ ctimeouts = 0;
+ cgarbage = 0;
+ cshort = 0;
+
+ while (TRUE)
+ {
+ boolean fexit;
+ size_t cneed;
+ boolean ffound;
+ size_t crec;
+
+ if (! fgprocess_data (qdaemon, TRUE, freturncontrol, &fexit,
+ &cneed, &ffound))
+ return FALSE;
+
+ if (fexit)
+ return TRUE;
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "fgwait_for_packet: Need %lu bytes",
+ (unsigned long) cneed);
+
+ if (ffound)
+ {
+ ctimeouts = 0;
+ cgarbage = 0;
+ }
+ else
+ {
+ if (cgarbage > cGgarbage_data)
+ {
+ ulog (LOG_ERROR, "Too much unrecognized data");
+ return FALSE;
+ }
+ }
+
+ if (! freceive_data (qdaemon->qconn, cneed, &crec, ctimeout, TRUE))
+ return FALSE;
+
+ cgarbage += crec;
+
+ if (crec != 0)
+ {
+ /* If we don't get enough data twice in a row, we may have
+ dropped some data and still be looking for the end of a
+ large packet. Incrementing iPrecstart will force
+ fgprocess_data to skip that packet and look through the
+ rest of the data. In some situations, this will be a
+ mistake. */
+ if (crec >= cneed)
+ cshort = 0;
+ else
+ {
+ ++cshort;
+ if (cshort > 1)
+ {
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
+ cshort = 0;
+ }
+ }
+ }
+ else
+ {
+ /* The read timed out. If we have an unacknowledged packet,
+ send it again. Otherwise, send an RJ with the last
+ packet we received correctly. */
+ ++ctimeouts;
+ if (ctimeouts > cretries)
+ {
+ if (cretries > 0)
+ ulog (LOG_ERROR, "Timed out waiting for packet");
+ return FALSE;
+ }
+
+ if (INEXTSEQ (iGremote_ack) != iGsendseq)
+ {
+ int inext;
+ char *zsend;
+
+ inext = INEXTSEQ (iGremote_ack);
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgwait_for_packet: Resending packet %d",
+ inext);
+
+ ++cGresent_packets;
+ zsend = zgadjust_ack (inext);
+ if (! fsend_data (qdaemon->qconn, zsend,
+ CFRAMELEN + CPACKLEN (zsend), TRUE))
+ return FALSE;
+ iGretransmit_seq = inext;
+ }
+ else
+ {
+ /* Send all pending acks first, to avoid confusing
+ the other side. */
+ if (iGlocal_ack != iGrecseq)
+ {
+ if (! fgsend_acks (qdaemon))
+ return FALSE;
+ }
+ if (! fgsend_control (qdaemon, RJ, iGrecseq))
+ return FALSE;
+ }
+ }
+ }
+}
+
+/* Send acks for all packets we haven't acked yet. */
+
+static boolean
+fgsend_acks (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ while (iGlocal_ack != iGrecseq)
+ {
+ iGlocal_ack = INEXTSEQ (iGlocal_ack);
+ if (! fgsend_control (qdaemon, RR, iGlocal_ack))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/* Handle an ack of a packet. According to Hanrahan's paper, this
+ acknowledges all previous packets. If this is an ack for a
+ retransmitted packet, continue by resending up to two more packets
+ following the retransmitted one. This should recover quickly from
+ a line glitch, while avoiding the problem of continual
+ retransmission. */
+
+static boolean
+fggot_ack (qdaemon, iack)
+ struct sdaemon *qdaemon;
+ int iack;
+{
+ int inext;
+ char *zsend;
+
+ /* We only decrement the error level if we are not retransmitting
+ packets. We want to catch a sudden downgrade in line quality as
+ fast as possible. */
+ if (cGerror_level > 0
+ && iGretransmit_seq == -1
+ && cGsent_packets % cGerror_decay == 0)
+ --cGerror_level;
+ cGexpect_bad_order = 0;
+
+ /* Each time packet 0 is acknowledged, we call uwindow_acked since a
+ new window has been acked. */
+ if (iack < iGremote_ack)
+ uwindow_acked (qdaemon, FALSE);
+
+ iGremote_ack = iack;
+
+ if (iGretransmit_seq == -1)
+ return TRUE;
+
+ inext = INEXTSEQ (iGretransmit_seq);
+ if (inext == iGsendseq)
+ iGretransmit_seq = -1;
+ else
+ {
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "fggot_ack: Sending packet %d", inext);
+
+ ++cGresent_packets;
+ zsend = zgadjust_ack (inext);
+ if (! fsend_data (qdaemon->qconn, zsend, CFRAMELEN + CPACKLEN (zsend),
+ TRUE))
+ return FALSE;
+ inext = INEXTSEQ (inext);
+ if (inext == iGsendseq)
+ iGretransmit_seq = -1;
+ else
+ {
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "fggot_ack: Sending packet %d", inext);
+
+ ++cGresent_packets;
+ zsend = zgadjust_ack (inext);
+ if (! fsend_data (qdaemon->qconn, zsend,
+ CFRAMELEN + CPACKLEN (zsend), TRUE))
+ return FALSE;
+ iGretransmit_seq = inext;
+ }
+ }
+
+ return TRUE;
+}
+
+/* See if we've received more than the permitted number of errors. If
+ we receive a bad packet, we can expect a window full (less one) of
+ out of order packets to follow, so we discount cGbad_order
+ accordingly. */
+
+static boolean
+fgcheck_errors (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ if (cGerror_level > cGmax_errors && cGmax_errors >= 0)
+ {
+ ulog (LOG_ERROR, "Too many '%c' protocol errors",
+ qdaemon->qproto->bname);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Process the receive buffer into a data packet, if possible. All
+ control packets are handled here. When a data packet is received,
+ fgprocess_data calls fgot_data with the data; if that sets its
+ pfexit argument to TRUE fgprocess_data will set *pfexit to TRUE and
+ return TRUE. Also, if the freturncontrol argument is TRUE
+ fgprocess_data will set *pfexit to TRUE and return TRUE. Otherwise
+ fgprocess_data will continue trying to process data. If some error
+ occurs, fgprocess_data will return FALSE. If there is not enough
+ data to form a complete packet, then *pfexit will be set to FALSE,
+ *pcneed will be set to the number of bytes needed to form a
+ complete packet (unless pcneed is NULL) and fgprocess_data will
+ return TRUE. If this function found a data packet, and pffound is
+ not NULL, it will set *pffound to TRUE; this can be used to tell
+ valid data from an endless stream of garbage and control packets.
+ If fdoacks is TRUE, received packets will be acknowledged;
+ otherwise they must be acknowledged later. */
+
+static boolean
+fgprocess_data (qdaemon, fdoacks, freturncontrol, pfexit, pcneed, pffound)
+ struct sdaemon *qdaemon;
+ boolean fdoacks;
+ boolean freturncontrol;
+ boolean *pfexit;
+ size_t *pcneed;
+ boolean *pffound;
+{
+ *pfexit = FALSE;
+ if (pffound != NULL)
+ *pffound = FALSE;
+
+ while (iPrecstart != iPrecend)
+ {
+ char ab[CFRAMELEN];
+ int i, iget, cwant;
+ unsigned short ihdrcheck, idatcheck;
+ const char *zfirst, *zsecond;
+ int cfirst, csecond;
+ boolean fduprr;
+
+ /* Look for the DLE which must start a packet. */
+ if (abPrecbuf[iPrecstart] != DLE)
+ {
+ char *zdle;
+
+ cfirst = iPrecend - iPrecstart;
+ if (cfirst < 0)
+ cfirst = CRECBUFLEN - iPrecstart;
+
+ zdle = memchr (abPrecbuf + iPrecstart, DLE, (size_t) cfirst);
+
+ if (zdle == NULL)
+ {
+ iPrecstart = (iPrecstart + cfirst) % CRECBUFLEN;
+ continue;
+ }
+
+ /* We don't need % CRECBUFLEN here because zdle - (abPrecbuf
+ + iPrecstart) < cfirst <= CRECBUFLEN - iPrecstart. */
+ iPrecstart += zdle - (abPrecbuf + iPrecstart);
+ }
+
+ /* Get the first six bytes into ab. */
+ for (i = 0, iget = iPrecstart;
+ i < CFRAMELEN && iget != iPrecend;
+ i++, iget = (iget + 1) % CRECBUFLEN)
+ ab[i] = abPrecbuf[iget];
+
+ /* If there aren't six bytes, there is no packet. */
+ if (i < CFRAMELEN)
+ {
+ if (pcneed != NULL)
+ *pcneed = CFRAMELEN - i;
+ return TRUE;
+ }
+
+ /* Make sure these six bytes start a packet. The check on
+ IFRAME_DLE is basically a debugging check, since the above
+ code should have ensured that it will never fail. If this is
+ not the start of a packet, bump iPrecstart and loop around to
+ look for another DLE. */
+ if (ab[IFRAME_DLE] != DLE
+ || ab[IFRAME_K] < 1
+ || ab[IFRAME_K] > 9
+ || ab[IFRAME_XOR] != (ab[IFRAME_K] ^ ab[IFRAME_CHECKLOW]
+ ^ ab[IFRAME_CHECKHIGH] ^ ab[IFRAME_CONTROL])
+ || CONTROL_TT (ab[IFRAME_CONTROL]) == ALTCHAN)
+ {
+ ++cGbad_hdr;
+ ++cGerror_level;
+
+ DEBUG_MESSAGE4 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgprocess_data: Bad header: K %d TT %d XOR byte %d calc %d",
+ ab[IFRAME_K] & 0xff,
+ CONTROL_TT (ab[IFRAME_CONTROL]),
+ ab[IFRAME_XOR] & 0xff,
+ (ab[IFRAME_K]
+ ^ ab[IFRAME_CHECKLOW]
+ ^ ab[IFRAME_CHECKHIGH]
+ ^ ab[IFRAME_CONTROL]) & 0xff);
+
+ if (! fgcheck_errors (qdaemon))
+ return FALSE;
+
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
+ continue;
+ }
+
+ /* The zfirst and cfirst pair point to the first set of data for
+ this packet; the zsecond and csecond point to the second set,
+ in case the packet wraps around the end of the buffer. */
+ zfirst = abPrecbuf + iPrecstart + CFRAMELEN;
+ cfirst = 0;
+ zsecond = NULL;
+ csecond = 0;
+
+ if (ab[IFRAME_K] == KCONTROL)
+ {
+ /* This is a control packet. It should not have any data. */
+ if (CONTROL_TT (ab[IFRAME_CONTROL]) != CONTROL)
+ {
+ ++cGbad_hdr;
+ ++cGerror_level;
+
+ DEBUG_MESSAGE0 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgprocess_data: Bad header: control packet with data");
+
+ if (! fgcheck_errors (qdaemon))
+ return FALSE;
+
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
+ continue;
+ }
+
+ idatcheck = (unsigned short) (0xaaaa - ab[IFRAME_CONTROL]);
+ cwant = 0;
+ }
+ else
+ {
+ int cinbuf;
+ unsigned short icheck;
+
+ /* This is a data packet. It should not be type CONTROL. */
+ if (CONTROL_TT (ab[IFRAME_CONTROL]) == CONTROL)
+ {
+ ++cGbad_hdr;
+ ++cGerror_level;
+
+ DEBUG_MESSAGE0 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgprocess_data: Bad header: data packet is type CONTROL");
+
+ if (! fgcheck_errors (qdaemon))
+ return FALSE;
+
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
+ continue;
+ }
+
+ cinbuf = iPrecend - iPrecstart;
+ if (cinbuf < 0)
+ cinbuf += CRECBUFLEN;
+ cinbuf -= CFRAMELEN;
+
+ /* Make sure we have enough data. If we don't, wait for
+ more. */
+
+ cwant = (int) CPACKLEN (ab);
+ if (cinbuf < cwant)
+ {
+ if (pcneed != NULL)
+ *pcneed = cwant - cinbuf;
+ return TRUE;
+ }
+
+ /* Set up the data pointers and compute the checksum. */
+ if (iPrecend >= iPrecstart)
+ cfirst = cwant;
+ else
+ {
+ cfirst = CRECBUFLEN - (iPrecstart + CFRAMELEN);
+ if (cfirst >= cwant)
+ cfirst = cwant;
+ else if (cfirst > 0)
+ {
+ zsecond = abPrecbuf;
+ csecond = cwant - cfirst;
+ }
+ else
+ {
+ /* Here cfirst is non-positive, so subtracting from
+ abPrecbuf will actually skip the appropriate number
+ of bytes at the start of abPrecbuf. */
+ zfirst = abPrecbuf - cfirst;
+ cfirst = cwant;
+ }
+ }
+
+ if (csecond == 0)
+ icheck = (unsigned short) igchecksum (zfirst, (size_t) cfirst);
+ else
+ icheck = (unsigned short) igchecksum2 (zfirst, (size_t) cfirst,
+ zsecond,
+ (size_t) csecond);
+
+ idatcheck = ((unsigned short)
+ (((0xaaaa - (icheck ^ (ab[IFRAME_CONTROL] & 0xff)))
+ & 0xffff)));
+ }
+
+ ihdrcheck = (unsigned short) (((ab[IFRAME_CHECKHIGH] & 0xff) << 8)
+ | (ab[IFRAME_CHECKLOW] & 0xff));
+
+ if (ihdrcheck != idatcheck)
+ {
+ DEBUG_MESSAGE2 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgprocess_data: Bad checksum: header 0x%x, data 0x%x",
+ ihdrcheck, idatcheck);
+
+ ++cGbad_checksum;
+ ++cGerror_level;
+
+ if (! fgcheck_errors (qdaemon))
+ return FALSE;
+
+ /* If the checksum failed for a data packet, then if it was
+ the one we were expecting send an RJ, otherwise ignore
+ it. Previously if this code got the wrong packet number
+ it would send an RR, but that may confuse some Telebit
+ modems and it doesn't help in any case since the receiver
+ will probably just ignore the RR as a duplicate (that's
+ basically what this code does). If we totally missed the
+ packet we will time out and send an RJ in the function
+ fgwait_for_packet above. */
+ if (CONTROL_TT (ab[IFRAME_CONTROL]) != CONTROL)
+ {
+ /* Make sure we've acked everything up to this point. */
+ if (iGrecseq != iGlocal_ack)
+ {
+ if (! fgsend_acks (qdaemon))
+ return FALSE;
+ }
+
+ /* If this is the packet we wanted, tell the sender that
+ it failed. */
+ if (CONTROL_XXX (ab[IFRAME_CONTROL]) == INEXTSEQ (iGrecseq))
+ {
+ if (! fgsend_control (qdaemon, RJ, iGrecseq))
+ return FALSE;
+ cGexpect_bad_order += iGrequest_winsize - 1;
+ }
+ }
+
+ /* We can't skip the packet data after this, because if we
+ have lost incoming bytes the next DLE will be somewhere
+ in what we thought was the packet data. */
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
+ continue;
+ }
+
+ /* We have a packet; remove the processed bytes from the receive
+ buffer. */
+ iPrecstart = (iPrecstart + cwant + CFRAMELEN) % CRECBUFLEN;
+
+ /* Store the control byte for the handshake routines. */
+ iGpacket_control = ab[IFRAME_CONTROL] & 0xff;
+
+ /* Annoyingly, some UUCP packages appear to send an RR packet
+ rather than an RJ packet when they want a packet to be
+ resent. If we get a duplicate RR, we treat it as an RJ. */
+ fduprr = FALSE;
+ if (CONTROL_TT (ab[IFRAME_CONTROL]) == CONTROL
+ && CONTROL_XXX (ab[IFRAME_CONTROL]) == RR
+ && iGremote_ack == CONTROL_YYY (ab[IFRAME_CONTROL])
+ && INEXTSEQ (iGremote_ack) != iGsendseq)
+ {
+ DEBUG_MESSAGE0 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgprocess_data: Treating duplicate RR as RJ");
+ fduprr = TRUE;
+ }
+
+ /* Update the received sequence number from the yyy field of a
+ data packet or an RR control packet. If we've been delaying
+ sending packets until we received an ack, this may send out
+ some packets. */
+ if (CONTROL_TT (ab[IFRAME_CONTROL]) != CONTROL
+ || CONTROL_XXX (ab[IFRAME_CONTROL]) == RR)
+ {
+ if (! fggot_ack (qdaemon, CONTROL_YYY (ab[IFRAME_CONTROL])))
+ return FALSE;
+ }
+
+ /* If this isn't a control message, make sure we have received
+ the expected packet sequence number, acknowledge the packet
+ if it's the right one, and process the data. */
+ if (CONTROL_TT (ab[IFRAME_CONTROL]) != CONTROL)
+ {
+ if (CONTROL_XXX (ab[IFRAME_CONTROL]) != INEXTSEQ (iGrecseq))
+ {
+ /* We got the wrong packet number. */
+ DEBUG_MESSAGE2 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgprocess_data: Got packet %d; expected %d",
+ CONTROL_XXX (ab[IFRAME_CONTROL]),
+ INEXTSEQ (iGrecseq));
+
+ if (cGexpect_bad_order > 0)
+ --cGexpect_bad_order;
+ else
+ {
+ ++cGbad_order;
+ ++cGerror_level;
+ if (! fgcheck_errors (qdaemon))
+ return FALSE;
+ }
+
+ /* This code used to send an RR to encourage the other
+ side to get back in synch, but that may confuse some
+ Telebit modems and does little good in any case,
+ since the other side will probably just ignore it
+ anyhow (that's what this code does). */
+ continue;
+ }
+
+ /* We got the packet we expected. */
+ ++cGrec_packets;
+ if (cGerror_level > 0
+ && cGrec_packets % cGerror_decay == 0)
+ --cGerror_level;
+ cGexpect_bad_order = 0;
+
+ iGrecseq = INEXTSEQ (iGrecseq);
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "fgprocess_data: Got packet %d", iGrecseq);
+
+ /* Tell the caller that we found something. */
+ if (pffound != NULL)
+ *pffound = TRUE;
+
+ /* If we are supposed to do acknowledgements here, send back
+ an RR packet. */
+ if (fdoacks)
+ {
+ if (! fgsend_acks (qdaemon))
+ return FALSE;
+ }
+
+ /* If this is a short data packet, adjust the data pointers
+ and lengths. */
+ if (CONTROL_TT (ab[IFRAME_CONTROL]) == SHORTDATA)
+ {
+ int cshort, cmove;
+
+ if ((zfirst[0] & 0x80) == 0)
+ {
+ cshort = zfirst[0] & 0xff;
+ cmove = 1;
+ }
+ else
+ {
+ int cbyte2;
+
+ if (cfirst > 1)
+ cbyte2 = zfirst[1] & 0xff;
+ else
+ cbyte2 = zsecond[0] & 0xff;
+ cshort = (zfirst[0] & 0x7f) + (cbyte2 << 7);
+ cmove = 2;
+ }
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "fgprocess_data: Packet short by %d",
+ cshort);
+
+ /* Adjust the start of the buffer for the bytes used
+ by the count. */
+ if (cfirst > cmove)
+ {
+ zfirst += cmove;
+ cfirst -= cmove;
+ }
+ else
+ {
+ zfirst = zsecond + (cmove - cfirst);
+ cfirst = csecond - (cmove - cfirst);
+ csecond = 0;
+ }
+
+ /* Adjust the length of the buffer for the bytes we are
+ not supposed to consider. */
+ cshort -= cmove;
+ if (csecond >= cshort)
+ csecond -= cshort;
+ else
+ {
+ cfirst -= cshort - csecond;
+ csecond = 0;
+ }
+
+#if DEBUG > 0
+ /* This should not happen, but just in case. */
+ if (cfirst < 0)
+ cfirst = 0;
+#endif
+ }
+
+ if (! fgot_data (qdaemon, zfirst, (size_t) cfirst,
+ zsecond, (size_t) csecond,
+ -1, -1, (long) -1,
+ INEXTSEQ (iGremote_ack) == iGsendseq,
+ pfexit))
+ return FALSE;
+
+ /* If fgot_data told us that we were finished, get out. */
+ if (*pfexit)
+ return TRUE;
+
+ /* If we've been asked to return control packets, get out
+ now. */
+ if (freturncontrol)
+ {
+ *pfexit = TRUE;
+ return TRUE;
+ }
+
+ continue;
+ }
+
+ /* Handle control messages here. */
+#if DEBUG > 1
+ if (FDEBUGGING (DEBUG_PROTO)
+ || (FDEBUGGING (DEBUG_ABNORMAL)
+ && CONTROL_XXX (ab[IFRAME_CONTROL]) != RR))
+ ulog (LOG_DEBUG, "fgprocess_data: Got control %s %d",
+ azGcontrol[CONTROL_XXX (ab[IFRAME_CONTROL])],
+ CONTROL_YYY (ab[IFRAME_CONTROL]));
+#endif
+
+ switch (CONTROL_XXX (ab[IFRAME_CONTROL]))
+ {
+ case CLOSE:
+ /* The other side has closed the connection. */
+ if (fLog_sighup)
+ {
+ ulog (LOG_ERROR, "Received unexpected CLOSE packet");
+ (void) fgsend_control (qdaemon, CLOSE, 0);
+ }
+ return FALSE;
+ case RR:
+ /* Acknowledge receipt of a packet. This was already handled
+ above, unless we are treating it as RJ. */
+ if (! fduprr)
+ break;
+ /* Fall through. */
+ case RJ:
+ /* The other side dropped a packet. Begin retransmission with
+ the packet following the one acknowledged. We don't
+ retransmit the packets immediately, but instead wait
+ for the first one to be acked. This prevents us from
+ sending an entire window several times if we get several
+ RJ packets. */
+ iGremote_ack = CONTROL_YYY (ab[IFRAME_CONTROL]);
+ iGretransmit_seq = INEXTSEQ (iGremote_ack);
+ if (iGretransmit_seq == iGsendseq)
+ iGretransmit_seq = -1;
+ else
+ {
+ char *zpack;
+
+ DEBUG_MESSAGE2 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgprocess_data: Remote reject: next %d resending %d",
+ iGsendseq, iGretransmit_seq);
+
+ ++cGresent_packets;
+ ++cGremote_rejects;
+ ++cGerror_level;
+ if (! fgcheck_errors (qdaemon))
+ return FALSE;
+ zpack = zgadjust_ack (iGretransmit_seq);
+ if (! fsend_data (qdaemon->qconn, zpack,
+ CFRAMELEN + CPACKLEN (zpack),
+ TRUE))
+ return FALSE;
+ }
+ break;
+ case SRJ:
+ /* Selectively reject a particular packet. This is not used
+ by UUCP, but it's easy to support. */
+ DEBUG_MESSAGE1 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fgprocess_data: Selective reject of %d",
+ CONTROL_YYY (ab[IFRAME_CONTROL]));
+ {
+ char *zpack;
+
+ ++cGresent_packets;
+ ++cGremote_rejects;
+ ++cGerror_level;
+ zpack = zgadjust_ack (CONTROL_YYY (ab[IFRAME_CONTROL]));
+ if (! fsend_data (qdaemon->qconn, zpack,
+ CFRAMELEN + CPACKLEN (zpack),
+ TRUE))
+ return FALSE;
+ }
+ break;
+ case INITC:
+ case INITB:
+ case INITA:
+ /* Ignore attempts to reinitialize. */
+ break;
+ }
+
+ /* If we've been asked to return control packets, get out. */
+ if (freturncontrol)
+ {
+ *pfexit = TRUE;
+ return TRUE;
+ }
+
+ /* Loop around to look for the next packet, if any. */
+ }
+
+ /* There is no data left in the receive buffer. */
+ if (pcneed != NULL)
+ *pcneed = CFRAMELEN;
+ return TRUE;
+}
+
+/* Compute the 'g' protocol checksum. This is unfortunately rather
+ awkward. This is the most time consuming code in the entire
+ program. It's also not a great checksum, since it can be fooled
+ by some single bit errors. */
+
+/* Sorry about this knavery, but it speeds up the VAX code
+ significantly. It would be better to rewrite the whole routine in
+ assembler. */
+#ifdef __GNUC__
+#ifdef __vax__
+#define VAX_ASM 1
+#endif
+#endif
+
+#if VAX_ASM
+#define ROTATE(i) \
+ asm ("cvtwl %1,%0\n\trotl $1,%0,%0" : "=g" (i) : "g" (i))
+#else
+#define ROTATE(i) i += i + ((i & 0x8000) >> 15)
+#endif
+
+#define ITERATION \
+ /* Rotate ichk1 left. */ \
+ ROTATE (ichk1); \
+ \
+ /* The guts of the checksum. */ \
+ b = BUCHAR (*z++); \
+ if (b != 0) \
+ { \
+ ichk1 &= 0xffff; \
+ ichk1 += b; \
+ ichk2 += ichk1 ^ c; \
+ if ((ichk1 >> 16) != 0) \
+ ichk1 ^= ichk2; \
+ } \
+ else \
+ { \
+ ichk2 += ichk1 ^ c; \
+ ichk1 ^= ichk2; \
+ } \
+ \
+ --c
+
+static int
+igchecksum (z, c)
+ register const char *z;
+ register size_t c;
+{
+ register unsigned long ichk1, ichk2;
+
+ ichk1 = 0xffff;
+ ichk2 = 0;
+
+ do
+ {
+ register unsigned int b;
+
+ ITERATION;
+ ITERATION;
+ ITERATION;
+ ITERATION;
+ }
+ while (c > 0);
+
+ return ichk1 & 0xffff;
+}
+
+/* We use a separate function compute the checksum if the block is
+ split around the end of the receive buffer since it occurs much
+ less frequently and the checksum is already high up in the
+ profiles. These functions are almost identical, and this one
+ actually only has a few more instructions in the inner loop. */
+
+static int
+igchecksum2 (zfirst, cfirst, zsecond, csecond)
+ const char *zfirst;
+ size_t cfirst;
+ const char *zsecond;
+ size_t csecond;
+{
+ register unsigned long ichk1, ichk2;
+ register const char *z;
+ register size_t c;
+
+ z = zfirst;
+ c = cfirst + csecond;
+
+ ichk1 = 0xffff;
+ ichk2 = 0;
+
+ do
+ {
+ register unsigned int b;
+
+ ITERATION;
+
+ /* If the first buffer has been finished, switch to the second. */
+ --cfirst;
+ if (cfirst == 0)
+ z = zsecond;
+ }
+ while (c > 0);
+
+ return ichk1 & 0xffff;
+}
diff --git a/gnu/libexec/uucp/uucico/proti.c b/gnu/libexec/uucp/uucico/proti.c
new file mode 100644
index 00000000000..606b2bd94f3
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/proti.c
@@ -0,0 +1,1563 @@
+/* proti.c
+ The 'i' protocol.
+
+ Copyright (C) 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char proti_rcsid[] = "$Id: proti.c,v 1.1 1993/08/04 19:36:22 jtc Exp $";
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "conn.h"
+#include "trans.h"
+#include "system.h"
+#include "prot.h"
+
+/* The 'i' protocol is a simple sliding window protocol, created by
+ me. It is in many ways similar to the 'g' protocol. Several ideas
+ are also taken from the paper ``A High-Throughput Message Transport
+ System'' by P. Lauder. I don't know where the paper was published,
+ but the author's e-mail address is piers@cs.su.oz.au. However, I
+ haven't adopted his main idea, which is to dispense with windows
+ entirely. This is because some links still do require flow control
+ and, more importantly, because I want to have a limit to the amount
+ of data I must be able to resend upon request. To reduce the costs
+ of window acknowledgements, I use a large window and only require
+ an ack at the halfway point.
+
+ Each packet starts with a header containing the following
+ information:
+
+ Intro byte 8 bits byte 1
+ Packet number 5 bits byte 2
+ Local channel 3 bits
+ Packet ack 5 bits byte 3
+ Remote channel 3 bits
+ Packet type 3 bits bytes 4-5
+ Direction 1 bit
+ Data length 12 bits
+ Header check 8 bits byte 6
+
+ If the data length is not 0, this is followed by the data and a 32
+ bit CRC checksum.
+
+ The following packet types are defined:
+
+ SYNC Initialize the connection
+ DATA Data packet
+ ACK Simple acknowledgement with no data
+ NAK Negative acknowledgement; requests resend of single packet
+ SPOS Set file position
+ CLOSE Close the connection
+ */
+
+/* The offsets of the bytes in the packet header. */
+
+#define IHDR_INTRO (0)
+#define IHDR_LOCAL (1)
+#define IHDR_REMOTE (2)
+#define IHDR_CONTENTS1 (3)
+#define IHDR_CONTENTS2 (4)
+#define IHDR_CHECK (5)
+
+/* Macros to set and extract values of IHDR_LOCAL and IHDR_REMOTE. */
+#define IHDRWIN_SET(iseq, ichan) (((iseq) << 3) | (ichan))
+#define IHDRWIN_GETSEQ(ival) (((ival) >> 3) & 0x1f)
+#define IHDRWIN_GETCHAN(ival) ((ival) & 0x07)
+
+/* Macros to set and extract values of IHDR_CONTENTS fields. */
+#define IHDRCON_SET1(ttype, fcaller, cbytes) \
+ (((ttype) << 5) | ((fcaller) ? (1 << 4) : 0) | (((cbytes) >> 8) & 0x0f))
+#define IHDRCON_SET2(ttype, fcaller, cbytes) ((cbytes) & 0xff)
+#define THDRCON_GETTYPE(i1, i2) (((i1) >> 5) & 0x07)
+#define FHDRCON_GETCALLER(i1, i2) (((i1) & (1 << 4)) != 0)
+#define CHDRCON_GETBYTES(i1, i2) ((((i1) & 0x0f) << 8) | ((i2) & 0xff))
+
+/* Macros for the IHDR_CHECK field. */
+#define IHDRCHECK_VAL(zhdr) \
+ ((zhdr[IHDR_LOCAL] \
+ ^ zhdr[IHDR_REMOTE] \
+ ^ zhdr[IHDR_CONTENTS1] \
+ ^ zhdr[IHDR_CONTENTS2]) \
+ & 0xff)
+
+/* Length of the packet header. */
+#define CHDRLEN (6)
+
+/* Amount of space to skip between start of packet and actual data.
+ This is used to make the actual data longword aligned, to encourage
+ good performance when copying data into the buffer. */
+#define CHDRSKIPLEN (CHDRLEN + (sizeof (long) - CHDRLEN % sizeof (long)))
+
+/* Amount of space to skip between memory buffer and header. */
+#define CHDROFFSET (CHDRSKIPLEN - CHDRLEN)
+
+/* Length of the trailing checksum. */
+#define CCKSUMLEN (4)
+
+/* Macros to set and get the checksum. These multiply evaluate their
+ arguments. */
+#define ICKSUM_GET(z) \
+ ((((((((unsigned long) ((z)[0] & 0xff)) << 8) \
+ | (unsigned long) ((z)[1] & 0xff)) << 8) \
+ | (unsigned long) ((z)[2] & 0xff)) << 8) \
+ | (unsigned long) ((z)[3] & 0xff))
+#define UCKSUM_SET(z, i) \
+ (void) ((z)[0] = (((i) >> 24) & 0xff), \
+ (z)[1] = (((i) >> 16) & 0xff), \
+ (z)[2] = (((i) >> 8) & 0xff), \
+ (z)[3] = ((i) & 0xff))
+
+/* The header introduction character. */
+#define IINTRO ('\007')
+
+/* The packet types. */
+
+#define DATA (0)
+#define SYNC (1)
+#define ACK (2)
+#define NAK (3)
+#define SPOS (4)
+#define CLOSE (5)
+
+/* Largest possible packet size (plus 1). */
+#define IMAXPACKSIZE (1 << 12)
+
+/* Largest possible sequence number (plus 1). */
+#define IMAXSEQ 32
+
+/* Get the next sequence number given a sequence number. */
+#define INEXTSEQ(i) ((i + 1) & (IMAXSEQ - 1))
+
+/* Compute i1 - i2 in sequence space (i.e., the number of packets from
+ i2 to i1). */
+#define CSEQDIFF(i1, i2) (((i1) + IMAXSEQ - (i2)) & (IMAXSEQ - 1))
+
+/* Largest possible channel number (plus 1). */
+#define IMAXICHAN (8)
+
+/* Default packet size to request (protocol parameter
+ ``packet-size''). */
+#define IREQUEST_PACKSIZE (1024)
+
+/* Default window size to request (protocol parameter ``window''). */
+#define IREQUEST_WINSIZE (16)
+
+/* Default timeout to use when sending the SYNC packet (protocol
+ parameter ``sync-timeout''). */
+#define CSYNC_TIMEOUT (10)
+
+/* Default number of times to retry sending the SYNC packet (protocol
+ parameter ``sync-retries''). */
+#define CSYNC_RETRIES (6)
+
+/* Default timeout to use when waiting for a packet (protocol
+ parameter ``timeout''). */
+#define CTIMEOUT (10)
+
+/* Default number of times to retry sending a packet before giving up
+ (protocol parameter ``retries''). */
+#define CRETRIES (6)
+
+/* Default maximum level of errors to accept before giving up
+ (protocol parameter ``errors''). */
+#define CERRORS (100)
+
+/* Default decay rate. Each time we receive this many packets
+ succesfully, we decrement the error level by one (protocol
+ parameter ``error-decay''). */
+#define CERROR_DECAY (10)
+
+/* The default list of characters to avoid: XON and XOFF. This string
+ is processed as an escape sequence. This is 'j' protocol parameter
+ ``avoid''; it is defined in this file because the 'i' and 'j'
+ protocols share protocol parameters. */
+#define ZAVOID "\\021\\023"
+
+/* Local variables. */
+
+/* Packet size to request (protocol parameter ``packet-size''). */
+static int iIrequest_packsize = IREQUEST_PACKSIZE;
+
+/* Window size to request (protocol parameter ``window''). */
+static int iIrequest_winsize = IREQUEST_WINSIZE;
+
+/* Remote packet size (set from SYNC packet or from
+ iIforced_remote_packsize). */
+static int iIremote_packsize;
+
+/* Size which buffers were allocated for. */
+static int iIalc_packsize;
+
+/* Forced remote packet size, used if non-zero (protocol parameter
+ ``remote-packet-size''). */
+static int iIforced_remote_packsize = 0;
+
+/* Remote window size (set from SYNC packet or from
+ iIforced_remote_winsize). */
+static int iIremote_winsize;
+
+/* Forced remote window size, used if non-zero (protocol parameter
+ ``remote-window''). */
+static int iIforced_remote_winsize = 0;
+
+/* Timeout to use when sending the SYNC packet (protocol
+ parameter ``sync-timeout''). */
+int cIsync_timeout = CSYNC_TIMEOUT;
+
+/* Number of times to retry sending the SYNC packet (protocol
+ parameter ``sync-retries''). */
+static int cIsync_retries = CSYNC_RETRIES;
+
+/* Timeout to use when waiting for a packet (protocol parameter
+ ``timeout''). */
+static int cItimeout = CTIMEOUT;
+
+/* Number of times to retry sending a packet before giving up
+ (protocol parameter ``retries''). */
+static int cIretries = CRETRIES;
+
+/* Maximum level of errors to accept before giving up (protocol
+ parameter ``errors''). */
+static int cIerrors = CERRORS;
+
+/* Each time we receive this many packets succesfully, we decrement
+ the error level by one (protocol parameter ``error-decay''). */
+static int cIerror_decay = CERROR_DECAY;
+
+/* The set of characters to avoid (protocol parameter ``avoid'').
+ This is actually part of the 'j' protocol; it is defined in this
+ file because the 'i' and 'j' protocols use the same protocol
+ parameters. */
+const char *zJavoid_parameter = ZAVOID;
+
+/* Routine to use when sending data. This is a hook for the 'j'
+ protocol. */
+static boolean (*pfIsend) P((struct sconnection *qconn, const char *zsend,
+ size_t csend, boolean fdoread));
+
+/* Routine to use to use when reading data. This is a hook for the
+ 'j' protocol. */
+static boolean (*pfIreceive) P((struct sconnection *qconn, size_t cneed,
+ size_t *pcrec, int ctimeout,
+ boolean freport));
+
+/* Next sequence number to send. */
+static int iIsendseq;
+
+/* Last sequence number received. */
+static int iIrecseq;
+
+/* Last sequence number we have acknowledged. */
+static int iIlocal_ack;
+
+/* Last sequence number remote system has acknowledged. */
+static int iIremote_ack;
+
+/* File position we are sending from. */
+static long iIsendpos;
+
+/* File position we are receiving to. */
+static long iIrecpos;
+
+/* TRUE if closing the connection. */
+static boolean fIclosing;
+
+/* Array of sent packets indexed by packet number. */
+static char *azIsendbuffers[IMAXSEQ];
+
+/* Array of received packets that we aren't ready to process yet,
+ indexed by packet number. */
+static char *azIrecbuffers[IMAXSEQ];
+
+/* For each packet sequence number, record whether we sent a NAK for
+ the packet. */
+static boolean afInaked[IMAXSEQ];
+
+/* Number of SYNC packets received (used only to detect whether one
+ was received). */
+static int cIsyncs;
+
+/* Number of packets sent. */
+static long cIsent_packets;
+
+/* Number of packets received. */
+static long cIreceived_packets;
+
+/* Number of packets resent. */
+static long cIresent_packets;
+
+/* Number of bad packet headers received. */
+static long cIbad_hdr;
+
+/* Number of out of order packets received. */
+static long cIbad_order;
+
+/* Number of bad checksums received. */
+static long cIbad_cksum;
+
+/* Number of packets rejected by remote system. */
+static long cIremote_rejects;
+
+/* Protocol parameter commands. */
+
+struct uuconf_cmdtab asIproto_params[] =
+{
+ { "packet-size", UUCONF_CMDTABTYPE_INT, (pointer) &iIrequest_packsize,
+ NULL },
+ { "window", UUCONF_CMDTABTYPE_INT, (pointer) &iIrequest_winsize, NULL },
+ { "remote-packet-size", UUCONF_CMDTABTYPE_INT,
+ (pointer) &iIforced_remote_packsize, NULL },
+ { "remote-window", UUCONF_CMDTABTYPE_INT,
+ (pointer) &iIforced_remote_winsize, NULL },
+ { "sync-timeout", UUCONF_CMDTABTYPE_INT, (pointer) &cIsync_timeout,
+ NULL },
+ { "sync-retries", UUCONF_CMDTABTYPE_INT, (pointer) &cIsync_retries,
+ NULL },
+ { "timeout", UUCONF_CMDTABTYPE_INT, (pointer) &cItimeout, NULL },
+ { "retries", UUCONF_CMDTABTYPE_INT, (pointer) &cIretries, NULL },
+ { "errors", UUCONF_CMDTABTYPE_INT, (pointer) &cIerrors, NULL },
+ { "error-decay", UUCONF_CMDTABTYPE_INT, (pointer) &cIerror_decay, NULL },
+ /* The ``avoid'' protocol parameter is part of the 'j' protocol, but
+ it is convenient for the 'i' and 'j' protocols to share the same
+ protocol parameter table. */
+ { "avoid", UUCONF_CMDTABTYPE_STRING, (pointer) &zJavoid_parameter, NULL },
+ { NULL, 0, NULL, NULL }
+};
+
+/* Local functions. */
+
+static boolean finak P((struct sdaemon *qdaemon, int iseq));
+static boolean firesend P((struct sdaemon *qdaemon));
+static boolean fiwindow_wait P((struct sdaemon *qdaemon));
+static boolean fiwait_for_packet P((struct sdaemon *qdaemon,
+ int ctimeout, int cretries,
+ boolean fone, boolean *ftimedout));
+static boolean ficheck_errors P((struct sdaemon *qdaemon));
+static boolean fiprocess_data P((struct sdaemon *qdaemon,
+ boolean *pfexit, boolean *pffound,
+ size_t *pcneed));
+static boolean fiprocess_packet P((struct sdaemon *qdaemon,
+ const char *zhdr,
+ const char *zfirst, int cfirst,
+ const char *zsecond, int csecond,
+ boolean *pfexit));
+
+/* The 'i' protocol start routine. The work is done in a routine
+ which is also called by the 'j' protocol start routine. */
+
+boolean
+fistart (qdaemon, pzlog)
+ struct sdaemon *qdaemon;
+ char **pzlog;
+{
+ return fijstart (qdaemon, pzlog, IMAXPACKSIZE, fsend_data, freceive_data);
+}
+
+/* Start the protocol. This routine is called by both the 'i' and 'j'
+ protocol start routines. We keep transmitting a SYNC packet
+ containing the window and packet size we would like to receive
+ until we receive a SYNC packet from the remote system. The first
+ two bytes of the data contents of a SYNC packet are the maximum
+ packet size we want to receive (high byte, low byte), and the next
+ byte is the maximum window size we want to use. */
+
+boolean
+fijstart (qdaemon, pzlog, imaxpacksize, pfsend, pfreceive)
+ struct sdaemon *qdaemon;
+ char **pzlog;
+ int imaxpacksize;
+ boolean (*pfsend) P((struct sconnection *qconn, const char *zsend,
+ size_t csend, boolean fdoread));
+ boolean (*pfreceive) P((struct sconnection *qconn, size_t cneed,
+ size_t *pcrec, int ctimeout, boolean freport));
+{
+ char ab[CHDRLEN + 3 + CCKSUMLEN];
+ unsigned long icksum;
+ int ctries;
+ int csyncs;
+
+ *pzlog = NULL;
+
+ pfIsend = pfsend;
+ pfIreceive = pfreceive;
+
+ if (iIforced_remote_packsize <= 0
+ || iIforced_remote_packsize >= imaxpacksize)
+ iIforced_remote_packsize = 0;
+ else
+ iIremote_packsize = iIforced_remote_packsize;
+ iIalc_packsize = 0;
+ if (iIforced_remote_winsize <= 0 || iIforced_remote_winsize >= IMAXSEQ)
+ iIforced_remote_winsize = 0;
+ else
+ iIremote_winsize = iIforced_remote_winsize;
+
+ iIsendseq = 1;
+ iIrecseq = 0;
+ iIlocal_ack = 0;
+ iIremote_ack = 0;
+ iIsendpos = 0;
+ iIrecpos = 0;
+ fIclosing = FALSE;
+
+ cIsent_packets = 0;
+ cIreceived_packets = 0;
+ cIresent_packets = 0;
+ cIbad_hdr = 0;
+ cIbad_order = 0;
+ cIbad_cksum = 0;
+ cIremote_rejects = 0;
+
+ ab[IHDR_INTRO] = IINTRO;
+ ab[IHDR_LOCAL] = ab[IHDR_REMOTE] = IHDRWIN_SET (0, 0);
+ ab[IHDR_CONTENTS1] = IHDRCON_SET1 (SYNC, qdaemon->fcaller, 3);
+ ab[IHDR_CONTENTS2] = IHDRCON_SET2 (SYNC, qdaemon->fcaller, 3);
+ ab[IHDR_CHECK] = IHDRCHECK_VAL (ab);
+ ab[CHDRLEN + 0] = (iIrequest_packsize >> 8) & 0xff;
+ ab[CHDRLEN + 1] = iIrequest_packsize & 0xff;
+ ab[CHDRLEN + 2] = iIrequest_winsize;
+ icksum = icrc (ab + CHDRLEN, 3, ICRCINIT);
+ UCKSUM_SET (ab + CHDRLEN + 3, icksum);
+
+ /* The static cIsyncs is incremented each time a SYNC packet is
+ received. */
+ csyncs = cIsyncs;
+ ctries = 0;
+
+ while (TRUE)
+ {
+ boolean ftimedout;
+
+ DEBUG_MESSAGE2 (DEBUG_PROTO,
+ "fistart: Sending SYNC packsize %d winsize %d",
+ iIrequest_packsize, iIrequest_winsize);
+
+ if (! (*pfIsend) (qdaemon->qconn, ab, CHDRLEN + 3 + CCKSUMLEN,
+ TRUE))
+ return FALSE;
+
+ if (fiwait_for_packet (qdaemon, cIsync_timeout, 0, FALSE,
+ &ftimedout))
+ {
+ if (csyncs != cIsyncs)
+ break;
+ }
+ else
+ {
+ if (! ftimedout)
+ return FALSE;
+
+ ++ctries;
+ if (ctries > cIsync_retries)
+ {
+ ulog (LOG_ERROR, "Protocol startup failed");
+ return FALSE;
+ }
+ }
+ }
+
+ /* We got a SYNC packet; set up packet buffers to use. */
+ if (iIremote_packsize > imaxpacksize)
+ iIremote_packsize = imaxpacksize;
+ do
+ {
+ int iseq;
+
+ for (iseq = 0; iseq < IMAXSEQ; iseq++)
+ {
+ azIrecbuffers[iseq] = NULL;
+ afInaked[iseq] = FALSE;
+ azIsendbuffers[iseq] = (char *) malloc (iIremote_packsize
+ + CHDRSKIPLEN
+ + CCKSUMLEN);
+ if (azIsendbuffers[iseq] == NULL)
+ {
+ int ifree;
+
+ for (ifree = 0; ifree < iseq; ifree++)
+ free ((pointer) azIsendbuffers[ifree]);
+ break;
+ }
+ }
+
+ if (iseq >= IMAXSEQ)
+ {
+ *pzlog = zbufalc (sizeof "protocol 'i' packet size %d window %d"
+ + 50);
+ sprintf (*pzlog, "protocol '%c' packet size %d window %d",
+ qdaemon->qproto->bname, iIremote_packsize,
+ iIremote_winsize);
+ iIalc_packsize = iIremote_packsize;
+
+ return TRUE;
+ }
+
+ iIremote_packsize >>= 1;
+ }
+ while (iIremote_packsize > 200);
+
+ ulog (LOG_ERROR,
+ "'%c' protocol startup failed; insufficient memory for packets",
+ qdaemon->qproto->bname);
+
+ return FALSE;
+}
+
+/* Shut down the protocol. We can be fairly informal about this,
+ since we know that the upper level protocol has already exchanged
+ hangup messages. If we didn't know that, we would have to make
+ sure that all packets before the CLOSE had been received. */
+
+boolean
+fishutdown (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ char *z;
+ size_t clen;
+
+ fIclosing = TRUE;
+
+ z = zigetspace (qdaemon, &clen) - CHDRLEN;
+
+ z[IHDR_INTRO] = IINTRO;
+ z[IHDR_LOCAL] = IHDRWIN_SET (iIsendseq, 0);
+ z[IHDR_REMOTE] = IHDRWIN_SET (iIrecseq, 0);
+ iIlocal_ack = iIrecseq;
+ z[IHDR_CONTENTS1] = IHDRCON_SET1 (CLOSE, qdaemon->fcaller, 0);
+ z[IHDR_CONTENTS2] = IHDRCON_SET2 (CLOSE, qdaemon->fcaller, 0);
+ z[IHDR_CHECK] = IHDRCHECK_VAL (z);
+
+ DEBUG_MESSAGE0 (DEBUG_PROTO, "fishutdown: Sending CLOSE");
+
+ if (! (*pfIsend) (qdaemon->qconn, z, CHDRLEN, FALSE))
+ return FALSE;
+
+ ulog (LOG_NORMAL,
+ "Protocol '%c' packets: sent %ld, resent %ld, received %ld",
+ qdaemon->qproto->bname, cIsent_packets, cIresent_packets,
+ cIreceived_packets);
+ if (cIbad_hdr != 0
+ || cIbad_cksum != 0
+ || cIbad_order != 0
+ || cIremote_rejects != 0)
+ ulog (LOG_NORMAL,
+ "Errors: header %ld, checksum %ld, order %ld, remote rejects %ld",
+ cIbad_hdr, cIbad_cksum, cIbad_order, cIremote_rejects);
+
+ /* Reset the protocol parameters to their default values. */
+ iIrequest_packsize = IREQUEST_PACKSIZE;
+ iIrequest_winsize = IREQUEST_WINSIZE;
+ iIforced_remote_packsize = 0;
+ iIforced_remote_winsize = 0;
+ cIsync_timeout = CSYNC_TIMEOUT;
+ cIsync_retries = CSYNC_RETRIES;
+ cItimeout = CTIMEOUT;
+ cIretries = CRETRIES;
+ cIerrors = CERRORS;
+ cIerror_decay = CERROR_DECAY;
+ zJavoid_parameter = ZAVOID;
+
+ return TRUE;
+}
+
+/* Send a command string. These are just sent as normal packets,
+ ending in a packet containing a null byte. */
+
+boolean
+fisendcmd (qdaemon, z, ilocal, iremote)
+ struct sdaemon *qdaemon;
+ const char *z;
+ int ilocal;
+ int iremote;
+{
+ size_t clen;
+
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO, "fisendcmd: Sending command \"%s\"", z);
+
+ clen = strlen (z);
+
+ while (TRUE)
+ {
+ char *zpacket;
+ size_t csize;
+
+ zpacket = zigetspace (qdaemon, &csize);
+
+ if (clen < csize)
+ {
+ memcpy (zpacket, z, clen + 1);
+ return fisenddata (qdaemon, zpacket, clen + 1, ilocal, iremote,
+ (long) -1);
+ }
+
+ memcpy (zpacket, z, csize);
+ z += csize;
+ clen -= csize;
+
+ if (! fisenddata (qdaemon, zpacket, csize, ilocal, iremote, (long) -1))
+ return FALSE;
+ }
+ /*NOTREACHED*/
+}
+
+/* Send a NAK. */
+
+static boolean
+finak (qdaemon, iseq)
+ struct sdaemon *qdaemon;
+ int iseq;
+{
+ char abnak[CHDRLEN];
+
+ abnak[IHDR_INTRO] = IINTRO;
+ abnak[IHDR_LOCAL] = IHDRWIN_SET (iseq, 0);
+ abnak[IHDR_REMOTE] = IHDRWIN_SET (iIrecseq, 0);
+ iIlocal_ack = iIrecseq;
+ abnak[IHDR_CONTENTS1] = IHDRCON_SET1 (NAK, qdaemon->fcaller, 0);
+ abnak[IHDR_CONTENTS2] = IHDRCON_SET2 (NAK, qdaemon->fcaller, 0);
+ abnak[IHDR_CHECK] = IHDRCHECK_VAL (abnak);
+
+ afInaked[iseq] = TRUE;
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "finak: Sending NAK %d", iseq);
+
+ return (*pfIsend) (qdaemon->qconn, abnak, CHDRLEN, TRUE);
+}
+
+/* Resend the latest packet the remote has not acknowledged. */
+
+static boolean
+firesend (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ int iseq;
+ char *zhdr;
+ size_t clen;
+
+ iseq = INEXTSEQ (iIremote_ack);
+ if (iseq == iIsendseq)
+ {
+ /* Everything has been ACKed and there is nothing to resend. */
+ return TRUE;
+ }
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "firesend: Resending packet %d", iseq);
+
+ /* Update the received sequence number. */
+ zhdr = azIsendbuffers[iseq] + CHDROFFSET;
+ if (IHDRWIN_GETSEQ (zhdr[IHDR_REMOTE]) != iIrecseq)
+ {
+ int iremote;
+
+ iremote = IHDRWIN_GETCHAN (zhdr[IHDR_REMOTE]);
+ zhdr[IHDR_REMOTE] = IHDRWIN_SET (iIrecseq, iremote);
+ zhdr[IHDR_CHECK] = IHDRCHECK_VAL (zhdr);
+ iIlocal_ack = iIrecseq;
+ }
+
+ ++cIresent_packets;
+
+ clen = CHDRCON_GETBYTES (zhdr[IHDR_CONTENTS1],
+ zhdr[IHDR_CONTENTS2]);
+
+ return (*pfIsend) (qdaemon->qconn, zhdr,
+ CHDRLEN + clen + (clen > 0 ? CCKSUMLEN : 0),
+ TRUE);
+}
+
+/* Wait until there is an opening in the receive window of the remote
+ system. */
+
+static boolean
+fiwindow_wait (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ /* iIsendseq is the sequence number we are sending, and iIremote_ack
+ is the last sequence number acknowledged by the remote. */
+ while (CSEQDIFF (iIsendseq, iIremote_ack) > iIremote_winsize)
+ {
+ /* If a NAK is lost, it is possible for the other side to be
+ sending a stream of packets while we are waiting for an ACK.
+ This should be caught in fiprocess_data; if it is about to
+ send an ACK, but it has an unacknowledged packet to send, it
+ sends the entire packet. Hopefully that will trigger an ACK
+ or a NAK and get us going again. */
+ DEBUG_MESSAGE0 (DEBUG_PROTO, "fiwindow_wait: Waiting for ACK");
+ if (! fiwait_for_packet (qdaemon, cItimeout, cIretries,
+ TRUE, (boolean *) NULL))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Get buffer space to use for packet data. We return a pointer to
+ the space to be used for the actual data, leaving room for the
+ header. */
+
+/*ARGSUSED*/
+char *
+zigetspace (qdaemon, pclen)
+ struct sdaemon *qdaemon;
+ size_t *pclen;
+{
+ *pclen = iIremote_packsize;
+ return azIsendbuffers[iIsendseq] + CHDRSKIPLEN;
+}
+
+/* Send a data packet. The zdata argument will always point to value
+ returned by zigetspace, so we know that we have room before it for
+ the header information. */
+
+boolean
+fisenddata (qdaemon, zdata, cdata, ilocal, iremote, ipos)
+ struct sdaemon *qdaemon;
+ char *zdata;
+ size_t cdata;
+ int ilocal;
+ int iremote;
+ long ipos;
+{
+ char *zhdr;
+ unsigned long icksum;
+ boolean fret;
+
+#if DEBUG > 0
+ if (ilocal < 0 || ilocal >= IMAXICHAN
+ || iremote < 0 || iremote >= IMAXICHAN)
+ ulog (LOG_FATAL, "fisenddata: ilocal %d iremote %d", ilocal, iremote);
+#endif
+
+ /* If we are changing the file position, we must send an SPOS
+ packet. */
+ if (ipos != iIsendpos && ipos != (long) -1)
+ {
+ int inext;
+ char *zspos;
+
+ /* We need to get a buffer to hold the SPOS packet, and it needs
+ to be next sequence number. However, the data we have been
+ given is currently in the next sequence number buffer. So we
+ shuffle the buffers around. */
+ inext = INEXTSEQ (iIsendseq);
+ zspos = azIsendbuffers[inext];
+ azIsendbuffers[inext] = zdata - CHDRSKIPLEN;
+ azIsendbuffers[iIsendseq] = zspos;
+ zspos += CHDROFFSET;
+
+ zspos[IHDR_INTRO] = IINTRO;
+ zspos[IHDR_LOCAL] = IHDRWIN_SET (iIsendseq, 0);
+ zspos[IHDR_REMOTE] = IHDRWIN_SET (iIrecseq, 0);
+ iIlocal_ack = iIrecseq;
+ zspos[IHDR_CONTENTS1] = IHDRCON_SET1 (SPOS, qdaemon->fcaller,
+ CCKSUMLEN);
+ zspos[IHDR_CONTENTS2] = IHDRCON_SET2 (SPOS, qdaemon->fcaller,
+ CCKSUMLEN);
+ zspos[IHDR_CHECK] = IHDRCHECK_VAL (zspos);
+ UCKSUM_SET (zspos + CHDRLEN, (unsigned long) ipos);
+ icksum = icrc (zspos + CHDRLEN, CCKSUMLEN, ICRCINIT);
+ UCKSUM_SET (zspos + CHDRLEN + CCKSUMLEN, icksum);
+
+ /* Wait for an opening in the window. */
+ if (iIremote_winsize > 0
+ && CSEQDIFF (iIsendseq, iIremote_ack) > iIremote_winsize)
+ {
+ if (! fiwindow_wait (qdaemon))
+ return FALSE;
+ }
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO, "fisenddata: Sending SPOS %ld",
+ ipos);
+
+ if (! (*pfIsend) (qdaemon->qconn, zspos,
+ CHDRLEN + CCKSUMLEN + CCKSUMLEN, TRUE))
+ return FALSE;
+
+ iIsendseq = INEXTSEQ (iIsendseq);
+ iIsendpos = ipos;
+ }
+
+ zhdr = zdata - CHDRLEN;
+ zhdr[IHDR_INTRO] = IINTRO;
+ zhdr[IHDR_LOCAL] = IHDRWIN_SET (iIsendseq, ilocal);
+ zhdr[IHDR_CONTENTS1] = IHDRCON_SET1 (DATA, qdaemon->fcaller, cdata);
+ zhdr[IHDR_CONTENTS2] = IHDRCON_SET2 (DATA, qdaemon->fcaller, cdata);
+
+ /* Compute and set the checksum. */
+ if (cdata > 0)
+ {
+ icksum = icrc (zdata, cdata, ICRCINIT);
+ UCKSUM_SET (zdata + cdata, icksum);
+ }
+
+ /* Wait until there is an opening in the window (we hope to not have
+ to wait here at all, actually; ideally the window should be large
+ enough to avoid a wait). */
+ if (iIremote_winsize > 0
+ && CSEQDIFF (iIsendseq, iIremote_ack) > iIremote_winsize)
+ {
+ if (! fiwindow_wait (qdaemon))
+ return FALSE;
+ }
+
+ /* We only fill in IHDR_REMOTE now, since only now do know the
+ correct value of iIrecseq. */
+ zhdr[IHDR_REMOTE] = IHDRWIN_SET (iIrecseq, iremote);
+ iIlocal_ack = iIrecseq;
+ zhdr[IHDR_CHECK] = IHDRCHECK_VAL (zhdr);
+
+ DEBUG_MESSAGE2 (DEBUG_PROTO, "fisenddata: Sending packet %d (%d bytes)",
+ iIsendseq, (int) cdata);
+
+ iIsendseq = INEXTSEQ (iIsendseq);
+ ++cIsent_packets;
+
+ fret = (*pfIsend) (qdaemon->qconn, zhdr,
+ cdata + CHDRLEN + (cdata > 0 ? CCKSUMLEN : 0),
+ TRUE);
+
+ iIsendpos += cdata;
+
+ if (fret && iPrecstart != iPrecend)
+ {
+ boolean fexit;
+
+ fret = fiprocess_data (qdaemon, &fexit, (boolean *) NULL,
+ (size_t *) NULL);
+ }
+
+ return fret;
+}
+
+/* Wait for data to come in. */
+
+boolean
+fiwait (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ return fiwait_for_packet (qdaemon, cItimeout, cIretries,
+ FALSE, (boolean *) NULL);
+}
+
+/* Wait for a packet. Either there is no data to send, or the remote
+ window is full. */
+
+static boolean
+fiwait_for_packet (qdaemon, ctimeout, cretries, fone, pftimedout)
+ struct sdaemon *qdaemon;
+ int ctimeout;
+ int cretries;
+ boolean fone;
+ boolean *pftimedout;
+{
+ int cshort;
+ int ctimeouts;
+
+ if (pftimedout != NULL)
+ *pftimedout = FALSE;
+
+ cshort = 0;
+ ctimeouts = 0;
+
+ while (TRUE)
+ {
+ boolean fexit, ffound;
+ size_t cneed;
+ size_t crec;
+
+ if (! fiprocess_data (qdaemon, &fexit, &ffound, &cneed))
+ return FALSE;
+
+ if (fexit || (fone && ffound))
+ return TRUE;
+
+ if (cneed == 0)
+ continue;
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO, "fiwait_for_packet: Need %d bytes",
+ (int) cneed);
+
+ if (! (*pfIreceive) (qdaemon->qconn, cneed, &crec, ctimeout, TRUE))
+ return FALSE;
+
+ if (crec != 0)
+ {
+ /* If we didn't get enough data twice in a row, we may have
+ dropped some data and be waiting for the end of a large
+ packet. Incrementing iPrecstart will force
+ fiprocess_data to skip the current packet and try to find
+ the next one. */
+ if (crec >= cneed)
+ cshort = 0;
+ else
+ {
+ ++cshort;
+ if (cshort > 1)
+ {
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
+ cshort = 0;
+ }
+ }
+ }
+ else
+ {
+ int i;
+
+ /* We timed out on the read. */
+ ++ctimeouts;
+ if (ctimeouts > cretries)
+ {
+ if (cretries > 0)
+ ulog (LOG_ERROR, "Timed out waiting for packet");
+ if (pftimedout != NULL)
+ *pftimedout = TRUE;
+ return FALSE;
+ }
+
+ /* Clear out the list of packets we have sent NAKs for. We
+ should have seen some sort of response by now. */
+ for (i = 0; i < IMAXSEQ; i++)
+ afInaked[i] = FALSE;
+
+ /* Send a NAK for the packet we want, and, if we have an
+ unacknowledged packet, send it again. */
+ if (! finak (qdaemon, INEXTSEQ (iIrecseq))
+ || ! firesend (qdaemon))
+ return FALSE;
+ }
+ }
+ /*NOTREACHED*/
+}
+
+/* Make sure we haven't overflowed the permissible error level. */
+
+static boolean
+ficheck_errors (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ if (cIerrors < 0)
+ return TRUE;
+
+ if (((cIbad_order + cIbad_hdr + cIbad_cksum + cIremote_rejects)
+ - (cIreceived_packets / cIerror_decay))
+ > cIerrors)
+ {
+ /* Try shrinking the packet size. */
+ if (iIrequest_packsize > 400)
+ {
+ char absync[CHDRLEN + 3 + CCKSUMLEN];
+ unsigned long icksum;
+
+ iIrequest_packsize /= 2;
+ absync[IHDR_INTRO] = IINTRO;
+ absync[IHDR_LOCAL] = IHDRWIN_SET (0, 0);
+ absync[IHDR_REMOTE] = IHDRWIN_SET (iIrecseq, 0);
+ iIlocal_ack = iIrecseq;
+ absync[IHDR_CONTENTS1] = IHDRCON_SET1 (SYNC, qdaemon->fcaller, 3);
+ absync[IHDR_CONTENTS2] = IHDRCON_SET2 (SYNC, qdaemon->fcaller, 3);
+ absync[IHDR_CHECK] = IHDRCHECK_VAL (absync);
+ absync[CHDRLEN + 0] = (iIrequest_packsize >> 8) & 0xff;
+ absync[CHDRLEN + 1] = iIrequest_packsize & 0xff;
+ absync[CHDRLEN + 2] = iIrequest_winsize;
+ icksum = icrc (absync + CHDRLEN, 3, ICRCINIT);
+ UCKSUM_SET (absync + CHDRLEN + 3, icksum);
+
+ cIerrors *= 2;
+
+ DEBUG_MESSAGE2 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "ficheck_errors: Sending SYNC packsize %d winsize %d",
+ iIrequest_packsize, iIrequest_winsize);
+
+ return (*pfIsend) (qdaemon->qconn, absync,
+ CHDRLEN + 3 + CCKSUMLEN, TRUE);
+ }
+
+ ulog (LOG_ERROR, "Too many '%c' protocol errors",
+ qdaemon->qproto->bname);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Process data waiting in the receive buffer, passing to the
+ fgot_data function. */
+
+static boolean
+fiprocess_data (qdaemon, pfexit, pffound, pcneed)
+ struct sdaemon *qdaemon;
+ boolean *pfexit;
+ boolean *pffound;
+ size_t *pcneed;
+{
+ boolean fbadhdr;
+
+ if (pfexit != NULL)
+ *pfexit = FALSE;
+ if (pffound != NULL)
+ *pffound = FALSE;
+
+ fbadhdr = FALSE;
+
+ while (iPrecstart != iPrecend)
+ {
+ char ab[CHDRLEN];
+ int cfirst, csecond;
+ char *zfirst, *zsecond;
+ int i;
+ int iget;
+ int ttype;
+ int iseq;
+ int csize;
+ int iack;
+
+ /* If we're closing the connection, ignore any data remaining in
+ the input buffer. */
+ if (fIclosing)
+ {
+ if (pfexit != NULL)
+ *pfexit = TRUE;
+ if (pcneed != NULL)
+ *pcneed = 0;
+ return TRUE;
+ }
+
+ /* Look for the IINTRO character. */
+ if (abPrecbuf[iPrecstart] != IINTRO)
+ {
+ char *zintro;
+ int cintro;
+
+ cintro = iPrecend - iPrecstart;
+ if (cintro < 0)
+ cintro = CRECBUFLEN - iPrecstart;
+
+ zintro = memchr (abPrecbuf + iPrecstart, IINTRO, (size_t) cintro);
+
+ if (zintro == NULL)
+ {
+ iPrecstart = (iPrecstart + cintro) % CRECBUFLEN;
+ continue;
+ }
+
+ /* We don't need % CRECBUFLEN here because zintro - (abPrecbuf
+ + iPrecstart) < cintro <= CRECBUFLEN - iPrecstart. */
+ iPrecstart += zintro - (abPrecbuf + iPrecstart);
+ }
+
+ /* Get the header into ab. */
+ for (i = 0, iget = iPrecstart;
+ i < CHDRLEN && iget != iPrecend;
+ i++, iget = (iget + 1) % CRECBUFLEN)
+ ab[i] = abPrecbuf[iget];
+
+ if (i < CHDRLEN)
+ {
+ if (pcneed != NULL)
+ *pcneed = CHDRLEN - i;
+ return TRUE;
+ }
+
+ if ((ab[IHDR_CHECK] & 0xff) != IHDRCHECK_VAL (ab)
+ || (FHDRCON_GETCALLER (ab[IHDR_CONTENTS1], ab[IHDR_CONTENTS2])
+ ? qdaemon->fcaller : ! qdaemon->fcaller))
+ {
+ /* We only report a single bad header message per call, to
+ avoid generating many errors if we get many INTRO bytes
+ in a row. */
+ if (! fbadhdr)
+ {
+ DEBUG_MESSAGE0 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fiprocess_data: Bad header");
+
+ ++cIbad_hdr;
+ if (! ficheck_errors (qdaemon))
+ return FALSE;
+
+ fbadhdr = TRUE;
+ }
+
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
+ continue;
+ }
+
+ zfirst = zsecond = NULL;
+ cfirst = csecond = 0;
+
+ ttype = THDRCON_GETTYPE (ab[IHDR_CONTENTS1], ab[IHDR_CONTENTS2]);
+ if (ttype == DATA || ttype == SPOS || ttype == CLOSE)
+ iseq = IHDRWIN_GETSEQ (ab[IHDR_LOCAL]);
+ else
+ iseq = -1;
+ csize = CHDRCON_GETBYTES (ab[IHDR_CONTENTS1], ab[IHDR_CONTENTS2]);
+
+ if (iseq != -1)
+ {
+ /* Make sure this packet is in our receive window. The last
+ packet we have acked is iIlocal_ack. */
+ if (iIrequest_winsize > 0
+ && CSEQDIFF (iseq, iIlocal_ack) > iIrequest_winsize)
+ {
+ DEBUG_MESSAGE1 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fiprocess_data: Out of order packet %d",
+ iseq);
+
+ ++cIbad_order;
+ if (! ficheck_errors (qdaemon))
+ return FALSE;
+
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
+
+ continue;
+ }
+ }
+
+ if (csize > 0)
+ {
+ int cinbuf;
+ char abcksum[CCKSUMLEN];
+ unsigned long ickdata;
+
+ cinbuf = iPrecend - iPrecstart;
+ if (cinbuf < 0)
+ cinbuf += CRECBUFLEN;
+ if (cinbuf < CHDRLEN + csize + CCKSUMLEN)
+ {
+ if (pcneed != NULL)
+ *pcneed = CHDRLEN + csize + CCKSUMLEN - cinbuf;
+ return TRUE;
+ }
+
+ if (iPrecend > iPrecstart)
+ {
+ cfirst = csize;
+ zfirst = abPrecbuf + iPrecstart + CHDRLEN;
+ }
+ else
+ {
+ cfirst = CRECBUFLEN - (iPrecstart + CHDRLEN);
+ if (cfirst <= 0)
+ {
+ /* Here cfirst is non-positive, so subtracting from
+ abPrecbuf will actually skip the appropriate number
+ of bytes at the start of abPrecbuf. */
+ zfirst = abPrecbuf - cfirst;
+ cfirst = csize;
+ }
+ else
+ {
+ if (cfirst >= csize)
+ cfirst = csize;
+ else
+ {
+ zsecond = abPrecbuf;
+ csecond = csize - cfirst;
+ }
+ zfirst = abPrecbuf + iPrecstart + CHDRLEN;
+ }
+ }
+
+ /* Get the checksum into abcksum. */
+ for (i = 0, iget = (iPrecstart + CHDRLEN + csize) % CRECBUFLEN;
+ i < CCKSUMLEN;
+ i++, iget = (iget + 1) % CRECBUFLEN)
+ abcksum[i] = abPrecbuf[iget];
+
+ ickdata = icrc (zfirst, (size_t) cfirst, ICRCINIT);
+ if (csecond > 0)
+ ickdata = icrc (zsecond, (size_t) csecond, ickdata);
+
+ if (ICKSUM_GET (abcksum) != ickdata)
+ {
+ DEBUG_MESSAGE2 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fiprocess_data: Bad checksum; data %lu, frame %lu",
+ ickdata, ICKSUM_GET (abcksum));
+
+ ++cIbad_cksum;
+ if (! ficheck_errors (qdaemon))
+ return FALSE;
+
+ /* If this sequence number is in our receive window,
+ send a NAK. iIrecseq is the last sequence number we
+ have succesfully received. */
+ if (iseq != -1
+ && iseq != iIrecseq
+ && (iIrequest_winsize <= 0
+ || CSEQDIFF (iseq, iIrecseq) <= iIrequest_winsize)
+ && azIrecbuffers[iseq] == NULL)
+ {
+ if (! finak (qdaemon, iseq))
+ return FALSE;
+ }
+
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
+ continue;
+ }
+ }
+
+ /* Here we know that this is a valid packet, so we can adjust
+ iPrecstart accordingly. */
+ if (csize == 0)
+ iPrecstart = (iPrecstart + CHDRLEN) % CRECBUFLEN;
+ else
+ {
+ iPrecstart = ((iPrecstart + CHDRLEN + csize + CCKSUMLEN)
+ % CRECBUFLEN);
+ ++cIreceived_packets;
+ }
+
+ /* Get the ack from the packet, if appropriate. iIsendseq is
+ the next sequence number we are going to send, and
+ iIremote_ack is the last sequence number acknowledged by the
+ remote system. */
+ iack = IHDRWIN_GETSEQ (ab[IHDR_REMOTE]);
+ if (iIremote_winsize > 0
+ && iack != iIsendseq
+ && CSEQDIFF (iack, iIremote_ack) <= iIremote_winsize
+ && CSEQDIFF (iIsendseq, iack) <= iIremote_winsize)
+ {
+ /* Call uwindow_acked each time packet 0 is acked. */
+ if (iack < iIremote_ack)
+ uwindow_acked (qdaemon, FALSE);
+ iIremote_ack = iack;
+ }
+
+ if (iseq != -1)
+ {
+ afInaked[iseq] = FALSE;
+
+ /* If we haven't handled all previous packets, we must save
+ off this packet and deal with it later. */
+ if (iseq != INEXTSEQ (iIrecseq))
+ {
+ if (iseq == iIrecseq
+ || (iIrequest_winsize > 0
+ && CSEQDIFF (iseq, iIrecseq) > iIrequest_winsize))
+ {
+ DEBUG_MESSAGE1 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fiprocess_data: Ignoring out of order packet %d",
+ iseq);
+ continue;
+ }
+ else
+ {
+ DEBUG_MESSAGE1 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fiprocess_data: Saving unexpected packet %d",
+ iseq);
+
+ if (azIrecbuffers[iseq] == NULL)
+ {
+ azIrecbuffers[iseq] = zbufalc ((size_t) (CHDRLEN
+ + csize));
+ memcpy (azIrecbuffers[iseq], ab, CHDRLEN);
+ if (csize > 0)
+ {
+ memcpy (azIrecbuffers[iseq] + CHDRLEN, zfirst,
+ (size_t) cfirst);
+ if (csecond > 0)
+ memcpy (azIrecbuffers[iseq] + CHDRLEN + cfirst,
+ zsecond, (size_t) csecond);
+ }
+ }
+ }
+
+ /* Send NAK's for each packet between the last one we
+ received and this one, avoiding any packets for which
+ we've already sent NAK's or which we've already
+ received. */
+ for (i = INEXTSEQ (iIrecseq);
+ i != iseq;
+ i = INEXTSEQ (i))
+ {
+ if (! afInaked[i]
+ && azIrecbuffers[i] == NULL)
+ {
+ if (! finak (qdaemon, i))
+ return FALSE;
+ }
+ }
+
+ continue;
+ }
+
+ iIrecseq = iseq;
+ }
+
+ if (pffound != NULL)
+ *pffound = TRUE;
+
+ if (! fiprocess_packet (qdaemon, ab, zfirst, cfirst, zsecond, csecond,
+ pfexit))
+ return FALSE;
+
+ if (iseq != -1)
+ {
+ int inext;
+
+ /* If we've already received the next packet(s), process
+ them. */
+ inext = INEXTSEQ (iIrecseq);
+ while (azIrecbuffers[inext] != NULL)
+ {
+ char *z;
+ int c;
+
+ z = azIrecbuffers[inext];
+ c = CHDRCON_GETBYTES (z[IHDR_CONTENTS1], z[IHDR_CONTENTS2]);
+ iIrecseq = inext;
+ if (! fiprocess_packet (qdaemon, z, z + CHDRLEN, c,
+ (char *) NULL, 0, pfexit))
+ return FALSE;
+ ubuffree (azIrecbuffers[inext]);
+ azIrecbuffers[inext] = NULL;
+ inext = INEXTSEQ (inext);
+ }
+ }
+
+ /* If we have received half of our window size or more since the
+ last ACK, send one now. Sending an ACK for half the window
+ at a time should significantly cut the acknowledgement
+ traffic when only one side is sending. We should normally
+ not have to send an ACK if we have data to send, since each
+ packet sent will ACK the most recently received packet.
+ However, it can happen if we receive a burst of short
+ packets, such as a set of command acknowledgements. */
+ if (iIrequest_winsize > 0
+ && CSEQDIFF (iIrecseq, iIlocal_ack) >= iIrequest_winsize / 2)
+ {
+ char aback[CHDRLEN];
+
+ aback[IHDR_INTRO] = IINTRO;
+ aback[IHDR_LOCAL] = IHDRWIN_SET (0, 0);
+ aback[IHDR_REMOTE] = IHDRWIN_SET (iIrecseq, 0);
+ iIlocal_ack = iIrecseq;
+ aback[IHDR_CONTENTS1] = IHDRCON_SET1 (ACK, qdaemon->fcaller, 0);
+ aback[IHDR_CONTENTS2] = IHDRCON_SET2 (ACK, qdaemon->fcaller, 0);
+ aback[IHDR_CHECK] = IHDRCHECK_VAL (aback);
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO, "fiprocess_data: Sending ACK %d",
+ iIrecseq);
+
+ if (! (*pfIsend) (qdaemon->qconn, aback, CHDRLEN, TRUE))
+ return FALSE;
+ }
+ }
+
+ if (pcneed != NULL)
+ *pcneed = CHDRLEN;
+
+ return TRUE;
+}
+
+/* Process a single packet. */
+
+static boolean
+fiprocess_packet (qdaemon, zhdr, zfirst, cfirst, zsecond, csecond, pfexit)
+ struct sdaemon *qdaemon;
+ const char *zhdr;
+ const char *zfirst;
+ int cfirst;
+ const char *zsecond;
+ int csecond;
+ boolean *pfexit;
+{
+ int ttype;
+
+ ttype = THDRCON_GETTYPE (zhdr[IHDR_CONTENTS1], zhdr[IHDR_CONTENTS2]);
+ switch (ttype)
+ {
+ case DATA:
+ {
+ int iseq;
+ boolean fret;
+
+ iseq = IHDRWIN_GETSEQ (zhdr[IHDR_LOCAL]);
+ DEBUG_MESSAGE2 (DEBUG_PROTO,
+ "fiprocess_packet: Got DATA packet %d size %d",
+ iseq, cfirst + csecond);
+ fret = fgot_data (qdaemon, zfirst, (size_t) cfirst,
+ zsecond, (size_t) csecond,
+ IHDRWIN_GETCHAN (zhdr[IHDR_REMOTE]),
+ IHDRWIN_GETCHAN (zhdr[IHDR_LOCAL]),
+ iIrecpos,
+ INEXTSEQ (iIremote_ack) == iIsendseq,
+ pfexit);
+ iIrecpos += cfirst + csecond;
+ return fret;
+ }
+
+ case SYNC:
+ {
+ int ipack, iwin;
+
+ /* We accept a SYNC packet to adjust the packet and window
+ sizes at any time. */
+ if (cfirst + csecond < 3)
+ {
+ ulog (LOG_ERROR, "Bad SYNC packet");
+ return FALSE;
+ }
+ ipack = (zfirst[0] & 0xff) << 8;
+ if (cfirst > 1)
+ ipack |= zfirst[1] & 0xff;
+ else
+ ipack |= zsecond[0];
+ if (cfirst > 2)
+ iwin = zfirst[2];
+ else
+ iwin = zsecond[2 - cfirst];
+
+ DEBUG_MESSAGE2 (DEBUG_PROTO,
+ "fiprocess_packet: Got SYNC packsize %d winsize %d",
+ ipack, iwin);
+
+ if (iIforced_remote_packsize == 0
+ && (iIalc_packsize == 0
+ || ipack <= iIalc_packsize))
+ iIremote_packsize = ipack;
+ if (iIforced_remote_winsize == 0)
+ iIremote_winsize = iwin;
+
+ /* We increment a static variable to tell the initialization
+ code that a SYNC was received, and we set *pfexit to TRUE
+ to get out to the initialization code (this will do no harm
+ if we are called from elsewhere). */
+ ++cIsyncs;
+ *pfexit = TRUE;
+ return TRUE;
+ }
+
+ case ACK:
+ /* There is nothing to do here, since the ack was already
+ handled in fiprocess_data. */
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "fiprocess_packet: Got ACK %d",
+ IHDRWIN_GETSEQ (zhdr[IHDR_REMOTE]));
+ return TRUE;
+
+ case NAK:
+ /* We must resend the requested packet. */
+ {
+ int iseq;
+ char *zsend;
+ size_t clen;
+
+ ++cIremote_rejects;
+ if (! ficheck_errors (qdaemon))
+ return FALSE;
+
+ iseq = IHDRWIN_GETSEQ (zhdr[IHDR_LOCAL]);
+
+ /* The timeout code will send a NAK for the packet the remote
+ side wants. So we may see a NAK here for the packet we are
+ about to send. */
+ if (iseq == iIsendseq
+ || (iIremote_winsize > 0
+ && (CSEQDIFF (iseq, iIremote_ack) > iIremote_winsize
+ || CSEQDIFF (iIsendseq, iseq) > iIremote_winsize)))
+ {
+ DEBUG_MESSAGE1 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fiprocess_packet: Ignoring out of order NAK %d",
+ iseq);
+ return TRUE;
+ }
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO | DEBUG_ABNORMAL,
+ "fiprocess_packet: Got NAK %d; resending packet",
+ iseq);
+
+ /* Update the received sequence number. */
+ zsend = azIsendbuffers[iseq] + CHDROFFSET;
+ if (IHDRWIN_GETSEQ (zsend[IHDR_REMOTE]) != iIrecseq)
+ {
+ int iremote;
+
+ iremote = IHDRWIN_GETCHAN (zsend[IHDR_REMOTE]);
+ zsend[IHDR_REMOTE] = IHDRWIN_SET (iIrecseq, iremote);
+ zsend[IHDR_CHECK] = IHDRCHECK_VAL (zsend);
+ iIlocal_ack = iIrecseq;
+ }
+
+ ++cIresent_packets;
+
+ clen = CHDRCON_GETBYTES (zsend[IHDR_CONTENTS1],
+ zsend[IHDR_CONTENTS2]);
+
+ return (*pfIsend) (qdaemon->qconn, zsend,
+ CHDRLEN + clen + (clen > 0 ? CCKSUMLEN : 0),
+ TRUE);
+ }
+
+ case SPOS:
+ /* Set the file position. */
+ {
+ char abpos[CCKSUMLEN];
+ const char *zpos;
+
+ if (cfirst >= CCKSUMLEN)
+ zpos = zfirst;
+ else
+ {
+ memcpy (abpos, zfirst, (size_t) cfirst);
+ memcpy (abpos + cfirst, zsecond, (size_t) (CCKSUMLEN - cfirst));
+ zpos = abpos;
+ }
+ iIrecpos = (long) ICKSUM_GET (zpos);
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "fiprocess_packet: Got SPOS %ld", iIrecpos);
+ return TRUE;
+ }
+
+ case CLOSE:
+ {
+ boolean fexpected;
+
+ fexpected = ! fLog_sighup || fIclosing;
+ if (! fexpected)
+ ulog (LOG_ERROR, "Received unexpected CLOSE packet");
+ else
+ DEBUG_MESSAGE0 (DEBUG_PROTO, "fiprocess_packet: Got CLOSE packet");
+
+ fIclosing = TRUE;
+ *pfexit = TRUE;
+ return fexpected;
+ }
+
+ default:
+ /* Just ignore unrecognized packet types, for future protocol
+ enhancements. */
+ DEBUG_MESSAGE1 (DEBUG_PROTO, "fiprocess_packet: Got packet type %d",
+ ttype);
+ return TRUE;
+ }
+ /*NOTREACHED*/
+}
diff --git a/gnu/libexec/uucp/uucico/protj.c b/gnu/libexec/uucp/uucico/protj.c
new file mode 100644
index 00000000000..bdf2b856114
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/protj.c
@@ -0,0 +1,671 @@
+/* protj.c
+ The 'j' protocol.
+
+ Copyright (C) 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char protj_rcsid[] = "$Id: protj.c,v 1.1 1993/08/04 19:36:23 jtc Exp $";
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+#include "uudefs.h"
+#include "conn.h"
+#include "trans.h"
+#include "system.h"
+#include "prot.h"
+
+/* The 'j' protocol.
+
+ The 'j' protocol is a wrapper around the 'i' protocol, which avoids
+ the use of certain characters, such as XON and XOFF.
+
+ Each 'j' protocol packet begins with a '^' character, followed by a
+ two byte encoded size giving the total number of bytes in the
+ packet. The first byte is HIGH, the second byte is LOW, and the
+ number of bytes is (HIGH - 32) * 64 + (LOW - 32), where 32 <= HIGH
+ < 127 and 32 <= LOW < 96 (i.e., HIGH and LOW are printable ASCII
+ characters). This is followed by a '=' character. The next two
+ bytes are the number of data bytes in the packet, using the same
+ encoding. This is followed by a '@' character, and then that
+ number of data bytes. The remaining bytes in the packet are
+ indices of bytes which must be transformed, followed by a trailing
+ '~' character. The indices are encoded in the following overly
+ complex format.
+
+ Each byte index is two bytes long. The first byte in the index is
+ INDEX-HIGH and the second is INDEX-LOW. If 32 <= INDEX-HIGH < 126,
+ the byte index refers to the byte at position (INDEX-HIGH - 32) *
+ 32 + INDEX-LOW % 32 in the actual data, where 32 <= INDEX-LOW <
+ 127. If 32 <= INDEX-LOW < 64, then 128 must be added to the
+ indexed byte. If 64 <= INDEX-LOW < 96, then the indexed byte must
+ be exclusive or'red with 32. If 96 <= INDEX-LOW < 127, both
+ operations must be performed. If INDEX-HIGH == 126, then the byte
+ index refers to the byte at position (INDEX-LOW - 32) * 32 + 31,
+ where 32 <= INDEX-LOW < 126. 128 must be added to the byte, and it
+ must be exclusive or'red with 32. This unfortunately requires a
+ special test (when encoding INDEX-LOW must be checked for 127; when
+ decoding INDEX-HIGH must be checked for 126). It does, however,
+ permit the byte indices field to consist exclusively of printable
+ ASCII characters.
+
+ The maximum value for a byte index is (125 - 32) * 32 + 31 == 3007,
+ so the is the maximum number of data bytes permitted. Since it is
+ convenient to have each 'j' protocol packet correspond to each 'i'
+ protocol packet, we restrict the 'i' protocol accordingly.
+
+ Note that this encoding method assumes that we can send all
+ printable ASCII characters. */
+
+/* The first byte of each packet. I just picked these values
+ randomly, trying to get characters that were perhaps slightly less
+ likely to appear in normal text. */
+#define FIRST '\136'
+
+/* The fourth byte of each packet. */
+#define FOURTH '\075'
+
+/* The seventh byte of each packet. */
+#define SEVENTH '\100'
+
+/* The trailing byte of each packet. */
+#define TRAILER '\176'
+
+/* The length of the header. */
+#define CHDRLEN (7)
+
+/* Get a number of bytes encoded in a two byte length at the start of
+ a packet. */
+#define CGETLENGTH(b1, b2) (((b1) - 32) * 64 + ((b2) - 32))
+
+/* Set the high and low bytes of a two byte length at the start of a
+ packet. */
+#define ISETLENGTH_FIRST(i) ((i) / 64 + 32)
+#define ISETLENGTH_SECOND(i) ((i) % 64 + 32)
+
+/* The maximum packet size we support, as determined by the byte
+ indices. */
+#define IMAXPACKSIZE ((125 - 32) * 32 + 31)
+
+/* Amount to offset the bytes in the byte index by. */
+#define INDEX_OFFSET (32)
+
+/* Maximum value of INDEX-LOW, before offsetting. */
+#define INDEX_MAX_LOW (32)
+
+/* Maximum value of INDEX-HIGH, before offsetting. */
+#define INDEX_MAX_HIGH (94)
+
+/* The set of characters to avoid. */
+static char *zJavoid;
+
+/* The number of characters to avoid. */
+static size_t cJavoid;
+
+/* A buffer used when sending data. */
+static char *zJbuf;
+
+/* The end of the undecoded data in abPrecbuf. */
+static int iJrecend;
+
+/* Local functions. */
+static boolean fjsend_data P((struct sconnection *qconn, const char *zsend,
+ size_t csend, boolean fdoread));
+static boolean fjreceive_data P((struct sconnection *qconn, size_t cneed,
+ size_t *pcrec, int ctimeout,
+ boolean freport));
+static boolean fjprocess_data P((size_t *pcneed));
+
+/* Start the protocol. We first send over the list of characters to
+ avoid as an escape sequence, starting with FIRST and ending with
+ TRAILER. There is no error checking done on this string. */
+
+boolean
+fjstart (qdaemon, pzlog)
+ struct sdaemon *qdaemon;
+ char **pzlog;
+{
+ size_t clen;
+ char *zsend;
+ int b;
+ size_t cbuf, cgot;
+ char *zbuf;
+ int i;
+
+ /* Send the characters we want to avoid to the other side. */
+ clen = strlen (zJavoid_parameter);
+ zsend = zbufalc (clen + 3);
+ zsend[0] = FIRST;
+ memcpy (zsend + 1, zJavoid_parameter, clen);
+ zsend[clen + 1] = TRAILER;
+ zsend[clen + 2] = '\0';
+ if (! fsend_data (qdaemon->qconn, zsend, clen + 2, TRUE))
+ {
+ ubuffree (zsend);
+ return FALSE;
+ }
+ ubuffree (zsend);
+
+ /* Read the characters the other side wants to avoid. */
+ while ((b = breceive_char (qdaemon->qconn, cIsync_timeout, TRUE))
+ != FIRST)
+ {
+ if (b < 0)
+ {
+ if (b == -1)
+ ulog (LOG_ERROR, "Timed out in 'j' protocol startup");
+ return FALSE;
+ }
+ }
+
+ cbuf = 20;
+ zbuf = zbufalc (cbuf);
+ cgot = 0;
+ while ((b = breceive_char (qdaemon->qconn, cIsync_timeout, TRUE))
+ != TRAILER)
+ {
+ if (b < 0)
+ {
+ ubuffree (zbuf);
+ if (b == -1)
+ ulog (LOG_ERROR, "Timed out in 'j' protocol startup");
+ return FALSE;
+ }
+ if (cgot + 1 >= cbuf)
+ {
+ char *znew;
+
+ cbuf += 20;
+ znew = zbufalc (cbuf);
+ memcpy (znew, zbuf, cgot);
+ ubuffree (zbuf);
+ zbuf = znew;
+ }
+ zbuf[cgot] = b;
+ ++cgot;
+ }
+ zbuf[cgot] = '\0';
+
+ /* Merge the local and remote avoid bytes into one list, translated
+ into bytes. */
+ cgot = cescape (zbuf);
+
+ clen = strlen (zJavoid_parameter);
+ zJavoid = zbufalc (clen + cgot + 1);
+ memcpy (zJavoid, zJavoid_parameter, clen + 1);
+ cJavoid = cescape (zJavoid);
+
+ for (i = 0; i < cgot; i++)
+ {
+ if (memchr (zJavoid, zbuf[i], cJavoid) == NULL)
+ {
+ zJavoid[cJavoid] = zbuf[i];
+ ++cJavoid;
+ }
+ }
+
+ ubuffree (zbuf);
+
+ /* We can't avoid ASCII printable characters, since the encoding
+ method assumes that they can always be sent. If it ever turns
+ out to be important, a different encoding method could be used,
+ perhaps keyed by a different FIRST character. */
+ if (cJavoid == 0)
+ {
+ ulog (LOG_ERROR, "No characters to avoid in 'j' protocol");
+ return FALSE;
+ }
+ for (i = 0; i < cJavoid; i++)
+ {
+ if (zJavoid[i] >= 32 && zJavoid[i] <= 126)
+ {
+ ulog (LOG_ERROR, "'j' protocol can't avoid character '\\%03o'",
+ zJavoid[i]);
+ return FALSE;
+ }
+ }
+
+ /* If we are avoiding XON and XOFF, use XON/XOFF handshaking. */
+ if (memchr (zJavoid, '\021', cJavoid) != NULL
+ && memchr (zJavoid, '\023', cJavoid) != NULL)
+ {
+ if (! fconn_set (qdaemon->qconn, PARITYSETTING_NONE,
+ STRIPSETTING_EIGHTBITS, XONXOFF_ON))
+ return FALSE;
+ }
+
+ /* Let the port settle. */
+ usysdep_sleep (2);
+
+ /* Allocate a buffer we use when sending data. We will probably
+ never actually need one this big; if this code is ported to a
+ computer with small amounts of memory, this should be changed to
+ increase the buffer size as needed. */
+ zJbuf = zbufalc (CHDRLEN + IMAXPACKSIZE * 3 + 1);
+ zJbuf[0] = FIRST;
+ zJbuf[3] = FOURTH;
+ zJbuf[6] = SEVENTH;
+
+ /* iJrecend is the end of the undecoded data, and iPrecend is the
+ end of the decoded data. At this point there is no decoded data,
+ and we must initialize the variables accordingly. */
+ iJrecend = iPrecend;
+ iPrecend = iPrecstart;
+
+ /* Now do the 'i' protocol startup. */
+ return fijstart (qdaemon, pzlog, IMAXPACKSIZE, fjsend_data,
+ fjreceive_data);
+}
+
+/* Shut down the protocol. */
+
+boolean
+fjshutdown (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ boolean fret;
+
+ fret = fishutdown (qdaemon);
+ ubuffree (zJavoid);
+ ubuffree (zJbuf);
+ return fret;
+}
+
+/* Encode a packet of data and send it. This copies the data, which
+ is a waste of time, but calling fsend_data three times (for the
+ header, the body, and the trailer) would waste even more time. */
+
+static boolean
+fjsend_data (qconn, zsend, csend, fdoread)
+ struct sconnection *qconn;
+ const char *zsend;
+ size_t csend;
+ boolean fdoread;
+{
+ char *zput, *zindex;
+ const char *zfrom, *zend;
+ char bfirst, bsecond;
+ int iprecendhold;
+ boolean fret;
+
+ zput = zJbuf + CHDRLEN;
+ zindex = zput + csend;
+ zfrom = zsend;
+ zend = zsend + csend;
+
+ /* Optimize for the common case of avoiding two characters. */
+ bfirst = zJavoid[0];
+ if (cJavoid <= 1)
+ bsecond = bfirst;
+ else
+ bsecond = zJavoid[1];
+ while (zfrom < zend)
+ {
+ char b;
+ boolean f128, f32;
+ int i, ihigh, ilow;
+
+ b = *zfrom++;
+ if (b != bfirst && b != bsecond)
+ {
+ int ca;
+ char *za;
+
+ if (cJavoid <= 2)
+ {
+ *zput++ = b;
+ continue;
+ }
+
+ ca = cJavoid - 2;
+ za = zJavoid + 2;
+ while (ca-- != 0)
+ if (*za++ == b)
+ break;
+
+ if (ca < 0)
+ {
+ *zput++ = b;
+ continue;
+ }
+ }
+
+ if ((b & 0x80) == 0)
+ f128 = FALSE;
+ else
+ {
+ b &=~ 0x80;
+ f128 = TRUE;
+ }
+ if (b >= 32 && b != 127)
+ f32 = FALSE;
+ else
+ {
+ b ^= 0x20;
+ f32 = TRUE;
+ }
+
+ /* We must now put the byte index into the buffer. The byte
+ index is encoded similarly to the length of the actual data,
+ but the byte index also encodes the operations that must be
+ performed on the byte. The first byte in the index is the
+ most significant bits. If we only had to subtract 128 from
+ the byte, we use the second byte directly. If we had to xor
+ the byte with 32, we add 32 to the second byte index. If we
+ had to perform both operations, we add 64 to the second byte
+ index. However, if we had to perform both operations, and
+ the second byte index was 31, then after adding 64 and
+ offsetting by 32 we would come up with 127, which we are not
+ permitted to use. Therefore, in this special case we set the
+ first byte of the index to 126 and put the original first
+ byte into the second byte position instead. This is why we
+ could not permit the high byte of the length of the actual
+ data to be 126. We can get away with the switch because both
+ the value of the second byte index (31) and the operations to
+ perform (both) are known. */
+ i = zput - (zJbuf + CHDRLEN);
+ ihigh = i / INDEX_MAX_LOW;
+ ilow = i % INDEX_MAX_LOW;
+
+ if (f128 && ! f32)
+ ;
+ else if (f32 && ! f128)
+ ilow += INDEX_MAX_LOW;
+ else
+ {
+ /* Both operations had to be performed. */
+ if (ilow != INDEX_MAX_LOW - 1)
+ ilow += 2 * INDEX_MAX_LOW;
+ else
+ {
+ ilow = ihigh;
+ ihigh = INDEX_MAX_HIGH;
+ }
+ }
+
+ *zindex++ = ihigh + INDEX_OFFSET;
+ *zindex++ = ilow + INDEX_OFFSET;
+ *zput++ = b;
+ }
+
+ *zindex++ = TRAILER;
+
+ /* Set the lengths into the buffer. zJbuf[0,3,6] were set when
+ zJbuf was allocated, and are never changed thereafter. */
+ zJbuf[1] = ISETLENGTH_FIRST (zindex - zJbuf);
+ zJbuf[2] = ISETLENGTH_SECOND (zindex - zJbuf);
+ zJbuf[4] = ISETLENGTH_FIRST (csend);
+ zJbuf[5] = ISETLENGTH_SECOND (csend);
+
+ /* Send the data over the line. We must preserve iPrecend as
+ discussed in fjreceive_data. */
+ iprecendhold = iPrecend;
+ iPrecend = iJrecend;
+ fret = fsend_data (qconn, zJbuf, (size_t) (zindex - zJbuf), fdoread);
+ iJrecend = iPrecend;
+ iPrecend = iprecendhold;
+
+ /* Process any bytes that may have been placed in abPrecbuf. */
+ if (fret && iPrecend != iJrecend)
+ {
+ if (! fjprocess_data ((size_t *) NULL))
+ return FALSE;
+ }
+
+ return fret;
+}
+
+/* Receive and decode data. This is called by fiwait_for_packet. We
+ need to be able to return decoded data between iPrecstart and
+ iPrecend, while not losing any undecoded partial packets we may
+ have read. We use iJrecend as a pointer to the end of the
+ undecoded data, and set iPrecend for the decoded data. iPrecend
+ points to the start of the undecoded data. */
+
+static boolean
+fjreceive_data (qconn, cineed, pcrec, ctimeout, freport)
+ struct sconnection *qconn;
+ size_t cineed;
+ size_t *pcrec;
+ int ctimeout;
+ boolean freport;
+{
+ int iprecendstart;
+ size_t cjneed;
+ size_t crec;
+ int cnew;
+
+ iprecendstart = iPrecend;
+
+ /* Figure out how many bytes we need to decode the next packet. */
+ if (! fjprocess_data (&cjneed))
+ return FALSE;
+
+ /* As we long as we read some data but don't have enough to decode a
+ packet, we try to read some more. We decrease the timeout each
+ time so that we will not wait forever if the connection starts
+ dribbling data. */
+ do
+ {
+ int iprecendhold;
+ size_t cneed;
+
+ if (cjneed > cineed)
+ cneed = cjneed;
+ else
+ cneed = cineed;
+
+ /* We are setting iPrecend to the end of the decoded data for
+ the 'i' protocol. When we do the actual read, we have to set
+ it to the end of the undecoded data so that any undecoded
+ data we have received is not overwritten. */
+ iprecendhold = iPrecend;
+ iPrecend = iJrecend;
+ if (! freceive_data (qconn, cneed, &crec, ctimeout, freport))
+ return FALSE;
+ iJrecend = iPrecend;
+ iPrecend = iprecendhold;
+
+ /* Process any data we have received. This will set iPrecend to
+ the end of the new decoded data. */
+ if (! fjprocess_data (&cjneed))
+ return FALSE;
+
+ cnew = iPrecend - iprecendstart;
+ if (cnew < 0)
+ cnew += CRECBUFLEN;
+
+ if (cnew > cineed)
+ cineed = 0;
+ else
+ cineed -= cnew;
+
+ --ctimeout;
+ }
+ while (cnew == 0 && crec > 0 && ctimeout > 0);
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO, "fjreceive_data: Got %d decoded bytes",
+ cnew);
+
+ *pcrec = cnew;
+ return TRUE;
+}
+
+/* Decode the data in the buffer, optionally returning the number of
+ bytes needed to complete the next packet. */
+
+static boolean
+fjprocess_data (pcneed)
+ size_t *pcneed;
+{
+ int istart;
+
+ istart = iPrecend;
+ while (istart != iJrecend)
+ {
+ int i, iget;
+ char ab[CHDRLEN];
+ int cpacket, cdata, chave;
+ int iindex, iendindex;
+
+ /* Find the next occurrence of FIRST. If we have to skip some
+ garbage bytes to get to it, zero them out (so they don't
+ confuse the 'i' protocol) and advance iPrecend. This will
+ save us from looking at them again. */
+ if (abPrecbuf[istart] != FIRST)
+ {
+ int cintro;
+ char *zintro;
+ size_t cskipped;
+
+ cintro = iJrecend - istart;
+ if (cintro < 0)
+ cintro = CRECBUFLEN - istart;
+
+ zintro = memchr (abPrecbuf + istart, FIRST, (size_t) cintro);
+ if (zintro == NULL)
+ {
+ bzero (abPrecbuf + istart, (size_t) cintro);
+ istart = (istart + cintro) % CRECBUFLEN;
+ iPrecend = istart;
+ continue;
+ }
+
+ cskipped = zintro - (abPrecbuf + istart);
+ bzero (abPrecbuf + istart, cskipped);
+ istart += cskipped;
+ iPrecend = istart;
+ }
+
+ for (i = 0, iget = istart;
+ i < CHDRLEN && iget != iJrecend;
+ ++i, iget = (iget + 1) % CRECBUFLEN)
+ ab[i] = abPrecbuf[iget];
+
+ if (i < CHDRLEN)
+ {
+ if (pcneed != NULL)
+ *pcneed = CHDRLEN - i;
+ return TRUE;
+ }
+
+ cpacket = CGETLENGTH (ab[1], ab[2]);
+ cdata = CGETLENGTH (ab[4], ab[5]);
+
+ /* Make sure the header has the right magic characters, that the
+ data is not larger than the packet, and that we have an even
+ number of byte index characters. */
+ if (ab[3] != FOURTH
+ || ab[6] != SEVENTH
+ || cdata > cpacket - CHDRLEN - 1
+ || (cpacket - cdata - CHDRLEN - 1) % 2 == 1)
+ {
+ istart = (istart + 1) % CRECBUFLEN;
+ continue;
+ }
+
+ chave = iJrecend - istart;
+ if (chave < 0)
+ chave += CRECBUFLEN;
+
+ if (chave < cpacket)
+ {
+ if (pcneed != NULL)
+ *pcneed = cpacket - chave;
+ return TRUE;
+ }
+
+ /* Figure out where the byte indices start and end. */
+ iindex = (istart + CHDRLEN + cdata) % CRECBUFLEN;
+ iendindex = (istart + cpacket - 1) % CRECBUFLEN;
+
+ /* Make sure the magic trailer character is there. */
+ if (abPrecbuf[iendindex] != TRAILER)
+ {
+ istart = (istart + 1) % CRECBUFLEN;
+ continue;
+ }
+
+ /* We have a packet to decode. The decoding process is simpler
+ than the encoding process, since all we have to do is examine
+ the byte indices. We zero out the byte indices as we go, so
+ that they will not confuse the 'i' protocol. */
+ while (iindex != iendindex)
+ {
+ int ihigh, ilow;
+ boolean f32, f128;
+ int iset;
+
+ ihigh = abPrecbuf[iindex] - INDEX_OFFSET;
+ abPrecbuf[iindex] = 0;
+ iindex = (iindex + 1) % CRECBUFLEN;
+ ilow = abPrecbuf[iindex] - INDEX_OFFSET;
+ abPrecbuf[iindex] = 0;
+ iindex = (iindex + 1) % CRECBUFLEN;
+
+ /* Now we must undo the encoding, by adding 128 and xoring
+ with 32 as appropriate. Which to do is encoded in the
+ low byte, except that if the high byte is the special
+ value 126, then the low byte is actually the high byte
+ and both operations are performed. */
+ f128 = TRUE;
+ f32 = TRUE;
+ if (ihigh == INDEX_MAX_HIGH)
+ iset = ilow * INDEX_MAX_LOW + INDEX_MAX_LOW - 1;
+ else
+ {
+ iset = ihigh * INDEX_MAX_LOW + ilow % INDEX_MAX_LOW;
+ if (ilow < INDEX_MAX_LOW)
+ f32 = FALSE;
+ else if (ilow < 2 * INDEX_MAX_LOW)
+ f128 = FALSE;
+ }
+
+ /* Now iset is the index from the start of the data to the
+ byte to modify; adjust it to an index in abPrecbuf. */
+ iset = (istart + CHDRLEN + iset) % CRECBUFLEN;
+
+ if (f128)
+ abPrecbuf[iset] |= 0x80;
+ if (f32)
+ abPrecbuf[iset] ^= 0x20;
+ }
+
+ /* Zero out the header and trailer to avoid confusing the 'i'
+ protocol, and update iPrecend to the end of decoded data. */
+ for (i = 0, iget = istart;
+ i < CHDRLEN && iget != iJrecend;
+ ++i, iget = (iget + 1) % CRECBUFLEN)
+ abPrecbuf[iget] = 0;
+ abPrecbuf[iendindex] = 0;
+ iPrecend = (iendindex + 1) % CRECBUFLEN;
+ istart = iPrecend;
+ }
+
+ if (pcneed != NULL)
+ *pcneed = CHDRLEN + 1;
+ return TRUE;
+}
diff --git a/gnu/libexec/uucp/uucico/prott.c b/gnu/libexec/uucp/uucico/prott.c
new file mode 100644
index 00000000000..477ccf4f49c
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/prott.c
@@ -0,0 +1,330 @@
+/* prott.c
+ The 't' protocol.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char prott_rcsid[] = "$Id: prott.c,v 1.1 1993/08/04 19:36:24 jtc Exp $";
+#endif
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "conn.h"
+#include "trans.h"
+#include "system.h"
+#include "prot.h"
+
+/* This implementation is based on code written by Rick Adams.
+
+ This code implements the 't' protocol, which does no error checking
+ whatsoever and thus requires an end-to-end verified eight bit
+ communication line, such as is provided by TCP. Using it with a
+ modem is unadvisable, since errors can occur between the modem and
+ the computer. */
+
+/* The buffer size we use. */
+#define CTBUFSIZE (1024)
+
+/* The offset in the buffer to the data. */
+#define CTFRAMELEN (4)
+
+/* Commands are sent in multiples of this size. */
+#define CTPACKSIZE (512)
+
+/* A pointer to the buffer we will use. */
+static char *zTbuf;
+
+/* True if we are receiving a file. */
+static boolean fTfile;
+
+/* The timeout we use. */
+static int cTtimeout = 120;
+
+struct uuconf_cmdtab asTproto_params[] =
+{
+ { "timeout", UUCONF_CMDTABTYPE_INT, (pointer) &cTtimeout, NULL },
+ { NULL, 0, NULL, NULL }
+};
+
+/* Local function. */
+
+static boolean ftprocess_data P((struct sdaemon *qdaemon, boolean *pfexit,
+ size_t *pcneed));
+
+/* Start the protocol. */
+
+boolean
+ftstart (qdaemon, pzlog)
+ struct sdaemon *qdaemon;
+ char **pzlog;
+{
+ *pzlog = NULL;
+ if (! fconn_set (qdaemon->qconn, PARITYSETTING_NONE,
+ STRIPSETTING_EIGHTBITS, XONXOFF_OFF))
+ return FALSE;
+ zTbuf = (char *) xmalloc (CTBUFSIZE + CTFRAMELEN);
+ /* The first two bytes of the buffer are always zero. */
+ zTbuf[0] = 0;
+ zTbuf[1] = 0;
+ fTfile = FALSE;
+ usysdep_sleep (2);
+ return TRUE;
+}
+
+/* Stop the protocol. */
+
+/*ARGSUSED*/
+boolean
+ftshutdown (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ xfree ((pointer) zTbuf);
+ zTbuf = NULL;
+ cTtimeout = 120;
+ return TRUE;
+}
+
+/* Send a command string. We send everything up to and including the
+ null byte. The number of bytes we send must be a multiple of
+ TPACKSIZE. */
+
+/*ARGSUSED*/
+boolean
+ftsendcmd (qdaemon, z, ilocal, iremote)
+ struct sdaemon *qdaemon;
+ const char *z;
+ int ilocal;
+ int iremote;
+{
+ size_t clen, csend;
+ char *zalc;
+ boolean fret;
+
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO, "ftsendcmd: Sending command \"%s\"", z);
+
+ clen = strlen (z);
+
+ /* We need to send the smallest multiple of CTPACKSIZE which is
+ greater than clen (not equal to clen, since we need room for the
+ null byte). */
+ csend = ((clen / CTPACKSIZE) + 1) * CTPACKSIZE;
+
+ zalc = zbufalc (csend);
+ memcpy (zalc, z, clen);
+ bzero (zalc + clen, csend - clen);
+
+ fret = fsend_data (qdaemon->qconn, zalc, csend, TRUE);
+ ubuffree (zalc);
+ return fret;
+}
+
+/* Get space to be filled with data. We provide a buffer which has
+ four bytes at the start available to hold the length. */
+
+/*ARGSIGNORED*/
+char *
+ztgetspace (qdaemon, pclen)
+ struct sdaemon *qdaemon;
+ size_t *pclen;
+{
+ *pclen = CTBUFSIZE;
+ return zTbuf + CTFRAMELEN;
+}
+
+/* Send out some data. We are allowed to modify the four bytes
+ preceding the buffer. This allows us to send the entire block with
+ header bytes in a single call. */
+
+/*ARGSIGNORED*/
+boolean
+ftsenddata (qdaemon, zdata, cdata, ilocal, iremote, ipos)
+ struct sdaemon *qdaemon;
+ char *zdata;
+ size_t cdata;
+ int ilocal;
+ int iremote;
+ long ipos;
+{
+ /* Here we do htonl by hand, since it doesn't exist everywhere. We
+ know that the amount of data cannot be greater than CTBUFSIZE, so
+ the first two bytes of this value will always be 0. They were
+ set to 0 in ftstart so we don't touch them here. This is useful
+ because we cannot portably right shift by 24 or 16, since we
+ might be dealing with sixteen bit integers. */
+ zdata[-2] = (char) ((cdata >> 8) & 0xff);
+ zdata[-1] = (char) (cdata & 0xff);
+
+ /* We pass FALSE to fsend_data since we don't expect the other side
+ to be sending us anything just now. */
+ return fsend_data (qdaemon->qconn, zdata - CTFRAMELEN, cdata + CTFRAMELEN,
+ FALSE);
+}
+
+/* Process data and return the amount we need in *pfneed. */
+
+static boolean
+ftprocess_data (qdaemon, pfexit, pcneed)
+ struct sdaemon *qdaemon;
+ boolean *pfexit;
+ size_t *pcneed;
+{
+ int cinbuf, cfirst, clen;
+
+ *pfexit = FALSE;
+
+ cinbuf = iPrecend - iPrecstart;
+ if (cinbuf < 0)
+ cinbuf += CRECBUFLEN;
+
+ if (! fTfile)
+ {
+ /* We are not receiving a file. Commands are read in chunks of
+ CTPACKSIZE. */
+ while (cinbuf >= CTPACKSIZE)
+ {
+ cfirst = CRECBUFLEN - iPrecstart;
+ if (cfirst > CTPACKSIZE)
+ cfirst = CTPACKSIZE;
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "ftprocess_data: Got %d command bytes",
+ cfirst);
+
+ if (! fgot_data (qdaemon, abPrecbuf + iPrecstart,
+ (size_t) cfirst, abPrecbuf,
+ (size_t) CTPACKSIZE - cfirst,
+ -1, -1, (long) -1, TRUE, pfexit))
+ return FALSE;
+
+ iPrecstart = (iPrecstart + CTPACKSIZE) % CRECBUFLEN;
+
+ if (*pfexit)
+ return TRUE;
+
+ cinbuf -= CTPACKSIZE;
+ }
+
+ if (pcneed != NULL)
+ *pcneed = CTPACKSIZE - cinbuf;
+
+ return TRUE;
+ }
+
+ /* Here we are receiving a file. The data comes in blocks. The
+ first four bytes contain the length, followed by that amount of
+ data. */
+
+ while (cinbuf >= CTFRAMELEN)
+ {
+ /* The length is stored in network byte order, MSB first. */
+
+ clen = (((((((abPrecbuf[iPrecstart] & 0xff) << 8)
+ + (abPrecbuf[(iPrecstart + 1) % CRECBUFLEN] & 0xff)) << 8)
+ + (abPrecbuf[(iPrecstart + 2) % CRECBUFLEN] & 0xff)) << 8)
+ + (abPrecbuf[(iPrecstart + 3) % CRECBUFLEN] & 0xff));
+
+ if (cinbuf < clen + CTFRAMELEN)
+ {
+ if (pcneed != NULL)
+ *pcneed = clen + CTFRAMELEN - cinbuf;
+ return TRUE;
+ }
+
+ iPrecstart = (iPrecstart + CTFRAMELEN) % CRECBUFLEN;
+
+ cfirst = CRECBUFLEN - iPrecstart;
+ if (cfirst > clen)
+ cfirst = clen;
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "ftprocess_data: Got %d data bytes",
+ clen);
+
+ if (! fgot_data (qdaemon, abPrecbuf + iPrecstart,
+ (size_t) cfirst, abPrecbuf, (size_t) (clen - cfirst),
+ -1, -1, (long) -1, TRUE, pfexit))
+ return FALSE;
+
+ iPrecstart = (iPrecstart + clen) % CRECBUFLEN;
+
+ if (*pfexit)
+ return TRUE;
+
+ cinbuf -= clen + CTFRAMELEN;
+ }
+
+ if (pcneed != NULL)
+ *pcneed = CTFRAMELEN - cinbuf;
+
+ return TRUE;
+}
+
+/* Wait for data to come in and process it until we've reached the end
+ of a command or a file. */
+
+boolean
+ftwait (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ while (TRUE)
+ {
+ boolean fexit;
+ size_t cneed, crec;
+
+ if (! ftprocess_data (qdaemon, &fexit, &cneed))
+ return FALSE;
+ if (fexit)
+ return TRUE;
+
+ if (! freceive_data (qdaemon->qconn, cneed, &crec, cTtimeout, TRUE))
+ return FALSE;
+
+ if (crec == 0)
+ {
+ ulog (LOG_ERROR, "Timed out waiting for data");
+ return FALSE;
+ }
+ }
+}
+
+/* File level routine, to set fTfile correctly. */
+
+/*ARGSUSED*/
+boolean
+ftfile (qdaemon, qtrans, fstart, fsend, cbytes, pfhandled)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+ boolean fstart;
+ boolean fsend;
+ long cbytes;
+ boolean *pfhandled;
+{
+ *pfhandled = FALSE;
+
+ if (! fsend)
+ fTfile = fstart;
+
+ return TRUE;
+}
diff --git a/gnu/libexec/uucp/uucico/protz.c b/gnu/libexec/uucp/uucico/protz.c
new file mode 100644
index 00000000000..e593e07e5b0
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/protz.c
@@ -0,0 +1,2626 @@
+/* protz.c Version 1.5, 92Apr24 */
+/* Modified by Ian Lance Taylor for Taylor UUCP 1.04 92Aug4. */
+
+/*
+ * Doug Evans, dje@sspiff.UUCP or dje@ersys.edmonton.ab.ca
+ *
+ * This file provides the Zmodem protocol (by Chuck Forsberg) for
+ * Ian Taylor's UUCP package.
+ *
+ * It was originally developed to establish a uucp link between myself and my
+ * employer: Ivation Datasystems, Inc. of Ottawa.
+ *
+ * My thanks to Ivation for letting me release this to the public. Given that
+ * Zmodem is in the public domain, no additional copyrights have been added.
+ *
+ *****************************************************************************
+ *
+ * It's been difficult fitting Zmodem into the UUCP world. I have been guided
+ * mostly by trying to plug it into Taylor UUCP. Where "the Zmodem way of doing
+ * things" conflicted with "the UUCP way of doing things", I have err'd on the
+ * side of UUCP. At the end of it all, I have achieved something that will plug
+ * into Taylor UUCP very easily, but some might argue that I have corrupted Z
+ * too much. At any rate, compatibility with sz/rz was sacrificed to achieve a
+ * clean UUCP protocol. Given that, I took the opportunity to start from
+ * scratch when defining protocol constants (EG: ZBIN).
+ *
+ * 1) I wasn't quite sure how to enhance Zmodem to handle send+receive in one
+ * session, so I added a 'g' protocol like initialization sequence. This
+ * also gets this stuff out of the way, in case we ever try to support
+ * full-duplex.
+ *
+ * Caller Callee
+ * ------ ------
+ * ZINIT --> <-- ZINIT
+ * ZDATA (ZCRCF) --> <-- ZDATA (ZCRCF)
+ * ZACK --> <-- ZACK
+ * ZINITEND --> <-- ZINITEND
+ *
+ * ZINIT is a combination of ZRINIT and ZSINIT and is intended to exchange
+ * simple protocol information (flags) and the protocol version number.
+ * ZDATA is intended to include window size information as well as the
+ * "Myattn" string (although at the moment it doesn't contain anything).
+ * ZDATA may contain at most 1k bytes of data and is sent out as one ZCRCF
+ * packet. Two ack's (ZACK + ZINITEND) are needed to ensure both sides have
+ * received ZDATA.
+ *
+ * 2) I've hardcoded several protocol parameters, like 32 bit CRC's for data.
+ * Others are not supported (we don't need them).
+ *
+ * 3) ZHEX headers use 32 bit CRC's.
+ *
+ * 4) Zmodem sends the ZFILE message "in one chunk". If there are errors, the
+ * entire string is resent. I have continued this practice. All UUCP
+ * commands are sent "in one chunk". This can be changed down the road if
+ * necessary.
+ *
+ * 5) The ZEOF message has been replaced with a new ZCRCx value: ZCRCF. ZCRCF
+ * is identical to ZCRCW except that it indicates the end of the message.
+ * The protocol here is *not* a file transfer protocol. It is an end to end
+ * transport protocol (that preserves message boundaries).
+ *
+ * 6) Zmodem handles restarting a file transfer, but as best as I can tell UUCP
+ * does not. At least Taylor UUCP doesn't. And if UUCP does start handling
+ * file restart, can it be plugged into the existing Zmodem way with zero
+ * changes? Beats me. Therefore I have removed this part of the code. One
+ * can always put it back in if and when UUCP handles it. Ditto for other
+ * pieces of removed code: there's no point in overly complicating this code
+ * when supporting all the bells and whistles requires enhancements to UUCP
+ * itself.
+ *
+ * *** It is easier to put code back in in an upward compatible manner ***
+ * *** than it is to correct for misunderstood code or poorly merged ***
+ * *** (Zmodem vs UUCP) code. ***
+ *
+ * 7) For the character in the initial "protocol selection" sequence, I have
+ * chosen 'a'. I'm told 'z' is already in use for something that isn't
+ * Zmodem. It's entirely reasonable to believe that if Zmodem ever becomes a
+ * standard UUCP protocol, this won't be it (so I'll leave z/Z for them).
+ * Publicly, this is the 'a' protocol. Internally, it is refered to as 'z'.
+ * A little confusing, I know. Maybe in time I'll refer to it internally as
+ * 'a', or maybe in time this will be *the* 'z' protocol.
+ *
+ * 8) Since we are writing a transport protocol, which isn't supposed to know
+ * anything about what is being transfered or where it is coming from, the
+ * header data value has changed meaning. It no longer means "file position"
+ * but instead means "window position". It is a running counter of the bytes
+ * transfered. Each "message" begins on a 1k boundary so the count isn't a
+ * precise byte count. The counter wraps every 4 gigabytes, although this
+ * wrapping isn't supported yet.
+ *
+ * FIXME: At present the max data transfered per session is 4 gigabytes.
+ *
+ ****************************************************************************
+ *
+ * A typical message sequence is (master sending file to slave):
+ *
+ * Master Slave
+ * ------ -----
+ * ZDATA (S, ZCRCF) -->
+ * <-- ZACK
+ * <-- ZDATA (SY, ZCRCF)
+ * ZACK -->
+ * ZDATA -->
+ * ... <-- ZACK/ZRPOS
+ * ZDATA (ZCRCF) -->
+ * <-- ZACK
+ * <-- ZDATA (CY, ZCRCF)
+ * ZACK -->
+ *
+ * A typical message sequence is (master receiving file from slave):
+ *
+ * Master Slave
+ * ------ -----
+ * ZDATA (R, ZCRCF) -->
+ * <-- ZACK
+ * <-- ZDATA (RY, ZCRCF)
+ * ZACK -->
+ * <-- ZDATA
+ * ZACK/ZRPOS ... -->
+ * <-- ZDATA (ZCRCF)
+ * ZACK -->
+ * ZDATA (CY, ZCRCF) -->
+ * <-- ZACK
+ *
+ *****************************************************************************
+ *
+ * Notes:
+ * 1) For future bidirectional concerns, keep packet types "unidirectional".
+ * Sender always uses: ZDATA, ZNAK
+ * Receiver always uses: ZRPOS, ZACK
+ * There is no intersection.
+ *
+ * I'm not sure if this is necessary or even useful, but it seems to be.
+ *
+ * 2) I use to store the byte count / 32 in the data header. This left 5 bits
+ * unused for future concerns. I removed this because of the following
+ * situation when sending a file:
+ *
+ * ZDATA (ZCRCG, xx bytes) - received ok
+ * ZDATA (ZCRCF, 0 bytes) - corrupted
+ *
+ * At this point the receiver would like to send back a ZRPOS with a value
+ * of the size of the file. However, it can't because the value is divided
+ * by 32, and it would have to round up to the next multiple of 32. This
+ * seemed a little ugly, so I went with using the entire header to store
+ * the byte count.
+ *
+ *****************************************************************************
+ *
+ * Source version:
+ *
+ * 1.1,2,3
+ * Protocol version 0
+ * Early attempts, completely rewritten later.
+ *
+ * 1.4 Protocol version 1
+ * Beta test sent to Ian for analysis 92Apr18.
+ *
+ * 1.5 Protocol version 1
+ * Released 92Apr24.
+ *
+ *****************************************************************************
+ *
+ * Protocol version:
+ *
+ * A version number is exchanged in the ZINIT message, so it is possible to
+ * correct or enhance the protocol, without breaking existing versions.
+ * The purpose of this section is to document these versions as they come out.
+ * Remember, this is the protocol version, not the source version.
+ *
+ * 0 Initial version.
+ * Zmodem controlled file transfer. This was more of a "plug Z
+ * into UUCP as is" port.
+ *
+ * 1 Complete rewrite.
+ * Made Z more of a transport protocol. UUCP now controls transfer and Z
+ * is on the same footing as the other UUCP protocols.
+ * Theoretically, there will be little pain when UUCP goes bidirectional.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char protz_rcsid[] = "$Id: protz.c,v 1.1 1993/08/04 19:36:25 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "conn.h"
+#include "trans.h"
+#include "system.h"
+#include "prot.h"
+
+#define ZPROTOCOL_VERSION 1
+
+/*
+ * Control message characters ...
+ */
+
+#define ZPAD '*' /* Padding character begins frames */
+#define ZDLE 030 /* Ctrl-X Zmodem escape - `ala BISYNC DLE */
+#define ZBIN 'A' /* Binary frame indicator */
+#define ZHEX 'B' /* HEX frame indicator */
+
+/*
+ * Frame types (see array "frametypes" in zm.c) ...
+ *
+ * Note that the numbers here have been reorganized, as we don't support
+ * all of them (nor do we need to).
+ *
+ * WARNING: The init sequence assumes ZINIT < ZDATA < ZACK < ZINITEND.
+ */
+
+#define ZINIT 0 /* Init (contains protocol version, flags) */
+#define ZDATA 1 /* Data packet(s) follow */
+#define ZRPOS 2 /* Resume data trans at this position */
+#define ZACK 3 /* ACK to above */
+#define ZNAK 4 /* Last packet was garbled */
+#define Zreserved 5 /* reserved (for future concerns) */
+#define ZINITEND 6 /* end of init sequence */
+#define ZFIN 7 /* Finish session */
+
+/*
+ * ZDLE sequences ...
+ *
+ * Note addition of ZCRCF: "end of message".
+ */
+
+#define ZCRCE 'h' /* CRC next, frame ends, header packet follows */
+#define ZCRCG 'i' /* CRC next, frame continues nonstop */
+#define ZCRCQ 'j' /* CRC next, frame continues, ZACK expected */
+#define ZCRCW 'k' /* CRC next, ZACK expected, end of frame */
+#define ZCRCF 'l' /* CRC next, ZACK expected, end of message */
+
+#define ZRUB0 'm' /* Translate to rubout 0177 */
+#define ZRUB1 'n' /* Translate to rubout 0377 */
+
+
+/*
+ * zdlread return values (internal) ...
+ * Other values are ZM_ERROR, ZM_TIMEOUT, ZM_RCDO.
+ */
+
+#define GOTOR 0400
+#define GOTCRCE (ZCRCE | GOTOR) /* ZDLE-ZCRCE received */
+#define GOTCRCG (ZCRCG | GOTOR) /* ZDLE-ZCRCG received */
+#define GOTCRCQ (ZCRCQ | GOTOR) /* ZDLE-ZCRCQ received */
+#define GOTCRCW (ZCRCW | GOTOR) /* ZDLE-ZCRCW received */
+#define GOTCRCF (ZCRCF | GOTOR) /* ZDLE-ZCRCF received */
+
+/*
+ * Byte positions within header array ...
+ */
+
+#define ZF0 3 /* First flags byte */
+#define ZF1 2
+#define ZF2 1
+#define ZF3 0
+
+#define ZP0 0 /* Low order 8 bits of position */
+#define ZP1 1
+#define ZP2 2
+#define ZP3 3 /* High order 8 bits of position */
+
+/*
+ * Bit Masks for ZRQINIT flags byte ZF0 ...
+ */
+
+#define TX_ESCCTL 1 /* Tx will escape control chars */
+
+/*
+ * Possible errors when running ZMODEM ...
+ */
+
+#define ZM_ERROR (-1) /* crc error, etc. */
+#define ZM_TIMEOUT (-2)
+#define ZM_RCDO (-3) /* Carrier Lost */
+
+/*
+ * ASCII characters ...
+ */
+
+#define LF 012
+#define CR 015
+#define XON 021
+#define XOFF 023
+
+#define XON_WAIT 10 /* seconds */
+
+/*
+ * Packet sizes ...
+ *
+ * FIXME: CPACKETSIZE is hardcoded in a lot of places.
+ * It's not clear to me whether changing it's value would be a
+ * "good thing" or not. But of course that doesn't excuse the hardcoding.
+ */
+
+#define CPACKETSIZE 1024 /* max packet size (data only) */
+#define CFRAMELEN 12 /* header size */
+#define CSUFFIXLEN 10 /* suffix at end of data packets */
+#define CEXCHANGE_INIT_RETRIES 4
+
+/* The header CRC value. */
+
+#if ANSI_C
+#define IHDRCRC 0xDEBB20E3UL
+#else
+#define IHDRCRC ((unsigned long) 0xDEBB20E3L)
+#endif
+
+/* packet buffer size */
+#define CPACKBUFSIZE (CFRAMELEN + 2 * CPACKETSIZE + CSUFFIXLEN + 42 /*slop*/)
+
+/*
+ * Data types ...
+ */
+
+typedef unsigned char achdrval_t[4];
+typedef unsigned long hdrval_t;
+typedef unsigned long winpos_t;
+
+/*
+ * Configurable parms ...
+ *
+ * FIXME: <cZrx_buf_len> isn't used yet. It may not be needed.
+ */
+
+#define CTIMEOUT 10
+#define CRETRIES 10
+#define CSTARTUP_RETRIES 4
+#define CGARBAGE 2400
+#define CSEND_WINDOW 16384
+#define FESCAPE_CONTROL FALSE
+
+static int cZtimeout = CTIMEOUT; /* (seconds) */
+static int cZretries = CRETRIES;
+static int cZstartup_retries = CSTARTUP_RETRIES;
+static int cZmax_garbage = CGARBAGE; /* max garbage before header */
+static int cZtx_window = CSEND_WINDOW; /* our transmission window */
+static int cZrx_buf_len = 0; /* our reception buffer size */
+static boolean fZesc_ctl = FESCAPE_CONTROL; /* escape control chars */
+
+struct uuconf_cmdtab asZproto_params[] =
+{
+ {"timeout", UUCONF_CMDTABTYPE_INT, (pointer) & cZtimeout, NULL},
+ {"retries", UUCONF_CMDTABTYPE_INT, (pointer) & cZretries, NULL},
+ {"startup-retries", UUCONF_CMDTABTYPE_INT,
+ (pointer) & cZstartup_retries, NULL},
+ {"garbage", UUCONF_CMDTABTYPE_INT, (pointer) & cZmax_garbage, NULL},
+ {"send-window", UUCONF_CMDTABTYPE_INT, (pointer) & cZtx_window, NULL},
+ {"escape-control", UUCONF_CMDTABTYPE_BOOLEAN, (pointer) & fZesc_ctl,
+ NULL},
+ {NULL, 0, NULL, NULL}
+};
+
+/*
+ * Variables for statistic gathering ...
+ *
+ * We use <wpZtxpos, wpZrxbytes> to record the number of "packets"
+ * sent/received. Packets is in double quotes because some of them aren't full.
+ */
+
+static unsigned long cZheaders_sent;
+static unsigned long cZheaders_received;
+static unsigned long cZbytes_resent;
+static unsigned long cZtimeouts;
+static unsigned long cZerrors;
+
+/*
+ * Data buffers ...
+ */
+
+static char *zZtx_buf; /* transmit buffer */
+
+static char *zZtx_packet_buf; /* raw outgoing packet data */
+static char *zZrx_packet_buf; /* raw incoming packet data */
+
+/*
+ * Transmitter state variables ...
+ */
+
+static unsigned cZblklen; /* data length in sent/received packets */
+static unsigned cZtxwspac; /* spacing between ZCRCQ requests */
+/*static unsigned cZblklen_override;*//* override value for <cZblklen> */
+static unsigned cZtxwcnt; /* counter used to space ack requests */
+static unsigned cZrxwcnt; /* counter used to watch receiver's buf size */
+static winpos_t wpZtxstart; /* <wpZtxpos> when message started */
+static winpos_t wpZtxpos; /* transmitter position */
+static winpos_t wpZlastsync; /* last offset to which we got a ZRPOS */
+static winpos_t wpZlrxpos; /* receiver's last reported offset */
+static winpos_t wpZrxpos; /* receiver file position */
+
+static int iZlast_tx_data_packet; /* type of last ZDATA packet (ZCRCx) */
+static int iZjunk_count; /* amount of garbage characters received */
+static int iZtleft; /* for dynamic packet resizing */
+
+static int iZbeenhereb4; /* times we've been ZRPOS'd to same place */
+
+/*
+ * Receiver state variables ...
+ */
+
+static winpos_t wpZrxbytes; /* receiver byte count */
+static int iZlast_rx_data_packet; /* last successfully received ZCRCx packet */
+
+/*
+ * Misc. globals ...
+ */
+
+static char xon = XON;
+
+#ifdef DJE_TESTING
+int uucptest = -1;
+int uucptest2;
+int uucptestseed;
+#endif
+
+/*
+ * Kludge!!!
+ * See fzfinish_tx(). Basically the next two globals are used to record the
+ * fact that we got a ZDATA, but aren't quite ready to process it.
+ */
+
+static int iZpkt_rcvd_kludge; /* -1 if not valid */
+static hdrval_t hvZpkt_hdrval_kludge;
+
+/*
+ * Packet types ...
+ */
+
+static const char *azZframe_types[] = {
+ "Carrier Lost", /* -3 */
+ "Timeout", /* -2 */
+ "Error", /* -1 */
+#define FTOFFSET 3
+ "ZINIT",
+ "ZDATA",
+ "ZRPOS",
+ "ZACK",
+ "ZNAK",
+ "Zreserved",
+ "ZINITEND",
+ "ZFIN",
+ "UNKNOWN!!!"
+};
+#define FTNUMBER (sizeof(azZframe_types) / sizeof(char *))
+
+#ifndef min
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#endif
+#define ZZHEADER_NAME(itype) \
+ azZframe_types[min((itype) + FTOFFSET, FTNUMBER - 1)]
+
+/*
+ * Local functions ...
+ */
+
+static boolean fzsend_data P((struct sdaemon *qdaemon, char *zdata,
+ size_t cdata, boolean fendofmessage));
+static boolean fzprocess P((struct sdaemon *qdaemon));
+static boolean fzstart_proto P((struct sdaemon *qdaemon));
+static int izexchange_init P((struct sdaemon *qdaemon, int send_type,
+ achdrval_t send_val, achdrval_t recv_val));
+static boolean fzshutdown_proto P((struct sdaemon *qdaemon));
+static boolean fzstart_tx P((void));
+static boolean fzfinish_tx P((struct sdaemon *qdaemon, long *plredo));
+static boolean fzstart_rx P((void));
+static boolean fzfinish_rx P((struct sdaemon *qdaemon));
+static boolean fzsend_hdr P((struct sdaemon *qdaemon, int ipkttype,
+ int ihdrtype, hdrval_t hdrval,
+ boolean fcheckreceive));
+static boolean fzsend_data_packet P((struct sdaemon *qdaemon, char *zdata,
+ size_t cdata, int frameend,
+ boolean fcheckreceive));
+static int czbuild_header P((char *zresult, int ipkttype, int ihdrtype,
+ hdrval_t hdrval));
+static int czbuild_data_packet P((char *zresult, const char *zdata,
+ size_t cdata, int frameend));
+/*
+ * The rest of the functions do not follow Ian's naming style. I have left
+ * the names the same as the original zm source. Over time, they may change.
+ */
+static int izrecv_hdr P((struct sdaemon *qdaemon, achdrval_t hdr));
+static int zrbhdr32 P((struct sdaemon *qdaemon, achdrval_t hdr));
+static int zrhhdr P((struct sdaemon *qdaemon, achdrval_t hdr));
+static int zrdat32 P((struct sdaemon *qdaemon, char *buf, int length,
+ int *iprxcount));
+static int getinsync P((struct sdaemon *qdaemon, boolean flag));
+static char *zputhex P((char *p, int ch));
+static char *zputchar P((char *p, int ch));
+static int zgethex P((struct sdaemon *qdaemon));
+static int zdlread P((struct sdaemon *qdaemon));
+static int noxrd7 P((struct sdaemon *qdaemon));
+static int realreadchar P((struct sdaemon *qdaemon, int timeout));
+static boolean fzreceive_ready P((void));
+static void stohdr P((hdrval_t pos, achdrval_t hdr));
+static hdrval_t rclhdr P((achdrval_t hdr));
+static hdrval_t hvzencode_data_hdr P((winpos_t cbytes));
+static void zdecode_data_hdr P((hdrval_t hdrval, winpos_t *pcbytes));
+static winpos_t lzupdate_rxpos P((achdrval_t rx_hdr, winpos_t rxpos,
+ winpos_t lrxpos, winpos_t txpos));
+
+/*
+ * This macro replaces readchar() because it achieves a noticable speed up. The
+ * readchar() function has been renamed realreadchar(). Thanks to Ian for
+ * running this stuff through a profiler to find this out. Ian suggests further
+ * speed ups may be obtained by doing a similar thing in zrdat32().
+ */
+
+/* Assign the next character to b. */
+#define READCHAR(qdaemon, b, i) \
+ (iPrecstart != iPrecend \
+ ? ((b) = BUCHAR (abPrecbuf[iPrecstart]), \
+ iPrecstart = (iPrecstart + 1) % CRECBUFLEN) \
+ : ((b) = realreadchar ((qdaemon), (i))))
+
+/************************************************************************/
+
+
+/*
+ * Start the protocol ...
+ */
+
+boolean
+fzstart(qdaemon, pzlog)
+struct sdaemon *qdaemon;
+char **pzlog;
+{
+ *pzlog = zbufalc (sizeof "protocol 'a' starting: , , , , , " + 100);
+ sprintf (*pzlog, "protocol 'a' starting: %d, %d, %d, %d, %d, %d",
+ cZtimeout, cZretries, cZstartup_retries,
+ cZmax_garbage, cZtx_window, fZesc_ctl);
+
+ if (! fconn_set (qdaemon->qconn, PARITYSETTING_NONE,
+ STRIPSETTING_EIGHTBITS, XONXOFF_OFF))
+ return FALSE;
+
+ /*
+ * For now, we place tight restrictions on the size of the transmit
+ * window. This might be relaxed in the future. If it is relaxed,
+ * some of these tests will stay, some will go. That is why it is
+ * coded like it is.
+ */
+
+ if (cZtx_window % 1024 != 0 ||
+ cZtx_window < 4096 || cZtx_window > 65536 ||
+ 65536 % cZtx_window != 0
+ ) {
+ ulog (LOG_ERROR,
+ "fzstart: cZtx_window not one of 4096, 8192, 16384, 32768, 65536");
+ return FALSE;
+ }
+
+ zZtx_buf = (char *) xmalloc (CPACKETSIZE);
+ zZtx_packet_buf = (char *) xmalloc (CPACKBUFSIZE);
+ zZrx_packet_buf = (char *) xmalloc (CPACKBUFSIZE);
+
+ iZlast_tx_data_packet = -1;
+ iZlast_rx_data_packet = -1;
+
+ wpZtxpos = wpZlrxpos = wpZrxpos = wpZrxbytes = 0;
+ cZtxwspac = cZtx_window / 4;
+
+ cZheaders_sent = cZheaders_received = cZbytes_resent = 0;
+ cZtimeouts = cZerrors = 0;
+
+ iZpkt_rcvd_kludge = -1;
+
+#if 0
+ /*
+ * We ensure <cZtx_window> is at least 4k, so the following is
+ * unnecessary. It can be put back in later if needed.
+ */
+ if (cZblklen_override > cZtxwspac
+ || (!cZblklen_override && cZtxwspac < 1024))
+ cZblklen_override = cZtxwspac;
+#endif
+
+#ifdef DJE_TESTING
+ {
+ extern int uucptest,uucptest2,uucptestseed;
+ FILE *f;
+
+ if (uucptest == -1) {
+ f = fopen ("/usr/local/src/bin/uucp/uucptest", "r");
+ if (f != NULL) {
+ fscanf (f, "%d %d %d",
+ &uucptestseed, &uucptest, &uucptest2);
+ fclose (f);
+ }
+ srand (uucptestseed);
+ }
+ }
+#endif
+
+ /*
+ * Fire up the protocol (exchange init messages) ...
+ */
+
+ if (!fzstart_proto (qdaemon))
+ return FALSE;
+
+ return TRUE;
+}
+
+/*
+ * Stop the protocol ...
+ */
+
+boolean
+fzshutdown(qdaemon)
+struct sdaemon *qdaemon;
+{
+ (void) fzshutdown_proto (qdaemon);
+
+ xfree ((pointer) zZtx_buf);
+ xfree ((pointer) zZtx_packet_buf);
+ xfree ((pointer) zZrx_packet_buf);
+ zZtx_buf = NULL;
+ zZtx_packet_buf = NULL;
+ zZrx_packet_buf = NULL;
+
+ /*
+ * Print some informative statistics ...
+ *
+ * I use the word "messages" here instead of "headers" because the
+ * latter is jargonese.
+ */
+
+ ulog (LOG_NORMAL,
+ "Protocol 'a' messages: sent %lu, received %lu",
+ cZheaders_sent, cZheaders_received);
+ ulog (LOG_NORMAL,
+ "Protocol 'a' packets: sent %lu, received %lu",
+ wpZtxpos / 1024, wpZrxbytes / 1024);
+ if (cZbytes_resent != 0 || cZtimeouts != 0 || cZerrors != 0)
+ ulog (LOG_NORMAL,
+ "Protocol 'a' errors: bytes resent %lu, timeouts %lu, errors %lu",
+ cZbytes_resent, cZtimeouts, cZerrors);
+
+ /*
+ * Reset all the parameters to their default values, so that the
+ * protocol parameters used for this connection do not affect the
+ * next one.
+ */
+
+ cZtimeout = CTIMEOUT;
+ cZretries = CRETRIES;
+ cZstartup_retries = CSTARTUP_RETRIES;
+ cZmax_garbage = CGARBAGE;
+ cZtx_window = CSEND_WINDOW;
+ fZesc_ctl = FESCAPE_CONTROL;
+
+ cZheaders_sent = cZheaders_received = cZbytes_resent = 0;
+ cZtimeouts = cZerrors = 0;
+
+ return TRUE;
+}
+
+/*
+ * Send a command string ...
+ * We send everything up to and including the null byte.
+ *
+ * We assume the command will fit in the outgoing data buffer.
+ * FIXME: A valid assumption?
+ */
+
+/*ARGSUSED*/
+boolean
+fzsendcmd(qdaemon, z, ilocal, iremote)
+struct sdaemon *qdaemon;
+const char *z;
+int ilocal;
+int iremote;
+{
+ size_t n,clen;
+ long lredo;
+ char *zbuf;
+
+ clen = strlen (z) + 1;
+
+ DEBUG_MESSAGE1 (DEBUG_PROTO, "fzsendcmd: sending command %s", z);
+
+ if (!fzstart_tx ()) /* must be called before zzgetspace() */
+ return FALSE;
+
+ if ((zbuf = zzgetspace (qdaemon, &n)) == NULL)
+ return FALSE;
+
+#if DEBUG > 0
+ if (clen > n)
+ ulog (LOG_FATAL, "fzsendcmd: clen > n");
+#endif
+
+ strcpy (zbuf, z);
+
+ /*
+ * Send it out ...
+ */
+
+ do {
+ if (!fzsend_data (qdaemon, zbuf, clen, TRUE))
+ return FALSE;
+ if (!fzfinish_tx (qdaemon, &lredo))
+ return FALSE;
+ } while (lredo >= 0);
+
+ return fzprocess (qdaemon);
+}
+
+/*
+ * Allocate a packet to send out ...
+ *
+ * Note that 'z' has dynamic packet resizing and that <cZblklen> will range
+ * from 32 to 1024, in multiples of 2.
+ */
+
+/*ARGSUSED*/
+char *
+zzgetspace(qdaemon, pclen)
+struct sdaemon *qdaemon;
+size_t *pclen;
+{
+ *pclen = cZblklen;
+ return zZtx_buf;
+}
+
+/*
+ * Send a block of data ...
+ *
+ * If (cdata == 0) then the end of the file has been reached.
+ */
+
+/*ARGSUSED*/
+boolean
+fzsenddata(qdaemon, zdata, cdata, ilocal, iremote, ipos)
+struct sdaemon *qdaemon;
+char *zdata;
+size_t cdata;
+int ilocal;
+int iremote;
+long ipos;
+{
+ DEBUG_MESSAGE1 (DEBUG_PROTO, "fzsenddata: %d bytes", cdata);
+
+ if (! fzsend_data (qdaemon, zdata, cdata, cdata == 0))
+ return FALSE;
+ return fzprocess (qdaemon);
+}
+
+/*
+ * Send a block of data (command or file) ...
+ */
+
+/* This should buffer the data internally. Until it does, it needs to
+ be able to reset the file position when it is called. This is
+ really ugly. */
+extern struct stransfer *qTsend;
+
+static boolean
+fzsend_data(qdaemon, zdata, cdata, fendofmessage)
+struct sdaemon *qdaemon;
+char *zdata;
+size_t cdata;
+boolean fendofmessage;
+{
+ size_t n;
+
+ if (iZlast_tx_data_packet == -1 || iZlast_tx_data_packet == ZCRCW) {
+ cZtxwcnt = cZrxwcnt = 0;
+ iZjunk_count = 0;
+ if (!fzsend_hdr (qdaemon, ZBIN, ZDATA,
+ hvzencode_data_hdr (wpZtxpos), TRUE))
+ return FALSE;
+ }
+
+ n = cdata;
+
+ if (fendofmessage)
+ iZlast_tx_data_packet = ZCRCF;
+ else if (iZjunk_count > 3)
+ iZlast_tx_data_packet = ZCRCW;
+ else if (wpZtxpos == wpZlastsync)
+ iZlast_tx_data_packet = ZCRCW;
+ else if (cZrx_buf_len && (cZrxwcnt += n) >= cZrx_buf_len)
+ iZlast_tx_data_packet = ZCRCW;
+ else if ((cZtxwcnt += n) >= cZtxwspac) {
+ iZlast_tx_data_packet = ZCRCQ;
+ cZtxwcnt = 0;
+ } else
+ iZlast_tx_data_packet = ZCRCG;
+
+ if (++iZtleft > 3) {
+ iZtleft = 0;
+ if (cZblklen < 1024)
+ cZblklen *= 2;
+#if 0 /* <cZblklen_override> is currently unnecessary */
+ if (cZblklen_override && cZblklen > cZblklen_override)
+ cZblklen = cZblklen_override;
+#endif
+ if (cZblklen > 1024)
+ cZblklen = 1024;
+ if (cZrx_buf_len && cZblklen > cZrx_buf_len)
+ cZblklen = cZrx_buf_len;
+ }
+
+#if DEBUG > 1
+ if (FDEBUGGING(DEBUG_PROTO)) {
+ const char *type;
+
+ switch (iZlast_tx_data_packet) {
+ case ZCRCW: type = "ZCRCW"; break;
+ case ZCRCG: type = "ZCRCG"; break;
+ case ZCRCQ: type = "ZCRCQ"; break;
+ case ZCRCE: type = "ZCRCE"; break;
+ case ZCRCF: type = "ZCRCF"; break;
+ default : type = "UNKNOWN!!!"; break;
+ }
+ DEBUG_MESSAGE3 (DEBUG_PROTO,
+ "fzsend_data: %s, pos 0x%lx, %d bytes",
+ type, wpZtxpos, n);
+ }
+#endif
+
+ if (!fzsend_data_packet (qdaemon, zdata, n, iZlast_tx_data_packet,
+ TRUE))
+ return FALSE;
+
+ wpZtxpos += n;
+
+ if (iZlast_tx_data_packet == ZCRCW) {
+ /*
+ * FIXME: Ideally this would be done in fzprocess. However, it
+ * is only called if there is data pending which there
+ * may not be yet. I could have patched fploop() a bit but
+ * for now, I've done it like this.
+ */
+ switch (getinsync (qdaemon, FALSE)) {
+ case ZACK:
+ break;
+ case ZRPOS:
+ if (qTsend == NULL
+ || ! ffileisopen (qTsend->e)) {
+ ulog (LOG_ERROR, "Can't reset non-file");
+ return FALSE;
+ }
+ iZlast_tx_data_packet = -1; /* trigger ZDATA */
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "fzsend_data: Seeking to %ld",
+ (long) (wpZrxpos - wpZtxstart));
+ if (!ffileseek (qTsend->e, wpZrxpos - wpZtxstart)) {
+ ulog (LOG_ERROR, "seek: %s", strerror (errno));
+ return FALSE;
+ }
+ break;
+ default:
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ /*
+ * If we've reached the maximum transmit window size, let the
+ * receiver catch up ...
+ *
+ * I use (cZtx_window - 2048) to play it safe.
+ */
+
+ while (wpZtxpos - wpZlrxpos >= cZtx_window - 2048) {
+ if (iZlast_tx_data_packet != ZCRCQ) {
+ if (!fzsend_data_packet (qdaemon, zdata, (size_t) 0,
+ iZlast_tx_data_packet = ZCRCQ,
+ TRUE))
+ return FALSE;
+ }
+ /*
+ * FIXME: I'd rather not call ffileseek() in this file. When we
+ * start buffering the outgoing data, the following
+ * ffileseek() will disappear.
+ */
+ switch (getinsync (qdaemon, TRUE)) {
+ case ZACK:
+ break;
+ case ZRPOS:
+ if (qTsend == NULL
+ || ! ffileisopen (qTsend->e)) {
+ ulog (LOG_ERROR, "Can't reset non-file");
+ return FALSE;
+ }
+ iZlast_tx_data_packet = -1; /* trigger ZDATA */
+ DEBUG_MESSAGE1 (DEBUG_PROTO,
+ "fzsend_data: Seeking to %ld",
+ (long) (wpZrxpos - wpZtxstart));
+ if (!ffileseek (qTsend->e, wpZrxpos - wpZtxstart)) {
+ ulog (LOG_ERROR, "seek: %s", strerror (errno));
+ return FALSE;
+ }
+ break;
+ default:
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/*
+ * Process existing data ...
+ */
+
+static boolean
+fzprocess(qdaemon)
+struct sdaemon *qdaemon;
+{
+ int c,ch;
+
+ while (fzreceive_ready ()) {
+ READCHAR (qdaemon, ch, 1);
+ switch (ch) {
+ case ZPAD:
+ /* see if we're detecting ZRPOS packets quickly */
+ DEBUG_MESSAGE0 (DEBUG_PROTO,
+ "fzprocess: possible ZRPOS packet");
+ /* We just ate the ZPAD char that getinsync
+ expects, so put it back. */
+ iPrecstart = ((iPrecstart + CRECBUFLEN - 1)
+ % CRECBUFLEN);
+ c = getinsync (qdaemon, TRUE);
+ if (c == ZACK)
+ break;
+ /* FIXME: sz does a TCFLSH here */
+#if 0 /* FIXME: Not sure if this is needed, or where to put it. */
+ /* ZCRCE - dinna wanna starta ping-pong game */
+ if (!fzsend_data_packet (qdaemon, zZtx_packet_buf,
+ 0, ZCRCE, TRUE))
+ return FALSE;
+#endif
+ if (c == ZRPOS) {
+ if (qTsend == NULL
+ || ! ffileisopen (qTsend->e)) {
+ ulog (LOG_ERROR,
+ "Attempt to back up non-file");
+ return FALSE;
+ }
+ if (! ffileseek (qTsend->e,
+ wpZrxpos - wpZtxstart)) {
+ ulog (LOG_ERROR,
+ "seek: %s", strerror (errno));
+ return FALSE;
+ }
+ iZlast_tx_data_packet = -1; /* trigger ZDATA */
+ break; /* not returning is intentional */
+ }
+ return FALSE;
+ case XOFF:
+ case XOFF | 0200:
+ READCHAR (qdaemon, ch, XON_WAIT);
+ break;
+ case CR:
+ break;
+ default:
+ iZjunk_count++;
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+/*
+ * Wait for data to come in.
+ *
+ * This continues processing until a complete file or command has been
+ * received.
+ */
+
+boolean
+fzwait(qdaemon)
+struct sdaemon *qdaemon;
+{
+ int c,cerr,rxcount;
+ boolean fexit;
+ achdrval_t rx_hdr;
+
+ if (!fzstart_rx ())
+ return FALSE;
+
+ cerr = cZretries;
+
+ goto nxthdr;
+
+ for (;;) {
+ if (!fzsend_hdr (qdaemon, ZHEX, ZRPOS,
+ hvzencode_data_hdr (wpZrxbytes), FALSE))
+ return FALSE;
+nxthdr:
+ c = izrecv_hdr (qdaemon, rx_hdr);
+
+ switch (c) {
+ case ZM_TIMEOUT:
+ case ZNAK:
+ if (--cerr < 0) {
+ ulog (LOG_ERROR, "fzwait: retries exhausted");
+ return FALSE;
+ }
+ continue;
+ case ZM_ERROR:
+ if (--cerr < 0) {
+ ulog (LOG_ERROR, "fzwait: retries exhausted");
+ return FALSE;
+ }
+ /*fport_break ();*/
+ continue;
+ case ZM_RCDO:
+ case ZFIN:
+ return FALSE;
+ case ZRPOS:
+ case ZACK:
+ goto nxthdr; /* ignore, partner is out of sync */
+ case ZDATA: {
+ winpos_t rx_bytes;
+
+ zdecode_data_hdr (rclhdr (rx_hdr), &rx_bytes);
+ DEBUG_MESSAGE2 (DEBUG_PROTO,
+ "fzwait: bytes(us,them) 0x%lx,0x%lx",
+ wpZrxbytes, rx_bytes);
+ if (rx_bytes != wpZrxbytes) {
+ if (--cerr < 0) {
+ ulog (LOG_ERROR,
+ "fzwait: retries exhausted");
+ return FALSE;
+ }
+ (void) zrdat32 (qdaemon, zZrx_packet_buf,
+ 1024, &rxcount);
+ /*fport_break ();*/
+ /*
+ * FIXME: Seems to me we should ignore this one
+ * and go for a timeout, the theory being
+ * that the appropriate ZRPOS has already
+ * been sent. We're obviously out of sync.
+ * /dje 92Mar10
+ */
+ continue; /* goto nxthdr? */
+ }
+moredata:
+ /*
+ * Do not call fgot_data() with (rxcount == 0) if it's
+ * not ZCRCF. fgot_data() will erroneously think this
+ * is the end of the message.
+ */
+ c = zrdat32 (qdaemon, zZrx_packet_buf, 1024,
+ &rxcount);
+#if DEBUG > 1
+ if (FDEBUGGING(DEBUG_PROTO)) {
+ const char *msg;
+
+ if (c < 0) {
+ msg = ZZHEADER_NAME(c);
+ } else {
+ switch (c) {
+ case GOTCRCW: msg = "ZCRCW"; break;
+ case GOTCRCG: msg = "ZCRCG"; break;
+ case GOTCRCQ: msg = "ZCRCQ"; break;
+ case GOTCRCE: msg = "ZCRCE"; break;
+ case GOTCRCF: msg = "ZCRCF"; break;
+ default : msg = NULL; break;
+ }
+ }
+ if (msg != NULL)
+ DEBUG_MESSAGE2 (DEBUG_PROTO,
+ "fzwait: zrdat32: %s, %d bytes",
+ msg, rxcount);
+ else
+ DEBUG_MESSAGE2 (DEBUG_PROTO,
+ "fzwait: zrdat32: %d, %d bytes",
+ c, rxcount);
+ }
+#endif
+ switch (c) {
+ case ZM_ERROR: /* CRC error */
+ cZerrors++;
+ if (--cerr < 0) {
+ ulog (LOG_ERROR,
+ "fzwait: retries exhausted");
+ return FALSE;
+ }
+ /*fport_break ();*/
+ continue;
+ case ZM_TIMEOUT:
+ cZtimeouts++;
+ if (--cerr < 0) {
+ ulog (LOG_ERROR,
+ "fzwait: retries exhausted");
+ return FALSE;
+ }
+ continue;
+ case ZM_RCDO:
+ return FALSE;
+ case GOTCRCW:
+ iZlast_rx_data_packet = ZCRCW;
+ cerr = cZretries;
+ if (rxcount != 0
+ && !fgot_data (qdaemon, zZrx_packet_buf,
+ (size_t) rxcount,
+ (const char *) NULL,
+ (size_t) 0,
+ -1, -1, (long) -1,
+ TRUE, &fexit))
+ return FALSE;
+ wpZrxbytes += rxcount;
+ if (!fzsend_hdr (qdaemon, ZHEX, ZACK,
+ hvzencode_data_hdr (wpZrxbytes),
+ FALSE))
+ return FALSE;
+ if (! fsend_data (qdaemon->qconn, &xon,
+ (size_t) 1, FALSE))
+ return FALSE;
+ goto nxthdr;
+ case GOTCRCQ:
+ iZlast_rx_data_packet = ZCRCQ;
+ cerr = cZretries;
+ if (rxcount != 0
+ && !fgot_data (qdaemon, zZrx_packet_buf,
+ (size_t) rxcount,
+ (const char *) NULL,
+ (size_t) 0,
+ -1, -1, (long) -1,
+ TRUE, &fexit))
+ return FALSE;
+ wpZrxbytes += rxcount;
+ if (!fzsend_hdr (qdaemon, ZHEX, ZACK,
+ hvzencode_data_hdr (wpZrxbytes),
+ FALSE))
+ return FALSE;
+ goto moredata;
+ case GOTCRCG:
+ iZlast_rx_data_packet = ZCRCG;
+ cerr = cZretries;
+ if (rxcount != 0
+ && !fgot_data (qdaemon, zZrx_packet_buf,
+ (size_t) rxcount,
+ (const char *) NULL,
+ (size_t) 0,
+ -1, -1, (long) -1,
+ TRUE, &fexit))
+ return FALSE;
+ wpZrxbytes += rxcount;
+ goto moredata;
+ case GOTCRCE:
+ iZlast_rx_data_packet = ZCRCE;
+ cerr = cZretries;
+ if (rxcount != 0
+ && !fgot_data (qdaemon, zZrx_packet_buf,
+ (size_t) rxcount,
+ (const char *) NULL,
+ (size_t) 0,
+ -1, -1, (long) -1,
+ TRUE, &fexit))
+ return FALSE;
+ wpZrxbytes += rxcount;
+ goto nxthdr;
+ case GOTCRCF:
+ iZlast_rx_data_packet = ZCRCF;
+ /*
+ * fzfinish_rx() must be called before
+ * fgot_data() because fgot_data() will send
+ * out a UUCP-command but the sender won't be
+ * ready for it until it receives our final
+ * ZACK.
+ */
+ cerr = cZretries;
+ wpZrxbytes += rxcount;
+ if (!fzfinish_rx (qdaemon))
+ return FALSE;
+ if (!fgot_data (qdaemon, zZrx_packet_buf,
+ (size_t) rxcount,
+ (const char *) NULL,
+ (size_t) 0, -1, -1,
+ (long) -1, TRUE, &fexit))
+ return FALSE;
+ /*
+ * FIXME: Examine <fexit>?
+ * Or maybe ensure it's TRUE?
+ */
+ return TRUE;
+ }
+ return FALSE;
+ }
+ default:
+ ulog (LOG_FATAL, "fzwait: received header %s",
+ ZZHEADER_NAME(c));
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/*
+ * File level routine. Called when initiating/terminating file transfers.
+ *
+ * When starting to send a file: (TRUE, TRUE, cbytes)
+ * When starting to receive a file: (TRUE, FALSE, -1)
+ * When send EOF, check resend: (FALSE, TRUE, -1)
+ * When receive EOF, check re-receive: (FALSE, FALSE, -1)
+ */
+
+boolean
+fzfile(qdaemon, qtrans, fstart, fsend, cbytes, pfhandled)
+struct sdaemon *qdaemon;
+struct stransfer *qtrans;
+boolean fstart;
+boolean fsend;
+long cbytes;
+boolean *pfhandled;
+{
+ long iredo;
+
+ *pfhandled = FALSE;
+
+ DEBUG_MESSAGE2 (DEBUG_PROTO, "fzfile: fstart=%d, fsend=%d", fstart,
+ fsend);
+
+ if (fsend) {
+ if (fstart)
+ return fzstart_tx ();
+ if (! fzfinish_tx (qdaemon, &iredo))
+ return FALSE;
+ if (iredo >= 0) {
+ if (! ffileisopen (qtrans->e)) {
+ ulog (LOG_ERROR,
+ "Attempt to back up non-file");
+ return FALSE;
+ }
+ if (! ffileseek (qtrans->e, iredo)) {
+ ulog (LOG_ERROR,
+ "seek: %s", strerror (errno));
+ return FALSE;
+ }
+ *pfhandled = TRUE;
+ qtrans->fsendfile = TRUE;
+ return fqueue_send (qdaemon, qtrans);
+ }
+ }
+
+ return TRUE;
+}
+
+/****************************************************************************/
+
+
+#if 0 /* not used, we only use 32 bit crc's */
+/*
+ * crctab calculated by Mark G. Mendel, Network Systems Corporation
+ */
+
+static unsigned short crctab[256] = {
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+ 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+ 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+ 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+ 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+ 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+ 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+ 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+ 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+ 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+ 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+ 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+ 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+ 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+ 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+ 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+ 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+ 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+ 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+ 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+ 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+ 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+ 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+ 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+ 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+ 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
+};
+#endif /* crctab */
+
+/*
+ * Copyright (C) 1986 Gary S. Brown. You may use this program, or
+ * code or tables extracted from it, as desired without restriction.
+ */
+
+/* First, the polynomial itself and its table of feedback terms. The */
+/* polynomial is */
+/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
+/* Note that we take it "backwards" and put the highest-order term in */
+/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */
+/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */
+/* the MSB being 1. */
+
+/* Note that the usual hardware shift register implementation, which */
+/* is what we're using (we're merely optimizing it by doing eight-bit */
+/* chunks at a time) shifts bits into the lowest-order term. In our */
+/* implementation, that means shifting towards the right. Why do we */
+/* do it this way? Because the calculated CRC must be transmitted in */
+/* order from highest-order term to lowest-order term. UARTs transmit */
+/* characters in order from LSB to MSB. By storing the CRC this way, */
+/* we hand it to the UART in the order low-byte to high-byte; the UART */
+/* sends each low-bit to hight-bit; and the result is transmission bit */
+/* by bit from highest- to lowest-order term without requiring any bit */
+/* shuffling on our part. Reception works similarly. */
+
+/* The feedback terms table consists of 256, 32-bit entries. Notes: */
+/* */
+/* The table can be generated at runtime if desired; code to do so */
+/* is shown later. It might not be obvious, but the feedback */
+/* terms simply represent the results of eight shift/xor opera- */
+/* tions for all combinations of data and CRC register values. */
+/* */
+/* The values must be right-shifted by eight bits by the "updcrc" */
+/* logic; the shift must be unsigned (bring in zeroes). On some */
+/* hardware you could probably optimize the shift in assembler by */
+/* using byte-swap instructions. */
+
+static unsigned long crc_32_tab[] = { /* CRC polynomial 0xedb88320 */
+ 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL,
+ 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
+ 0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L,
+ 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
+ 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
+ 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
+ 0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL,
+ 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
+ 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L,
+ 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
+ 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L,
+ 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
+ 0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L,
+ 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
+ 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
+ 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
+ 0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL,
+ 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
+ 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L,
+ 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
+ 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL,
+ 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
+ 0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL,
+ 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
+ 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
+ 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
+ 0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L,
+ 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
+ 0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L,
+ 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
+ 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L,
+ 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
+ 0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL,
+ 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
+ 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
+ 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
+ 0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL,
+ 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
+ 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL,
+ 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
+ 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L,
+ 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
+ 0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L,
+ 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
+ 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
+ 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
+ 0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L,
+ 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
+ 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL,
+ 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
+ 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L,
+ 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
+ 0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL,
+ 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
+ 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
+ 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
+ 0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L,
+ 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
+ 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L,
+ 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
+ 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L,
+ 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
+ 0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L,
+ 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL
+};
+
+/*
+ * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell.
+ * NOTE: First argument must be in range 0 to 255.
+ * Second argument is referenced twice.
+ *
+ * Programmers may incorporate any or all code into their programs,
+ * giving proper credit within the source. Publication of the
+ * source routines is permitted so long as proper credit is given
+ * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
+ * Omen Technology.
+ */
+
+#define updcrc(cp, crc) (crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
+
+#define UPDC32(b, crc) \
+ (crc_32_tab[((unsigned)(crc) ^ (unsigned)(b)) & 0xff] \
+ ^ (((crc) >> 8) & 0x00ffffffL))
+
+/****************************************************************************/
+
+/*
+ * This section contains the guts of the Zmodem protocol. The intention
+ * is to leave as much of it alone as possible at the start. Overtime it
+ * will be cleaned up (EG: I'd like to clean up the naming of the globals).
+ * Also, Zmodem has a different coding style. Over time this will be converted
+ * to the Taylor UUCP coding style.
+ */
+
+/*
+ * Start the protocol (exchange init packets) ...
+ *
+ * UUCP can transfer files in both directions in one session. Therefore the
+ * init sequence is a little different.
+ *
+ * 1) ZINIT packets are exchanged
+ * - contains protocol version and protocol flags
+ * 2) ZDATA packets are exchanged
+ * - is intended to contain various numeric and string information
+ * 3) ZACK packets are exchanged
+ * 4) ZINITEND packets are exchanged
+ */
+
+static boolean
+fzstart_proto(qdaemon)
+struct sdaemon *qdaemon;
+{
+ int i;
+ achdrval_t tx_hdr,rx_hdr;
+
+ for (i = 0; i < cZstartup_retries; i++) {
+ stohdr (0L, tx_hdr);
+ tx_hdr[ZF0] = ZPROTOCOL_VERSION;
+ if (fZesc_ctl)
+ tx_hdr[ZF1] |= TX_ESCCTL;
+ switch (izexchange_init (qdaemon, ZINIT, tx_hdr, rx_hdr)) {
+ case -1: return FALSE;
+ case 0: continue;
+ case 1: break;
+ }
+#if 0 /* can't work, but kept for documentation */
+ if (rx_hdr[ZF0] == 0) {
+ ulog (LOG_ERROR, "Old protocol version, init failed");
+ return FALSE;
+ }
+#endif
+ fZesc_ctl = fZesc_ctl || (rx_hdr[ZF1] & TX_ESCCTL) != 0;
+
+ stohdr (0L, tx_hdr);
+ switch (izexchange_init (qdaemon, ZDATA, tx_hdr, rx_hdr)) {
+ case -1: return FALSE;
+ case 0: continue;
+ case 1: break;
+ }
+
+ stohdr (0L, tx_hdr);
+ switch (izexchange_init (qdaemon, ZACK, tx_hdr, rx_hdr)) {
+ case -1: return FALSE;
+ case 0: continue;
+ case 1: break;
+ }
+
+ stohdr (0L, tx_hdr);
+ switch (izexchange_init (qdaemon, ZINITEND, tx_hdr, rx_hdr)) {
+ case -1: return FALSE;
+ case 0: continue;
+ case 1: break;
+ }
+
+ DEBUG_MESSAGE0 (DEBUG_PROTO,
+ "fzstart_proto: Protocol started");
+ return TRUE;
+
+ /* FIXME: see protg.c regarding sequencing here. */
+ }
+
+ ulog (LOG_ERROR, "Protocol init failed");
+ return FALSE;
+}
+
+/*
+ * Exchange init messages. This is based on 'g'.
+ * See the comments concerning fgexchange_init() in protg.c.
+ *
+ * We return 1 for success, 0 for restart, -1 for comm failure (terminate).
+ */
+
+static int
+izexchange_init(qdaemon, send_type, send_val, recv_val)
+struct sdaemon *qdaemon;
+int send_type;
+achdrval_t send_val;
+achdrval_t recv_val;
+{
+ int i,recv_type,count;
+
+ for (i = 0; i < CEXCHANGE_INIT_RETRIES; i++) {
+ if (!fzsend_hdr (qdaemon, send_type == ZDATA ? ZBIN : ZHEX,
+ send_type, rclhdr (send_val), FALSE))
+ return -1;
+
+ /*
+ * The ZDATA packet is intended to contain the <Attn> string
+ * (eventually, if it's ever usable) and allow for anything
+ * else that will need to be thrown in.
+ */
+
+ if (send_type == ZDATA) {
+ count = czbuild_data_packet (zZtx_packet_buf, "",
+ (size_t) 1, ZCRCF);
+ if (!fsend_data (qdaemon->qconn, zZtx_packet_buf,
+ (size_t) count, FALSE))
+ return -1;
+ }
+
+ recv_type = izrecv_hdr (qdaemon, recv_val);
+
+ switch (recv_type) {
+ case ZM_TIMEOUT:
+ case ZM_ERROR:
+ continue;
+ case ZM_RCDO:
+ case ZFIN:
+ return -1;
+ case ZINIT:
+ case ZACK:
+ case ZINITEND:
+ break;
+ case ZDATA:
+ if (zrdat32 (qdaemon, zZrx_packet_buf, 1024, &count)
+ == GOTCRCF)
+ break;
+ continue;
+ default:
+ continue;
+ }
+
+ if (recv_type == send_type)
+ return 1;
+
+ /*
+ * If the other side is farther along than we are, we have lost
+ * a packet. Fall immediately back to ZINIT (but don't fail
+ * if we are already doing ZINIT, since that would count
+ * against cStart_retries more than it should).
+ *
+ * FIXME: The ">" test is "<" in protg.c. Check who's right.
+ */
+
+ if (recv_type > send_type && send_type != ZINIT)
+ return 0;
+
+ /*
+ * If we are sending ZINITEND and we receive an ZINIT, the
+ * other side has falled back (we know this because we have
+ * seen a ZINIT from them). Fall back ourselves to start
+ * the whole handshake over again.
+ */
+
+ if (recv_type == ZINIT && send_type == ZINITEND)
+ return 0;
+ }
+
+ return 0;
+}
+
+/*
+ * Shut down the protocol ...
+ */
+
+static boolean
+fzshutdown_proto(qdaemon)
+struct sdaemon *qdaemon;
+{
+ (void) fzsend_hdr (qdaemon, ZHEX, ZFIN, 0L, FALSE);
+ return TRUE;
+}
+
+/*
+ * Reset the transmitter side for sending a new message ...
+ */
+
+static boolean
+fzstart_tx()
+{
+ iZlast_tx_data_packet = -1;
+
+ /*
+ * <wpZlastsync> is set to -1L to suppress ZCRCW request otherwise
+ * triggered by (wpZlastsync == wpZtxpos).
+ */
+
+ cZblklen = 1024;
+ wpZlastsync = -1L;
+ iZbeenhereb4 = 0;
+ iZtleft = 0;
+ iZjunk_count = 0;
+
+ wpZtxpos = (wpZtxpos + 1024L) & ~1023L; /* next packet boundary */
+ wpZlrxpos = wpZrxpos = wpZtxpos;
+
+ wpZtxstart = wpZtxpos; /* so we can compute the "file offset" */
+
+ return TRUE;
+}
+
+/*
+ * Finish the sending of a message ...
+ *
+ * Basically, we wait for some indication that the receiver received our last
+ * message. If the receiver tells us to restart from some point, we set
+ * *plredo to that point.
+ *
+ * FIXME: This function is a major kludge at the moment. It is taken from
+ * getinsync(). It is necessary because I don't yet buffer outgoing data.
+ * It will go away when we do (buffer outgoing data).
+ */
+
+static boolean
+fzfinish_tx(qdaemon, plredo)
+struct sdaemon *qdaemon;
+long *plredo;
+{
+ int c,cerr,ctimeouts;
+ achdrval_t rx_hdr;
+ winpos_t rx_bytes;
+
+ *plredo = -1;
+ cerr = cZretries;
+ ctimeouts = 0;
+
+ DEBUG_MESSAGE4 (DEBUG_PROTO,
+ "fzfinish_tx: txpos=0x%lx, rxpos=0x%lx, lrxpos=0x%lx, rxbytes=0x%lx",
+ wpZtxpos, wpZrxpos, wpZlrxpos, wpZrxbytes);
+
+ for (;;) {
+ c = izrecv_hdr (qdaemon, rx_hdr);
+
+ switch (c) {
+ case ZRPOS:
+ wpZrxpos = lzupdate_rxpos (rx_hdr, wpZrxpos,
+ wpZlrxpos, wpZtxpos);
+ /*
+ * If the receiver sends a ZRPOS for the 1k block after
+ * the one we're currently at, we lost the final ZACK.
+ * We cheat and ignore this ZRPOS. Remember: the theory
+ * is that this entire function will go away when we
+ * begin buffering the outgoing data. Of course, one
+ * can reword the protocol definition and say this
+ * isn't cheating at all.
+ */
+ if (((wpZtxpos + 1024) & ~1023) == wpZrxpos)
+ return TRUE;
+ cZbytes_resent += wpZtxpos - wpZrxpos;
+ wpZlrxpos = wpZtxpos = wpZrxpos;
+ if (wpZlastsync == wpZrxpos) {
+ if (++iZbeenhereb4 > 4)
+ if (cZblklen > 32)
+ cZblklen /= 2;
+ /* FIXME: shouldn't we reset iZbeenhereb4? */
+ }
+ wpZlastsync = wpZrxpos;
+ iZlast_tx_data_packet = ZCRCW; /* force a timeout */
+ *plredo = wpZrxpos - wpZtxstart;
+ return TRUE;
+ case ZACK:
+ wpZrxpos = lzupdate_rxpos (rx_hdr, wpZrxpos,
+ wpZlrxpos, wpZtxpos);
+ wpZlrxpos = wpZrxpos;
+ if (wpZtxpos == wpZrxpos) /* the ACK we want? */
+ return TRUE;
+ break;
+ case ZDATA:
+ /*
+ * We cheat here and take advantage of UUCP's current
+ * half duplex nature. If we get a ZDATA starting on
+ * the next 1k boundary, we lost the ZACK. We cheat and
+ * tuck it away so that izrecv_hdr() can later detect
+ * it. Remember: see above.
+ */
+ zdecode_data_hdr (rclhdr (rx_hdr), &rx_bytes);
+ if (((wpZrxbytes + 1024L) & ~1023L) == rx_bytes) {
+ iZpkt_rcvd_kludge = ZDATA;
+ hvZpkt_hdrval_kludge = rclhdr (rx_hdr);
+ return TRUE;
+ }
+ break; /* ignore, out of sync (old) */
+ case ZNAK:
+ /*
+ * We cheat here and take advantage of UUCP's current
+ * half duplex nature. If we get a ZNAK starting on
+ * the next 1k boundary, we lost the ZACK. We cheat and
+ * throw the ZNAK away. Remember: see above.
+ *
+ * On the other hand, if (rx_bytes == wpZrxbytes) then
+ * the other side is also in fzfinish_tx(). He must
+ * have lost our ZACK, so we send him another.
+ */
+ zdecode_data_hdr (rclhdr (rx_hdr), &rx_bytes);
+ if (((wpZrxbytes + 1024L) & ~1023L) == rx_bytes)
+ return TRUE;
+ if (rx_bytes == wpZrxbytes) {
+ if (!fzsend_hdr (qdaemon, ZHEX, ZACK,
+ hvzencode_data_hdr (wpZrxbytes),
+ TRUE))
+ return FALSE;
+ }
+ break; /* ignore, out of sync (old) */
+ case ZFIN:
+ case ZM_RCDO:
+ return FALSE;
+ case ZM_TIMEOUT:
+ if (--cerr < 0) {
+ ulog (LOG_ERROR,
+ "fzfinish_tx: retries exhausted");
+ return FALSE;
+ }
+ /*
+ * Normally the sender doesn't send NAK's for timeouts.
+ * We have to here because of the following scenario:
+ *
+ * - We send ZDATA/ZCRCF
+ * - They send ZACK (corrupted)
+ * - They send ZDATA/ZCRCF (corrupted)
+ *
+ * At this point, both sides are in fzfinish_tx().
+ * We only send ZNAK every second timeout to increase
+ * our timeout delay vs. our partner. This tries to
+ * avoid ZRPOS and ZNAK "passing in transit".
+ */
+ if (++ctimeouts % 2 == 0)
+ if (!fzsend_hdr (qdaemon, ZHEX, ZNAK,
+ hvzencode_data_hdr (wpZtxpos),
+ TRUE))
+ return FALSE;
+ break;
+ case ZM_ERROR:
+ default:
+ if (--cerr < 0) {
+ ulog (LOG_ERROR,
+ "fzfinish_tx: retries exhausted");
+ return FALSE;
+ }
+ if (!fzsend_hdr (qdaemon, ZHEX, ZNAK,
+ hvzencode_data_hdr (wpZtxpos),
+ TRUE))
+ return FALSE;
+ break;
+ }
+ }
+}
+
+/*
+ * Initialize the receiver ...
+ */
+
+static boolean
+fzstart_rx()
+{
+ wpZrxbytes = (wpZrxbytes + 1024L) & ~1023L; /* next packet boundary */
+
+ return TRUE;
+}
+
+/*
+ * Terminate the receiver ...
+ *
+ * Acknowledge the last packet received.
+ */
+
+static boolean
+fzfinish_rx(qdaemon)
+struct sdaemon *qdaemon;
+{
+ DEBUG_MESSAGE0 (DEBUG_PROTO, "fzfinish_rx: message/file received");
+
+ return fzsend_hdr (qdaemon, ZHEX, ZACK,
+ hvzencode_data_hdr (wpZrxbytes), FALSE);
+}
+
+/*
+ * Send a Zmodem header to our partner ...
+ */
+
+static boolean
+fzsend_hdr(qdaemon, ipkttype, ihdrtype, hdrval, fcheckreceive)
+struct sdaemon *qdaemon;
+int ipkttype;
+int ihdrtype;
+hdrval_t hdrval;
+boolean fcheckreceive;
+{
+ int cpacketlen;
+
+ DEBUG_MESSAGE2 (DEBUG_PROTO, "fzsend_hdr: %s, data = 0x%lx",
+ ZZHEADER_NAME(ihdrtype), hdrval);
+
+ cpacketlen = czbuild_header (zZtx_packet_buf, ipkttype,
+ ihdrtype, hdrval);
+
+#ifdef DJE_TESTING
+#if 0
+ if (ihdrtype == ZACK && rand () % 100 < uucptest2) {
+ cZheaders_sent++;
+ return TRUE;
+ }
+#else
+ if (ihdrtype == ZACK || ihdrtype == ZDATA) {
+ boolean fresult;
+ int old;
+ extern int uucptest,uucptest2;
+
+ old = uucptest;
+ uucptest = uucptest2;
+ cZheaders_sent++;
+ fresult = fsend_data (qdaemon->qconn, zZtx_packet_buf,
+ (size_t) cpacketlen, fcheckreceive);
+ uucptest = old;
+ return fresult;
+ }
+#endif
+#endif
+ cZheaders_sent++;
+ return fsend_data (qdaemon->qconn, zZtx_packet_buf,
+ (size_t) cpacketlen, fcheckreceive);
+}
+
+/*
+ * Send a data packet to our partner ...
+ * <frameend> is one of ZCRCx.
+ */
+
+static boolean
+fzsend_data_packet(qdaemon, zdata, cdata, frameend, fcheckreceive)
+struct sdaemon *qdaemon;
+char *zdata;
+size_t cdata;
+int frameend;
+boolean fcheckreceive;
+{
+ int cpacketlen;
+
+ cpacketlen = czbuild_data_packet (zZtx_packet_buf, zdata, cdata,
+ frameend);
+
+ return fsend_data (qdaemon->qconn, zZtx_packet_buf,
+ (size_t) cpacketlen, fcheckreceive);
+}
+
+/*
+ * Build Zmodem headers ...
+ *
+ * Note that we use 32 bit CRC's for ZHEX headers.
+ *
+ * This function is a combination of zm fns: zsbhdr(), zsbh32(), and zshhdr().
+ */
+
+static int
+czbuild_header(zresult, ipkttype, ihdrtype, hdrval)
+char *zresult;
+int ipkttype;
+int ihdrtype;
+hdrval_t hdrval;
+{
+ char *p;
+ int i;
+ unsigned long crc;
+ achdrval_t achdrval;
+
+ p = zresult;
+
+ switch (ipkttype) {
+ case ZBIN:
+ *p++ = ZPAD;
+ *p++ = ZDLE;
+ *p++ = ZBIN;
+ p = zputchar (p, ihdrtype);
+ crc = ICRCINIT;
+ crc = UPDC32 (ihdrtype, crc);
+ stohdr (hdrval, achdrval);
+ for (i = 0; i < 4; i++) {
+ p = zputchar (p, achdrval[i]);
+ crc = UPDC32 (achdrval[i], crc);
+ }
+ crc = ~crc;
+ for (i = 0; i < 4; i++) {
+ p = zputchar (p, (char) crc);
+ crc >>= 8;
+ }
+ break;
+ case ZHEX: /* build hex header */
+ *p++ = ZPAD;
+ *p++ = ZPAD;
+ *p++ = ZDLE;
+ *p++ = ZHEX;
+ p = zputhex (p, ihdrtype);
+ crc = ICRCINIT;
+ crc = UPDC32 (ihdrtype, crc);
+ stohdr (hdrval, achdrval);
+ for (i = 0; i < 4; i++) {
+ p = zputhex (p, achdrval[i]);
+ crc = UPDC32 (achdrval[i], crc);
+ }
+ crc = ~crc;
+ for (i = 0; i < 4; i++) {
+ p = zputhex (p, (char) crc);
+ crc >>= 8;
+ }
+ *p++ = CR;
+ /*
+ * Uncork the remote in case a fake XOFF has stopped data flow.
+ */
+ if (ihdrtype != ZFIN && ihdrtype != ZACK) /* FIXME: why? */
+ *p++ = XON;
+ break;
+ default:
+ ulog (LOG_FATAL, "czbuild_header: ipkttype == %d", ipkttype);
+ break;
+ }
+
+ return p - zresult;
+}
+
+/*
+ * Build Zmodem data packets ...
+ *
+ * This function is zsdata() and zsda32() from the zm source.
+ */
+
+static int
+czbuild_data_packet(zresult, zdata, cdata, frameend)
+char *zresult;
+const char *zdata;
+size_t cdata;
+int frameend;
+{
+ char *p;
+ unsigned long crc;
+
+ p = zresult;
+
+ crc = ICRCINIT;
+ for ( ; cdata-- != 0; zdata++) {
+ char c;
+
+ c = *zdata;
+ if (c & 0140)
+ *p++ = c;
+ else
+ p = zputchar (p, c);
+ crc = UPDC32 ((unsigned char) c, crc);
+ }
+ *p++ = ZDLE;
+ *p++ = frameend;
+ crc = UPDC32 (frameend, crc);
+ crc = ~crc;
+ for (cdata = 0; cdata < 4; cdata++) {
+ p = zputchar (p, (char) crc);
+ crc >>= 8;
+ }
+ if (frameend == ZCRCW || frameend == ZCRCE || frameend == ZCRCF) {
+ *p++ = CR;
+ *p++ = XON;
+ }
+
+ return p - zresult;
+}
+
+/*
+ * Read in a header ...
+ *
+ * This is function zgethdr() from the Zmodem source.
+ */
+
+static int
+izrecv_hdr(qdaemon, hdr)
+struct sdaemon *qdaemon;
+achdrval_t hdr;
+{
+ int c,cerr;
+
+ /*
+ * Kludge alert! If another part of the program received a packet but
+ * wasn't ready to handle it, it is tucked away for us to handle now.
+ */
+
+ if (iZpkt_rcvd_kludge != -1) {
+ c = iZpkt_rcvd_kludge;
+ iZpkt_rcvd_kludge = -1;
+ stohdr (hvZpkt_hdrval_kludge, hdr);
+ DEBUG_MESSAGE2 (DEBUG_PROTO,
+ "izrecv_hdr: queued %s, data = 0x%lx",
+ ZZHEADER_NAME(c), rclhdr (hdr));
+ cZheaders_received++;
+ return c;
+ }
+
+ cerr = cZmax_garbage; /* Max bytes before start of frame */
+
+again:
+ switch (c = noxrd7 (qdaemon)) {
+ case ZM_TIMEOUT:
+ case ZM_ERROR:
+ case ZM_RCDO:
+ goto fifi;
+ case ZPAD: /* This is what we want */
+ break;
+ case CR: /* padding at end of previous header */
+ default:
+ if (--cerr < 0) {
+ c = ZM_ERROR;
+ goto fifi;
+ }
+ goto again;
+ }
+
+splat:
+ switch (c = noxrd7 (qdaemon)) {
+ case ZPAD:
+ if (--cerr < 0) {
+ c = ZM_ERROR;
+ goto fifi;
+ }
+ goto splat;
+ case ZM_TIMEOUT:
+ case ZM_RCDO:
+ goto fifi;
+ case ZDLE: /* This is what we want */
+ break;
+ default:
+ if (--cerr < 0) {
+ c = ZM_ERROR;
+ goto fifi;
+ }
+ goto again;
+ }
+
+ switch (c = noxrd7 (qdaemon)) {
+ case ZM_TIMEOUT:
+ case ZM_RCDO:
+ goto fifi;
+ case ZBIN:
+ c = zrbhdr32 (qdaemon, hdr);
+ break;
+ case ZHEX:
+ c = zrhhdr (qdaemon, hdr);
+ break;
+ default:
+ if (--cerr < 0) {
+ c = ZM_ERROR;
+ goto fifi;
+ }
+ goto again;
+ }
+
+fifi:
+ switch (c) {
+ case ZM_TIMEOUT:
+ cZtimeouts++;
+ break;
+ case ZM_ERROR:
+ cZerrors++;
+ break;
+ case ZM_RCDO:
+ break;
+ default:
+ cZheaders_received++;
+ break;
+ }
+ DEBUG_MESSAGE2 (DEBUG_PROTO, "izrecv_hdr: %s, data = 0x%x",
+ ZZHEADER_NAME(c), rclhdr (hdr));
+
+ return c;
+}
+
+/*
+ * Receive a binary style header (type and position) with 32 bit FCS ...
+ */
+
+static int
+zrbhdr32(qdaemon, hdr)
+struct sdaemon *qdaemon;
+achdrval_t hdr;
+{
+ int c,i,type;
+ unsigned long crc;
+
+ if ((c = zdlread (qdaemon)) & ~0377)
+ return c;
+ type = c;
+ crc = ICRCINIT;
+ crc = UPDC32 (c, crc);
+
+ for (i = 0; i < 4; i++) {
+ if ((c = zdlread (qdaemon)) & ~0377)
+ return c;
+ crc = UPDC32 (c, crc);
+ hdr[i] = (char) c;
+ }
+ for (i = 0; i < 4; i++) {
+ if ((c = zdlread (qdaemon)) & ~0377)
+ return c;
+ crc = UPDC32 (c, crc);
+ }
+ if (crc != IHDRCRC)
+ return ZM_ERROR;
+
+ return type;
+}
+
+/*
+ * Receive a hex style header (type and position) ...
+ */
+
+static int
+zrhhdr(qdaemon, hdr)
+struct sdaemon *qdaemon;
+achdrval_t hdr;
+{
+ int c,i,type;
+ unsigned long crc;
+
+ if ((c = zgethex (qdaemon)) < 0)
+ return c;
+ type = c;
+ crc = ICRCINIT;
+ crc = UPDC32 (c, crc);
+
+ for (i = 0; i < 4; i++) {
+ if ((c = zgethex (qdaemon)) < 0)
+ return c;
+ crc = UPDC32 (c, crc);
+ hdr[i] = (char) c;
+ }
+ for (i = 0; i < 4; i++) {
+ if ((c = zgethex (qdaemon)) < 0)
+ return c;
+ crc = UPDC32 (c, crc);
+ }
+ if (crc != IHDRCRC)
+ return ZM_ERROR;
+
+ return type;
+}
+
+/*
+ * Receive a data packet ...
+ */
+
+static int
+zrdat32(qdaemon, buf, length, iprxcount)
+struct sdaemon *qdaemon;
+char *buf;
+int length;
+int *iprxcount;
+{
+ int c,d;
+ unsigned long crc;
+ char *end;
+
+ crc = ICRCINIT;
+ *iprxcount = 0;
+ end = buf + length;
+ while (buf <= end) {
+ if ((c = zdlread (qdaemon)) & ~0377) {
+crcfoo:
+ switch (c) {
+ case GOTCRCE:
+ case GOTCRCG:
+ case GOTCRCQ:
+ case GOTCRCW:
+ case GOTCRCF:
+ d = c;
+ c &= 0377;
+ crc = UPDC32 (c, crc);
+ if ((c = zdlread (qdaemon)) & ~0377)
+ goto crcfoo;
+ crc = UPDC32 (c, crc);
+ if ((c = zdlread (qdaemon)) & ~0377)
+ goto crcfoo;
+ crc = UPDC32 (c, crc);
+ if ((c = zdlread (qdaemon)) & ~0377)
+ goto crcfoo;
+ crc = UPDC32 (c, crc);
+ if ((c = zdlread (qdaemon)) & ~0377)
+ goto crcfoo;
+ crc = UPDC32 (c, crc);
+ if (crc != IHDRCRC)
+ return ZM_ERROR;
+ *iprxcount = length - (end - buf);
+ return d;
+ case ZM_TIMEOUT:
+ case ZM_RCDO:
+ return c;
+ default:
+ return ZM_ERROR;
+ }
+ }
+ *buf++ = (char) c;
+ crc = UPDC32 (c, crc);
+ }
+
+ return ZM_ERROR; /* bad packet, too long */
+}
+
+/*
+ * Respond to receiver's complaint, get back in sync with receiver ...
+ */
+
+static int
+getinsync(qdaemon, flag)
+struct sdaemon *qdaemon;
+boolean flag;
+{
+ int c,cerr;
+ achdrval_t rx_hdr;
+
+ cerr = cZretries;
+
+ for (;;) {
+ c = izrecv_hdr (qdaemon, rx_hdr);
+
+ switch (c) {
+ case ZRPOS:
+ wpZrxpos = lzupdate_rxpos (rx_hdr, wpZrxpos,
+ wpZlrxpos, wpZtxpos);
+ cZbytes_resent += wpZtxpos - wpZrxpos;
+ wpZlrxpos = wpZtxpos = wpZrxpos;
+ if (wpZlastsync == wpZrxpos) {
+ if (++iZbeenhereb4 > 4)
+ if (cZblklen > 32)
+ cZblklen /= 2;
+ /* FIXME: shouldn't we reset iZbeenhereb4? */
+ }
+ wpZlastsync = wpZrxpos;
+ return ZRPOS;
+ case ZACK:
+ wpZrxpos = lzupdate_rxpos (rx_hdr, wpZrxpos,
+ wpZlrxpos, wpZtxpos);
+ wpZlrxpos = wpZrxpos;
+ if (flag || wpZtxpos == wpZrxpos)
+ return ZACK;
+ break;
+ case ZNAK: {
+ winpos_t rx_bytes;
+ /*
+ * Our partner is in fzfinish_tx() and is waiting
+ * for ZACK ...
+ */
+ zdecode_data_hdr (rclhdr (rx_hdr), &rx_bytes);
+ if (rx_bytes == wpZrxbytes) {
+ if (!fzsend_hdr (qdaemon, ZHEX, ZACK,
+ hvzencode_data_hdr (wpZrxbytes),
+ TRUE))
+ return FALSE;
+ }
+ break;
+ }
+ case ZFIN:
+ case ZM_RCDO:
+ return c;
+ case ZM_TIMEOUT:
+ if (--cerr < 0) {
+ ulog (LOG_ERROR,
+ "getinsync: retries exhausted");
+ return ZM_ERROR;
+ }
+ break; /* sender doesn't send ZNAK for timeout */
+ case ZM_ERROR:
+ default:
+ if (--cerr < 0) {
+ ulog (LOG_ERROR,
+ "getinsync: retries exhausted");
+ return ZM_ERROR;
+ }
+ if (!fzsend_hdr (qdaemon, ZHEX, ZNAK,
+ hvzencode_data_hdr (wpZtxpos),
+ TRUE))
+ return ZM_ERROR;
+ break;
+ }
+ }
+}
+
+/*
+ * Send a byte as two hex digits ...
+ */
+
+static char *
+zputhex(p, ch)
+char *p;
+int ch;
+{
+ static char digits[] = "0123456789abcdef";
+
+ *p++ = digits[(ch & 0xF0) >> 4];
+ *p++ = digits[ch & 0xF];
+ return p;
+}
+
+/*
+ * Send character c with ZMODEM escape sequence encoding ...
+ *
+ * Escape XON, XOFF.
+ * FIXME: Escape CR following @ (Telenet net escape) ... disabled for now
+ * Will need to put back references to <lastsent>.
+ */
+
+static char *
+zputchar(p, ch)
+char *p;
+int ch;
+{
+ char c = ch;
+
+ /* Quick check for non control characters */
+
+ if (c & 0140) {
+ *p++ = c;
+ } else {
+ switch (c & 0377) {
+ case ZDLE:
+ *p++ = ZDLE;
+ *p++ = c ^ 0100;
+ break;
+ case CR:
+#if 0
+ if (!fZesc_ctl && (lastsent & 0177) != '@')
+ goto sendit;
+#endif
+ /* fall through */
+ case 020: /* ^P */
+ case XON:
+ case XOFF:
+ *p++ = ZDLE;
+ c ^= 0100;
+/*sendit:*/
+ *p++ = c;
+ break;
+ default:
+ if (fZesc_ctl && !(c & 0140)) {
+ *p++ = ZDLE;
+ c ^= 0100;
+ }
+ *p++ = c;
+ break;
+ }
+ }
+
+ return p;
+}
+
+/*
+ * Decode two lower case hex digits into an 8 bit byte value ...
+ */
+
+static int
+zgethex(qdaemon)
+struct sdaemon *qdaemon;
+{
+ int c,n;
+
+ if ((c = noxrd7 (qdaemon)) < 0)
+ return c;
+ n = c - '0';
+ if (n > 9)
+ n -= ('a' - ':');
+ if (n & ~0xF)
+ return ZM_ERROR;
+ if ((c = noxrd7 (qdaemon)) < 0)
+ return c;
+ c -= '0';
+ if (c > 9)
+ c -= ('a' - ':');
+ if (c & ~0xF)
+ return ZM_ERROR;
+ c += (n << 4);
+
+ return c;
+}
+
+/*
+ * Read a byte, checking for ZMODEM escape encoding ...
+ */
+
+static int
+zdlread(qdaemon)
+struct sdaemon *qdaemon;
+{
+ int c;
+
+again:
+ READCHAR (qdaemon, c, cZtimeout);
+ if (c < 0)
+ return c;
+ if (c & 0140) /* quick check for non control characters */
+ return c;
+ switch (c) {
+ case ZDLE:
+ break;
+ case XON:
+ goto again;
+ case XOFF:
+ READCHAR (qdaemon, c, XON_WAIT);
+ goto again;
+ default:
+ if (fZesc_ctl && !(c & 0140))
+ goto again;
+ return c;
+ }
+
+again2:
+ READCHAR (qdaemon, c, cZtimeout);
+ if (c < 0)
+ return c;
+ switch (c) {
+ case ZCRCE:
+ case ZCRCG:
+ case ZCRCQ:
+ case ZCRCW:
+ case ZCRCF:
+ return c | GOTOR;
+ case ZRUB0: /* FIXME: This is never generated. */
+ return 0177;
+ case ZRUB1: /* FIXME: This is never generated. */
+ return 0377;
+ case XON:
+ goto again2;
+ case XOFF:
+ READCHAR (qdaemon, c, XON_WAIT);
+ goto again2;
+ default:
+ if (fZesc_ctl && !(c & 0140))
+ goto again2; /* FIXME: why again2? */
+ if ((c & 0140) == 0100)
+ return c ^ 0100;
+ break;
+ }
+
+ return ZM_ERROR;
+}
+
+/*
+ * Read a character from the modem line with timeout ...
+ * Eat parity bit, XON and XOFF characters.
+ */
+
+static int
+noxrd7(qdaemon)
+struct sdaemon *qdaemon;
+{
+ int c;
+
+ for (;;) {
+ READCHAR (qdaemon, c, cZtimeout);
+ if (c < 0)
+ return c;
+ switch (c &= 0177) {
+ case XON:
+ continue;
+ case XOFF:
+ READCHAR (qdaemon, c, XON_WAIT);
+ continue;
+ case CR:
+ case ZDLE:
+ return c;
+ default:
+ if (fZesc_ctl && !(c & 0140))
+ continue;
+ return c;
+ }
+ }
+}
+
+/*
+ * Read a character from the receive buffer, or from the line if empty ...
+ *
+ * <timeout> is in seconds (maybe make it tenths of seconds like in Zmodem?)
+ */
+
+static int
+realreadchar(qdaemon, timeout)
+struct sdaemon *qdaemon;
+int timeout;
+{
+ int c;
+
+ if ((c = breceive_char (qdaemon->qconn, timeout, TRUE)) >= 0)
+ return c;
+
+ switch (c) {
+ case -1:
+ return ZM_TIMEOUT;
+ case -2:
+ return ZM_RCDO;
+ }
+
+ ulog (LOG_FATAL, "realreadchar: breceive_char() returned %d", c);
+ return ZM_ERROR;
+}
+
+
+/*
+ * Check if the receive channel has any characters in it.
+ *
+ * At present we can only test the receive buffer. No mechanism is available
+ * to go to the hardware. This should not be a problem though, as long as all
+ * appropriate calls to fsend_data() set <fdoread> to TRUE.
+ */
+
+static boolean
+fzreceive_ready()
+{
+ return iPrecstart != iPrecend;
+}
+
+/*
+ * Store integer value in an achdrval_t ...
+ */
+
+static void
+stohdr(val, hdr)
+hdrval_t val;
+achdrval_t hdr;
+{
+ hdr[ZP0] = (char) val;
+ hdr[ZP1] = (char) (val >> 8);
+ hdr[ZP2] = (char) (val >> 16);
+ hdr[ZP3] = (char) (val >> 24);
+}
+
+/*
+ * Recover an integer from a header ...
+ */
+
+static hdrval_t
+rclhdr(hdr)
+achdrval_t hdr;
+{
+ hdrval_t v;
+
+ v = hdr[ZP3] & 0377;
+ v = (v << 8) | (hdr[ZP2] & 0377);
+ v = (v << 8) | (hdr[ZP1] & 0377);
+ v = (v << 8) | (hdr[ZP0] & 0377);
+
+ return v;
+}
+
+/*
+ * Encode a <hdrval_t> from the byte count ...
+ *
+ * We use to store the byte count / 32 and a message sequence number which
+ * made this function very useful. Don't remove it.
+ * FIXME: Well, maybe remove it later.
+ */
+
+static hdrval_t
+hvzencode_data_hdr(cbytes)
+winpos_t cbytes;
+{
+ return (hdrval_t) cbytes;
+}
+
+/*
+ * Decode a <hdrval_t> into a byte count ...
+ *
+ * We use to store the byte count / 32 and a message sequence number which
+ * made this function very useful. Don't remove it.
+ * FIXME: Well, maybe remove it later.
+ */
+
+static void
+zdecode_data_hdr(hdrval, pcbytes)
+hdrval_t hdrval;
+winpos_t *pcbytes;
+{
+ *pcbytes = hdrval;
+}
+
+/*
+ * Update <wpZrxpos> from the received data header value ...
+ *
+ * FIXME: Here is where we'd handle wrapping around at 4 gigabytes.
+ */
+
+static winpos_t
+lzupdate_rxpos(rx_hdr, rxpos, lrxpos, txpos)
+achdrval_t rx_hdr;
+winpos_t rxpos,lrxpos,txpos;
+{
+ winpos_t rx_pktpos;
+
+ zdecode_data_hdr (rclhdr (rx_hdr), &rx_pktpos);
+
+ DEBUG_MESSAGE4 (DEBUG_PROTO,
+ "lzupdate_rxpos: rx_pktpos=0x%lx, rxpos=0x%lx, lrxpos=0x%lx, txpos=0x%lx",
+ rx_pktpos, rxpos, lrxpos, txpos);
+
+ /*
+ * Check if <rx_pktpos> valid. It could be old.
+ */
+
+ if (rx_pktpos < wpZlrxpos
+ || rx_pktpos > ((wpZtxpos + 1024L) & ~1023L))
+ return rxpos;
+
+ return rx_pktpos;
+}
diff --git a/gnu/libexec/uucp/uucico/rec.c b/gnu/libexec/uucp/uucico/rec.c
new file mode 100644
index 00000000000..160aab705ad
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/rec.c
@@ -0,0 +1,1162 @@
+/* rec.c
+ Routines to receive a file.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char rec_rcsid[] = "$Id: rec.c,v 1.1 1993/08/04 19:36:28 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+#include "prot.h"
+#include "trans.h"
+
+/* If the other side does not tell us the size of a file it wants to
+ send us, we assume it is this long. This is only used for free
+ space checking. */
+#define CASSUMED_FILE_SIZE (10240)
+
+/* We keep this information in the pinfo field of the stransfer
+ structure. */
+struct srecinfo
+{
+ /* Local user to send mail to (may be NULL). */
+ char *zmail;
+ /* Full file name. */
+ char *zfile;
+ /* Temporary file name. */
+ char *ztemp;
+ /* TRUE if this is a spool directory file. */
+ boolean fspool;
+ /* TRUE if this was a local request. */
+ boolean flocal;
+ /* TRUE if the file has been completely received. */
+ boolean freceived;
+ /* TRUE if remote request has been replied to. */
+ boolean freplied;
+ /* TRUE if we moved the file to the final destination. */
+ boolean fmoved;
+};
+
+/* This structure is kept in the pinfo field if we are refusing a
+ remote request. */
+struct srecfailinfo
+{
+ /* Reason for refusal. */
+ enum tfailure twhy;
+ /* TRUE if we have sent the reason for refusal. */
+ boolean fsent;
+ /* TRUE if we have seen the end of the file. */
+ boolean freceived;
+};
+
+/* Local functions. */
+
+static void urrec_free P((struct stransfer *qtrans));
+static boolean flocal_rec_fail P((struct stransfer *qtrans,
+ struct scmd *qcmd,
+ const struct uuconf_system *qsys,
+ const char *zwhy));
+static boolean flocal_rec_send_request P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean flocal_rec_await_reply P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon,
+ const char *zdata,
+ size_t cdata));
+static boolean fremote_send_reply P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean fremote_send_fail P((struct sdaemon *qdaemon,
+ struct scmd *qcmd,
+ enum tfailure twhy,
+ int iremote));
+static boolean fremote_send_fail_send P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean fremote_discard P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon,
+ const char *zdata, size_t cdata));
+static boolean frec_file_end P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon,
+ const char *zdata, size_t cdata));
+static boolean frec_file_send_confirm P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+
+/* Free up a receive stransfer structure. */
+
+static void
+urrec_free (qtrans)
+ struct stransfer *qtrans;
+{
+ struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
+
+ if (qinfo != NULL)
+ {
+ ubuffree (qinfo->zmail);
+ ubuffree (qinfo->zfile);
+ ubuffree (qinfo->ztemp);
+ xfree (qtrans->pinfo);
+ }
+
+ utransfree (qtrans);
+}
+
+/* Set up a request for a file from the remote system. This may be
+ called before the remote system has been called.
+
+ This is the order of function calls:
+
+ flocal_rec_file_init --> fqueue_local
+ flocal_rec_send_request (send R ...) --> fqueue_receive
+ flocal_rec_await_reply (open file, call pffile) --> fqueue_receive
+ receive file
+ frec_file_end (close and move file, call pffile) --> fqueue_send
+ frec_file_send_confirm (send CY)
+ */
+
+boolean
+flocal_rec_file_init (qdaemon, qcmd)
+ struct sdaemon *qdaemon;
+ struct scmd *qcmd;
+{
+ const struct uuconf_system *qsys;
+ boolean fspool;
+ char *zfile;
+ struct srecinfo *qinfo;
+ struct stransfer *qtrans;
+
+ qsys = qdaemon->qsys;
+
+ /* Make sure we are permitted to transfer files. */
+ if (qdaemon->fcaller
+ ? ! qsys->uuconf_fcall_transfer
+ : ! qsys->uuconf_fcalled_transfer)
+ {
+ /* This case will have been checked by uucp or uux, but it could
+ have changed. */
+ if (! qsys->uuconf_fcall_transfer
+ && ! qsys->uuconf_fcalled_transfer)
+ return flocal_rec_fail ((struct stransfer *) NULL, qcmd, qsys,
+ "not permitted to request files");
+ return TRUE;
+ }
+
+ fspool = fspool_file (qcmd->zto);
+
+ if (fspool)
+ {
+ pointer puuconf;
+ int iuuconf;
+ const char *zlocalname;
+ struct uuconf_system slocalsys;
+
+ /* Normal users are not allowed to request files to be received
+ into the spool directory. To support uux forwarding, we use
+ the special option '9'. This permits a file to be received
+ into the spool directory for the local system only without
+ the usual checking. This is only done for local requests, of
+ course. */
+ if (qcmd->zto[0] != 'D'
+ || strchr (qcmd->zoptions, '9') == NULL)
+ return flocal_rec_fail ((struct stransfer *) NULL, qcmd, qsys,
+ "not permitted to receive");
+
+ puuconf = qdaemon->puuconf;
+ iuuconf = uuconf_localname (puuconf, &zlocalname);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ zlocalname = zsysdep_localname ();
+ if (zlocalname == NULL)
+ return FALSE;
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+
+ iuuconf = uuconf_system_info (puuconf, zlocalname, &slocalsys);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ iuuconf = uuconf_system_local (puuconf, &slocalsys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+
+ zfile = zsysdep_spool_file_name (&slocalsys, qcmd->zto, qcmd->pseq);
+
+ (void) uuconf_system_free (puuconf, &slocalsys);
+
+ if (zfile == NULL)
+ return FALSE;
+ }
+ else
+ {
+ zfile = zsysdep_add_base (qcmd->zto, qcmd->zfrom);
+ if (zfile == NULL)
+ return FALSE;
+
+ /* Check permissions. */
+ if (! fin_directory_list (zfile, qsys->uuconf_pzlocal_receive,
+ qsys->uuconf_zpubdir, TRUE,
+ FALSE, qcmd->zuser))
+ {
+ ubuffree (zfile);
+ return flocal_rec_fail ((struct stransfer *) NULL, qcmd, qsys,
+ "not permitted to receive");
+ }
+
+ /* The 'f' option means that directories should not
+ be created if they do not already exist. */
+ if (strchr (qcmd->zoptions, 'f') == NULL)
+ {
+ if (! fsysdep_make_dirs (zfile, TRUE))
+ {
+ ubuffree (zfile);
+ return flocal_rec_fail ((struct stransfer *) NULL, qcmd,
+ qsys, "cannot create directories");
+ }
+ }
+ }
+
+ qinfo = (struct srecinfo *) xmalloc (sizeof (struct srecinfo));
+ if (strchr (qcmd->zoptions, 'm') == NULL)
+ qinfo->zmail = NULL;
+ else
+ qinfo->zmail = zbufcpy (qcmd->zuser);
+ qinfo->zfile = zfile;
+ qinfo->ztemp = NULL;
+ qinfo->fspool = fspool;
+ qinfo->flocal = TRUE;
+ qinfo->freceived = FALSE;
+ qinfo->freplied = TRUE;
+
+ qtrans = qtransalc (qcmd);
+ qtrans->psendfn = flocal_rec_send_request;
+ qtrans->pinfo = (pointer) qinfo;
+
+ return fqueue_local (qdaemon, qtrans);
+}
+
+/* Report an error for a local receive request. */
+
+static boolean
+flocal_rec_fail (qtrans, qcmd, qsys, zwhy)
+ struct stransfer *qtrans;
+ struct scmd *qcmd;
+ const struct uuconf_system *qsys;
+ const char *zwhy;
+{
+ if (zwhy != NULL)
+ {
+ ulog (LOG_ERROR, "%s: %s", qcmd->zfrom, zwhy);
+ (void) fmail_transfer (FALSE, qcmd->zuser, (const char *) NULL, zwhy,
+ qcmd->zfrom, qsys->uuconf_zname,
+ qcmd->zto, (const char *) NULL,
+ (const char *) NULL);
+ (void) fsysdep_did_work (qcmd->pseq);
+ }
+ if (qtrans != NULL)
+ urrec_free (qtrans);
+ return TRUE;
+}
+
+/* This is called when we are ready to send the actual request to the
+ other system. */
+
+static boolean
+flocal_rec_send_request (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
+ long cbytes, cbytes2;
+ size_t clen;
+ char *zsend;
+ boolean fret;
+
+ qinfo->ztemp = zsysdep_receive_temp (qdaemon->qsys, qinfo->zfile,
+ (const char *) NULL);
+ if (qinfo->ztemp == NULL)
+ {
+ urrec_free (qtrans);
+ return FALSE;
+ }
+
+ /* Check the amount of free space available for both the temporary
+ file and the real file. */
+ cbytes = csysdep_bytes_free (qinfo->ztemp);
+ cbytes2 = csysdep_bytes_free (qinfo->zfile);
+ if (cbytes < cbytes2)
+ cbytes = cbytes2;
+ if (cbytes != -1)
+ {
+ cbytes -= qdaemon->qsys->uuconf_cfree_space;
+ if (cbytes < 0)
+ cbytes = 0;
+ }
+
+ if (qdaemon->clocal_size != -1
+ && (cbytes == -1 || qdaemon->clocal_size < cbytes))
+ cbytes = qdaemon->clocal_size;
+
+ /* We send the string
+ R from to user options
+
+ We put a dash in front of options. If we are talking to a
+ counterpart, we also send the maximum size file we are prepared
+ to accept, as returned by esysdep_open_receive. */
+ clen = (strlen (qtrans->s.zfrom) + strlen (qtrans->s.zto)
+ + strlen (qtrans->s.zuser) + strlen (qtrans->s.zoptions) + 30);
+ zsend = zbufalc (clen);
+ if ((qdaemon->ifeatures & FEATURE_SIZES) == 0)
+ sprintf (zsend, "R %s %s %s -%s", qtrans->s.zfrom, qtrans->s.zto,
+ qtrans->s.zuser, qtrans->s.zoptions);
+ else if ((qdaemon->ifeatures & FEATURE_V103) == 0)
+ sprintf (zsend, "R %s %s %s -%s 0x%lx", qtrans->s.zfrom, qtrans->s.zto,
+ qtrans->s.zuser, qtrans->s.zoptions, (unsigned long) cbytes);
+ else
+ sprintf (zsend, "R %s %s %s -%s %ld", qtrans->s.zfrom, qtrans->s.zto,
+ qtrans->s.zuser, qtrans->s.zoptions, cbytes);
+
+ fret = (*qdaemon->qproto->pfsendcmd) (qdaemon, zsend, qtrans->ilocal,
+ qtrans->iremote);
+ ubuffree (zsend);
+ if (! fret)
+ {
+ urrec_free (qtrans);
+ return FALSE;
+ }
+
+ qtrans->fcmd = TRUE;
+ qtrans->precfn = flocal_rec_await_reply;
+
+ return fqueue_receive (qdaemon, qtrans);
+}
+
+/* This is called when a reply is received for the request. */
+
+/*ARGSUSED*/
+static boolean
+flocal_rec_await_reply (qtrans, qdaemon, zdata, cdata)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+ const char *zdata;
+ size_t cdata;
+{
+ struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
+ long crestart;
+ const char *zlog;
+
+ if (zdata[0] != 'R'
+ || (zdata[1] != 'Y' && zdata[1] != 'N'))
+ {
+ ulog (LOG_ERROR, "%s: bad response to receive request: \"%s\"",
+ qtrans->s.zfrom, zdata);
+ urrec_free (qtrans);
+ return FALSE;
+ }
+
+ if (zdata[1] == 'N')
+ {
+ boolean fnever;
+ const char *zerr;
+
+ fnever = TRUE;
+ if (zdata[2] == '2')
+ zerr = "no such file";
+ else if (zdata[2] == '6')
+ {
+ /* We sent over the maximum file size we were prepared to
+ receive, and the remote system is telling us that the
+ file is larger than that. Try again later. It would be
+ better if we could know whether there will ever be enough
+ room. */
+ zerr = "too large to receive now";
+ fnever = FALSE;
+ }
+ else
+ zerr = "unknown reason";
+
+ if (fnever)
+ return flocal_rec_fail (qtrans, &qtrans->s, qdaemon->qsys, zerr);
+
+ ulog (LOG_ERROR, "%s: %s", qtrans->s.zfrom, zerr);
+
+ urrec_free (qtrans);
+
+ return TRUE;
+ }
+
+ /* The mode should have been sent as "RY 0%o". If it wasn't, we use
+ 0666. */
+ qtrans->s.imode = (unsigned int) strtol ((char *) (zdata + 2),
+ (char **) NULL, 8);
+ if (qtrans->s.imode == 0)
+ qtrans->s.imode = 0666;
+
+ /* Open the file to receive into. We just ignore any restart count,
+ since we have no way to tell it to the other side. SVR4 may have
+ some way to do this, but I don't know what it is. */
+ qtrans->e = esysdep_open_receive (qdaemon->qsys, qinfo->zfile,
+ (const char *) NULL, qinfo->ztemp,
+ &crestart);
+ if (! ffileisopen (qtrans->e))
+ return flocal_rec_fail (qtrans, &qtrans->s, qdaemon->qsys,
+ "cannot open file");
+
+ if (qinfo->fspool)
+ zlog = qtrans->s.zto;
+ else
+ zlog = qinfo->zfile;
+ qtrans->zlog = zbufalc (sizeof "Receiving " + strlen (zlog));
+ sprintf (qtrans->zlog, "Receiving %s", zlog);
+
+ if (qdaemon->qproto->pffile != NULL)
+ {
+ boolean fhandled;
+
+ if (! (*qdaemon->qproto->pffile) (qdaemon, qtrans, TRUE, FALSE,
+ (long) -1, &fhandled))
+ {
+ (void) ffileclose (qtrans->e);
+ return flocal_rec_fail (qtrans, &qtrans->s, qdaemon->qsys,
+ (const char *) NULL);
+ }
+ if (fhandled)
+ return TRUE;
+ }
+
+ qtrans->frecfile = TRUE;
+ qtrans->psendfn = frec_file_send_confirm;
+ qtrans->precfn = frec_file_end;
+
+ return fqueue_receive (qdaemon, qtrans);
+}
+
+/* Make sure there is still enough disk space available to receive a
+ file. */
+
+boolean
+frec_check_free (qtrans, cfree_space)
+ struct stransfer *qtrans;
+ long cfree_space;
+{
+ struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
+ long cfree1, cfree2;
+
+ cfree1 = csysdep_bytes_free (qinfo->ztemp);
+ cfree2 = csysdep_bytes_free (qinfo->zfile);
+ if (cfree1 < cfree2)
+ cfree1 = cfree2;
+ if (cfree1 != -1 && cfree1 < cfree_space)
+ {
+ ulog (LOG_ERROR, "%s: too big to receive now", qinfo->zfile);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* A remote request to send a file to the local system, meaning that
+ we are going to receive a file.
+
+ If we are using a protocol which does not support multiple
+ channels, the remote system will not start sending us the file
+ until it has received our confirmation. In that case, the order of
+ functions is as follows:
+
+ fremote_send_file_init (open file) --> fqueue_remote
+ fremote_send_reply (send SY, call pffile) --> fqueue_receive
+ receive file
+ frec_file_end (close and move file, call pffile) --> fqueue_send
+ frec_file_send_confirm (send CY)
+
+ If the protocol supports multiple channels, then the remote system
+ will start sending the file immediately after the send request.
+ That means that the data may come in before remote_send_reply is
+ called, so frec_file_end may be called before fremote_send_reply.
+ Note that this means the pffile entry points may be called in
+ reverse order for such a protocol.
+
+ If the send request is rejected, via fremote_send_fail, and the
+ protocol supports multiple channels, we must accept and discard
+ data until a zero byte buffer is received from the other side,
+ indicating that it has received our rejection.
+
+ This code also handles execution requests, which are very similar
+ to send requests. */
+
+boolean
+fremote_send_file_init (qdaemon, qcmd, iremote)
+ struct sdaemon *qdaemon;
+ struct scmd *qcmd;
+ int iremote;
+{
+ const struct uuconf_system *qsys;
+ boolean fspool;
+ char *zfile;
+ openfile_t e;
+ char *ztemp;
+ long cbytes, cbytes2;
+ long crestart;
+ struct srecinfo *qinfo;
+ struct stransfer *qtrans;
+ const char *zlog;
+
+ qsys = qdaemon->qsys;
+
+ if (! qsys->uuconf_frec_request)
+ {
+ ulog (LOG_ERROR, "%s: not permitted to receive files from remote",
+ qcmd->zfrom);
+ return fremote_send_fail (qdaemon, qcmd, FAILURE_PERM, iremote);
+ }
+
+ fspool = fspool_file (qcmd->zto);
+
+ /* We don't accept remote command files. An execution request may
+ only send a simple data file. */
+ if ((fspool && qcmd->zto[0] == 'C')
+ || (qcmd->bcmd == 'E'
+ && (! fspool || qcmd->zto[0] != 'D')))
+ {
+ ulog (LOG_ERROR, "%s: not permitted to receive", qcmd->zfrom);
+ return fremote_send_fail (qdaemon, qcmd, FAILURE_PERM, iremote);
+ }
+
+ /* See if we have already received this file in a previous
+ conversation. */
+ if (fsysdep_already_received (qsys, qcmd->zto, qcmd->ztemp))
+ return fremote_send_fail (qdaemon, qcmd, FAILURE_RECEIVED, iremote);
+
+ if (fspool)
+ {
+ zfile = zsysdep_spool_file_name (qsys, qcmd->zto, (pointer) NULL);
+ if (zfile == NULL)
+ return FALSE;
+ }
+ else
+ {
+ zfile = zsysdep_local_file (qcmd->zto, qsys->uuconf_zpubdir);
+ if (zfile != NULL)
+ {
+ char *zadd;
+
+ zadd = zsysdep_add_base (zfile, qcmd->zfrom);
+ ubuffree (zfile);
+ zfile = zadd;
+ }
+ if (zfile == NULL)
+ return FALSE;
+
+ /* Check permissions. */
+ if (! fin_directory_list (zfile, qsys->uuconf_pzremote_receive,
+ qsys->uuconf_zpubdir, TRUE,
+ FALSE, (const char *) NULL))
+ {
+ ulog (LOG_ERROR, "%s: not permitted to receive", zfile);
+ ubuffree (zfile);
+ return fremote_send_fail (qdaemon, qcmd, FAILURE_PERM, iremote);
+ }
+
+ if (strchr (qcmd->zoptions, 'f') == NULL)
+ {
+ if (! fsysdep_make_dirs (zfile, TRUE))
+ {
+ ubuffree (zfile);
+ return fremote_send_fail (qdaemon, qcmd, FAILURE_OPEN,
+ iremote);
+ }
+ }
+ }
+
+ ztemp = zsysdep_receive_temp (qsys, zfile, qcmd->ztemp);
+
+ /* Adjust the number of bytes we are prepared to receive according
+ to the amount of free space we are supposed to leave available
+ and the maximum file size we are permitted to transfer. */
+ cbytes = csysdep_bytes_free (ztemp);
+ cbytes2 = csysdep_bytes_free (zfile);
+ if (cbytes < cbytes2)
+ cbytes = cbytes2;
+
+ if (cbytes != -1)
+ {
+ cbytes -= qsys->uuconf_cfree_space;
+ if (cbytes < 0)
+ cbytes = 0;
+ }
+
+ if (qdaemon->cremote_size != -1
+ && (cbytes == -1 || qdaemon->cremote_size < cbytes))
+ cbytes = qdaemon->cremote_size;
+
+ /* If the number of bytes we are prepared to receive is less than
+ the file size, we must fail. If the remote did not tell us the
+ file size, arbitrarily assumed that it is 10240 bytes. */
+ if (cbytes != -1)
+ {
+ long csize;
+
+ csize = qcmd->cbytes;
+ if (csize == -1)
+ csize = CASSUMED_FILE_SIZE;
+ if (cbytes < csize)
+ {
+ ulog (LOG_ERROR, "%s: too big to receive", zfile);
+ ubuffree (ztemp);
+ ubuffree (zfile);
+ return fremote_send_fail (qdaemon, qcmd, FAILURE_SIZE, iremote);
+ }
+ }
+
+ /* Open the file to receive into. This may find an old copy of the
+ file, which will be used for file restart if the other side
+ supports it. */
+ e = esysdep_open_receive (qsys, zfile, qcmd->ztemp, ztemp, &crestart);
+ if (! ffileisopen (e))
+ {
+ ubuffree (ztemp);
+ ubuffree (zfile);
+ return fremote_send_fail (qdaemon, qcmd, FAILURE_OPEN, iremote);
+ }
+
+ if (crestart > 0)
+ {
+ if ((qdaemon->ifeatures & FEATURE_RESTART) == 0)
+ crestart = -1;
+ else
+ {
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO,
+ "fremote_send_file_init: Restarting receive from %ld",
+ crestart);
+ if (! ffileseek (e, crestart))
+ {
+ ulog (LOG_ERROR, "seek: %s", strerror (errno));
+ (void) ffileclose (e);
+ ubuffree (ztemp);
+ ubuffree (zfile);
+ return FALSE;
+ }
+ }
+ }
+
+ qinfo = (struct srecinfo *) xmalloc (sizeof (struct srecinfo));
+ if (strchr (qcmd->zoptions, 'n') == NULL)
+ qinfo->zmail = NULL;
+ else
+ qinfo->zmail = zbufcpy (qcmd->znotify);
+ qinfo->zfile = zfile;
+ qinfo->ztemp = ztemp;
+ qinfo->fspool = fspool;
+ qinfo->flocal = FALSE;
+ qinfo->freceived = FALSE;
+ qinfo->freplied = FALSE;
+
+ qtrans = qtransalc (qcmd);
+ qtrans->psendfn = fremote_send_reply;
+ qtrans->precfn = frec_file_end;
+ qtrans->iremote = iremote;
+ qtrans->pinfo = (pointer) qinfo;
+ qtrans->frecfile = TRUE;
+ qtrans->e = e;
+ if (crestart > 0)
+ qtrans->ipos = crestart;
+
+ if (qcmd->bcmd == 'E')
+ zlog = qcmd->zcmd;
+ else
+ {
+ if (qinfo->fspool)
+ zlog = qcmd->zto;
+ else
+ zlog = qinfo->zfile;
+ }
+ qtrans->zlog = zbufalc (sizeof "Receiving " + strlen (zlog));
+ sprintf (qtrans->zlog, "Receiving %s", zlog);
+
+ return fqueue_remote (qdaemon, qtrans);
+}
+
+/* Reply to a send request, and prepare to receive the file. */
+
+static boolean
+fremote_send_reply (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
+ char ab[50];
+
+ ab[0] = qtrans->s.bcmd;
+ ab[1] = 'Y';
+ if (qtrans->ipos <= 0)
+ ab[2] = '\0';
+ else
+ sprintf (ab + 2, " 0x%lx", (unsigned long) qtrans->ipos);
+
+ if (! (*qdaemon->qproto->pfsendcmd) (qdaemon, ab, qtrans->ilocal,
+ qtrans->iremote))
+ {
+ (void) ffileclose (qtrans->e);
+ (void) remove (qinfo->ztemp);
+ urrec_free (qtrans);
+ return FALSE;
+ }
+
+ qinfo->freplied = TRUE;
+
+ if (qdaemon->qproto->pffile != NULL)
+ {
+ boolean fhandled;
+
+ if (! (*qdaemon->qproto->pffile) (qdaemon, qtrans, TRUE, FALSE,
+ (long) -1, &fhandled))
+ {
+ (void) ffileclose (qtrans->e);
+ (void) remove (qinfo->ztemp);
+ urrec_free (qtrans);
+ return FALSE;
+ }
+ if (fhandled)
+ return TRUE;
+ }
+
+ /* If the file has been completely received, we just want to send
+ the final confirmation. Otherwise, we must wait for the file
+ first. */
+ qtrans->psendfn = frec_file_send_confirm;
+ if (qinfo->freceived)
+ return fqueue_send (qdaemon, qtrans);
+ else
+ return fqueue_receive (qdaemon, qtrans);
+}
+
+/* If we can't receive a file, queue up a response to the remote
+ system. */
+
+static boolean
+fremote_send_fail (qdaemon, qcmd, twhy, iremote)
+ struct sdaemon *qdaemon;
+ struct scmd *qcmd;
+ enum tfailure twhy;
+ int iremote;
+{
+ struct srecfailinfo *qinfo;
+ struct stransfer *qtrans;
+
+ qinfo = (struct srecfailinfo *) xmalloc (sizeof (struct srecfailinfo));
+ qinfo->twhy = twhy;
+ qinfo->fsent = FALSE;
+
+ /* If the protocol does not support multiple channels (cchans <= 1),
+ then we have essentially already received the entire file. */
+ qinfo->freceived = qdaemon->qproto->cchans <= 1;
+
+ qtrans = qtransalc (qcmd);
+ qtrans->psendfn = fremote_send_fail_send;
+ qtrans->precfn = fremote_discard;
+ qtrans->iremote = iremote;
+ qtrans->pinfo = (pointer) qinfo;
+
+ return fqueue_remote (qdaemon, qtrans);
+}
+
+/* Send a failure string for a send command to the remote system;
+ this is called when we are ready to reply to the command. */
+
+static boolean
+fremote_send_fail_send (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct srecfailinfo *qinfo = (struct srecfailinfo *) qtrans->pinfo;
+ char ab[4];
+ boolean fret;
+
+ ab[0] = qtrans->s.bcmd;
+ ab[1] = 'N';
+
+ switch (qinfo->twhy)
+ {
+ case FAILURE_PERM:
+ ab[2] = '2';
+ break;
+ case FAILURE_OPEN:
+ ab[2] = '4';
+ break;
+ case FAILURE_SIZE:
+ ab[2] = '6';
+ break;
+ case FAILURE_RECEIVED:
+ /* Remember this file as though we successfully received it;
+ when the other side acknowledges our rejection, we know that
+ we no longer have to remember that we received this file. */
+ usent_receive_ack (qdaemon, qtrans);
+ ab[2] = '8';
+ break;
+ default:
+ ab[2] = '\0';
+ break;
+ }
+
+ ab[3] = '\0';
+
+ fret = (*qdaemon->qproto->pfsendcmd) (qdaemon, ab, qtrans->ilocal,
+ qtrans->iremote);
+
+ qinfo->fsent = TRUE;
+
+ /* Wait for the end of file marker if we haven't gotten it yet. */
+ if (! qinfo->freceived)
+ {
+ if (! fqueue_receive (qdaemon, qtrans))
+ fret = FALSE;
+ }
+ else
+ {
+ xfree (qtrans->pinfo);
+ utransfree (qtrans);
+ }
+
+ return fret;
+}
+
+/* Discard data until we reach the end of the file. This is used for
+ a protocol with multiple channels, since the remote system may
+ start sending the file before the confirmation is sent. If we
+ refuse the file, the remote system will get us back in synch by
+ sending an empty buffer, which is what we look for here. */
+
+/*ARGSUSED*/
+static boolean
+fremote_discard (qtrans, qdaemon, zdata, cdata)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+ const char *zdata;
+ size_t cdata;
+{
+ struct srecfailinfo *qinfo = (struct srecfailinfo *) qtrans->pinfo;
+
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO,
+ "fremote_discard: Discarding %lu bytes",
+ (unsigned long) cdata);
+
+ if (cdata != 0)
+ return TRUE;
+
+ qinfo->freceived = TRUE;
+
+ /* If we have already sent the denial, we are done. */
+ if (qinfo->fsent)
+ {
+ xfree (qtrans->pinfo);
+ utransfree (qtrans);
+ }
+
+ return TRUE;
+}
+
+/* This is called when a file has been completely received. It sends
+ a response to the remote system. */
+
+/*ARGSUSED*/
+static boolean
+frec_file_end (qtrans, qdaemon, zdata, cdata)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+ const char *zdata;
+ size_t cdata;
+{
+ struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
+ const char *zerr;
+ boolean fnever;
+
+ DEBUG_MESSAGE3 (DEBUG_UUCP_PROTO, "frec_file_end: %s to %s (freplied %s)",
+ qtrans->s.zfrom, qtrans->s.zto,
+ qinfo->freplied ? "TRUE" : "FALSE");
+
+ if (qdaemon->qproto->pffile != NULL)
+ {
+ boolean fhandled;
+
+ if (! (*qdaemon->qproto->pffile) (qdaemon, qtrans, FALSE, FALSE,
+ (long) -1, &fhandled))
+ {
+ (void) ffileclose (qtrans->e);
+ (void) remove (qinfo->ztemp);
+ urrec_free (qtrans);
+ return FALSE;
+ }
+ if (fhandled)
+ return TRUE;
+ }
+
+ qinfo->freceived = TRUE;
+
+ fnever = FALSE;
+
+ if (! ffileclose (qtrans->e))
+ {
+ zerr = strerror (errno);
+ ulog (LOG_ERROR, "%s: close: %s", qtrans->s.zto, zerr);
+ }
+ else if (! fsysdep_move_file (qinfo->ztemp, qinfo->zfile, qinfo->fspool,
+ FALSE, ! qinfo->fspool,
+ (qinfo->flocal
+ ? qtrans->s.zuser
+ : (const char *) NULL)))
+ {
+ zerr = "could not move to final location";
+ ulog (LOG_ERROR, "%s: %s", qinfo->zfile, zerr);
+ fnever = TRUE;
+ }
+ else
+ {
+ if (! qinfo->fspool)
+ {
+ unsigned int imode;
+
+ /* Unless we can change the ownership of the file, the only
+ choice to make about these bits is whether to set the
+ execute bit or not. */
+ if ((qtrans->s.imode & 0111) != 0)
+ imode = 0777;
+ else
+ imode = 0666;
+ (void) fsysdep_change_mode (qinfo->zfile, imode);
+ }
+
+ zerr = NULL;
+ }
+
+ if (zerr != NULL)
+ (void) remove (qinfo->ztemp);
+
+ ustats (zerr == NULL, qtrans->s.zuser, qdaemon->qsys->uuconf_zname,
+ FALSE, qtrans->cbytes, qtrans->isecs, qtrans->imicros,
+ qdaemon->fmaster);
+
+ if (zerr == NULL)
+ {
+ if (qinfo->zmail != NULL && *qinfo->zmail != '\0')
+ (void) fmail_transfer (TRUE, qtrans->s.zuser, qinfo->zmail,
+ (const char *) NULL,
+ qtrans->s.zfrom, qdaemon->qsys->uuconf_zname,
+ qtrans->s.zto, (const char *) NULL,
+ (const char *) NULL);
+
+ if (qtrans->s.pseq != NULL)
+ (void) fsysdep_did_work (qtrans->s.pseq);
+
+ if (! qinfo->flocal)
+ {
+ /* Remember that we have received this file, so that if the
+ connection drops at this point we won't receive it again.
+ We could check the return value here, but if we return
+ FALSE we couldn't do anything but drop the connection,
+ which would hardly be reasonable. Instead we trust that
+ the administrator will notice and handle any error
+ messages, which are very unlikely to occur if everything
+ is set up correctly. */
+ (void) fsysdep_remember_reception (qdaemon->qsys, qtrans->s.zto,
+ qtrans->s.ztemp);
+ }
+ }
+ else
+ {
+ /* If the transfer failed, we send mail if it was requested
+ locally and if it can never succeed. */
+ if (qinfo->flocal && fnever)
+ {
+ (void) fmail_transfer (FALSE, qtrans->s.zuser, qinfo->zmail,
+ zerr, qtrans->s.zfrom,
+ qdaemon->qsys->uuconf_zname,
+ qtrans->s.zto, (const char *) NULL,
+ (const char *) NULL);
+ (void) fsysdep_did_work (qtrans->s.pseq);
+ }
+ }
+
+ /* If this is an execution request, we must create the execution
+ file itself. */
+ if (qtrans->s.bcmd == 'E' && zerr == NULL)
+ {
+ char *zxqt, *zxqtfile, *ztemp;
+ FILE *e;
+ boolean fbad;
+
+ /* We get an execution file name by simply replacing the leading
+ D in the received file name with an X. This pretty much
+ always has to work since we can always receive a file name
+ starting with X, so the system dependent code must be
+ prepared to see one. */
+ zxqt = zbufcpy (qtrans->s.zto);
+ zxqt[0] = 'X';
+ zxqtfile = zsysdep_spool_file_name (qdaemon->qsys, zxqt,
+ (pointer) NULL);
+ ubuffree (zxqt);
+
+ if (zxqtfile == NULL)
+ {
+ urrec_free (qtrans);
+ return FALSE;
+ }
+
+ /* We have to write via a temporary file, because otherwise
+ uuxqt might pick up the file before we have finished writing
+ it. */
+ e = NULL;
+ ztemp = zsysdep_receive_temp (qdaemon->qsys, zxqtfile, "D.0");
+ if (ztemp != NULL)
+ e = esysdep_fopen (ztemp, FALSE, FALSE, TRUE);
+
+ if (e == NULL)
+ {
+ ubuffree (zxqtfile);
+ ubuffree (ztemp);
+ urrec_free (qtrans);
+ return FALSE;
+ }
+
+ fprintf (e, "U %s %s\n", qtrans->s.zuser, qdaemon->qsys->uuconf_zname);
+ fprintf (e, "F %s\n", qtrans->s.zto);
+ fprintf (e, "I %s\n", qtrans->s.zto);
+ if (strchr (qtrans->s.zoptions, 'N') != NULL)
+ fprintf (e, "N\n");
+ if (strchr (qtrans->s.zoptions, 'Z') != NULL)
+ fprintf (e, "Z\n");
+ if (strchr (qtrans->s.zoptions, 'R') != NULL)
+ fprintf (e, "R %s\n", qtrans->s.znotify);
+ if (strchr (qtrans->s.zoptions, 'e') != NULL)
+ fprintf (e, "e\n");
+ fprintf (e, "C %s\n", qtrans->s.zcmd);
+
+ fbad = FALSE;
+ if (fclose (e) == EOF)
+ {
+ ulog (LOG_ERROR, "fclose: %s", strerror (errno));
+ (void) remove (ztemp);
+ fbad = TRUE;
+ }
+
+ if (! fbad)
+ {
+ if (! fsysdep_move_file (ztemp, zxqtfile, TRUE, FALSE, FALSE,
+ (const char *) NULL))
+ fbad = TRUE;
+ }
+
+ ubuffree (zxqtfile);
+ ubuffree (ztemp);
+
+ if (fbad)
+ {
+ urrec_free (qtrans);
+ return FALSE;
+ }
+ }
+
+ /* Prepare to send the completion string to the remote system. If
+ we have not yet replied to the remote send request, we leave the
+ transfer structure on the remote queue. Otherwise we add it to
+ the send queue. The psendfn field will already be set. */
+ qinfo->fmoved = zerr == NULL;
+ if (qinfo->freplied)
+ return fqueue_send (qdaemon, qtrans);
+
+ return TRUE;
+}
+
+/* Send the final confirmation string to the remote system. */
+
+static boolean
+frec_file_send_confirm (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
+ const char *zsend;
+ boolean fret;
+
+ if (! qinfo->fmoved)
+ zsend = "CN5";
+ else if (! qdaemon->frequest_hangup)
+ zsend = "CY";
+ else
+ {
+#if DEBUG > 0
+ if (qdaemon->fmaster)
+ ulog (LOG_FATAL, "frec_file_send_confirm: Can't happen");
+#endif
+
+ DEBUG_MESSAGE0 (DEBUG_UUCP_PROTO,
+ "frec_send_file_confirm: Requesting remote to transfer control");
+ zsend = "CYM";
+ }
+
+ fret = (*qdaemon->qproto->pfsendcmd) (qdaemon, zsend,
+ qtrans->ilocal, qtrans->iremote);
+
+ /* Now, if that was a remote command, then when the confirmation
+ message is acked we no longer have to remember that we received
+ that file. */
+ if (! qinfo->flocal && qinfo->fmoved)
+ usent_receive_ack (qdaemon, qtrans);
+
+ urrec_free (qtrans);
+ return fret;
+}
+
+/* Discard a temporary file if it is not useful. A temporary file is
+ useful if it could be used to restart a receive. This is called if
+ the connection is lost. It is only called if qtrans->frecfile is
+ TRUE. */
+
+boolean
+frec_discard_temp (qdaemon, qtrans)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+{
+ struct srecinfo *qinfo = (struct srecinfo *) qtrans->pinfo;
+
+ if ((qdaemon->ifeatures & FEATURE_RESTART) == 0
+ || qtrans->s.ztemp == NULL
+ || qtrans->s.ztemp[0] != 'D'
+ || strcmp (qtrans->s.ztemp, "D.0") == 0)
+ (void) remove (qinfo->ztemp);
+ return TRUE;
+}
diff --git a/gnu/libexec/uucp/uucico/send.c b/gnu/libexec/uucp/uucico/send.c
new file mode 100644
index 00000000000..9337de39c69
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/send.c
@@ -0,0 +1,1273 @@
+/* send.c
+ Routines to send a file.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char send_rcsid[] = "$Id: send.c,v 1.1 1993/08/04 19:36:29 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+#include "prot.h"
+#include "trans.h"
+
+/* We keep this information in the pinfo field of the stransfer
+ structure. */
+struct ssendinfo
+{
+ /* Local user to send mail to (may be NULL). */
+ char *zmail;
+ /* Full file name. */
+ char *zfile;
+ /* Number of bytes in file. */
+ long cbytes;
+ /* TRUE if this was a local request. */
+ boolean flocal;
+ /* TRUE if this is a spool directory file. */
+ boolean fspool;
+ /* TRUE if the file has been completely sent. */
+ boolean fsent;
+ /* Execution file for sending an unsupported E request. */
+ char *zexec;
+};
+
+/* Local functions. */
+
+static void usfree_send P((struct stransfer *qtrans));
+static boolean flocal_send_fail P((struct stransfer *qtrans,
+ struct scmd *qcmd,
+ const struct uuconf_system *qsys,
+ const char *zwhy));
+static boolean flocal_send_request P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean flocal_send_await_reply P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon,
+ const char *zdata, size_t cdata));
+static boolean flocal_send_cancelled P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean flocal_send_open_file P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean fremote_rec_fail P((struct sdaemon *qdaemon,
+ enum tfailure twhy, int iremote));
+static boolean fremote_rec_fail_send P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean fremote_rec_reply P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean fsend_file_end P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean fsend_await_confirm P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon,
+ const char *zdata, size_t cdata));
+static boolean fsend_exec_file_init P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static void usadd_exec_line P((char **pz, size_t *pcalc, size_t *pclen,
+ int bcmd, const char *z1, const char *z2));
+static boolean fsend_exec_file P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+
+/* Free up a send stransfer structure. */
+
+static void
+usfree_send (qtrans)
+ struct stransfer *qtrans;
+{
+ struct ssendinfo *qinfo = (struct ssendinfo *) qtrans->pinfo;
+
+ if (qinfo != NULL)
+ {
+ ubuffree (qinfo->zmail);
+ ubuffree (qinfo->zfile);
+ ubuffree (qinfo->zexec);
+ xfree (qtrans->pinfo);
+ }
+
+ utransfree (qtrans);
+}
+
+/* Set up a local request to send a file. This may be called before
+ we have even tried to call the remote system.
+
+ If we are using a traditional protocol, which doesn't support
+ channel numbers and doesn't permit the file to be sent until an
+ acknowledgement has been received, the sequence of function calls
+ looks like this:
+
+ flocal_send_file_init --> fqueue_local
+ flocal_send_request (sends S request) --> fqueue_receive
+ flocal_send_await_reply (waits for SY) --> fqueue_send
+ flocal_send_open_file (opens file, calls pffile) --> fqueue_send
+ send file
+ fsend_file_end (calls pffile) --> fqueue_receive
+ fsend_await_confirm (waits for CY)
+
+ If flocal_send_await_reply gets an SN, it deletes the request. If
+ the SY reply contains a file position at which to start sending,
+ flocal_send_await_reply sets qinfo->ipos.
+
+ This gets more complex if the protocol supports channels. In that
+ case, we want to start sending the file data immediately, to avoid
+ the round trip delay between flocal_send_request and
+ flocal_send_await_reply. To do this, flocal_send_request calls
+ fqueue_send rather than fqueue_receive. The main execution
+ sequence looks like this:
+
+ flocal_send_file_init --> fqueue_local
+ flocal_send_request (sends S request) --> fqueue_send
+ flocal_send_open_file (opens file, calls pffile) --> fqueue_send
+ send file
+ fsend_file_end (calls pffile) --> fqueue_receive
+ sometime: flocal_send_await_reply (waits for SY)
+ fsend_await_confirm (waits for CY)
+
+ In this case flocal_send_await_reply must be run before
+ fsend_await_confirm; it may be run anytime after
+ flocal_send_request.
+
+ If flocal_send_await_reply is called before the entire file has
+ been sent: if it gets an SN, it calls flocal_send_cancelled to send
+ an empty data block to inform the remote system that the file
+ transfer has stopped. If it gets a file position request, it must
+ adjust the file position accordingly.
+
+ If flocal_send_await_reply is called after the entire file has been
+ sent: if it gets an SN, it can simply delete the request. It can
+ ignore any file position request.
+
+ If the request is not deleted, flocal_send_await_reply must arrange
+ for the next string to be passed to fsend_await_confirm.
+ Presumably fsend_await_confirm will only be called after the entire
+ file has been sent.
+
+ Just to make things even more complex, these same routines support
+ sending execution requests, since that is much like sending a file.
+ For an execution request, the bcmd character will be E rather than
+ S. If an execution request is being sent to a system which does
+ not support them, it must be sent as two S requests instead. The
+ second one will be the execution file, but no actual file is
+ created; instead the zexec and znext fields in the ssendinfo
+ structure are used. So if the bcmd character is E, then if the
+ zexec field is NULL, the data file is being sent, otherwise the
+ fake execution file is being sent. */
+
+boolean
+flocal_send_file_init (qdaemon, qcmd)
+ struct sdaemon *qdaemon;
+ struct scmd *qcmd;
+{
+ const struct uuconf_system *qsys;
+ boolean fspool;
+ char *zfile;
+ long cbytes;
+ struct ssendinfo *qinfo;
+ struct stransfer *qtrans;
+
+ qsys = qdaemon->qsys;
+
+ if (qdaemon->fcaller
+ ? ! qsys->uuconf_fcall_transfer
+ : ! qsys->uuconf_fcalled_transfer)
+ {
+ /* uux or uucp should have already made sure that the transfer
+ is possible, but it might have changed since then. */
+ if (! qsys->uuconf_fcall_transfer
+ && ! qsys->uuconf_fcalled_transfer)
+ return flocal_send_fail ((struct stransfer *) NULL, qcmd, qsys,
+ "not permitted to transfer files");
+
+ /* We can't do the request now, but it may get done later. */
+ return TRUE;
+ }
+
+ /* The 'C' option means that the file has been copied to the spool
+ directory. */
+ if (strchr (qcmd->zoptions, 'C') == NULL
+ && ! fspool_file (qcmd->zfrom))
+ {
+ fspool = FALSE;
+ if (! fin_directory_list (qcmd->zfrom,
+ qsys->uuconf_pzlocal_send,
+ qsys->uuconf_zpubdir, TRUE,
+ TRUE, qcmd->zuser))
+ return flocal_send_fail ((struct stransfer *) NULL, qcmd, qsys,
+ "not permitted to send");
+ zfile = zbufcpy (qcmd->zfrom);
+ }
+ else
+ {
+ fspool = TRUE;
+ zfile = zsysdep_spool_file_name (qsys, qcmd->ztemp, qcmd->pseq);
+ if (zfile == NULL)
+ return FALSE;
+ }
+
+ /* Make sure we meet any local size restrictions. The connection
+ may not have been opened at this point, so we can't check remote
+ size restrictions. */
+ cbytes = csysdep_size (zfile);
+ if (cbytes < 0)
+ {
+ ubuffree (zfile);
+ if (cbytes != -1)
+ return FALSE;
+ /* A cbytes value of -1 means that the file does not exist.
+ This can happen legitimately if it has already been sent from
+ the spool directory. */
+ if (! fspool)
+ return flocal_send_fail ((struct stransfer *) NULL, qcmd, qsys,
+ "does not exist");
+ (void) fsysdep_did_work (qcmd->pseq);
+ return TRUE;
+ }
+
+ if (qdaemon->clocal_size != -1
+ && qdaemon->clocal_size < cbytes)
+ {
+ ubuffree (zfile);
+
+ if (qdaemon->cmax_ever == -2)
+ {
+ long c1, c2;
+
+ c1 = cmax_size_ever (qsys->uuconf_qcall_local_size);
+ c2 = cmax_size_ever (qsys->uuconf_qcalled_local_size);
+ if (c1 > c2)
+ qdaemon->cmax_ever = c1;
+ else
+ qdaemon->cmax_ever = c2;
+ }
+
+ if (qdaemon->cmax_ever != -1
+ && qdaemon->cmax_ever < qcmd->cbytes)
+ return flocal_send_fail ((struct stransfer *) NULL, qcmd, qsys,
+ "too large to send");
+
+ return TRUE;
+ }
+
+ /* We are now prepared to send the command to the remote system. We
+ queue up a transfer request to send the command when we are
+ ready. */
+ qinfo = (struct ssendinfo *) xmalloc (sizeof (struct ssendinfo));
+ if (strchr (qcmd->zoptions, 'm') == NULL)
+ qinfo->zmail = NULL;
+ else
+ qinfo->zmail = zbufcpy (qcmd->zuser);
+ qinfo->zfile = zfile;
+ qinfo->cbytes = cbytes;
+ qinfo->flocal = TRUE;
+ qinfo->fspool = fspool;
+ qinfo->fsent = FALSE;
+ qinfo->zexec = NULL;
+
+ qtrans = qtransalc (qcmd);
+ qtrans->psendfn = flocal_send_request;
+ qtrans->pinfo = (pointer) qinfo;
+
+ return fqueue_local (qdaemon, qtrans);
+}
+
+/* Clean up after a failing local send request. If zwhy is not NULL,
+ this reports an error to the log file and to the user. */
+
+static boolean
+flocal_send_fail (qtrans, qcmd, qsys, zwhy)
+ struct stransfer *qtrans;
+ struct scmd *qcmd;
+ const struct uuconf_system *qsys;
+ const char *zwhy;
+{
+ if (zwhy != NULL)
+ {
+ char *zfree;
+
+ if (qcmd->bcmd != 'E')
+ zfree = NULL;
+ else
+ {
+ zfree = zbufalc (sizeof "Execution of \"\": "
+ + strlen (qcmd->zcmd)
+ + strlen (zwhy));
+ sprintf (zfree, "Execution of \"%s\": %s", qcmd->zcmd, zwhy);
+ zwhy = zfree;
+ }
+
+ ulog (LOG_ERROR, "%s: %s", qcmd->zfrom, zwhy);
+ (void) fmail_transfer (FALSE, qcmd->zuser, (const char *) NULL,
+ zwhy, qcmd->zfrom, (const char *) NULL,
+ qcmd->zto, qsys->uuconf_zname,
+ zsysdep_save_temp_file (qcmd->pseq));
+
+ ubuffree (zfree);
+ }
+
+ (void) fsysdep_did_work (qcmd->pseq);
+
+ if (qtrans != NULL)
+ usfree_send (qtrans);
+
+ return TRUE;
+}
+
+/* This is called when we are ready to send the request to the remote
+ system. We form the request and send it over. If the protocol
+ does not support multiple channels, we start waiting for the
+ response; otherwise we can start sending the file immediately. */
+
+static boolean
+flocal_send_request (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct ssendinfo *qinfo = (struct ssendinfo *) qtrans->pinfo;
+ char *zsend;
+ const char *znotify;
+ char absize[20];
+ boolean fret;
+
+ /* Make sure the file meets any remote size restrictions. */
+ if (qdaemon->cmax_receive != -1
+ && qdaemon->cmax_receive < qinfo->cbytes)
+ return flocal_send_fail (qtrans, &qtrans->s, qdaemon->qsys,
+ "too large for receiver");
+
+ /* Construct the notify string to send. If we are going to send a
+ size or an execution command, it must be non-empty. */
+ znotify = qtrans->s.znotify;
+ if (znotify == NULL)
+ znotify = "";
+ if ((qdaemon->ifeatures & FEATURE_SIZES) != 0
+ || (qtrans->s.bcmd == 'E'
+ && (qdaemon->ifeatures & FEATURE_EXEC) != 0))
+ {
+ if (*znotify == '\0')
+ znotify = "\"\"";
+ }
+ else
+ {
+ /* We don't need a notify string. Some crufty UUCP code can't
+ handle a pair of double quotes. */
+ if (strcmp (znotify, "\"\"") == 0)
+ znotify = "";
+ }
+
+ /* Construct the size string to send. */
+ if ((qdaemon->ifeatures & FEATURE_SIZES) == 0
+ && (qtrans->s.bcmd != 'E'
+ || (qdaemon->ifeatures & FEATURE_EXEC) == 0))
+ absize[0] = '\0';
+ else if ((qdaemon->ifeatures & FEATURE_V103) == 0)
+ sprintf (absize, "0x%lx", (unsigned long) qinfo->cbytes);
+ else
+ sprintf (absize, "%ld", qinfo->cbytes);
+
+ zsend = zbufalc (strlen (qtrans->s.zfrom) + strlen (qtrans->s.zto)
+ + strlen (qtrans->s.zuser) + strlen (qtrans->s.zoptions)
+ + strlen (qtrans->s.ztemp) + strlen (znotify)
+ + strlen (absize)
+ + (qtrans->s.zcmd != NULL ? strlen (qtrans->s.zcmd) : 0)
+ + 50);
+
+ /* If this an execution request and the other side supports
+ execution requests, we send an E command. Otherwise we send an S
+ command. The case of an execution request when we are sending
+ the fake execution file is handled just like an S request at this
+ point. */
+ if (qtrans->s.bcmd == 'E'
+ && (qdaemon->ifeatures & FEATURE_EXEC) != 0)
+ {
+ /* Send the string
+ E zfrom zto zuser zoptions ztemp imode znotify size zcmd
+ to the remote system. We put a '-' in front of the (possibly
+ empty) options and a '0' in front of the mode. */
+ sprintf (zsend, "E %s %s %s -%s %s 0%o %s %s %s", qtrans->s.zfrom,
+ qtrans->s.zto, qtrans->s.zuser, qtrans->s.zoptions,
+ qtrans->s.ztemp, qtrans->s.imode, znotify, absize,
+ qtrans->s.zcmd);
+ }
+ else
+ {
+ const char *zoptions, *zdummy;
+
+ /* Send the string
+ S zfrom zto zuser zoptions ztemp imode znotify
+ to the remote system. We put a '-' in front of the (possibly
+ empty) options and a '0' in front of the mode. If size
+ negotiation is supported, we also send the size; in this case
+ if znotify is empty we must send it as "". If this is really
+ an execution request, we have to simplify the options string
+ to remove the various execution options which may confuse the
+ remote system. SVR4 expects a string "dummy" between the
+ notify string and the size; I don't know why. */
+ if (qtrans->s.bcmd != 'E')
+ zoptions = qtrans->s.zoptions;
+ else if (strchr (qtrans->s.zoptions, 'C') != NULL)
+ {
+ /* This should set zoptions to "C", but at least one UUCP
+ program gets confused by it. That means that it will
+ fail in certain cases, but I suppose we might as well
+ kowtow to compatibility. This shouldn't matter to any
+ other program, I hope. */
+ zoptions = "";
+ }
+ else
+ zoptions = "c";
+
+ if ((qdaemon->ifeatures & FEATURE_SVR4) != 0)
+ zdummy = " dummy ";
+ else
+ zdummy = " ";
+
+ sprintf (zsend, "S %s %s %s -%s %s 0%o %s%s%s", qtrans->s.zfrom,
+ qtrans->s.zto, qtrans->s.zuser, zoptions,
+ qtrans->s.ztemp, qtrans->s.imode, znotify, zdummy,
+ absize);
+ }
+
+ fret = (*qdaemon->qproto->pfsendcmd) (qdaemon, zsend, qtrans->ilocal,
+ qtrans->iremote);
+ ubuffree (zsend);
+ if (! fret)
+ {
+ usfree_send (qtrans);
+ return FALSE;
+ }
+
+ /* If we are using a protocol which can make multiple channels, then
+ we can open and send the file whenever we are ready. This is
+ because we will be able to distinguish the response by the
+ channel it is directed to. This assumes that every protocol
+ which supports multiple channels also supports sending the file
+ position in mid-stream, since otherwise we would not be able to
+ restart files. */
+ qtrans->fcmd = TRUE;
+ qtrans->psendfn = flocal_send_open_file;
+ qtrans->precfn = flocal_send_await_reply;
+
+ if (qdaemon->qproto->cchans > 1)
+ return fqueue_send (qdaemon, qtrans);
+ else
+ return fqueue_receive (qdaemon, qtrans);
+}
+
+/* This is called when a reply is received for the send request. As
+ described at length above, if the protocol supports multiple
+ channels we may be in the middle of sending the file, or we may
+ even finished sending the file. */
+
+static boolean
+flocal_send_await_reply (qtrans, qdaemon, zdata, cdata)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+ const char *zdata;
+ size_t cdata;
+{
+ struct ssendinfo *qinfo = (struct ssendinfo *) qtrans->pinfo;
+ char bcmd;
+
+ if (qtrans->s.bcmd == 'E'
+ && (qdaemon->ifeatures & FEATURE_EXEC) != 0)
+ bcmd = 'E';
+ else
+ bcmd = 'S';
+ if (zdata[0] != bcmd
+ || (zdata[1] != 'Y' && zdata[1] != 'N'))
+ {
+ ulog (LOG_ERROR, "%s: Bad response to %c request: \"%s\"",
+ qtrans->s.zfrom, bcmd, zdata);
+ usfree_send (qtrans);
+ return FALSE;
+ }
+
+ if (zdata[1] == 'N')
+ {
+ const char *zerr;
+ boolean fnever;
+
+ fnever = TRUE;
+ if (zdata[2] == '2')
+ zerr = "permission denied by remote";
+ else if (zdata[2] == '4')
+ {
+ zerr = "remote cannot create work files";
+ fnever = FALSE;
+ }
+ else if (zdata[2] == '6')
+ {
+ zerr = "too large for remote now";
+ fnever = FALSE;
+ }
+ else if (zdata[2] == '7')
+ {
+ /* The file is too large to ever send. */
+ zerr = "too large for remote";
+ }
+ else if (zdata[2] == '8')
+ {
+ /* The file was already received by the remote system. This
+ is not an error, it just means that the ack from the
+ remote was lost in the previous conversation, and there
+ is no need to resend the file. */
+ zerr = NULL;
+ }
+ else
+ zerr = "unknown reason";
+
+ if (! fnever)
+ {
+ if (qtrans->s.bcmd == 'E')
+ ulog (LOG_ERROR, "Execution of \"%s\": %s", qtrans->s.zcmd,
+ zerr);
+ else
+ ulog (LOG_ERROR, "%s: %s", qtrans->s.zfrom, zerr);
+ }
+ else
+ {
+ if (! flocal_send_fail ((struct stransfer *) NULL, &qtrans->s,
+ qdaemon->qsys, zerr))
+ return FALSE;
+ }
+
+ /* If the protocol does not support multiple channels, we can
+ simply remove the transaction. Otherwise we must make sure
+ the remote side knows that we have finished sending the file
+ data. If we have already sent the entire file, there will be
+ no confusion. */
+ if (qdaemon->qproto->cchans == 1 || qinfo->fsent)
+ {
+ usfree_send (qtrans);
+ return TRUE;
+ }
+ else
+ {
+ qtrans->psendfn = flocal_send_cancelled;
+ qtrans->precfn = NULL;
+ qtrans->fsendfile = FALSE;
+ return fqueue_send (qdaemon, qtrans);
+ }
+ }
+
+ /* A number following the SY or EY is the file position to start
+ sending from. If we are already sending the file, we must set
+ the position accordingly. */
+ if (zdata[2] != '\0')
+ {
+ long cskip;
+
+ cskip = strtol ((char *) (zdata + 2), (char **) NULL, 0);
+ if (cskip > 0 && qtrans->ipos < cskip)
+ {
+ if (qtrans->fsendfile && ! qinfo->fsent)
+ {
+ if (! ffileseek (qtrans->e, cskip))
+ {
+ ulog (LOG_ERROR, "seek: %s", strerror (errno));
+ usfree_send (qtrans);
+ return FALSE;
+ }
+ }
+ qtrans->ipos = cskip;
+ }
+ }
+
+ /* Now queue up to send the file or to wait for the confirmation.
+ We already set psendfn at the end of flocal_send_request. If the
+ protocol supports multiple channels, we have already called
+ fqueue_send; calling it again would move the request in the
+ queue, which would make the log file a bit confusing. */
+ qtrans->precfn = fsend_await_confirm;
+ if (qinfo->fsent)
+ return fqueue_receive (qdaemon, qtrans);
+ else if (qdaemon->qproto->cchans <= 1)
+ return fqueue_send (qdaemon, qtrans);
+ else
+ return TRUE;
+}
+
+/* Open the file, if any, and prepare to send it. */
+
+static boolean
+flocal_send_open_file (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct ssendinfo *qinfo = (struct ssendinfo *) qtrans->pinfo;
+ const char *zuser;
+
+ /* If this is not a fake execution file, open it. */
+ if (qinfo->zexec == NULL)
+ {
+ /* If there is an ! in the user name, this is a remote request
+ queued up by fremote_xcmd_init. */
+ zuser = qtrans->s.zuser;
+ if (strchr (zuser, '!') != NULL)
+ zuser = NULL;
+
+ qtrans->e = esysdep_open_send (qdaemon->qsys, qinfo->zfile,
+ ! qinfo->fspool, zuser);
+ if (! ffileisopen (qtrans->e))
+ {
+ (void) fmail_transfer (FALSE, qtrans->s.zuser,
+ (const char *) NULL,
+ "cannot open file",
+ qtrans->s.zfrom, (const char *) NULL,
+ qtrans->s.zto,
+ qdaemon->qsys->uuconf_zname,
+ zsysdep_save_temp_file (qtrans->s.pseq));
+ (void) fsysdep_did_work (qtrans->s.pseq);
+ usfree_send (qtrans);
+
+ /* Unfortunately, there is no way to cancel a file send
+ after we've already put it in progress. So we have to
+ return FALSE to drop the connection. */
+ return FALSE;
+ }
+ }
+
+ /* If flocal_send_await_reply has received a reply with a file
+ position, it will have set qtrans->ipos to the position at which
+ to start. */
+ if (qtrans->ipos > 0)
+ {
+ if (qinfo->zexec != NULL)
+ {
+ if (qtrans->ipos > qtrans->cbytes)
+ qtrans->ipos = qtrans->cbytes;
+ }
+ else
+ {
+ if (! ffileseek (qtrans->e, qtrans->ipos))
+ {
+ ulog (LOG_ERROR, "seek: %s", strerror (errno));
+ usfree_send (qtrans);
+ return FALSE;
+ }
+ }
+ }
+
+ /* We don't bother to log sending the execution file. */
+ if (qinfo->zexec == NULL)
+ {
+ const char *zsend;
+ char *zalc;
+
+ if (qtrans->s.bcmd != 'E')
+ {
+ zsend = qtrans->s.zfrom;
+ zalc = NULL;
+ }
+ else
+ {
+ zalc = zbufalc (strlen (qtrans->s.zcmd) + sizeof " ()"
+ + strlen (qtrans->s.zfrom));
+ sprintf (zalc, "%s (%s)", qtrans->s.zcmd, qtrans->s.zfrom);
+ zsend = zalc;
+ }
+ qtrans->zlog = zbufalc (sizeof "Sending " + strlen (zsend));
+ sprintf (qtrans->zlog, "Sending %s", zsend);
+ ubuffree (zalc);
+ }
+
+ if (qdaemon->qproto->pffile != NULL)
+ {
+ boolean fhandled;
+
+ if (! (*qdaemon->qproto->pffile) (qdaemon, qtrans, TRUE, TRUE,
+ qinfo->cbytes, &fhandled))
+ {
+ usfree_send (qtrans);
+ return FALSE;
+ }
+
+ if (fhandled)
+ return TRUE;
+ }
+
+ if (qinfo->zexec != NULL)
+ qtrans->psendfn = fsend_exec_file;
+ else
+ {
+ qtrans->fsendfile = TRUE;
+ qtrans->psendfn = fsend_file_end;
+ }
+
+ return fqueue_send (qdaemon, qtrans);
+}
+
+/* Cancel a file send by sending an empty buffer. This is only called
+ for a protocol which supports multiple channels. It is needed
+ so that both systems agree as to when a channel is no longer
+ needed. */
+
+static boolean
+flocal_send_cancelled (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ char *zdata;
+ size_t cdata;
+ boolean fret;
+
+ zdata = (*qdaemon->qproto->pzgetspace) (qdaemon, &cdata);
+ if (zdata == NULL)
+ {
+ usfree_send (qtrans);
+ return FALSE;
+ }
+
+ fret = (*qdaemon->qproto->pfsenddata) (qdaemon, zdata, (size_t) 0,
+ qtrans->ilocal, qtrans->iremote,
+ qtrans->ipos);
+ usfree_send (qtrans);
+ return fret;
+}
+
+/* A remote request to receive a file (meaning that we have to send a
+ file). The sequence of functions calls is as follows:
+
+ fremote_rec_file_init (open file) --> fqueue_remote
+ fremote_rec_reply (send RY, call pffile) --> fqueue_send
+ send file
+ fsend_file_end (calls pffile) --> fqueue_receive
+ fsend_await_confirm (waits for CY)
+ */
+
+boolean
+fremote_rec_file_init (qdaemon, qcmd, iremote)
+ struct sdaemon *qdaemon;
+ struct scmd *qcmd;
+ int iremote;
+{
+ const struct uuconf_system *qsys;
+ char *zfile;
+ long cbytes;
+ unsigned int imode;
+ openfile_t e;
+ struct ssendinfo *qinfo;
+ struct stransfer *qtrans;
+
+ qsys = qdaemon->qsys;
+
+ if (! qsys->uuconf_fsend_request)
+ {
+ ulog (LOG_ERROR, "%s: not permitted to send files to remote",
+ qcmd->zfrom);
+ return fremote_rec_fail (qdaemon, FAILURE_PERM, iremote);
+ }
+
+ if (fspool_file (qcmd->zfrom))
+ {
+ ulog (LOG_ERROR, "%s: not permitted to send", qcmd->zfrom);
+ return fremote_rec_fail (qdaemon, FAILURE_PERM, iremote);
+ }
+
+ zfile = zsysdep_local_file (qcmd->zfrom, qsys->uuconf_zpubdir);
+ if (zfile != NULL)
+ {
+ char *zbased;
+
+ zbased = zsysdep_add_base (zfile, qcmd->zto);
+ ubuffree (zfile);
+ zfile = zbased;
+ }
+ if (zfile == NULL)
+ return fremote_rec_fail (qdaemon, FAILURE_PERM, iremote);
+
+ if (! fin_directory_list (zfile, qsys->uuconf_pzremote_send,
+ qsys->uuconf_zpubdir, TRUE, TRUE,
+ (const char *) NULL))
+ {
+ ulog (LOG_ERROR, "%s: not permitted to send", zfile);
+ ubuffree (zfile);
+ return fremote_rec_fail (qdaemon, FAILURE_PERM, iremote);
+ }
+
+ /* If the file is larger than the amount of space the other side
+ reported, we can't send it. Should we adjust this check based on
+ the restart position? */
+ cbytes = csysdep_size (zfile);
+ if (cbytes != -1
+ && ((qcmd->cbytes != -1 && qcmd->cbytes < cbytes)
+ || (qdaemon->cremote_size != -1
+ && qdaemon->cremote_size < cbytes)
+ || (qdaemon->cmax_receive != -1
+ && qdaemon->cmax_receive < cbytes)))
+ {
+ ulog (LOG_ERROR, "%s: too large to send", zfile);
+ ubuffree (zfile);
+ return fremote_rec_fail (qdaemon, FAILURE_SIZE, iremote);
+ }
+
+ imode = ixsysdep_file_mode (zfile);
+
+ e = esysdep_open_send (qsys, zfile, TRUE, (const char *) NULL);
+ if (! ffileisopen (e))
+ {
+ ubuffree (zfile);
+ return fremote_rec_fail (qdaemon, FAILURE_OPEN, iremote);
+ }
+
+ /* If the remote requested that the file send start from a
+ particular position, arrange to do so. */
+ if (qcmd->ipos > 0)
+ {
+ if (! ffileseek (e, qcmd->ipos))
+ {
+ ulog (LOG_ERROR, "seek: %s", strerror (errno));
+ ubuffree (zfile);
+ return FALSE;
+ }
+ }
+
+ qinfo = (struct ssendinfo *) xmalloc (sizeof (struct ssendinfo));
+ qinfo->zmail = NULL;
+ qinfo->zfile = zfile;
+ qinfo->cbytes = cbytes;
+ qinfo->flocal = FALSE;
+ qinfo->fspool = FALSE;
+ qinfo->fsent = FALSE;
+ qinfo->zexec = NULL;
+
+ qtrans = qtransalc (qcmd);
+ qtrans->psendfn = fremote_rec_reply;
+ qtrans->iremote = iremote;
+ qtrans->pinfo = (pointer) qinfo;
+ qtrans->e = e;
+ qtrans->ipos = qcmd->ipos;
+ qtrans->s.imode = imode;
+
+ return fqueue_remote (qdaemon, qtrans);
+}
+
+/* Reply to a receive request from the remote system, and prepare to
+ start sending the file. */
+
+static boolean
+fremote_rec_reply (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct ssendinfo *qinfo = (struct ssendinfo *) qtrans->pinfo;
+ char absend[50];
+
+ sprintf (absend, "RY 0%o 0x%lx", qtrans->s.imode,
+ (unsigned long) qinfo->cbytes);
+ if (! (*qdaemon->qproto->pfsendcmd) (qdaemon, absend, qtrans->ilocal,
+ qtrans->iremote))
+ {
+ (void) ffileclose (qtrans->e);
+ usfree_send (qtrans);
+ return FALSE;
+ }
+
+ qtrans->zlog = zbufalc (sizeof "Sending " + strlen (qtrans->s.zfrom));
+ sprintf (qtrans->zlog, "Sending %s", qtrans->s.zfrom);
+
+ if (qdaemon->qproto->pffile != NULL)
+ {
+ boolean fhandled;
+
+ if (! (*qdaemon->qproto->pffile) (qdaemon, qtrans, TRUE, TRUE,
+ qinfo->cbytes, &fhandled))
+ {
+ usfree_send (qtrans);
+ return FALSE;
+ }
+
+ if (fhandled)
+ return TRUE;
+ }
+
+ qtrans->fsendfile = TRUE;
+ qtrans->psendfn = fsend_file_end;
+ qtrans->precfn = fsend_await_confirm;
+
+ return fqueue_send (qdaemon, qtrans);
+}
+
+/* If we can't send a file as requested by the remote system, queue up
+ a failure reply which will be sent when possible. */
+
+static boolean
+fremote_rec_fail (qdaemon, twhy, iremote)
+ struct sdaemon *qdaemon;
+ enum tfailure twhy;
+ int iremote;
+{
+ enum tfailure *ptinfo;
+ struct stransfer *qtrans;
+
+ ptinfo = (enum tfailure *) xmalloc (sizeof (enum tfailure));
+ *ptinfo = twhy;
+
+ qtrans = qtransalc ((struct scmd *) NULL);
+ qtrans->psendfn = fremote_rec_fail_send;
+ qtrans->iremote = iremote;
+ qtrans->pinfo = (pointer) ptinfo;
+
+ return fqueue_remote (qdaemon, qtrans);
+}
+
+/* Send a failure string for a receive command to the remote system;
+ this is called when we are ready to reply to the command. */
+
+static boolean
+fremote_rec_fail_send (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ enum tfailure *ptinfo = (enum tfailure *) qtrans->pinfo;
+ const char *z;
+ boolean fret;
+
+ switch (*ptinfo)
+ {
+ case FAILURE_PERM:
+ case FAILURE_OPEN:
+ z = "RN2";
+ break;
+ case FAILURE_SIZE:
+ z = "RN6";
+ break;
+ default:
+ z = "RN";
+ break;
+ }
+
+ fret = (*qdaemon->qproto->pfsendcmd) (qdaemon, z, qtrans->ilocal,
+ qtrans->iremote);
+ xfree (qtrans->pinfo);
+ utransfree (qtrans);
+ return fret;
+}
+
+/* This is called when the main loop has finished sending a file. It
+ prepares to wait for a response from the remote system. Note that
+ if this is a local request and the protocol supports multiple
+ channels, we may not even have received a confirmation of the send
+ request. */
+
+static boolean
+fsend_file_end (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct ssendinfo *qinfo = (struct ssendinfo *) qtrans->pinfo;
+
+ if (qdaemon->qproto->pffile != NULL)
+ {
+ boolean fhandled;
+
+ if (! (*qdaemon->qproto->pffile) (qdaemon, qtrans, FALSE, TRUE,
+ (long) -1, &fhandled))
+ {
+ usfree_send (qtrans);
+ return FALSE;
+ }
+
+ if (fhandled)
+ return TRUE;
+ }
+
+ qinfo->fsent = TRUE;
+
+ /* qtrans->precfn should have been set by a previous function. */
+ qtrans->fcmd = TRUE;
+ return fqueue_receive (qdaemon, qtrans);
+}
+
+/* Handle the confirmation string received after sending a file. */
+
+/*ARGSUSED*/
+static boolean
+fsend_await_confirm (qtrans, qdaemon, zdata, cdata)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+ const char *zdata;
+ size_t cdata;
+{
+ struct ssendinfo *qinfo = (struct ssendinfo *) qtrans->pinfo;
+ boolean fnever;
+ const char *zerr;
+
+ if (qinfo->zexec == NULL)
+ (void) ffileclose (qtrans->e);
+
+ fnever = FALSE;
+ if (zdata[0] != 'C'
+ || (zdata[1] != 'Y' && zdata[1] != 'N'))
+ {
+ zerr = "bad confirmation from remote";
+ ulog (LOG_ERROR, "%s: %s \"%s\"", qtrans->s.zfrom, zerr, zdata);
+ }
+ else if (zdata[1] == 'N')
+ {
+ fnever = TRUE;
+ if (zdata[2] == '5')
+ {
+ zerr = "file could not be stored in final location";
+ ulog (LOG_ERROR, "%s: %s", qtrans->s.zfrom, zerr);
+ }
+ else
+ {
+ zerr = "file send failed for unknown reason";
+ ulog (LOG_ERROR, "%s: %s \"%s\"", qtrans->s.zfrom, zerr, zdata);
+ }
+ }
+ else
+ {
+ zerr = NULL;
+
+ /* If we receive CYM, it means that the other side wants us to
+ hang up so that they can send us something. The
+ fhangup_requested field is checked in the main loop. */
+ if (zdata[2] == 'M' && qdaemon->fmaster)
+ {
+ DEBUG_MESSAGE0 (DEBUG_UUCP_PROTO,
+ "fsend_await_confirm: Remote has requested transfer of control");
+ qdaemon->fhangup_requested = TRUE;
+ }
+ }
+
+ ustats (zerr == NULL, qtrans->s.zuser, qdaemon->qsys->uuconf_zname,
+ TRUE, qtrans->cbytes, qtrans->isecs, qtrans->imicros,
+ qdaemon->fmaster);
+
+ if (zerr == NULL)
+ {
+ /* If this is an execution request, and the remote system
+ doesn't support execution requests, we have to set up the
+ fake execution file and loop around again. */
+ if (qtrans->s.bcmd == 'E'
+ && (qdaemon->ifeatures & FEATURE_EXEC) == 0
+ && qinfo->zexec == NULL)
+ return fsend_exec_file_init (qtrans, qdaemon);
+
+ /* Send mail about the transfer if requested. */
+ if (qinfo->zmail != NULL && *qinfo->zmail != '\0')
+ (void) fmail_transfer (TRUE, qtrans->s.zuser, qinfo->zmail,
+ (const char *) NULL,
+ qtrans->s.zfrom, (const char *) NULL,
+ qtrans->s.zto, qdaemon->qsys->uuconf_zname,
+ (const char *) NULL);
+
+ if (qtrans->s.pseq != NULL)
+ (void) fsysdep_did_work (qtrans->s.pseq);
+ }
+ else
+ {
+ /* If the file send failed, we only try to save the file and
+ send mail if it was requested locally and it will never
+ succeed. We send mail to qinfo->zmail if set, otherwise to
+ qtrans->s.zuser. I hope this is reasonable. */
+ if (fnever && qinfo->flocal)
+ {
+ (void) fmail_transfer (FALSE, qtrans->s.zuser, qinfo->zmail,
+ zerr, qtrans->s.zfrom, (const char *) NULL,
+ qtrans->s.zto, qdaemon->qsys->uuconf_zname,
+ zsysdep_save_temp_file (qtrans->s.pseq));
+ (void) fsysdep_did_work (qtrans->s.pseq);
+ }
+ }
+
+ usfree_send (qtrans);
+
+ return TRUE;
+}
+
+/* Prepare to send an execution file to a system which does not
+ support execution requests. We build the execution file in memory,
+ and then call flocal_send_request as though we were sending a real
+ file. Instead of sending a file, the code in flocal_send_open_file
+ will arrange to call fsend_exec_file which will send data out of
+ the buffer we have created. */
+
+static boolean
+fsend_exec_file_init (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct ssendinfo *qinfo = (struct ssendinfo *) qtrans->pinfo;
+ char *zxqtfile;
+ char abtname[CFILE_NAME_LEN];
+ char abxname[CFILE_NAME_LEN];
+ char *z;
+ size_t calc, clen;
+
+ z = NULL;
+ calc = 0;
+ clen = 0;
+
+ usadd_exec_line (&z, &calc, &clen, 'U', qtrans->s.zuser,
+ qdaemon->zlocalname);
+ usadd_exec_line (&z, &calc, &clen, 'F', qtrans->s.zto, "");
+ usadd_exec_line (&z, &calc, &clen, 'I', qtrans->s.zto, "");
+ if (strchr (qtrans->s.zoptions, 'N') != NULL)
+ usadd_exec_line (&z, &calc, &clen, 'N', "", "");
+ if (strchr (qtrans->s.zoptions, 'Z') != NULL)
+ usadd_exec_line (&z, &calc, &clen, 'Z', "", "");
+ if (strchr (qtrans->s.zoptions, 'R') != NULL)
+ usadd_exec_line (&z, &calc, &clen, 'R', qtrans->s.znotify, "");
+ if (strchr (qtrans->s.zoptions, 'e') != NULL)
+ usadd_exec_line (&z, &calc, &clen, 'e', "", "");
+ usadd_exec_line (&z, &calc, &clen, 'C', qtrans->s.zcmd, "");
+
+ qinfo->zexec = z;
+ qinfo->cbytes = clen;
+
+ zxqtfile = zsysdep_data_file_name (qdaemon->qsys, qdaemon->zlocalname,
+ BDEFAULT_UUX_GRADE, TRUE, abtname,
+ (char *) NULL, abxname);
+ if (zxqtfile == NULL)
+ {
+ usfree_send (qtrans);
+ return FALSE;
+ }
+ ubuffree (zxqtfile);
+
+ ubuffree ((char *) qtrans->s.zfrom);
+ qtrans->s.zfrom = zbufcpy (abtname);
+ ubuffree ((char *) qtrans->s.zto);
+ qtrans->s.zto = zbufcpy (abxname);
+ ubuffree ((char *) qtrans->s.zoptions);
+ qtrans->s.zoptions = zbufcpy ("C");
+ ubuffree ((char *) qtrans->s.ztemp);
+ qtrans->s.ztemp = zbufcpy (abtname);
+
+ qtrans->psendfn = flocal_send_request;
+ qtrans->precfn = NULL;
+ qtrans->ipos = 0;
+ qtrans->cbytes = 0;
+ qtrans->isecs = 0;
+ qtrans->imicros = 0;
+ qinfo->fsent = FALSE;
+
+ return fqueue_send (qdaemon, qtrans);
+}
+
+/* Add a line to the fake execution file. */
+
+static void
+usadd_exec_line (pz, pcalc, pclen, bcmd, z1, z2)
+ char **pz;
+ size_t *pcalc;
+ size_t *pclen;
+ int bcmd;
+ const char *z1;
+ const char *z2;
+{
+ size_t c1, c2;
+ char *znew;
+
+ c1 = strlen (z1);
+ c2 = strlen (z2);
+
+ if (*pclen + c1 + c2 + 4 >= *pcalc)
+ {
+ *pcalc += c1 + c2 + 100;
+ znew = zbufalc (*pcalc);
+ if (*pclen > 0)
+ {
+ memcpy (znew, *pz, *pclen);
+ ubuffree (*pz);
+ }
+ *pz = znew;
+ }
+
+ znew = *pz + *pclen;
+ *znew++ = bcmd;
+ if (*z1 != '\0')
+ {
+ *znew++ = ' ';
+ memcpy (znew, z1, c1);
+ znew += c1;
+ if (*z2 != '\0')
+ {
+ *znew++ = ' ';
+ memcpy (znew, z2, c2);
+ znew += c2;
+ }
+ }
+
+ /* In some bizarre non-Unix case we might have to worry about the
+ newline here. We don't know how a newline is normally written
+ out to a file, but whatever is written to a file is what we will
+ normally transfer. If that is not simply \n then this fake
+ execution file will not look like other execution files. */
+ *znew++ = '\n';
+
+ *pclen = znew - *pz;
+}
+
+/* This routine is called to send the contents of the fake execution
+ file. Normally file data is sent by the floop routine in trans.c,
+ but since we don't have an actual file we must do it here. This
+ routine sends the complete buffer, followed by a zero length
+ packet, and then calls fsend_file_end. */
+
+static boolean
+fsend_exec_file (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ struct ssendinfo *qinfo = (struct ssendinfo *) qtrans->pinfo;
+ char *zdata;
+ size_t cdata;
+ size_t csend;
+
+ zdata = (*qdaemon->qproto->pzgetspace) (qdaemon, &cdata);
+ if (zdata == NULL)
+ {
+ usfree_send (qtrans);
+ return FALSE;
+ }
+
+ csend = qinfo->cbytes - qtrans->ipos;
+ if (csend > cdata)
+ csend = cdata;
+
+ memcpy (zdata, qinfo->zexec + qtrans->ipos, csend);
+
+ if (! (*qdaemon->qproto->pfsenddata) (qdaemon, zdata, csend,
+ qtrans->ilocal, qtrans->iremote,
+ qtrans->ipos))
+ {
+ usfree_send (qtrans);
+ return FALSE;
+ }
+
+ qtrans->cbytes += csend;
+ qtrans->ipos += csend;
+
+ if (csend == 0)
+ return fsend_file_end (qtrans, qdaemon);
+
+ /* Leave the job on the send queue. */
+
+ return TRUE;
+}
diff --git a/gnu/libexec/uucp/uucico/time.c b/gnu/libexec/uucp/uucico/time.c
new file mode 100644
index 00000000000..c082662c2bf
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/time.c
@@ -0,0 +1,130 @@
+/* time.c
+ Routines to deal with UUCP time spans.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char time_rcsid[] = "$Id: time.c,v 1.1 1993/08/04 19:36:30 jtc Exp $";
+#endif
+
+#include <ctype.h>
+
+#if HAVE_TIME_H
+#include <time.h>
+#endif
+
+#include "uudefs.h"
+#include "uuconf.h"
+
+/* External functions. */
+#ifndef time
+extern time_t time ();
+#endif
+#ifndef localtime
+extern struct tm *localtime ();
+#endif
+
+/* See if the current time matches a time span. If it does, return
+ TRUE, set *pival to the value for the matching span, and set
+ *pcretry to the retry for the matching span. Otherwise return
+ FALSE. */
+
+boolean
+ftimespan_match (qspan, pival, pcretry)
+ const struct uuconf_timespan *qspan;
+ long *pival;
+ int *pcretry;
+{
+ time_t inow;
+ struct tm *qtm;
+ int itm;
+ const struct uuconf_timespan *q;
+
+ if (qspan == NULL)
+ return FALSE;
+
+ time (&inow);
+ qtm = localtime (&inow);
+
+ /* Get the number of minutes since Sunday for the time. */
+ itm = qtm->tm_wday * 24 * 60 + qtm->tm_hour * 60 + qtm->tm_min;
+
+ for (q = qspan; q != NULL; q = q->uuconf_qnext)
+ {
+ if (q->uuconf_istart <= itm && itm <= q->uuconf_iend)
+ {
+ if (pival != NULL)
+ *pival = q->uuconf_ival;
+ if (pcretry != NULL)
+ *pcretry = q->uuconf_cretry;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+/* Determine the maximum size that may ever be transferred, according
+ to a timesize span. This returns -1 if there is no limit. */
+
+long
+cmax_size_ever (qtimesize)
+ const struct uuconf_timespan *qtimesize;
+{
+ long imax;
+ const struct uuconf_timespan *q;
+
+ if (qtimesize == NULL)
+ return -1;
+
+ /* Look through the list of spans. If there is any gap larger than
+ 1 hour, we assume there are no restrictions. Otherwise we keep
+ track of the largest value we see. I picked 1 hour arbitrarily,
+ on the theory that a 1 hour span to transfer large files might
+ actually occur, and is probably not an accident. */
+ if (qtimesize->uuconf_istart >= 60)
+ return -1;
+
+ imax = -1;
+
+ for (q = qtimesize; q != NULL; q = q->uuconf_qnext)
+ {
+ if (q->uuconf_qnext == NULL)
+ {
+ if (q->uuconf_iend <= 6 * 24 * 60 + 23 * 60)
+ return -1;
+ }
+ else
+ {
+ if (q->uuconf_iend + 60 <= q->uuconf_qnext->uuconf_istart)
+ return -1;
+ }
+
+ if (imax < q->uuconf_ival)
+ imax = q->uuconf_ival;
+ }
+
+ return imax;
+}
diff --git a/gnu/libexec/uucp/uucico/trans.c b/gnu/libexec/uucp/uucico/trans.c
new file mode 100644
index 00000000000..065caa4ac79
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/trans.c
@@ -0,0 +1,1439 @@
+/* trans.c
+ Routines to handle file transfers.
+
+ Copyright (C) 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char trans_rcsid[] = "$Id: trans.c,v 1.1 1993/08/04 19:36:31 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "prot.h"
+#include "system.h"
+#include "trans.h"
+
+/* Local functions. */
+
+static void utqueue P((struct stransfer **, struct stransfer *,
+ boolean fhead));
+static void utdequeue P((struct stransfer *));
+static void utchanalc P((struct sdaemon *qdaemon, struct stransfer *qtrans));
+__inline__ static struct stransfer *qtchan P((int ichan));
+__inline__ static void utchanfree P((struct stransfer *qtrans));
+static boolean ftcharge P((struct sdaemon *qdaemon,
+ struct stransfer *qtrans,
+ boolean fsend, boolean fforce));
+static boolean fcheck_queue P((struct sdaemon *qdaemon));
+static boolean ftadd_cmd P((struct sdaemon *qdaemon, const char *z,
+ size_t cdata, int iremote, boolean flast));
+static boolean fremote_hangup_reply P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean flocal_poll_file P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+
+/* Queue of transfer structures that are ready to start which have
+ been requested by the local system. These are only permitted to
+ start when the local system is the master. */
+static struct stransfer *qTlocal;
+
+/* Queue of transfer structures that are ready to start which have
+ been requested by the remote system. These are responses to
+ commands received from the remote system, and should be started as
+ soon as possible. */
+static struct stransfer *qTremote;
+
+/* Queue of transfer structures that have been started and want to
+ send information. This should be static, but the 'a' protocol
+ looks at it, at least for now. */
+struct stransfer *qTsend;
+
+/* Queue of transfer structures that have been started and are waiting
+ to receive information. */
+static struct stransfer *qTreceive;
+
+/* Queue of free transfer structures. */
+static struct stransfer *qTavail;
+
+/* Array of transfer structures indexed by local channel number. This
+ is maintained for local jobs. */
+static struct stransfer *aqTchan[IMAX_CHAN + 1];
+
+/* Number of local channel numbers currently allocated. */
+static int cTchans;
+
+/* Next channel number to allocate. */
+static int iTchan;
+
+/* Array of transfer structures indexed by remote channel number.
+ This is maintained for remote jobs. */
+static struct stransfer *aqTremote[IMAX_CHAN + 1];
+
+/* A structure used to charge time to file transfers. */
+struct scharge
+{
+ /* The transfer we are currently charging. */
+ struct stransfer *qtrans;
+ /* The time at the last update. */
+ long isecs;
+ long imicros;
+};
+
+/* We are always charging one send and one receive. */
+static struct scharge sTsend;
+static struct scharge sTreceive;
+
+/* The minimum amount of time, in seconds, to wait between times we
+ check the spool directory, if we are busy transferring data. If we
+ have nothing to do, we will check the spool directory regardless of
+ how long ago the last check was. This should probably be
+ configurable. */
+#define CCHECKWAIT (600)
+
+/* The time we last checked the spool directory for work. This is set
+ from the return value of ixsysdep_process_time, not ixsysdep_time,
+ for convenience in the routines which use it. */
+static long iTchecktime;
+
+/* The size of the command we have read so far in ftadd_cmd. */
+static size_t cTcmdlen;
+
+/* The structure we use when waiting for an acknowledgement of a
+ confirmed received file in fsent_receive_ack, and a list of those
+ structures. */
+
+struct sreceive_ack
+{
+ struct sreceive_ack *qnext;
+ char *zto;
+ char *ztemp;
+ boolean fmarked;
+};
+
+static struct sreceive_ack *qTreceive_ack;
+
+/* Queue up a transfer structure before *pq. This puts it at the head
+ or the tail of the list headed by *pq. */
+
+static void
+utqueue (pq, q, fhead)
+ struct stransfer **pq;
+ struct stransfer *q;
+ boolean fhead;
+{
+ if (*pq == NULL)
+ {
+ *pq = q;
+ q->qprev = q->qnext = q;
+ }
+ else
+ {
+ q->qnext = *pq;
+ q->qprev = (*pq)->qprev;
+ q->qprev->qnext = q;
+ q->qnext->qprev = q;
+ if (fhead)
+ *pq = q;
+ }
+ q->pqqueue = pq;
+}
+
+/* Dequeue a transfer structure. */
+
+static void
+utdequeue (q)
+ struct stransfer *q;
+{
+ if (q->pqqueue != NULL)
+ {
+ if (*(q->pqqueue) == q)
+ {
+ if (q->qnext == q)
+ *(q->pqqueue) = NULL;
+ else
+ *(q->pqqueue) = q->qnext;
+ }
+ q->pqqueue = NULL;
+ }
+ if (q->qprev != NULL)
+ q->qprev->qnext = q->qnext;
+ if (q->qnext != NULL)
+ q->qnext->qprev = q->qprev;
+ q->qprev = NULL;
+ q->qnext = NULL;
+}
+
+/* Queue up a transfer structure requested by the local system. */
+
+/*ARGSIGNORED*/
+boolean
+fqueue_local (qdaemon, qtrans)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+{
+ utdequeue (qtrans);
+ utqueue (&qTlocal, qtrans, FALSE);
+ return TRUE;
+}
+
+/* Queue up a transfer structure requested by the remote system. The
+ stransfer structure should have the iremote field set. We need to
+ record it, so that any subsequent data associated with this
+ channel can be routed to the right place. */
+
+boolean
+fqueue_remote (qdaemon, qtrans)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+{
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO, "fqueue_remote: Channel %d",
+ qtrans->iremote);
+ if (qtrans->iremote > 0)
+ aqTremote[qtrans->iremote] = qtrans;
+ utdequeue (qtrans);
+ utqueue (&qTremote, qtrans, FALSE);
+
+ /* We just received data for this transfer, so start charging. */
+ return ftcharge (qdaemon, qtrans, FALSE, FALSE);
+}
+
+/* Queue up a transfer with something to send. */
+
+boolean
+fqueue_send (qdaemon, qtrans)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+{
+#if DEBUG > 0
+ if (qtrans->psendfn == NULL)
+ ulog (LOG_FATAL, "fqueue_send: Bad call");
+#endif
+ utdequeue (qtrans);
+ utqueue (&qTsend, qtrans, FALSE);
+
+ /* Since we're now going to wait to send data, don't charge this
+ transfer for receive time. */
+ if (qtrans == sTreceive.qtrans)
+ return ftcharge (qdaemon, (struct stransfer *) NULL, FALSE, FALSE);
+ return TRUE;
+}
+
+/* Queue up a transfer with something to receive. */
+
+boolean
+fqueue_receive (qdaemon, qtrans)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+{
+#if DEBUG > 0
+ if (qtrans->precfn == NULL)
+ ulog (LOG_FATAL, "fqueue_receive: Bad call");
+#endif
+ utdequeue (qtrans);
+ utqueue (&qTreceive, qtrans, FALSE);
+
+ /* Since we are now going to wait to receive data, don't charge this
+ transfer for send time. */
+ if (qtrans == sTsend.qtrans)
+ return ftcharge (qdaemon, (struct stransfer *) NULL, TRUE, FALSE);
+ return TRUE;
+}
+
+/* Get a new local channel number. */
+
+static void
+utchanalc (qdaemon, qtrans)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+{
+ do
+ {
+ ++iTchan;
+ if (iTchan > qdaemon->qproto->cchans)
+ iTchan = 1;
+ }
+ while (aqTchan[iTchan] != NULL);
+
+ qtrans->ilocal = iTchan;
+ aqTchan[iTchan] = qtrans;
+ ++cTchans;
+}
+
+/* Return the transfer for a channel number. */
+
+__inline__
+static struct stransfer *
+qtchan (ic)
+ int ic;
+{
+ return aqTchan[ic];
+}
+
+/* Clear the channel number for a transfer. */
+
+__inline__
+static void
+utchanfree (qt)
+ struct stransfer *qt;
+{
+ if (qt->ilocal != 0)
+ {
+ aqTchan[qt->ilocal] = NULL;
+ qt->ilocal = 0;
+ --cTchans;
+ }
+}
+
+/* Allocate a new transfer structure. */
+
+struct stransfer *
+qtransalc (qcmd)
+ struct scmd *qcmd;
+{
+ register struct stransfer *q;
+
+ q = qTavail;
+ if (q != NULL)
+ utdequeue (q);
+ else
+ q = (struct stransfer *) xmalloc (sizeof (struct stransfer));
+ q->qnext = NULL;
+ q->qprev = NULL;
+ q->pqqueue = NULL;
+ q->psendfn = NULL;
+ q->precfn = NULL;
+ q->pinfo = NULL;
+ q->fsendfile = FALSE;
+ q->frecfile = FALSE;
+ q->e = EFILECLOSED;
+ q->ipos = 0;
+ q->fcmd = FALSE;
+ q->zcmd = NULL;
+ q->ccmd = 0;
+ q->ilocal = 0;
+ q->iremote = 0;
+ if (qcmd != NULL)
+ {
+ q->s = *qcmd;
+ q->s.zfrom = zbufcpy (qcmd->zfrom);
+ q->s.zto = zbufcpy (qcmd->zto);
+ q->s.zuser = zbufcpy (qcmd->zuser);
+ q->s.zoptions = zbufcpy (qcmd->zoptions);
+ q->s.ztemp = zbufcpy (qcmd->ztemp);
+ q->s.znotify = zbufcpy (qcmd->znotify);
+ q->s.zcmd = zbufcpy (qcmd->zcmd);
+ }
+ else
+ {
+ q->s.zfrom = NULL;
+ q->s.zto = NULL;
+ q->s.zuser = NULL;
+ q->s.zoptions = NULL;
+ q->s.ztemp = NULL;
+ q->s.znotify = NULL;
+ q->s.zcmd = NULL;
+ }
+ q->isecs = 0;
+ q->imicros = 0;
+ q->cbytes = 0;
+
+ return q;
+}
+
+/* Free a transfer structure. This does not free any pinfo
+ information that may have been allocated. */
+
+void
+utransfree (q)
+ struct stransfer *q;
+{
+ ubuffree (q->zcmd);
+ ubuffree ((char *) q->s.zfrom);
+ ubuffree ((char *) q->s.zto);
+ ubuffree ((char *) q->s.zuser);
+ ubuffree ((char *) q->s.zoptions);
+ ubuffree ((char *) q->s.ztemp);
+ ubuffree ((char *) q->s.znotify);
+ ubuffree ((char *) q->s.zcmd);
+
+ utchanfree (q);
+ if (q->iremote > 0)
+ {
+ aqTremote[q->iremote] = NULL;
+ q->iremote = 0;
+ }
+
+#if DEBUG > 0
+ q->zcmd = NULL;
+ q->s.zfrom = NULL;
+ q->s.zto = NULL;
+ q->s.zuser = NULL;
+ q->s.zoptions = NULL;
+ q->s.ztemp = NULL;
+ q->s.znotify = NULL;
+ q->s.zcmd = NULL;
+ q->psendfn = NULL;
+ q->precfn = NULL;
+#endif
+
+ /* Don't try to charge time to this structure any longer. */
+ if (sTsend.qtrans == q)
+ sTsend.qtrans = NULL;
+ if (sTreceive.qtrans == q)
+ sTreceive.qtrans = NULL;
+
+ utdequeue (q);
+ utqueue (&qTavail, q, FALSE);
+}
+
+/* Handle timing of file tranfers. This is called when processing
+ starts for a transfer structure. All time up to the next call to
+ this function is charged to that transfer structure. Sending time
+ and receiving time are charged separately. Normally if we are
+ about to start charging the same structure we are already charging,
+ we do nothing; but if the fforce argument is TRUE, we charge the
+ time anyhow. */
+
+static boolean
+ftcharge (qdaemon, qtrans, fsend, fforce)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+ boolean fsend;
+ boolean fforce;
+{
+ struct scharge *qcharge, *qother;
+ long inextsecs, inextmicros;
+
+ if (fsend)
+ {
+ qcharge = &sTsend;
+ qother = &sTreceive;
+ }
+ else
+ {
+ qcharge = &sTreceive;
+ qother = &sTsend;
+ }
+
+ if (! fforce && qtrans == qcharge->qtrans)
+ return TRUE;
+
+ inextsecs = ixsysdep_process_time (&inextmicros);
+ if (qcharge->qtrans != NULL)
+ {
+ qcharge->qtrans->isecs += inextsecs - qcharge->isecs;
+ qcharge->qtrans->imicros += inextmicros - qcharge->imicros;
+
+ /* If we are charging the same structure for both send and
+ receive, update the time we are not currently charging so
+ that we don't charge twice for the same time. */
+ if (qcharge->qtrans == qother->qtrans)
+ {
+ qother->isecs = inextsecs;
+ qother->imicros = inextmicros;
+ }
+ }
+
+ qcharge->qtrans = qtrans;
+ qcharge->isecs = inextsecs;
+ qcharge->imicros = inextmicros;
+
+ /* If enough time has elapsed since the last time we checked the
+ queue, check it again. We do this here because we have already
+ gone to the trouble of getting the time. */
+ if (inextsecs - iTchecktime >= CCHECKWAIT)
+ {
+ if (! fcheck_queue (qdaemon))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/* Gather local commands and queue them up for later processing. Also
+ recompute time based control values. */
+
+boolean
+fqueue (qdaemon, pfany)
+ struct sdaemon *qdaemon;
+ boolean *pfany;
+{
+ const struct uuconf_system *qsys;
+ int bgrade;
+ struct uuconf_timespan *qlocal_size, *qremote_size;
+
+ if (pfany != NULL)
+ *pfany = FALSE;
+
+ qsys = qdaemon->qsys;
+
+ /* If we are not the caller, the grade will be set during the
+ initial handshake. */
+ if (! qdaemon->fcaller)
+ bgrade = qdaemon->bgrade;
+ else
+ {
+ long ival;
+
+ if (! ftimespan_match (qsys->uuconf_qtimegrade, &ival,
+ (int *) NULL))
+ bgrade = '\0';
+ else
+ bgrade = (char) ival;
+ }
+
+ /* Determine the maximum sizes we can send and receive. */
+ if (qdaemon->fcaller)
+ {
+ qlocal_size = qsys->uuconf_qcall_local_size;
+ qremote_size = qsys->uuconf_qcall_remote_size;
+ }
+ else
+ {
+ qlocal_size = qsys->uuconf_qcalled_local_size;
+ qremote_size = qsys->uuconf_qcalled_remote_size;
+ }
+
+ if (! ftimespan_match (qlocal_size, &qdaemon->clocal_size, (int *) NULL))
+ qdaemon->clocal_size = (long) -1;
+ if (! ftimespan_match (qremote_size, &qdaemon->cremote_size, (int *) NULL))
+ qdaemon->cremote_size = (long) -1;
+
+ if (bgrade == '\0')
+ return TRUE;
+
+ if (! fsysdep_get_work_init (qsys, bgrade))
+ return FALSE;
+
+ while (TRUE)
+ {
+ struct scmd s;
+
+ if (! fsysdep_get_work (qsys, bgrade, &s))
+ return FALSE;
+
+ if (s.bcmd == 'H')
+ {
+ ulog_user ((const char *) NULL);
+ break;
+ }
+
+ if (s.bcmd == 'P')
+ {
+ struct stransfer *qtrans;
+
+ /* A poll file. */
+ ulog_user ((const char *) NULL);
+ qtrans = qtransalc (&s);
+ qtrans->psendfn = flocal_poll_file;
+ if (! fqueue_local (qdaemon, qtrans))
+ return FALSE;
+ continue;
+ }
+
+ ulog_user (s.zuser);
+
+ switch (s.bcmd)
+ {
+ case 'S':
+ case 'E':
+ if (! flocal_send_file_init (qdaemon, &s))
+ return FALSE;
+ break;
+ case 'R':
+ if (! flocal_rec_file_init (qdaemon, &s))
+ return FALSE;
+ break;
+ case 'X':
+ if (! flocal_xcmd_init (qdaemon, &s))
+ return FALSE;
+ break;
+#if DEBUG > 0
+ default:
+ ulog (LOG_FATAL, "fqueue: Can't happen");
+ break;
+#endif
+ }
+ }
+
+ if (pfany != NULL)
+ *pfany = qTlocal != NULL;
+
+ iTchecktime = ixsysdep_process_time ((long *) NULL);
+
+ return TRUE;
+}
+
+/* Clear everything off the work queue. This is used when the call is
+ complete, or if the call is never made. */
+
+void
+uclear_queue (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ int i;
+
+ usysdep_get_work_free (qdaemon->qsys);
+
+ qTlocal = NULL;
+ qTremote = NULL;
+ qTsend = NULL;
+ qTreceive = NULL;
+ cTchans = 0;
+ iTchan = 0;
+ sTsend.qtrans = NULL;
+ sTreceive.qtrans = NULL;
+ cTcmdlen = 0;
+ qTreceive_ack = NULL;
+ for (i = 0; i < IMAX_CHAN + 1; i++)
+ {
+ aqTchan[i] = NULL;
+ aqTremote[i] = NULL;
+ }
+}
+
+/* Recheck the work queue during a conversation. This is only called
+ if it's been more than CCHECKWAIT seconds since the last time the
+ queue was checked. */
+
+static boolean
+fcheck_queue (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ int cchans;
+
+ /* Only check if we are the master, or if there are multiple
+ channels, or if we aren't already trying to get the other side to
+ hang up. Otherwise, there's nothing we can do with any new jobs
+ we might find. */
+ if ((qdaemon->ireliable & UUCONF_RELIABLE_FULLDUPLEX) == 0)
+ cchans = 1;
+ else
+ cchans = qdaemon->qproto->cchans;
+ if (qdaemon->fmaster
+ || cchans > 1
+ || ! qdaemon->frequest_hangup)
+ {
+ boolean fany;
+
+ DEBUG_MESSAGE0 (DEBUG_UUCP_PROTO,
+ "fcheck_queue: Rechecking work queue");
+ if (! fqueue (qdaemon, &fany))
+ return FALSE;
+
+ /* If we found something to do, and we're not the master, and we
+ don't have multiple channels to send new jobs over, try to
+ get the other side to hang up. */
+ if (fany && ! qdaemon->fmaster && cchans <= 1)
+ qdaemon->frequest_hangup = TRUE;
+ }
+
+ return TRUE;
+}
+
+/* The main transfer loop. The uucico daemon spends essentially all
+ its time in this function. */
+
+boolean
+floop (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ int cchans;
+ boolean fret;
+
+ /* If we are using a half-duplex line, act as though we have only a
+ single channel; otherwise we might start a send and a receive at
+ the same time. */
+ if ((qdaemon->ireliable & UUCONF_RELIABLE_FULLDUPLEX) == 0)
+ cchans = 1;
+ else
+ cchans = qdaemon->qproto->cchans;
+
+ fret = TRUE;
+
+ while (! qdaemon->fhangup)
+ {
+ register struct stransfer *q;
+
+#if DEBUG > 1
+ /* If we're doing any debugging, close the log and debugging
+ files regularly. This will let people copy them off and
+ remove them while the conversation is in progresss. */
+ if (iDebug != 0)
+ {
+ ulog_close ();
+ ustats_close ();
+ }
+#endif
+
+ if (qdaemon->fmaster)
+ {
+ boolean fhangup;
+
+ /* We've managed to become the master, so we no longer want
+ to request a hangup. */
+ qdaemon->frequest_hangup = FALSE;
+
+ fhangup = FALSE;
+
+ if (qdaemon->fhangup_requested
+ && qTsend == NULL)
+ {
+ /* The remote system has requested that we transfer
+ control by sending CYM after receiving a file. */
+ DEBUG_MESSAGE0 (DEBUG_UUCP_PROTO,
+ "floop: Transferring control at remote request");
+ fhangup = TRUE;
+ }
+ else if (qTremote == NULL
+ && qTlocal == NULL
+ && qTsend == NULL
+ && qTreceive == NULL)
+ {
+ /* We don't have anything to do. Try to find some new
+ jobs. If we can't, transfer control. */
+ if (! fqueue (qdaemon, (boolean *) NULL))
+ {
+ fret = FALSE;
+ break;
+ }
+ if (qTlocal == NULL)
+ {
+ DEBUG_MESSAGE0 (DEBUG_UUCP_PROTO,
+ "floop: No work for master");
+ fhangup = TRUE;
+ }
+ }
+
+ if (fhangup)
+ {
+ if (! (*qdaemon->qproto->pfsendcmd) (qdaemon, "H", 0, 0))
+ {
+ fret = FALSE;
+ break;
+ }
+ qdaemon->fmaster = FALSE;
+ }
+ }
+
+ /* If we are no long the master, clear any requested hangup. We
+ may have already hung up before checking this variable in the
+ block above. */
+ if (! qdaemon->fmaster)
+ qdaemon->fhangup_requested = FALSE;
+
+ /* Immediately queue up any remote jobs. We don't need local
+ channel numbers for them, since we can disambiguate based on
+ the remote channel number. */
+ while (qTremote != NULL)
+ {
+ q = qTremote;
+ utdequeue (q);
+ utqueue (&qTsend, q, TRUE);
+ }
+
+ /* If we are the master, or if we have multiple channels, try to
+ queue up additional local jobs. */
+ if (qdaemon->fmaster || cchans > 1)
+ {
+ while (qTlocal != NULL && cTchans < cchans)
+ {
+ /* We have room for an additional channel. */
+ q = qTlocal;
+ if (! fqueue_send (qdaemon, q))
+ {
+ fret = FALSE;
+ break;
+ }
+ utchanalc (qdaemon, q);
+ }
+ if (! fret)
+ break;
+ }
+
+ q = qTsend;
+
+ if (q == NULL)
+ {
+ ulog_user ((const char *) NULL);
+ DEBUG_MESSAGE0 (DEBUG_UUCP_PROTO, "floop: Waiting for data");
+ if (! (*qdaemon->qproto->pfwait) (qdaemon))
+ {
+ fret = FALSE;
+ break;
+ }
+ }
+ else
+ {
+ ulog_user (q->s.zuser);
+
+ if (! q->fsendfile)
+ {
+ if (! ftcharge (qdaemon, q, TRUE, TRUE))
+ {
+ fret = FALSE;
+ break;
+ }
+
+ if (! (*q->psendfn) (q, qdaemon))
+ {
+ fret = FALSE;
+ break;
+ }
+ }
+ else
+ {
+ if (! ftcharge (qdaemon, q, TRUE, FALSE))
+ {
+ fret = FALSE;
+ break;
+ }
+
+ if (q->zlog != NULL)
+ {
+ ulog (LOG_NORMAL, "%s", q->zlog);
+ ubuffree (q->zlog);
+ q->zlog = NULL;
+ }
+
+ /* We can read the file in a tight loop until qTremote
+ changes or until we have transferred the entire file.
+ We can disregard any changes to qTlocal since we
+ already have something to send anyhow. */
+ while (qTremote == NULL)
+ {
+ char *zdata;
+ size_t cdata;
+ long ipos;
+
+ zdata = (*qdaemon->qproto->pzgetspace) (qdaemon, &cdata);
+ if (zdata == NULL)
+ {
+ fret = FALSE;
+ break;
+ }
+
+ if (ffileeof (q->e))
+ cdata = 0;
+ else
+ {
+ cdata = cfileread (q->e, zdata, cdata);
+ if (ffilereaderror (q->e, cdata))
+ {
+ /* There is no way to report a file reading
+ error, so we just drop the connection. */
+ ulog (LOG_ERROR, "read: %s", strerror (errno));
+ fret = FALSE;
+ break;
+ }
+ }
+
+ ipos = q->ipos;
+ q->ipos += cdata;
+ q->cbytes += cdata;
+
+ if (! (*qdaemon->qproto->pfsenddata) (qdaemon, zdata,
+ cdata, q->ilocal,
+ q->iremote, ipos))
+ {
+ fret = FALSE;
+ break;
+ }
+
+ /* It is possible that this transfer has just been
+ cancelled. */
+ if (q != qTsend || ! q->fsendfile)
+ break;
+
+ if (cdata == 0)
+ {
+ /* We must update the time now, because this
+ call may make an entry in the statistics
+ file. */
+ if (! ftcharge (qdaemon, q, TRUE, TRUE))
+ fret = FALSE;
+ q->fsendfile = FALSE;
+ if (! (*q->psendfn) (q, qdaemon))
+ fret = FALSE;
+ break;
+ }
+ }
+
+ if (! fret)
+ break;
+ }
+ }
+ }
+
+ ulog_user ((const char *) NULL);
+
+ (void) (*qdaemon->qproto->pfshutdown) (qdaemon);
+
+ if (fret)
+ uwindow_acked (qdaemon, TRUE);
+ else
+ ufailed (qdaemon);
+
+ return fret;
+}
+
+/* This is called by the protocol routines when they have received
+ some data. If pfexit is not NULL, *pfexit should be set to TRUE if
+ the protocol receive loop should exit back to the main floop
+ routine, above. It is only important to set *pfexit to TRUE if the
+ main loop called the pfwait entry point, so we need never set it to
+ TRUE if we just receive data for a file. This routine never sets
+ *pfexit to FALSE. */
+
+boolean
+fgot_data (qdaemon, zfirst, cfirst, zsecond, csecond, ilocal, iremote, ipos,
+ fallacked, pfexit)
+ struct sdaemon *qdaemon;
+ const char *zfirst;
+ size_t cfirst;
+ const char *zsecond;
+ size_t csecond;
+ int ilocal;
+ int iremote;
+ long ipos;
+ boolean fallacked;
+ boolean *pfexit;
+{
+ struct stransfer *q;
+ int cwrote;
+ boolean fret;
+
+ if (fallacked && qTreceive_ack != NULL)
+ uwindow_acked (qdaemon, TRUE);
+
+ /* Now we have to decide which transfer structure gets the data. If
+ ilocal is -1, it means that the protocol does not know where to
+ route the data. In that case we route it to the first transfer
+ that is waiting for data, or, if none, as a new command. If
+ ilocal is 0, we either select based on the remote channel number
+ or we have a new command. */
+ if (ilocal == -1 && qTreceive != NULL)
+ q = qTreceive;
+ else if (ilocal == 0 && iremote > 0 && aqTremote[iremote] != NULL)
+ q = aqTremote[iremote];
+ else if (ilocal <= 0)
+ {
+ const char *znull;
+
+ ulog_user ((const char *) NULL);
+
+ /* This data is part of a command. If there is no null
+ character in the data, this string will be continued by the
+ next packet. Otherwise this must be the last string in the
+ command, and we don't care about what comes after the null
+ byte. */
+ znull = (const char *) memchr (zfirst, '\0', cfirst);
+ if (znull != NULL)
+ fret = ftadd_cmd (qdaemon, zfirst, (size_t) (znull - zfirst),
+ iremote, TRUE);
+ else
+ {
+ fret = ftadd_cmd (qdaemon, zfirst, cfirst, iremote, FALSE);
+ if (fret && csecond > 0)
+ {
+ znull = (const char *) memchr (zsecond, '\0', csecond);
+ if (znull != NULL)
+ fret = ftadd_cmd (qdaemon, zsecond,
+ (size_t) (znull - zsecond), iremote, TRUE);
+ else
+ fret = ftadd_cmd (qdaemon, zsecond, csecond, iremote, FALSE);
+ }
+ }
+
+ if (pfexit != NULL && (qdaemon->fhangup || qTremote != NULL))
+ *pfexit = TRUE;
+
+ return fret;
+ }
+ else
+ {
+ /* Get the transfer structure this data is intended for. */
+
+ q = qtchan (ilocal);
+ }
+
+#if DEBUG > 0
+ if (q == NULL || q->precfn == NULL)
+ {
+ ulog (LOG_ERROR, "Protocol error: %lu bytes remote %d local %d",
+ (unsigned long) (cfirst + csecond),
+ iremote, ilocal);
+ return FALSE;
+ }
+#endif
+
+ ulog_user (q->s.zuser);
+
+ fret = TRUE;
+
+ /* If we're receiving a command, then accumulate it up to the null
+ byte. */
+ if (q->fcmd)
+ {
+ const char *znull;
+
+ znull = NULL;
+ while (cfirst > 0)
+ {
+ size_t cnew;
+ char *znew;
+
+ znull = (const char *) memchr (zfirst, '\0', cfirst);
+ if (znull != NULL)
+ cnew = znull - zfirst;
+ else
+ cnew = cfirst;
+ znew = zbufalc (q->ccmd + cnew + 1);
+ memcpy (znew, q->zcmd, q->ccmd);
+ memcpy (znew + q->ccmd, zfirst, cnew);
+ znew[q->ccmd + cnew] = '\0';
+ ubuffree (q->zcmd);
+ q->zcmd = znew;
+ q->ccmd += cnew;
+
+ if (znull != NULL)
+ break;
+
+ zfirst = zsecond;
+ cfirst = csecond;
+ csecond = 0;
+ }
+
+ if (znull != NULL)
+ {
+ char *zcmd;
+ size_t ccmd;
+
+ if (! ftcharge (qdaemon, q, FALSE, TRUE))
+ fret = FALSE;
+ zcmd = q->zcmd;
+ ccmd = q->ccmd;
+ q->fcmd = FALSE;
+ q->zcmd = NULL;
+ q->ccmd = 0;
+ if (! (*q->precfn) (q, qdaemon, zcmd, ccmd + 1))
+ fret = FALSE;
+ ubuffree (zcmd);
+ }
+ else
+ {
+ if (! ftcharge (qdaemon, q, FALSE, FALSE))
+ fret = FALSE;
+ }
+
+ if (pfexit != NULL
+ && (qdaemon->fhangup
+ || qdaemon->fmaster
+ || qTsend != NULL))
+ *pfexit = TRUE;
+ }
+ else if (! q->frecfile || cfirst == 0)
+ {
+ /* We're either not receiving a file or the file transfer is
+ complete. */
+ if (! ftcharge (qdaemon, q, FALSE, TRUE))
+ fret = FALSE;
+ q->frecfile = FALSE;
+ if (! (*q->precfn) (q, qdaemon, zfirst, cfirst))
+ fret = FALSE;
+ if (fret && csecond > 0)
+ return fgot_data (qdaemon, zsecond, csecond,
+ (const char *) NULL, (size_t) 0,
+ ilocal, iremote, ipos + (long) cfirst,
+ FALSE, pfexit);
+ if (pfexit != NULL
+ && (qdaemon->fhangup
+ || qdaemon->fmaster
+ || qTsend != NULL))
+ *pfexit = TRUE;
+ }
+ else
+ {
+ if (! ftcharge (qdaemon, q, FALSE, FALSE))
+ fret = FALSE;
+
+ if (q->zlog != NULL)
+ {
+ ulog (LOG_NORMAL, "%s", q->zlog);
+ ubuffree (q->zlog);
+ q->zlog = NULL;
+ }
+
+ if (ipos != -1 && ipos != q->ipos)
+ {
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO,
+ "fgot_data: Seeking to %ld", ipos);
+ if (! ffileseek (q->e, ipos))
+ {
+ ulog (LOG_ERROR, "seek: %s", strerror (errno));
+ fret = FALSE;
+ }
+ q->ipos = ipos;
+ }
+
+ if (fret)
+ {
+ while (cfirst > 0)
+ {
+ cwrote = cfilewrite (q->e, (char *) zfirst, cfirst);
+ if (cwrote == cfirst)
+ {
+#if FREE_SPACE_DELTA > 0
+ long cfree_space;
+
+ /* Check that there is still enough space on the
+ disk. If there isn't, we drop the connection,
+ because we have no way to abort a file transfer
+ in progress. */
+ cfree_space = qdaemon->qsys->uuconf_cfree_space;
+ if (cfree_space > 0
+ && ((q->cbytes / FREE_SPACE_DELTA)
+ != (q->cbytes + cfirst) / FREE_SPACE_DELTA)
+ && ! frec_check_free (q, cfree_space))
+ {
+ fret = FALSE;
+ break;
+ }
+#endif
+ q->cbytes += cfirst;
+ q->ipos += cfirst;
+ }
+ else
+ {
+ if (cwrote < 0)
+ ulog (LOG_ERROR, "write: %s", strerror (errno));
+ else
+ ulog (LOG_ERROR,
+ "Wrote %d to file when trying to write %lu",
+ cwrote, (unsigned long) cfirst);
+
+ /* Any write error is almost certainly a temporary
+ condition, or else UUCP would not be functioning
+ at all. If we continue to accept the file, we
+ will wind up rejecting it at the end (what else
+ could we do?) and the remote system will throw
+ away the request. We're better off just dropping
+ the connection, which is what happens when we
+ return FALSE, and trying again later. */
+ fret = FALSE;
+ break;
+ }
+
+ zfirst = zsecond;
+ cfirst = csecond;
+ csecond = 0;
+ }
+ }
+
+ if (pfexit != NULL && qdaemon->fhangup)
+ *pfexit = TRUE;
+ }
+
+ return fret;
+}
+
+/* Accumulate a string into a command. If the command is complete,
+ start up a new transfer. */
+
+static boolean
+ftadd_cmd (qdaemon, z, clen, iremote, flast)
+ struct sdaemon *qdaemon;
+ const char *z;
+ size_t clen;
+ int iremote;
+ boolean flast;
+{
+ static char *zbuf;
+ static size_t cbuf;
+ size_t cneed;
+ struct scmd s;
+
+ cneed = cTcmdlen + clen + 1;
+ if (cneed > cbuf)
+ {
+ zbuf = (char *) xrealloc ((pointer) zbuf, cneed);
+ cbuf = cneed;
+ }
+
+ memcpy (zbuf + cTcmdlen, z, clen);
+ zbuf[cTcmdlen + clen] = '\0';
+
+ if (! flast)
+ {
+ cTcmdlen += clen;
+ return TRUE;
+ }
+
+ /* Don't save this string for next time. */
+ cTcmdlen = 0;
+
+ DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO,
+ "ftadd_cmd: Got command \"%s\"", zbuf);
+
+ if (! fparse_cmd (zbuf, &s))
+ {
+ ulog (LOG_ERROR, "Received garbled command \"%s\"", zbuf);
+ return TRUE;
+ }
+
+ if (s.bcmd != 'H' && s.bcmd != 'Y' && s.bcmd != 'N')
+ ulog_user (s.zuser);
+ else
+ ulog_user ((const char *) NULL);
+
+ switch (s.bcmd)
+ {
+ case 'S':
+ case 'E':
+ return fremote_send_file_init (qdaemon, &s, iremote);
+ case 'R':
+ return fremote_rec_file_init (qdaemon, &s, iremote);
+ case 'X':
+ return fremote_xcmd_init (qdaemon, &s, iremote);
+ case 'H':
+ /* This is a remote request for a hangup. We close the log
+ files so that they may be moved at this point. */
+ ulog_close ();
+ ustats_close ();
+ {
+ struct stransfer *q;
+
+ q = qtransalc ((struct scmd *) NULL);
+ q->psendfn = fremote_hangup_reply;
+ q->iremote = iremote;
+ return fqueue_remote (qdaemon, q);
+ }
+ case 'N':
+ /* This means a hangup request is being denied; we just ignore
+ this and wait for further commands. */
+ return TRUE;
+ case 'Y':
+ /* This is a remote confirmation of a hangup. We reconfirm. */
+ if (qdaemon->fhangup)
+ return TRUE;
+#if DEBUG > 0
+ if (qdaemon->fmaster)
+ ulog (LOG_ERROR, "Got hangup reply as master");
+#endif
+ /* Don't check errors rigorously here, since the other side
+ might jump the gun and hang up. The fLog_sighup variable
+ will get set TRUE again when the port is closed. */
+ fLog_sighup = FALSE;
+ (void) (*qdaemon->qproto->pfsendcmd) (qdaemon, "HY", 0, iremote);
+ qdaemon->fhangup = TRUE;
+ return TRUE;
+#if DEBUG > 0
+ default:
+ ulog (LOG_FATAL, "ftadd_cmd: Can't happen");
+ return FALSE;
+#endif
+ }
+}
+
+/* The remote system is requesting a hang up. If we have something to
+ do, send an HN. Otherwise send two HY commands (the other side is
+ presumed to send an HY command between the first and second, but we
+ don't bother to wait for it) and hang up. */
+
+static boolean
+fremote_hangup_reply (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ boolean fret;
+
+ utransfree (qtrans);
+
+ if (qTremote == NULL
+ && qTlocal == NULL
+ && qTsend == NULL
+ && qTreceive == NULL)
+ {
+ if (! fqueue (qdaemon, (boolean *) NULL))
+ return FALSE;
+
+ if (qTlocal == NULL)
+ {
+ DEBUG_MESSAGE0 (DEBUG_UUCP_PROTO, "fremote_hangup_reply: No work");
+ fret = ((*qdaemon->qproto->pfsendcmd) (qdaemon, "HY", 0, 0)
+ && (*qdaemon->qproto->pfsendcmd) (qdaemon, "HY", 0, 0));
+ qdaemon->fhangup = TRUE;
+ return fret;
+ }
+ }
+
+ DEBUG_MESSAGE0 (DEBUG_UUCP_PROTO, "fremote_hangup_reply: Found work");
+ fret = (*qdaemon->qproto->pfsendcmd) (qdaemon, "HN", 0, 0);
+ qdaemon->fmaster = TRUE;
+ return fret;
+}
+
+/* As described in system.h, we need to keep track of which files have
+ been successfully received for which we do not know that the other
+ system has received our acknowledgement. This routine is called to
+ keep a list of such files. */
+
+static struct sreceive_ack *qTfree_receive_ack;
+
+void
+usent_receive_ack (qdaemon, qtrans)
+ struct sdaemon *qdaemon;
+ struct stransfer *qtrans;
+{
+ struct sreceive_ack *q;
+
+ if (qTfree_receive_ack == NULL)
+ q = (struct sreceive_ack *) xmalloc (sizeof (struct sreceive_ack));
+ else
+ {
+ q = qTfree_receive_ack;
+ qTfree_receive_ack = q->qnext;
+ }
+
+ q->qnext = qTreceive_ack;
+ q->zto = zbufcpy (qtrans->s.zto);
+ q->ztemp = zbufcpy (qtrans->s.ztemp);
+ q->fmarked = FALSE;
+
+ qTreceive_ack = q;
+}
+
+/* This routine is called by the protocol code when either all
+ outstanding data has been acknowledged or one complete window has
+ passed. It may be called directly by the protocol, or it may be
+ called via fgot_data. If one complete window has passed, then all
+ unmarked receives are marked, and we know that all marked ones have
+ been acked. */
+
+void
+uwindow_acked (qdaemon, fallacked)
+ struct sdaemon *qdaemon;
+ boolean fallacked;
+{
+ register struct sreceive_ack **pq;
+
+ pq = &qTreceive_ack;
+ while (*pq != NULL)
+ {
+ if (fallacked || (*pq)->fmarked)
+ {
+ struct sreceive_ack *q;
+
+ q = *pq;
+ (void) fsysdep_forget_reception (qdaemon->qsys, q->zto,
+ q->ztemp);
+ ubuffree (q->zto);
+ ubuffree (q->ztemp);
+ *pq = q->qnext;
+ q->qnext = qTfree_receive_ack;
+ qTfree_receive_ack = q;
+ }
+ else
+ {
+ (*pq)->fmarked = TRUE;
+ pq = &(*pq)->qnext;
+ }
+ }
+}
+
+/* This routine is called when an error occurred and we are crashing
+ out of the connection. It is used to report statistics on failed
+ transfers to the statistics file, and it also discards useless
+ temporary files for file receptions. Note that the number of bytes
+ we report as having been sent has little or nothing to do with the
+ number of bytes the remote site actually received. */
+
+void
+ufailed (qdaemon)
+ struct sdaemon *qdaemon;
+{
+ register struct stransfer *q;
+
+ /* Update the transfer times, but avoid looking in the queue. */
+ iTchecktime = ixsysdep_process_time ((long *) NULL);
+ (void) ftcharge (qdaemon, (struct stransfer *) NULL, TRUE, TRUE);
+ (void) ftcharge (qdaemon, (struct stransfer *) NULL, FALSE, TRUE);
+
+ if (qTsend != NULL)
+ {
+ q = qTsend;
+ do
+ {
+ if ((q->fsendfile || q->frecfile)
+ && q->cbytes > 0)
+ ustats (FALSE, q->s.zuser, qdaemon->qsys->uuconf_zname,
+ q->fsendfile, q->cbytes, q->isecs, q->imicros,
+ FALSE);
+ if (q->frecfile)
+ (void) frec_discard_temp (qdaemon, q);
+ q = q->qnext;
+ }
+ while (q != qTsend);
+ }
+
+ if (qTreceive != NULL)
+ {
+ q = qTreceive;
+ do
+ {
+ if ((q->fsendfile || q->frecfile)
+ && q->cbytes > 0)
+ ustats (FALSE, q->s.zuser, qdaemon->qsys->uuconf_zname,
+ q->fsendfile, q->cbytes, q->isecs, q->imicros,
+ FALSE);
+ if (q->frecfile)
+ (void) frec_discard_temp (qdaemon, q);
+ q = q->qnext;
+ }
+ while (q != qTreceive);
+ }
+}
+
+/* When a local poll file is found, it is entered on the queue like
+ any other job. When it is pulled off the queue, this function is
+ called. It just calls fsysdep_did_work, which will remove the poll
+ file. This ensures that poll files are only removed if the system
+ is actually called. */
+
+/*ARGSUSED*/
+static boolean
+flocal_poll_file (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ boolean fret;
+
+ fret = fsysdep_did_work (qtrans->s.pseq);
+ utransfree (qtrans);
+ return fret;
+}
diff --git a/gnu/libexec/uucp/uucico/uucico.8 b/gnu/libexec/uucp/uucico/uucico.8
new file mode 100644
index 00000000000..fba8bb588fc
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/uucico.8
@@ -0,0 +1,225 @@
+''' $Id: uucico.8,v 1.1 1993/08/04 19:36:33 jtc Exp $
+.TH uucico 8 "Taylor UUCP 1.04"
+.SH NAME
+uucico \- UUCP file transfer daemon
+.SH SYNOPSIS
+.B uucico
+[ options ]
+.SH DESCRIPTION
+The
+.I uucico
+daemon processes file transfer requests queued by
+.I uucp
+(1) and
+.I uux
+(1). It is started when
+.I uucp
+or
+.I uux
+is run (unless they are given the
+.B \-r
+option). It is also typically started periodically using
+entries in the
+.I crontab
+table(s).
+
+When invoked with the
+.B \-r1
+option or the
+.B \-s
+or
+.B \-S
+option, the daemon will place a call to a remote system, running in
+master mode.
+Otherwise the daemon will start in slave mode, accepting a
+call from a remote system. Typically a special login name will be set
+up for UUCP which automatically invokes
+.I uucico
+when a call is made.
+
+When
+.I uucico
+terminates, it invokes the
+.I uuxqt
+(8) daemon, unless the
+.B \-q
+option is given;
+.I uuxqt
+(8) executes any work orders created by
+.I uux
+(1) on a remote system, and any work orders created locally which have
+received remote files for which they were waiting.
+
+If a call fails,
+.I uucico
+will normally refuse to retry the
+call until a certain (configurable) amount of time
+has passed. This may be overriden by the
+.B -f
+or the
+.B -S
+option.
+
+The
+.B \-l
+or
+.B \-e
+option may be used to force
+.I uucico
+to produce its own prompts of "login: " and "Password:". When another
+daemon calls in, it will see these prompts and log in as usual; the
+login name and password will be checked against a separate list kept
+specially for
+.I uucico
+rather than the
+.I /etc/passwd
+file. The
+.B \-l
+option will prompt once and then exit. The
+.B \-e
+option will prompt again after the first session is over; in this mode
+.I uucico
+will permanently control a port.
+
+If
+.I uucico
+receives a SIGQUIT, SIGTERM or SIGPIPE signal, it will cleanly abort
+any current conversation with a remote system and exit. If it
+receives a SIGHUP signal it will abort any current conversation, but
+will continue to place calls to (if invoked with
+.B \-r1)
+and accept calls from (if invoked with
+.B \-e)
+other systems. If it receives a
+SIGINT signal it will finish the current conversation, but will not
+place or accept any more calls.
+.SH OPTIONS
+The following options may be given to
+.I uucico.
+.TP 5
+.B \-r1
+Start in master mode (call out to a system); implied by
+.B \-s
+or
+.B \-S.
+If no system is specified, call any system for which work is waiting
+to be done.
+.TP 5
+.B \-r0
+Start in slave mode. This is the default.
+.TP 5
+.B \-s system
+Call the named system.
+.TP 5
+.B \-S system
+Call the named system, ignoring any required wait.
+.TP 5
+.B \-f
+Ignore any required wait for any systems to be called.
+.TP 5
+.B \-l
+Prompt for login name and password using "login: " and "Password:".
+This allows
+.I uucico
+to be easily run from
+.I inetd
+(8). The login name and password are checked against the UUCP
+password file, which has no connection to the file
+.I /etc/passwd.
+.TP 5
+.B \-p port
+Specify a port to call out on or to listen to. In slave mode, this
+implies
+.B \-e.
+.TP 5
+.B \-e
+Enter endless loop of login/password prompts and slave mode daemon
+execution. The program will not stop by itself; you must use
+.I kill
+(1) to shut it down.
+.TP 5
+.B \-w
+After calling out (to a particular system when
+.B \-s
+or
+.B \-S
+is specifed, or to all systems which have work when
+.B \-r1
+is specifed), begin an endless loop as with
+.B \-e.
+.TP 5
+.B \-q
+Do not start the
+.I uuxqt
+(8) daemon when finished.
+.TP 5
+.B \-c
+If no calls are permitted at this time, then don't make the call, but
+also do not put an error message in the log file and do not update the
+system status (as reported by
+.I uustat
+(1)). This can be convenient for automated polling scripts, which may
+want to simply attempt to call every system rather than worry about
+which particular systems may be called at the moment.
+.TP 5
+.B \-D
+Do not detach from the controlling terminal. Normally
+.I uucico
+detaches from the terminal before each call out to another system and
+before invoking
+.I uuxqt.
+This option prevents this.
+.TP 5
+.B \-x type, \-X type
+Turn on particular debugging types. The following types are
+recognized: abnormal, chat, handshake, uucp-proto, proto, port,
+config, spooldir, execute, incoming, outgoing.
+
+Multiple types may be given, separated by commas, and the
+.B \-x
+option may appear multiple times. A number may also be given, which
+will turn on that many types from the foregoing list; for example,
+.B \-x 2
+is equivalent to
+.B \-x abnormal,chat.
+
+The debugging output is sent to the debugging file, usually one of
+/usr/spool/uucp/Debug, /usr/spool/uucp/DEBUG, or
+/usr/spool/uucp/.Admin/audit.local.
+.TP 5
+.B \-I file
+Set configuration file to use. This option may not be available,
+depending upon how
+.I uucico
+was compiled.
+.TP 5
+.B \-u login
+This option is ignored. It is only included because some versions of
+uucpd invoke
+.I uucico
+with it.
+.SH FILES
+The file names may be changed at compilation time or by the
+configuration file, so these are only approximations.
+
+.br
+/usr/lib/uucp/config - Configuration file.
+.br
+/usr/lib/uucp/passwd - Default UUCP password file.
+.br
+/usr/spool/uucp -
+UUCP spool directory.
+.br
+/usr/spool/uucp/Log -
+UUCP log file.
+.br
+/usr/spool/uucppublic -
+Default UUCP public directory.
+.br
+/usr/spool/uucp/Debug -
+Debugging file.
+.SH SEE ALSO
+kill(1), uucp(1), uux(1), uustat(1), uuxqt(8)
+.SH AUTHOR
+Ian Lance Taylor
+(ian@airs.com or uunet!airs!ian)
diff --git a/gnu/libexec/uucp/uucico/uucico.c b/gnu/libexec/uucp/uucico/uucico.c
new file mode 100644
index 00000000000..ecd6c235c80
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/uucico.c
@@ -0,0 +1,2618 @@
+/* uucico.c
+ This is the main UUCP communication program.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char uucico_rcsid[] = "$Id: uucico.c,v 1.1 1993/08/04 19:36:34 jtc Exp $";
+#endif
+
+#include <ctype.h>
+
+#if HAVE_LIMITS_H
+#include <limits.h>
+#else
+#define LONG_MAX 2147483647L
+#endif
+
+#include "getopt.h"
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "conn.h"
+#include "prot.h"
+#include "trans.h"
+#include "system.h"
+
+/* The program name. */
+char abProgram[] = "uucico";
+
+/* Define the known protocols. */
+
+#define TCP_PROTO \
+ (UUCONF_RELIABLE_ENDTOEND \
+ | UUCONF_RELIABLE_RELIABLE \
+ | UUCONF_RELIABLE_EIGHT)
+
+static const struct sprotocol asProtocols[] =
+{
+ { 't', TCP_PROTO, 1,
+ asTproto_params, ftstart, ftshutdown, ftsendcmd, ztgetspace,
+ ftsenddata, ftwait, ftfile },
+ { 'e', TCP_PROTO, 1,
+ asEproto_params, festart, feshutdown, fesendcmd, zegetspace,
+ fesenddata, fewait, fefile },
+ { 'i', UUCONF_RELIABLE_EIGHT, 7,
+ asIproto_params, fistart, fishutdown, fisendcmd, zigetspace,
+ fisenddata, fiwait, NULL },
+ { 'a', UUCONF_RELIABLE_EIGHT, 1,
+ asZproto_params, fzstart, fzshutdown, fzsendcmd, zzgetspace,
+ fzsenddata, fzwait, fzfile },
+ { 'g', UUCONF_RELIABLE_EIGHT, 1,
+ asGproto_params, fgstart, fgshutdown, fgsendcmd, zggetspace,
+ fgsenddata, fgwait, NULL },
+ { 'G', UUCONF_RELIABLE_EIGHT, 1,
+ asGproto_params, fbiggstart, fgshutdown, fgsendcmd, zggetspace,
+ fgsenddata, fgwait, NULL },
+ { 'j', UUCONF_RELIABLE_EIGHT, 7,
+ asIproto_params, fjstart, fjshutdown, fisendcmd, zigetspace,
+ fisenddata, fiwait, NULL },
+ { 'f', UUCONF_RELIABLE_RELIABLE, 1,
+ asFproto_params, ffstart, ffshutdown, ffsendcmd, zfgetspace,
+ ffsenddata, ffwait, fffile },
+};
+
+#define CPROTOCOLS (sizeof asProtocols / sizeof asProtocols[0])
+
+/* Locked system. */
+static boolean fLocked_system;
+static struct uuconf_system sLocked_system;
+
+/* Daemon structure holding information about the remote system (must
+ be global so the error handler can see it. */
+static struct sdaemon sDaemon;
+
+/* Open connection. */
+static struct sconnection *qConn;
+
+/* uuconf global pointer; need to close the connection after a fatal
+ error. */
+static pointer pUuconf;
+
+/* This structure is passed to iuport_lock via uuconf_find_port. */
+struct spass
+{
+ boolean fmatched;
+ boolean flocked;
+ struct sconnection *qconn;
+};
+
+/* Local functions. */
+
+static void uusage P((void));
+static void uabort P((void));
+static boolean fcall P((pointer puuconf,
+ const struct uuconf_system *qsys,
+ struct uuconf_port *qport, boolean fifwork,
+ boolean fforce, boolean fdetach,
+ boolean ftimewarn));
+static boolean fconn_call P((struct sdaemon *qdaemon,
+ struct uuconf_port *qport,
+ struct sstatus *qstat, int cretry,
+ boolean *pfcalled));
+static boolean fdo_call P((struct sdaemon *qdaemon,
+ struct sstatus *qstat,
+ const struct uuconf_dialer *qdialer,
+ boolean *pfcalled, enum tstatus_type *pterr));
+static int iuport_lock P((struct uuconf_port *qport, pointer pinfo));
+static boolean flogin_prompt P((pointer puuconf,
+ struct sconnection *qconn));
+static boolean faccept_call P((pointer puuconf, const char *zlogin,
+ struct sconnection *qconn,
+ const char **pzsystem));
+static void uapply_proto_params P((pointer puuconf, int bproto,
+ struct uuconf_cmdtab *qcmds,
+ struct uuconf_proto_param *pas));
+static boolean fsend_uucp_cmd P((struct sconnection *qconn,
+ const char *z));
+static char *zget_uucp_cmd P((struct sconnection *qconn,
+ boolean frequired));
+static char *zget_typed_line P((struct sconnection *qconn));
+
+/* Long getopt options. */
+static const struct option asLongopts[] = { { NULL, 0, NULL, 0 } };
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ /* -c: Whether to warn if a call is attempted at a bad time. */
+ boolean ftimewarn = TRUE;
+ /* -D: don't detach from controlling terminal. */
+ boolean fdetach = TRUE;
+ /* -e: Whether to do an endless loop of accepting calls. */
+ boolean fendless = FALSE;
+ /* -f: Whether to force a call despite status of previous call. */
+ boolean fforce = FALSE;
+ /* -I file: configuration file name. */
+ const char *zconfig = NULL;
+ /* -l: Whether to give a single login prompt. */
+ boolean flogin = FALSE;
+ /* -P port: port to use; in master mode, call out on this port. In
+ slave mode, accept logins on this port. If port not specified,
+ then in master mode figure it out for each system, and in slave
+ mode use stdin and stdout. */
+ const char *zport = NULL;
+ /* -q: Whether to start uuxqt when done. */
+ boolean fuuxqt = TRUE;
+ /* -r1: Whether we are the master. */
+ boolean fmaster = FALSE;
+ /* -s,-S system: system to call. */
+ const char *zsystem = NULL;
+ /* -w: Whether to wait for a call after doing one. */
+ boolean fwait = FALSE;
+ int iopt;
+ struct uuconf_port *qport;
+ struct uuconf_port sport;
+ boolean fret = TRUE;
+ pointer puuconf;
+ int iuuconf;
+#if DEBUG > 1
+ int iholddebug;
+#endif
+
+ while ((iopt = getopt_long (argc, argv,
+ "cDefI:lp:qr:s:S:u:x:X:w",
+ asLongopts, (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 'c':
+ /* Don't warn if a call is attempted at a bad time. */
+ ftimewarn = FALSE;
+ break;
+
+ case 'D':
+ /* Don't detach from controlling terminal. */
+ fdetach = FALSE;
+ break;
+
+ case 'e':
+ /* Do an endless loop of accepting calls. */
+ fendless = TRUE;
+ break;
+
+ case 'f':
+ /* Force a call even if it hasn't been long enough since the last
+ failed call. */
+ fforce = TRUE;
+ break;
+
+ case 'I':
+ /* Set configuration file name (default is in sysdep.h). */
+ if (fsysdep_other_config (optarg))
+ zconfig = optarg;
+ break;
+
+ case 'l':
+ /* Prompt for login name and password. */
+ flogin = TRUE;
+ break;
+
+ case 'p':
+ /* Port to use */
+ zport = optarg;
+ break;
+
+ case 'q':
+ /* Don't start uuxqt. */
+ fuuxqt = FALSE;
+ break;
+
+ case 'r':
+ /* Set mode: -r1 for master, -r0 for slave (default) */
+ if (strcmp (optarg, "1") == 0)
+ fmaster = TRUE;
+ else if (strcmp (optarg, "0") == 0)
+ fmaster = FALSE;
+ else
+ uusage ();
+ break;
+
+ case 's':
+ /* Set system name */
+ zsystem = optarg;
+ fmaster = TRUE;
+ break;
+
+ case 'S':
+ /* Set system name and force call like -f */
+ zsystem = optarg;
+ fforce = TRUE;
+ fmaster = TRUE;
+ break;
+
+ case 'u':
+ /* Some versions of uucpd invoke uucico with a -u argument
+ specifying the login name. I'm told it is safe to ignore
+ this value, although perhaps we should use it rather than
+ zsysdep_login_name (). */
+ break;
+
+ case 'x':
+ case 'X':
+#if DEBUG > 1
+ /* Set debugging level */
+ iDebug |= idebug_parse (optarg);
+#endif
+ break;
+
+ case 'w':
+ /* Call out and then wait for a call in */
+ fwait = TRUE;
+ break;
+
+ case 0:
+ /* Long option found, and flag value set. */
+ break;
+
+ default:
+ uusage ();
+ break;
+ }
+ }
+
+ if (optind != argc)
+ uusage ();
+
+ if (fwait && zport == NULL)
+ {
+ ulog (LOG_ERROR, "-w requires -e");
+ uusage ();
+ }
+
+ iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ pUuconf = puuconf;
+
+#if DEBUG > 1
+ {
+ const char *zdebug;
+
+ iuuconf = uuconf_debuglevel (puuconf, &zdebug);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (zdebug != NULL)
+ iDebug |= idebug_parse (zdebug);
+ }
+#endif
+
+ /* If a port was named, get its information. */
+ if (zport == NULL)
+ qport = NULL;
+ else
+ {
+ iuuconf = uuconf_find_port (puuconf, zport, (long) 0, (long) 0,
+ (int (*) P((struct uuconf_port *,
+ pointer))) NULL,
+ (pointer) NULL, &sport);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ ulog (LOG_FATAL, "%s: Port not found", zport);
+ else if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ qport = &sport;
+ }
+
+#ifdef SIGINT
+ usysdep_signal (SIGINT);
+#endif
+#ifdef SIGHUP
+ usysdep_signal (SIGHUP);
+#endif
+#ifdef SIGQUIT
+ usysdep_signal (SIGQUIT);
+#endif
+#ifdef SIGTERM
+ usysdep_signal (SIGTERM);
+#endif
+#ifdef SIGPIPE
+ usysdep_signal (SIGPIPE);
+#endif
+
+ usysdep_initialize (puuconf, INIT_SUID);
+
+ ulog_to_file (puuconf, TRUE);
+ ulog_fatal_fn (uabort);
+
+ if (fmaster)
+ {
+ if (zsystem != NULL)
+ {
+ /* A system was named. Call it. */
+ iuuconf = uuconf_system_info (puuconf, zsystem,
+ &sLocked_system);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ ulog (LOG_FATAL, "%s: System not found", zsystem);
+ else if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ /* Detach from the controlling terminal for the call. This
+ probably makes sense only on Unix. We want the modem
+ line to become the controlling terminal. */
+ if (fdetach &&
+ (qport == NULL
+ || qport->uuconf_ttype != UUCONF_PORTTYPE_STDIN))
+ usysdep_detach ();
+
+ ulog_system (sLocked_system.uuconf_zname);
+
+#if DEBUG > 1
+ iholddebug = iDebug;
+ if (sLocked_system.uuconf_zdebug != NULL)
+ iDebug |= idebug_parse (sLocked_system.uuconf_zdebug);
+#endif
+
+ if (! fsysdep_lock_system (&sLocked_system))
+ {
+ ulog (LOG_ERROR, "System already locked");
+ fret = FALSE;
+ }
+ else
+ {
+ fLocked_system = TRUE;
+ fret = fcall (puuconf, &sLocked_system, qport, FALSE,
+ fforce, fdetach, ftimewarn);
+ if (fLocked_system)
+ {
+ (void) fsysdep_unlock_system (&sLocked_system);
+ fLocked_system = FALSE;
+ }
+ }
+#if DEBUG > 1
+ iDebug = iholddebug;
+#endif
+ ulog_system ((const char *) NULL);
+ (void) uuconf_system_free (puuconf, &sLocked_system);
+ }
+ else
+ {
+ char **pznames, **pz;
+ int c, i;
+ boolean fdidone;
+
+ /* Call all systems which have work to do. */
+ fret = TRUE;
+ fdidone = FALSE;
+
+ iuuconf = uuconf_system_names (puuconf, &pznames, 0);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ /* Randomize the order in which we call the systems. */
+ c = 0;
+ for (pz = pznames; *pz != NULL; pz++)
+ c++;
+
+ srand ((unsigned int) ixsysdep_time ((long *) NULL));
+ for (i = c - 1; i > 0; i--)
+ {
+ int iuse;
+ char *zhold;
+
+ iuse = rand () % (i + 1);
+ zhold = pznames[i];
+ pznames[i] = pznames[iuse];
+ pznames[iuse] = zhold;
+ }
+
+ for (pz = pznames; *pz != NULL && ! FGOT_SIGNAL (); pz++)
+ {
+ iuuconf = uuconf_system_info (puuconf, *pz,
+ &sLocked_system);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ xfree ((pointer) *pz);
+ continue;
+ }
+
+ if (fsysdep_has_work (&sLocked_system))
+ {
+ fdidone = TRUE;
+
+ /* Detach from the controlling terminal. On Unix
+ this means that we will wind up forking a new
+ process for each system we call. */
+ if (fdetach
+ && (qport == NULL
+ || qport->uuconf_ttype != UUCONF_PORTTYPE_STDIN))
+ usysdep_detach ();
+
+ ulog_system (sLocked_system.uuconf_zname);
+
+#if DEBUG > 1
+ iholddebug = iDebug;
+ if (sLocked_system.uuconf_zdebug != NULL)
+ iDebug |= idebug_parse (sLocked_system.uuconf_zdebug);
+#endif
+
+ if (! fsysdep_lock_system (&sLocked_system))
+ {
+ ulog (LOG_ERROR, "System already locked");
+ fret = FALSE;
+ }
+ else
+ {
+ fLocked_system = TRUE;
+ if (! fcall (puuconf, &sLocked_system, qport, TRUE,
+ fforce, fdetach, ftimewarn))
+ fret = FALSE;
+
+ /* Now ignore any SIGHUP that we got. */
+ afSignal[INDEXSIG_SIGHUP] = FALSE;
+
+ if (fLocked_system)
+ {
+ (void) fsysdep_unlock_system (&sLocked_system);
+ fLocked_system = FALSE;
+ }
+ }
+#if DEBUG > 1
+ iDebug = iholddebug;
+#endif
+ ulog_system ((const char *) NULL);
+ }
+
+ (void) uuconf_system_free (puuconf, &sLocked_system);
+ xfree ((pointer) *pz);
+ }
+
+ xfree ((pointer) pznames);
+
+ if (! fdidone)
+ ulog (LOG_NORMAL, "No work");
+ }
+
+ /* If requested, wait for calls after dialing out. */
+ if (fwait)
+ {
+ fendless = TRUE;
+ fmaster = FALSE;
+ }
+ }
+
+ if (! fmaster)
+ {
+ struct sconnection sconn;
+ boolean flocked;
+
+ /* If a port was specified by name, we go into endless loop
+ mode. In this mode, we wait for calls and prompt them with
+ "login:" and "Password:", so that they think we are a regular
+ UNIX system. If we aren't in endless loop mode, we have been
+ called by some other system. If flogin is TRUE, we prompt
+ with "login:" and "Password:" a single time. */
+
+ fret = TRUE;
+ zsystem = NULL;
+
+ if (! fconn_init (qport, &sconn))
+ fret = FALSE;
+
+ if (qport != NULL)
+ {
+ /* We are not using standard input. Detach from the
+ controlling terminal, so that the port we are about to
+ use becomes our controlling terminal. */
+ if (fdetach
+ && qport->uuconf_ttype != UUCONF_PORTTYPE_STDIN)
+ usysdep_detach ();
+
+ /* If a port was given, we loop forever. */
+ fendless = TRUE;
+ }
+
+ if (fconn_lock (&sconn, TRUE))
+ flocked = TRUE;
+ else
+ {
+ flocked = FALSE;
+ ulog (LOG_ERROR, "%s: Port already locked",
+ qport->uuconf_zname);
+ fret = FALSE;
+ }
+
+ if (fret)
+ {
+ if (! fconn_open (&sconn, (long) 0, (long) 0, TRUE))
+ fret = FALSE;
+ qConn = &sconn;
+ }
+
+ if (fret)
+ {
+ if (fendless)
+ {
+ while (! FGOT_SIGNAL ()
+ && flogin_prompt (puuconf, &sconn))
+ {
+ /* Now ignore any SIGHUP that we got. */
+ afSignal[INDEXSIG_SIGHUP] = FALSE;
+
+ if (fLocked_system)
+ {
+ (void) fsysdep_unlock_system (&sLocked_system);
+ fLocked_system = FALSE;
+ }
+ if (! fconn_reset (&sconn))
+ break;
+ }
+ fret = FALSE;
+ }
+ else
+ {
+ if (flogin)
+ fret = flogin_prompt (puuconf, &sconn);
+ else
+ {
+#if DEBUG > 1
+ iholddebug = iDebug;
+#endif
+ fret = faccept_call (puuconf, zsysdep_login_name (),
+ &sconn, &zsystem);
+#if DEBUG > 1
+ iDebug = iholddebug;
+#endif
+ }
+ }
+ }
+
+ if (qConn != NULL)
+ {
+ if (! fconn_close (&sconn, puuconf, (struct uuconf_dialer *) NULL,
+ fret))
+ fret = FALSE;
+ qConn = NULL;
+ }
+
+ if (flocked)
+ (void) fconn_unlock (&sconn);
+
+ if (fLocked_system)
+ {
+ (void) fsysdep_unlock_system (&sLocked_system);
+ fLocked_system = FALSE;
+ }
+
+ uconn_free (&sconn);
+ }
+
+ ulog_close ();
+ ustats_close ();
+
+ /* If we got a SIGTERM, perhaps because the system is going down,
+ don't run uuxqt. We go ahead and run it for any other signal,
+ since I think they indicate more temporary conditions. */
+ if (afSignal[INDEXSIG_SIGTERM])
+ fuuxqt = FALSE;
+
+ if (fuuxqt)
+ {
+ /* Detach from the controlling terminal before starting up uuxqt,
+ so that it runs as a true daemon. */
+ if (fdetach)
+ usysdep_detach ();
+ if (zsystem == NULL)
+ {
+ if (! fsysdep_run ("uuxqt", (const char *) NULL,
+ (const char *) NULL))
+ fret = FALSE;
+ }
+ else
+ {
+ if (! fsysdep_run ("uuxqt", "-s", zsystem))
+ fret = FALSE;
+ }
+ }
+
+ usysdep_exit (fret);
+
+ /* Avoid complaints about not returning. */
+ return 0;
+}
+
+/* Print out a usage message. */
+
+static void
+uusage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uucico [options]\n");
+ fprintf (stderr,
+ " -s,-S system: Call system (-S implies -f)\n");
+ fprintf (stderr,
+ " -f: Force call despite system status\n");
+ fprintf (stderr,
+ " -r state: 1 for master, 0 for slave (default)\n");
+ fprintf (stderr,
+ " -p port: Specify port (implies -e)\n");
+ fprintf (stderr,
+ " -l: prompt for login name and password\n");
+ fprintf (stderr,
+ " -e: Endless loop of login prompts and daemon execution\n");
+ fprintf (stderr,
+ " -w: After calling out, wait for incoming calls\n");
+ fprintf (stderr,
+ " -q: Don't start uuxqt when done\n");
+ fprintf (stderr,
+ " -x,-X debug: Set debugging level\n");
+#if HAVE_TAYLOR_CONFIG
+ fprintf (stderr,
+ " -I file: Set configuration file to use\n");
+#endif /* HAVE_TAYLOR_CONFIG */
+
+ exit (EXIT_FAILURE);
+}
+
+/* This function is called when a LOG_FATAL error occurs. */
+
+static void
+uabort ()
+{
+ if (fLocked_system)
+ ufailed (&sDaemon);
+
+ ulog_user ((const char *) NULL);
+
+ if (qConn != NULL)
+ {
+ (void) fconn_close (qConn, pUuconf, (struct uuconf_dialer *) NULL,
+ FALSE);
+ (void) fconn_unlock (qConn);
+ uconn_free (qConn);
+ }
+
+ if (fLocked_system)
+ {
+ (void) fsysdep_unlock_system (&sLocked_system);
+ fLocked_system = FALSE;
+ }
+
+ ulog_system ((const char *) NULL);
+
+ ulog_close ();
+ ustats_close ();
+
+ usysdep_exit (FALSE);
+}
+
+/* Call another system, trying all the possible sets of calling
+ instructions. The qsys argument is the system to call. The qport
+ argument is the port to use, and may be NULL. If the fifwork
+ argument is TRUE, the call is only placed if there is work to be
+ done. If the fforce argument is TRUE, a call is forced even if not
+ enough time has passed since the last failed call. If the
+ ftimewarn argument is TRUE (the normal case), then a warning is
+ given if calls are not permitted at this time. */
+
+static boolean
+fcall (puuconf, qorigsys, qport, fifwork, fforce, fdetach, ftimewarn)
+ pointer puuconf;
+ const struct uuconf_system *qorigsys;
+ struct uuconf_port *qport;
+ boolean fifwork;
+ boolean fforce;
+ boolean fdetach;
+ boolean ftimewarn;
+{
+ struct sstatus sstat;
+ long inow;
+ boolean fbadtime, fnevertime;
+ const struct uuconf_system *qsys;
+
+ if (! fsysdep_get_status (qorigsys, &sstat, (boolean *) NULL))
+ return FALSE;
+
+ /* Make sure it's been long enough since the last failed call, and
+ that we haven't exceeded the maximum number of retries. Even if
+ we are over the limit on retries, we permit a call to be made if
+ 24 hours have passed. This 24 hour limit is still controlled by
+ the retry time. */
+ inow = ixsysdep_time ((long *) NULL);
+ if (! fforce)
+ {
+ if (qorigsys->uuconf_cmax_retries > 0
+ && sstat.cretries >= qorigsys->uuconf_cmax_retries
+ && sstat.ilast + 24 * 60 * 60 < inow)
+ {
+ ulog (LOG_ERROR, "Too many retries");
+ return FALSE;
+ }
+
+ if (sstat.ttype == STATUS_COMPLETE
+ ? sstat.ilast + qorigsys->uuconf_csuccess_wait > inow
+ : sstat.ilast + sstat.cwait > inow)
+ {
+ ulog (LOG_NORMAL, "Retry time not reached");
+ return FALSE;
+ }
+ }
+
+ sDaemon.puuconf = puuconf;
+ sDaemon.qsys = NULL;
+ sDaemon.zlocalname = NULL;
+ sDaemon.qconn = NULL;
+ sDaemon.qproto = NULL;
+ sDaemon.clocal_size = -1;
+ sDaemon.cremote_size = -1;
+ sDaemon.cmax_ever = -2;
+ sDaemon.cmax_receive = -1;
+ sDaemon.ifeatures = 0;
+ sDaemon.frequest_hangup = FALSE;
+ sDaemon.fhangup_requested = FALSE;
+ sDaemon.fhangup = FALSE;
+ sDaemon.fmaster = TRUE;
+ sDaemon.fcaller = TRUE;
+ sDaemon.ireliable = 0;
+ sDaemon.bgrade = '\0';
+
+ fbadtime = TRUE;
+ fnevertime = TRUE;
+
+ for (qsys = qorigsys; qsys != NULL; qsys = qsys->uuconf_qalternate)
+ {
+ int cretry;
+ boolean fany, fret, fcalled;
+
+ if (FGOT_SIGNAL ())
+ return FALSE;
+
+ if (! qsys->uuconf_fcall || qsys->uuconf_qtimegrade == NULL)
+ continue;
+
+ fnevertime = FALSE;
+
+ /* Make sure this is a legal time to call. */
+ if (! ftimespan_match (qsys->uuconf_qtimegrade, (long *) NULL,
+ &cretry))
+ continue;
+
+ sDaemon.qsys = qsys;
+
+ /* Queue up any work there is to do. */
+ if (! fqueue (&sDaemon, &fany))
+ return FALSE;
+
+ /* If we are only supposed to call if there is work, and there
+ isn't any work, check the next alternates. We can't give up
+ at this point because there might be some other alternates
+ with fewer restrictions on grade or file transfer size. */
+ if (fifwork && ! fany)
+ {
+ uclear_queue (&sDaemon);
+ continue;
+ }
+
+ fbadtime = FALSE;
+
+ fret = fconn_call (&sDaemon, qport, &sstat, cretry, &fcalled);
+
+ uclear_queue (&sDaemon);
+
+ if (fret)
+ return TRUE;
+ if (fcalled)
+ return FALSE;
+
+ /* Now we have to dump that port so that we can aquire a new
+ one. On Unix this means that we will fork and get a new
+ process ID, so we must unlock and relock the system. */
+ if (fdetach)
+ {
+ (void) fsysdep_unlock_system (&sLocked_system);
+ fLocked_system = FALSE;
+ usysdep_detach ();
+ if (! fsysdep_lock_system (&sLocked_system))
+ return FALSE;
+ fLocked_system = TRUE;
+ }
+ }
+
+ if (fbadtime && ftimewarn)
+ {
+ ulog (LOG_NORMAL, "Wrong time to call");
+
+ /* Update the status, unless the system can never be called. If
+ the system can never be called, there is little point to
+ putting in a ``wrong time to call'' message. We don't change
+ the number of retries, although we do set the wait until the
+ next retry to 0. */
+ if (! fnevertime)
+ {
+ sstat.ttype = STATUS_WRONG_TIME;
+ sstat.ilast = inow;
+ sstat.cwait = 0;
+ (void) fsysdep_set_status (qorigsys, &sstat);
+ }
+ }
+
+ return FALSE;
+}
+
+/* Find a port to use when calling a system, open a connection, and
+ dial the system. The actual call is done in fdo_call. This
+ routine is responsible for opening and closing the connection. */
+
+static boolean
+fconn_call (qdaemon, qport, qstat, cretry, pfcalled)
+ struct sdaemon *qdaemon;
+ struct uuconf_port *qport;
+ struct sstatus *qstat;
+ int cretry;
+ boolean *pfcalled;
+{
+ pointer puuconf;
+ const struct uuconf_system *qsys;
+ struct uuconf_port sport;
+ struct sconnection sconn;
+ enum tstatus_type terr;
+ boolean fret;
+
+ puuconf = qdaemon->puuconf;
+ qsys = qdaemon->qsys;
+
+ *pfcalled = FALSE;
+
+ /* Ignore any SIGHUP signal we may have received up to this point.
+ This is needed on Unix because we may have gotten one from the
+ shell before we detached from the controlling terminal. */
+ afSignal[INDEXSIG_SIGHUP] = FALSE;
+
+ /* If no port was specified on the command line, use any port
+ defined for the system. To select the system port: 1) see if
+ port information was specified directly; 2) see if a port was
+ named; 3) get an available port given the baud rate. We don't
+ change the system status if a port is unavailable; i.e. we don't
+ force the system to wait for the retry time. */
+ if (qport == NULL)
+ qport = qsys->uuconf_qport;
+ if (qport != NULL)
+ {
+ if (! fconn_init (qport, &sconn))
+ return FALSE;
+ if (! fconn_lock (&sconn, FALSE))
+ {
+ ulog (LOG_ERROR, "%s: Port already locked",
+ qport->uuconf_zname);
+ return FALSE;
+ }
+ }
+ else
+ {
+ struct spass s;
+ int iuuconf;
+
+ s.fmatched = FALSE;
+ s.flocked = FALSE;
+ s.qconn = &sconn;
+ iuuconf = uuconf_find_port (puuconf, qsys->uuconf_zport,
+ qsys->uuconf_ibaud,
+ qsys->uuconf_ihighbaud,
+ iuport_lock, (pointer) &s,
+ &sport);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ if (s.fmatched)
+ ulog (LOG_ERROR, "All matching ports in use");
+ else
+ ulog (LOG_ERROR, "No matching ports");
+ return FALSE;
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ if (s.flocked)
+ {
+ (void) fconn_unlock (&sconn);
+ uconn_free (&sconn);
+ }
+ return FALSE;
+ }
+ }
+
+ if (! fconn_open (&sconn, qsys->uuconf_ibaud, qsys->uuconf_ihighbaud,
+ FALSE))
+ {
+ terr = STATUS_PORT_FAILED;
+ fret = FALSE;
+ }
+ else
+ {
+ struct uuconf_dialer *qdialer;
+ struct uuconf_dialer sdialer;
+ enum tdialerfound tdialer;
+
+ if (qsys->uuconf_zalternate == NULL)
+ ulog (LOG_NORMAL, "Calling system %s (port %s)", qsys->uuconf_zname,
+ zLdevice == NULL ? (char *) "unknown" : zLdevice);
+ else
+ ulog (LOG_NORMAL, "Calling system %s (alternate %s, port %s)",
+ qsys->uuconf_zname, qsys->uuconf_zalternate,
+ zLdevice == NULL ? (char *) "unknown" : zLdevice);
+
+ qdialer = NULL;
+
+ if (! fconn_dial (&sconn, puuconf, qsys, qsys->uuconf_zphone,
+ &sdialer, &tdialer))
+ {
+ terr = STATUS_DIAL_FAILED;
+ fret = FALSE;
+ }
+ else
+ {
+ qdaemon->qconn = &sconn;
+ if (tdialer == DIALERFOUND_FALSE)
+ qdialer = NULL;
+ else
+ qdialer = &sdialer;
+ fret = fdo_call (qdaemon, qstat, qdialer, pfcalled, &terr);
+ }
+
+ (void) fconn_close (&sconn, puuconf, qdialer, fret);
+
+ if (tdialer == DIALERFOUND_FREE)
+ (void) uuconf_dialer_free (puuconf, &sdialer);
+ }
+
+ if (! fret)
+ {
+ DEBUG_MESSAGE2 (DEBUG_HANDSHAKE, "Call failed: %d (%s)",
+ (int) terr, azStatus[(int) terr]);
+ qstat->ttype = terr;
+ qstat->cretries++;
+ qstat->ilast = ixsysdep_time ((long *) NULL);
+ if (cretry == 0)
+ qstat->cwait = CRETRY_WAIT (qstat->cretries);
+ else
+ qstat->cwait = cretry * 60;
+ (void) fsysdep_set_status (qsys, qstat);
+ }
+
+ (void) fconn_unlock (&sconn);
+ uconn_free (&sconn);
+
+ if (qport == NULL)
+ (void) uuconf_port_free (puuconf, &sport);
+
+ return fret;
+}
+
+/* Do the actual work of calling another system. The qsys argument is
+ the system to call, the qconn argument is the connection to use,
+ the qstat argument holds the current status of the ssystem, and the
+ qdialer argument holds the dialer being used (it may be NULL). If
+ we log in successfully, set *pfcalled to TRUE; this is used to
+ distinguish a failed dial from a failure during the call. If an
+ error occurs *pterr is set to the status type to record. */
+
+static boolean
+fdo_call (qdaemon, qstat, qdialer, pfcalled, pterr)
+ struct sdaemon *qdaemon;
+ struct sstatus *qstat;
+ const struct uuconf_dialer *qdialer;
+ boolean *pfcalled;
+ enum tstatus_type *pterr;
+{
+ pointer puuconf;
+ const struct uuconf_system *qsys;
+ struct sconnection *qconn;
+ const char *zport;
+ int iuuconf;
+ char *zstr;
+ long istart_time;
+ char *zlog;
+
+ puuconf = qdaemon->puuconf;
+ qsys = qdaemon->qsys;
+ qconn = qdaemon->qconn;
+
+ *pterr = STATUS_LOGIN_FAILED;
+
+ if (qconn->qport == NULL)
+ zport = "unknown";
+ else
+ zport = qconn->qport->uuconf_zname;
+ if (! fchat (qconn, puuconf, &qsys->uuconf_schat, qsys,
+ (const struct uuconf_dialer *) NULL,
+ (const char *) NULL, FALSE, zport,
+ iconn_baud (qconn)))
+ return FALSE;
+
+ *pfcalled = TRUE;
+ istart_time = ixsysdep_time ((long *) NULL);
+
+ *pterr = STATUS_HANDSHAKE_FAILED;
+
+ /* We should now see "Shere" from the other system. Newer systems
+ send "Shere=foo" where foo is the remote name. */
+ zstr = zget_uucp_cmd (qconn, TRUE);
+ if (zstr == NULL)
+ return FALSE;
+
+ if (strncmp (zstr, "Shere", 5) != 0)
+ {
+ ulog (LOG_ERROR, "Bad initialization string");
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ ulog (LOG_NORMAL, "Login successful");
+
+ qstat->ttype = STATUS_TALKING;
+ qstat->ilast = ixsysdep_time ((long *) NULL);
+ qstat->cretries = 0;
+ qstat->cwait = 0;
+ if (! fsysdep_set_status (qsys, qstat))
+ return FALSE;
+
+ if (zstr[5] == '=')
+ {
+ const char *zheresys;
+ size_t clen;
+ int icmp;
+
+ /* Some UUCP packages only provide seven characters in the Shere
+ machine name. Others only provide fourteen. */
+ zheresys = zstr + 6;
+ clen = strlen (zheresys);
+ if (clen == 7 || clen == 14)
+ icmp = strncmp (zheresys, qsys->uuconf_zname, clen);
+ else
+ icmp = strcmp (zheresys, qsys->uuconf_zname);
+ if (icmp != 0)
+ {
+ if (qsys->uuconf_pzalias != NULL)
+ {
+ char **pz;
+
+ for (pz = qsys->uuconf_pzalias; *pz != NULL; pz++)
+ {
+ if (clen == 7 || clen == 14)
+ icmp = strncmp (zheresys, *pz, clen);
+ else
+ icmp = strcmp (zheresys, *pz);
+ if (icmp == 0)
+ break;
+ }
+ }
+ if (icmp != 0)
+ {
+ ulog (LOG_ERROR, "Called wrong system (%s)", zheresys);
+ ubuffree (zstr);
+ return FALSE;
+ }
+ }
+ }
+#if DEBUG > 1
+ else if (zstr[5] != '\0')
+ DEBUG_MESSAGE1 (DEBUG_HANDSHAKE,
+ "fdo_call: Strange Shere: %s", zstr);
+#endif
+
+ ubuffree (zstr);
+
+ /* We now send "S" name switches, where name is our UUCP name. If
+ we are using sequence numbers with this system, we send a -Q
+ argument with the sequence number. If the call-timegrade command
+ was used, we send a -p argument and a -vgrade= argument with the
+ grade to send us (we send both argument to make it more likely
+ that one is recognized). We always send a -N (for new) switch
+ indicating what new features we support. */
+ {
+ long ival;
+ char bgrade;
+ char *zsend;
+ boolean fret;
+
+ /* Determine the grade we should request of the other system. A
+ '\0' means that no restrictions have been made. */
+ if (! ftimespan_match (qsys->uuconf_qcalltimegrade, &ival,
+ (int *) NULL))
+ bgrade = '\0';
+ else
+ bgrade = (char) ival;
+
+ /* Determine the name we will call ourselves. */
+ if (qsys->uuconf_zlocalname != NULL)
+ qdaemon->zlocalname = qsys->uuconf_zlocalname;
+ else
+ {
+ iuuconf = uuconf_localname (puuconf, &qdaemon->zlocalname);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ qdaemon->zlocalname = zsysdep_localname ();
+ if (qdaemon->zlocalname == NULL)
+ return FALSE;
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+ }
+
+ zsend = zbufalc (strlen (qdaemon->zlocalname) + 70);
+ if (! qsys->uuconf_fsequence)
+ {
+ if (bgrade == '\0')
+ sprintf (zsend, "S%s -R -N0%o", qdaemon->zlocalname,
+ (unsigned int) (FEATURE_SIZES
+ | FEATURE_EXEC
+ | FEATURE_RESTART));
+ else
+ sprintf (zsend, "S%s -p%c -vgrade=%c -R -N0%o",
+ qdaemon->zlocalname, bgrade, bgrade,
+ (unsigned int) (FEATURE_SIZES
+ | FEATURE_EXEC
+ | FEATURE_RESTART));
+ }
+ else
+ {
+ long iseq;
+
+ iseq = ixsysdep_get_sequence (qsys);
+ if (iseq < 0)
+ return FALSE;
+ if (bgrade == '\0')
+ sprintf (zsend, "S%s -Q%ld -R -N0%o", qdaemon->zlocalname, iseq,
+ (unsigned int) (FEATURE_SIZES
+ | FEATURE_EXEC
+ | FEATURE_RESTART));
+ else
+ sprintf (zsend, "S%s -Q%ld -p%c -vgrade=%c -R -N0%o",
+ qdaemon->zlocalname, iseq, bgrade, bgrade,
+ (unsigned int) (FEATURE_SIZES
+ | FEATURE_EXEC
+ | FEATURE_RESTART));
+ }
+
+ fret = fsend_uucp_cmd (qconn, zsend);
+ ubuffree (zsend);
+ if (! fret)
+ return FALSE;
+ }
+
+ /* Now we should see ROK or Rreason where reason gives a cryptic
+ reason for failure. If we are talking to a counterpart, we will
+ get back ROKN, possibly with a feature bitfield attached. */
+ zstr = zget_uucp_cmd (qconn, TRUE);
+ if (zstr == NULL)
+ return FALSE;
+
+ if (zstr[0] != 'R')
+ {
+ ulog (LOG_ERROR, "Bad reponse to handshake string (%s)",
+ zstr);
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ if (strncmp (zstr + 1, "OKN", sizeof "OKN" - 1) == 0)
+ {
+ if (zstr[sizeof "ROKN" - 1] == '\0')
+ qdaemon->ifeatures |= FEATURE_SIZES | FEATURE_V103;
+ else
+ qdaemon->ifeatures |= (int) strtol (zstr + sizeof "ROKN" - 1,
+ (char **) NULL, 0);
+ }
+ else if (strncmp (zstr + 1, "OK", sizeof "OK" - 1) == 0)
+ {
+ if (zstr[sizeof "ROK" - 1] != '\0')
+ {
+ char *zopt;
+
+ /* SVR4 UUCP returns options following the ROK string. */
+ zopt = zstr + sizeof "ROK" - 1;
+ while (*zopt != '\0')
+ {
+ char b;
+ long c;
+ char *zend;
+
+ b = *zopt++;
+ if (isspace (b) || b != '-')
+ continue;
+ switch (*zopt)
+ {
+ case 'R':
+ qdaemon->ifeatures |= (FEATURE_RESTART
+ | FEATURE_SVR4
+ | FEATURE_SIZES);
+ break;
+ case 'U':
+ c = strtol (zopt, &zend, 0);
+ if (c > 0 && c <= LONG_MAX / (long) 512)
+ qdaemon->cmax_receive = c * (long) 512;
+ zopt = zend;
+ break;
+ }
+ while (*zopt != '\0' && ! isspace (*zopt))
+ ++zopt;
+ }
+ }
+ }
+ else if (strcmp (zstr + 1, "CB") == 0)
+ {
+ ulog (LOG_NORMAL, "Remote system will call back");
+ qstat->ttype = STATUS_COMPLETE;
+ (void) fsysdep_set_status (qsys, qstat);
+ ubuffree (zstr);
+ return TRUE;
+ }
+ else
+ {
+ ulog (LOG_ERROR, "Handshake failed (%s)", zstr + 1);
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ ubuffree (zstr);
+
+ /* The slave should now send \020Pprotos\0 where protos is a list of
+ supported protocols. Each protocol is a single character. */
+ zstr = zget_uucp_cmd (qconn, TRUE);
+ if (zstr == NULL)
+ return FALSE;
+
+ if (zstr[0] != 'P')
+ {
+ ulog (LOG_ERROR, "Bad protocol handshake (%s)", zstr);
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ /* Determine the reliability characteristics of the connection by
+ combining information for the port and the dialer. If we have no
+ information, default to a reliable eight-bit full-duplex
+ connection. */
+ if (qconn->qport != NULL
+ && (qconn->qport->uuconf_ireliable & UUCONF_RELIABLE_SPECIFIED) != 0)
+ qdaemon->ireliable = qconn->qport->uuconf_ireliable;
+ if (qdialer != NULL
+ && (qdialer->uuconf_ireliable & UUCONF_RELIABLE_SPECIFIED) != 0)
+ {
+ if (qdaemon->ireliable != 0)
+ qdaemon->ireliable &= qdialer->uuconf_ireliable;
+ else
+ qdaemon->ireliable = qdialer->uuconf_ireliable;
+ }
+ if (qdaemon->ireliable == 0)
+ qdaemon->ireliable = (UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT
+ | UUCONF_RELIABLE_FULLDUPLEX
+ | UUCONF_RELIABLE_SPECIFIED);
+
+ /* Now decide which protocol to use. The system and the port may
+ have their own list of protocols. */
+ {
+ int i;
+ char ab[5];
+
+ i = CPROTOCOLS;
+ if (qsys->uuconf_zprotocols != NULL
+ || (qconn->qport != NULL
+ && qconn->qport->uuconf_zprotocols != NULL))
+ {
+ const char *zproto;
+
+ if (qsys->uuconf_zprotocols != NULL)
+ zproto = qsys->uuconf_zprotocols;
+ else
+ zproto = qconn->qport->uuconf_zprotocols;
+ for (; *zproto != '\0'; zproto++)
+ {
+ if (strchr (zstr + 1, *zproto) != NULL)
+ {
+ for (i = 0; i < CPROTOCOLS; i++)
+ if (asProtocols[i].bname == *zproto)
+ break;
+ if (i < CPROTOCOLS)
+ break;
+ }
+ }
+ }
+ else
+ {
+ /* If neither the system nor the port specified a list of
+ protocols, we want only protocols that match the known
+ reliability of the dialer and the port. */
+ for (i = 0; i < CPROTOCOLS; i++)
+ {
+ int ipr;
+
+ ipr = asProtocols[i].ireliable;
+ if ((ipr & qdaemon->ireliable) != ipr)
+ continue;
+ if (strchr (zstr + 1, asProtocols[i].bname) != NULL)
+ break;
+ }
+ }
+
+ ubuffree (zstr);
+
+ if (i >= CPROTOCOLS)
+ {
+ (void) fsend_uucp_cmd (qconn, "UN");
+ ulog (LOG_ERROR, "No mutually supported protocols");
+ return FALSE;
+ }
+
+ qdaemon->qproto = &asProtocols[i];
+
+ sprintf (ab, "U%c", qdaemon->qproto->bname);
+ if (! fsend_uucp_cmd (qconn, ab))
+ return FALSE;
+ }
+
+ /* Run any protocol parameter commands. */
+ if (qdaemon->qproto->qcmds != NULL)
+ {
+ if (qsys->uuconf_qproto_params != NULL)
+ uapply_proto_params (puuconf, qdaemon->qproto->bname,
+ qdaemon->qproto->qcmds,
+ qsys->uuconf_qproto_params);
+ if (qconn->qport != NULL
+ && qconn->qport->uuconf_qproto_params != NULL)
+ uapply_proto_params (puuconf, qdaemon->qproto->bname,
+ qdaemon->qproto->qcmds,
+ qconn->qport->uuconf_qproto_params);
+ if (qdialer != NULL
+ && qdialer->uuconf_qproto_params != NULL)
+ uapply_proto_params (puuconf, qdaemon->qproto->bname,
+ qdaemon->qproto->qcmds,
+ qdialer->uuconf_qproto_params);
+ }
+
+ /* Turn on the selected protocol. */
+ if (! (*qdaemon->qproto->pfstart) (qdaemon, &zlog))
+ return FALSE;
+ if (zlog == NULL)
+ {
+ zlog = zbufalc (sizeof "protocol ''" + 1);
+ sprintf (zlog, "protocol '%c'", qdaemon->qproto->bname);
+ }
+ ulog (LOG_NORMAL, "Handshake successful (%s)", zlog);
+ ubuffree (zlog);
+
+ *pterr = STATUS_FAILED;
+
+ {
+ boolean fret;
+ long iend_time;
+
+ fret = floop (qdaemon);
+
+ /* Now send the hangup message. As the caller, we send six O's
+ and expect to receive seven O's. We send the six O's twice to
+ help the other side. We don't worry about errors here. */
+ if (fsend_uucp_cmd (qconn, "OOOOOO")
+ && fsend_uucp_cmd (qconn, "OOOOOO"))
+ {
+ int i, fdone;
+
+ /* We look for the remote hangup string to ensure that the
+ modem has sent out our hangup string. This is only
+ necessary because some versions of UUCP complain if they
+ don't get the hangup string. The remote site should send 7
+ O's, but some versions of UUCP only send 6. We look for
+ the string several times because supposedly some
+ implementations send some garbage after the last packet but
+ before the hangup string. */
+ for (i = 0; i < 25; i++)
+ {
+ zstr = zget_uucp_cmd (qconn, FALSE);
+ if (zstr == NULL)
+ break;
+ fdone = strstr (zstr, "OOOOOO") != NULL;
+ ubuffree (zstr);
+ if (fdone)
+ break;
+ }
+ }
+
+ iend_time = ixsysdep_time ((long *) NULL);
+
+ ulog (LOG_NORMAL, "Call complete (%ld seconds)",
+ iend_time - istart_time);
+
+ if (fret)
+ {
+ qstat->ttype = STATUS_COMPLETE;
+ qstat->ilast = iend_time;
+ (void) fsysdep_set_status (qsys, qstat);
+ }
+
+ return fret;
+ }
+}
+
+/* This routine is called via uuconf_find_port when a matching port is
+ found. It tries to lock the port. If it fails, it returns
+ UUCONF_NOT_FOUND to force uuconf_find_port to continue searching
+ for the next matching port. */
+
+static int
+iuport_lock (qport, pinfo)
+ struct uuconf_port *qport;
+ pointer pinfo;
+{
+ struct spass *q = (struct spass *) pinfo;
+
+ q->fmatched = TRUE;
+
+ if (! fconn_init (qport, q->qconn))
+ return UUCONF_NOT_FOUND;
+ else if (! fconn_lock (q->qconn, FALSE))
+ {
+ uconn_free (q->qconn);
+ return UUCONF_NOT_FOUND;
+ }
+ else
+ {
+ q->flocked = TRUE;
+ return UUCONF_SUCCESS;
+ }
+}
+
+/* Prompt for a login name and a password, and run as the slave. */
+
+static boolean
+flogin_prompt (puuconf, qconn)
+ pointer puuconf;
+ struct sconnection *qconn;
+{
+ char *zuser, *zpass;
+ boolean fret;
+ int iuuconf;
+
+ DEBUG_MESSAGE0 (DEBUG_HANDSHAKE, "flogin_prompt: Waiting for login");
+
+ zuser = NULL;
+ do
+ {
+ ubuffree (zuser);
+ if (! fconn_write (qconn, "login: ", sizeof "login: " - 1))
+ return FALSE;
+ zuser = zget_typed_line (qconn);
+ }
+ while (zuser != NULL && *zuser == '\0');
+
+ if (zuser == NULL)
+ return TRUE;
+
+ if (! fconn_write (qconn, "Password:", sizeof "Password:" - 1))
+ {
+ ubuffree (zuser);
+ return FALSE;
+ }
+
+ zpass = zget_typed_line (qconn);
+ if (zpass == NULL)
+ {
+ ubuffree (zuser);
+ return TRUE;
+ }
+
+ fret = TRUE;
+
+ iuuconf = uuconf_callin (puuconf, zuser, zpass);
+ ubuffree (zpass);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ ulog (LOG_ERROR, "Bad login");
+ else if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ fret = FALSE;
+ }
+ else
+ {
+#if DEBUG > 1
+ int iholddebug;
+#endif
+
+ /* We ignore the return value of faccept_call because we really
+ don't care whether the call succeeded or not. We are going
+ to reset the port anyhow. */
+#if DEBUG > 1
+ iholddebug = iDebug;
+#endif
+ (void) faccept_call (puuconf, zuser, qconn, (const char **) NULL);
+#if DEBUG > 1
+ iDebug = iholddebug;
+#endif
+ }
+
+ ubuffree (zuser);
+
+ return fret;
+}
+
+/* Accept a call from a remote system. If pqsys is not NULL, *pqsys
+ will be set to the system that called in if known. */
+
+static boolean
+faccept_call (puuconf, zlogin, qconn, pzsystem)
+ pointer puuconf;
+ const char *zlogin;
+ struct sconnection *qconn;
+ const char **pzsystem;
+{
+ long istart_time;
+ const char *zport;
+ struct uuconf_port *qport;
+ struct uuconf_port sport;
+ int iuuconf;
+ struct uuconf_dialer *qdialer;
+ struct uuconf_dialer sdialer;
+ boolean ftcp_port;
+ char *zsend, *zspace;
+ boolean fret;
+ char *zstr;
+ struct uuconf_system ssys;
+ const struct uuconf_system *qsys;
+ const struct uuconf_system *qany;
+ char *zloc;
+ struct sstatus sstat;
+ boolean fgotseq, fgotn;
+ int i;
+ char *zlog;
+ char *zgrade;
+
+ if (pzsystem != NULL)
+ *pzsystem = NULL;
+
+ ulog (LOG_NORMAL, "Incoming call (login %s port %s)", zlogin,
+ zLdevice == NULL ? (char *) "unknown" : zLdevice);
+
+ istart_time = ixsysdep_time ((long *) NULL);
+
+ /* Figure out protocol parameters determined by the port. If no
+ port was specified we're reading standard input, so try to get
+ the port name and read information from the port file. We only
+ use the port information to get protocol parameters; we don't
+ want to start treating the port as though it were a modem, for
+ example. */
+ if (qconn->qport != NULL)
+ {
+ qport = qconn->qport;
+ zport = qport->uuconf_zname;
+ ftcp_port = FALSE;
+ }
+ else
+ {
+ zport = zsysdep_port_name (&ftcp_port);
+ if (zport == NULL)
+ {
+ qport = NULL;
+ zport = "unknown";
+ }
+ else
+ {
+ iuuconf = uuconf_find_port (puuconf, zport, (long) 0, (long) 0,
+ (int (*) P((struct uuconf_port *,
+ pointer pinfo))) NULL,
+ (pointer) NULL,
+ &sport);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ qport = NULL;
+ else if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+ else
+ qport = &sport;
+ }
+ }
+
+ /* If we've managed to figure out that this is a modem port, now try
+ to get protocol parameters from the dialer. */
+ qdialer = NULL;
+ if (qport != NULL)
+ {
+ if (qport->uuconf_ttype == UUCONF_PORTTYPE_MODEM)
+ {
+ if (qport->uuconf_u.uuconf_smodem.uuconf_pzdialer != NULL)
+ {
+ const char *zdialer;
+
+ zdialer = qport->uuconf_u.uuconf_smodem.uuconf_pzdialer[0];
+ iuuconf = uuconf_dialer_info (puuconf, zdialer, &sdialer);
+ if (iuuconf == UUCONF_SUCCESS)
+ qdialer = &sdialer;
+ }
+ else
+ qdialer = qport->uuconf_u.uuconf_smodem.uuconf_qdialer;
+ }
+ else if (qport->uuconf_ttype == UUCONF_PORTTYPE_TCP
+ || (qport->uuconf_ttype == UUCONF_PORTTYPE_TLI
+ && (qport->uuconf_ireliable
+ & UUCONF_RELIABLE_SPECIFIED) == 0))
+ ftcp_port = TRUE;
+ }
+
+ sDaemon.puuconf = puuconf;
+ sDaemon.qsys = NULL;
+ sDaemon.zlocalname = NULL;
+ sDaemon.qconn = qconn;
+ sDaemon.qproto = NULL;
+ sDaemon.clocal_size = -1;
+ sDaemon.cremote_size = -1;
+ sDaemon.cmax_ever = -2;
+ sDaemon.cmax_receive = -1;
+ sDaemon.ifeatures = 0;
+ sDaemon.frequest_hangup = FALSE;
+ sDaemon.fhangup_requested = FALSE;
+ sDaemon.fhangup = FALSE;
+ sDaemon.fmaster = FALSE;
+ sDaemon.fcaller = FALSE;
+ sDaemon.ireliable = 0;
+ sDaemon.bgrade = UUCONF_GRADE_LOW;
+
+ /* Get the local name to use. If uuconf_login_localname returns a
+ value, it is not always freed up, although it should be. */
+ iuuconf = uuconf_login_localname (puuconf, zlogin, &zloc);
+ if (iuuconf == UUCONF_SUCCESS)
+ sDaemon.zlocalname = zloc;
+ else if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ sDaemon.zlocalname = zsysdep_localname ();
+ if (sDaemon.zlocalname == NULL)
+ return FALSE;
+ }
+ else
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+
+ /* Tell the remote system who we are. */
+ zsend = zbufalc (strlen (sDaemon.zlocalname) + sizeof "Shere=");
+ sprintf (zsend, "Shere=%s", sDaemon.zlocalname);
+ fret = fsend_uucp_cmd (qconn, zsend);
+ ubuffree (zsend);
+ if (! fret)
+ return FALSE;
+
+ zstr = zget_uucp_cmd (qconn, TRUE);
+ if (zstr == NULL)
+ return FALSE;
+
+ if (zstr[0] != 'S')
+ {
+ ulog (LOG_ERROR, "Bad introduction string");
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ zspace = strchr (zstr, ' ');
+ if (zspace != NULL)
+ *zspace = '\0';
+
+ iuuconf = uuconf_system_info (puuconf, zstr + 1, &ssys);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ char *zscript;
+
+ /* Run the remote.unknown script, if appropriate. */
+ iuuconf = uuconf_remote_unknown (puuconf, &zscript);
+ if (iuuconf == UUCONF_SUCCESS)
+ {
+ if (! fsysdep_unknown_caller (zscript, zstr + 1))
+ {
+ xfree ((pointer) zscript);
+ (void) fsend_uucp_cmd (qconn, "RYou are unknown to me");
+ ubuffree (zstr);
+ return FALSE;
+ }
+ xfree ((pointer) zscript);
+ }
+ else if (iuuconf != UUCONF_NOT_FOUND)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ if (! funknown_system (puuconf, zstr + 1, &ssys))
+ {
+ (void) fsend_uucp_cmd (qconn, "RYou are unknown to me");
+ ulog (LOG_ERROR, "Call from unknown system %s", zstr + 1);
+ ubuffree (zstr);
+ return FALSE;
+ }
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ qany = NULL;
+ for (qsys = &ssys; qsys != NULL; qsys = qsys->uuconf_qalternate)
+ {
+ if (! qsys->uuconf_fcalled)
+ continue;
+
+ if (qsys->uuconf_zcalled_login == NULL
+ || strcmp (qsys->uuconf_zcalled_login, "ANY") == 0)
+ {
+ if (qany == NULL)
+ qany = qsys;
+ }
+ else if (strcmp (qsys->uuconf_zcalled_login, zlogin) == 0)
+ break;
+ }
+
+ if (qsys == NULL && qany != NULL)
+ {
+ iuuconf = uuconf_validate (puuconf, qany, zlogin);
+ if (iuuconf == UUCONF_SUCCESS)
+ qsys = qany;
+ else if (iuuconf != UUCONF_NOT_FOUND)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ ubuffree (zstr);
+ return FALSE;
+ }
+ }
+
+ if (qsys == NULL)
+ {
+ (void) fsend_uucp_cmd (qconn, "RLOGIN");
+ ulog (LOG_ERROR, "System %s used wrong login name %s",
+ zstr + 1, zlogin);
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ sDaemon.qsys = qsys;
+
+ if (pzsystem != NULL)
+ *pzsystem = zbufcpy (qsys->uuconf_zname);
+
+ ulog_system (qsys->uuconf_zname);
+
+#if DEBUG > 1
+ if (qsys->uuconf_zdebug != NULL)
+ iDebug |= idebug_parse (qsys->uuconf_zdebug);
+#endif
+
+ /* See if we are supposed to call the system back. This will queue
+ up an empty command. It would be better to actually call back
+ directly at this point as well. */
+ if (qsys->uuconf_fcallback)
+ {
+ (void) fsend_uucp_cmd (qconn, "RCB");
+ ulog (LOG_NORMAL, "Will call back");
+
+ /* Clear any existing status. */
+ sstat.ttype = STATUS_COMPLETE;
+ sstat.cretries = 0;
+ sstat.ilast = ixsysdep_time ((long *) NULL);
+ sstat.cwait = 0;
+ (void) fsysdep_set_status (qsys, &sstat);
+
+ ubuffree (zsysdep_spool_commands (qsys, UUCONF_GRADE_HIGH, 0,
+ (const struct scmd *) NULL));
+ ubuffree (zstr);
+ return TRUE;
+ }
+
+ /* We only permit one call at a time from a remote system. Lock it. */
+ if (! fsysdep_lock_system (qsys))
+ {
+ (void) fsend_uucp_cmd (qconn, "RLCK");
+ ulog (LOG_ERROR, "System already locked");
+ ubuffree (zstr);
+ return FALSE;
+ }
+ sLocked_system = *qsys;
+ fLocked_system = TRUE;
+
+ /* Set the system status. We don't care what the status was before.
+ We also don't want to kill the conversation just because we can't
+ output the .Status file, so we ignore any errors. */
+ sstat.ttype = STATUS_TALKING;
+ sstat.cretries = 0;
+ sstat.ilast = ixsysdep_time ((long *) NULL);
+ sstat.cwait = 0;
+ (void) fsysdep_set_status (qsys, &sstat);
+
+ /* Check the arguments of the remote system, if any. */
+ fgotseq = FALSE;
+ fgotn = FALSE;
+ if (zspace != NULL)
+ {
+ char **paz;
+ char **pzset;
+
+ ++zspace;
+
+ /* Break the introduction line up into arguments. */
+ paz = (char **) xmalloc ((strlen (zspace) / 2 + 2) * sizeof (char *));
+ pzset = paz;
+ *pzset++ = NULL;
+ while (TRUE)
+ {
+ while (*zspace != '\0' && isspace (BUCHAR (*zspace)))
+ ++zspace;
+ if (*zspace == '\0')
+ break;
+ *pzset++ = zspace;
+ ++zspace;
+ while (*zspace != '\0' && ! isspace (BUCHAR (*zspace)))
+ ++zspace;
+ if (*zspace == '\0')
+ break;
+ *zspace++ = '\0';
+ }
+
+ if (pzset != paz + 1)
+ {
+ int iopt;
+
+ *pzset = NULL;
+
+ /* We are going to use getopt to parse the arguments. We
+ must clear optind to force getopt to reinitialize, and
+ clear opterr to prevent getopt from printing an error
+ message. This approach assumes we are using the GNU
+ getopt, which is distributed with the program anyhow. */
+ optind = 0;
+ opterr = 0;
+
+ while ((iopt = getopt (pzset - paz, paz,
+ "N::p:Q:RU:v:x:")) != EOF)
+ {
+ long iseq;
+ long c;
+ char b;
+ int iwant;
+
+ switch (iopt)
+ {
+ case 'N':
+ /* This is used to indicate support for Taylor UUCP
+ extensions. An plain -N mean support for size
+ negotiation. If -N is followed by a number (with
+ no intervening space), the number is a bit field
+ of feature flags as defined in trans.h. Note
+ that the argument may start with 0x for hex or 0
+ for octal. */
+ fgotn = TRUE;
+ if (optarg == NULL)
+ sDaemon.ifeatures |= FEATURE_SIZES | FEATURE_V103;
+ else
+ sDaemon.ifeatures |= (int) strtol (optarg,
+ (char **) NULL,
+ 0);
+ break;
+
+ case 'p':
+ /* The argument is the lowest grade of work the
+ local system should send. */
+ if (UUCONF_GRADE_LEGAL (optarg[0]))
+ sDaemon.bgrade = optarg[0];
+ break;
+
+ case 'Q':
+ /* The conversation sequence number. */
+ iseq = strtol (optarg, (char **) NULL, 10);
+ if (qsys->uuconf_fsequence
+ && iseq != ixsysdep_get_sequence (qsys))
+ {
+ (void) fsend_uucp_cmd (qconn, "RBADSEQ");
+ ulog (LOG_ERROR, "Out of sequence call rejected");
+ sstat.ttype = STATUS_FAILED;
+ (void) fsysdep_set_status (qsys, &sstat);
+ xfree ((pointer) paz);
+ ubuffree (zstr);
+ return FALSE;
+ }
+ fgotseq = TRUE;
+ break;
+
+ case 'R':
+ /* The remote system supports file restart. */
+ sDaemon.ifeatures |= FEATURE_RESTART;
+ break;
+
+ case 'U':
+ /* The maximum file size the remote system is
+ prepared to received, in blocks where each block
+ is 512 bytes. */
+ c = strtol (optarg, (char **) NULL, 0);
+ if (c > 0 && c < LONG_MAX / (long) 512)
+ sDaemon.cmax_receive = c * (long) 512;
+ break;
+
+ case 'v':
+ /* -vgrade=X can be used to set the lowest grade of
+ work the local system should send. */
+ if (strncmp (optarg, "grade=", sizeof "grade=" - 1) == 0)
+ {
+ b = optarg[sizeof "grade=" - 1];
+ if (UUCONF_GRADE_LEGAL (b))
+ sDaemon.bgrade = b;
+ }
+ break;
+
+ case 'x':
+ iwant = (int) strtol (optarg, (char **) NULL, 10);
+#if DEBUG > 1
+ if (iwant <= 9)
+ iwant = (1 << iwant) - 1;
+ if (qsys->uuconf_zmax_remote_debug != NULL)
+ iwant &= idebug_parse (qsys->uuconf_zmax_remote_debug);
+ if ((iDebug | iwant) != iDebug)
+ {
+ iDebug |= iwant;
+ ulog (LOG_NORMAL, "Setting debugging mode to 0%o",
+ iDebug);
+ }
+#endif
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ xfree ((pointer) paz);
+ }
+
+ ubuffree (zstr);
+
+ if (qsys->uuconf_fsequence && ! fgotseq)
+ {
+ (void) fsend_uucp_cmd (qconn, "RBADSEQ");
+ ulog (LOG_ERROR, "No sequence number (call rejected)");
+ sstat.ttype = STATUS_FAILED;
+ (void) fsysdep_set_status (qsys, &sstat);
+ return FALSE;
+ }
+
+ /* We recognized the system, and the sequence number (if any) was
+ OK. Send an ROK, and send a list of protocols. If we got the -N
+ switch, send ROKN to confirm it; if the -N switch was followed by
+ a feature bitfield, return our own feature bitfield. */
+ {
+ char ab[20];
+ const char *zreply;
+
+ if (! fgotn)
+ {
+ if ((sDaemon.ifeatures & FEATURE_RESTART) == 0)
+ zreply = "ROK";
+ else
+ {
+ /* We got -R without -N, so assume that this is SVR4 UUCP.
+ SVR4 UUCP expects ROK -R to signal support for file
+ restart. */
+ sDaemon.ifeatures |= FEATURE_SVR4 | FEATURE_SIZES;
+ zreply = "ROK -R";
+ }
+ }
+ else if ((sDaemon.ifeatures & FEATURE_V103) != 0)
+ zreply = "ROKN";
+ else
+ {
+ sprintf (ab, "ROKN0%o",
+ (unsigned int) (FEATURE_SIZES
+ | FEATURE_EXEC
+ | FEATURE_RESTART));
+ zreply = ab;
+ }
+ if (! fsend_uucp_cmd (qconn, zreply))
+ {
+ sstat.ttype = STATUS_FAILED;
+ (void) fsysdep_set_status (qsys, &sstat);
+ return FALSE;
+ }
+ }
+
+ /* Determine the reliability of the connection based on the
+ reliability of the port and the dialer. If we have no
+ information, default to a reliable eight-bit full-duplex
+ connection. */
+ if (ftcp_port)
+ sDaemon.ireliable = (UUCONF_RELIABLE_SPECIFIED
+ | UUCONF_RELIABLE_ENDTOEND
+ | UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT
+ | UUCONF_RELIABLE_FULLDUPLEX);
+ else
+ {
+ if (qport != NULL
+ && (qport->uuconf_ireliable & UUCONF_RELIABLE_SPECIFIED) != 0)
+ sDaemon.ireliable = qport->uuconf_ireliable;
+ if (qdialer != NULL
+ && (qdialer->uuconf_ireliable & UUCONF_RELIABLE_SPECIFIED) != 0)
+ {
+ if (sDaemon.ireliable != 0)
+ sDaemon.ireliable &= qdialer->uuconf_ireliable;
+ else
+ sDaemon.ireliable = qdialer->uuconf_ireliable;
+ }
+ if (sDaemon.ireliable == 0)
+ sDaemon.ireliable = (UUCONF_RELIABLE_RELIABLE
+ | UUCONF_RELIABLE_EIGHT
+ | UUCONF_RELIABLE_FULLDUPLEX
+ | UUCONF_RELIABLE_SPECIFIED);
+ }
+
+ if (qsys->uuconf_zprotocols != NULL ||
+ (qport != NULL && qport->uuconf_zprotocols != NULL))
+ {
+ const char *zprotos;
+
+ if (qsys->uuconf_zprotocols != NULL)
+ zprotos = qsys->uuconf_zprotocols;
+ else
+ zprotos = qport->uuconf_zprotocols;
+ zsend = zbufalc (strlen (zprotos) + 2);
+ sprintf (zsend, "P%s", zprotos);
+ }
+ else
+ {
+ char *zset;
+
+ zsend = zbufalc (CPROTOCOLS + 2);
+ zset = zsend;
+ *zset++ = 'P';
+
+ /* If the system did not specify a list of protocols, we want
+ only protocols that match the known reliability of the dialer
+ and the port. */
+ for (i = 0; i < CPROTOCOLS; i++)
+ {
+ int ipr;
+
+ ipr = asProtocols[i].ireliable;
+ if ((ipr & sDaemon.ireliable) != ipr)
+ continue;
+ *zset++ = asProtocols[i].bname;
+ }
+ *zset = '\0';
+ }
+
+ fret = fsend_uucp_cmd (qconn, zsend);
+ ubuffree (zsend);
+ if (! fret)
+ {
+ sstat.ttype = STATUS_FAILED;
+ (void) fsysdep_set_status (qsys, &sstat);
+ return FALSE;
+ }
+
+ /* The master will now send back the selected protocol. */
+ zstr = zget_uucp_cmd (qconn, TRUE);
+ if (zstr == NULL)
+ {
+ sstat.ttype = STATUS_FAILED;
+ (void) fsysdep_set_status (qsys, &sstat);
+ return FALSE;
+ }
+
+ if (zstr[0] != 'U' || zstr[2] != '\0')
+ {
+ ulog (LOG_ERROR, "Bad protocol response string");
+ sstat.ttype = STATUS_FAILED;
+ (void) fsysdep_set_status (qsys, &sstat);
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ if (zstr[1] == 'N')
+ {
+ ulog (LOG_ERROR, "No supported protocol");
+ sstat.ttype = STATUS_FAILED;
+ (void) fsysdep_set_status (qsys, &sstat);
+ ubuffree (zstr);
+ return FALSE;
+ }
+
+ for (i = 0; i < CPROTOCOLS; i++)
+ if (asProtocols[i].bname == zstr[1])
+ break;
+
+ ubuffree (zstr);
+
+ if (i >= CPROTOCOLS)
+ {
+ ulog (LOG_ERROR, "No supported protocol");
+ sstat.ttype = STATUS_FAILED;
+ (void) fsysdep_set_status (qsys, &sstat);
+ return FALSE;
+ }
+
+ sDaemon.qproto = &asProtocols[i];
+
+ /* Run the chat script for when a call is received. */
+ if (! fchat (qconn, puuconf, &qsys->uuconf_scalled_chat, qsys,
+ (const struct uuconf_dialer *) NULL, (const char *) NULL,
+ FALSE, zport, iconn_baud (qconn)))
+ {
+ sstat.ttype = STATUS_FAILED;
+ sstat.ilast = ixsysdep_time ((long *) NULL);
+ (void) fsysdep_set_status (qsys, &sstat);
+ return FALSE;
+ }
+
+ /* Run any protocol parameter commands. */
+ if (sDaemon.qproto->qcmds != NULL)
+ {
+ if (qsys->uuconf_qproto_params != NULL)
+ uapply_proto_params (puuconf, sDaemon.qproto->bname,
+ sDaemon.qproto->qcmds,
+ qsys->uuconf_qproto_params);
+ if (qport != NULL
+ && qport->uuconf_qproto_params != NULL)
+ uapply_proto_params (puuconf, sDaemon.qproto->bname,
+ sDaemon.qproto->qcmds,
+ qport->uuconf_qproto_params);
+ if (qdialer != NULL
+ && qdialer->uuconf_qproto_params != NULL)
+ uapply_proto_params (puuconf, sDaemon.qproto->bname,
+ sDaemon.qproto->qcmds,
+ qdialer->uuconf_qproto_params);
+ }
+
+ /* We don't need the dialer information any more. */
+ if (qdialer == &sdialer)
+ (void) uuconf_dialer_free (puuconf, &sdialer);
+
+ /* Get any jobs queued for the system, and turn on the selected
+ protocol. */
+ if (! fqueue (&sDaemon, (boolean *) NULL)
+ || ! (*sDaemon.qproto->pfstart) (&sDaemon, &zlog))
+ {
+ uclear_queue (&sDaemon);
+ sstat.ttype = STATUS_FAILED;
+ sstat.ilast = ixsysdep_time ((long *) NULL);
+ (void) fsysdep_set_status (qsys, &sstat);
+ return FALSE;
+ }
+
+ if (zlog == NULL)
+ {
+ zlog = zbufalc (sizeof "protocol ''" + 1);
+ sprintf (zlog, "protocol '%c'", sDaemon.qproto->bname);
+ }
+
+ zgrade = zbufalc (sizeof "grade " + 1);
+ if (sDaemon.bgrade == UUCONF_GRADE_LOW)
+ *zgrade = '\0';
+ else
+ sprintf (zgrade, "grade %c ", sDaemon.bgrade);
+
+ /* If we are using HAVE_HDB_LOGGING, then the previous ``incoming
+ call'' message went to the general log, since we didn't know the
+ system name at that point. In that case, we repeat the port and
+ login names. */
+#if HAVE_HDB_LOGGING
+ ulog (LOG_NORMAL, "Handshake successful (login %s port %s %s%s)",
+ zlogin,
+ zLdevice == NULL ? "unknown" : zLdevice,
+ zgrade, zlog);
+#else /* ! HAVE_HDB_LOGGING */
+ ulog (LOG_NORMAL, "Handshake successful (%s%s)", zgrade, zlog);
+#endif /* ! HAVE_HDB_LOGGING */
+
+ ubuffree (zlog);
+ ubuffree (zgrade);
+
+ {
+ long iend_time;
+
+ fret = floop (&sDaemon);
+
+ /* Hangup. As the answerer, we send seven O's and expect to
+ receive six O's. We send the seven O's twice to help the other
+ side. We don't worry about errors here. */
+ if (fsend_uucp_cmd (qconn, "OOOOOOO")
+ && fsend_uucp_cmd (qconn, "OOOOOOO"))
+ {
+ int fdone;
+
+ /* We look for the remote hangup string to ensure that the
+ modem has sent out our hangup string. This is only
+ necessary because some versions of UUCP complain if they
+ don't get the hangup string. We look for the string
+ several times because supposedly some implementations send
+ some garbage after the last packet but before the hangup
+ string. */
+ for (i = 0; i < 25; i++)
+ {
+ zstr = zget_uucp_cmd (qconn, FALSE);
+ if (zstr == NULL)
+ break;
+ fdone = strstr (zstr, "OOOOOO") != NULL;
+ ubuffree (zstr);
+ if (fdone)
+ break;
+ }
+ }
+
+ iend_time = ixsysdep_time ((long *) NULL);
+
+ ulog (LOG_NORMAL, "Call complete (%ld seconds)",
+ iend_time - istart_time);
+
+ uclear_queue (&sDaemon);
+
+ if (fret)
+ sstat.ttype = STATUS_COMPLETE;
+ else
+ sstat.ttype = STATUS_FAILED;
+ sstat.ilast = iend_time;
+ (void) fsysdep_set_status (qsys, &sstat);
+
+ (void) uuconf_system_free (puuconf, &ssys);
+ if (qport == &sport)
+ (void) uuconf_port_free (puuconf, &sport);
+ xfree ((pointer) zloc);
+
+ return fret;
+ }
+}
+
+/* Apply protocol parameters, once we know the protocol. */
+
+static void
+uapply_proto_params (puuconf, bproto, qcmds, pas)
+ pointer puuconf;
+ int bproto;
+ struct uuconf_cmdtab *qcmds;
+ struct uuconf_proto_param *pas;
+{
+ struct uuconf_proto_param *qp;
+
+ for (qp = pas; qp->uuconf_bproto != '\0'; qp++)
+ {
+ if (qp->uuconf_bproto == bproto)
+ {
+ struct uuconf_proto_param_entry *qe;
+
+ for (qe = qp->uuconf_qentries; qe->uuconf_cargs > 0; qe++)
+ {
+ int iuuconf;
+
+ iuuconf = uuconf_cmd_args (puuconf, qe->uuconf_cargs,
+ qe->uuconf_pzargs, qcmds,
+ (pointer) NULL,
+ (uuconf_cmdtabfn) NULL, 0,
+ (pointer) NULL);
+ if (UUCONF_ERROR_VALUE (iuuconf) != UUCONF_SUCCESS)
+ {
+ ulog (LOG_ERROR, "Error in %c protocol parameters",
+ bproto);
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ }
+ }
+
+ break;
+ }
+ }
+}
+
+/* Send a string to the other system beginning with a DLE
+ character and terminated with a null byte. This is only
+ used when no protocol is in force. */
+
+static boolean
+fsend_uucp_cmd (qconn, z)
+ struct sconnection *qconn;
+ const char *z;
+{
+ size_t cwrite;
+ char *zalc;
+ boolean fret;
+
+ DEBUG_MESSAGE1 (DEBUG_HANDSHAKE, "fsend_uucp_cmd: Sending \"%s\"", z);
+
+ cwrite = strlen (z) + 2;
+
+ zalc = zbufalc (cwrite);
+ zalc[0] = '\020';
+ memcpy (zalc + 1, z, cwrite - 1);
+
+ fret = fconn_write (qconn, zalc, cwrite);
+ ubuffree (zalc);
+ return fret;
+}
+
+/* Get a UUCP command beginning with a DLE character and ending with a
+ null byte. This is only used when no protocol is in force. This
+ implementation has the potential of being seriously slow. It also
+ doesn't have any real error recovery. The frequired argument is
+ passed as TRUE if we need the string; we don't care that much if
+ we're closing down the connection anyhow. */
+
+#define CTIMEOUT (120)
+#define CSHORTTIMEOUT (10)
+#define CINCREMENT (100)
+
+static char *
+zget_uucp_cmd (qconn, frequired)
+ struct sconnection *qconn;
+ boolean frequired;
+{
+ char *zalc;
+ size_t calc;
+ size_t cgot;
+ boolean fintro;
+ long iendtime;
+ int ctimeout;
+#if DEBUG > 1
+ int cchars;
+ int iolddebug;
+#endif
+
+ iendtime = ixsysdep_time ((long *) NULL);
+ if (frequired)
+ iendtime += CTIMEOUT;
+ else
+ iendtime += CSHORTTIMEOUT;
+
+#if DEBUG > 1
+ cchars = 0;
+ iolddebug = iDebug;
+ if (FDEBUGGING (DEBUG_HANDSHAKE))
+ {
+ ulog (LOG_DEBUG_START, "zget_uucp_cmd: Got \"");
+ iDebug &=~ (DEBUG_INCOMING | DEBUG_PORT);
+ }
+#endif
+
+ zalc = NULL;
+ calc = 0;
+ cgot = 0;
+ fintro = FALSE;
+ while ((ctimeout = (int) (iendtime - ixsysdep_time ((long *) NULL))) > 0)
+ {
+ int b;
+
+ b = breceive_char (qconn, ctimeout, frequired);
+ /* Now b == -1 on timeout, -2 on error. */
+ if (b < 0)
+ {
+#if DEBUG > 1
+ if (FDEBUGGING (DEBUG_HANDSHAKE))
+ {
+ ulog (LOG_DEBUG_END, "\" (%s)",
+ b == -1 ? "timeout" : "error");
+ iDebug = iolddebug;
+ }
+#endif
+ if (b == -1 && frequired)
+ ulog (LOG_ERROR, "Timeout");
+ ubuffree (zalc);
+ return NULL;
+ }
+
+ /* Apparently some systems use parity on these strings, so we
+ strip the parity bit. This may need to be configurable at
+ some point, although only if system names can have eight bit
+ characters. */
+ if (! isprint (BUCHAR (b)))
+ b &= 0x7f;
+
+#if DEBUG > 1
+ if (FDEBUGGING (DEBUG_HANDSHAKE))
+ {
+ char ab[5];
+
+ ++cchars;
+ if (cchars > 60)
+ {
+ ulog (LOG_DEBUG_END, "\"");
+ ulog (LOG_DEBUG_START, "zget_uucp_cmd: Got \"");
+ cchars = 0;
+ }
+ (void) cdebug_char (ab, b);
+ ulog (LOG_DEBUG_CONTINUE, "%s", ab);
+ }
+#endif
+
+ if (! fintro)
+ {
+ if (b == '\020')
+ fintro = TRUE;
+ continue;
+ }
+
+ /* If we see another DLE, something has gone wrong; continue
+ as though this were the first one we saw. */
+ if (b == '\020')
+ {
+ cgot = 0;
+ continue;
+ }
+
+ /* Some systems send a trailing \n on the Shere line. As far as
+ I can tell this line can never contain a \n, so this
+ modification should be safe enough. */
+ if (b == '\r' || b == '\n')
+ b = '\0';
+
+ if (cgot >= calc)
+ {
+ char *znew;
+
+ calc += CINCREMENT;
+ znew = zbufalc (calc);
+ memcpy (znew, zalc, cgot);
+ ubuffree (zalc);
+ zalc = znew;
+ }
+
+ zalc[cgot] = (char) b;
+ ++cgot;
+
+ if (b == '\0')
+ {
+#if DEBUG > 1
+ if (FDEBUGGING (DEBUG_HANDSHAKE))
+ {
+ ulog (LOG_DEBUG_END, "\"");
+ iDebug = iolddebug;
+ }
+#endif
+ return zalc;
+ }
+ }
+
+#if DEBUG > 1
+ if (FDEBUGGING (DEBUG_HANDSHAKE))
+ {
+ ulog (LOG_DEBUG_END, "\" (timeout)");
+ iDebug = iolddebug;
+ }
+#endif
+
+ ubuffree (zalc);
+
+ if (frequired)
+ ulog (LOG_ERROR, "Timeout");
+ return NULL;
+}
+
+/* Read a sequence of characters up to a newline or carriage return, and
+ return the line without the line terminating character. */
+
+static char *
+zget_typed_line (qconn)
+ struct sconnection *qconn;
+{
+ char *zalc;
+ size_t calc;
+ size_t cgot;
+
+#if DEBUG > 1
+ int cchars;
+ int iolddebug;
+
+ cchars = 0;
+ iolddebug = iDebug;
+ if (FDEBUGGING (DEBUG_CHAT))
+ {
+ ulog (LOG_DEBUG_START, "zget_typed_line: Got \"");
+ iDebug &=~ (DEBUG_INCOMING | DEBUG_PORT);
+ }
+#endif
+
+ zalc = NULL;
+ calc = 0;
+ cgot = 0;
+ while (TRUE)
+ {
+ int b;
+
+ b = breceive_char (qconn, CTIMEOUT, FALSE);
+
+ /* Now b == -1 on timeout, -2 on error. */
+
+ if (b == -2 || FGOT_SIGNAL ())
+ {
+#if DEBUG > 1
+ if (FDEBUGGING (DEBUG_CHAT))
+ {
+ ulog (LOG_DEBUG_END, "\" (error)");
+ iDebug = iolddebug;
+ }
+#endif
+ ubuffree (zalc);
+ return NULL;
+ }
+
+ if (b == -1)
+ continue;
+
+#if DEBUG > 1
+ if (FDEBUGGING (DEBUG_CHAT))
+ {
+ char ab[5];
+
+ ++cchars;
+ if (cchars > 60)
+ {
+ ulog (LOG_DEBUG_END, "\"");
+ ulog (LOG_DEBUG_START, "zget_typed_line: Got \"");
+ cchars = 0;
+ }
+ (void) cdebug_char (ab, b);
+ ulog (LOG_DEBUG_CONTINUE, "%s", ab);
+ }
+#endif
+
+ if (cgot >= calc)
+ {
+ char *znew;
+
+ calc += CINCREMENT;
+ znew = zbufalc (calc);
+ memcpy (znew, zalc, cgot);
+ ubuffree (zalc);
+ zalc = znew;
+ }
+
+ if (b == '\r' || b == '\n')
+ b = '\0';
+
+ zalc[cgot] = (char) b;
+ ++cgot;
+
+ if (b == '\0')
+ {
+#if DEBUG > 1
+ if (FDEBUGGING (DEBUG_CHAT))
+ {
+ ulog (LOG_DEBUG_END, "\"");
+ iDebug = iolddebug;
+ }
+#endif
+ return zalc;
+ }
+ }
+}
diff --git a/gnu/libexec/uucp/uucico/xcmd.c b/gnu/libexec/uucp/uucico/xcmd.c
new file mode 100644
index 00000000000..494fe127abd
--- /dev/null
+++ b/gnu/libexec/uucp/uucico/xcmd.c
@@ -0,0 +1,396 @@
+/* xcmd.c
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char xcmd_rcsid[] = "$Id: xcmd.c,v 1.1 1993/08/04 19:36:35 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+#include "prot.h"
+#include "trans.h"
+
+/* Local functions. */
+
+static boolean flocal_xcmd_request P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon));
+static boolean flocal_xcmd_await_reply P((struct stransfer *qtrans,
+ struct sdaemon *qdaemon,
+ 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
+ transmission. */
+
+boolean
+flocal_xcmd_init (qdaemon, qcmd)
+ struct sdaemon *qdaemon;
+ struct scmd *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. */
+
+static boolean
+flocal_xcmd_request (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ size_t clen;
+ char *zsend;
+ boolean fret;
+
+ ulog (LOG_NORMAL, "Requesting work: %s to %s", qtrans->s.zfrom,
+ qtrans->s.zto);
+
+ /* We send the string
+ X from to user options
+ 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);
+ zsend = zbufalc (clen);
+ 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->iremote);
+ ubuffree (zsend);
+ if (! fret)
+ {
+ utransfree (qtrans);
+ return FALSE;
+ }
+
+ qtrans->fcmd = TRUE;
+ qtrans->precfn = flocal_xcmd_await_reply;
+
+ return fqueue_receive (qdaemon, qtrans);
+}
+
+/* Get a reply to an execution request from the remote system. */
+
+/*ARGSUSED*/
+static boolean
+flocal_xcmd_await_reply (qtrans, qdaemon, zdata, cdata)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+ const char *zdata;
+ size_t cdata;
+{
+ qtrans->precfn = NULL;
+
+ if (zdata[0] != 'X'
+ || (zdata[1] != 'Y' && zdata[1] != 'N'))
+ {
+ ulog (LOG_ERROR, "Bad response to work request");
+ utransfree (qtrans);
+ return FALSE;
+ }
+
+ if (zdata[1] == 'N')
+ {
+ ulog (LOG_ERROR, "%s: work request denied", qtrans->s.zfrom);
+ (void) fmail_transfer (FALSE, qtrans->s.zuser, (const char *) NULL,
+ "work request denied",
+ qtrans->s.zfrom, qdaemon->qsys->uuconf_zname,
+ qtrans->s.zto, (const char *) NULL,
+ (const char *) NULL);
+ }
+
+ (void) fsysdep_did_work (qtrans->s.pseq);
+ utransfree (qtrans);
+
+ return TRUE;
+}
+
+/* Handle a remote work request. This just queues up the requests for
+ later processing. */
+
+boolean
+fremote_xcmd_init (qdaemon, qcmd, iremote)
+ struct sdaemon *qdaemon;
+ struct scmd *qcmd;
+ int iremote;
+{
+ const struct uuconf_system *qsys;
+ const char *zexclam;
+ const struct uuconf_system *qdestsys;
+ struct uuconf_system sdestsys;
+ char *zdestfile;
+ boolean fmkdirs;
+ struct stransfer *qtrans;
+ char *zuser;
+ char aboptions[5];
+ char *zfrom;
+ boolean fret;
+ char *zfile;
+
+ ulog (LOG_NORMAL, "Work requested: %s to %s", qcmd->zfrom,
+ qcmd->zto);
+
+ qsys = qdaemon->qsys;
+
+ zexclam = strchr (qcmd->zto, '!');
+ if (zexclam == NULL
+ || zexclam == qcmd->zto
+ || strncmp (qdaemon->zlocalname, qcmd->zto,
+ (size_t) (zexclam - qcmd->zto)) == 0)
+ {
+ const char *zconst;
+
+ /* The files are supposed to be copied to the local system. */
+ qdestsys = NULL;
+ if (zexclam == NULL)
+ zconst = qcmd->zto;
+ else
+ zconst = zexclam + 1;
+
+ zdestfile = zsysdep_local_file (zconst, qsys->uuconf_zpubdir);
+ if (zdestfile == NULL)
+ return FALSE;
+
+ zuser = NULL;
+ fmkdirs = strchr (qcmd->zoptions, 'f') != NULL;
+ }
+ else
+ {
+ size_t clen;
+ char *zcopy;
+ int iuuconf;
+ char *zoptions;
+
+ clen = zexclam - qcmd->zto;
+ zcopy = zbufalc (clen + 1);
+ memcpy (zcopy, qcmd->zto, clen);
+ zcopy[clen] = '\0';
+
+ 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);
+ ubuffree (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);
+ ubuffree (zcopy);
+ return FALSE;
+ }
+
+ ubuffree (zcopy);
+
+ qdestsys = &sdestsys;
+ zdestfile = zbufcpy (zexclam + 1);
+
+ zuser = zbufalc (strlen (qdestsys->uuconf_zname)
+ + strlen (qcmd->zuser) + sizeof "!");
+ sprintf (zuser, "%s!%s", qdestsys->uuconf_zname, qcmd->zuser);
+ zoptions = aboptions;
+ *zoptions++ = 'C';
+ if (strchr (qcmd->zoptions, 'd') != NULL)
+ *zoptions++ = 'd';
+ if (strchr (qcmd->zoptions, 'm') != NULL)
+ *zoptions++ = 'm';
+ *zoptions = '\0';
+ fmkdirs = TRUE;
+ }
+
+ /* 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))
+ {
+ ubuffree (zdestfile);
+ ubuffree (zuser);
+ return FALSE;
+ }
+
+ /* 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 (zfrom == NULL)
+ {
+ ubuffree (zdestfile);
+ ubuffree (zuser);
+ return FALSE;
+ }
+
+ if (! fsysdep_wildcard_start (zfrom))
+ {
+ ubuffree (zfrom);
+ ubuffree (zdestfile);
+ ubuffree (zuser);
+ return FALSE;
+ }
+
+ fret = TRUE;
+
+ while ((zfile = zsysdep_wildcard (zfrom)) != NULL)
+ {
+ char *zto;
+ char abtname[CFILE_NAME_LEN];
+
+ if (! fsysdep_file_exists (zfile))
+ {
+ ulog (LOG_ERROR, "%s: no such file", zfile);
+ continue;
+ }
+
+ /* Make sure the remote system is permitted to read the
+ specified file. */
+ if (! fin_directory_list (zfile, qsys->uuconf_pzremote_send,
+ qsys->uuconf_zpubdir, TRUE, TRUE,
+ (const char *) NULL))
+ {
+ ulog (LOG_ERROR, "%s: not permitted to send", zfile);
+ break;
+ }
+
+ if (qdestsys != NULL)
+ {
+ /* We really should get the original grade here. */
+ zto = zsysdep_data_file_name (qdestsys, qdaemon->zlocalname,
+ BDEFAULT_UUCP_GRADE, FALSE,
+ abtname, (char *) NULL,
+ (char *) NULL);
+ if (zto == NULL)
+ {
+ fret = FALSE;
+ break;
+ }
+ }
+ else
+ {
+ zto = zsysdep_add_base (zdestfile, zfile);
+ if (zto == NULL)
+ {
+ fret = FALSE;
+ break;
+ }
+ /* 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,
+ (const char *) NULL))
+ {
+ ulog (LOG_ERROR, "%s: not permitted to receive", zto);
+ ubuffree (zto);
+ break;
+ }
+ }
+
+ /* Copy the file either to the final destination or to the
+ spool directory. */
+ if (! fcopy_file (zfile, zto, qdestsys == NULL, fmkdirs))
+ {
+ ubuffree (zto);
+ break;
+ }
+
+ ubuffree (zto);
+
+ /* If there is a destination system, queue it up. */
+ if (qdestsys != NULL)
+ {
+ struct scmd ssend;
+ char *zjobid;
+
+ ssend.bcmd = 'S';
+ ssend.pseq = NULL;
+ ssend.zfrom = zfile;
+ ssend.zto = zdestfile;
+ ssend.zuser = zuser;
+ ssend.zoptions = aboptions;
+ ssend.ztemp = abtname;
+ ssend.imode = ixsysdep_file_mode (zfile);
+ ssend.znotify = "";
+ ssend.cbytes = -1;
+ ssend.zcmd = NULL;
+ ssend.ipos = 0;
+
+ zjobid = zsysdep_spool_commands (qdestsys, BDEFAULT_UUCP_GRADE,
+ 1, &ssend);
+ if (zjobid == NULL)
+ break;
+ ubuffree (zjobid);
+ }
+
+ ubuffree (zfile);
+ }
+
+ if (zfile != NULL)
+ ubuffree (zfile);
+
+ (void) fsysdep_wildcard_end ();
+
+ ubuffree (zdestfile);
+ if (qdestsys != NULL)
+ (void) uuconf_system_free (qdaemon->puuconf, &sdestsys);
+
+ ubuffree (zfrom);
+ ubuffree (zuser);
+
+ return fret;
+}
+
+/* Reply to a remote work request. */
+
+static boolean
+fremote_xcmd_reply (qtrans, qdaemon)
+ struct stransfer *qtrans;
+ struct sdaemon *qdaemon;
+{
+ boolean fret;
+
+ fret = (*qdaemon->qproto->pfsendcmd) (qdaemon,
+ (const char *) qtrans->pinfo,
+ qtrans->ilocal,
+ qtrans->iremote);
+ utransfree (qtrans);
+ return fret;
+}
diff --git a/gnu/libexec/uucp/uuconv/Makefile b/gnu/libexec/uucp/uuconv/Makefile
new file mode 100644
index 00000000000..d7cbeca43f9
--- /dev/null
+++ b/gnu/libexec/uucp/uuconv/Makefile
@@ -0,0 +1,16 @@
+# Makefile for uuconv
+
+BINDIR= $(sbindir)
+BINOWN= $(owner)
+
+PROG= uuconv
+SRCS= uuconv.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -I$(.CURDIR)/../libuuconf\
+ -DVERSION=\"$(VERSION)\"
+
+NOMAN= noman
+
+.include <bsd.prog.mk>
diff --git a/gnu/libexec/uucp/uuconv/uuconv.c b/gnu/libexec/uucp/uuconv/uuconv.c
new file mode 100644
index 00000000000..82f4e35f933
--- /dev/null
+++ b/gnu/libexec/uucp/uuconv/uuconv.c
@@ -0,0 +1,2012 @@
+/* uuconv.c
+ Convert one type of UUCP configuration file to another.
+
+ 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.
+ */
+
+#include "uucnfi.h"
+
+#if USE_RCS_ID
+const char uuconv_rcsid[] = "$Id: uuconv.c,v 1.1 1993/08/04 19:36:39 jtc Exp $";
+#endif
+
+#include "getopt.h"
+
+/* Local functions. */
+
+static void uvusage P((void));
+static void uvwrite_time P((FILE *e, struct uuconf_timespan *qtime));
+static void uvwrite_string P((FILE *e, const char *zarg, const char *zcmd));
+static void uvwrite_size P((FILE *e, struct uuconf_timespan *qsize,
+ const char *zcmd));
+static void uvwrite_boolean P((FILE *e, int iarg, const char *zcmd));
+static void uvwrite_string_array P((FILE *e, char **pz, const char *zcmd));
+static void uvwrite_chat_script P((FILE *e, char **pz));
+static void uvwrite_chat P((FILE *e, const struct uuconf_chat *qchat,
+ const struct uuconf_chat *qlast,
+ const char *zprefix, boolean fforce));
+static void uvwrite_proto_params P((FILE *e,
+ const struct uuconf_proto_param *qparam,
+ const char *zprefix));
+static void uvwrite_taylor_system P((FILE *e,
+ const struct uuconf_system *qsys));
+static void uvwrite_v2_system P((FILE *e,
+ const struct uuconf_system *qsys));
+static void uvwrite_hdb_system P((FILE *e,
+ const struct uuconf_system *qsys));
+static boolean fvperm_string_cmp P((const char *z1, const char *z2));
+static boolean fvperm_array_cmp P((const char **pz1, const char **pz2));
+static void uvadd_perm P((struct shpermissions *qadd));
+static void uvwrite_perms P((void));
+static void uvwrite_perm_array P((FILE *e, const char **pz,
+ const char *zcmd, size_t *pccol));
+static void uvwrite_perm_boolean P((FILE *e, int f, const char *zcmd,
+ size_t *pccol, boolean fsendfiles));
+static void uvwrite_perm_rw_array P((FILE *e, const char **pz,
+ const char *zcmd, size_t *pccol));
+static void uvwrite_perm_string P((FILE *e, const char *z, const char *zcmd,
+ size_t *pccol));
+static int ivwrite_taylor_port P((struct uuconf_port *qport,
+ pointer pinfo));
+static int ivwrite_v2_port P((struct uuconf_port *qport, pointer pinfo));
+static int ivwrite_hdb_port P((struct uuconf_port *qport, pointer pinfo));
+static void uvwrite_taylor_port P((FILE *e, struct uuconf_port *qport,
+ const char *zprefix));
+static void uvwrite_taylor_dialer P((FILE *e, struct uuconf_dialer *qdialer,
+ const char *zprefix));
+static void uvwrite_hdb_dialer P((FILE *e, struct uuconf_dialer *qdialer));
+static void uvuuconf_error P((pointer puuconf, int iret));
+
+/* A list of Permissions entries built when writing out HDB system
+ information. */
+static struct shpermissions *qVperms;
+
+/* Type of configuration file. */
+enum tconfig
+{
+ CONFIG_TAYLOR,
+ CONFIG_V2,
+ CONFIG_HDB
+};
+
+/* Long getopt options. */
+static const struct option asVlongopts[] = { { NULL, 0, NULL, 0 } };
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ /* -I: The configuration file name. */
+ const char *zconfig = NULL;
+ /* -i: Input type. */
+ const char *zinput = NULL;
+ /* -o: Output type. */
+ const char *zoutput = NULL;
+ /* -p: Program name. */
+ const char *zprogram = NULL;
+ int iopt;
+ enum tconfig tinput, toutput;
+ int iret;
+ pointer pinput;
+
+ while ((iopt = getopt_long (argc, argv, "i:I:o:p:x:", asVlongopts,
+ (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 'i':
+ /* Input type. */
+ zinput = optarg;
+ break;
+
+ case 'o':
+ /* Output type. */
+ zoutput = optarg;
+ break;
+
+ case 'p':
+ /* Program name. */
+ zprogram = optarg;
+ break;
+
+ case 'I':
+ /* Set the configuration file name. */
+ zconfig = optarg;
+ break;
+
+ case 'x':
+ /* Set the debugging level. */
+ break;
+
+ case 0:
+ /* Long option found and flag set. */
+ break;
+
+ default:
+ uvusage ();
+ break;
+ }
+ }
+
+ if (optind != argc
+ || zinput == NULL
+ || zoutput == NULL)
+ uvusage ();
+
+ if (strcasecmp (zinput, "taylor") == 0)
+ tinput = CONFIG_TAYLOR;
+ else if (strcasecmp (zinput, "v2") == 0)
+ tinput = CONFIG_V2;
+ else if (strcasecmp (zinput, "hdb") == 0)
+ tinput = CONFIG_HDB;
+ else
+ {
+ uvusage ();
+ tinput = CONFIG_TAYLOR;
+ }
+
+ if (strcasecmp (zoutput, "taylor") == 0)
+ toutput = CONFIG_TAYLOR;
+ else if (strcasecmp (zoutput, "v2") == 0)
+ toutput = CONFIG_V2;
+ else if (strcasecmp (zoutput, "hdb") == 0)
+ toutput = CONFIG_HDB;
+ else
+ {
+ uvusage ();
+ toutput = CONFIG_TAYLOR;
+ }
+
+ if (tinput == toutput)
+ uvusage ();
+
+ iret = UUCONF_SUCCESS;
+
+ /* Initialize the input. */
+ pinput = NULL;
+ switch (tinput)
+ {
+ case CONFIG_TAYLOR:
+ iret = uuconf_taylor_init (&pinput, zprogram, zconfig);
+ break;
+ case CONFIG_V2:
+ iret = uuconf_v2_init (&pinput);
+ break;
+ case CONFIG_HDB:
+ iret = uuconf_hdb_init (&pinput, zprogram);
+ break;
+ }
+ if (iret != UUCONF_SUCCESS)
+ {
+ uvuuconf_error (pinput, iret);
+ exit (EXIT_FAILURE);
+ }
+
+ {
+ char **pzsystems;
+ char *zsys;
+ char abtaylor[sizeof ZCURDIR + sizeof SYSFILE - 1];
+ char abv2[sizeof ZCURDIR + sizeof V2_SYSTEMS - 1];
+ char abhdb[sizeof ZCURDIR + sizeof HDB_SYSTEMS - 1];
+ FILE *esys;
+ char **pz;
+
+ /* Get the list of systems. */
+ switch (tinput)
+ {
+ case CONFIG_TAYLOR:
+ iret = uuconf_taylor_system_names (pinput, &pzsystems, FALSE);
+ break;
+ case CONFIG_V2:
+ iret = uuconf_v2_system_names (pinput, &pzsystems, FALSE);
+ break;
+ case CONFIG_HDB:
+ iret = uuconf_hdb_system_names (pinput, &pzsystems, FALSE);
+ break;
+ }
+ if (iret != UUCONF_SUCCESS)
+ uvuuconf_error (pinput, iret);
+ else
+ {
+ /* Open the sys file for the output type. */
+ switch (toutput)
+ {
+ default:
+ case CONFIG_TAYLOR:
+ sprintf (abtaylor, "%s%s", ZCURDIR, SYSFILE);
+ zsys = abtaylor;
+ break;
+ case CONFIG_V2:
+ sprintf (abv2, "%s%s", ZCURDIR, V2_SYSTEMS);
+ zsys = abv2;
+ break;
+ case CONFIG_HDB:
+ sprintf (abhdb, "%s%s", ZCURDIR, HDB_SYSTEMS);
+ zsys = abhdb;
+ break;
+ }
+ esys = fopen (zsys, "w");
+ if (esys == NULL)
+ {
+ fprintf (stderr, "uuchk:%s: ", zsys);
+ perror ("fopen");
+ exit (EXIT_FAILURE);
+ }
+
+ fprintf (esys, "# %s file automatically generated by uuconv.\n",
+ zsys);
+
+ /* Read and write each system. We cheat and call the internal
+ routines, so that we can easily detect default information and
+ not write it out. This isn't necessary, but it makes the output
+ smaller and simpler. */
+ for (pz = pzsystems; *pz != NULL; pz++)
+ {
+ struct uuconf_system ssys;
+
+ switch (tinput)
+ {
+ case CONFIG_TAYLOR:
+ iret = _uuconf_itaylor_system_internal (pinput, *pz, &ssys);
+ break;
+ case CONFIG_V2:
+ iret = _uuconf_iv2_system_internal (pinput, *pz, &ssys);
+ break;
+ case CONFIG_HDB:
+ iret = _uuconf_ihdb_system_internal (pinput, *pz, &ssys);
+ break;
+ }
+ if (iret != UUCONF_SUCCESS)
+ uvuuconf_error (pinput, iret);
+ else
+ {
+ switch (toutput)
+ {
+ case CONFIG_TAYLOR:
+ uvwrite_taylor_system (esys, &ssys);
+ break;
+ case CONFIG_V2:
+ uvwrite_v2_system (esys, &ssys);
+ break;
+ case CONFIG_HDB:
+ uvwrite_hdb_system (esys, &ssys);
+ break;
+ }
+ if (toutput != CONFIG_HDB)
+ (void) uuconf_system_free (pinput, &ssys);
+ }
+ }
+
+ if (toutput == CONFIG_HDB)
+ uvwrite_perms ();
+
+ if (ferror (esys)
+ || fclose (esys) == EOF)
+ {
+ fprintf (stderr, "uuchk:%s: error during output\n", zsys);
+ exit (EXIT_FAILURE);
+ }
+ }
+ }
+
+ {
+ /* Open the port file for the output type. */
+ char *zport;
+ char abtaylor[sizeof ZCURDIR + sizeof PORTFILE - 1];
+ char abv2[sizeof ZCURDIR + sizeof V2_DEVICES - 1];
+ char abhdb[sizeof ZCURDIR + sizeof HDB_DEVICES - 1];
+ FILE *eport;
+ int (*piportfn) P((struct uuconf_port *, pointer));
+ struct uuconf_port sport;
+
+ switch (toutput)
+ {
+ default:
+ case CONFIG_TAYLOR:
+ sprintf (abtaylor, "%s%s", ZCURDIR, PORTFILE);
+ zport = abtaylor;
+ piportfn = ivwrite_taylor_port;
+ break;
+ case CONFIG_V2:
+ sprintf (abv2, "%s%s", ZCURDIR, V2_DEVICES);
+ zport = abv2;
+ piportfn = ivwrite_v2_port;
+ break;
+ case CONFIG_HDB:
+ sprintf (abhdb, "%s%s", ZCURDIR, HDB_DEVICES);
+ zport = abhdb;
+ piportfn = ivwrite_hdb_port;
+ break;
+ }
+ eport = fopen (zport, "w");
+ if (eport == NULL)
+ {
+ fprintf (stderr, "uuchk:%s: ", zport);
+ perror ("fopen");
+ exit (EXIT_FAILURE);
+ }
+
+ fprintf (eport, "# %s file automatically generated by uuconv.\n", zport);
+
+ switch (tinput)
+ {
+ case CONFIG_TAYLOR:
+ iret = uuconf_taylor_find_port (pinput, (const char *) NULL, 0L,
+ 0L, piportfn, (pointer) eport,
+ &sport);
+ break;
+ case CONFIG_V2:
+ iret = uuconf_v2_find_port (pinput, (const char *) NULL, 0L, 0L,
+ piportfn, (pointer) eport, &sport);
+ break;
+ case CONFIG_HDB:
+ iret = uuconf_hdb_find_port (pinput, (const char *) NULL, 0L, 0L,
+ piportfn, (pointer) eport, &sport);
+ break;
+ }
+
+ if (iret != UUCONF_NOT_FOUND)
+ uvuuconf_error (pinput, iret);
+
+ if (ferror (eport)
+ || fclose (eport) == EOF)
+ {
+ fprintf (stderr, "uuchk:%s: error during output\n", zport);
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ /* V2 configuration files don't support dialers. */
+ if (tinput != CONFIG_V2 && toutput != CONFIG_V2)
+ {
+ char **pzdialers;
+ char *zdialer;
+ char abtaylor[sizeof ZCURDIR + sizeof DIALFILE - 1];
+ char abhdb[sizeof ZCURDIR + sizeof HDB_DIALERS - 1];
+ FILE *edialer;
+ char **pz;
+
+ /* Get the list of dialers. */
+ switch (tinput)
+ {
+ default:
+ case CONFIG_TAYLOR:
+ iret = uuconf_taylor_dialer_names (pinput, &pzdialers);
+ break;
+ case CONFIG_HDB:
+ iret = uuconf_hdb_dialer_names (pinput, &pzdialers);
+ break;
+ }
+ if (iret != UUCONF_SUCCESS)
+ uvuuconf_error (pinput, iret);
+ else
+ {
+ /* Open the sys file for the output type. */
+ switch (toutput)
+ {
+ default:
+ case CONFIG_TAYLOR:
+ sprintf (abtaylor, "%s%s", ZCURDIR, DIALFILE);
+ zdialer = abtaylor;
+ break;
+ case CONFIG_HDB:
+ sprintf (abhdb, "%s%s", ZCURDIR, HDB_DIALERS);
+ zdialer = abhdb;
+ break;
+ }
+ edialer = fopen (zdialer, "w");
+ if (edialer == NULL)
+ {
+ fprintf (stderr, "uuchk:%s: ", zdialer);
+ perror ("fopen");
+ exit (EXIT_FAILURE);
+ }
+
+ fprintf (edialer, "# %s file automatically generated by uuconv.\n",
+ zdialer);
+
+ /* Read and write each dialer. */
+ for (pz = pzdialers; *pz != NULL; pz++)
+ {
+ struct uuconf_dialer sdialer;
+
+ switch (tinput)
+ {
+ default:
+ case CONFIG_TAYLOR:
+ iret = uuconf_taylor_dialer_info (pinput, *pz, &sdialer);
+ break;
+ case CONFIG_HDB:
+ iret = uuconf_hdb_dialer_info (pinput, *pz, &sdialer);
+ break;
+ }
+ if (iret != UUCONF_SUCCESS)
+ uvuuconf_error (pinput, iret);
+ else
+ {
+ switch (toutput)
+ {
+ default:
+ case CONFIG_TAYLOR:
+ fprintf (edialer, "# Start of dialer %s\n",
+ sdialer.uuconf_zname);
+ fprintf (edialer, "dialer %s\n", sdialer.uuconf_zname);
+ uvwrite_taylor_dialer (edialer, &sdialer, "");
+ break;
+ case CONFIG_HDB:
+ uvwrite_hdb_dialer (edialer, &sdialer);
+ break;
+ }
+ (void) uuconf_dialer_free (pinput, &sdialer);
+ }
+ }
+
+ if (ferror (edialer)
+ || fclose (edialer) == EOF)
+ {
+ fprintf (stderr, "uuchk:%s: error during output\n", zdialer);
+ exit (EXIT_FAILURE);
+ }
+ }
+ }
+
+ exit (EXIT_SUCCESS);
+}
+
+/* Print out a usage message and die. */
+
+static void
+uvusage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uuconv -i input -o output [-p program] [-I file]\n");
+ fprintf (stderr,
+ " -i input: Set input type (one of taylor, v2, hdb)\n");
+ fprintf (stderr,
+ " -o output: Set output type (one of taylor, v2, hdb)\n");
+ fprintf (stderr,
+ " -p program: Program to convert (e.g., uucp or cu)\n");
+ fprintf (stderr,
+ " -I file: Set Taylor UUCP configuration file to use\n");
+ exit (EXIT_FAILURE);
+}
+
+/* Write out a timespan. */
+
+static void
+uvwrite_time (e, qtime)
+ FILE *e;
+ struct uuconf_timespan *qtime;
+{
+ if (qtime == NULL)
+ {
+ fprintf (e, "Never");
+ return;
+ }
+
+ if (qtime->uuconf_istart == 0 && qtime->uuconf_iend == 7 * 24 * 60)
+ {
+ fprintf (e, "Any");
+ return;
+ }
+
+ for (; qtime != NULL; qtime = qtime->uuconf_qnext)
+ {
+ int idaystart, idayend;
+ int ihourstart, ihourend;
+ int iminutestart, iminuteend;
+ const char * const zdays = "Su\0Mo\0Tu\0We\0Th\0Fr\0Sa";
+
+ idaystart = qtime->uuconf_istart / (24 * 60);
+ ihourstart = (qtime->uuconf_istart % (24 * 60)) / 60;
+ iminutestart = qtime->uuconf_istart % 60;
+ if (qtime->uuconf_iend >= 7 * 24 * 60)
+ qtime->uuconf_iend = 7 * 24 * 60 - 1;
+ idayend = qtime->uuconf_iend / (24 * 60);
+ ihourend = (qtime->uuconf_iend % (24 * 60)) / 60;
+ iminuteend = qtime->uuconf_iend % 60;
+ if (ihourend == 0 && iminuteend == 0)
+ --idayend;
+
+ if (idaystart == idayend)
+ fprintf (e, "%s%02d%02d-%02d%02d", zdays + idaystart * 3,
+ ihourstart, iminutestart, ihourend, iminuteend);
+ else
+ {
+ int i;
+
+ fprintf (e, "%s%02d%02d-0000", zdays + idaystart * 3,
+ ihourstart, iminutestart);
+ for (i = idaystart + 1; i < idayend; i++)
+ fprintf (e, ",%s", zdays + i * 3);
+ if (ihourend != 0 || iminuteend != 0)
+ fprintf (e, ",%s0000-%02d%02d", zdays + idayend * 3, ihourend,
+ iminuteend);
+ }
+
+ if (qtime->uuconf_qnext != NULL)
+ fprintf (e, ",");
+ }
+}
+
+/* Some subroutines used when writing out Taylor UUCP configuration
+ files. */
+
+/* Write a command with a string argument. */
+
+static void
+uvwrite_string (e, zarg, zcmd)
+ FILE *e;
+ const char *zarg;
+ const char *zcmd;
+{
+ if (zarg != (const char *) &_uuconf_unset)
+ fprintf (e, "%s %s\n", zcmd, zarg == NULL ? (const char *) "" : zarg);
+}
+
+/* Write out a size restriction command. */
+
+static void
+uvwrite_size (e, qtime, zcmd)
+ FILE *e;
+ struct uuconf_timespan *qtime;
+ const char *zcmd;
+{
+ if (qtime != (struct uuconf_timespan *) &_uuconf_unset)
+ {
+ for (; qtime != NULL; qtime = qtime->uuconf_qnext)
+ {
+ fprintf (e, "%s %ld", zcmd, qtime->uuconf_ival);
+ uvwrite_time (e, qtime);
+ fprintf (e, "\n");
+ }
+ }
+}
+
+/* Write out a boolean argument with a string command. If the value
+ is less than zero, than it was uninitialized and we don't write
+ anything. */
+
+static void
+uvwrite_boolean (e, fval, zcmd)
+ FILE *e;
+ int fval;
+ const char *zcmd;
+{
+ if (fval >= 0)
+ fprintf (e, "%s %s\n", zcmd, fval > 0 ? "true" : "false");
+}
+
+/* Write out a string array as a single command. */
+
+static void
+uvwrite_string_array (e, pz, zcmd)
+ FILE *e;
+ char **pz;
+ const char *zcmd;
+{
+ if (pz != (char **) &_uuconf_unset)
+ {
+ fprintf (e, "%s", zcmd);
+ if (pz != NULL)
+ for (; *pz != NULL; pz++)
+ fprintf (e, " %s", *pz);
+ fprintf (e, "\n");
+ }
+}
+
+/* Write out a chat script. Don't separate subsend/subexpect strings
+ by spaces. */
+
+static void
+uvwrite_chat_script (e, pzarg)
+ FILE *e;
+ char **pzarg;
+{
+ char **pz;
+
+ if (pzarg == NULL || pzarg == (char **) &_uuconf_unset)
+ return;
+
+ for (pz = pzarg; *pz != NULL; pz++)
+ {
+ if ((*pz)[0] != '-' && pz != pzarg)
+ fprintf (e, " ");
+ fprintf (e, *pz);
+ }
+}
+
+/* Write out chat information. If the qlast argument is not NULL,
+ then only values that are different from qlast should be written.
+ The fforce argument is used to get around a peculiar problem: if
+ the ``chat'' command is used with no arguments for a system, then
+ uuconf_pzchat will be NULL (not &_uuconf_unset) and the default
+ chat script will not be used. We must distinguish this case from
+ the ``chat'' command not appearing at all for a port or dialer, in
+ which case the value will again be NULL. In the former case we
+ must output a ``chat'' command, in the latter case we would prefer
+ not to. */
+
+static void
+uvwrite_chat (e, q, qlast, zprefix, fforce)
+ FILE *e;
+ const struct uuconf_chat *q;
+ const struct uuconf_chat *qlast;
+ const char *zprefix;
+ boolean fforce;
+{
+ char **pz;
+ char ab[100];
+
+ if (q->uuconf_pzchat != (char **) &_uuconf_unset
+ && (qlast == NULL
+ ? (fforce || q->uuconf_pzchat != NULL)
+ : qlast->uuconf_pzchat != q->uuconf_pzchat))
+ {
+ fprintf (e, "%schat ", zprefix);
+ uvwrite_chat_script (e, q->uuconf_pzchat);
+ fprintf (e, "\n");
+ }
+
+ if (q->uuconf_pzprogram != (char **) &_uuconf_unset
+ && (qlast == NULL
+ ? q->uuconf_pzprogram != NULL
+ : qlast->uuconf_pzprogram != q->uuconf_pzprogram))
+ {
+ sprintf (ab, "%schat-program", zprefix);
+ uvwrite_string_array (e, q->uuconf_pzprogram, ab);
+ }
+
+ if (q->uuconf_ctimeout >= 0
+ && (qlast == NULL
+ || qlast->uuconf_ctimeout != q->uuconf_ctimeout))
+ fprintf (e, "%schat-timeout %d\n", zprefix, q->uuconf_ctimeout);
+
+ if (q->uuconf_pzfail != NULL
+ && q->uuconf_pzfail != (char **) &_uuconf_unset
+ && (qlast == NULL
+ || qlast->uuconf_pzfail != q->uuconf_pzfail))
+ for (pz = q->uuconf_pzfail; *pz != NULL; pz++)
+ fprintf (e, "%schat-fail %s\n", zprefix, *pz);
+
+ if (qlast == NULL || qlast->uuconf_fstrip != q->uuconf_fstrip)
+ {
+ sprintf (ab, "%schat-strip", zprefix);
+ uvwrite_boolean (e, q->uuconf_fstrip, ab);
+ }
+}
+
+/* Write out protocol parameters to a Taylor UUCP file. */
+
+static void
+uvwrite_proto_params (e, qparams, zprefix)
+ FILE *e;
+ const struct uuconf_proto_param *qparams;
+ const char *zprefix;
+{
+ const struct uuconf_proto_param *qp;
+
+ if (qparams == NULL
+ || qparams == (struct uuconf_proto_param *) &_uuconf_unset)
+ return;
+
+ for (qp = qparams; qp->uuconf_bproto != '\0'; qp++)
+ {
+ const struct uuconf_proto_param_entry *qe;
+
+ for (qe = qp->uuconf_qentries; qe->uuconf_cargs > 0; qe++)
+ {
+ int i;
+
+ fprintf (e, "%sprotocol-parameter %c", zprefix, qp->uuconf_bproto);
+ for (i = 0; i < qe->uuconf_cargs; i++)
+ fprintf (e, " %s", qe->uuconf_pzargs[i]);
+ fprintf (e, "\n");
+ }
+ }
+}
+
+/* Write out Taylor UUCP system information. */
+
+static void
+uvwrite_taylor_system (e, q)
+ FILE *e;
+ const struct uuconf_system *q;
+{
+ char **pz;
+ const struct uuconf_system *qlast;
+
+ fprintf (e, "# Start of system %s\n", q->uuconf_zname);
+
+ fprintf (e, "system %s\n", q->uuconf_zname);
+ if (q->uuconf_pzalias != NULL
+ && q->uuconf_pzalias != (char **) &_uuconf_unset)
+ for (pz = q->uuconf_pzalias; *pz != NULL; pz++)
+ uvwrite_string (e, *pz, "alias");
+
+ for (qlast = NULL; q != NULL; qlast = q, q = q->uuconf_qalternate)
+ {
+ struct uuconf_timespan *qtime;
+
+ if (qlast != NULL)
+ {
+ fprintf (e, "alternate");
+ if (q->uuconf_zalternate != (char *) &_uuconf_unset
+ && q->uuconf_zalternate != NULL)
+ fprintf (e, " %s", q->uuconf_zalternate);
+ fprintf (e, "\n");
+ }
+
+#define CHANGED(x) (qlast == NULL || qlast->x != q->x)
+
+ if (CHANGED (uuconf_qtimegrade)
+ && (q->uuconf_qtimegrade
+ != (struct uuconf_timespan *) &_uuconf_unset))
+ {
+ if (q->uuconf_qtimegrade == NULL)
+ fprintf (e, "time never\n");
+ else
+ {
+ for (qtime = q->uuconf_qtimegrade;
+ qtime != NULL;
+ qtime = qtime->uuconf_qnext)
+ {
+ if ((char) qtime->uuconf_ival == UUCONF_GRADE_LOW)
+ fprintf (e, "time ");
+ else
+ fprintf (e, "timegrade %c ", (char) qtime->uuconf_ival);
+ uvwrite_time (e, qtime);
+ if (qtime->uuconf_cretry != 0)
+ fprintf (e, " %d", qtime->uuconf_cretry);
+ fprintf (e, "\n");
+ }
+ }
+ }
+
+ if (CHANGED (uuconf_qcalltimegrade)
+ && (q->uuconf_qcalltimegrade
+ != (struct uuconf_timespan *) &_uuconf_unset))
+ {
+ for (qtime = q->uuconf_qcalltimegrade;
+ qtime != NULL;
+ qtime = qtime->uuconf_qnext)
+ {
+ fprintf (e, "call-timegrade %c ", (char) qtime->uuconf_ival);
+ uvwrite_time (e, qtime);
+ fprintf (e, "\n");
+ }
+ }
+
+ if (CHANGED (uuconf_qcall_local_size))
+ uvwrite_size (e, q->uuconf_qcall_local_size, "call-local-size");
+
+ if (CHANGED (uuconf_qcall_remote_size))
+ uvwrite_size (e, q->uuconf_qcall_remote_size, "call-remote-size");
+
+ if (CHANGED (uuconf_qcalled_local_size))
+ uvwrite_size (e, q->uuconf_qcalled_local_size, "called-local-size");
+
+ if (CHANGED (uuconf_qcalled_remote_size))
+ uvwrite_size (e, q->uuconf_qcalled_remote_size, "called-remote-size");
+
+ if (CHANGED (uuconf_ibaud) || CHANGED (uuconf_ihighbaud))
+ {
+ if (q->uuconf_ibaud >= 0)
+ {
+ if (q->uuconf_ihighbaud > 0)
+ fprintf (e, "baud-range %ld %ld\n", q->uuconf_ibaud,
+ q->uuconf_ihighbaud);
+ else
+ fprintf (e, "baud %ld\n", q->uuconf_ibaud);
+ }
+ }
+
+ if (CHANGED (uuconf_zport) || CHANGED (uuconf_qport))
+ {
+ if (q->uuconf_zport != NULL
+ && q->uuconf_zport != (char *) &_uuconf_unset)
+ uvwrite_string (e, q->uuconf_zport, "port");
+ else if (q->uuconf_qport != NULL
+ && (q->uuconf_qport
+ != (struct uuconf_port *) &_uuconf_unset))
+ uvwrite_taylor_port (e, q->uuconf_qport, "port ");
+ }
+
+ if (CHANGED (uuconf_zphone))
+ {
+ const char *zcmd;
+
+ if (q->uuconf_qport != NULL
+ && q->uuconf_qport != (struct uuconf_port *) &_uuconf_unset
+ && (q->uuconf_qport->uuconf_ttype == UUCONF_PORTTYPE_TCP
+ || q->uuconf_qport->uuconf_ttype == UUCONF_PORTTYPE_TLI))
+ zcmd = "address";
+ else
+ zcmd = "phone";
+ uvwrite_string (e, q->uuconf_zphone, zcmd);
+ }
+
+ uvwrite_chat (e, &q->uuconf_schat,
+ (qlast == NULL
+ ? (struct uuconf_chat *) NULL
+ : &qlast->uuconf_schat),
+ "", TRUE);
+
+ if (CHANGED (uuconf_zcall_login))
+ uvwrite_string (e, q->uuconf_zcall_login, "call-login");
+
+ if (CHANGED (uuconf_zcall_password))
+ uvwrite_string (e, q->uuconf_zcall_password, "call-password");
+
+ if (CHANGED (uuconf_zcalled_login))
+ uvwrite_string (e, q->uuconf_zcalled_login, "called-login");
+
+ if (CHANGED (uuconf_fcallback))
+ uvwrite_boolean (e, q->uuconf_fcallback, "callback");
+
+ if (CHANGED (uuconf_fsequence))
+ uvwrite_boolean (e, q->uuconf_fsequence, "sequence");
+
+ if (CHANGED (uuconf_zprotocols))
+ uvwrite_string (e, q->uuconf_zprotocols, "protocol");
+
+ if (CHANGED (uuconf_qproto_params))
+ uvwrite_proto_params (e, q->uuconf_qproto_params, "");
+
+ uvwrite_chat (e, &q->uuconf_scalled_chat,
+ (qlast == NULL
+ ? (struct uuconf_chat *) NULL
+ : &qlast->uuconf_scalled_chat),
+ "called-", FALSE);
+
+ if (CHANGED (uuconf_zdebug))
+ uvwrite_string (e, q->uuconf_zdebug, "debug");
+
+ if (CHANGED (uuconf_zmax_remote_debug))
+ uvwrite_string (e, q->uuconf_zmax_remote_debug, "max-remote-debug");
+
+ if ((CHANGED (uuconf_fsend_request)
+ || CHANGED (uuconf_frec_request))
+ && (q->uuconf_fsend_request >= 0
+ || q->uuconf_frec_request >= 0))
+ {
+ if (q->uuconf_fsend_request >= 0
+ && (q->uuconf_fsend_request > 0
+ ? q->uuconf_frec_request > 0
+ : q->uuconf_frec_request == 0))
+ uvwrite_boolean (e, q->uuconf_fsend_request, "request");
+ else
+ {
+ uvwrite_boolean (e, q->uuconf_fsend_request, "send-request");
+ uvwrite_boolean (e, q->uuconf_frec_request,
+ "receive-request");
+ }
+ }
+
+ if ((CHANGED (uuconf_fcall_transfer)
+ || CHANGED (uuconf_fcalled_transfer))
+ && (q->uuconf_fcall_transfer >= 0
+ || q->uuconf_fcalled_transfer >= 0))
+ {
+ if (q->uuconf_fcall_transfer >= 0
+ && (q->uuconf_fcall_transfer > 0
+ ? q->uuconf_fcalled_transfer > 0
+ : q->uuconf_fcalled_transfer == 0))
+ uvwrite_boolean (e, q->uuconf_fcall_transfer, "transfer");
+ else
+ {
+ uvwrite_boolean (e, q->uuconf_fcall_transfer, "call-transfer");
+ uvwrite_boolean (e, q->uuconf_fcalled_transfer,
+ "called-transfer");
+ }
+ }
+
+ if (CHANGED (uuconf_pzlocal_send))
+ uvwrite_string_array (e, q->uuconf_pzlocal_send, "local-send");
+
+ if (CHANGED (uuconf_pzremote_send))
+ uvwrite_string_array (e, q->uuconf_pzremote_send, "remote-send");
+
+ if (CHANGED (uuconf_pzlocal_receive))
+ uvwrite_string_array (e, q->uuconf_pzlocal_receive, "local-receive");
+
+ if (CHANGED (uuconf_pzremote_receive))
+ uvwrite_string_array (e, q->uuconf_pzremote_receive,
+ "remote-receive");
+
+ if (CHANGED (uuconf_pzpath))
+ uvwrite_string_array (e, q->uuconf_pzpath, "command-path");
+
+ if (CHANGED (uuconf_pzcmds))
+ uvwrite_string_array (e, q->uuconf_pzcmds, "commands");
+
+ if (CHANGED (uuconf_cfree_space)
+ && q->uuconf_cfree_space >= 0)
+ fprintf (e, "free-space %ld\n", q->uuconf_cfree_space);
+
+ if (CHANGED (uuconf_pzforward_from))
+ uvwrite_string_array (e, q->uuconf_pzforward_from, "forward-from");
+
+ if (CHANGED (uuconf_pzforward_to))
+ uvwrite_string_array (e, q->uuconf_pzforward_to, "forward-to");
+
+ if (CHANGED (uuconf_zpubdir))
+ uvwrite_string (e, q->uuconf_zpubdir, "pubdir");
+
+ if (CHANGED (uuconf_zlocalname))
+ uvwrite_string (e, q->uuconf_zlocalname, "myname");
+ }
+}
+
+/* Write out V2 system information. */
+
+static void
+uvwrite_v2_system (e, q)
+ FILE *e;
+ const struct uuconf_system *q;
+{
+ for (; q != NULL; q = q->uuconf_qalternate)
+ {
+ fprintf (e, "%s", q->uuconf_zname);
+
+ if (q->uuconf_qtimegrade != (struct uuconf_timespan *) &_uuconf_unset)
+ {
+ fprintf (e, " ");
+ uvwrite_time (e, q->uuconf_qtimegrade);
+
+ if (q->uuconf_zport != (char *) &_uuconf_unset
+ || q->uuconf_qport != (struct uuconf_port *) &_uuconf_unset)
+ {
+ struct uuconf_port *qp;
+ boolean ftcp;
+
+ qp = q->uuconf_qport;
+ ftcp = (qp != (struct uuconf_port *) &_uuconf_unset
+ && qp != NULL
+ && qp->uuconf_ttype == UUCONF_PORTTYPE_TCP);
+ if (ftcp
+ || (q->uuconf_zport != NULL
+ && q->uuconf_zport != (char *) &_uuconf_unset))
+ {
+ if (ftcp)
+ fprintf (e, " TCP");
+ else
+ fprintf (e, " %s", q->uuconf_zport);
+
+ if (ftcp || q->uuconf_ibaud >= 0)
+ {
+ fprintf (e, " ");
+ if (ftcp)
+ {
+ const char *zport;
+
+ zport = qp->uuconf_u.uuconf_stcp.uuconf_zport;
+ if (zport == NULL)
+ zport = "uucp";
+ fprintf (e, "%s", zport);
+ }
+ else
+ fprintf (e, "%ld", q->uuconf_ibaud);
+
+ if (q->uuconf_zphone != (char *) &_uuconf_unset
+ && q->uuconf_zphone != NULL)
+ {
+ char **pzc;
+
+ fprintf (e, " %s", q->uuconf_zphone);
+ pzc = q->uuconf_schat.uuconf_pzchat;
+ if (pzc != (char **) &_uuconf_unset
+ && pzc != NULL)
+ {
+ fprintf (e, " ");
+ uvwrite_chat_script (e, pzc);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ fprintf (e, "\n");
+
+ /* Here we should gather information to write out to USERFILE
+ and L.cmds, and perhaps some day we will. It's much more
+ likely to happen if somebody else does it, though. */
+ }
+}
+
+/* Write out HDB system information. */
+
+static void
+uvwrite_hdb_system (e, qsys)
+ FILE *e;
+ const struct uuconf_system *qsys;
+{
+ const struct uuconf_system *q;
+ struct shpermissions sperm;
+ char *azmachine[2];
+ char *azlogname[2];
+
+ for (q = qsys; q != NULL; q = q->uuconf_qalternate)
+ {
+ if (q->uuconf_fcall)
+ {
+ fprintf (e, "%s", q->uuconf_zname);
+
+ if (q->uuconf_qtimegrade
+ != (struct uuconf_timespan *) &_uuconf_unset)
+ {
+ const char *zport;
+
+ fprintf (e, " ");
+ uvwrite_time (e, q->uuconf_qtimegrade);
+
+ zport = q->uuconf_zport;
+ if (q->uuconf_qport != NULL
+ && q->uuconf_qport != (struct uuconf_port *) &_uuconf_unset
+ && q->uuconf_qport->uuconf_ttype == UUCONF_PORTTYPE_TCP)
+ zport = "TCP";
+ if (zport != NULL && zport != (char *) &_uuconf_unset)
+ {
+ fprintf (e, " %s", zport);
+ if (q->uuconf_zprotocols != (char *) &_uuconf_unset
+ && q->uuconf_zprotocols != NULL)
+ fprintf (e, ",%s", q->uuconf_zprotocols);
+
+ if (q->uuconf_ibaud >= 0
+ || q->uuconf_zphone != (char *) &_uuconf_unset)
+ {
+ fprintf (e, " ");
+ if (q->uuconf_ibaud < 0)
+ fprintf (e, "Any");
+ else
+ {
+ fprintf (e, "%ld", q->uuconf_ibaud);
+ if (q->uuconf_ihighbaud >= 0)
+ fprintf (e, "-%ld", q->uuconf_ihighbaud);
+ }
+
+ if (q->uuconf_zphone != (char *) &_uuconf_unset
+ && q->uuconf_zphone != NULL)
+ {
+ char **pzc;
+
+ fprintf (e, " %s", q->uuconf_zphone);
+ pzc = q->uuconf_schat.uuconf_pzchat;
+ if (pzc != (char **) &_uuconf_unset
+ && pzc != NULL)
+ {
+ fprintf (e, " ");
+ uvwrite_chat_script (e, pzc);
+ }
+ }
+ }
+ }
+ }
+
+ fprintf (e, "\n");
+ }
+ }
+
+ /* Build a Permissions entry for this system. There will be only
+ one MACHINE entry for a given system. */
+
+ for (q = qsys; q != NULL; q = q->uuconf_qalternate)
+ if (q->uuconf_fcall)
+ break;
+
+ if (q != NULL)
+ {
+ sperm.qnext = NULL;
+ sperm.pzlogname = NULL;
+ sperm.pzmachine = NULL;
+ sperm.frequest = -1;
+ sperm.fsendfiles = -1;
+ sperm.pzread = NULL;
+ sperm.pzwrite = NULL;
+ sperm.fcallback = -1;
+ sperm.pzcommands = NULL;
+ sperm.pzvalidate = NULL;
+ sperm.zmyname = NULL;
+ sperm.zpubdir = NULL;
+ sperm.pzalias = NULL;
+
+ azmachine[0] = q->uuconf_zname;
+ azmachine[1] = NULL;
+ sperm.pzmachine = azmachine;
+ if (q->uuconf_fsend_request >= 0)
+ sperm.frequest = q->uuconf_fsend_request;
+ if (q->uuconf_pzremote_send != (char **) &_uuconf_unset
+ && q->uuconf_pzremote_send != NULL)
+ sperm.pzread = q->uuconf_pzremote_send;
+ if (q->uuconf_pzremote_receive != (char **) &_uuconf_unset
+ && q->uuconf_pzremote_receive != NULL)
+ sperm.pzwrite = q->uuconf_pzremote_receive;
+ if (q->uuconf_pzcmds != (char **) &_uuconf_unset
+ && q->uuconf_pzcmds != NULL)
+ sperm.pzcommands = q->uuconf_pzcmds;
+ if (q->uuconf_zlocalname != (char *) &_uuconf_unset
+ && q->uuconf_zlocalname != NULL)
+ sperm.zmyname = q->uuconf_zlocalname;
+ if (q->uuconf_zpubdir != (char *) &_uuconf_unset
+ && q->uuconf_zpubdir != NULL)
+ sperm.zpubdir = q->uuconf_zpubdir;
+ if (q->uuconf_pzalias != (char **) &_uuconf_unset
+ && q->uuconf_pzalias != NULL)
+ sperm.pzalias = q->uuconf_pzalias;
+
+ if (q->uuconf_fcalled
+ && q->uuconf_zcalled_login != (char *) &_uuconf_unset
+ && q->uuconf_zcalled_login != NULL)
+ {
+ azlogname[0] = q->uuconf_zcalled_login;
+ azlogname[1] = NULL;
+ sperm.pzlogname = azlogname;
+ if (q->uuconf_fcalled_transfer >= 0)
+ sperm.fsendfiles = q->uuconf_fcalled_transfer;
+ if (q->uuconf_fcallback >= 0)
+ sperm.fcallback = q->uuconf_fcallback;
+ sperm.pzvalidate = azmachine;
+ }
+
+ uvadd_perm (&sperm);
+ }
+
+ /* Now add a Permissions entry for each alternative that is not used
+ for calling out. */
+ for (q = qsys; q != NULL; q = q->uuconf_qalternate)
+ {
+ if (! q->uuconf_fcalled || q->uuconf_fcall)
+ continue;
+
+ sperm.qnext = NULL;
+ sperm.pzlogname = NULL;
+ sperm.pzmachine = NULL;
+ sperm.frequest = -1;
+ sperm.fsendfiles = -1;
+ sperm.pzread = NULL;
+ sperm.pzwrite = NULL;
+ sperm.fcallback = -1;
+ sperm.pzcommands = NULL;
+ sperm.pzvalidate = NULL;
+ sperm.zmyname = NULL;
+ sperm.zpubdir = NULL;
+ sperm.pzalias = NULL;
+
+ if (q->uuconf_zcalled_login != (char *) &_uuconf_unset
+ && q->uuconf_zcalled_login != NULL)
+ azlogname[0] = q->uuconf_zcalled_login;
+ else
+ azlogname[0] = (char *) "OTHER";
+ azlogname[1] = NULL;
+ sperm.pzlogname = azlogname;
+
+ if (q->uuconf_fsend_request >= 0)
+ sperm.frequest = q->uuconf_fsend_request;
+ if (q->uuconf_fcalled_transfer >= 0)
+ sperm.fsendfiles = q->uuconf_fcalled_transfer;
+ if (q->uuconf_pzremote_send != (char **) &_uuconf_unset
+ && q->uuconf_pzremote_send != NULL)
+ sperm.pzread = q->uuconf_pzremote_send;
+ if (q->uuconf_pzremote_receive != (char **) &_uuconf_unset
+ && q->uuconf_pzremote_receive != NULL)
+ sperm.pzwrite = q->uuconf_pzremote_receive;
+ if (q->uuconf_fcallback >= 0)
+ sperm.fcallback = q->uuconf_fcallback;
+ if (q->uuconf_zlocalname != (char *) &_uuconf_unset
+ && q->uuconf_zlocalname != NULL)
+ sperm.zmyname = q->uuconf_zlocalname;
+ if (q->uuconf_zpubdir != (char *) &_uuconf_unset
+ && q->uuconf_zpubdir != NULL)
+ sperm.zpubdir = q->uuconf_zpubdir;
+
+ uvadd_perm (&sperm);
+ }
+}
+
+/* Compare two strings from a Permissions entry, returning TRUE if
+ they are the same. */
+static boolean
+fvperm_string_cmp (z1, z2)
+ const char *z1;
+ const char *z2;
+{
+ if (z1 == NULL
+ ? z2 != NULL
+ : z2 == NULL)
+ return FALSE;
+
+ if (z1 == NULL)
+ return TRUE;
+
+ return strcmp (z1, z2) == 0;
+}
+
+/* Compare two arrays of strings from a Permissions entry, returning
+ TRUE if they are the same. */
+
+static boolean
+fvperm_array_cmp (pz1, pz2)
+ const char **pz1;
+ const char **pz2;
+{
+ if (pz1 == NULL
+ ? pz2 != NULL
+ : pz2 == NULL)
+ return FALSE;
+
+ if (pz1 == NULL)
+ return TRUE;
+
+ for (; *pz1 != NULL && *pz2 != NULL; pz1++, pz2++)
+ if (strcmp (*pz1, *pz2) != 0)
+ break;
+
+ return *pz1 == NULL && *pz2 == NULL;
+}
+
+/* Add a Permissions entry to a global list, combining entries where
+ possible. */
+
+static void
+uvadd_perm (qadd)
+ struct shpermissions *qadd;
+{
+ struct shpermissions *qlook;
+ struct shpermissions *qnew;
+ int iret;
+
+ /* If there's no information, don't bother to add this entry. */
+ if (qadd->pzlogname == NULL
+ && qadd->frequest < 0
+ && qadd->fsendfiles < 0
+ && qadd->pzread == NULL
+ && qadd->pzwrite == NULL
+ && qadd->fcallback < 0
+ && qadd->pzcommands == NULL
+ && qadd->pzvalidate == NULL
+ && qadd->zmyname == NULL
+ && qadd->zpubdir == NULL
+ && qadd->pzalias == NULL)
+ return;
+
+ for (qlook = qVperms; qlook != NULL; qlook = qlook->qnext)
+ {
+ /* See if we can merge qadd into qlook. */
+ if (qadd->pzlogname == NULL
+ ? qlook->pzlogname != NULL
+ : qlook->pzlogname == NULL)
+ continue;
+ if (qadd->pzmachine == NULL
+ ? qlook->pzmachine != NULL
+ : qlook->pzmachine == NULL)
+ continue;
+ if (qadd->frequest != qlook->frequest
+ || qadd->fsendfiles != qlook->fsendfiles
+ || qadd->fcallback != qlook->fcallback)
+ continue;
+ if (! fvperm_string_cmp (qadd->zmyname, qlook->zmyname)
+ || ! fvperm_string_cmp (qadd->zpubdir, qlook->zpubdir))
+ continue;
+ if (! fvperm_array_cmp ((const char **) qadd->pzread,
+ (const char **) qlook->pzread)
+ || ! fvperm_array_cmp ((const char **) qadd->pzwrite,
+ (const char **) qlook->pzwrite)
+ || ! fvperm_array_cmp ((const char **) qadd->pzcommands,
+ (const char **) qlook->pzcommands))
+ continue;
+
+ /* Merge qadd into qlook. */
+ if (qadd->pzmachine != NULL)
+ {
+ iret = _uuconf_iadd_string ((struct sglobal *) NULL,
+ qadd->pzmachine[0], FALSE,
+ TRUE, &qlook->pzmachine,
+ (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ uvuuconf_error ((pointer) NULL, iret);
+ }
+ if (qadd->pzlogname != NULL)
+ {
+ iret = _uuconf_iadd_string ((struct sglobal *) NULL,
+ qadd->pzlogname[0], FALSE,
+ TRUE, &qlook->pzlogname,
+ (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ uvuuconf_error ((pointer) NULL, iret);
+ }
+ if (qadd->pzalias != NULL)
+ {
+ char **pz;
+
+ for (pz = qadd->pzalias; *pz != NULL; pz++)
+ {
+ iret = _uuconf_iadd_string ((struct sglobal *) NULL,
+ *pz, FALSE, TRUE,
+ &qlook->pzalias, (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ uvuuconf_error ((pointer) NULL, iret);
+ }
+ }
+
+ return;
+ }
+
+ /* We must add qadd as a new entry on the list, which means we must
+ copy it into the heap. */
+
+ qnew = (struct shpermissions *) malloc (sizeof (struct shpermissions));
+ if (qnew == NULL)
+ uvuuconf_error ((pointer) NULL, UUCONF_MALLOC_FAILED);
+ *qnew = *qadd;
+ if (qadd->pzmachine != NULL)
+ {
+ qnew->pzmachine = NULL;
+ iret = _uuconf_iadd_string ((struct sglobal *) NULL,
+ qadd->pzmachine[0], FALSE,
+ FALSE, &qnew->pzmachine,
+ (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ uvuuconf_error ((pointer) NULL, iret);
+ }
+ if (qadd->pzlogname != NULL)
+ {
+ qnew->pzlogname = NULL;
+ iret = _uuconf_iadd_string ((struct sglobal *) NULL,
+ qadd->pzlogname[0], FALSE,
+ FALSE, &qnew->pzlogname,
+ (pointer) NULL);
+ if (iret != UUCONF_SUCCESS)
+ uvuuconf_error ((pointer) NULL, iret);
+ }
+ if (qadd->pzvalidate != NULL)
+ qnew->pzvalidate = qnew->pzmachine;
+
+ qnew->qnext = qVperms;
+ qVperms = qnew;
+}
+
+/* Write out the Permissions entries. */
+
+static void
+uvwrite_perms ()
+{
+ char ab[sizeof ZCURDIR + sizeof HDB_PERMISSIONS - 1];
+ FILE *e;
+ struct shpermissions *q;
+
+ sprintf (ab, "%s%s", ZCURDIR, HDB_PERMISSIONS);
+ e = fopen (ab, "w");
+ if (e == NULL)
+ {
+ fprintf (stderr, "uuchk:%s: ", ab);
+ perror ("fopen");
+ exit (EXIT_FAILURE);
+ }
+
+ fprintf (e, "# Permissions file automatically generated by uuconv.\n");
+
+ for (q = qVperms; q != NULL; q = q->qnext)
+ {
+ size_t ccol;
+
+ ccol = 0;
+ uvwrite_perm_array (e, (const char **) q->pzlogname, "LOGNAME", &ccol);
+ uvwrite_perm_array (e, (const char **) q->pzmachine, "MACHINE", &ccol);
+ uvwrite_perm_boolean (e, q->frequest, "REQUEST", &ccol, FALSE);
+ uvwrite_perm_boolean (e, q->fsendfiles, "SENDFILES", &ccol, TRUE);
+ uvwrite_perm_rw_array (e, (const char **) q->pzread, "READ", &ccol);
+ uvwrite_perm_rw_array (e, (const char **) q->pzwrite, "WRITE", &ccol);
+ uvwrite_perm_boolean (e, q->fcallback, "CALLBACK", &ccol, FALSE);
+ uvwrite_perm_array (e, (const char **) q->pzcommands, "COMMANDS",
+ &ccol);
+ uvwrite_perm_array (e, (const char **) q->pzvalidate, "VALIDATE",
+ &ccol);
+ uvwrite_perm_string (e, q->zmyname, "MYNAME", &ccol);
+ uvwrite_perm_string (e, q->zpubdir, "PUBDIR", &ccol);
+ uvwrite_perm_array (e, (const char **) q->pzalias, "ALIAS", &ccol);
+
+ fprintf (e, "\n");
+ }
+
+ if (ferror (e)
+ || fclose (e) == EOF)
+ {
+ fprintf (stderr, "uuchk:%s: error during output\n", HDB_PERMISSIONS);
+ exit (EXIT_FAILURE);
+ }
+}
+
+/* Write an array out to the Permissions file. */
+
+static void
+uvwrite_perm_array (e, pzarg, zcmd, pccol)
+ FILE *e;
+ const char **pzarg;
+ const char *zcmd;
+ size_t *pccol;
+{
+ size_t c;
+ const char **pz;
+
+ if (pzarg == NULL)
+ return;
+
+ c = strlen (zcmd) + 1;
+
+ for (pz = pzarg; *pz != NULL; pz++)
+ c += strlen (*pz) + 1;
+
+ if (*pccol > 20 && c + *pccol > 75)
+ {
+ fprintf (e, " \\\n");
+ *pccol = c - 1;
+ }
+ else
+ {
+ if (*pccol != 0)
+ fprintf (e, " ");
+ *pccol += c;
+ }
+
+ fprintf (e, "%s=", zcmd);
+ for (pz = pzarg; *pz != NULL; pz++)
+ {
+ if (pz != pzarg)
+ fprintf (e, ":");
+ fprintf (e, "%s", *pz);
+ }
+}
+
+/* Write a boolean value out to the Permissions file. This may be
+ either a yes/no boolean or a yes/call boolean (the latter is for
+ SENDFILES). */
+
+static void
+uvwrite_perm_boolean (e, f, zcmd, pccol, fsendfiles)
+ FILE *e;
+ int f;
+ const char *zcmd;
+ size_t *pccol;
+ boolean fsendfiles;
+{
+ const char *az[2];
+
+ if (f < 0)
+ return;
+
+ if (f)
+ az[0] = "yes";
+ else
+ az[0] = fsendfiles ? "call" : "no";
+ az[1] = NULL;
+
+ uvwrite_perm_array (e, az, zcmd, pccol);
+}
+
+/* Write a set of READ or WRITE entries to the Permissions file. We
+ have to separate out all entries that start with '!'. */
+
+static void
+uvwrite_perm_rw_array (e, pzarg, zcmd, pccol)
+ FILE *e;
+ const char **pzarg;
+ const char *zcmd;
+ size_t *pccol;
+{
+ size_t c;
+ const char **pz, **pzcopy, **pzset;
+
+ if (pzarg == NULL)
+ return;
+
+ c = 0;
+ for (pz = pzarg; *pz != NULL; pz++)
+ c++;
+
+ pzcopy = (const char **) malloc ((c + 1) * sizeof (char *));
+ if (pzcopy == NULL)
+ uvuuconf_error ((pointer) NULL, UUCONF_MALLOC_FAILED);
+
+ pzset = pzcopy;
+ for (pz = pzarg; *pz != NULL; pz++)
+ if ((*pz)[0] != '!')
+ *pzset++ = *pz;
+ *pzset = NULL;
+
+ if (pzset != pzcopy)
+ uvwrite_perm_array (e, (const char **) pzcopy, zcmd, pccol);
+
+ pzset = pzcopy;
+ for (pz = pzarg; *pz != NULL; pz++)
+ if ((*pz)[0] == '!')
+ *pzset++ = *pz;
+ *pzset = NULL;
+
+ if (pzset != pzcopy)
+ {
+ char ab[20];
+
+ sprintf (ab, "NO%s", zcmd);
+ uvwrite_perm_array (e, (const char **) pzcopy, ab, pccol);
+ }
+}
+
+/* Write a string out to the Permissions file. */
+
+static void
+uvwrite_perm_string (e, z, zcmd, pccol)
+ FILE *e;
+ const char *z;
+ const char *zcmd;
+ size_t *pccol;
+{
+ const char *az[2];
+
+ if (z == NULL)
+ return;
+
+ az[0] = z;
+ az[1] = NULL;
+
+ uvwrite_perm_array (e, az, zcmd, pccol);
+}
+
+/* Write out a Taylor UUCP port. This is called via uuconf_find_port;
+ the pinfo argument is the port file. */
+
+static int
+ivwrite_taylor_port (qport, pinfo)
+ struct uuconf_port *qport;
+ pointer pinfo;
+{
+ FILE *e = (FILE *) pinfo;
+
+ fprintf (e, "port %s\n", qport->uuconf_zname);
+
+ uvwrite_taylor_port (e, qport, "");
+
+ /* Return UUCONF_NOT_FOUND to force uuconf_find_port to keep looking
+ for ports. */
+ return UUCONF_NOT_FOUND;
+}
+
+/* Write a port out to a Taylor UUCP configuration file. This doesn't
+ output the name, since it is called to output a specially defined
+ port in the sys file. */
+
+static void
+uvwrite_taylor_port (e, qport, zprefix)
+ FILE *e;
+ struct uuconf_port *qport;
+ const char *zprefix;
+{
+ const char *ztype;
+ char ab[100];
+
+ switch (qport->uuconf_ttype)
+ {
+ default:
+ case UUCONF_PORTTYPE_UNKNOWN:
+ fprintf (stderr, "uuconv: Bad port type\n");
+ exit (EXIT_FAILURE);
+ break;
+ case UUCONF_PORTTYPE_STDIN:
+ ztype = "stdin";
+ break;
+ case UUCONF_PORTTYPE_MODEM:
+ ztype = "modem";
+ break;
+ case UUCONF_PORTTYPE_DIRECT:
+ ztype = "direct";
+ break;
+ case UUCONF_PORTTYPE_TCP:
+ ztype = "tcp";
+ break;
+ case UUCONF_PORTTYPE_TLI:
+ ztype = "tli";
+ break;
+ }
+
+ fprintf (e, "%stype %s\n", zprefix, ztype);
+
+ if (qport->uuconf_zprotocols != NULL)
+ fprintf (e, "%sprotocol %s\n", zprefix, qport->uuconf_zprotocols);
+
+ if (qport->uuconf_qproto_params != NULL)
+ uvwrite_proto_params (e, qport->uuconf_qproto_params, zprefix);
+
+ if ((qport->uuconf_ireliable & UUCONF_RELIABLE_SPECIFIED) != 0)
+ {
+ sprintf (ab, "%sseven-bit", zprefix);
+ uvwrite_boolean (e,
+ ((qport->uuconf_ireliable & UUCONF_RELIABLE_EIGHT)
+ == 0),
+ ab);
+ sprintf (ab, "%sreliable", zprefix);
+ uvwrite_boolean (e,
+ ((qport->uuconf_ireliable & UUCONF_RELIABLE_RELIABLE)
+ != 0),
+ ab);
+ sprintf (ab, "%shalf-duplex", zprefix);
+ uvwrite_boolean (e,
+ ((qport->uuconf_ireliable & UUCONF_RELIABLE_FULLDUPLEX)
+ == 0),
+ ab);
+ }
+
+ if (qport->uuconf_zlockname != NULL)
+ fprintf (e, "%slockname %s\n", zprefix, qport->uuconf_zlockname);
+
+ switch (qport->uuconf_ttype)
+ {
+ default:
+ break;
+ case UUCONF_PORTTYPE_MODEM:
+ {
+ struct uuconf_modem_port *qm;
+
+ qm = &qport->uuconf_u.uuconf_smodem;
+ if (qm->uuconf_zdevice != NULL)
+ fprintf (e, "%sdevice %s\n", zprefix, qm->uuconf_zdevice);
+ if (qm->uuconf_zdial_device != NULL)
+ fprintf (e, "%sdial-device %s\n", zprefix, qm->uuconf_zdial_device);
+ if (qm->uuconf_ibaud != 0)
+ fprintf (e, "%sbaud %ld\n", zprefix, qm->uuconf_ibaud);
+ if (qm->uuconf_ilowbaud != 0)
+ fprintf (e, "%sbaud-range %ld %ld\n", zprefix, qm->uuconf_ilowbaud,
+ qm->uuconf_ihighbaud);
+ if (! qm->uuconf_fcarrier)
+ fprintf (e, "%scarrier false\n", zprefix);
+ if (qm->uuconf_pzdialer != NULL)
+ {
+ if (qm->uuconf_pzdialer[1] == NULL)
+ fprintf (e, "%sdialer %s\n", zprefix, qm->uuconf_pzdialer[0]);
+ else
+ {
+ sprintf (ab, "%sdialer-sequence", zprefix);
+ uvwrite_string_array (e, qm->uuconf_pzdialer, zprefix);
+ }
+ }
+ if (qm->uuconf_qdialer != NULL)
+ {
+ sprintf (ab, "%sdialer ", zprefix);
+ uvwrite_taylor_dialer (e, qm->uuconf_qdialer, ab);
+ }
+ }
+ break;
+ case UUCONF_PORTTYPE_DIRECT:
+ {
+ struct uuconf_direct_port *qd;
+
+ qd = &qport->uuconf_u.uuconf_sdirect;
+ if (qd->uuconf_zdevice != NULL)
+ fprintf (e, "%sdevice %s\n", zprefix, qd->uuconf_zdevice);
+ if (qd->uuconf_ibaud != 0)
+ fprintf (e, "%sbaud %ld\n", zprefix, qd->uuconf_ibaud);
+ }
+ break;
+ case UUCONF_PORTTYPE_TCP:
+ if (qport->uuconf_u.uuconf_stcp.uuconf_zport != NULL)
+ fprintf (e, "%sservice %s\n", zprefix,
+ qport->uuconf_u.uuconf_stcp.uuconf_zport);
+ break;
+ case UUCONF_PORTTYPE_TLI:
+ {
+ struct uuconf_tli_port *qt;
+
+ qt = &qport->uuconf_u.uuconf_stli;
+ if (qt->uuconf_zdevice != NULL)
+ fprintf (e, "%sdevice %s\n", zprefix, qt->uuconf_zdevice);
+ sprintf (ab, "%sstream", zprefix);
+ uvwrite_boolean (e, qt->uuconf_fstream, ab);
+ if (qt->uuconf_pzpush != NULL)
+ {
+ sprintf (ab, "%spush", zprefix);
+ uvwrite_string_array (e, qt->uuconf_pzpush, ab);
+ }
+ if (qt->uuconf_pzdialer != NULL)
+ {
+ sprintf (ab, "%sdialer-sequence", zprefix);
+ uvwrite_string_array (e, qt->uuconf_pzdialer, ab);
+ }
+ if (qt->uuconf_zservaddr != NULL)
+ fprintf (e, "%sserver-address %s\n", zprefix,
+ qt->uuconf_zservaddr);
+ }
+ break;
+ }
+}
+
+/* Write out a port to the V2 L-devices file. This is called via
+ uuconf_find_port. */
+
+static int
+ivwrite_v2_port (qport, pinfo)
+ struct uuconf_port *qport;
+ pointer pinfo;
+{
+ FILE *e = (FILE *) pinfo;
+
+ if (qport->uuconf_ttype == UUCONF_PORTTYPE_DIRECT)
+ {
+ fprintf (e, "DIR %s - %ld direct",
+ qport->uuconf_u.uuconf_sdirect.uuconf_zdevice,
+ qport->uuconf_u.uuconf_sdirect.uuconf_ibaud);
+ }
+ else if (qport->uuconf_ttype == UUCONF_PORTTYPE_MODEM)
+ {
+ fprintf (e, "%s %s ", qport->uuconf_zname,
+ qport->uuconf_u.uuconf_smodem.uuconf_zdevice);
+ if (qport->uuconf_u.uuconf_smodem.uuconf_zdial_device != NULL)
+ fprintf (e, "%s", qport->uuconf_u.uuconf_smodem.uuconf_zdial_device);
+ else
+ fprintf (e, "-");
+ fprintf (e, " ");
+ if (qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud != 0L)
+ fprintf (e, "%ld-%ld",
+ qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud,
+ qport->uuconf_u.uuconf_smodem.uuconf_ihighbaud);
+ else if (qport->uuconf_u.uuconf_smodem.uuconf_ibaud != 0L)
+ fprintf (e, "%ld", qport->uuconf_u.uuconf_smodem.uuconf_ibaud);
+ else
+ fprintf (e, "Any");
+ if (qport->uuconf_u.uuconf_smodem.uuconf_pzdialer != NULL)
+ fprintf (e, " %s",
+ qport->uuconf_u.uuconf_smodem.uuconf_pzdialer[0]);
+ }
+ else
+ {
+ fprintf (e, "# Ignoring port %s with unsupported type",
+ qport->uuconf_zname);
+ }
+
+ fprintf (e, "\n");
+
+ /* Return UUCONF_NOT_FOUND to force uuconf_find_port to keep looking
+ for a port. */
+ return UUCONF_NOT_FOUND;
+}
+
+/* Write out a port to the HDB Devices file. This is called via
+ uuconf_find_port. */
+
+static int
+ivwrite_hdb_port (qport, pinfo)
+ struct uuconf_port *qport;
+ pointer pinfo;
+{
+ FILE *e = (FILE *) pinfo;
+
+ if (qport->uuconf_ttype == UUCONF_PORTTYPE_DIRECT)
+ {
+ fprintf (e, "Direct");
+ if (qport->uuconf_zprotocols != NULL)
+ fprintf (e, ",%s", qport->uuconf_zprotocols);
+ fprintf (e, " ");
+ if (qport->uuconf_u.uuconf_sdirect.uuconf_zdevice != NULL)
+ fprintf (e, "%s", qport->uuconf_u.uuconf_sdirect.uuconf_zdevice);
+ else
+ fprintf (e, "%s", qport->uuconf_zname);
+ fprintf (e, " - %ld", qport->uuconf_u.uuconf_sdirect.uuconf_ibaud);
+ }
+ else if (qport->uuconf_ttype == UUCONF_PORTTYPE_MODEM)
+ {
+ fprintf (e, "%s", qport->uuconf_zname);
+ if (qport->uuconf_zprotocols != NULL)
+ fprintf (e, ",%s", qport->uuconf_zprotocols);
+ fprintf (e, " ");
+ if (qport->uuconf_u.uuconf_smodem.uuconf_zdevice != NULL)
+ fprintf (e, "%s", qport->uuconf_u.uuconf_smodem.uuconf_zdevice);
+ else
+ fprintf (e, "%s", qport->uuconf_zname);
+ fprintf (e, " ");
+ if (qport->uuconf_u.uuconf_smodem.uuconf_zdial_device != NULL)
+ fprintf (e, "%s", qport->uuconf_u.uuconf_smodem.uuconf_zdial_device);
+ else
+ fprintf (e, "-");
+ fprintf (e, " ");
+ if (qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud != 0L)
+ fprintf (e, "%ld-%ld",
+ qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud,
+ qport->uuconf_u.uuconf_smodem.uuconf_ihighbaud);
+ else if (qport->uuconf_u.uuconf_smodem.uuconf_ibaud != 0L)
+ fprintf (e, "%ld", qport->uuconf_u.uuconf_smodem.uuconf_ibaud);
+ else
+ fprintf (e, "Any");
+ if (qport->uuconf_u.uuconf_smodem.uuconf_pzdialer != NULL)
+ {
+ char **pz;
+
+ for (pz = qport->uuconf_u.uuconf_smodem.uuconf_pzdialer;
+ *pz != NULL;
+ pz++)
+ fprintf (e, " %s", *pz);
+ }
+ }
+ else if (qport->uuconf_ttype == UUCONF_PORTTYPE_TCP)
+ {
+ fprintf (e, "TCP");
+ if (qport->uuconf_zprotocols != NULL)
+ fprintf (e, ",%s", qport->uuconf_zprotocols);
+ fprintf (e, " ");
+ if (qport->uuconf_u.uuconf_stcp.uuconf_zport == NULL)
+ fprintf (e, "uucp");
+ else
+ fprintf (e, "%s", qport->uuconf_u.uuconf_stcp.uuconf_zport);
+ fprintf (e, " - -");
+ }
+ else if (qport->uuconf_ttype == UUCONF_PORTTYPE_TLI)
+ {
+ char **pz;
+
+ fprintf (e, "%s", qport->uuconf_zname);
+ if (qport->uuconf_zprotocols != NULL)
+ fprintf (e, ",%s", qport->uuconf_zprotocols);
+ fprintf (e, " ");
+ if (qport->uuconf_u.uuconf_stli.uuconf_zdevice != NULL)
+ fprintf (e, "%s", qport->uuconf_u.uuconf_smodem.uuconf_zdevice);
+ else
+ fprintf (e, "-");
+ fprintf (e, " - -");
+ pz = qport->uuconf_u.uuconf_stli.uuconf_pzdialer;
+ if (pz == NULL
+ || *pz == NULL
+ || (strcmp (*pz, "TLI") != 0
+ && strcmp (*pz, "TLIS") != 0))
+ fprintf (e, " TLI%s \\D",
+ qport->uuconf_u.uuconf_stli.uuconf_fstream ? "S" : "");
+ if (pz != NULL)
+ for (; *pz != NULL; pz++)
+ fprintf (e, " %s", *pz);
+ }
+ else
+ {
+ fprintf (e, "# Ignoring port %s with unsupported type",
+ qport->uuconf_zname);
+ }
+
+ fprintf (e, "\n");
+
+ /* Return UUCONF_NOT_FOUND to force uuconf_find_port to keep looking
+ for a port. */
+ return UUCONF_NOT_FOUND;
+}
+
+/* Write a dialer out to a Taylor UUCP configuration file. This
+ doesn't output the name, since it is called to output a specially
+ defined dialer in the sys or port file. */
+
+static void
+uvwrite_taylor_dialer (e, qdialer, zprefix)
+ FILE *e;
+ struct uuconf_dialer *qdialer;
+ const char *zprefix;
+{
+ char ab[100];
+
+ /* Reset default values, so we don't output them unnecessarily. */
+ if (qdialer->uuconf_schat.uuconf_ctimeout == 60)
+ qdialer->uuconf_schat.uuconf_ctimeout = -1;
+ if (qdialer->uuconf_schat.uuconf_fstrip)
+ qdialer->uuconf_schat.uuconf_fstrip = -1;
+ if (qdialer->uuconf_scomplete.uuconf_ctimeout == 60)
+ qdialer->uuconf_scomplete.uuconf_ctimeout = -1;
+ if (qdialer->uuconf_scomplete.uuconf_fstrip)
+ qdialer->uuconf_scomplete.uuconf_fstrip = -1;
+ if (qdialer->uuconf_sabort.uuconf_ctimeout == 60)
+ qdialer->uuconf_sabort.uuconf_ctimeout = -1;
+ if (qdialer->uuconf_sabort.uuconf_fstrip)
+ qdialer->uuconf_sabort.uuconf_fstrip = -1;
+
+ uvwrite_chat (e, &qdialer->uuconf_schat, (struct uuconf_chat *) NULL,
+ zprefix, FALSE);
+ if (qdialer->uuconf_zdialtone != NULL
+ && strcmp (qdialer->uuconf_zdialtone, ",") != 0)
+ fprintf (e, "%sdialtone %s\n", zprefix, qdialer->uuconf_zdialtone);
+ if (qdialer->uuconf_zpause != NULL
+ && strcmp (qdialer->uuconf_zpause, ",") != 0)
+ fprintf (e, "%spause %s\n", zprefix, qdialer->uuconf_zpause);
+ if (! qdialer->uuconf_fcarrier)
+ fprintf (e, "%scarrier false\n", zprefix);
+ if (qdialer->uuconf_ccarrier_wait != 60)
+ fprintf (e, "%scarrier-wait %d\n", zprefix,
+ qdialer->uuconf_ccarrier_wait);
+ if (qdialer->uuconf_fdtr_toggle)
+ fprintf (e, "%sdtr-toggle %s %s\n", zprefix,
+ qdialer->uuconf_fdtr_toggle ? "true" : "false",
+ qdialer->uuconf_fdtr_toggle_wait ? "true" : "false");
+ sprintf (ab, "%scomplete-", zprefix);
+ uvwrite_chat (e, &qdialer->uuconf_scomplete, (struct uuconf_chat *) NULL,
+ ab, FALSE);
+ sprintf (ab, "%sabort-", zprefix);
+ uvwrite_chat (e, &qdialer->uuconf_sabort, (struct uuconf_chat *) NULL,
+ ab, FALSE);
+ if (qdialer->uuconf_qproto_params != NULL)
+ uvwrite_proto_params (e, qdialer->uuconf_qproto_params, zprefix);
+ if ((qdialer->uuconf_ireliable & UUCONF_RELIABLE_SPECIFIED) != 0)
+ {
+ sprintf (ab, "%sseven-bit", zprefix);
+ uvwrite_boolean (e,
+ ((qdialer->uuconf_ireliable & UUCONF_RELIABLE_EIGHT)
+ == 0),
+ ab);
+ sprintf (ab, "%sreliable", zprefix);
+ uvwrite_boolean (e,
+ ((qdialer->uuconf_ireliable & UUCONF_RELIABLE_RELIABLE)
+ != 0),
+ ab);
+ sprintf (ab, "%shalf-duplex", zprefix);
+ uvwrite_boolean (e,
+ ((qdialer->uuconf_ireliable
+ & UUCONF_RELIABLE_FULLDUPLEX) == 0),
+ ab);
+ }
+}
+
+/* Write a dialer out to an HDB configuration file. */
+
+static void
+uvwrite_hdb_dialer (e, qdialer)
+ FILE *e;
+ struct uuconf_dialer *qdialer;
+{
+ fprintf (e, "%s ", qdialer->uuconf_zname);
+
+ if (qdialer->uuconf_zdialtone != NULL)
+ fprintf (e, "=%c", qdialer->uuconf_zdialtone[0]);
+ if (qdialer->uuconf_zpause != NULL)
+ fprintf (e, "-%c", qdialer->uuconf_zpause[0]);
+
+ if (qdialer->uuconf_schat.uuconf_pzchat != NULL)
+ {
+ if (qdialer->uuconf_zdialtone == NULL
+ && qdialer->uuconf_zpause == NULL)
+ fprintf (e, "\"\"");
+ fprintf (e, " ");
+ uvwrite_chat_script (e, qdialer->uuconf_schat.uuconf_pzchat);
+ }
+
+ fprintf (e, "\n");
+}
+
+/* Display a uuconf error and exit. */
+
+static void
+uvuuconf_error (puuconf, iret)
+ pointer puuconf;
+ int iret;
+{
+ char ab[512];
+
+ (void) uuconf_error_string (puuconf, iret, ab, sizeof ab);
+ if ((iret & UUCONF_ERROR_FILENAME) == 0)
+ fprintf (stderr, "uuconv: %s\n", ab);
+ else
+ fprintf (stderr, "uuconv:%s\n", ab);
+ if (UUCONF_ERROR_VALUE (iret) != UUCONF_FOPEN_FAILED)
+ exit (EXIT_FAILURE);
+}
diff --git a/gnu/libexec/uucp/uucp/Makefile b/gnu/libexec/uucp/uucp/Makefile
new file mode 100644
index 00000000000..b1160f9d079
--- /dev/null
+++ b/gnu/libexec/uucp/uucp/Makefile
@@ -0,0 +1,15 @@
+# Makefile for uucp
+
+BINDIR= $(bindir)
+BINOWN= $(owner)
+BINMODE= 4555
+
+PROG= uucp
+SRCS= uucp.c util.c log.c copy.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -DVERSION=\"$(VERSION)\"
+
+.include <bsd.prog.mk>
+.PATH: $(.CURDIR)/../common_sources
diff --git a/gnu/libexec/uucp/uucp/uucp.1 b/gnu/libexec/uucp/uucp/uucp.1
new file mode 100644
index 00000000000..0fa81fe6530
--- /dev/null
+++ b/gnu/libexec/uucp/uucp/uucp.1
@@ -0,0 +1,175 @@
+''' $Id: uucp.1,v 1.1 1993/08/04 19:36:43 jtc Exp $
+.TH uucp 1 "Taylor UUCP 1.04"
+.SH NAME
+uucp \- Unix to Unix copy
+.SH SYNOPSIS
+.B uucp
+[ options ] source-file destination-file
+.PP
+.B uucp
+[ options ] source-file... destination-directory
+.SH DESCRIPTION
+The
+.I uucp
+command copies files between systems. Each
+.I file
+argument is either a pathname on the local machine or is of the form
+.IP
+system!path
+.LP
+which is interpreted as being on a remote system.
+In the first form, the contents of the first file are copied to the
+second. In the second form, each source file is copied into the
+destination directory.
+
+A file be transferred to or from
+.I system2
+via
+.I system1
+by using
+.IP
+system1!system2!path.
+.LP
+
+Any pathname that does not begin with / or ~ will be appended to the
+current directory (unless the
+.B \-W
+option is used); this resulting path will not necessarily exist on a
+remote system. A pathname beginning with a simple ~ starts at the
+UUCP public directory; a pathname beginning with ~name starts at the
+home directory of the named user. The ~ is interpreted on the
+appropriate system. Note that some shells will interpret a simple ~
+to the local home directory before
+.I uucp
+sees it; to avoid this the ~ must be quoted.
+
+Shell metacharacters ? * [ ] are interpreted on the appropriate
+system, assuming they are quoted to prevent the shell from
+interpreting them first.
+
+The copy does not take place immediately, but is queued up for the
+.I uucico
+(8) daemon; the daemon is started immediately unless the
+.B \-r
+switch is given. In any case, the next time the remote system is called the
+file(s) will be copied.
+.SH OPTIONS
+The following options may be given to
+.I uucp.
+.TP 5
+.B \-c
+Do not copy local source files to the spool directory. If they are
+removed before being processed by the
+.I uucico
+(8) daemon, the copy will fail. The files must be readable by the
+.I uucico
+(8) daemon, and by the invoking user.
+.TP 5
+.B \-C
+Copy local source files to the spool directory. This is the default.
+.TP 5
+.B \-d
+Create all necessary directories when doing the copy. This is the
+default.
+.TP 5
+.B \-f
+If any necessary directories do not exist for the destination path,
+abort the copy.
+.TP 5
+.B \-g grade
+Set the grade of the file transfer command. Jobs of a higher grade
+are executed first. Grades run 0 ... 9 A ... Z a ... z from high to
+low.
+.TP 5
+.B \-m
+Report completion or failure of the file transfer by
+.I mail
+(1).
+.TP 5
+.B \-n user
+Report completion or failure of the file transfer by
+.I mail
+(1) to the named
+user on the remote system.
+.TP 5
+.B \-r
+Do not start
+.I uucico
+(8) daemon immediately; merely queue up the file transfer for later
+execution.
+.TP 5
+.B \-j
+Print jobid on standard output. The job may be
+later cancelled by passing the jobid to the
+.B \-k
+switch of
+.I uustat
+(1).
+It is possible for some complex operations to produce more than one
+jobid, in which case each will be printed on a separate line. For
+example
+.EX
+uucp sys1!~user1/file1 sys2!~user2/file2 /usr/spool/uucppublic
+.EE
+will generate two separate jobs, one for the system
+.I sys1
+and one for the system
+.I sys2.
+.TP 5
+.B \-W
+Do not prepend remote relative path names with the current directory.
+.TP 5
+.B \-x type
+Turn on particular debugging types. The following types are
+recognized: abnormal, chat, handshake, uucp-proto, proto, port,
+config, spooldir, execute, incoming, outgoing. Only abnormal, config,
+spooldir and execute are meaningful for
+.I uucp.
+
+Multiple types may be given, separated by commas, and the
+.B \-x
+option may appear multiple times. A number may also be given, which
+will turn on that many types from the foregoing list; for example,
+.B \-x 2
+is equivalent to
+.B \-x abnormal,chat.
+.TP 5
+.B \-I file
+Set configuration file to use. This option may not be available,
+depending upon how
+.I uucp
+was compiled.
+.SH FILES
+The file names may be changed at compilation time or by the
+configuration file, so these are only approximations.
+
+.br
+/usr/lib/uucp/config - Configuration file.
+.br
+/usr/spool/uucp -
+UUCP spool directory.
+.br
+/usr/spool/uucp/Log -
+UUCP log file.
+.br
+/usr/spool/uucppublic -
+Default UUCP public directory.
+.SH SEE ALSO
+mail(1), uux(1), uustat(1), uucico(8)
+.SH BUGS
+Some of the options are dependent on the capabilities of the
+.I uucico
+(8) daemon on the remote system.
+
+The
+.I \-n
+and
+.I \-m
+switches do not work when transferring a file from one remote system
+to another.
+
+File modes are not preserved, except for the execute bit. The
+resulting file is owned by the uucp user.
+.SH AUTHOR
+Ian Lance Taylor
+(ian@airs.com or uunet!airs!ian)
diff --git a/gnu/libexec/uucp/uucp/uucp.c b/gnu/libexec/uucp/uucp/uucp.c
new file mode 100644
index 00000000000..93e9ff44849
--- /dev/null
+++ b/gnu/libexec/uucp/uucp/uucp.c
@@ -0,0 +1,1181 @@
+/* uucp.c
+ Prepare to copy a file to or from a remote system.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char uucp_rcsid[] = "$Id: uucp.c,v 1.1 1993/08/04 19:36:44 jtc Exp $";
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+#include "getopt.h"
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+
+/* Local functions. */
+
+static void ucusage P((void));
+static void ucdirfile P((const char *zdir, const char *zfile,
+ pointer pinfo));
+static void uccopy P((const char *zfile, const char *zdest));
+static void ucadd_cmd P((const struct uuconf_system *qsys,
+ const struct scmd *qcmd, const char *zlog));
+static void ucspool_cmds P((boolean fjobid));
+static const char *zcone_system P((boolean *pfany));
+static void ucrecord_file P((const char *zfile));
+static void ucabort P((void));
+
+/* The program name. */
+char abProgram[] = "uucp";
+
+/* Long getopt options. */
+static const struct option asClongopts[] = { { NULL, 0, NULL, 0 } };
+
+/* Local variables. There are a bunch of these, mostly set by the
+ options and the last (the destination) argument. These have file
+ scope so that they may be easily passed into uccopy; they could for
+ the most part also be wrapped up in a structure and passed in. */
+
+/* The uuconf global pointer. */
+static pointer pCuuconf;
+
+/* TRUE if source files should be copied to the spool directory. */
+static boolean fCcopy = TRUE;
+
+/* Grade to use. */
+static char bCgrade = BDEFAULT_UUCP_GRADE;
+
+/* Whether to send mail to the requesting user when the copy is
+ complete. */
+static boolean fCmail = FALSE;
+
+/* User to notify on remote system. */
+static const char *zCnotify = "";
+
+/* TRUE if remote files should be prefixed with the current working
+ directory. */
+static boolean fCexpand = TRUE;
+
+/* TRUE if necessary directories should be created on the destination
+ system. */
+static boolean fCmkdirs = TRUE;
+
+/* Local name. */
+static const char *zClocalname;
+
+/* User name. */
+static const char *zCuser = NULL;
+
+/* TRUE if this is a remote request. */
+static boolean fCremote = FALSE;
+
+/* TRUE if the destination is this system. */
+static boolean fClocaldest;
+
+/* Destination system. */
+static struct uuconf_system sCdestsys;
+
+/* Systems to forward to, if not NULL. */
+static char *zCforward;
+
+/* Options to use when sending a file. */
+static char abCsend_options[20];
+
+/* Options to use when receiving a file. */
+static char abCrec_options[20];
+
+/* TRUE if the current file being copied from is in the cwd. */
+static boolean fCneeds_cwd;
+
+/* The main program. */
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ /* -I: configuration file name. */
+ const char *zconfig = NULL;
+ /* -j: output job id. */
+ boolean fjobid = FALSE;
+ /* -r: don't start uucico when finished. */
+ boolean fuucico = TRUE;
+ /* -R: copy directories recursively. */
+ boolean frecursive = FALSE;
+ /* -s: report status to named file. */
+ const char *zstatus_file = NULL;
+ /* -t: emulate uuto. */
+ boolean fuuto = FALSE;
+ int iopt;
+ pointer puuconf;
+ int iuuconf;
+ int i;
+ boolean fgetcwd;
+ char *zexclam;
+ char *zdestfile;
+ const char *zdestsys;
+ char *zoptions;
+ boolean fexit;
+
+ while ((iopt = getopt_long (argc, argv, "cCdfg:I:jmn:prRs:tu:Wx:",
+ asClongopts, (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 'c':
+ /* Do not copy local files to spool directory. */
+ fCcopy = FALSE;
+ break;
+
+ case 'p':
+ case 'C':
+ /* Copy local files to spool directory. */
+ fCcopy = TRUE;
+ break;
+
+ case 'd':
+ /* Create directories if necessary. */
+ fCmkdirs = TRUE;
+ break;
+
+ case 'f':
+ /* Do not create directories if they don't exist. */
+ fCmkdirs = FALSE;
+ break;
+
+ case 'g':
+ /* Set job grade. */
+ bCgrade = optarg[0];
+ break;
+
+ case 'I':
+ /* Name configuration file. */
+ if (fsysdep_other_config (optarg))
+ zconfig = optarg;
+ break;
+
+ case 'j':
+ /* Output job id. */
+ fjobid = TRUE;
+ break;
+
+ case 'm':
+ /* Mail to requesting user. */
+ fCmail = TRUE;
+ break;
+
+ case 'n':
+ /* Notify remote user. */
+ zCnotify = optarg;
+ break;
+
+ case 'r':
+ /* Don't start uucico when finished. */
+ fuucico = FALSE;
+ break;
+
+ case 'R':
+ /* Copy directories recursively. */
+ frecursive = TRUE;
+ break;
+
+ case 's':
+ /* Report status to named file. */
+ zstatus_file = optarg;
+ break;
+
+ case 't':
+ /* Emulate uuto. */
+ fuuto = TRUE;
+ break;
+
+ case 'u':
+ /* Set user name. */
+ zCuser = optarg;
+ break;
+
+ case 'W':
+ /* Expand only local file names. */
+ fCexpand = FALSE;
+ break;
+
+ case 'x':
+#if DEBUG > 1
+ /* Set debugging level. */
+ iDebug |= idebug_parse (optarg);
+#endif
+ break;
+
+ case 0:
+ /* Long option found and flag set. */
+ break;
+
+ default:
+ ucusage ();
+ break;
+ }
+ }
+
+ if (! UUCONF_GRADE_LEGAL (bCgrade))
+ {
+ ulog (LOG_ERROR, "Ignoring illegal grade");
+ bCgrade = BDEFAULT_UUCP_GRADE;
+ }
+
+ /* The user name must contain a '!', which is treated as a remote
+ name, to avoid spoofing of other users (there is no advantage to
+ spoofing remote users, except to send them random bits of mail,
+ which you can do anyhow). */
+ if (zCuser != NULL)
+ {
+ if (strchr (zCuser, '!') != NULL)
+ fCremote = TRUE;
+ else
+ {
+ ulog (LOG_ERROR, "Ignoring local user name");
+ zCuser = NULL;
+ }
+ }
+
+ if (argc - optind < 2)
+ ucusage ();
+
+ iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ pCuuconf = puuconf;
+
+#if DEBUG > 1
+ {
+ const char *zdebug;
+
+ iuuconf = uuconf_debuglevel (puuconf, &zdebug);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (zdebug != NULL)
+ iDebug |= idebug_parse (zdebug);
+ }
+#endif
+
+ /* See if we are going to need to know the current directory. We
+ just check each argument to see whether it's an absolute
+ pathname. We actually aren't going to need the cwd if fCexpand
+ is FALSE and the file is remote, but so what. */
+ fgetcwd = FALSE;
+ for (i = optind; i < argc; i++)
+ {
+ zexclam = strrchr (argv[i], '!');
+ if (zexclam == NULL)
+ zexclam = argv[i];
+ else
+ ++zexclam;
+ if (fsysdep_needs_cwd (zexclam))
+ {
+ fgetcwd = TRUE;
+ break;
+ }
+ }
+
+#ifdef SIGINT
+ usysdep_signal (SIGINT);
+#endif
+#ifdef SIGHUP
+ usysdep_signal (SIGHUP);
+#endif
+#ifdef SIGQUIT
+ usysdep_signal (SIGQUIT);
+#endif
+#ifdef SIGTERM
+ usysdep_signal (SIGTERM);
+#endif
+#ifdef SIGPIPE
+ usysdep_signal (SIGPIPE);
+#endif
+
+ usysdep_initialize (puuconf, INIT_SUID | (fgetcwd ? INIT_GETCWD : 0));
+
+ ulog_fatal_fn (ucabort);
+
+ if (zCuser == NULL)
+ zCuser = zsysdep_login_name ();
+
+ iuuconf = uuconf_localname (puuconf, &zClocalname);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ zClocalname = zsysdep_localname ();
+ if (zClocalname == NULL)
+ exit (EXIT_FAILURE);
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ /* If we are emulating uuto, translate the destination argument, and
+ notify the destination user. This had better not turn into
+ something that requires the current directory, or we may have
+ passed INIT_GETCWD incorrectly. */
+ if (fuuto)
+ {
+ if (*zCnotify == '\0')
+ {
+ zexclam = strrchr (argv[argc - 1], '!');
+ if (zexclam == NULL)
+ ucusage ();
+ zCnotify = zexclam + 1;
+ }
+ argv[argc - 1] = zsysdep_uuto (argv[argc - 1], zClocalname);
+ if (argv[argc - 1] == NULL)
+ ucusage ();
+ }
+
+ /* Set up the file transfer options. */
+ zoptions = abCsend_options;
+ if (fCcopy)
+ *zoptions++ = 'C';
+ else
+ *zoptions++ = 'c';
+ if (fCmkdirs)
+ *zoptions++ = 'd';
+ else
+ *zoptions++ = 'f';
+ if (fCmail)
+ *zoptions++ = 'm';
+ if (*zCnotify != '\0')
+ *zoptions++ = 'n';
+ *zoptions = '\0';
+
+ zoptions = abCrec_options;
+ if (fCmkdirs)
+ *zoptions++ = 'd';
+ else
+ *zoptions++ = 'f';
+ if (fCmail)
+ *zoptions++ = 'm';
+ *zoptions = '\0';
+
+ zexclam = strchr (argv[argc - 1], '!');
+ if (zexclam == NULL)
+ {
+ zdestsys = zClocalname;
+ zdestfile = argv[argc - 1];
+ fClocaldest = TRUE;
+ }
+ else
+ {
+ size_t clen;
+ char *zcopy;
+
+ clen = zexclam - argv[argc - 1];
+ zcopy = zbufalc (clen + 1);
+ memcpy (zcopy, argv[argc - 1], clen);
+ zcopy[clen] = '\0';
+ zdestsys = zcopy;
+
+ zdestfile = zexclam + 1;
+
+ fClocaldest = FALSE;
+ }
+
+ iuuconf = uuconf_system_info (puuconf, zdestsys, &sCdestsys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf != UUCONF_NOT_FOUND)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (fClocaldest)
+ {
+ iuuconf = uuconf_system_local (puuconf, &sCdestsys);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ sCdestsys.uuconf_zname = (char *) zClocalname;
+ }
+ else
+ {
+ if (! funknown_system (puuconf, zdestsys, &sCdestsys))
+ ulog (LOG_FATAL, "%s: System not found", zdestsys);
+ }
+ }
+
+ /* Here zdestfile is the destination file name following the
+ destination system name (if any); it may contain other systems to
+ forward the files through. Isolate the file from the list of
+ systems. */
+ zexclam = strrchr (zdestfile, '!');
+ if (zexclam == NULL)
+ zCforward = NULL;
+ else
+ {
+ size_t clen;
+
+#if DEBUG > 0
+ if (fClocaldest)
+ ulog (LOG_FATAL, "Can't happen");
+#endif
+ clen = zexclam - zdestfile;
+ zCforward = zbufalc (clen + 1);
+ memcpy (zCforward, zdestfile, clen);
+ zCforward[clen] = '\0';
+ zdestfile = zexclam + 1;
+ }
+
+ /* Turn the destination into an absolute path, unless it is on a
+ remote system and -W was used. */
+ if (fClocaldest)
+ zdestfile = zsysdep_local_file_cwd (zdestfile, sCdestsys.uuconf_zpubdir);
+ else if (fCexpand)
+ zdestfile = zsysdep_add_cwd (zdestfile);
+ if (zdestfile == NULL)
+ {
+ ulog_close ();
+ usysdep_exit (FALSE);
+ }
+
+ /* Process each source argument. */
+ for (i = optind; i < argc - 1 && ! FGOT_SIGNAL (); i++)
+ {
+ boolean flocal;
+ char *zfrom;
+
+ fCneeds_cwd = FALSE;
+
+ if (strchr (argv[i], '!') != NULL)
+ {
+ flocal = FALSE;
+ zfrom = zbufcpy (argv[i]);
+ }
+ else
+ {
+ /* This is a local file. Make sure we get it out of the
+ original directory. We don't support local wildcards,
+ leaving that to the shell. */
+ flocal = TRUE;
+ if (fsysdep_needs_cwd (argv[i]))
+ fCneeds_cwd = TRUE;
+ zfrom = zsysdep_local_file_cwd (argv[i],
+ sCdestsys.uuconf_zpubdir);
+ if (zfrom == NULL)
+ ucabort ();
+ }
+
+ if (! flocal || ! fsysdep_directory (zfrom))
+ uccopy (zfrom, zdestfile);
+ else
+ {
+ char *zbase, *zindir;
+
+ if (! frecursive)
+ ulog (LOG_FATAL, "%s: directory without -R", zfrom);
+
+ zbase = zsysdep_base_name (zfrom);
+ if (zbase == NULL)
+ ucabort ();
+ zindir = zsysdep_in_dir (zdestfile, zbase);
+ ubuffree (zbase);
+ if (zindir == NULL)
+ ucabort ();
+ usysdep_walk_tree (zfrom, ucdirfile, zindir);
+ ubuffree (zindir);
+ }
+
+ ubuffree (zfrom);
+ }
+
+ /* See if we got an interrupt, presumably from the user. */
+ if (FGOT_SIGNAL ())
+ ucabort ();
+
+ /* Now push out the actual commands, making log entries for them. */
+ ulog_to_file (puuconf, TRUE);
+ ulog_user (zCuser);
+
+ ucspool_cmds (fjobid);
+
+ ulog_close ();
+
+ if (! fuucico)
+ fexit = TRUE;
+ else
+ {
+ const char *zsys;
+ boolean fany;
+
+ zsys = zcone_system (&fany);
+ if (zsys != NULL)
+ fexit = fsysdep_run ("uucico", "-s", zsys);
+ else if (fany)
+ fexit = fsysdep_run ("uucico", "-r1", (const char *) NULL);
+ else
+ fexit = TRUE;
+ }
+
+ usysdep_exit (fexit);
+
+ /* Avoid error about not returning. */
+ return 0;
+}
+
+static void
+ucusage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uucp [options] file1 [file2 ...] dest\n");
+ fprintf (stderr,
+ " -c: Do not copy local files to spool directory\n");
+ fprintf (stderr,
+ " -C, -p: Copy local files to spool directory (default)\n");
+ fprintf (stderr,
+ " -d: Create necessary directories (default)\n");
+ fprintf (stderr,
+ " -f: Do not create directories (fail if they do not exist)\n");
+ fprintf (stderr,
+ " -g grade: Set job grade (must be alphabetic)\n");
+ fprintf (stderr,
+ " -m: Report status of copy by mail\n");
+ fprintf (stderr,
+ " -n user: Report status of copy by mail to remote user\n");
+ fprintf (stderr,
+ " -R: Copy directories recursively\n");
+ fprintf (stderr,
+ " -r: Do not start uucico daemon\n");
+ fprintf (stderr,
+ " -s file: Report completion status to file\n");
+ fprintf (stderr,
+ " -j: Report job id\n");
+ fprintf (stderr,
+ " -W: Do not add current directory to remote filenames\n");
+ fprintf (stderr,
+ " -t: Emulate uuto\n");
+ fprintf (stderr,
+ " -u name: Set user name\n");
+ fprintf (stderr,
+ " -x debug: Set debugging level\n");
+#if HAVE_TAYLOR_CONFIG
+ fprintf (stderr,
+ " -I file: Set configuration file to use\n");
+#endif /* HAVE_TAYLOR_CONFIG */
+ exit (EXIT_FAILURE);
+}
+
+/* This is called for each file in a directory heirarchy. */
+
+static void
+ucdirfile (zfull, zrelative, pinfo)
+ const char *zfull;
+ const char *zrelative;
+ pointer pinfo;
+{
+ const char *zdestfile = (const char *) pinfo;
+ char *zto;
+
+ zto = zsysdep_in_dir (zdestfile, zrelative);
+ if (zto == NULL)
+ ucabort ();
+
+ uccopy (zfull, zto);
+
+ ubuffree (zto);
+}
+
+/* Handle the copying of one regular file. The zdest argument is the
+ destination file; if we are recursively copying a directory, it
+ will be extended by any subdirectory names. Note that zdest is an
+ absolute path. */
+
+static void
+uccopy (zfile, zdest)
+ const char *zfile;
+ const char *zdest;
+{
+ struct scmd s;
+ char *zexclam;
+ char *zto;
+
+ zexclam = strchr (zfile, '!');
+
+ if (zexclam == NULL)
+ {
+ openfile_t efrom;
+
+ /* Copy from a local file. Make sure the user has access to
+ this file, since we are running setuid. */
+ if (! fsysdep_access (zfile))
+ ucabort ();
+
+ /* If this copy is being requested by a remote system, we may
+ transfer the file if it needs the current working directory
+ (meaning, I hope, that it is in the execution directory) or
+ it is on the permitted transfer list. Note that unlike most
+ of the other checks, this one is not double-checked by
+ uucico. */
+ if (fCremote
+ && ! fCneeds_cwd
+ && ! fin_directory_list (zfile, sCdestsys.uuconf_pzremote_send,
+ sCdestsys.uuconf_zpubdir, TRUE,
+ TRUE, (const char *) NULL))
+ ulog (LOG_FATAL, "Not permitted to send %s", zfile);
+
+ if (fClocaldest)
+ {
+ boolean fok;
+
+ /* Copy one local file to another. */
+
+ /* Check that we have permission to receive into the desired
+ directory. */
+ if (fCremote)
+ fok = fin_directory_list (zdest,
+ sCdestsys.uuconf_pzremote_receive,
+ sCdestsys.uuconf_zpubdir, TRUE,
+ FALSE, (const char *) NULL);
+ else
+ fok = fin_directory_list (zdest,
+ sCdestsys.uuconf_pzlocal_receive,
+ sCdestsys.uuconf_zpubdir, TRUE,
+ FALSE, zCuser);
+ if (! fok)
+ ulog (LOG_FATAL, "Not permitted to receive to %s", zdest);
+
+ zto = zsysdep_add_base (zdest, zfile);
+ if (zto == NULL)
+ ucabort ();
+
+ efrom = esysdep_user_fopen (zfile, TRUE, TRUE);
+ if (! ffileisopen (efrom))
+ ucabort ();
+ if (! fcopy_open_file (efrom, zto, FALSE, fCmkdirs))
+ ucabort ();
+ (void) ffileclose (efrom);
+ ubuffree (zto);
+ }
+ else
+ {
+ const char *zloc;
+ char abtname[CFILE_NAME_LEN];
+ unsigned int imode;
+ char *ztemp;
+
+ /* Copy a local file to a remote file. We may have to
+ copy the local file to the spool directory. */
+ imode = ixsysdep_file_mode (zfile);
+ if (imode == 0)
+ ucabort ();
+
+ zloc = sCdestsys.uuconf_zlocalname;
+ if (zloc == NULL)
+ zloc = zClocalname;
+
+ ztemp = zsysdep_data_file_name (&sCdestsys, zloc, bCgrade,
+ FALSE, abtname, (char *) NULL,
+ (char *) NULL);
+ if (ztemp == NULL)
+ ucabort ();
+
+ if (! fCcopy)
+ {
+ /* If we are copying the file, we don't actually use the
+ temporary file; we still want to get a name for the
+ other system to use as a key for file restart. */
+ ubuffree (ztemp);
+
+ /* Make sure the daemon will be permitted to send
+ this file. */
+ if (! fsysdep_daemon_access (zfile))
+ ucabort ();
+ if (! fin_directory_list (zfile, sCdestsys.uuconf_pzlocal_send,
+ sCdestsys.uuconf_zpubdir, TRUE, TRUE,
+ (fCremote
+ ? (const char *) NULL
+ : zCuser)))
+ ulog (LOG_FATAL, "Not permitted to send %s", zfile);
+ }
+ else
+ {
+ efrom = esysdep_user_fopen (zfile, TRUE, TRUE);
+ if (! ffileisopen (efrom))
+ ucabort ();
+ ucrecord_file (ztemp);
+ if (! fcopy_open_file (efrom, ztemp, FALSE, TRUE))
+ ucabort ();
+ (void) ffileclose (efrom);
+ }
+
+ if (zCforward == NULL)
+ {
+ /* We're not forwarding. Just send the file. */
+ s.bcmd = 'S';
+ s.pseq = NULL;
+ s.zfrom = zbufcpy (zfile);
+ s.zto = zbufcpy (zdest);
+ s.zuser = zCuser;
+ s.zoptions = abCsend_options;
+ s.ztemp = zbufcpy (abtname);
+ s.imode = imode;
+ s.znotify = zCnotify;
+ s.cbytes = -1;
+ s.zcmd = NULL;
+ s.ipos = 0;
+
+ ucadd_cmd (&sCdestsys, &s, (const char *) NULL);
+ }
+ else
+ {
+ char *zbase;
+ char *zxqt;
+ char abxtname[CFILE_NAME_LEN];
+ char abdname[CFILE_NAME_LEN];
+ char abxname[CFILE_NAME_LEN];
+ FILE *e;
+ char *zlog;
+
+ /* We want to forward this file through sCdestsys to
+ some other system(s). We set up a remote execution
+ of uucp on sCdestsys to forward the file along. */
+ zbase = zsysdep_base_name (zfile);
+ if (zbase == NULL)
+ ucabort ();
+
+ zxqt = zsysdep_data_file_name (&sCdestsys, zloc, bCgrade,
+ TRUE, abxtname, abdname,
+ abxname);
+ if (zxqt == NULL)
+ ucabort ();
+ e = esysdep_fopen (zxqt, FALSE, FALSE, TRUE);
+ if (e == NULL)
+ ucabort ();
+ ucrecord_file (zxqt);
+
+ fprintf (e, "U %s %s\n", zCuser, zloc);
+ fprintf (e, "F %s %s\n", abdname, zbase);
+ fprintf (e, "C uucp -C");
+ if (fCmkdirs)
+ fprintf (e, " -d");
+ else
+ fprintf (e, " -f");
+ fprintf (e, " -g %c", bCgrade);
+ if (fCmail)
+ fprintf (e, " -m");
+ if (*zCnotify != '\0')
+ fprintf (e, " -n %s", zCnotify);
+ if (! fCexpand)
+ fprintf (e, " -W");
+ fprintf (e, " %s %s!%s\n", zbase, zCforward, zdest);
+
+ ubuffree (zbase);
+
+ if (fclose (e) != 0)
+ ulog (LOG_FATAL, "fclose: %s", strerror (errno));
+
+ /* Send the execution file. */
+ s.bcmd = 'S';
+ s.pseq = NULL;
+ s.zfrom = zbufcpy (abxtname);
+ s.zto = zbufcpy (abxname);
+ s.zuser = zCuser;
+ s.zoptions = "C";
+ s.ztemp = s.zfrom;
+ s.imode = 0666;
+ s.znotify = NULL;
+ s.cbytes = -1;
+ s.zcmd = NULL;
+ s.ipos = 0;
+
+ zlog = zbufalc (sizeof "Queuing uucp !" + strlen (zfile)
+ + strlen (zCforward) + strlen (zdest));
+ sprintf (zlog, "Queuing uucp %s %s!%s", zfile, zCforward,
+ zdest);
+
+ ucadd_cmd (&sCdestsys, &s, zlog);
+
+ /* Send the data file. */
+ s.bcmd = 'S';
+ s.pseq = NULL;
+ s.zfrom = zbufcpy (zfile);
+ s.zto = zbufcpy (abdname);
+ s.zuser = zCuser;
+ s.zoptions = fCcopy ? "C" : "c";
+ s.ztemp = zbufcpy (abtname);
+ s.imode = 0666;
+ s.znotify = NULL;
+ s.cbytes = -1;
+ s.zcmd = NULL;
+ s.ipos = 0;
+
+ ucadd_cmd (&sCdestsys, &s, "");
+ }
+ }
+ }
+ else
+ {
+ char *zfrom;
+ char *zforward;
+ size_t clen;
+ char *zcopy;
+ struct uuconf_system *qfromsys;
+ int iuuconf;
+ const char *zloc;
+
+ /* Copy from a remote file. Get the file name after any systems
+ we may need to forward the file from. */
+ zfrom = strrchr (zfile, '!');
+ if (zfrom == zexclam)
+ zforward = NULL;
+ else
+ {
+ clen = zfrom - zexclam - 1;
+ zforward = zbufalc (clen + 1);
+ memcpy (zforward, zexclam + 1, clen);
+ }
+
+ ++zfrom;
+ if (fCexpand)
+ {
+ /* Add the current directory to the filename if it's not
+ already there. */
+ zfrom = zsysdep_add_cwd (zfrom);
+ if (zfrom == NULL)
+ ucabort ();
+ }
+
+ /* Read the system information. */
+ clen = zexclam - zfile;
+ zcopy = zbufalc (clen + 1);
+ memcpy (zcopy, zfile, clen);
+ zcopy[clen] = '\0';
+
+ qfromsys = ((struct uuconf_system *)
+ xmalloc (sizeof (struct uuconf_system)));
+
+ iuuconf = uuconf_system_info (pCuuconf, zcopy, qfromsys);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ if (! funknown_system (pCuuconf, zcopy, qfromsys))
+ ulog (LOG_FATAL, "%s: System not found", zcopy);
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, pCuuconf, iuuconf);
+ ubuffree (zcopy);
+
+ zloc = qfromsys->uuconf_zlocalname;
+ if (zloc == NULL)
+ zloc = zClocalname;
+
+ if (zforward == NULL && fClocaldest)
+ {
+ boolean fok;
+
+ /* The file is to come directly from qfromsys to the local
+ system. */
+
+ /* Check that we have permission to receive into the desired
+ directory. If we don't have permission, uucico will
+ fail. */
+ if (fCremote)
+ fok = fin_directory_list (zdest,
+ qfromsys->uuconf_pzremote_receive,
+ qfromsys->uuconf_zpubdir, TRUE,
+ FALSE, (const char *) NULL);
+ else
+ fok = fin_directory_list (zdest,
+ qfromsys->uuconf_pzlocal_receive,
+ qfromsys->uuconf_zpubdir, TRUE,
+ FALSE, zCuser);
+ if (! fok)
+ ulog (LOG_FATAL, "Not permitted to receive to %s", zdest);
+
+ /* If the remote filespec is wildcarded, we must generate an
+ 'X' request. We currently check for Unix shell
+ wildcards. Note that it should do no harm to mistake a
+ non-wildcard for a wildcard. */
+ if (zfrom[strcspn (zfrom, "*?[")] != '\0')
+ {
+ s.bcmd = 'X';
+ zto = zbufalc (strlen (zloc) + strlen (zdest) + sizeof "!");
+ sprintf (zto, "%s!%s", zloc, zdest);
+ }
+ else
+ {
+ s.bcmd = 'R';
+ zto = zbufcpy (zdest);
+ }
+
+ s.pseq = NULL;
+ s.zfrom = zfrom;
+ s.zto = zto;
+ s.zuser = zCuser;
+ s.zoptions = abCrec_options;
+ s.ztemp = "";
+ s.imode = 0;
+ s.znotify = "";
+ s.cbytes = -1;
+ s.zcmd = NULL;
+ s.ipos = 0;
+
+ ucadd_cmd (qfromsys, &s, (const char *) NULL);
+ }
+ else
+ {
+ char *zxqt;
+ char abtname[CFILE_NAME_LEN];
+ char abxname[CFILE_NAME_LEN];
+ FILE *e;
+ char *zcmd;
+ char *zlog;
+
+ /* The file either comes from some other system through
+ qfromsys or is intended for some other system. Send an
+ execution request to qfromsys to handle everything. */
+ zxqt = zsysdep_data_file_name (qfromsys, zloc, bCgrade, TRUE,
+ abtname, (char *) NULL,
+ abxname);
+ if (zxqt == NULL)
+ ucabort ();
+ e = esysdep_fopen (zxqt, FALSE, FALSE, TRUE);
+ if (e == NULL)
+ ucabort ();
+ ucrecord_file (zxqt);
+
+ fprintf (e, "U %s %s\n", zCuser, zloc);
+ fprintf (e, "C uucp -C");
+ if (fCmkdirs)
+ fprintf (e, " -d");
+ else
+ fprintf (e, " -f");
+ fprintf (e, " -g %c", bCgrade);
+ if (fCmail)
+ fprintf (e, " -m");
+ if (*zCnotify != '\0')
+ fprintf (e, " -n %s", zCnotify);
+ if (! fCexpand)
+ fprintf (e, " -W");
+
+ clen = (strlen (zfrom) + strlen (zloc)
+ + strlen (sCdestsys.uuconf_zname) + strlen (zdest));
+ if (zforward != NULL)
+ clen += strlen (zforward);
+ if (zCforward != NULL)
+ clen += strlen (zCforward);
+ zcmd = zbufalc (sizeof "! !!!" + clen);
+ *zcmd = '\0';
+ if (zforward != NULL)
+ sprintf (zcmd + strlen (zcmd), "%s!", zforward);
+ sprintf (zcmd + strlen (zcmd), "%s %s!", zfrom, zloc);
+ if (! fClocaldest)
+ sprintf (zcmd + strlen (zcmd), "%s!", sCdestsys.uuconf_zname);
+ if (zCforward != NULL)
+ sprintf (zcmd + strlen (zcmd), "%s!", zCforward);
+ sprintf (zcmd + strlen (zcmd), "%s", zdest);
+
+ fprintf (e, " %s\n", zcmd);
+
+ if (fclose (e) != 0)
+ ulog (LOG_FATAL, "fclose: %s", strerror (errno));
+
+ /* Send the execution file. */
+ s.bcmd = 'S';
+ s.pseq = NULL;
+ s.zfrom = zbufcpy (abtname);
+ s.zto = zbufcpy (abxname);
+ s.zuser = zCuser;
+ s.zoptions = "C";
+ s.ztemp = s.zfrom;
+ s.imode = 0666;
+ s.znotify = NULL;
+ s.cbytes = -1;
+ s.zcmd = NULL;
+ s.ipos = 0;
+
+ zlog = zbufalc (sizeof "Queueing uucp " + strlen (zcmd));
+ sprintf (zlog, "Queueing uucp %s", zcmd);
+
+ ucadd_cmd (qfromsys, &s, zlog);
+
+ ubuffree (zcmd);
+ ubuffree (zforward);
+ }
+ }
+}
+
+/* We keep a list of jobs for each system. */
+
+struct sjob
+{
+ struct sjob *qnext;
+ const struct uuconf_system *qsys;
+ int ccmds;
+ struct scmd *pascmds;
+ const char **pazlogs;
+};
+
+static struct sjob *qCjobs;
+
+static void
+ucadd_cmd (qsys, qcmd, zlog)
+ const struct uuconf_system *qsys;
+ const struct scmd *qcmd;
+ const char *zlog;
+{
+ struct sjob *qjob;
+
+ if (! qsys->uuconf_fcall_transfer
+ && ! qsys->uuconf_fcalled_transfer)
+ ulog (LOG_FATAL, "Not permitted to transfer files to or from %s",
+ qsys->uuconf_zname);
+
+ for (qjob = qCjobs; qjob != NULL; qjob = qjob->qnext)
+ if (strcmp (qjob->qsys->uuconf_zname, qsys->uuconf_zname) == 0)
+ break;
+
+ if (qjob == NULL)
+ {
+ qjob = (struct sjob *) xmalloc (sizeof (struct sjob));
+ qjob->qnext = qCjobs;
+ qjob->qsys = qsys;
+ qjob->ccmds = 0;
+ qjob->pascmds = NULL;
+ qjob->pazlogs = NULL;
+ qCjobs = qjob;
+ }
+
+ qjob->pascmds = ((struct scmd *)
+ xrealloc ((pointer) qjob->pascmds,
+ (qjob->ccmds + 1) * sizeof (struct scmd)));
+ qjob->pascmds[qjob->ccmds] = *qcmd;
+ qjob->pazlogs = ((const char **)
+ xrealloc ((pointer) qjob->pazlogs,
+ (qjob->ccmds + 1) * sizeof (const char *)));
+ qjob->pazlogs[qjob->ccmds] = zlog;
+ ++qjob->ccmds;
+}
+
+static void
+ucspool_cmds (fjobid)
+ boolean fjobid;
+{
+ struct sjob *qjob;
+ char *zjobid;
+
+ for (qjob = qCjobs; qjob != NULL; qjob = qjob->qnext)
+ {
+ ulog_system (qjob->qsys->uuconf_zname);
+ zjobid = zsysdep_spool_commands (qjob->qsys, bCgrade, qjob->ccmds,
+ qjob->pascmds);
+ if (zjobid != NULL)
+ {
+ int i;
+ struct scmd *qcmd;
+ const char **pz;
+
+ for (i = 0, qcmd = qjob->pascmds, pz = qjob->pazlogs;
+ i < qjob->ccmds;
+ i++, qcmd++, pz++)
+ {
+ if (*pz != NULL)
+ {
+ if (**pz != '\0')
+ ulog (LOG_NORMAL, "%s", *pz);
+ }
+ else if (qcmd->bcmd == 'S')
+ ulog (LOG_NORMAL, "Queuing send of %s to %s",
+ qcmd->zfrom, qcmd->zto);
+ else if (qcmd->bcmd == 'R')
+ ulog (LOG_NORMAL, "Queuing request of %s to %s",
+ qcmd->zfrom, qcmd->zto);
+ else
+ {
+ const char *zto;
+
+ zto = strrchr (qcmd->zto, '!');
+ if (zto != NULL)
+ ++zto;
+ else
+ zto = qcmd->zto;
+ ulog (LOG_NORMAL, "Queuing request of %s to %s",
+ qcmd->zfrom, zto);
+ }
+ }
+
+ if (fjobid)
+ printf ("%s\n", zjobid);
+
+ ubuffree (zjobid);
+ }
+ }
+}
+
+/* Return the system name for which we have created commands, or NULL
+ if we've created commands for more than one system. Set *pfany to
+ FALSE if we didn't create work for any system. */
+
+static const char *
+zcone_system (pfany)
+ boolean *pfany;
+{
+ if (qCjobs == NULL)
+ {
+ *pfany = FALSE;
+ return NULL;
+ }
+
+ *pfany = TRUE;
+
+ if (qCjobs->qnext == NULL)
+ return qCjobs->qsys->uuconf_zname;
+ else
+ return NULL;
+}
+
+/* Keep track of all files we have created so that we can delete them
+ if we get a signal. The argument will be on the heap. */
+
+static int cCfiles;
+static const char **pCaz;
+
+static void
+ucrecord_file (zfile)
+ const char *zfile;
+{
+ pCaz = (const char **) xrealloc ((pointer) pCaz,
+ (cCfiles + 1) * sizeof (const char *));
+ pCaz[cCfiles] = zfile;
+ ++cCfiles;
+}
+
+/* Delete all the files we have recorded and exit. */
+
+static void
+ucabort ()
+{
+ int i;
+
+ for (i = 0; i < cCfiles; i++)
+ (void) remove (pCaz[i]);
+ ulog_close ();
+ usysdep_exit (FALSE);
+}
diff --git a/gnu/libexec/uucp/uulog/Makefile b/gnu/libexec/uucp/uulog/Makefile
new file mode 100644
index 00000000000..aa966b0c285
--- /dev/null
+++ b/gnu/libexec/uucp/uulog/Makefile
@@ -0,0 +1,15 @@
+# Makefile for uulog
+
+BINDIR= $(bindir)
+
+PROG= uulog
+SRCS= uulog.c log.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -DVERSION=\"$(VERSION)\"
+
+NOMAN= noman
+
+.include <bsd.prog.mk>
+.PATH: $(.CURDIR)/../common_sources
diff --git a/gnu/libexec/uucp/uulog/uulog.c b/gnu/libexec/uucp/uulog/uulog.c
new file mode 100644
index 00000000000..9a58fffeb22
--- /dev/null
+++ b/gnu/libexec/uucp/uulog/uulog.c
@@ -0,0 +1,444 @@
+/* uulog.c
+ Display the UUCP log file.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char uulog_rcsid[] = "$Id: uulog.c,v 1.1 1993/08/04 19:36:47 jtc Exp $";
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+#include "getopt.h"
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+
+/* This is a pretty bad implementation of uulog, which I don't think
+ is a very useful program anyhow. It only takes a single -s and/or
+ -u switch. When using HAVE_HDB_LOGGING it requires a system. */
+
+/* The program name. */
+char abProgram[] = "uulog";
+
+/* Local functions. */
+
+static void ulusage P((void));
+
+/* Long getopt options. */
+static const struct option asLlongopts[] = { { NULL, 0, NULL, 0 } };
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ /* -D: display Debug file */
+ boolean fdebug = FALSE;
+ /* -f: keep displaying lines forever. */
+ boolean fforever = FALSE;
+ /* -n lines: number of lines to display. */
+ int cshow = 0;
+ /* -s: system name. */
+ const char *zsystem = NULL;
+ /* -S: display Stats file */
+ boolean fstats = FALSE;
+ /* -u: user name. */
+ const char *zuser = NULL;
+ /* -I: configuration file name. */
+ const char *zconfig = NULL;
+ /* -x: display uuxqt log file. */
+ boolean fuuxqt = FALSE;
+ int i;
+ int iopt;
+ pointer puuconf;
+ int iuuconf;
+ const char *zlogfile;
+ const char *zstatsfile;
+ const char *zdebugfile;
+ const char *zfile;
+ FILE *e;
+ char **pzshow = NULL;
+ int ishow = 0;
+ size_t csystem = 0;
+ size_t cuser = 0;
+ char *zline;
+ size_t cline;
+
+ /* Look for a straight number argument, and convert it to -n before
+ passing the arguments to getopt. */
+ for (i = 0; i < argc; i++)
+ {
+ if (argv[i][0] == '-' && isdigit (argv[i][1]))
+ {
+ size_t clen;
+ char *znew;
+
+ clen = strlen (argv[i]);
+ znew = zbufalc (clen + 2);
+ znew[0] = '-';
+ znew[1] = 'n';
+ memcpy (znew + 2, argv[i] + 1, clen);
+ argv[i] = znew;
+ }
+ }
+
+ while ((iopt = getopt_long (argc, argv, "Df:FI:n:s:Su:xX:", asLlongopts,
+ (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 'D':
+ /* Show debugging file. */
+ fdebug = TRUE;
+ break;
+
+ case 'f':
+ /* Keep displaying lines forever for a particular system. */
+ fforever = TRUE;
+ zsystem = optarg;
+ if (cshow == 0)
+ cshow = 10;
+ break;
+
+ case 'F':
+ /* Keep displaying lines forever. */
+ fforever = TRUE;
+ if (cshow == 0)
+ cshow = 10;
+ break;
+
+ case 'I':
+ /* Configuration file name. */
+ if (fsysdep_other_config (optarg))
+ zconfig = optarg;
+ break;
+
+ case 'n':
+ /* Number of lines to display. */
+ cshow = (int) strtol (optarg, (char **) NULL, 10);
+ break;
+
+ case 's':
+ /* System name. */
+ zsystem = optarg;
+ break;
+
+ case 'S':
+ /* Show statistics file. */
+ fstats = TRUE;
+ break;
+
+ case 'u':
+ /* User name. */
+ zuser = optarg;
+ break;
+
+ case 'x':
+ /* Display uuxqt log file. */
+ fuuxqt = TRUE;
+ break;
+
+ case 'X':
+#if DEBUG > 1
+ /* Set debugging level. */
+ iDebug |= idebug_parse (optarg);
+#endif
+ break;
+
+ case 0:
+ /* Long option found and flag set. */
+ break;
+
+ default:
+ ulusage ();
+ break;
+ }
+ }
+
+ if (optind != argc || (fstats && fdebug))
+ ulusage ();
+
+ iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+#if DEBUG > 1
+ {
+ const char *zdebug;
+
+ iuuconf = uuconf_debuglevel (puuconf, &zdebug);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (zdebug != NULL)
+ iDebug |= idebug_parse (zdebug);
+ }
+#endif
+
+ iuuconf = uuconf_logfile (puuconf, &zlogfile);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ iuuconf = uuconf_statsfile (puuconf, &zstatsfile);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ iuuconf = uuconf_debugfile (puuconf, &zdebugfile);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ usysdep_initialize (puuconf, 0);
+
+ if (zsystem != NULL)
+ {
+#if HAVE_HDB_LOGGING
+ if (strcmp (zsystem, "ANY") != 0)
+#endif
+ {
+ struct uuconf_system ssys;
+
+ iuuconf = uuconf_system_info (puuconf, zsystem, &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf != UUCONF_NOT_FOUND)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ ulog (LOG_FATAL, "%s: System not found", zsystem);
+ }
+ zsystem = zbufcpy (ssys.uuconf_zname);
+ (void) uuconf_system_free (puuconf, &ssys);
+ }
+ }
+
+ if (fstats)
+ zfile = zstatsfile;
+ else if (fdebug)
+ zfile = zdebugfile;
+ else
+ {
+#if ! HAVE_HDB_LOGGING
+ zfile = zlogfile;
+#else
+ const char *zprogram;
+ char *zalc;
+
+ /* We need a system to find a HDB log file. */
+ if (zsystem == NULL)
+ ulusage ();
+
+ if (fuuxqt)
+ zprogram = "uuxqt";
+ else
+ zprogram = "uucico";
+
+ zalc = zbufalc (strlen (zlogfile)
+ + strlen (zprogram)
+ + strlen (zsystem)
+ + 1);
+ sprintf (zalc, zlogfile, zprogram, zsystem);
+ zfile = zalc;
+
+ if (strcmp (zsystem, "ANY") == 0)
+ zsystem = NULL;
+#endif
+ }
+
+ e = fopen (zfile, "r");
+ if (e == NULL)
+ {
+ ulog (LOG_ERROR, "fopen (%s): %s", zfile, strerror (errno));
+ usysdep_exit (FALSE);
+ }
+
+ if (cshow > 0)
+ {
+ pzshow = (char **) xmalloc (cshow * sizeof (char *));
+ for (ishow = 0; ishow < cshow; ishow++)
+ pzshow[ishow] = NULL;
+ ishow = 0;
+ }
+
+ /* Read the log file and output the appropriate lines. */
+ if (zsystem != NULL)
+ csystem = strlen (zsystem);
+
+ if (zuser != NULL)
+ cuser = strlen (zuser);
+
+ zline = NULL;
+ cline = 0;
+
+ while (TRUE)
+ {
+ while (getline (&zline, &cline, e) > 0)
+ {
+ char *zluser, *zlsys, *znext;
+ size_t cluser, clsys;
+
+ /* Skip any leading whitespace (not that there should be
+ any). */
+ znext = zline + strspn (zline, " \t");
+
+ if (! fstats)
+ {
+#if ! HAVE_TAYLOR_LOGGING
+ /* The user name is the first field on the line. */
+ zluser = znext;
+ cluser = strcspn (znext, " \t");
+#endif
+
+ /* Skip the first field. */
+ znext += strcspn (znext, " \t");
+ znext += strspn (znext, " \t");
+
+ /* The system is the second field on the line. */
+ zlsys = znext;
+ clsys = strcspn (znext, " \t");
+
+ /* Skip the second field. */
+ znext += clsys;
+ znext += strspn (znext, " \t");
+
+#if HAVE_TAYLOR_LOGGING
+ /* The user is the third field on the line. */
+ zluser = znext;
+ cluser = strcspn (znext, " \t");
+#endif
+ }
+ else
+ {
+#if ! HAVE_HDB_LOGGING
+ /* The user name is the first field on the line, and the
+ system name is the second. */
+ zluser = znext;
+ cluser = strcspn (znext, " \t");
+ znext += cluser;
+ znext += strspn (znext, " \t");
+ zlsys = znext;
+ clsys = strcspn (znext, " \t");
+#else
+ /* The first field is system!user. */
+ zlsys = znext;
+ clsys = strcspn (znext, "!");
+ znext += clsys + 1;
+ zlsys = znext;
+ clsys = strcspn (znext, " \t");
+#endif
+ }
+
+ /* See if we should print this line. */
+ if (zsystem != NULL
+ && (csystem != clsys
+ || strncmp (zsystem, zlsys, clsys) != 0))
+ continue;
+
+ if (zuser != NULL
+ && (cuser != cluser
+ || strncmp (zuser, zluser, cluser) != 0))
+ continue;
+
+ /* Output the line, or save it if we are outputting only a
+ particular number of lines. */
+ if (cshow <= 0)
+ printf ("%s", zline);
+ else
+ {
+ ubuffree ((pointer) pzshow[ishow]);
+ pzshow[ishow] = zbufcpy (zline);
+ ishow = (ishow + 1) % cshow;
+ }
+ }
+
+ /* Output the number of lines requested by the -n option. */
+ if (cshow > 0)
+ {
+ for (i = 0; i < cshow; i++)
+ {
+ if (pzshow[ishow] != NULL)
+ printf ("%s", pzshow[ishow]);
+ ishow = (ishow + 1) % cshow;
+ }
+ }
+
+ /* If -f was not specified, or an error occurred while reading
+ the file, get out. */
+ if (! fforever || ferror (e))
+ break;
+
+ clearerr (e);
+ cshow = 0;
+
+ /* Sleep 1 second before going around the loop again. */
+ usysdep_sleep (1);
+ }
+
+ (void) fclose (e);
+
+ ulog_close ();
+
+ usysdep_exit (TRUE);
+
+ /* Avoid errors about not returning a value. */
+ return 0;
+}
+
+/* Print a usage message and die. */
+
+static void
+ulusage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uulog [-n #] [-sf system] [-u user] [-xDSF] [-I file] [-X debug]\n");
+ fprintf (stderr,
+ " -n: show given number of lines from end of log\n");
+ fprintf (stderr,
+ " -s: print entries for named system\n");
+ fprintf (stderr,
+ " -f: follow entries for named system\n");
+ fprintf (stderr,
+ " -u: print entries for named user\n");
+#if HAVE_HDB_LOGGING
+ fprintf (stderr,
+ " -x: print uuxqt log rather than uucico log\n");
+#else
+ fprintf (stderr,
+ " -F: follow entries for any system\n");
+#endif
+ fprintf (stderr,
+ " -S: show statistics file\n");
+ fprintf (stderr,
+ " -D: show debugging file\n");
+ fprintf (stderr,
+ " -X debug: Set debugging level (0 for none, 9 is max)\n");
+#if HAVE_TAYLOR_CONFIG
+ fprintf (stderr,
+ " -I file: Set configuration file to use\n");
+#endif /* HAVE_TAYLOR_CONFIG */
+ exit (EXIT_FAILURE);
+}
diff --git a/gnu/libexec/uucp/uuname/Makefile b/gnu/libexec/uucp/uuname/Makefile
new file mode 100644
index 00000000000..6cd1696bbad
--- /dev/null
+++ b/gnu/libexec/uucp/uuname/Makefile
@@ -0,0 +1,17 @@
+# Makefile for uuname
+
+BINDIR= $(bindir)
+BINOWN= $(owner)
+BINMODE= 4555
+
+PROG= uuname
+SRCS= uuname.c log.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -DVERSION=\"$(VERSION)\"
+
+NOMAN= noman
+
+.include <bsd.prog.mk>
+.PATH: $(.CURDIR)/../common_sources
diff --git a/gnu/libexec/uucp/uuname/uuname.c b/gnu/libexec/uucp/uuname/uuname.c
new file mode 100644
index 00000000000..54a87dfa392
--- /dev/null
+++ b/gnu/libexec/uucp/uuname/uuname.c
@@ -0,0 +1,192 @@
+/* uuname.c
+ List the names of known remote UUCP sites.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char uuname_rcsid[] = "$Id: uuname.c,v 1.1 1993/08/04 19:36:52 jtc Exp $";
+#endif
+
+#include "getopt.h"
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+
+/* The program name. */
+char abProgram[] = "uuname";
+
+/* Local functions. */
+
+static void unusage P((void));
+static void unuuconf_error P((pointer puuconf, int iuuconf));
+
+/* Long getopt options. */
+static const struct option asNlongopts[] = { { NULL, 0, NULL, 0 } };
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ /* -a: display aliases. */
+ boolean falias = FALSE;
+ /* -l: if true, output local node name. */
+ boolean flocal = FALSE;
+ /* -I: configuration file name. */
+ const char *zconfig = NULL;
+ int iopt;
+ pointer puuconf;
+ int iuuconf;
+
+ while ((iopt = getopt_long (argc, argv, "alI:x:", asNlongopts,
+ (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 'a':
+ /* Display aliases. */
+ falias = TRUE;
+ break;
+
+ case 'l':
+ /* Output local node name. */
+ flocal = TRUE;
+ break;
+
+ case 'I':
+ /* Configuration file name. */
+ if (fsysdep_other_config (optarg))
+ zconfig = optarg;
+ break;
+
+ case 'x':
+#if DEBUG > 1
+ /* Set debugging level. */
+ iDebug |= idebug_parse (optarg);
+#endif
+ break;
+
+ case 0:
+ /* Long option found and flag set. */
+ break;
+
+ default:
+ unusage ();
+ break;
+ }
+ }
+
+ if (optind != argc)
+ unusage ();
+
+ iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
+ if (iuuconf != UUCONF_SUCCESS)
+ unuuconf_error (puuconf, iuuconf);
+
+#if DEBUG > 1
+ {
+ const char *zdebug;
+
+ iuuconf = uuconf_debuglevel (puuconf, &zdebug);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (zdebug != NULL)
+ iDebug |= idebug_parse (zdebug);
+ }
+#endif
+
+ usysdep_initialize (puuconf, INIT_SUID);
+
+ if (flocal)
+ {
+ const char *zlocalname;
+
+ iuuconf = uuconf_localname (puuconf, &zlocalname);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ zlocalname = zsysdep_localname ();
+ if (zlocalname == NULL)
+ usysdep_exit (FALSE);
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ unuuconf_error (puuconf, iuuconf);
+ printf ("%s\n", zlocalname);
+ }
+ else
+ {
+ char **pznames, **pz;
+
+ iuuconf = uuconf_system_names (puuconf, &pznames, falias);
+ if (iuuconf != UUCONF_SUCCESS)
+ unuuconf_error (puuconf, iuuconf);
+
+ for (pz = pznames; *pz != NULL; pz++)
+ printf ("%s\n", *pz);
+ }
+
+ usysdep_exit (TRUE);
+
+ /* Avoid warnings about not returning a value. */
+ return 0;
+}
+
+/* Print a usage message and die. */
+
+static void
+unusage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uuname [-a] [-l] [-I file]\n");
+ fprintf (stderr,
+ " -a: display aliases\n");
+ fprintf (stderr,
+ " -l: print local name\n");
+#if HAVE_TAYLOR_CONFIG
+ fprintf (stderr,
+ " -I file: Set configuration file to use\n");
+#endif /* HAVE_TAYLOR_CONFIG */
+ exit (EXIT_FAILURE);
+}
+
+/* Display a uuconf error and exit. */
+
+static void
+unuuconf_error (puuconf, iret)
+ pointer puuconf;
+ int iret;
+{
+ char ab[512];
+
+ (void) uuconf_error_string (puuconf, iret, ab, sizeof ab);
+ if ((iret & UUCONF_ERROR_FILENAME) == 0)
+ fprintf (stderr, "uuname: %s\n", ab);
+ else
+ fprintf (stderr, "uuname:%s\n", ab);
+ exit (EXIT_FAILURE);
+}
diff --git a/gnu/libexec/uucp/uupick/Makefile b/gnu/libexec/uucp/uupick/Makefile
new file mode 100644
index 00000000000..2772424669c
--- /dev/null
+++ b/gnu/libexec/uucp/uupick/Makefile
@@ -0,0 +1,15 @@
+# Makefile for uupick
+
+BINDIR= $(bindir)
+
+PROG= uupick
+SRCS= uupick.c log.c copy.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -DVERSION=\"$(VERSION)\"
+
+NOMAN= noman
+
+.include <bsd.prog.mk>
+.PATH: $(.CURDIR)/../common_sources
diff --git a/gnu/libexec/uucp/uupick/uupick.c b/gnu/libexec/uucp/uupick/uupick.c
new file mode 100644
index 00000000000..4e1f1b3affb
--- /dev/null
+++ b/gnu/libexec/uucp/uupick/uupick.c
@@ -0,0 +1,323 @@
+/* uupick.c
+ Get files stored in the public directory by uucp -t.
+
+ Copyright (C) 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char uupick_rcsid[] = "$Id: uupick.c,v 1.1 1993/08/04 19:36:56 jtc Exp $";
+#endif
+
+#include <errno.h>
+
+#include "getopt.h"
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+
+/* Local functions. */
+
+static void upmovedir P((const char *zfull, const char *zrelative,
+ pointer pinfo));
+static void upmove P((const char *zfrom, const char *zto));
+
+/* The program name. */
+char abProgram[] = "uupick";
+
+/* Long getopt options. */
+static const struct option asPlongopts[] = { { NULL, 0, NULL, 0 } };
+
+/* Local functions. */
+
+static void upusage P((void));
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ /* -s: system name. */
+ const char *zsystem = NULL;
+ /* -I: configuration file name. */
+ const char *zconfig = NULL;
+ int iopt;
+ pointer puuconf;
+ int iuuconf;
+ struct uuconf_system ssys;
+ const char *zpubdir;
+ char *zfile, *zfrom, *zfull;
+ char *zallsys;
+ char ab[1000];
+ boolean fquit;
+
+ while ((iopt = getopt_long (argc, argv, "I:s:x:", asPlongopts,
+ (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 's':
+ /* System name to get files from. */
+ zsystem = optarg;
+ break;
+
+ case 'I':
+ /* Name configuration file. */
+ if (fsysdep_other_config (optarg))
+ zconfig = optarg;
+ break;
+
+ case 'x':
+#if DEBUG > 1
+ /* Set debugging level. */
+ iDebug |= idebug_parse (optarg);
+#endif
+ break;
+
+ case 0:
+ /* Long option found and flag set. */
+ break;
+
+ default:
+ upusage ();
+ break;
+ }
+ }
+
+ if (argc != optind)
+ upusage ();
+
+ iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ usysdep_initialize (puuconf, INIT_GETCWD | INIT_NOCHDIR);
+
+ zpubdir = NULL;
+ if (zsystem != NULL)
+ {
+ iuuconf = uuconf_system_info (puuconf, zsystem, &ssys);
+ if (iuuconf == UUCONF_SUCCESS)
+ {
+ zpubdir = zbufcpy (ssys.uuconf_zpubdir);
+ (void) uuconf_system_free (puuconf, &ssys);
+ }
+ else if (iuuconf != UUCONF_NOT_FOUND)
+ (void) ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ }
+ if (zpubdir == NULL)
+ {
+ iuuconf = uuconf_pubdir (puuconf, &zpubdir);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ }
+
+ if (! fsysdep_uupick_init (zsystem, zpubdir))
+ usysdep_exit (FALSE);
+
+ zallsys = NULL;
+ fquit = FALSE;
+
+ while (! fquit
+ && ((zfile = zsysdep_uupick (zsystem, zpubdir, &zfrom, &zfull))
+ != NULL))
+ {
+ boolean fdir;
+ char *zto, *zlocal;
+ FILE *e;
+ boolean fcontinue;
+
+ fdir = fsysdep_directory (zfull);
+
+ do
+ {
+ fcontinue = FALSE;
+
+ if (zallsys == NULL
+ || strcmp (zallsys, zfrom) != 0)
+ {
+ if (zallsys != NULL)
+ {
+ ubuffree (zallsys);
+ zallsys = NULL;
+ }
+
+ printf ("from %s: %s %s ?\n", zfrom, fdir ? "dir" : "file",
+ zfile);
+
+ if (fgets (ab, sizeof ab, stdin) == NULL)
+ break;
+ }
+
+ if (ab[0] == 'q')
+ {
+ fquit = TRUE;
+ break;
+ }
+
+ switch (ab[0])
+ {
+ case '\n':
+ break;
+
+ case 'd':
+ if (fdir)
+ (void) fsysdep_rmdir (zfull);
+ else
+ {
+ if (remove (zfull) != 0)
+ ulog (LOG_ERROR, "remove (%s): %s", zfull,
+ strerror(errno));
+ }
+ break;
+
+ case 'm':
+ case 'a':
+ zto = ab + 1 + strspn (ab + 1, " \t");
+ zto[strcspn (zto, " \t\n")] = '\0';
+ zlocal = zsysdep_uupick_local_file (zto);
+ if (zlocal == NULL)
+ usysdep_exit (FALSE);
+ zto = zsysdep_in_dir (zlocal, zfile);
+ ubuffree (zlocal);
+ if (zto == NULL)
+ usysdep_exit (FALSE);
+ if (! fdir)
+ upmove (zfull, zto);
+ else
+ {
+ usysdep_walk_tree (zfull, upmovedir, (pointer) zto);
+ (void) fsysdep_rmdir (zfull);
+ }
+ ubuffree (zto);
+
+ if (ab[0] == 'a')
+ {
+ zallsys = zbufcpy (zfrom);
+ ab[0] = 'm';
+ }
+
+ break;
+
+ case 'p':
+ if (fdir)
+ ulog (LOG_ERROR, "Can't print directory");
+ else
+ {
+ e = fopen (zfull, "r");
+ if (e == NULL)
+ ulog (LOG_ERROR, "fopen (%s): %s", zfull,
+ strerror (errno));
+ else
+ {
+ while (fgets (ab, sizeof ab, e) != NULL)
+ (void) fputs (ab, stdout);
+ (void) fclose (e);
+ }
+ }
+ fcontinue = TRUE;
+ break;
+
+ case '!':
+ (void) system (ab + 1);
+ fcontinue = TRUE;
+ break;
+
+ default:
+ printf ("uupick commands:\n");
+ printf ("q: quit\n");
+ printf ("<return>: skip file\n");
+ printf ("m [dir]: move file to directory\n");
+ printf ("a [dir]: move all files from this system to directory\n");
+ printf ("p: list file to stdout\n");
+ printf ("! command: shell escape\n");
+ fcontinue = TRUE;
+ break;
+ }
+ }
+ while (fcontinue);
+
+ ubuffree (zfull);
+ ubuffree (zfrom);
+ ubuffree (zfile);
+ }
+
+ (void) fsysdep_uupick_free (zsystem, zpubdir);
+
+ usysdep_exit (TRUE);
+
+ /* Avoid error about not returning. */
+ return 0;
+}
+
+/* Print usage message. */
+
+static void
+upusage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uupick [-s system] [-I config] [-x debug]\n");
+ fprintf (stderr,
+ " -s system: Only consider files from named system\n");
+ fprintf (stderr,
+ " -x debug: Set debugging level\n");
+#if HAVE_TAYLOR_CONFIG
+ fprintf (stderr,
+ " -I file: Set configuration file to use\n");
+#endif /* HAVE_TAYLOR_CONFIG */
+ exit (EXIT_FAILURE);
+}
+
+/* This routine is called by usysdep_walk_tree when moving the
+ contents of an entire directory. */
+
+static void
+upmovedir (zfull, zrelative, pinfo)
+ const char *zfull;
+ const char *zrelative;
+ pointer pinfo;
+{
+ const char *ztodir = (const char *) pinfo;
+ char *zto;
+
+ zto = zsysdep_in_dir (ztodir, zrelative);
+ if (zto == NULL)
+ usysdep_exit (FALSE);
+ upmove (zfull, zto);
+ ubuffree (zto);
+}
+
+/* Move a file. */
+
+static void
+upmove (zfrom, zto)
+ const char *zfrom;
+ const char *zto;
+{
+ (void) fsysdep_move_file (zfrom, zto, TRUE, TRUE, FALSE,
+ (const char *) NULL);
+}
diff --git a/gnu/libexec/uucp/uusched/Makefile b/gnu/libexec/uucp/uusched/Makefile
new file mode 100644
index 00000000000..b400e7bc428
--- /dev/null
+++ b/gnu/libexec/uucp/uusched/Makefile
@@ -0,0 +1,14 @@
+# Makefile for uusched
+# $Id: Makefile,v 1.1 1993/08/04 19:36:59 jtc Exp $
+
+BINDIR= $(bindir)
+
+PROG= uusched
+SRCS=
+NOMAN=
+
+uusched: uusched.in
+ sed -e "s|@BINDIR@|$(bindir)|g" -e "s|@SBINDIR@|$(sbindir)|g" \
+ $(.CURDIR)/uusched.in > $(.TARGET)
+
+.include <bsd.prog.mk>
diff --git a/gnu/libexec/uucp/uusched/uusched.in b/gnu/libexec/uucp/uusched/uusched.in
new file mode 100644
index 00000000000..e539b902fba
--- /dev/null
+++ b/gnu/libexec/uucp/uusched/uusched.in
@@ -0,0 +1,13 @@
+:
+# uusched
+# Call all systems which have work in a random order
+#
+# Copyright (C) 1992 Ian Lance Taylor
+#
+# Please feel free do whatever you like with this exciting shell
+# script.
+#
+# This is pretty trivial, since all the functionality was moved into
+# uucico itself.
+#
+@SBINDIR@/uucico -r1 $*
diff --git a/gnu/libexec/uucp/uustat/Makefile b/gnu/libexec/uucp/uustat/Makefile
new file mode 100644
index 00000000000..a09b5f04600
--- /dev/null
+++ b/gnu/libexec/uucp/uustat/Makefile
@@ -0,0 +1,16 @@
+# Makefile for uustat
+
+BINDIR= $(bindir)
+BINOWN= $(owner)
+BINMODE= 4555
+
+PROG= uustat
+SRCS= uustat.c util.c log.c copy.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -DOWNER=\"$(owner)\"\
+ -DVERSION=\"$(VERSION)\"
+
+.include <bsd.prog.mk>
+.PATH: $(.CURDIR)/../common_sources
diff --git a/gnu/libexec/uucp/uustat/uustat.1 b/gnu/libexec/uucp/uustat/uustat.1
new file mode 100644
index 00000000000..b8185216764
--- /dev/null
+++ b/gnu/libexec/uucp/uustat/uustat.1
@@ -0,0 +1,380 @@
+''' $Id: uustat.1,v 1.1 1993/08/04 19:37:04 jtc Exp $
+.TH uustat 1 "Taylor UUCP 1.04"
+.SH NAME
+uustat \- UUCP status inquiry and control
+.SH SYNOPSIS
+.B uustat \-a
+.PP
+.B uustat
+[
+.B \-eKiMNQ ] [
+.B \-sS
+system ] [
+.B \-uU
+user ] [
+.B \-cC
+command ] [
+.B \-o
+hours ] [
+.B \-y
+hours ] [
+.B \-B
+lines ]
+.PP
+.B uustat
+[
+.B \-k
+jobid ] [
+.B \-r
+jobid ]
+.PP
+.B uustat \-q
+.PP
+.B uustat \-m
+.PP
+.B uustat \-p
+.SH DESCRIPTION
+The
+.I uustat
+command can display various types of status information about the UUCP
+system. It can also be used to cancel or rejuvenate requests made by
+.I uucp
+(1) or
+.I uux
+(1).
+
+By default
+.I uustat
+displays all jobs queued up for the invoking user, as if given the
+.B \-u
+option with the appropriate argument.
+
+If any of the
+.B \-a,
+.B \-e,
+.B \-s,
+.B \-S,
+.B \-u,
+.B \-U,
+.B \-c,
+.B \-C,
+.B \-o,
+.B \-y
+options are given, then all jobs which match the combined
+specifications are displayed.
+
+The
+.B \-K
+option may be used to kill off a selected group of jobs, such as all
+jobs more than 7 days old.
+.SH OPTIONS
+The following options may be given to
+.I uustat.
+.TP 5
+.B \-a
+List all queued file transfer requests.
+.TP 5
+.B \-e
+List queued execution requests rather than queued file transfer
+requests. Queued execution requests are processed by
+.I uuxqt
+(8) rather than
+.I uucico
+(8). Queued execution requests may be waiting for some file to be
+transferred from a remote system. They are created by an invocation
+of
+.I uux
+(1).
+.TP 5
+.B \-s system
+List all jobs queued up for the named system. This option may be
+specified multiple times, in which case all jobs for all the systems
+will be listed.
+.TP 5
+.B \-S system
+List all jobs queued for systems other than the one named. This
+option may be specified multiple times, in which case no jobs from any
+of the specified systems will be listed. This option may not be used
+with
+.B \-s.
+.TP 5
+.B \-u user
+List all jobs queued up for the named user. This option may be
+specified multiple times, in which case all jobs for all the users
+will be listed.
+.TP 5
+.B \-U user
+List all jobs queued up for users other than the one named. This
+option may be specified multiple times, in which case no jobs from any
+of the specified users will be listed. This option may not be used
+with
+.B \-u.
+.TP 5
+.B \-c command
+List all jobs requesting the execution of the named command. If
+.B command
+is
+.I ALL
+this will list all jobs requesting the execution of some command (as
+opposed to simply requesting a file transfer). This option may be
+specified multiple times, in which case all jobs requesting any of the
+commands will be listed.
+.TP 5
+.B \-C command
+List all jobs requesting execution of some command other than the
+named command, or, if
+.B command
+is
+.I ALL,
+list all jobs that simply request a file transfer (as opposed to
+requesting the execution of some command). This option may be
+specified multiple times, in which case no job requesting one of the
+specified commands will be listed. This option may not be used with
+.B \-c.
+.TP 5
+.B \-o hours
+List all queued jobs older than the given number of hours.
+.TP 5
+.B \-y hours
+List all queued jobs younger than the given number of hours.
+.TP 5
+.B \-k jobid
+Kill the named job. The job id is shown by the default output format,
+as well as by the
+.B \-j
+option to
+.I uucp
+(1) or
+.I uux
+(1). A job may only be killed by the user who created the job, or by
+the UUCP administrator or the superuser. The
+.B \-k
+option may be used multiple times on the command line to kill several
+jobs.
+.TP 5
+.B \-r jobid
+Rejuvenate the named job. This will mark it as having been invoked at
+the current time, affecting the output of the
+.B \-o
+or
+.B \-y
+options and preserving it from any automated cleanup daemon. The job
+id is shown by the default output format, as well as by the
+.B \-j
+option to
+.I uucp
+(1) or
+.I uux
+(1). A job may only be rejuvenated by the user who created the job,
+or by the UUCP administrator or the superuser. The
+.B \-r
+option may be used multiple times on the command line to rejuvenate
+several jobs.
+.TP 5
+.B \-q
+Display the status of commands, executions and conversations for all
+remote systems for which commands or executions are queued.
+.TP 5
+.B \-m
+Display the status of conversations for all remote systems.
+.TP 5
+.B \-p
+Display the status of all processes holding UUCP locks on systems or
+ports.
+.TP 5
+.B \-i
+For each listed job, prompt whether to kill the job or not. If the
+first character of the input line is
+.I y
+or
+.I Y
+the job will be killed.
+.TP 5
+.B \-K
+Automatically kill each listed job. This can be useful for automatic
+cleanup scripts, in conjunction with the
+.B \-M
+and
+.B \-N
+options.
+.TP 5
+.B \-M
+For each listed job, send mail to the UUCP administrator. If the job
+is killed (due to
+.B \-K
+or
+.B \-i
+with an affirmative response) the mail will indicate that. A comment
+specified by the
+.B \-W
+option may be included. If the job is an execution, the initial
+portion of its standard input will be included in the mail message;
+the number of lines to include may be set with the
+.B \-B
+option (the default is 100). If the standard input contains null
+characters, it is assumed to be a binary file and is not included.
+.TP 5
+.B \-N
+For each listed job, send mail to the user who requested the job. The
+mail is identical to that sent by the
+.B \-M
+option.
+.TP 5
+.B \-W
+Specify a comment to be included in mail sent with the
+.B \-M
+or
+.B \-N
+options.
+.TP 5
+.B \-Q
+Do not actually list the job, but only take any actions indicated by
+the
+.B \-i,
+.B \-K,
+.B \-M,
+.B \-N
+options.
+.TP 5
+.B \-x type
+Turn on particular debugging types. The following types are
+recognized: abnormal, chat, handshake, uucp-proto, proto, port,
+config, spooldir, execute, incoming, outgoing. Only abnormal, config,
+spooldir and execute are meaningful for
+.I uustat.
+
+Multiple types may be given, separated by commas, and the
+.B \-x
+option may appear multiple times. A number may also be given, which
+will turn on that many types from the foregoing list; for example,
+.B \-x 2
+is equivalent to
+.B \-x abnormal,chat.
+.TP 5
+.B \-I file
+Set configuration file to use. This option may not be available,
+depending upon how
+.I uustat
+was compiled.
+.SH EXAMPLES
+.EX
+uustat -a
+.EE
+Display status of all jobs. A sample output line is as follows:
+.EX
+bugsA027h bugs ian 04-01 13:50 Executing rmail ian@airs.com (sending 1283 bytes)
+.EE
+The format is
+.EX
+jobid system user queue-date command (size)
+.EE
+The jobid may be passed to the
+.B \-k
+or
+.B \-r
+options.
+The size indicates how much data is to be transferred to the remote
+system, and is absent for a file receive request.
+The
+.B \-s,
+.B \-S,
+.B \-u,
+.B \-U,
+.B \-c,
+.B \-C,
+.B \-o,
+and
+.B \-y
+options may be used to control which jobs are listed.
+
+.EX
+uustat -e
+.EE
+Display status of queued up execution requests. A sample output line
+is as follows:
+.EX
+bugs bugs!ian 05-20 12:51 rmail ian
+.EE
+The format is
+.EX
+system requestor queue-date command
+.EE
+The
+.B \-s,
+.B \-S,
+.B \-u,
+.B \-U,
+.B \-c,
+.B \-C,
+.B \-o,
+and
+.B \-y
+options may be used to control which requests are listed.
+
+.EX
+uustat -q
+.EE
+Display status for all systems with queued up commands. A sample
+output line is as follows:
+.EX
+bugs 4C (1 hour) 0X (0 secs) 04-01 14:45 Dial failed
+.EE
+This indicates the system, the number of queued commands, the age of
+the oldest queued command, the number of queued local executions, the
+age of the oldest queued execution, the date of the last conversation,
+and the status of that conversation.
+
+.EX
+uustat -m
+.EE
+Display conversation status for all remote systems. A sample output
+line is as follows:
+.EX
+bugs 04-01 15:51 Conversation complete
+.EE
+This indicates the system, the date of the last conversation, and the
+status of that conversation. If the last conversation failed,
+.I uustat
+will indicate how many attempts have been made to call the system. If
+the retry period is currently preventing calls to that system,
+.I uustat
+also displays the time when the next call will be permitted.
+
+.EX
+uustat -p
+.EE
+Display the status of all processes holding UUCP locks. The output
+format is system dependent, as
+.I uustat
+simply invokes
+.I ps
+(1) on each process holding a lock.
+
+.EX
+uustat -c rmail -o 168 -K -Q -M -N -W"Queued for over 1 week"
+.EE
+This will kill all
+.I rmail
+commands that have been queued up waiting for delivery for over 1 week
+(168 hours). For each such command, mail will be sent both to the
+UUCP administrator and to the user who requested the rmail execution.
+The mail message sent will include the string given by the
+.B \-W
+option. The
+.B \-Q
+option prevents any of the jobs from being listed on the terminal, so
+any output from the program will be error messages.
+.SH FILES
+The file names may be changed at compilation time or by the
+configuration file, so these are only approximations.
+
+.br
+/usr/lib/uucp/config - Configuration file.
+.br
+/usr/spool/uucp -
+UUCP spool directory.
+.SH SEE ALSO
+ps(1), rmail(1), uucp(1), uux(1), uucico(8), uuxqt(8)
+.SH AUTHOR
+Ian Lance Taylor
+(ian@airs.com or uunet!airs!ian)
diff --git a/gnu/libexec/uucp/uustat/uustat.c b/gnu/libexec/uucp/uustat/uustat.c
new file mode 100644
index 00000000000..3c1352668c2
--- /dev/null
+++ b/gnu/libexec/uucp/uustat/uustat.c
@@ -0,0 +1,2241 @@
+/* uustat.c
+ UUCP status program
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char uustat_rcsid[] = "$Id: uustat.c,v 1.1 1993/08/04 19:37:05 jtc Exp $";
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+#if HAVE_TIME_H
+#include <time.h>
+#endif
+
+#include "getopt.h"
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+
+/* The uustat program permits various listings and manipulations of
+ files in the spool directory. This implementation supports the
+ following switches:
+
+ -a list all jobs
+ -Blines number of lines of standard input to mail
+ -ccommand list only executions of specified command
+ -Ccommand list only jobs other than executions of specified command
+ -e list execute jobs rather than command requests
+ -i ask user whether to kill each listed job
+ -Ifile set configuration file name
+ -kjobid kill job with specified ID
+ -K kill each listed job
+ -m report status for all remote machines
+ -M mail uucp about each job killed with -K
+ -N mail requestor about each job killed with -K
+ -ohour report jobs older than specified number of hours
+ -p do "ps -flp" on all processes holding lock files (Unix specific)
+ -q list number of jobs for all systems
+ -Q don't list jobs, just do -K processing
+ -rjobid rejuvenate job with specified ID
+ -ssystem report on all jobs for specified system
+ -Ssystem report on all jobs other than for specified system
+ -uuser report on all jobs for specified user
+ -Uuser report on all jobs other than for specified user
+ -Wcomment comment to include in mail messages
+ -xdebug set debugging level
+ -yhour report jobs younger than specified number of hours */
+
+/* The program name. */
+char abProgram[] = "uustat";
+
+/* What to do with a job that matches the selection criteria; these
+ values may be or'red together. */
+#define JOB_SHOW (01)
+#define JOB_INQUIRE (02)
+#define JOB_KILL (04)
+#define JOB_MAIL (010)
+#define JOB_NOTIFY (020)
+
+/* This structure is used to accumulate all the lines in a single
+ command file, so that they can all be displayed at once and so that
+ executions can be displayed reasonably. */
+
+struct scmdlist
+{
+ struct scmdlist *qnext;
+ struct scmd s;
+ long itime;
+};
+
+/* Local functions. */
+
+static void ususage P((void));
+static boolean fsxqt_file_read P((pointer puuconf, const char *zfile));
+static void usxqt_file_free P((void));
+static int isxqt_cmd P((pointer puuconf, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int isxqt_file P((pointer puuconf, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int isxqt_user P((pointer puuconf, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static boolean fsworkfiles P((pointer puuconf, int icmd, int csystems,
+ char **pazsystems, boolean fnotsystems,
+ int cusers, char **pazusers,
+ boolean fnotusers, long iold, long iyoung,
+ int ccommands, char **pazcommands,
+ boolean fnotcommands, const char *zcomment,
+ int cstdin));
+static boolean fsworkfiles_system P((pointer puuconf,int icmd,
+ const struct uuconf_system *qsys,
+ int cusers, char **pazusers,
+ boolean fnotusers, long iold,
+ long iyoung, int ccommands,
+ char **pazcommands,
+ boolean fnotcommands,
+ const char *zcomment, int cstdin));
+static boolean fsworkfile_show P((pointer puuconf, int icmd,
+ const struct uuconf_system *qsys,
+ const struct scmd *qcmd,
+ long itime, int ccommands,
+ char **pazcommands, boolean fnotcommands,
+ const char *zcomment, int cstdin));
+static void usworkfile_header P((const struct uuconf_system *qsys,
+ const struct scmd *qcmd,
+ const char *zjobid,
+ long itime, boolean ffirst));
+static boolean fsexecutions P((pointer puuconf, int icmd, int csystems,
+ char **pazsystems, boolean fnotsystems,
+ int cusers, char **pazusers,
+ boolean fnotusers, long iold, long iyoung,
+ int ccommands, char **pazcommands,
+ boolean fnotcommands, const char *zcomment,
+ int cstdin));
+static boolean fsnotify P((pointer puuconf, int icmd, const char *zcomment,
+ int cstdin, boolean fkilled, const char *zcmd,
+ struct scmdlist *qcmd, const char *zid,
+ const char *zuser,
+ const struct uuconf_system *qsys,
+ const char *zstdin, pointer pstdinseq,
+ const char *zrequestor));
+static boolean fsquery P((pointer puuconf));
+static int csunits_show P((long idiff));
+static boolean fsmachines P((void));
+
+/* Long getopt options. */
+static const struct option asSlongopts[] = { { NULL, 0, NULL, 0 } };
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ /* -a: list all jobs. */
+ boolean fall = FALSE;
+ /* -B lines: number of lines of standard input to mail. */
+ int cstdin = 100;
+ /* -c,-C command: list only specified command. */
+ int ccommands = 0;
+ char **pazcommands = NULL;
+ boolean fnotcommands = FALSE;
+ /* -e: list execute jobs. */
+ boolean fexecute = FALSE;
+ /* -k jobid: kill specified job. */
+ int ckills = 0;
+ char **pazkills = NULL;
+ /* -m: report machine status. */
+ boolean fmachine = FALSE;
+ /* -o hour: report jobs older than given number of hours. */
+ int ioldhours = -1;
+ /* -p: report status of jobs holding lock files. */
+ boolean fps = FALSE;
+ /* -q: list number of jobs for each system. */
+ boolean fquery = FALSE;
+ /* -r jobid: rejuvenate specified job. */
+ int crejuvs = 0;
+ char **pazrejuvs = NULL;
+ /* -s,-S system: list all jobs for specified system. */
+ int csystems = 0;
+ char **pazsystems = NULL;
+ boolean fnotsystems = FALSE;
+ /* -u,-U user: list all jobs for specified user. */
+ int cusers = 0;
+ char **pazusers = NULL;
+ boolean fnotusers = FALSE;
+ /* -W comment: comment to include in mail messages. */
+ const char *zcomment = NULL;
+ /* -y hour: report jobs younger than given number of hours. */
+ int iyounghours = -1;
+ /* -I file: set configuration file. */
+ const char *zconfig = NULL;
+ /* -Q, -i, -K, -M, -N: what to do with each job. */
+ int icmd = JOB_SHOW;
+ int ccmds;
+ int iopt;
+ pointer puuconf;
+ int iuuconf;
+ long iold;
+ long iyoung;
+ const char *azoneuser[1];
+ boolean fret;
+
+ while ((iopt = getopt_long (argc, argv,
+ "aB:c:C:eiI:k:KmMNo:pqQr:s:S:u:U:W:x:y:",
+ asSlongopts, (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 'a':
+ /* List all jobs. */
+ fall = TRUE;
+ break;
+
+ case 'B':
+ /* Number of lines of standard input to mail. */
+ cstdin = (int) strtol (optarg, (char **) NULL, 10);
+ break;
+
+ case 'C':
+ /* List jobs for other than specified command. */
+ fnotcommands = TRUE;
+ /* Fall through. */
+ case 'c':
+ /* List specified command. */
+ ++ccommands;
+ pazcommands = (char **) xrealloc ((pointer) pazcommands,
+ ccommands * sizeof (char *));
+ pazcommands[ccommands - 1] = optarg;
+ break;
+
+ case 'e':
+ /* List execute jobs. */
+ fexecute = TRUE;
+ break;
+
+ case 'i':
+ /* Prompt the user whether to kill each job. */
+ icmd |= JOB_INQUIRE;
+ break;
+
+ case 'I':
+ /* Set configuration file name. */
+ if (fsysdep_other_config (optarg))
+ zconfig = optarg;
+ break;
+
+ case 'k':
+ /* Kill specified job. */
+ ++ckills;
+ pazkills = (char **) xrealloc ((pointer) pazkills,
+ ckills * sizeof (char *));
+ pazkills[ckills - 1] = optarg;
+ break;
+
+ case 'K':
+ /* Kill each listed job. */
+ icmd |= JOB_KILL;
+ break;
+
+ case 'm':
+ /* Report machine status. */
+ fmachine = TRUE;
+ break;
+
+ case 'M':
+ /* Mail to uucp action taken on each job. */
+ icmd |= JOB_MAIL;
+ break;
+
+ case 'N':
+ /* Mail to requestor action taken on each job. */
+ icmd |= JOB_NOTIFY;
+ break;
+
+ case 'o':
+ /* Report old jobs. */
+ ioldhours = (int) strtol (optarg, (char **) NULL, 10);
+ break;
+
+ case 'p':
+ /* Get status of processes holding locks. */
+ fps = TRUE;
+ break;
+
+ case 'q':
+ /* List number of jobs for each system. */
+ fquery = TRUE;
+ break;
+
+ case 'Q':
+ /* Don't list jobs, just do -K processing. */
+ icmd &=~ JOB_SHOW;
+ break;
+
+ case 'r':
+ /* Rejuvenate specified job. */
+ ++crejuvs;
+ pazrejuvs = (char **) xrealloc ((pointer) pazrejuvs,
+ crejuvs * sizeof (char *));
+ pazrejuvs[crejuvs - 1] = optarg;
+ break;
+
+ case 'S':
+ /* List jobs for other than specified system. */
+ fnotsystems = TRUE;
+ /* Fall through. */
+ case 's':
+ /* List jobs for specified system. */
+ ++csystems;
+ pazsystems = (char **) xrealloc ((pointer) pazsystems,
+ csystems * sizeof (char *));
+ pazsystems[csystems - 1] = optarg;
+ break;
+
+ case 'U':
+ /* List jobs for other than specified user. */
+ fnotusers = TRUE;
+ /* Fall through. */
+ case 'u':
+ /* List jobs for specified user. */
+ ++cusers;
+ pazusers = (char **) xrealloc ((pointer) pazusers,
+ cusers * sizeof (char *));
+ pazusers[cusers - 1] = optarg;
+ break;
+
+ case 'W':
+ /* Comment to include in mail messages. */
+ zcomment = optarg;
+ break;
+
+ case 'x':
+#if DEBUG > 1
+ /* Set debugging level. */
+ iDebug |= idebug_parse (optarg);
+#endif
+ break;
+
+ case 'y':
+ /* List jobs younger than given number of hours. */
+ iyounghours = (int) strtol (optarg, (char **) NULL, 10);
+ break;
+
+ case 0:
+ /* Long option found and flag set. */
+ break;
+
+ default:
+ ususage ();
+ break;
+ }
+ }
+
+ if (optind != argc)
+ ususage ();
+
+ /* To avoid confusion, most options are only permitted by
+ themselves. This restriction might be removed later, but it is
+ imposed by most implementations. We do permit any combination of
+ -c, -s, -u, -o and -y, and any combination of -k and -r. */
+ ccmds = 0;
+ if (fall)
+ ++ccmds;
+ if (ckills > 0 || crejuvs > 0)
+ ++ccmds;
+ if (fmachine)
+ ++ccmds;
+ if (fps)
+ ++ccmds;
+ if (fquery)
+ ++ccmds;
+ if (fexecute || csystems > 0 || cusers > 0 || ioldhours != -1
+ || iyounghours != -1 || ccommands > 0)
+ ++ccmds;
+
+ if (ccmds > 1)
+ {
+ ulog (LOG_ERROR, "Too many options");
+ ususage ();
+ }
+
+ iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+#if DEBUG > 1
+ {
+ const char *zdebug;
+
+ iuuconf = uuconf_debuglevel (puuconf, &zdebug);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (zdebug != NULL)
+ iDebug |= idebug_parse (zdebug);
+ }
+#endif
+
+ usysdep_initialize (puuconf, INIT_SUID);
+
+ /* If no commands were specified, we list all commands for the given
+ user. */
+ if (ccmds == 0)
+ {
+ cusers = 1;
+ azoneuser[0] = zsysdep_login_name ();
+ pazusers = (char **) azoneuser;
+ }
+
+ /* Canonicalize the system names. */
+ if (csystems > 0)
+ {
+ int i;
+
+ for (i = 0; i < csystems; i++)
+ {
+ struct uuconf_system ssys;
+
+ iuuconf = uuconf_system_info (puuconf, pazsystems[i], &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf == UUCONF_NOT_FOUND)
+ ulog (LOG_FATAL, "%s: System not found", pazsystems[i]);
+ else
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ }
+ if (strcmp (pazsystems[i], ssys.uuconf_zname) != 0)
+ pazsystems[i] = zbufcpy (ssys.uuconf_zname);
+ (void) uuconf_system_free (puuconf, &ssys);
+ }
+ }
+
+ if (ioldhours == -1)
+ iold = (long) -1;
+ else
+ {
+ iold = (ixsysdep_time ((long *) NULL)
+ - (long) ioldhours * (long) 60 * (long) 60);
+ if (iold < 0L)
+ iold = 0L;
+ }
+ if (iyounghours == -1)
+ iyoung = (long) -1;
+ else
+ {
+ iyoung = (ixsysdep_time ((long *) NULL)
+ - (long) iyounghours * (long) 60 * (long) 60);
+ if (iyoung < 0L)
+ iyoung = 0L;
+ }
+
+ if (! fexecute
+ && (fall
+ || csystems > 0
+ || cusers > 0
+ || ioldhours != -1
+ || iyounghours != -1
+ || ccommands > 0))
+ fret = fsworkfiles (puuconf, icmd, csystems, pazsystems, fnotsystems,
+ cusers, pazusers, fnotusers, iold, iyoung,
+ ccommands, pazcommands, fnotcommands, zcomment,
+ cstdin);
+ else if (fexecute)
+ fret = fsexecutions (puuconf, icmd, csystems, pazsystems, fnotsystems,
+ cusers, pazusers, fnotusers, iold, iyoung,
+ ccommands, pazcommands, fnotcommands, zcomment,
+ cstdin);
+ else if (icmd != JOB_SHOW)
+ {
+ ulog (LOG_ERROR,
+ "-i, -K, -M, -N, -Q not supported with -k, -m, -p, -q, -r");
+ ususage ();
+ fret = FALSE;
+ }
+ else if (fquery)
+ fret = fsquery (puuconf);
+ else if (fmachine)
+ fret = fsmachines ();
+ else if (ckills > 0 || crejuvs > 0)
+ {
+ int i;
+
+ fret = TRUE;
+ for (i = 0; i < ckills; i++)
+ if (! fsysdep_kill_job (puuconf, pazkills[i]))
+ fret = FALSE;
+
+ for (i = 0; i < crejuvs; i++)
+ if (! fsysdep_rejuvenate_job (puuconf, pazrejuvs[i]))
+ fret = FALSE;
+ }
+ else if (fps)
+ fret = fsysdep_lock_status ();
+ else
+ {
+#if DEBUG > 0
+ ulog (LOG_FATAL, "Can't happen");
+#endif
+ fret = FALSE;
+ }
+
+ ulog_close ();
+
+ usysdep_exit (fret);
+
+ /* Avoid errors about not returning a value. */
+ return 0;
+}
+
+/* Print a usage message and die. */
+
+static void
+ususage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uustat [options]\n");
+ fprintf (stderr,
+ " -a: list all UUCP jobs\n");
+ fprintf (stderr,
+ " -B num: number of lines to return in -M or -N mail message\n");
+ fprintf (stderr,
+ " -c command: list requests for named command\n");
+ fprintf (stderr,
+ " -C command: list requests for other than named command\n");
+ fprintf (stderr,
+ " -e: list queued executions rather than job requests\n");
+ fprintf (stderr,
+ " -i: prompt for whether to kill each listed job\n");
+ fprintf (stderr,
+ " -k job: kill specified UUCP job\n");
+ fprintf (stderr,
+ " -K: kill each listed job\n");
+ fprintf (stderr,
+ " -m: report status for all remote machines\n");
+ fprintf (stderr,
+ " -M: mail report on each listed job to UUCP administrator\n");
+ fprintf (stderr,
+ " -N: mail report on each listed job to requestor\n");
+ fprintf (stderr,
+ " -o hours: list all jobs older than given number of hours\n");
+ fprintf (stderr,
+ " -p: show status of all processes holding UUCP locks\n");
+ fprintf (stderr,
+ " -q: list number of jobs for each system\n");
+ fprintf (stderr,
+ " -Q: don't list jobs, just take actions (-i, -K, -M, -N)\n");
+ fprintf (stderr,
+ " -r job: rejuvenate specified UUCP job\n");
+ fprintf (stderr,
+ " -s system: list all jobs for specified system\n");
+ fprintf (stderr,
+ " -S system: list all jobs for other than specified system\n");
+ fprintf (stderr,
+ " -u user: list all jobs for specified user\n");
+ fprintf (stderr,
+ " -U user: list all jobs for other than specified user\n");
+ fprintf (stderr,
+ " -W comment: comment to include in mail messages\n");
+ fprintf (stderr,
+ " -y hours: list all jobs younger than given number of hours\n");
+ fprintf (stderr,
+ " -x debug: Set debugging level (0 for none, 9 is max)\n");
+#if HAVE_TAYLOR_CONFIG
+ fprintf (stderr,
+ " -I file: Set configuration file to use\n");
+#endif /* HAVE_TAYLOR_CONFIG */
+ exit (EXIT_FAILURE);
+}
+
+/* We need to be able to read information from an execution file. */
+
+/* The user name extracted from an execution file. */
+static char *zSxqt_user;
+
+/* The system name from an execution file. */
+static char *zSxqt_system;
+
+/* Address of requesting user (who to send mail to). */
+static const char *zSxqt_requestor;
+
+/* The command (no arguments) from an execution file. */
+static char *zSxqt_prog;
+
+/* The full command line from an execution file. */
+static char *zSxqt_cmd;
+
+/* Number of files associated with an execution file. */
+static int cSxqt_files;
+
+/* Names of files associated with execution file. */
+static char **pazSxqt_files;
+
+/* Standard input file name. */
+static const char *zSxqt_stdin;
+
+/* A command table used to dispatch an execution file. */
+static const struct uuconf_cmdtab asSxqt_cmds[] =
+{
+ { "C", UUCONF_CMDTABTYPE_FN | 0, NULL, isxqt_cmd },
+ { "I", UUCONF_CMDTABTYPE_STRING, (pointer) &zSxqt_stdin, NULL },
+ { "F", UUCONF_CMDTABTYPE_FN | 0, NULL, isxqt_file },
+ { "R", UUCONF_CMDTABTYPE_STRING, (pointer) &zSxqt_requestor, NULL },
+ { "U", UUCONF_CMDTABTYPE_FN | 3, NULL, isxqt_user },
+ { NULL, 0, NULL, NULL }
+};
+
+/* Read an execution file, setting the above variables. */
+
+static boolean
+fsxqt_file_read (puuconf, zfile)
+ pointer puuconf;
+ const char *zfile;
+{
+ FILE *e;
+ int iuuconf;
+ boolean fret;
+
+ e = fopen (zfile, "r");
+ if (e == NULL)
+ {
+ ulog (LOG_ERROR, "fopen (%s): %s", zfile, strerror (errno));
+ return FALSE;
+ }
+
+ zSxqt_user = NULL;
+ zSxqt_system = NULL;
+ zSxqt_stdin = NULL;
+ zSxqt_requestor = NULL;
+ zSxqt_prog = NULL;
+ zSxqt_cmd = NULL;
+ cSxqt_files = 0;
+ pazSxqt_files = NULL;
+
+ iuuconf = uuconf_cmd_file (puuconf, e, asSxqt_cmds, (pointer) NULL,
+ (uuconf_cmdtabfn) NULL,
+ UUCONF_CMDTABFLAG_CASE, (pointer) NULL);
+ (void) fclose (e);
+ if (iuuconf == UUCONF_SUCCESS)
+ fret = TRUE;
+ else
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ fret = FALSE;
+ }
+
+ if (zSxqt_user == NULL)
+ zSxqt_user = zbufcpy ("*unknown*");
+ if (zSxqt_system == NULL)
+ zSxqt_system = zbufcpy ("*unknown*");
+ if (zSxqt_prog == NULL)
+ {
+ zSxqt_prog = zbufcpy ("*none*");
+ zSxqt_cmd = zbufcpy ("*none*");
+ }
+
+ return fret;
+}
+
+/* Free up the information read from an execution file. */
+
+static void
+usxqt_file_free ()
+{
+ int i;
+
+ ubuffree (zSxqt_user);
+ zSxqt_user = NULL;
+ ubuffree (zSxqt_system);
+ zSxqt_system = NULL;
+ ubuffree (zSxqt_prog);
+ zSxqt_prog = NULL;
+ ubuffree (zSxqt_cmd);
+ zSxqt_cmd = NULL;
+ for (i = 0; i < cSxqt_files; i++)
+ ubuffree (pazSxqt_files[i]);
+ cSxqt_files = 0;
+ xfree ((pointer) pazSxqt_files);
+ pazSxqt_files = NULL;
+ zSxqt_stdin = NULL;
+ zSxqt_requestor = NULL;
+}
+
+/* Get the command from an execution file. */
+
+/*ARGSUSED*/
+static int
+isxqt_cmd (puuconf, argc, argv, pvar, pinfo)
+ pointer puuconf;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ size_t clen;
+ int i;
+
+ if (argc <= 1)
+ return UUCONF_CMDTABRET_CONTINUE;
+
+ zSxqt_prog = zbufcpy (argv[1]);
+
+ clen = 0;
+ for (i = 1; i < argc; i++)
+ clen += strlen (argv[i]) + 1;
+
+ zSxqt_cmd = zbufalc (clen);
+ zSxqt_cmd[0] = '\0';
+ for (i = 1; i < argc - 1; i++)
+ {
+ strcat (zSxqt_cmd, argv[i]);
+ strcat (zSxqt_cmd, " ");
+ }
+ strcat (zSxqt_cmd, argv[i]);
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Get the associated files from an execution file. */
+
+/*ARGSUSED*/
+static int
+isxqt_file (puuconf, argc, argv, pvar, pinfo)
+ pointer puuconf;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ if (argc != 2 && argc != 3)
+ return UUCONF_CMDTABRET_CONTINUE;
+
+ /* If this file is not in the spool directory, just ignore it. */
+ if (! fspool_file (argv[1]))
+ return UUCONF_CMDTABRET_CONTINUE;
+
+ ++cSxqt_files;
+ pazSxqt_files = (char **) xrealloc ((pointer) pazSxqt_files,
+ cSxqt_files * sizeof (char *));
+
+ pazSxqt_files[cSxqt_files - 1] = zbufcpy (argv[1]);
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Get the requesting user and system from an execution file. */
+
+/*ARGSUSED*/
+static int
+isxqt_user (puuconf, argc, argv, pvar, pinfo)
+ pointer puuconf;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ zSxqt_user = zbufcpy (argv[1]);
+ zSxqt_system = zbufcpy (argv[2]);
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Handle various possible requests to look at work files. */
+
+static boolean
+fsworkfiles (puuconf, icmd, csystems, pazsystems, fnotsystems, cusers,
+ pazusers, fnotusers, iold, iyoung, ccommands, pazcommands,
+ fnotcommands, zcomment, cstdin)
+ pointer puuconf;
+ int icmd;
+ int csystems;
+ char **pazsystems;
+ boolean fnotsystems;
+ int cusers;
+ char **pazusers;
+ boolean fnotusers;
+ long iold;
+ long iyoung;
+ int ccommands;
+ char **pazcommands;
+ boolean fnotcommands;
+ const char *zcomment;
+ int cstdin;
+{
+ boolean fret;
+ int i;
+ int iuuconf;
+ struct uuconf_system ssys;
+
+ fret = TRUE;
+
+ if (csystems > 0 && ! fnotsystems)
+ {
+ for (i = 0; i < csystems; i++)
+ {
+ iuuconf = uuconf_system_info (puuconf, pazsystems[i], &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf == UUCONF_NOT_FOUND)
+ ulog (LOG_ERROR, "%s: System not found", pazsystems[i]);
+ else
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ fret = FALSE;
+ continue;
+ }
+
+ if (! fsworkfiles_system (puuconf, icmd, &ssys, cusers, pazusers,
+ fnotusers, iold, iyoung, ccommands,
+ pazcommands, fnotcommands, zcomment,
+ cstdin))
+ fret = FALSE;
+
+ (void) uuconf_system_free (puuconf, &ssys);
+ }
+ }
+ else
+ {
+ char **pznames, **pz;
+
+ iuuconf = uuconf_system_names (puuconf, &pznames, 0);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+
+ for (pz = pznames; *pz != NULL; pz++)
+ {
+ if (csystems > 0)
+ {
+ for (i = 0; i < csystems; i++)
+ if (strcmp (*pz, pazsystems[i]) == 0)
+ break;
+ if (i < csystems)
+ continue;
+ }
+
+ iuuconf = uuconf_system_info (puuconf, *pz, &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ fret = FALSE;
+ continue;
+ }
+
+ if (! fsworkfiles_system (puuconf, icmd, &ssys, cusers, pazusers,
+ fnotusers, iold, iyoung, ccommands,
+ pazcommands, fnotcommands, zcomment,
+ cstdin))
+ fret = FALSE;
+
+ (void) uuconf_system_free (puuconf, &ssys);
+ xfree ((pointer) *pz);
+ }
+ xfree ((pointer) pznames);
+ }
+
+ return fret;
+}
+
+/* Look at the work files for a particular system. */
+
+static boolean
+fsworkfiles_system (puuconf, icmd, qsys, cusers, pazusers, fnotusers, iold,
+ iyoung, ccommands, pazcommands, fnotcommands, zcomment,
+ cstdin)
+ pointer puuconf;
+ int icmd;
+ const struct uuconf_system *qsys;
+ int cusers;
+ char **pazusers;
+ boolean fnotusers;
+ long iold;
+ long iyoung;
+ int ccommands;
+ char **pazcommands;
+ boolean fnotcommands;
+ const char *zcomment;
+ int cstdin;
+{
+ boolean fret;
+
+ if (! fsysdep_get_work_init (qsys, UUCONF_GRADE_LOW))
+ return FALSE;
+
+ while (TRUE)
+ {
+ struct scmd s;
+ long itime;
+
+ if (! fsysdep_get_work (qsys, UUCONF_GRADE_LOW, &s))
+ {
+ usysdep_get_work_free (qsys);
+ return FALSE;
+ }
+ if (s.bcmd == 'H')
+ break;
+
+ if (cusers > 0)
+ {
+ boolean fmatch;
+ int i;
+
+ fmatch = fnotusers;
+ for (i = 0; i < cusers; i++)
+ {
+ if (s.zuser != NULL
+ && strcmp (pazusers[i], s.zuser) == 0)
+ {
+ fmatch = ! fmatch;
+ break;
+ }
+ }
+ if (! fmatch)
+ continue;
+ }
+
+ itime = ixsysdep_work_time (qsys, s.pseq);
+
+ if (iold != (long) -1 && itime > iold)
+ continue;
+
+ if (iyoung != (long) -1 && itime < iyoung)
+ continue;
+
+ if (! fsworkfile_show (puuconf, icmd, qsys, &s, itime, ccommands,
+ pazcommands, fnotcommands, zcomment, cstdin))
+ {
+ usysdep_get_work_free (qsys);
+ return FALSE;
+ }
+ }
+
+ fret = fsworkfile_show (puuconf, icmd, qsys, (const struct scmd *) NULL,
+ 0L, ccommands, pazcommands, fnotcommands, zcomment,
+ cstdin);
+
+ usysdep_get_work_free (qsys);
+
+ return fret;
+}
+
+/* Show a single workfile. This is actually called once for each line
+ in the workfile, so we accumulate the lines and show them all at
+ once. This lets us show an execution in a useful fashion. */
+
+static boolean
+fsworkfile_show (puuconf, icmd, qsys, qcmd, itime, ccommands, pazcommands,
+ fnotcommands, zcomment, cstdin)
+ pointer puuconf;
+ int icmd;
+ const struct uuconf_system *qsys;
+ const struct scmd *qcmd;
+ long itime;
+ int ccommands;
+ char **pazcommands;
+ boolean fnotcommands;
+ const char *zcomment;
+ int cstdin;
+{
+ static struct scmdlist *qlist;
+ static char *zlistid;
+ char *zid;
+
+ if (qcmd == NULL)
+ zid = NULL;
+ else
+ {
+ zid = zsysdep_jobid (qsys, qcmd->pseq);
+ if (zid == NULL)
+ return FALSE;
+ }
+
+ /* If this is the same jobid as the list, put it on the end. */
+
+ if (qcmd != NULL
+ && qlist != NULL
+ && strcmp (zlistid, zid) == 0)
+ {
+ struct scmdlist *qnew, **pq;
+
+ ubuffree (zid);
+ qnew = (struct scmdlist *) xmalloc (sizeof (struct scmdlist));
+ qnew->qnext = NULL;
+ qnew->s = *qcmd;
+ qnew->itime = itime;
+ for (pq = &qlist; *pq != NULL; pq = &(*pq)->qnext)
+ ;
+ *pq = qnew;
+ return TRUE;
+ }
+
+ /* Here we have found a different job ID, so we print the scmd
+ structures that we have accumulated. We look for the special
+ case of an execution (an E command, or one of the destination
+ files begins with X.). We could be more clever about other
+ situations as well. */
+ if (qlist != NULL)
+ {
+ boolean fmatch;
+ const char *zprog, *zcmd, *zrequestor, *zstdin;
+ char *zfree;
+ struct scmdlist *qxqt;
+ struct scmdlist *qfree;
+
+ fmatch = FALSE;
+ zprog = zcmd = zrequestor = zstdin = NULL;
+ zfree = NULL;
+
+ for (qxqt = qlist; qxqt != NULL; qxqt = qxqt->qnext)
+ if (qxqt->s.bcmd == 'E'
+ || (qxqt->s.bcmd == 'S'
+ && qxqt->s.zto[0] == 'X'
+ && qxqt->s.zto[1] == '.'
+ && fspool_file (qxqt->s.zfrom)))
+ break;
+
+ if (qxqt == NULL)
+ {
+ if (ccommands == 0
+ || (fnotcommands
+ && strcmp (pazcommands[0], "ALL") == 0))
+ {
+ /* Show all the lines in a regular work file. */
+ fmatch = TRUE;
+
+ if ((icmd & JOB_SHOW) != 0)
+ {
+ struct scmdlist *qshow;
+
+ for (qshow = qlist; qshow != NULL; qshow = qshow->qnext)
+ {
+ char *zfile;
+ long cbytes;
+
+ usworkfile_header (qsys, &qshow->s, zlistid,
+ qshow->itime, qshow == qlist);
+
+ switch (qshow->s.bcmd)
+ {
+ case 'S':
+ if (strchr (qshow->s.zoptions, 'C') != NULL
+ || fspool_file (qshow->s.zfrom))
+ zfile = zsysdep_spool_file_name (qsys,
+ qshow->s.ztemp,
+ qshow->s.pseq);
+ else
+ zfile = zbufcpy (qshow->s.zfrom);
+ if (zfile == NULL)
+ cbytes = 0;
+ else
+ {
+ cbytes = csysdep_size (zfile);
+ if (cbytes < 0)
+ cbytes = 0;
+ }
+ printf ("Sending %s (%ld bytes) to %s",
+ qshow->s.zfrom, cbytes, qshow->s.zto);
+ ubuffree (zfile);
+ break;
+ case 'R':
+ printf ("Requesting %s to %s", qshow->s.zfrom,
+ qshow->s.zto);
+ break;
+ case 'X':
+ printf ("Requesting %s to %s", qshow->s.zfrom,
+ qshow->s.zto);
+ break;
+ case 'P':
+ printf ("(poll file)");
+ break;
+#if DEBUG > 0
+ default:
+ printf ("Bad line %d", qshow->s.bcmd);
+ break;
+#endif
+ }
+
+ printf ("\n");
+ }
+ }
+ }
+ }
+ else
+ {
+ long csize;
+ struct scmdlist *qsize;
+
+ /* Show the command for an execution file. */
+ if (qxqt->s.bcmd == 'E')
+ {
+ zfree = zbufcpy (qxqt->s.zcmd);
+ zfree[strcspn (zfree, " \t")] = '\0';
+ zprog = zfree;
+ zcmd = qxqt->s.zcmd;
+ if (strchr (qxqt->s.zoptions, 'R') != NULL)
+ zrequestor = qxqt->s.znotify;
+ }
+ else
+ {
+ char *zxqt;
+
+ zxqt = zsysdep_spool_file_name (qsys, qxqt->s.zfrom,
+ qxqt->s.pseq);
+ if (zxqt == NULL)
+ return FALSE;
+
+ if (! fsxqt_file_read (puuconf, zxqt))
+ {
+ ubuffree (zxqt);
+ return FALSE;
+ }
+
+ ubuffree (zxqt);
+
+ zprog = zSxqt_prog;
+ zcmd = zSxqt_cmd;
+ zrequestor = zSxqt_requestor;
+ }
+
+ csize = 0L;
+ for (qsize = qlist; qsize != NULL; qsize = qsize->qnext)
+ {
+ if (qsize->s.bcmd == 'S' || qsize->s.bcmd == 'E')
+ {
+ char *zfile;
+
+ if (strchr (qsize->s.zoptions, 'C') != NULL
+ || fspool_file (qsize->s.zfrom))
+ zfile = zsysdep_spool_file_name (qsys, qsize->s.ztemp,
+ qsize->s.pseq);
+ else
+ zfile = zbufcpy (qsize->s.zfrom);
+ if (zfile != NULL)
+ {
+ long cbytes;
+
+ cbytes = csysdep_size (zfile);
+ if (cbytes > 0)
+ csize += cbytes;
+ ubuffree (zfile);
+ }
+ }
+ }
+
+ if (ccommands == 0)
+ fmatch = TRUE;
+ else
+ {
+ int i;
+
+ fmatch = fnotcommands;
+ for (i = 0; i < ccommands; i++)
+ {
+ if (strcmp (pazcommands[i], "ALL") == 0
+ || strcmp (pazcommands[i], zprog) == 0)
+ {
+ fmatch = ! fmatch;
+ break;
+ }
+ }
+ }
+
+ /* To get the name of the standard input file on this system
+ we have to look through the list of file transfers to
+ find the right one on the remote system. */
+ if (fmatch)
+ {
+ struct scmdlist *qstdin;
+
+ if (qxqt->s.bcmd == 'E')
+ qstdin = qxqt;
+ else if (zSxqt_stdin != NULL)
+ {
+ for (qstdin = qlist;
+ qstdin != NULL;
+ qstdin = qstdin->qnext)
+ if (qstdin->s.bcmd == 'S'
+ && strcmp (qstdin->s.zto, zSxqt_stdin) == 0)
+ break;
+ }
+ else
+ qstdin = NULL;
+
+ if (qstdin != NULL)
+ {
+ if (strchr (qstdin->s.zoptions, 'C') != NULL
+ || fspool_file (qstdin->s.zfrom))
+ zstdin = qstdin->s.ztemp;
+ else
+ zstdin = qstdin->s.zfrom;
+ }
+ }
+
+ if (fmatch && (icmd & JOB_SHOW) != 0)
+ {
+ usworkfile_header (qsys, &qxqt->s, zlistid, qxqt->itime,
+ TRUE);
+ printf ("Executing %s (sending %ld bytes)\n", zcmd, csize);
+ }
+ }
+
+ if (fmatch)
+ {
+ boolean fkill;
+
+ fkill = FALSE;
+ if ((icmd & JOB_INQUIRE) != 0)
+ {
+ int b;
+
+ /* Ask stdin whether this job should be killed. */
+ fprintf (stderr, "%s: Kill %s? ", abProgram, zlistid);
+ (void) fflush (stderr);
+ b = getchar ();
+ fkill = b == 'y' || b == 'Y';
+ while (b != EOF && b != '\n')
+ b = getchar ();
+ }
+ else if ((icmd & JOB_KILL) != 0)
+ fkill = TRUE;
+
+ if (fkill
+ && (qlist->s.zuser == NULL
+ || strcmp (zsysdep_login_name (), qlist->s.zuser) != 0)
+ && ! fsysdep_privileged ())
+ ulog (LOG_ERROR, "%s: Not submitted by you", zlistid);
+ else
+ {
+ if ((icmd & (JOB_MAIL | JOB_NOTIFY)) != 0)
+ {
+ if (! fsnotify (puuconf, icmd, zcomment, cstdin, fkill,
+ zcmd, qlist, zlistid, qlist->s.zuser,
+ qsys, zstdin, qlist->s.pseq, zrequestor))
+ return FALSE;
+ }
+
+ if (fkill)
+ {
+ if (! fsysdep_kill_job (puuconf, zlistid))
+ return FALSE;
+ }
+ }
+ }
+
+ if (qxqt != NULL)
+ {
+ if (qxqt->s.bcmd == 'E')
+ ubuffree (zfree);
+ else
+ usxqt_file_free ();
+ }
+
+ /* Free up the list of entries. */
+ qfree = qlist;
+ while (qfree != NULL)
+ {
+ struct scmdlist *qnext;
+
+ qnext = qfree->qnext;
+ xfree ((pointer) qfree);
+ qfree = qnext;
+ }
+
+ ubuffree (zlistid);
+
+ qlist = NULL;
+ zlistid = NULL;
+ }
+
+ /* Start a new list with the entry we just got. */
+ if (qcmd != NULL)
+ {
+ qlist = (struct scmdlist *) xmalloc (sizeof (struct scmdlist));
+ qlist->qnext = NULL;
+ qlist->s = *qcmd;
+ qlist->itime = itime;
+ zlistid = zid;
+ }
+
+ return TRUE;
+}
+
+/* Show the header of the line describing a workfile. */
+
+static void
+usworkfile_header (qsys, qcmd, zjobid, itime, ffirst)
+ const struct uuconf_system *qsys;
+ const struct scmd *qcmd;
+ const char *zjobid;
+ long itime;
+ boolean ffirst;
+{
+ const char *zshowid;
+ struct tm stime;
+
+ if (ffirst)
+ zshowid = zjobid;
+ else
+ zshowid = "-";
+
+ printf ("%s %s %s ", zshowid, qsys->uuconf_zname,
+ qcmd->zuser != NULL ? qcmd->zuser : OWNER);
+
+ usysdep_localtime (itime, &stime);
+ printf ("%02d-%02d %02d:%02d ",
+ stime.tm_mon + 1, stime.tm_mday, stime.tm_hour, stime.tm_min);
+}
+
+/* List queued executions that have not been processed by uuxqt for
+ one reason or another. */
+
+static boolean
+fsexecutions (puuconf, icmd, csystems, pazsystems, fnotsystems, cusers,
+ pazusers, fnotusers, iold, iyoung, ccommands, pazcommands,
+ fnotcommands, zcomment, cstdin)
+ pointer puuconf;
+ int icmd;
+ int csystems;
+ char **pazsystems;
+ boolean fnotsystems;
+ int cusers;
+ char **pazusers;
+ boolean fnotusers;
+ long iold;
+ long iyoung;
+ int ccommands;
+ char **pazcommands;
+ boolean fnotcommands;
+ const char *zcomment;
+ int cstdin;
+{
+ const char *zlocalname;
+ int iuuconf;
+ char *zfile;
+ char *zsystem;
+ boolean ferr;
+
+ iuuconf = uuconf_localname (puuconf, &zlocalname);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ zlocalname = zsysdep_localname ();
+ if (zlocalname == NULL)
+ return FALSE;
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+
+ if (! fsysdep_get_xqt_init ())
+ return FALSE;
+
+ while ((zfile = zsysdep_get_xqt (&zsystem, &ferr)) != NULL)
+ {
+ boolean fmatch;
+ int i;
+ long itime;
+
+ if (csystems > 0)
+ {
+ fmatch = fnotsystems;
+ for (i = 0; i < csystems; i++)
+ {
+ if (strcmp (pazsystems[i], zsystem) == 0)
+ {
+ fmatch = ! fmatch;
+ break;
+ }
+ }
+ if (! fmatch)
+ {
+ ubuffree (zfile);
+ ubuffree (zsystem);
+ continue;
+ }
+ }
+
+ itime = ixsysdep_file_time (zfile);
+
+ if ((iold != (long) -1 && itime > iold)
+ || (iyoung != (long) -1 && itime < iyoung))
+ {
+ ubuffree (zfile);
+ ubuffree (zsystem);
+ continue;
+ }
+
+ /* We need to read the execution file before we can check the
+ user name. */
+ if (! fsxqt_file_read (puuconf, zfile))
+ {
+ ubuffree (zfile);
+ ubuffree (zsystem);
+ continue;
+ }
+
+ if (cusers == 0)
+ fmatch = TRUE;
+ else
+ {
+ fmatch = fnotusers;
+ for (i = 0; i < cusers; i++)
+ {
+ if (strcmp (zSxqt_user, pazusers[i]) == 0
+ || (zSxqt_requestor != NULL
+ && strcmp (zSxqt_requestor, pazusers[i]) == 0))
+ {
+ fmatch = ! fmatch;
+ break;
+ }
+ }
+ }
+
+ if (fmatch && ccommands > 0)
+ {
+ fmatch = fnotcommands;
+ for (i = 0; i < ccommands; i++)
+ {
+ if (strcmp (pazcommands[i], "ALL") == 0
+ || strcmp (pazcommands[i], zSxqt_prog) == 0)
+ {
+ fmatch = ! fmatch;
+ break;
+ }
+ }
+ }
+
+ if (fmatch)
+ {
+ boolean fbad, fkill;
+ struct uuconf_system ssys;
+
+ fbad = FALSE;
+
+ if ((icmd & JOB_SHOW) != 0)
+ {
+ struct tm stime;
+
+ printf ("%s %s!", zsystem, zSxqt_system);
+ if (zSxqt_requestor != NULL)
+ printf ("%s", zSxqt_requestor);
+ else
+ printf ("%s", zSxqt_user);
+
+ usysdep_localtime (itime, &stime);
+ printf (" %02d-%02d %02d:%02d ",
+ stime.tm_mon + 1, stime.tm_mday, stime.tm_hour,
+ stime.tm_min);
+
+ printf ("%s\n", zSxqt_cmd);
+ }
+
+ fkill = FALSE;
+ if ((icmd & JOB_INQUIRE) != 0)
+ {
+ int b;
+
+ /* Ask stdin whether this job should be killed. */
+ fprintf (stderr, "%s: Kill %s? ", abProgram, zSxqt_cmd);
+ (void) fflush (stderr);
+ b = getchar ();
+ fkill = b == 'y' || b == 'Y';
+ while (b != EOF && b != '\n')
+ b = getchar ();
+ }
+ else if ((icmd & JOB_KILL) != 0)
+ fkill = TRUE;
+
+ if (fkill)
+ {
+ if ((strcmp (zSxqt_user, zsysdep_login_name ()) != 0
+ || strcmp (zsystem, zlocalname) != 0)
+ && ! fsysdep_privileged ())
+ {
+ ulog (LOG_ERROR, "Job not submitted by you\n");
+ fbad = TRUE;
+ }
+ }
+
+ if (! fbad)
+ {
+ iuuconf = uuconf_system_info (puuconf, zsystem, &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf != UUCONF_NOT_FOUND)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ fbad = TRUE;
+ }
+ else if (strcmp (zsystem, zlocalname) == 0)
+ {
+ iuuconf = uuconf_system_local (puuconf, &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ fbad = TRUE;
+ }
+ }
+ else if (! funknown_system (puuconf, zsystem, &ssys))
+ {
+ ulog (LOG_ERROR, "Job for unknown system %s",
+ zsystem);
+ fbad = TRUE;
+ }
+ }
+ }
+
+ if (! fbad && (icmd & (JOB_MAIL | JOB_NOTIFY)) != 0)
+ {
+ if (! fsnotify (puuconf, icmd, zcomment, cstdin, fkill,
+ zSxqt_cmd, (struct scmdlist *) NULL,
+ (const char *) NULL, zSxqt_user, &ssys,
+ zSxqt_stdin, (pointer) NULL, zSxqt_requestor))
+ {
+ ferr = TRUE;
+ usxqt_file_free ();
+ ubuffree (zfile);
+ ubuffree (zsystem);
+ break;
+ }
+ }
+
+ if (! fbad && fkill)
+ {
+ for (i = 0; i < cSxqt_files; i++)
+ {
+ char *z;
+
+ z = zsysdep_spool_file_name (&ssys, pazSxqt_files[i],
+ (pointer) NULL);
+ if (z != NULL)
+ {
+ (void) remove (z);
+ ubuffree (z);
+ }
+ }
+ if (remove (zfile) != 0)
+ ulog (LOG_ERROR, "remove (%s): %s", zfile,
+ strerror (errno));
+ }
+
+ if (! fbad)
+ (void) uuconf_system_free (puuconf, &ssys);
+ }
+
+ usxqt_file_free ();
+ ubuffree (zfile);
+ ubuffree (zsystem);
+ }
+
+ usysdep_get_xqt_free ();
+
+ return ferr;
+}
+
+/* When a job is killed, send mail to the appropriate people. */
+
+static boolean
+fsnotify (puuconf, icmd, zcomment, cstdin, fkilled, zcmd, qcmd, zid, zuser,
+ qsys, zstdin, pstdinseq, zrequestor)
+ pointer puuconf;
+ int icmd;
+ const char *zcomment;
+ int cstdin;
+ boolean fkilled;
+ const char *zcmd;
+ struct scmdlist *qcmd;
+ const char *zid;
+ const char *zuser;
+ const struct uuconf_system *qsys;
+ const char *zstdin;
+ pointer pstdinseq;
+ const char *zrequestor;
+{
+ const char **pz;
+ int cgot;
+ int i, istdin;
+ const char *zsubject;
+ boolean fret;
+
+ pz = (const char **) xmalloc (20 * sizeof (const char *));
+ cgot = 20;
+
+ i = 0;
+ if (zid == NULL)
+ pz[i++] = "A UUCP execution request";
+ else
+ {
+ pz[i++] = "UUCP job\n\t";
+ pz[i++] = zid;
+ pz[i++] = "\nfor system\n\t";
+ pz[i++] = qsys->uuconf_zname;
+ }
+ pz[i++] = "\nrequested by\n\t";
+ pz[i++] = zuser != NULL ? zuser : OWNER;
+ if (zid == NULL)
+ {
+ pz[i++] = "\non system\n\t";
+ pz[i++] = qsys->uuconf_zname;
+ }
+ pz[i++] = "\n";
+
+ if (fkilled)
+ pz[i++] = "has been killed.\n";
+
+ if (zcomment != NULL)
+ {
+ pz[i++] = zcomment;
+ pz[i++] = "\n";
+ }
+
+ pz[i++] = "The job ";
+ if (fkilled)
+ pz[i++] = "was\n";
+ else
+ pz[i++] = "is\n";
+
+ if (zcmd != NULL)
+ {
+ pz[i++] = "\t";
+ pz[i++] = zcmd;
+ }
+ else
+ {
+ struct scmdlist *qshow;
+
+ for (qshow = qcmd; qshow != NULL; qshow = qshow->qnext)
+ {
+ if (i + 10 > cgot)
+ {
+ cgot += 20;
+ pz = (const char **) xrealloc ((pointer) pz,
+ cgot * sizeof (const char *));
+ }
+
+ switch (qshow->s.bcmd)
+ {
+ case 'S':
+ pz[i++] = "\tsend ";
+ break;
+ default:
+ case 'R':
+ case 'X':
+ pz[i++] = "\trequest ";
+ break;
+ case 'P':
+ pz[i++] = "\tpoll ";
+#if DEBUG > 0
+ case 'E':
+ ulog (LOG_FATAL, "fsnotify: Can't happen");
+ break;
+#endif
+ }
+ if (qshow->s.zfrom != NULL && qshow->s.zto != NULL)
+ {
+ pz[i++] = qshow->s.zfrom;
+ pz[i++] = " to ";
+ pz[i++] = qshow->s.zto;
+ }
+ }
+ }
+
+ istdin = i;
+ if (cstdin > 0 && zstdin != NULL)
+ {
+ boolean fspool;
+ char *zfile;
+ FILE *e;
+
+ fspool = fspool_file (zstdin);
+ if (fspool)
+ zfile = zsysdep_spool_file_name (qsys, zstdin, pstdinseq);
+ else
+ zfile = zsysdep_local_file (zstdin, qsys->uuconf_zpubdir);
+
+ if (zfile != NULL
+ && (fspool
+ || fin_directory_list (zfile, qsys->uuconf_pzremote_send,
+ qsys->uuconf_zpubdir, TRUE, TRUE,
+ (const char *) NULL)))
+ {
+ e = fopen (zfile, "r");
+ if (e != NULL)
+ {
+ int clines, clen;
+ char *zline;
+ size_t cline;
+
+ pz[i++] = "\n";
+ istdin = i;
+
+ clines = 0;
+
+ zline = NULL;
+ cline = 0;
+ while ((clen = getline (&zline, &cline, e)) > 0)
+ {
+ if (memchr (zline, '\0', (size_t) clen) != NULL)
+ {
+ int ifree;
+
+ /* A null character means this is probably a
+ binary file. */
+ for (ifree = istdin; ifree < i; ifree++)
+ ubuffree ((char *) pz[ifree]);
+ i = istdin - 1;
+ break;
+ }
+ ++clines;
+ if (clines > cstdin)
+ break;
+ if (i >= cgot)
+ {
+ cgot += 20;
+ pz = (const char **) xrealloc ((pointer) pz,
+ (cgot
+ * sizeof (char *)));
+ }
+ pz[i++] = zbufcpy (zline);
+ }
+ xfree ((pointer) zline);
+ (void) fclose (e);
+ }
+ }
+
+ ubuffree (zfile);
+ }
+
+ if (fkilled)
+ zsubject = "UUCP job killed";
+ else
+ zsubject = "UUCP notification";
+
+ fret = TRUE;
+
+ if ((icmd & JOB_MAIL) != 0)
+ {
+ if (! fsysdep_mail (OWNER, zsubject, i, pz))
+ fret = FALSE;
+ }
+
+ if ((icmd & JOB_NOTIFY) != 0
+ && (zrequestor != NULL || zuser != NULL))
+ {
+ const char *zmail;
+ char *zfree;
+
+ if (zrequestor != NULL)
+ zmail = zrequestor;
+ else
+ zmail = zuser;
+
+ zfree = NULL;
+
+ if (zid == NULL)
+ {
+ int iuuconf;
+ const char *zloc;
+
+ /* This is an execution request, which may be from another
+ system. If it is, we must prepend that system name to
+ the user name extracted from the X. file. */
+ iuuconf = uuconf_localname (puuconf, &zloc);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ zloc = zsysdep_localname ();
+ if (zloc == NULL)
+ return FALSE;
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ if (strcmp (qsys->uuconf_zname, zloc) != 0
+#if HAVE_INTERNET_MAIL
+ && strchr (zmail, '@') == NULL
+#endif
+ )
+ {
+ zfree = zbufalc (strlen (qsys->uuconf_zname)
+ + strlen (zmail)
+ + sizeof "!");
+ sprintf (zfree, "%s!%s", qsys->uuconf_zname, zmail);
+ zmail = zfree;
+ }
+ }
+
+ if (! fsysdep_mail (zmail, zsubject, i, pz))
+ fret = FALSE;
+
+ ubuffree (zfree);
+ }
+
+ while (istdin < i)
+ {
+ ubuffree ((char *) pz[istdin]);
+ istdin++;
+ }
+
+ xfree ((pointer) pz);
+
+ return fret;
+}
+
+/* Handle the -q option. For each remote system this lists the number
+ of jobs queued, the number of executions queued, and the current
+ call status. We get the executions all at once, because they are
+ not accessed by system. They could be, but it is possible to have
+ executions pending for an unknown system, so special handling would
+ still be required. */
+
+struct sxqtlist
+{
+ struct sxqtlist *qnext;
+ char *zsystem;
+ int cxqts;
+ long ifirst;
+};
+
+/* These local functions need the definition of sxqtlist for the
+ prototype. */
+
+static boolean fsquery_system P((const struct uuconf_system *qsys,
+ struct sxqtlist **pq,
+ long inow, const char *zlocalname));
+static boolean fsquery_show P((const struct uuconf_system *qsys, int cwork,
+ long ifirstwork,
+ struct sxqtlist *qxqt,
+ long inow, const char *zlocalname));
+
+static boolean
+fsquery (puuconf)
+ pointer puuconf;
+{
+ int iuuconf;
+ const char *zlocalname;
+ struct sxqtlist *qlist;
+ char *zfile, *zsystem;
+ boolean ferr;
+ long inow;
+ char **pznames, **pz;
+ boolean fret;
+
+ iuuconf = uuconf_localname (puuconf, &zlocalname);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ zlocalname = zsysdep_localname ();
+ if (zlocalname == NULL)
+ return FALSE;
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+
+ /* Get a count of all the execution files. */
+ if (! fsysdep_get_xqt_init ())
+ return FALSE;
+
+ qlist = NULL;
+ while ((zfile = zsysdep_get_xqt (&zsystem, &ferr)) != NULL)
+ {
+ struct sxqtlist *qlook;
+
+ for (qlook = qlist; qlook != NULL; qlook = qlook->qnext)
+ if (strcmp (zsystem, qlook->zsystem) == 0)
+ break;
+
+ if (qlook != NULL)
+ {
+ long itime;
+
+ ubuffree (zsystem);
+ ++qlook->cxqts;
+ itime = ixsysdep_file_time (zfile);
+ if (itime < qlook->ifirst)
+ qlook->ifirst = itime;
+ }
+ else
+ {
+ struct sxqtlist *qnew;
+
+ qnew = (struct sxqtlist *) xmalloc (sizeof (struct sxqtlist));
+ qnew->qnext = qlist;
+ qnew->zsystem = zsystem;
+ qnew->cxqts = 1;
+ qnew->ifirst = ixsysdep_file_time (zfile);
+ qlist = qnew;
+ }
+
+ ubuffree (zfile);
+ }
+
+ usysdep_get_xqt_free ();
+
+ if (ferr)
+ return FALSE;
+
+ inow = ixsysdep_time ((long *) NULL);
+
+ /* Show the information for each system. */
+ iuuconf = uuconf_system_names (puuconf, &pznames, 0);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return FALSE;
+ }
+
+ fret = TRUE;
+
+ for (pz = pznames; *pz != NULL; pz++)
+ {
+ struct uuconf_system ssys;
+
+ iuuconf = uuconf_system_info (puuconf, *pz, &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ fret = FALSE;
+ continue;
+ }
+
+ if (! fsquery_system (&ssys, &qlist, inow, zlocalname))
+ fret = FALSE;
+
+ (void) uuconf_system_free (puuconf, &ssys);
+ xfree ((pointer) *pz);
+ }
+
+ /* Check for the local system in the list of execution files. */
+ if (qlist != NULL)
+ {
+ struct sxqtlist **pq;
+
+ for (pq = &qlist; *pq != NULL; pq = &(*pq)->qnext)
+ {
+ if (strcmp ((*pq)->zsystem, zlocalname) == 0)
+ {
+ struct uuconf_system ssys;
+ struct sxqtlist *qfree;
+
+ iuuconf = uuconf_system_info (puuconf, zlocalname, &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf != UUCONF_NOT_FOUND)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ fret = FALSE;
+ break;
+ }
+
+ iuuconf = uuconf_system_local (puuconf, &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ fret = FALSE;
+ break;
+ }
+ ssys.uuconf_zname = (char *) zlocalname;
+ }
+
+ if (! fsquery_show (&ssys, 0, 0L, *pq, inow, zlocalname))
+ fret = FALSE;
+ (void) uuconf_system_free (puuconf, &ssys);
+ qfree = *pq;
+ *pq = qfree->qnext;
+ ubuffree (qfree->zsystem);
+ xfree ((pointer) qfree);
+ break;
+ }
+ }
+ }
+
+ /* Print out information for any unknown systems for which we have
+ execution files. */
+ while (qlist != NULL)
+ {
+ struct uuconf_system ssys;
+ struct sxqtlist *qnext;
+
+ if (! funknown_system (puuconf, qlist->zsystem, &ssys))
+ {
+ ulog (LOG_ERROR, "Executions queued up for unknown systems");
+ fret = FALSE;
+ break;
+ }
+
+ if (! fsquery_show (&ssys, 0, 0L, qlist, inow, zlocalname))
+ fret = FALSE;
+ (void) uuconf_system_free (puuconf, &ssys);
+ qnext = qlist->qnext;
+ ubuffree (qlist->zsystem);
+ xfree ((pointer) qlist);
+ qlist = qnext;
+ }
+
+ return fret;
+}
+
+/* Query a single known system. */
+
+static boolean
+fsquery_system (qsys, pq, inow, zlocalname)
+ const struct uuconf_system *qsys;
+ struct sxqtlist **pq;
+ long inow;
+ const char *zlocalname;
+{
+ int cwork;
+ long ifirstwork;
+ char *zid;
+ boolean fret;
+
+ if (! fsysdep_get_work_init (qsys, UUCONF_GRADE_LOW))
+ return FALSE;
+
+ cwork = 0;
+ ifirstwork = 0L;
+ zid = NULL;
+ while (TRUE)
+ {
+ struct scmd s;
+ long itime;
+ char *zthisid;
+
+ if (! fsysdep_get_work (qsys, UUCONF_GRADE_LOW, &s))
+ return FALSE;
+ if (s.bcmd == 'H')
+ break;
+
+ zthisid = zsysdep_jobid (qsys, s.pseq);
+ if (zid != NULL && strcmp (zid, zthisid) == 0)
+ ubuffree (zthisid);
+ else
+ {
+ ++cwork;
+ ubuffree (zid);
+ zid = zthisid;
+ }
+
+ itime = ixsysdep_work_time (qsys, s.pseq);
+ if (ifirstwork == 0L || ifirstwork > itime)
+ ifirstwork = itime;
+ }
+
+ usysdep_get_work_free (qsys);
+ ubuffree (zid);
+
+ /* Find the execution information, if any. */
+ while (*pq != NULL)
+ {
+ if (strcmp ((*pq)->zsystem, qsys->uuconf_zname) == 0)
+ break;
+ pq = &(*pq)->qnext;
+ }
+
+ /* If there are no commands and no executions, don't print any
+ information for this system. */
+ if (cwork == 0 && *pq == NULL)
+ return TRUE;
+
+ fret = fsquery_show (qsys, cwork, ifirstwork, *pq, inow, zlocalname);
+
+ if (*pq != NULL)
+ {
+ struct sxqtlist *qfree;
+
+ qfree = *pq;
+ *pq = qfree->qnext;
+ ubuffree (qfree->zsystem);
+ xfree ((pointer) qfree);
+ }
+
+ return fret;
+}
+
+/* Print out the query information for a single system. We handle the
+ local system specially. */
+
+static boolean
+fsquery_show (qsys, cwork, ifirstwork, qxqt, inow, zlocalname)
+ const struct uuconf_system *qsys;
+ int cwork;
+ long ifirstwork;
+ struct sxqtlist *qxqt;
+ long inow;
+ const char *zlocalname;
+{
+ boolean flocal;
+ struct sstatus sstat;
+ boolean fnostatus;
+ struct tm stime;
+ int cpad;
+
+ flocal = strcmp (qsys->uuconf_zname, zlocalname) == 0;
+
+ if (! flocal)
+ {
+ if (! fsysdep_get_status (qsys, &sstat, &fnostatus))
+ return FALSE;
+ }
+
+ printf ("%-10s %3dC (", qsys->uuconf_zname, cwork);
+
+ if (cwork == 0)
+ {
+ printf ("0 secs");
+ cpad = 3;
+ }
+ else
+ cpad = csunits_show (inow - ifirstwork);
+
+ printf (") ");
+ while (cpad-- != 0)
+ printf (" ");
+
+ if (qxqt == NULL)
+ printf (" 0X (0 secs) ");
+ else
+ {
+ printf ("%3dX (", qxqt->cxqts);
+ cpad = csunits_show (inow - qxqt->ifirst);
+ printf (")");
+ while (cpad-- != 0)
+ printf (" ");
+ }
+
+ if (flocal || fnostatus)
+ {
+ printf ("\n");
+ return TRUE;
+ }
+
+ usysdep_localtime (sstat.ilast, &stime);
+
+ printf (" %02d-%02d %02d:%02d ",
+ stime.tm_mon + 1,stime.tm_mday, stime.tm_hour, stime.tm_min);
+
+ printf ("%s\n", azStatus[(int) sstat.ttype]);
+
+ return TRUE;
+}
+
+/* Print a time difference in the largest applicable units. */
+
+static int
+csunits_show (idiff)
+ long idiff;
+{
+ const char *zunit;
+ long iunits;
+ int cpad;
+
+ if (idiff > (long) 24 * (long) 60 * (long) 60)
+ {
+ iunits = idiff / ((long) 24 * (long) 60 * (long) 60);
+ zunit = "day";
+ cpad = 4;
+ }
+ else if (idiff > (long) 60 * 60)
+ {
+ iunits = idiff / (long) (60 * 60);
+ zunit = "hour";
+ cpad = 3;
+ }
+ else if (idiff > (long) 60)
+ {
+ iunits = idiff / (long) 60;
+ zunit = "min";
+ cpad = 4;
+ }
+ else
+ {
+ iunits = idiff;
+ zunit = "sec";
+ cpad = 4;
+ }
+
+ printf ("%ld %s%s", iunits, zunit, iunits == 1 ? "" : "s");
+
+ if (iunits != 1)
+ --cpad;
+ if (iunits > 99)
+ --cpad;
+ if (iunits > 9)
+ --cpad;
+ return cpad;
+}
+
+/* Give a list of all status entries for all machines that we have
+ status entries for. We need to get a list of status entries in a
+ system dependent fashion, since we may have status for unknown
+ systems. */
+
+static boolean
+fsmachines ()
+{
+ pointer phold;
+ char *zsystem;
+ boolean ferr;
+ struct sstatus sstat;
+
+ if (! fsysdep_all_status_init (&phold))
+ return FALSE;
+
+ while ((zsystem = zsysdep_all_status (phold, &ferr, &sstat)) != NULL)
+ {
+ struct tm stime;
+
+ usysdep_localtime (sstat.ilast, &stime);
+ printf ("%-14s %02d-%02d %02d:%02d %s", zsystem,
+ stime.tm_mon + 1, stime.tm_mday, stime.tm_hour,
+ stime.tm_min, azStatus[(int) sstat.ttype]);
+ ubuffree (zsystem);
+ if (sstat.ttype != STATUS_TALKING
+ && sstat.cwait > 0)
+ {
+ printf (" (%d %s", sstat.cretries,
+ sstat.cretries == 1 ? "try" : "tries");
+ if (sstat.ilast + sstat.cwait > ixsysdep_time ((long *) NULL))
+ {
+ usysdep_localtime (sstat.ilast + sstat.cwait, &stime);
+ printf (", next after %02d-%02d %02d:%02d",
+ stime.tm_mon + 1, stime.tm_mday, stime.tm_hour,
+ stime.tm_min);
+ }
+ printf (")");
+ }
+ printf ("\n");
+ }
+
+ usysdep_all_status_free (phold);
+
+ return ! ferr;
+}
diff --git a/gnu/libexec/uucp/uuto/Makefile b/gnu/libexec/uucp/uuto/Makefile
new file mode 100644
index 00000000000..f5457d86790
--- /dev/null
+++ b/gnu/libexec/uucp/uuto/Makefile
@@ -0,0 +1,13 @@
+# Makefile for uuto
+
+BINDIR= $(bindir)
+
+PROG= uuto
+SRCS=
+NOMAN=
+
+uuto: uuto.in
+ sed -e "s|@BINDIR@|$(bindir)|g" -e "s|@SBINDIR@|$(sbindir)|g" \
+ $(.CURDIR)/uuto.in > $(.TARGET)
+
+.include <bsd.prog.mk>
diff --git a/gnu/libexec/uucp/uuto/uuto.in b/gnu/libexec/uucp/uuto/uuto.in
new file mode 100644
index 00000000000..2d7d96a9587
--- /dev/null
+++ b/gnu/libexec/uucp/uuto/uuto.in
@@ -0,0 +1,16 @@
+:
+# uuto
+# Send files to a user on another system.
+#
+# Copyright (C) 1992 Ian Lance Taylor
+#
+# Please feel free do whatever you like with this exciting shell
+# script.
+#
+# This is pretty trivial, since all the functionality was moved into
+# uucp itself. The -t means to interpret the final argument as
+# system!user, the -R means to copy directories recursively, and the
+# -c means to not copy the files to the spool directory (may be
+# overriden by -C or -p).
+#
+@BINDIR@/uucp -t -R -c $*
diff --git a/gnu/libexec/uucp/uux/Makefile b/gnu/libexec/uucp/uux/Makefile
new file mode 100644
index 00000000000..87c9ea9de0e
--- /dev/null
+++ b/gnu/libexec/uucp/uux/Makefile
@@ -0,0 +1,15 @@
+# Makefile for uux
+
+BINDIR= $(bindir)
+BINOWN= $(owner)
+BINMODE= 4555
+
+PROG= uux
+SRCS= uux.c util.c log.c copy.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -DVERSION=\"$(VERSION)\"
+
+.include <bsd.prog.mk>
+.PATH: $(.CURDIR)/../common_sources
diff --git a/gnu/libexec/uucp/uux/uux.1 b/gnu/libexec/uucp/uux/uux.1
new file mode 100644
index 00000000000..69c85abb51b
--- /dev/null
+++ b/gnu/libexec/uucp/uux/uux.1
@@ -0,0 +1,234 @@
+''' $Id: uux.1,v 1.1 1993/08/04 19:37:13 jtc Exp $
+.TH uux 1 "Taylor UUCP 1.04"
+.SH NAME
+uux \- Remote command execution over UUCP
+.SH SYNOPSIS
+.B uux
+[ options ] command
+.SH DESCRIPTION
+The
+.I uux
+command is used to execute a command on a remote system, or to execute
+a command on the local system using files from remote systems.
+The command
+is not executed immediately; the request is queued until the
+.I uucico
+(8) daemon calls the system and executes it. The daemon is
+started automatically unless the
+.B \-r
+switch is given.
+
+The actual command execution is done by the
+.I uuxqt
+(8) daemon.
+
+File arguments can be gathered from remote systems to the execution
+system, as can standard input. Standard output may be directed to a
+file on a remote system.
+
+The command name may be preceded by a system name followed by an
+exclamation point if it is to be executed on a remote system. An
+empty system name is taken as the local system.
+
+Each argument that contains an exclamation point is treated as naming
+a file. The system which the file is on is before the exclamation
+point, and the pathname on that system follows it. An empty system
+name is taken as the local system; this must be used to transfer a
+file to a command being executed on a remote system. If the path is
+not absolute, it will be appended to the current working directory on
+the local system; the result may not be meaningful on the remote
+system. A pathname may begin with ~/, in which case it is relative to
+the UUCP public directory (usually /usr/spool/uucppublic) on the
+appropriate system. A pathname may begin with ~name/, in which case
+it is relative to the home directory of the named user on the
+appropriate system.
+
+Standard input and output may be redirected as usual; the pathnames
+used may contain exclamation points to indicate that they are on
+remote systems. Note that the redirection characters must be quoted
+so that they are passed to
+.I uux
+rather than interpreted by the shell. Append redirection (>>) does
+not work.
+
+All specified files are gathered together into a single directory
+before execution of the command begins. This means that each file
+must have a distinct base name. For example,
+.EX
+uux 'sys1!diff sys2!~user1/foo sys3!~user2/foo >!foo.diff'
+.EE
+will fail because both files will be copied to sys1 and stored under
+the name foo.
+
+Arguments may be quoted by parentheses to avoid interpretation of
+exclamation points. This is useful when executing the
+.I uucp
+command on a remote system.
+.SH OPTIONS
+The following options may be given to
+.I uux.
+.TP 5
+.B \-,\-p
+Read standard input and use it as the standard input for the command
+to be executed.
+.TP 5
+.B \-c
+Do not copy local files to the spool directory. This is the default.
+If they are
+removed before being processed by the
+.I uucico
+(8) daemon, the copy will fail. The files must be readable by the
+.I uucico
+(8) daemon,
+as well as the by the invoker of
+.I uux.
+.TP 5
+.B \-C
+Copy local files to the spool directory.
+.TP 5
+.B \-l
+Link local files into the spool directory. If a file can not be
+linked because it is on a different device, it will be copied unless
+the
+.B \-c
+option also appears (in other words, use of
+.B \-l
+switches the default from
+.B \-c
+to
+.B \-C).
+If the files are changed before being processed by the
+.I uucico
+(8) daemon, the changed versions will be used. The files must be
+readable by the
+.I uucico
+(8) daemon, as well as by the invoker of
+.I uux.
+.TP 5
+.B \-g grade
+Set the grade of the file transfer command. Jobs of a higher grade
+are executed first. Grades run 0 ... 9 A ... Z a ... z from high to
+low.
+.TP 5
+.B \-n
+Do not send mail about the status of the job, even if it fails.
+.TP 5
+.B \-z
+Send mail about the status of the job if an error occurs. For many
+.I uuxqt
+daemons, including the Taylor UUCP
+.I uuxqt,
+this is the default action; for those,
+.B \-z
+will have no effect. However, some
+.I uuxqt
+daemons will send mail if the job succeeds unless the
+.B \-z
+option is used, and some other
+.I uuxqt
+daemons will not send mail if the job fails unless the
+.B \-z
+option is used.
+.TP 5
+.B \-r
+Do not start the
+.I uucico
+(8) daemon immediately; merely queue up the execution request for later
+processing.
+.TP 5
+.B \-j
+Print jobids on standard output. A jobid will be generated for each
+file copy operation required to perform the operation. These file
+copies may be cancelled by
+passing the jobid to the
+.B \-k
+switch of
+.I uustat
+(1), which will make the execution impossible to complete.
+.TP 5
+.B \-a address
+Report job status to the specified e-mail address.
+.TP 5
+.B \-x type
+Turn on particular debugging types. The following types are
+recognized: abnormal, chat, handshake, uucp-proto, proto, port,
+config, spooldir, execute, incoming, outgoing. Only abnormal, config,
+spooldir and execute are meaningful for
+.I uux.
+
+Multiple types may be given, separated by commas, and the
+.B \-x
+option may appear multiple times. A number may also be given, which
+will turn on that many types from the foregoing list; for example,
+.B \-x 2
+is equivalent to
+.B \-x abnormal,chat.
+.TP 5
+.B \-I file
+Set configuration file to use. This option may not be available,
+depending upon how
+.I uux
+was compiled.
+.SH EXAMPLES
+.EX
+uux -z - sys1!rmail user1
+.EE
+Execute the command ``rmail user1'' on the system sys1, giving it as
+standard input whatever is given to
+.I uux
+as standard input. If a failure occurs, send a message using
+.I mail
+(1).
+.EX
+uux 'diff -c sys1!~user1/file1 sys2!~user2/file2 >!file.diff'
+.EE
+Fetch the two named files from system sys1 and system sys2 and execute
+.I diff
+putting the result in file.diff in the current directory. The current
+directory must be writable by the
+.I uuxqt
+(8) daemon for this to work.
+.EX
+uux 'sys1!uucp ~user1/file1 (sys2!~user2/file2)'
+.EE
+Execute
+.I uucp
+on the system sys1 copying file1 (on system sys1) to sys2. This
+illustrates the use of parentheses for quoting.
+.SH RESTRICTIONS
+The remote system may not permit you to execute certain commands.
+Many remote systems only permit the execution of
+.I rmail
+and
+.I rnews.
+
+Some of the options are dependent on the capabilities of the
+.I uuxqt
+(8) daemon on the remote system.
+.SH FILES
+The file names may be changed at compilation time or by the
+configuration file, so these are only approximations.
+
+.br
+/usr/lib/uucp/config - Configuration file.
+.br
+/usr/spool/uucp -
+UUCP spool directory.
+.br
+/usr/spool/uucp/Log -
+UUCP log file.
+.br
+/usr/spool/uucppublic -
+Default UUCP public directory.
+.SH SEE ALSO
+mail(1), uustat(1), uucp(1), uucico(8), uuxqt(8)
+.SH BUGS
+Files can not be referenced across multiple systems.
+
+Too many jobids are output by
+.B \-j,
+and there is no good way to cancel a local execution requiring remote
+files.
+.SH AUTHOR
+Ian Lance Taylor
+(ian@airs.com or uunet!airs!ian)
diff --git a/gnu/libexec/uucp/uux/uux.c b/gnu/libexec/uucp/uux/uux.c
new file mode 100644
index 00000000000..5dc98661483
--- /dev/null
+++ b/gnu/libexec/uucp/uux/uux.c
@@ -0,0 +1,1502 @@
+/* uux.c
+ Prepare to execute a command on a remote system.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char uux_rcsid[] = "$Id: uux.c,v 1.1 1993/08/04 19:37:14 jtc Exp $";
+#endif
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+#include "sysdep.h"
+#include "getopt.h"
+
+#include <ctype.h>
+#include <errno.h>
+
+/* These character lists should, perhaps, be in sysdep.h. */
+
+/* This is the list of shell metacharacters that we check for. If one
+ of these is present, we request uuxqt to execute the command with
+ /bin/sh. Otherwise we let it execute using execve. */
+
+#define ZSHELLCHARS "\"'`*?[;&()|<>\\$"
+
+/* This is the list of word separators. We break filename arguments
+ at these characters. */
+#define ZSHELLSEPS ";&*|<> \t"
+
+/* This is the list of word separators without the redirection
+ operators. */
+#define ZSHELLNONREDIRSEPS ";&*| \t"
+
+/* The program name. */
+char abProgram[] = "uux";
+
+/* The name of the execute file. */
+const char *zXxqt_name;
+
+/* The execute file we are creating. */
+static FILE *eXxqt_file;
+
+/* A list of commands to be spooled. */
+static struct scmd *pasXcmds;
+static int cXcmds;
+
+/* A file to close if we're forced to exit. */
+static FILE *eXclose;
+
+/* Local functions. */
+static void uxusage P((void));
+static void uxadd_xqt_line P((int bchar, const char *z1, const char *z2));
+static void uxadd_send_file P((const char *zfrom, const char *zto,
+ const char *zoptions, const char *ztemp,
+ const char *zforward,
+ const struct uuconf_system *qxqtsys,
+ const char *zxqtloc,
+ int bgrade));
+static void uxcopy_stdin P((FILE *e));
+static void uxrecord_file P((const char *zfile));
+static void uxabort P((void));
+
+/* Long getopt options. */
+static const struct option asXlongopts[] = { { NULL, 0, NULL, 0 } };
+
+/* The main routine. */
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ /* -a: requestor address for status reports. */
+ const char *zrequestor = NULL;
+ /* -b: if true, return standard input on error. */
+ boolean fretstdin = FALSE;
+ /* -c,-C: if true, copy to spool directory. */
+ boolean fcopy = FALSE;
+ /* -c: set if -c appears explicitly; if it and -l appear, then if the
+ link fails we don't copy the file. */
+ boolean fdontcopy = FALSE;
+ /* -I: configuration file name. */
+ const char *zconfig = NULL;
+ /* -j: output job id. */
+ boolean fjobid = FALSE;
+ /* -g: job grade. */
+ char bgrade = BDEFAULT_UUX_GRADE;
+ /* -l: link file to spool directory. */
+ boolean flink = FALSE;
+ /* -n: do not notify upon command completion. */
+ boolean fno_ack = FALSE;
+ /* -p: read standard input for command standard input. */
+ boolean fread_stdin = FALSE;
+ /* -r: do not start uucico when finished. */
+ boolean fuucico = TRUE;
+ /* -s: report status to named file. */
+ const char *zstatus_file = NULL;
+ /* -W: only expand local file names. */
+ boolean fexpand = TRUE;
+ /* -z: report status only on error. */
+ boolean ferror_ack = FALSE;
+ int iopt;
+ pointer puuconf;
+ int iuuconf;
+ const char *zlocalname;
+ const char *zxqtloc;
+ int i;
+ size_t clen;
+ char *zargs;
+ char *zarg;
+ char *zcmd;
+ const char *zsys;
+ char *zexclam;
+ boolean fgetcwd;
+ const char *zuser;
+ struct uuconf_system sxqtsys;
+ boolean fxqtlocal;
+ char *zforward;
+ char **pzargs;
+ int calloc_args;
+ int cargs;
+ char abxqt_tname[CFILE_NAME_LEN];
+ char abxqt_xname[CFILE_NAME_LEN];
+ const char *zinput_from;
+ const char *zinput_to;
+ const char *zinput_temp;
+ boolean finputcopied;
+ char *zcall_system;
+ boolean fcall_any;
+ struct uuconf_system slocalsys;
+ boolean fneedshell;
+ char *zfullcmd;
+ boolean fexit;
+
+ /* We need to be able to read a single - as an option, which getopt
+ won't do. So that we can still use getopt, we run through the
+ options looking for an option "-"; if we find one we change it to
+ "-p", which is equivalent to "-". */
+ for (i = 1; i < argc; i++)
+ {
+ if (argv[i][0] != '-')
+ break;
+ if (argv[i][1] == '\0')
+ argv[i] = zbufcpy ("-p");
+ else
+ {
+ const char *z;
+
+ for (z = argv[i] + 1; *z != '\0'; z++)
+ {
+ /* If the option takes an argument, and the argument is
+ not appended, then skip the next argument. */
+ if (*z == 'a' || *z == 'g' || *z == 'I'
+ || *z == 's' || *z == 'x')
+ {
+ if (z[1] == '\0')
+ i++;
+ break;
+ }
+ }
+ }
+ }
+
+ /* The leading + in the getopt string means to stop processing
+ options as soon as a non-option argument is seen. */
+ while ((iopt = getopt_long (argc, argv, "+a:bcCg:I:jlnprs:Wx:z",
+ asXlongopts, (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 'a':
+ /* Set requestor name: mail address to which status reports
+ should be sent. */
+ zrequestor = optarg;
+ break;
+
+ case 'b':
+ /* Return standard input on error. */
+ fretstdin = TRUE;
+ break;
+
+ case 'c':
+ /* Do not copy local files to spool directory. */
+ fcopy = FALSE;
+ fdontcopy = TRUE;
+ break;
+
+ case 'C':
+ /* Copy local files to spool directory. */
+ fcopy = TRUE;
+ break;
+
+ case 'I':
+ /* Configuration file name. */
+ if (fsysdep_other_config (optarg))
+ zconfig = optarg;
+ break;
+
+ case 'j':
+ /* Output jobid. */
+ fjobid = TRUE;
+ break;
+
+ case 'g':
+ /* Set job grade. */
+ bgrade = optarg[0];
+ break;
+
+ case 'l':
+ /* Link file to spool directory. */
+ flink = TRUE;
+ break;
+
+ case 'n':
+ /* Do not notify upon command completion. */
+ fno_ack = TRUE;
+ break;
+
+ case 'p':
+ /* Read standard input for command standard input. */
+ fread_stdin = TRUE;
+ break;
+
+ case 'r':
+ /* Do not start uucico when finished. */
+ fuucico = FALSE;
+ break;
+
+ case 's':
+ /* Report status to named file. */
+ zstatus_file = optarg;
+ break;
+
+ case 'W':
+ /* Only expand local file names. */
+ fexpand = FALSE;
+ break;
+
+ case 'x':
+#if DEBUG > 1
+ /* Set debugging level. */
+ iDebug |= idebug_parse (optarg);
+#endif
+ break;
+
+ case 'z':
+ /* Report status only on error. */
+ ferror_ack = TRUE;
+ break;
+
+ case 0:
+ /* Long option found and flag set. */
+ break;
+
+ default:
+ uxusage ();
+ break;
+ }
+ }
+
+ if (! UUCONF_GRADE_LEGAL (bgrade))
+ {
+ ulog (LOG_ERROR, "Ignoring illegal grade");
+ bgrade = BDEFAULT_UUX_GRADE;
+ }
+
+ if (optind == argc)
+ uxusage ();
+
+ iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+#if DEBUG > 1
+ {
+ const char *zdebug;
+
+ iuuconf = uuconf_debuglevel (puuconf, &zdebug);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (zdebug != NULL)
+ iDebug |= idebug_parse (zdebug);
+ }
+#endif
+
+ /* The command and files arguments could be quoted in any number of
+ ways, so we split them apart ourselves. We do this before
+ calling usysdep_initialize because we want to set fgetcwd
+ correctly. */
+ clen = 1;
+ for (i = optind; i < argc; i++)
+ clen += strlen (argv[i]) + 1;
+
+ zargs = zbufalc (clen);
+ *zargs = '\0';
+ for (i = optind; i < argc; i++)
+ {
+ strcat (zargs, argv[i]);
+ strcat (zargs, " ");
+ }
+
+ /* The first argument is the command to execute. */
+ clen = strcspn (zargs, ZSHELLSEPS);
+ zcmd = zbufalc (clen + 1);
+ strncpy (zcmd, zargs, clen);
+ zcmd[clen] = '\0';
+ zargs += clen;
+
+ /* Split the arguments out into an array. We break the arguments
+ into alternating sequences of characters not in ZSHELLSEPS
+ and characters in ZSHELLSEPS. We remove whitespace. We
+ separate the redirection characters '>' and '<' into their
+ own arguments to make them easier to process below. */
+ calloc_args = 10;
+ pzargs = (char **) xmalloc (calloc_args * sizeof (char *));
+ cargs = 0;
+
+ for (zarg = strtok (zargs, " \t");
+ zarg != NULL;
+ zarg = strtok ((char *) NULL, " \t"))
+ {
+ while (*zarg != '\0')
+ {
+ if (cargs + 1 >= calloc_args)
+ {
+ calloc_args += 10;
+ pzargs = (char **) xrealloc ((pointer) pzargs,
+ calloc_args * sizeof (char *));
+ }
+
+ clen = strcspn (zarg, ZSHELLSEPS);
+ if (clen > 0)
+ {
+ pzargs[cargs] = zbufalc (clen + 1);
+ memcpy (pzargs[cargs], zarg, clen);
+ pzargs[cargs][clen] = '\0';
+ ++cargs;
+ zarg += clen;
+ }
+
+ /* We deliberately separate '>' and '<' out. */
+ if (*zarg != '\0')
+ {
+ clen = strspn (zarg, ZSHELLNONREDIRSEPS);
+ if (clen == 0)
+ clen = 1;
+ pzargs[cargs] = zbufalc (clen + 1);
+ memcpy (pzargs[cargs], zarg, clen);
+ pzargs[cargs][clen] = '\0';
+ ++cargs;
+ zarg += clen;
+ }
+ }
+ }
+
+ /* Now look through the arguments to see if we are going to need the
+ current working directory. We don't try to make a precise
+ determination, just a conservative one. The basic idea is that
+ we don't want to get the cwd for 'foo!rmail - user' (note that we
+ don't examine the command itself). */
+ fgetcwd = FALSE;
+ for (i = 0; i < cargs; i++)
+ {
+ if (pzargs[i][0] == '(')
+ continue;
+ zexclam = strrchr (pzargs[i], '!');
+ if (zexclam != NULL && fsysdep_needs_cwd (zexclam + 1))
+ {
+ fgetcwd = TRUE;
+ break;
+ }
+ if ((pzargs[i][0] == '<' || pzargs[i][0] == '>')
+ && i + 1 < cargs
+ && strchr (pzargs[i + 1], '!') == NULL
+ && fsysdep_needs_cwd (pzargs[i + 1]))
+ {
+ fgetcwd = TRUE;
+ break;
+ }
+ }
+
+#ifdef SIGINT
+ usysdep_signal (SIGINT);
+#endif
+#ifdef SIGHUP
+ usysdep_signal (SIGHUP);
+#endif
+#ifdef SIGQUIT
+ usysdep_signal (SIGQUIT);
+#endif
+#ifdef SIGTERM
+ usysdep_signal (SIGTERM);
+#endif
+#ifdef SIGPIPE
+ usysdep_signal (SIGPIPE);
+#endif
+
+ usysdep_initialize (puuconf, INIT_SUID | (fgetcwd ? INIT_GETCWD : 0));
+
+ ulog_fatal_fn (uxabort);
+
+ zuser = zsysdep_login_name ();
+
+ /* Get the local system name. */
+ iuuconf = uuconf_localname (puuconf, &zlocalname);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ zlocalname = zsysdep_localname ();
+ if (zlocalname == NULL)
+ exit (EXIT_FAILURE);
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ /* Get the local system information. */
+ iuuconf = uuconf_system_info (puuconf, zlocalname, &slocalsys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf != UUCONF_NOT_FOUND)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ iuuconf = uuconf_system_local (puuconf, &slocalsys);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ }
+
+ /* Figure out which system the command is to be executed on. Some
+ mailers apparently pass local!rmail, so we must explicitly check
+ for that. */
+ zexclam = strchr (zcmd, '!');
+ while (zexclam != NULL)
+ {
+ *zexclam = '\0';
+ if (strcmp (zcmd, zlocalname) == 0)
+ ;
+ else if (slocalsys.uuconf_pzalias == NULL)
+ break;
+ else
+ {
+ char **pzal;
+
+ for (pzal = slocalsys.uuconf_pzalias; *pzal != NULL; pzal++)
+ if (strcmp (zcmd, *pzal) == 0)
+ break;
+ if (*pzal == NULL)
+ break;
+ }
+ zcmd = zexclam + 1;
+ zexclam = strchr (zcmd, '!');
+ }
+ if (zexclam == NULL)
+ {
+ zsys = zlocalname;
+ fxqtlocal = TRUE;
+ zforward = NULL;
+ }
+ else
+ {
+ zsys = zcmd;
+ zcmd = zexclam + 1;
+ fxqtlocal = FALSE;
+
+ /* See if we must forward this command through other systems
+ (e.g. uux a!b!cmd). */
+ zexclam = strrchr (zcmd, '!');
+ if (zexclam == NULL)
+ zforward = NULL;
+ else
+ {
+ clen = zexclam - zcmd;
+ zforward = zbufalc (clen);
+ memcpy (zforward, zcmd, clen);
+ zforward[clen] = '\0';
+ zcmd = zexclam + 1;
+ }
+ }
+
+ if (fxqtlocal)
+ sxqtsys = slocalsys;
+ else
+ {
+ iuuconf = uuconf_system_info (puuconf, zsys, &sxqtsys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf != UUCONF_NOT_FOUND)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (! funknown_system (puuconf, zsys, &sxqtsys))
+ ulog (LOG_FATAL, "%s: System not found", zsys);
+ }
+ }
+
+ /* Get the local name the remote system know us as. */
+ zxqtloc = sxqtsys.uuconf_zlocalname;
+ if (zxqtloc == NULL)
+ zxqtloc = zlocalname;
+
+ /* We can send this as an E command if the execution is on a
+ different, directly connected, system and the only file used is
+ the standard input and comes from this system. This is true of
+ the common cases of rmail and rnews. We get an execute file name
+ here in case we need it. */
+ if (fxqtlocal)
+ zXxqt_name = zsysdep_xqt_file_name ();
+ else
+ zXxqt_name = zsysdep_data_file_name (&sxqtsys, zxqtloc, bgrade, TRUE,
+ abxqt_tname, (char *) NULL,
+ abxqt_xname);
+ if (zXxqt_name == NULL)
+ uxabort ();
+
+ uxrecord_file (zXxqt_name);
+
+ /* Look through the arguments. Any argument containing an
+ exclamation point character is interpreted as a file name, and is
+ sent to the appropriate system. */
+ zinput_from = NULL;
+ zinput_to = NULL;
+ zinput_temp = NULL;
+ finputcopied = FALSE;
+ zcall_system = NULL;
+ fcall_any = FALSE;
+
+ for (i = 0; i < cargs; i++)
+ {
+ const char *zsystem;
+ char *zfile;
+ char *zforw;
+ boolean finput, foutput;
+ boolean flocal, fonxqt;
+
+ /* Check for a parenthesized argument; remove the parentheses
+ and otherwise ignore it (this is how an exclamation point is
+ quoted). */
+ if (pzargs[i][0] == '(')
+ {
+ clen = strlen (pzargs[i]);
+ if (pzargs[i][clen - 1] != ')')
+ ulog (LOG_ERROR, "Mismatched parentheses");
+ else
+ pzargs[i][clen - 1] = '\0';
+ ++pzargs[i];
+ continue;
+ }
+
+ /* Check whether we are doing a redirection. */
+ finput = FALSE;
+ foutput = FALSE;
+ if (i + 1 < cargs)
+ {
+ if (pzargs[i][0] == '<')
+ finput = TRUE;
+ else if (pzargs[i][0] == '>')
+ foutput = TRUE;
+ if (finput || foutput)
+ {
+ pzargs[i] = NULL;
+ i++;
+ }
+ }
+
+ zexclam = strchr (pzargs[i], '!');
+
+ /* If there is no exclamation point and no redirection, this
+ argument is left untouched. */
+ if (zexclam == NULL && ! finput && ! foutput)
+ continue;
+
+ /* Get the system name and file name for this file. */
+ if (zexclam == NULL)
+ {
+ zsystem = zlocalname;
+ zfile = pzargs[i];
+ flocal = TRUE;
+ zforw = NULL;
+ }
+ else
+ {
+ *zexclam = '\0';
+ zsystem = pzargs[i];
+ if (*zsystem != '\0')
+ flocal = FALSE;
+ else
+ {
+ zsystem = zlocalname;
+ flocal = TRUE;
+ }
+ zfile = zexclam + 1;
+ zexclam = strrchr (zfile, '!');
+ if (zexclam == NULL)
+ zforw = NULL;
+ else
+ {
+ if (flocal)
+ ulog (LOG_FATAL, "!%s: Can't figure out where to get file",
+ zfile);
+ *zexclam = '\0';
+ zforw = zfile;
+ zfile = zexclam + 1;
+ }
+ }
+
+ /* Check if the file is already on the execution system. */
+ if (flocal)
+ fonxqt = fxqtlocal;
+ else if (fxqtlocal)
+ fonxqt = FALSE;
+ else if (zforward == NULL ? zforw != NULL : zforw == NULL)
+ fonxqt = FALSE;
+ else if (zforward != NULL
+ && zforw != NULL
+ && strcmp (zforward, zforw) != 0)
+ fonxqt = FALSE;
+ else if (strcmp (zsystem, sxqtsys.uuconf_zname) == 0)
+ fonxqt = TRUE;
+ else if (sxqtsys.uuconf_pzalias == NULL)
+ fonxqt = FALSE;
+ else
+ {
+ char **pzal;
+
+ fonxqt = FALSE;
+ for (pzal = sxqtsys.uuconf_pzalias; *pzal != NULL; pzal++)
+ {
+ if (strcmp (zsystem, *pzal) == 0)
+ {
+ fonxqt = TRUE;
+ break;
+ }
+ }
+ }
+
+ /* Turn the file into an absolute path. */
+ if (flocal)
+ zfile = zsysdep_local_file_cwd (zfile, sxqtsys.uuconf_zpubdir);
+ else if (fexpand)
+ zfile = zsysdep_add_cwd (zfile);
+ if (zfile == NULL)
+ uxabort ();
+
+ /* Check for output redirection. */
+ if (foutput)
+ {
+ if (flocal)
+ {
+ if (! fin_directory_list (zfile,
+ sxqtsys.uuconf_pzremote_receive,
+ sxqtsys.uuconf_zpubdir, TRUE,
+ FALSE, (const char *) NULL))
+ ulog (LOG_FATAL, "Not permitted to create %s", zfile);
+ }
+
+ /* There are various cases of output redirection.
+
+ uux cmd >out: The command is executed on the local
+ system, and the output file is placed on the local
+ system (fonxqt is TRUE).
+
+ uux cmd >a!out: The command is executed on the local
+ system, and the output file is sent to a.
+
+ uux a!cmd >out: The command is executed on a, and the
+ output file is returned to the local system (flocal
+ is TRUE).
+
+ uux a!cmd >a!out: The command is executed on a, and the
+ output file is left on a (fonxqt is TRUE).
+
+ uux a!cmd >b!out: The command is executed on a, and the
+ output file is sent to b; traditionally, I believe
+ that b is relative to a, rather than to the local
+ system. However, this essentially contradicts the
+ previous two cases, in which the output file is
+ relative to the local system.
+
+ Now, the cases that we don't handle.
+
+ uux cmd >a!b!out: The command is executed on the local
+ system, and the output file is sent to b via a. This
+ requires the local uuxqt to support forwarding of the
+ output file.
+
+ uux a!b!cmd >out: The command is executed on b, which is
+ reached via a. Probably the output file is intended
+ for the local system, in which case the uuxqt on b
+ must support forwarding of the output file.
+
+ uux a!b!cmd >c!out: Is c relative to b or to the local
+ system? If it's relative to b this is easy to
+ handle. Otherwise, we must arrange for the file to
+ be sent back to the local system and for the local
+ system to send it on to c.
+
+ There are many variations of the last case. It's not at
+ all clear to me how they should be handled. */
+ if (zforward != NULL || zforw != NULL)
+ ulog (LOG_FATAL, "May not forward standard output");
+
+ if (fonxqt)
+ uxadd_xqt_line ('O', zfile, (const char *) NULL);
+ else if (flocal)
+ uxadd_xqt_line ('O', zfile, zxqtloc);
+ else
+ uxadd_xqt_line ('O', zfile, zsystem);
+ pzargs[i] = NULL;
+ continue;
+ }
+
+ if (finput)
+ {
+ if (fread_stdin)
+ ulog (LOG_FATAL, "Standard input specified twice");
+ pzargs[i] = NULL;
+ }
+
+ if (flocal)
+ {
+ char *zuse;
+ char *zdata;
+ char abtname[CFILE_NAME_LEN];
+ char abdname[CFILE_NAME_LEN];
+
+ /* It's a local file. If requested by -C, copy the file to
+ the spool directory. If requested by -l, link the file
+ to the spool directory; if the link fails, we copy the
+ file, unless -c was explictly used. If the execution is
+ occurring on the local system, we force the copy as well,
+ because otherwise we would have to have some way to tell
+ uuxqt not to move the file. If the file is being shipped
+ to another system, we must set up a transfer request.
+ First make sure the user has legitimate access, since we
+ are running setuid. */
+ if (! fsysdep_access (zfile))
+ uxabort ();
+
+ zdata = zsysdep_data_file_name (&sxqtsys, zxqtloc, bgrade, FALSE,
+ abtname, abdname, (char *) NULL);
+ if (zdata == NULL)
+ uxabort ();
+
+ if (fcopy || flink || fxqtlocal)
+ {
+ boolean fdid;
+
+ uxrecord_file (zdata);
+
+ fdid = FALSE;
+ if (flink)
+ {
+ boolean fworked;
+
+ if (! fsysdep_link (zfile, zdata, &fworked))
+ uxabort ();
+
+ if (fworked)
+ fdid = TRUE;
+ else if (fdontcopy)
+ ulog (LOG_FATAL, "%s: Can't link to spool directory",
+ zfile);
+ }
+
+ if (! fdid)
+ {
+ openfile_t efile;
+
+ efile = esysdep_user_fopen (zfile, TRUE, TRUE);
+ if (! ffileisopen (efile))
+ uxabort ();
+ if (! fcopy_open_file (efile, zdata, FALSE, TRUE))
+ uxabort ();
+ (void) ffileclose (efile);
+ }
+
+ zuse = abtname;
+ }
+ else
+ {
+ /* We don't actually use the spool file name, but we
+ need a name to use as the destination. */
+ ubuffree (zdata);
+ /* Make sure the daemon can access the file. */
+ if (! fsysdep_daemon_access (zfile))
+ uxabort ();
+ if (! fin_directory_list (zfile, sxqtsys.uuconf_pzlocal_send,
+ sxqtsys.uuconf_zpubdir, TRUE,
+ TRUE, zuser))
+ ulog (LOG_FATAL, "Not permitted to send from %s",
+ zfile);
+
+ zuse = zfile;
+ }
+
+ if (fxqtlocal)
+ {
+ if (finput)
+ uxadd_xqt_line ('I', zuse, (char *) NULL);
+ else
+ pzargs[i] = zuse;
+ }
+ else
+ {
+ finputcopied = fcopy || flink;
+
+ if (finput)
+ {
+ zinput_from = zuse;
+ zinput_to = zbufcpy (abdname);
+ zinput_temp = zbufcpy (abtname);
+ }
+ else
+ {
+ char *zbase;
+
+ uxadd_send_file (zuse, abdname,
+ finputcopied ? "C" : "c",
+ abtname, zforward, &sxqtsys,
+ zxqtloc, bgrade);
+ zbase = zsysdep_base_name (zfile);
+ if (zbase == NULL)
+ uxabort ();
+ uxadd_xqt_line ('F', abdname, zbase);
+ pzargs[i] = zbase;
+ }
+ }
+ }
+ else if (fonxqt)
+ {
+ /* The file is already on the system where the command is to
+ be executed. */
+ if (finput)
+ uxadd_xqt_line ('I', zfile, (const char *) NULL);
+ else
+ pzargs[i] = zfile;
+ }
+ else
+ {
+ struct uuconf_system sfromsys;
+ char abtname[CFILE_NAME_LEN];
+ struct scmd s;
+ char *zjobid;
+
+ /* We need to request a remote file. */
+ iuuconf = uuconf_system_info (puuconf, zsystem, &sfromsys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf != UUCONF_NOT_FOUND)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (! funknown_system (puuconf, zsystem, &sfromsys))
+ ulog (LOG_FATAL, "%s: System not found", zsystem);
+ }
+
+ if (fonxqt)
+ {
+ /* The file is already on the system where the command is to
+ be executed. */
+ if (finput)
+ uxadd_xqt_line ('I', zfile, (const char *) NULL);
+ else
+ pzargs[i] = zfile;
+ }
+ else
+ {
+ char *zdata;
+
+ if (! sfromsys.uuconf_fcall_transfer
+ && ! sfromsys.uuconf_fcalled_transfer)
+ ulog (LOG_FATAL,
+ "Not permitted to transfer files to or from %s",
+ sfromsys.uuconf_zname);
+
+ if (zforw != NULL)
+ {
+ /* This is ``uux cmd a!b!file''. To make this work,
+ we would have to be able to set up a request to a
+ to fetch file from b and send it to us. But it
+ turns out that that will not work, because when a
+ sends us the file we will put it in a's spool
+ directory, not the local system spool directory.
+ So we won't have any way to find it. This is not
+ a conceptual problem, and it could doubtless be
+ solved. Please feel free to solve it and send me
+ the solution. */
+ ulog (LOG_FATAL, "File forwarding not supported");
+ }
+
+ /* We must request the file from the remote system to
+ this one. */
+ zdata = zsysdep_data_file_name (&slocalsys, zxqtloc, bgrade,
+ FALSE, abtname, (char *) NULL,
+ (char *) NULL);
+ if (zdata == NULL)
+ uxabort ();
+ ubuffree (zdata);
+
+ /* Request the file. The special option '9' is a signal
+ to uucico that it's OK to receive a file into the
+ spool directory; normally such requests are rejected.
+ This privilege is easy to abuse. */
+ s.bcmd = 'R';
+ s.pseq = NULL;
+ s.zfrom = zfile;
+ s.zto = zbufcpy (abtname);
+ s.zuser = zuser;
+ s.zoptions = "9";
+ s.ztemp = "";
+ s.imode = 0600;
+ s.znotify = "";
+ s.cbytes = -1;
+ s.zcmd = NULL;
+ s.ipos = 0;
+
+ zjobid = zsysdep_spool_commands (&sfromsys, bgrade, 1, &s);
+ if (zjobid == NULL)
+ uxabort ();
+
+ if (fjobid)
+ printf ("%s\n", zjobid);
+
+ ubuffree (zjobid);
+
+ if (fcall_any)
+ {
+ ubuffree (zcall_system);
+ zcall_system = NULL;
+ }
+ else
+ {
+ fcall_any = TRUE;
+ zcall_system = zbufcpy (sfromsys.uuconf_zname);
+ }
+
+ if (fxqtlocal)
+ {
+ /* Tell the command execution to wait until the file
+ has been received, and tell it the real file
+ name. */
+ if (finput)
+ {
+ uxadd_xqt_line ('F', abtname, (char *) NULL);
+ uxadd_xqt_line ('I', abtname, (char *) NULL);
+ }
+ else
+ {
+ char *zbase;
+
+ zbase = zsysdep_base_name (zfile);
+ if (zbase == NULL)
+ uxabort ();
+ uxadd_xqt_line ('F', abtname, zbase);
+ pzargs[i] = zbase;
+ }
+ }
+ else
+ {
+ char abxtname[CFILE_NAME_LEN];
+ char *zbase;
+ char *zxqt;
+ FILE *e;
+
+ /* Now we must arrange to forward the file on to the
+ execution system. We need to get a name to give
+ the file on the execution system (abxtname). */
+ zdata = zsysdep_data_file_name (&sxqtsys, zxqtloc,
+ bgrade, TRUE, abxtname,
+ (char *) NULL,
+ (char *) NULL);
+ if (zdata == NULL)
+ uxabort ();
+ ubuffree (zdata);
+
+ zbase = zsysdep_base_name (zfile);
+ if (zbase == NULL)
+ uxabort ();
+
+ zxqt = zsysdep_xqt_file_name ();
+ if (zxqt == NULL)
+ uxabort ();
+ e = esysdep_fopen (zxqt, FALSE, FALSE, TRUE);
+ if (e == NULL)
+ uxabort ();
+ uxrecord_file (zxqt);
+
+ fprintf (e, "U %s %s\n", zsysdep_login_name (),
+ zlocalname);
+ fprintf (e, "F %s %s\n", abtname, zbase);
+ fprintf (e, "C uucp -C -W -d -g %c %s %s!", bgrade,
+ zbase, sxqtsys.uuconf_zname);
+ if (zforward != NULL)
+ fprintf (e, "%s!", zforward);
+ fprintf (e, "%s\n", abxtname);
+
+ if (fclose (e) != 0)
+ ulog (LOG_FATAL, "fclose: %s", strerror (errno));
+
+ if (finput)
+ {
+ uxadd_xqt_line ('F', abxtname, (char *) NULL);
+ uxadd_xqt_line ('I', abxtname, (char *) NULL);
+ ubuffree (zbase);
+ }
+ else
+ {
+ uxadd_xqt_line ('F', abxtname, zbase);
+ pzargs[i] = zbase;
+ }
+ }
+ }
+
+ (void) uuconf_system_free (puuconf, &sfromsys);
+ }
+ }
+
+ /* If standard input is to be read from the stdin of uux, we read it
+ here into a temporary file and send it to the execute system. */
+ if (fread_stdin)
+ {
+ char *zdata;
+ char abtname[CFILE_NAME_LEN];
+ char abdname[CFILE_NAME_LEN];
+ FILE *e;
+
+ zdata = zsysdep_data_file_name (&sxqtsys, zxqtloc, bgrade, FALSE,
+ abtname, abdname, (char *) NULL);
+ if (zdata == NULL)
+ uxabort ();
+
+ e = esysdep_fopen (zdata, FALSE, FALSE, TRUE);
+ if (e == NULL)
+ uxabort ();
+
+ eXclose = e;
+ uxrecord_file (zdata);
+
+ uxcopy_stdin (e);
+
+ eXclose = NULL;
+ if (fclose (e) != 0)
+ ulog (LOG_FATAL, "fclose: %s", strerror (errno));
+
+ if (fxqtlocal)
+ uxadd_xqt_line ('I', abtname, (const char *) NULL);
+ else
+ {
+ zinput_from = zbufcpy (abtname);
+ zinput_to = zbufcpy (abdname);
+ zinput_temp = zinput_from;
+ finputcopied = TRUE;
+ }
+ }
+
+ /* If we are returning standard input, or we're putting the status
+ in a file, we can't use an E command. */
+ if (fretstdin)
+ uxadd_xqt_line ('B', (const char *) NULL, (const char *) NULL);
+
+ if (zstatus_file != NULL)
+ uxadd_xqt_line ('M', zstatus_file, (const char *) NULL);
+
+ /* Get the complete command line, and decide whether the command
+ needs to be executed by the shell. */
+ fneedshell = FALSE;
+
+ if (zcmd[strcspn (zcmd, ZSHELLCHARS)] != '\0')
+ fneedshell = TRUE;
+
+ clen = strlen (zcmd) + 1;
+ for (i = 0; i < cargs; i++)
+ {
+ if (pzargs[i] != NULL)
+ {
+ clen += strlen (pzargs[i]) + 1;
+ if (pzargs[i][strcspn (pzargs[i], ZSHELLCHARS)] != '\0')
+ fneedshell = TRUE;
+ }
+ }
+
+ zfullcmd = zbufalc (clen);
+
+ strcpy (zfullcmd, zcmd);
+ for (i = 0; i < cargs; i++)
+ {
+ if (pzargs[i] != NULL)
+ {
+ strcat (zfullcmd, " ");
+ strcat (zfullcmd, pzargs[i]);
+ }
+ }
+
+ /* If we haven't written anything to the execution file yet, and we
+ have a standard input file, and we're not forwarding, then every
+ other option can be handled in an E command. */
+ if (eXxqt_file == NULL && zinput_from != NULL && zforward == NULL)
+ {
+ struct scmd s;
+ char aboptions[10];
+ char *zoptions;
+
+ /* Set up an E command. */
+ s.bcmd = 'E';
+ s.pseq = NULL;
+ s.zuser = zuser;
+ s.zfrom = zinput_from;
+ s.zto = zinput_to;
+ s.zoptions = aboptions;
+ zoptions = aboptions;
+ *zoptions++ = finputcopied ? 'C' : 'c';
+ if (fno_ack)
+ *zoptions++ = 'N';
+ if (ferror_ack)
+ *zoptions++ = 'Z';
+ if (zrequestor != NULL)
+ *zoptions++ = 'R';
+ if (fneedshell)
+ *zoptions++ = 'e';
+ *zoptions = '\0';
+ s.ztemp = zinput_temp;
+ s.imode = 0666;
+ if (zrequestor == NULL)
+ zrequestor = "\"\"";
+ s.znotify = zrequestor;
+ s.cbytes = -1;
+ s.zcmd = zfullcmd;
+ s.ipos = 0;
+
+ ++cXcmds;
+ pasXcmds = (struct scmd *) xrealloc ((pointer) pasXcmds,
+ cXcmds * sizeof (struct scmd));
+ pasXcmds[cXcmds - 1] = s;
+ }
+ else
+ {
+ /* Finish up the execute file. */
+ uxadd_xqt_line ('U', zuser, zxqtloc);
+ if (zinput_from != NULL)
+ {
+ uxadd_xqt_line ('F', zinput_to, (char *) NULL);
+ uxadd_xqt_line ('I', zinput_to, (char *) NULL);
+ uxadd_send_file (zinput_from, zinput_to,
+ finputcopied ? "C" : "c",
+ zinput_temp, zforward, &sxqtsys, zxqtloc,
+ bgrade);
+ }
+ if (fno_ack)
+ uxadd_xqt_line ('N', (const char *) NULL, (const char *) NULL);
+ if (ferror_ack)
+ uxadd_xqt_line ('Z', (const char *) NULL, (const char *) NULL);
+ if (zrequestor != NULL)
+ uxadd_xqt_line ('R', zrequestor, (const char *) NULL);
+ if (fneedshell)
+ uxadd_xqt_line ('e', (const char *) NULL, (const char *) NULL);
+ uxadd_xqt_line ('C', zfullcmd, (const char *) NULL);
+ if (fclose (eXxqt_file) != 0)
+ ulog (LOG_FATAL, "fclose: %s", strerror (errno));
+ eXxqt_file = NULL;
+
+ /* If the execution is to occur on another system, we must now
+ arrange to copy the execute file to this system. */
+ if (! fxqtlocal)
+ uxadd_send_file (abxqt_tname, abxqt_xname, "C", abxqt_tname,
+ zforward, &sxqtsys, zxqtloc, bgrade);
+ }
+
+ /* If we got a signal, get out before spooling anything. */
+ if (FGOT_SIGNAL ())
+ uxabort ();
+
+ /* From here on in, it's too late. We don't call uxabort. */
+ if (cXcmds > 0)
+ {
+ char *zjobid;
+
+ if (! sxqtsys.uuconf_fcall_transfer
+ && ! sxqtsys.uuconf_fcalled_transfer)
+ ulog (LOG_FATAL, "Not permitted to transfer files to or from %s",
+ sxqtsys.uuconf_zname);
+
+ zjobid = zsysdep_spool_commands (&sxqtsys, bgrade, cXcmds, pasXcmds);
+ if (zjobid == NULL)
+ {
+ ulog_close ();
+ usysdep_exit (FALSE);
+ }
+
+ if (fjobid)
+ printf ("%s\n", zjobid);
+
+ ubuffree (zjobid);
+
+ if (fcall_any)
+ {
+ ubuffree (zcall_system);
+ zcall_system = NULL;
+ }
+ else
+ {
+ fcall_any = TRUE;
+ zcall_system = zbufcpy (sxqtsys.uuconf_zname);
+ }
+ }
+
+ /* If all that worked, make a log file entry. All log file reports
+ up to this point went to stderr. */
+ ulog_to_file (puuconf, TRUE);
+ ulog_system (sxqtsys.uuconf_zname);
+ ulog_user (zuser);
+
+ ulog (LOG_NORMAL, "Queuing %s", zfullcmd);
+
+ ulog_close ();
+
+ if (! fuucico)
+ fexit = TRUE;
+ else
+ {
+ if (zcall_system != NULL)
+ fexit = fsysdep_run ("uucico", "-s", zcall_system);
+ else if (fcall_any)
+ fexit = fsysdep_run ("uucico", "-r1", (const char *) NULL);
+ else
+ fexit = TRUE;
+ }
+
+ usysdep_exit (fexit);
+
+ /* Avoid error about not returning a value. */
+ return 0;
+}
+
+/* Report command usage. */
+
+static void
+uxusage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uux [options] [-] command\n");
+ fprintf (stderr,
+ " -,-p: Read standard input for standard input of command\n");
+ fprintf (stderr,
+ " -c: Do not copy local files to spool directory (default)\n");
+ fprintf (stderr,
+ " -C: Copy local files to spool directory\n");
+ fprintf (stderr,
+ " -l: link local files to spool directory\n");
+ fprintf (stderr,
+ " -g grade: Set job grade (must be alphabetic)\n");
+ fprintf (stderr,
+ " -n: Do not report completion status\n");
+ fprintf (stderr,
+ " -z: Report completion status only on error\n");
+ fprintf (stderr,
+ " -r: Do not start uucico daemon\n");
+ fprintf (stderr,
+ " -a address: Address to mail status report to\n");
+ fprintf (stderr,
+ " -b: Return standard input with status report\n");
+ fprintf (stderr,
+ " -s file: Report completion status to file\n");
+ fprintf (stderr,
+ " -j: Report job id\n");
+ fprintf (stderr,
+ " -x debug: Set debugging level\n");
+#if HAVE_TAYLOR_CONFIG
+ fprintf (stderr,
+ " -I file: Set configuration file to use\n");
+#endif /* HAVE_TAYLOR_CONFIG */
+ exit (EXIT_FAILURE);
+}
+
+/* Add a line to the execute file. */
+
+static void
+uxadd_xqt_line (bchar, z1, z2)
+ int bchar;
+ const char *z1;
+ const char *z2;
+{
+ if (eXxqt_file == NULL)
+ {
+ eXxqt_file = esysdep_fopen (zXxqt_name, FALSE, FALSE, TRUE);
+ if (eXxqt_file == NULL)
+ uxabort ();
+ }
+
+ if (z1 == NULL)
+ fprintf (eXxqt_file, "%c\n", bchar);
+ else if (z2 == NULL)
+ fprintf (eXxqt_file, "%c %s\n", bchar, z1);
+ else
+ fprintf (eXxqt_file, "%c %s %s\n", bchar, z1, z2);
+}
+
+/* Add a file to be sent to the execute system. */
+
+static void
+uxadd_send_file (zfrom, zto, zoptions, ztemp, zforward, qxqtsys, zxqtloc,
+ bgrade)
+ const char *zfrom;
+ const char *zto;
+ const char *zoptions;
+ const char *ztemp;
+ const char *zforward;
+ const struct uuconf_system *qxqtsys;
+ const char *zxqtloc;
+ int bgrade;
+{
+ struct scmd s;
+
+ if (zforward != NULL)
+ {
+ char *zbase;
+ char *zxqt;
+ char abtname[CFILE_NAME_LEN];
+ char abdname[CFILE_NAME_LEN];
+ char abxname[CFILE_NAME_LEN];
+ FILE *e;
+
+ /* We want to forward this file through the first execution
+ system to other systems. We set up a remote execution of
+ uucp to forward the file. */
+ zbase = zsysdep_base_name (zfrom);
+ if (zbase == NULL)
+ uxabort ();
+
+ zxqt = zsysdep_data_file_name (qxqtsys, zxqtloc, bgrade, TRUE, abtname,
+ abdname, abxname);
+ if (zxqt == NULL)
+ uxabort ();
+ e = esysdep_fopen (zxqt, FALSE, FALSE, TRUE);
+ if (e == NULL)
+ uxabort ();
+ uxrecord_file (zxqt);
+
+ fprintf (e, "U %s %s\n", zsysdep_login_name (), zxqtloc);
+ fprintf (e, "F %s %s\n", abdname, zbase);
+ fprintf (e, "C uucp -C -W -d -g %c %s %s!%s\n",
+ bgrade, zbase, zforward, zto);
+
+ ubuffree (zbase);
+
+ if (fclose (e) != 0)
+ ulog (LOG_FATAL, "fclose: %s", strerror (errno));
+
+ /* Send the execution file. */
+ s.bcmd = 'S';
+ s.pseq = NULL;
+ s.zfrom = zbufcpy (abtname);
+ s.zto = zbufcpy (abxname);
+ s.zuser = zsysdep_login_name ();
+ s.zoptions = "C";
+ s.ztemp = s.zfrom;
+ s.imode = 0666;
+ s.znotify = NULL;
+ s.cbytes = -1;
+ s.zcmd = NULL;
+ s.ipos = 0;
+
+ ++cXcmds;
+ pasXcmds = (struct scmd *) xrealloc ((pointer) pasXcmds,
+ cXcmds * sizeof (struct scmd));
+ pasXcmds[cXcmds - 1] = s;
+
+ /* Send the data file to abdname where the execution file will
+ expect it. */
+ zto = abdname;
+ }
+
+ s.bcmd = 'S';
+ s.pseq = NULL;
+ s.zfrom = zbufcpy (zfrom);
+ s.zto = zbufcpy (zto);
+ s.zuser = zsysdep_login_name ();
+ s.zoptions = zbufcpy (zoptions);
+ s.ztemp = zbufcpy (ztemp);
+ s.imode = 0666;
+ s.znotify = "";
+ s.cbytes = -1;
+ s.zcmd = NULL;
+ s.ipos = 0;
+
+ ++cXcmds;
+ pasXcmds = (struct scmd *) xrealloc ((pointer) pasXcmds,
+ cXcmds * sizeof (struct scmd));
+ pasXcmds[cXcmds - 1] = s;
+}
+
+/* Copy stdin to a file. This is a separate function because it may
+ call setjmp. */
+
+static void
+uxcopy_stdin (e)
+ FILE *e;
+{
+ CATCH_PROTECT size_t cread;
+ char ab[1024];
+
+ do
+ {
+ size_t cwrite;
+
+ /* I want to use fread here, but there is a bug in some versions
+ of SVR4 which causes fread to return less than a complete
+ buffer even if EOF has not been reached. This is not online
+ time, so speed is not critical, but it's still quite annoying
+ to have to use an inefficient algorithm. */
+ cread = 0;
+ if (fsysdep_catch ())
+ {
+ usysdep_start_catch ();
+
+ while (cread < sizeof (ab))
+ {
+ int b;
+
+ if (FGOT_SIGNAL ())
+ uxabort ();
+
+ /* There's an unimportant race here. If the user hits
+ ^C between the FGOT_SIGNAL we just did and the time
+ we enter getchar, we won't know about the signal
+ (unless we're doing a longjmp, but we normally
+ aren't). It's not a big problem, because the user
+ can just hit ^C again. */
+ b = getchar ();
+ if (b == EOF)
+ break;
+ ab[cread] = b;
+ ++cread;
+ }
+ }
+
+ usysdep_end_catch ();
+
+ if (FGOT_SIGNAL ())
+ uxabort ();
+
+ if (cread > 0)
+ {
+ cwrite = fwrite (ab, sizeof (char), cread, e);
+ if (cwrite != cread)
+ ulog (LOG_FATAL, "fwrite: Wrote %d when attempted %d",
+ (int) cwrite, (int) cread);
+ }
+ }
+ while (cread == sizeof ab);
+}
+
+/* Keep track of all files we have created so that we can delete them
+ if we get a signal. The argument will be on the heap. */
+
+static int cXfiles;
+static const char **pXaz;
+
+static void
+uxrecord_file (zfile)
+ const char *zfile;
+{
+ pXaz = (const char **) xrealloc ((pointer) pXaz,
+ (cXfiles + 1) * sizeof (const char *));
+ pXaz[cXfiles] = zfile;
+ ++cXfiles;
+}
+
+/* Delete all the files we have recorded and exit. */
+
+static void
+uxabort ()
+{
+ int i;
+
+ if (eXxqt_file != NULL)
+ (void) fclose (eXxqt_file);
+ if (eXclose != NULL)
+ (void) fclose (eXclose);
+ for (i = 0; i < cXfiles; i++)
+ (void) remove (pXaz[i]);
+ ulog_close ();
+ usysdep_exit (FALSE);
+}
diff --git a/gnu/libexec/uucp/uuxqt/Makefile b/gnu/libexec/uucp/uuxqt/Makefile
new file mode 100644
index 00000000000..49a7e955314
--- /dev/null
+++ b/gnu/libexec/uucp/uuxqt/Makefile
@@ -0,0 +1,17 @@
+# Makefile for uuxqt
+
+BINDIR= $(sbindir)
+BINOWN= $(owner)
+BINMODE= 4555
+
+PROG= uuxqt
+SRCS= uuxqt.c util.c log.c copy.c
+LDADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+DPADD+= $(LIBUNIX) $(LIBUUCONF) $(LIBUUCP)
+CFLAGS+= -I$(.CURDIR)/../common_sources\
+ -DVERSION=\"$(VERSION)\"
+
+MAN8= uuxqt.0
+
+.include <bsd.prog.mk>
+.PATH: $(.CURDIR)/../common_sources
diff --git a/gnu/libexec/uucp/uuxqt/uuxqt.8 b/gnu/libexec/uucp/uuxqt/uuxqt.8
new file mode 100644
index 00000000000..faee1cf7a81
--- /dev/null
+++ b/gnu/libexec/uucp/uuxqt/uuxqt.8
@@ -0,0 +1,92 @@
+''' $Id: uuxqt.8,v 1.1 1993/08/04 19:37:18 jtc Exp $
+.TH uuxqt 8 "Taylor UUCP 1.04"
+.SH NAME
+uuxqt \- UUCP execution daemon
+.SH SYNOPSIS
+.B uuxqt
+[ options ]
+.SH DESCRIPTION
+The
+.I uuxqt
+daemon executes commands requested by
+.I uux
+(1) from either the local system or from remote systems.
+It is started automatically by the
+.I uucico
+(8) daemon (unless
+.I uucico
+(8) is given the
+.B \-q
+option).
+
+There is normally no need to run this command, since it will be
+invoked by
+.I uucico
+(8). However, it can be used to provide greater control over the
+processing of the work queue.
+
+Multiple invocations of
+.I uuxqt
+may be run at once, as controlled by the
+.I max-uuxqts
+configuration command.
+.SH OPTIONS
+The following options may be given to
+.I uuxqt.
+.TP 5
+.B \-c command
+Only execute requests for the specified command. For example:
+.EX
+uuxqt -c rmail
+.EE
+.TP 5
+.B \-s system
+Only execute requests originating from the specified system.
+.TP 5
+.B \-x type
+Turn on particular debugging types. The following types are
+recognized: abnormal, chat, handshake, uucp-proto, proto, port,
+config, spooldir, execute, incoming, outgoing. Only abnormal, config,
+spooldir and execute are meaningful for
+.I uuxqt.
+
+Multiple types may be given, separated by commas, and the
+.B \-x
+option may appear multiple times. A number may also be given, which
+will turn on that many types from the foregoing list; for example,
+.B \-x 2
+is equivalent to
+.B \-x abnormal,chat.
+
+The debugging output is sent to the debugging file, usually one of
+/usr/spool/uucp/Debug, /usr/spool/uucp/DEBUG, or
+/usr/spool/uucp/.Admin/audit.local.
+.TP 5
+.B \-I file
+Set configuration file to use. This option may not be available,
+depending upon how
+.I uuxqt
+was compiled.
+.SH FILES
+The file names may be changed at compilation time or by the
+configuration file, so these are only approximations.
+
+.br
+/usr/lib/uucp/config - Configuration file.
+.br
+/usr/spool/uucp -
+UUCP spool directory.
+.br
+/usr/spool/uucp/Log -
+UUCP log file.
+.br
+/usr/spool/uucppublic -
+Default UUCP public directory.
+.br
+/usr/spool/uucp/Debug -
+Debugging file.
+.SH SEE ALSO
+uucp(1), uux(1), uucico(8)
+.SH AUTHOR
+Ian Lance Taylor
+(ian@airs.com or uunet!airs!ian)
diff --git a/gnu/libexec/uucp/uuxqt/uuxqt.c b/gnu/libexec/uucp/uuxqt/uuxqt.c
new file mode 100644
index 00000000000..919ea7ecd4e
--- /dev/null
+++ b/gnu/libexec/uucp/uuxqt/uuxqt.c
@@ -0,0 +1,1549 @@
+/* uuxqt.c
+ Run uux commands.
+
+ 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.
+ */
+
+#include "uucp.h"
+
+#if USE_RCS_ID
+const char uuxqt_rcsid[] = "$Id: uuxqt.c,v 1.1 1993/08/04 19:37:19 jtc Exp $";
+#endif
+
+#include <errno.h>
+#include <ctype.h>
+
+#include "getopt.h"
+
+#include "uudefs.h"
+#include "uuconf.h"
+#include "system.h"
+
+/* The program name. */
+char abProgram[] = "uuxqt";
+
+/* Static variables used to unlock things if we get a fatal error. */
+static int iQlock_seq = -1;
+static const char *zQunlock_cmd;
+static const char *zQunlock_file;
+static boolean fQunlock_directory;
+int cQmaxuuxqts;
+
+/* Static variables to free in uqcleanup. */
+static char *zQoutput;
+static char *zQmail;
+
+/* Local functions. */
+static void uqusage P((void));
+static void uqabort P((void));
+static void uqdo_xqt_file P((pointer puuconf, const char *zfile,
+ const char *zbase,
+ const struct uuconf_system *qsys,
+ const char *zlocalname,
+ const char *zcmd, boolean *pfprocessed));
+static void uqcleanup P((const char *zfile, int iflags));
+static boolean fqforward P((const char *zfile, char **pzallowed,
+ const char *zlog, const char *zmail));
+
+/* Long getopt options. */
+static const struct option asQlongopts[] = { { NULL, 0, NULL, 0 } };
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ /* The type of command to execute (NULL for any type). */
+ const char *zcmd = NULL;
+ /* The configuration file name. */
+ const char *zconfig = NULL;
+ /* The system to execute commands for. */
+ const char *zdosys = NULL;
+ int iopt;
+ pointer puuconf;
+ int iuuconf;
+ const char *zlocalname;
+ boolean fany;
+ char *z, *zgetsys;
+ boolean ferr;
+ boolean fsys;
+ struct uuconf_system ssys;
+
+ while ((iopt = getopt_long (argc, argv, "c:I:s:x:", asQlongopts,
+ (int *) NULL)) != EOF)
+ {
+ switch (iopt)
+ {
+ case 'c':
+ /* Set the type of command to execute. */
+ zcmd = optarg;
+ break;
+
+ case 'I':
+ /* Set the configuration file name. */
+ if (fsysdep_other_config (optarg))
+ zconfig = optarg;
+ break;
+
+ case 's':
+ zdosys = optarg;
+ break;
+
+ case 'x':
+#if DEBUG > 1
+ /* Set the debugging level. */
+ iDebug |= idebug_parse (optarg);
+#endif
+ break;
+
+ case 0:
+ /* Long option found and flag set. */
+ break;
+
+ default:
+ uqusage ();
+ break;
+ }
+ }
+
+ if (optind != argc)
+ uqusage ();
+
+ iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+#if DEBUG > 1
+ {
+ const char *zdebug;
+
+ iuuconf = uuconf_debuglevel (puuconf, &zdebug);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+ if (zdebug != NULL)
+ iDebug |= idebug_parse (zdebug);
+ }
+#endif
+
+ iuuconf = uuconf_maxuuxqts (puuconf, &cQmaxuuxqts);
+ if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+#ifdef SIGINT
+ usysdep_signal (SIGINT);
+#endif
+#ifdef SIGHUP
+ usysdep_signal (SIGHUP);
+#endif
+#ifdef SIGQUIT
+ usysdep_signal (SIGQUIT);
+#endif
+#ifdef SIGTERM
+ usysdep_signal (SIGTERM);
+#endif
+#ifdef SIGPIPE
+ usysdep_signal (SIGPIPE);
+#endif
+
+ usysdep_initialize (puuconf, INIT_SUID);
+
+ ulog_to_file (puuconf, TRUE);
+ ulog_fatal_fn (uqabort);
+
+ iuuconf = uuconf_localname (puuconf, &zlocalname);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ {
+ zlocalname = zsysdep_localname ();
+ if (zlocalname == NULL)
+ exit (EXIT_FAILURE);
+ }
+ else if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ fsys = FALSE;
+
+ /* If we were given a system name, canonicalize it, since the system
+ dependent layer will not be returning aliases. */
+ if (zdosys != NULL)
+ {
+ iuuconf = uuconf_system_info (puuconf, zdosys, &ssys);
+ if (iuuconf == UUCONF_NOT_FOUND)
+ ulog (LOG_FATAL, "%s: System not found", zdosys);
+ else if (iuuconf != UUCONF_SUCCESS)
+ ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
+
+ zdosys = zbufcpy (ssys.uuconf_zname);
+ fsys = TRUE;
+ }
+
+ /* Limit the number of uuxqt processes, and make sure we're the only
+ uuxqt daemon running for this command. */
+ iQlock_seq = ixsysdep_lock_uuxqt (zcmd, cQmaxuuxqts);
+ if (iQlock_seq < 0)
+ {
+ ulog_close ();
+ usysdep_exit (TRUE);
+ }
+ zQunlock_cmd = zcmd;
+
+ /* Keep scanning the execute files until we don't process any of
+ them. */
+ do
+ {
+ fany = FALSE;
+
+ /* Look for each execute file, and run it. */
+
+ if (! fsysdep_get_xqt_init ())
+ {
+ ulog_close ();
+ usysdep_exit (FALSE);
+ }
+
+ while ((z = zsysdep_get_xqt (&zgetsys, &ferr)) != NULL)
+ {
+ const char *zloc;
+ boolean fprocessed;
+ char *zbase;
+
+ /* It would be more efficient to pass zdosys down to the
+ routines which retrieve execute files. */
+ if (zdosys != NULL && strcmp (zdosys, zgetsys) != 0)
+ {
+ ubuffree (z);
+ ubuffree (zgetsys);
+ continue;
+ }
+
+ if (! fsys || strcmp (ssys.uuconf_zname, zgetsys) != 0)
+ {
+ if (fsys)
+ (void) uuconf_system_free (puuconf, &ssys);
+
+ iuuconf = uuconf_system_info (puuconf, zgetsys,
+ &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf != UUCONF_NOT_FOUND)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ ubuffree (z);
+ ubuffree (zgetsys);
+ continue;
+ }
+ else if (strcmp (zgetsys, zlocalname) == 0)
+ {
+ iuuconf = uuconf_system_local (puuconf, &ssys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ ubuffree (z);
+ ubuffree (zgetsys);
+ continue;
+ }
+ }
+ else
+ {
+ if (! funknown_system (puuconf, zgetsys, &ssys))
+ {
+ ulog (LOG_ERROR,
+ "%s: Execute file for unknown system %s",
+ z, zgetsys);
+ (void) remove (z);
+ ubuffree (z);
+ ubuffree (zgetsys);
+ continue;
+ }
+ }
+ }
+
+ fsys = TRUE;
+ }
+
+ /* If we've received a signal, get out of the loop. */
+ if (FGOT_SIGNAL ())
+ {
+ ubuffree (z);
+ ubuffree (zgetsys);
+ break;
+ }
+
+ zloc = ssys.uuconf_zlocalname;
+ if (zloc == NULL)
+ zloc = zlocalname;
+
+ ulog_system (ssys.uuconf_zname);
+ zbase = zsysdep_base_name (z);
+ uqdo_xqt_file (puuconf, z, zbase, &ssys, zloc, zcmd, &fprocessed);
+ ubuffree (zbase);
+ ulog_system ((const char *) NULL);
+ ulog_user ((const char *) NULL);
+
+ if (fprocessed)
+ fany = TRUE;
+ ubuffree (z);
+ ubuffree (zgetsys);
+ }
+
+ usysdep_get_xqt_free ();
+ }
+ while (fany && ! FGOT_SIGNAL ());
+
+ (void) fsysdep_unlock_uuxqt (iQlock_seq, zcmd, cQmaxuuxqts);
+ iQlock_seq = -1;
+
+ ulog_close ();
+
+ if (FGOT_SIGNAL ())
+ ferr = TRUE;
+
+ usysdep_exit (! ferr);
+
+ /* Avoid errors about not returning a value. */
+ return 0;
+}
+
+static void
+uqusage ()
+{
+ fprintf (stderr,
+ "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
+ VERSION);
+ fprintf (stderr,
+ "Usage: uuxqt [-c cmd] [-I file] [-s system] [-x debug]\n");
+ fprintf (stderr,
+ " -c cmd: Set type of command to execute\n");
+ fprintf (stderr,
+ " -s system: Execute commands only for named system\n");
+ fprintf (stderr,
+ " -x debug: Set debugging level (0 for none, 9 is max)\n");
+#if HAVE_TAYLOR_CONFIG
+ fprintf (stderr,
+ " -I file: Set configuration file to use\n");
+#endif /* HAVE_TAYLOR_CONFIG */
+ exit (EXIT_FAILURE);
+}
+
+/* This is the abort function called when we get a fatal error. */
+
+static void
+uqabort ()
+{
+#if ! HAVE_HDB_LOGGING
+ /* When using HDB logging, it's a pain to have no system name. */
+ ulog_system ((const char *) NULL);
+#endif
+
+ ulog_user ((const char *) NULL);
+
+ if (fQunlock_directory)
+ (void) fsysdep_unlock_uuxqt_dir (iQlock_seq);
+
+ if (zQunlock_file != NULL)
+ (void) fsysdep_unlock_uuxqt_file (zQunlock_file);
+
+ if (iQlock_seq >= 0)
+ (void) fsysdep_unlock_uuxqt (iQlock_seq, zQunlock_cmd, cQmaxuuxqts);
+
+ ulog_close ();
+
+ usysdep_exit (FALSE);
+}
+
+/* An execute file is a series of lines. The first character of each
+ line is a command. The following commands are defined:
+
+ C command-line
+ I standard-input
+ O standard-output [ system ]
+ F required-file filename-to-use
+ R requestor-address
+ U user system
+ Z (acknowledge if command failed; default)
+ N (no acknowledgement on failure)
+ n (acknowledge if command succeeded)
+ B (return command input on error)
+ e (process with sh)
+ E (process with exec)
+ M status-file
+ # comment
+
+ Unrecognized commands are ignored. We actually do not recognize
+ the Z command, since it requests default behaviour. We always send
+ mail on failure, unless the N command appears. We never send mail
+ on success, unless the n command appears.
+
+ This code does not currently support the B or M commands. */
+
+/* Command arguments. */
+static char **azQargs;
+/* Command as a complete string. */
+static char *zQcmd;
+/* Standard input file name. */
+static char *zQinput;
+/* Standard output file name. */
+static char *zQoutfile;
+/* Standard output system. */
+static char *zQoutsys;
+/* Number of required files. */
+static int cQfiles;
+/* Names of required files. */
+static char **azQfiles;
+/* Names required files should be renamed to (NULL if original is OK). */
+static char **azQfiles_to;
+/* Requestor address (this is where mail should be sent). */
+static char *zQrequestor;
+/* User name. */
+static const char *zQuser;
+/* System name. */
+static const char *zQsystem;
+/* This is set by the N flag, meaning that no acknowledgement should
+ be mailed on failure. */
+static boolean fQno_ack;
+/* This is set by the n flag, meaning that acknowledgement should be
+ mailed if the command succeeded. */
+static boolean fQsuccess_ack;
+/* This is set by the B flag, meaning that command input should be
+ mailed to the requestor if an error occurred. */
+static boolean fQsend_input;
+/* This is set by the E flag, meaning that exec should be used to
+ execute the command. */
+static boolean fQuse_exec;
+/* The status should be copied to this file on the requesting host. */
+static const char *zQstatus_file;
+#if ALLOW_SH_EXECUTION
+/* This is set by the e flag, meaning that sh should be used to
+ execute the command. */
+static boolean fQuse_sh;
+#endif /* ALLOW_SH_EXECUTION */
+
+static int iqcmd P((pointer puuconf, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int iqout P((pointer puuconf, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int iqfile P((pointer puuconf, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int iqrequestor P((pointer puuconf, int argc, char **argv,
+ pointer pvar, pointer pinfo));
+static int iquser P((pointer puuconf, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+static int iqset P((pointer puuconf, int argc, char **argv, pointer pvar,
+ pointer pinfo));
+
+static const struct uuconf_cmdtab asQcmds[] =
+{
+ { "C", UUCONF_CMDTABTYPE_FN | 0, NULL, iqcmd },
+ { "I", UUCONF_CMDTABTYPE_STRING, (pointer) &zQinput, NULL },
+ { "O", UUCONF_CMDTABTYPE_FN | 0, NULL, iqout },
+ { "F", UUCONF_CMDTABTYPE_FN | 0, NULL, iqfile },
+ { "R", UUCONF_CMDTABTYPE_FN, NULL, iqrequestor },
+ { "U", UUCONF_CMDTABTYPE_FN | 3, NULL, iquser },
+ { "N", UUCONF_CMDTABTYPE_FN | 1, (pointer) &fQno_ack, iqset },
+ { "n", UUCONF_CMDTABTYPE_FN | 1, (pointer) &fQsuccess_ack, iqset },
+ /* Some systems create execution files in which B takes an argument;
+ I don't know what it means, so I just ignore it. */
+ { "B", UUCONF_CMDTABTYPE_FN | 0, (pointer) &fQsend_input, iqset },
+#if ALLOW_SH_EXECUTION
+ { "e", UUCONF_CMDTABTYPE_FN | 1, (pointer) &fQuse_sh, iqset },
+#endif
+ { "E", UUCONF_CMDTABTYPE_FN | 1, (pointer) &fQuse_exec, iqset },
+ { "M", UUCONF_CMDTABTYPE_STRING, (pointer) &zQstatus_file, NULL },
+ { NULL, 0, NULL, NULL }
+};
+
+/* Handle the C command: store off the arguments. */
+
+/*ARGSUSED*/
+static int
+iqcmd (puuconf, argc, argv, pvar, pinfo)
+ pointer puuconf;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ int i;
+ size_t clen;
+
+ if (argc <= 1)
+ return UUCONF_CMDTABRET_CONTINUE;
+
+ azQargs = (char **) xmalloc (argc * sizeof (char *));
+ clen = 0;
+ for (i = 1; i < argc; i++)
+ {
+ azQargs[i - 1] = zbufcpy (argv[i]);
+ clen += strlen (argv[i]) + 1;
+ }
+ azQargs[i - 1] = NULL;
+
+ zQcmd = (char *) xmalloc (clen);
+ zQcmd[0] = '\0';
+ for (i = 1; i < argc - 1; i++)
+ {
+ strcat (zQcmd, argv[i]);
+ strcat (zQcmd, " ");
+ }
+ strcat (zQcmd, argv[i]);
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Handle the O command, which may have one or two arguments. */
+
+/*ARGSUSED*/
+static int
+iqout (puuconf, argc, argv, pvar, pinfo)
+ pointer puuconf;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ const char *zbase = (const char *) pinfo;
+
+ if (argc != 2 && argc != 3)
+ {
+ ulog (LOG_ERROR, "%s: %s: Wrong number of arguments",
+ zbase, argv[0]);
+ return UUCONF_CMDTABRET_CONTINUE;
+ }
+
+ zQoutfile = zbufcpy (argv[1]);
+ if (argc == 3)
+ zQoutsys = zbufcpy (argv[2]);
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Handle the F command, which may have one or two arguments. */
+
+/*ARGSUSED*/
+static int
+iqfile (puuconf, argc, argv, pvar, pinfo)
+ pointer puuconf;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ const char *zbase = (const char *) pinfo;
+
+ if (argc != 2 && argc != 3)
+ {
+ ulog (LOG_ERROR, "%s: %s: Wrong number of arguments",
+ zbase, argv[0]);
+ return UUCONF_CMDTABRET_CONTINUE;
+ }
+
+ /* If this file is not in the spool directory, just ignore it. */
+ if (! fspool_file (argv[1]))
+ return UUCONF_CMDTABRET_CONTINUE;
+
+ ++cQfiles;
+ azQfiles = (char **) xrealloc ((pointer) azQfiles,
+ cQfiles * sizeof (char *));
+ azQfiles_to = (char **) xrealloc ((pointer) azQfiles_to,
+ cQfiles * sizeof (char *));
+
+ azQfiles[cQfiles - 1] = zbufcpy (argv[1]);
+ if (argc == 3)
+ azQfiles_to[cQfiles - 1] = zbufcpy (argv[2]);
+ else
+ azQfiles_to[cQfiles - 1] = NULL;
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Handle the R command, which may have one or two arguments. */
+
+/*ARGSUSED*/
+static int
+iqrequestor (puuconf, argc, argv, pvar, pinfo)
+ pointer puuconf;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ const char *zbase = (const char *) pinfo;
+
+ if (argc != 2 && argc != 3)
+ {
+ ulog (LOG_ERROR, "%s: %s: Wrong number of arguments",
+ zbase, argv[0]);
+ return UUCONF_CMDTABRET_CONTINUE;
+ }
+
+ /* We normally have a single argument, which is the ``requestor''
+ address, to which we should send any success or error messages.
+ Apparently the DOS program UUPC sends two arguments, which are
+ the username and the host. */
+ if (argc == 2)
+ zQrequestor = zbufcpy (argv[1]);
+ else
+ {
+ zQrequestor = zbufalc (strlen (argv[1]) + strlen (argv[2])
+ + sizeof "!");
+ sprintf (zQrequestor, "%s!%s", argv[2], argv[1]);
+ }
+
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* Handle the U command, which takes two arguments. */
+
+/*ARGSUSED*/
+static int
+iquser (puuconf, argc, argv, pvar, pinfo)
+ pointer puuconf;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ zQuser = argv[1];
+ zQsystem = argv[2];
+ return UUCONF_CMDTABRET_KEEP;
+}
+
+/* Handle various commands which just set boolean variables. */
+
+/*ARGSUSED*/
+static int
+iqset (puuconf, argc, argv, pvar, pinfo)
+ pointer puuconf;
+ int argc;
+ char **argv;
+ pointer pvar;
+ pointer pinfo;
+{
+ boolean *pf = (boolean *) pvar;
+
+ *pf = TRUE;
+ return UUCONF_CMDTABRET_CONTINUE;
+}
+
+/* The execution processing does a lot of things that have to be
+ cleaned up. Rather than try to add the appropriate statements
+ to each return point, we keep a set of flags indicating what
+ has to be cleaned up. The actual clean up is done by the
+ function uqcleanup. */
+#define REMOVE_FILE (01)
+#define REMOVE_NEEDED (02)
+#define FREE_QINPUT (04)
+#define FREE_OUTPUT (010)
+#define FREE_MAIL (020)
+
+/* Process an execute file. The zfile argument is the name of the
+ execute file. The zbase argument is the base name of zfile. The
+ qsys argument describes the system it came from. The zcmd argument
+ is the name of the command we are executing (from the -c option) or
+ NULL if any command is OK. This sets *pfprocessed to TRUE if the
+ file is ready to be executed. */
+
+static void
+uqdo_xqt_file (puuconf, zfile, zbase, qsys, zlocalname, zcmd, pfprocessed)
+ pointer puuconf;
+ const char *zfile;
+ const char *zbase;
+ const struct uuconf_system *qsys;
+ const char *zlocalname;
+ const char *zcmd;
+ boolean *pfprocessed;
+{
+ char *zabsolute;
+ boolean ferr;
+ FILE *e;
+ int iuuconf;
+ int i;
+ int iclean;
+ const char *zmail;
+ char *zoutput;
+ char *zinput;
+ char abtemp[CFILE_NAME_LEN];
+ char abdata[CFILE_NAME_LEN];
+ char *zerror;
+ struct uuconf_system soutsys;
+ const struct uuconf_system *qoutsys;
+ boolean fshell;
+ size_t clen;
+ char *zfullcmd;
+ boolean ftemp;
+
+ *pfprocessed = FALSE;
+
+ e = fopen (zfile, "r");
+ if (e == NULL)
+ return;
+
+ azQargs = NULL;
+ zQcmd = NULL;
+ zQinput = NULL;
+ zQoutfile = NULL;
+ zQoutsys = NULL;
+ cQfiles = 0;
+ azQfiles = NULL;
+ azQfiles_to = NULL;
+ zQrequestor = NULL;
+ zQuser = NULL;
+ zQsystem = NULL;
+ fQno_ack = FALSE;
+ fQsuccess_ack = FALSE;
+ fQsend_input = FALSE;
+ fQuse_exec = FALSE;
+ zQstatus_file = NULL;
+#if ALLOW_SH_EXECUTION
+ fQuse_sh = FALSE;
+#endif
+
+ iuuconf = uuconf_cmd_file (puuconf, e, asQcmds, (pointer) zbase,
+ (uuconf_cmdtabfn) NULL,
+ UUCONF_CMDTABFLAG_CASE, (pointer) NULL);
+ (void) fclose (e);
+
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ return;
+ }
+
+ iclean = 0;
+
+ if (azQargs == NULL)
+ {
+ ulog (LOG_ERROR, "%s: No command given", zbase);
+ uqcleanup (zfile, iclean | REMOVE_FILE);
+ return;
+ }
+
+ if (zcmd != NULL)
+ {
+ if (strcmp (zcmd, azQargs[0]) != 0)
+ {
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ }
+ else
+ {
+ /* If there is a lock file for this particular command already,
+ it means that some other uuxqt is supposed to handle it. */
+ if (fsysdep_uuxqt_locked (azQargs[0]))
+ {
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ }
+
+ /* Lock this particular file. */
+ if (! fsysdep_lock_uuxqt_file (zfile))
+ {
+ uqcleanup (zfile, iclean);
+ return;
+ }
+
+ zQunlock_file = zfile;
+
+ /* Now that we have the file locked, make sure it still exists.
+ Otherwise another uuxqt could have just finished processing it
+ and removed the lock file. */
+ if (! fsysdep_file_exists (zfile))
+ {
+ uqcleanup (zfile, iclean);
+ return;
+ }
+
+ if (zQuser != NULL)
+ ulog_user (zQuser);
+ else if (zQrequestor != NULL)
+ ulog_user (zQrequestor);
+ else
+ ulog_user ("unknown");
+
+ /* Make sure that all the required files exist, and get their
+ full names in the spool directory. */
+ for (i = 0; i < cQfiles; i++)
+ {
+ char *zreal;
+
+ zreal = zsysdep_spool_file_name (qsys, azQfiles[i], (pointer) NULL);
+ if (zreal == NULL)
+ {
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ if (! fsysdep_file_exists (zreal))
+ {
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ ubuffree (azQfiles[i]);
+ azQfiles[i] = zbufcpy (zreal);
+ ubuffree (zreal);
+ }
+
+ /* Lock the execution directory. */
+ if (! fsysdep_lock_uuxqt_dir (iQlock_seq))
+ {
+ ulog (LOG_ERROR, "Could not lock execute directory");
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ fQunlock_directory = TRUE;
+
+ iclean |= REMOVE_FILE | REMOVE_NEEDED;
+ *pfprocessed = TRUE;
+
+ /* Get the address to mail results to. Prepend the system from
+ which the execute file originated, since mail addresses are
+ relative to it. */
+ zmail = NULL;
+ if (zQrequestor != NULL)
+ zmail = zQrequestor;
+ else if (zQuser != NULL)
+ zmail = zQuser;
+ if (zmail != NULL
+ && zQsystem != NULL
+#if HAVE_INTERNET_MAIL
+ && strchr (zmail, '@') == NULL
+#endif
+ && strcmp (zQsystem, zlocalname) != 0)
+ {
+ char *zset;
+
+ zset = zbufalc (strlen (zQsystem) + strlen (zmail) + 2);
+ sprintf (zset, "%s!%s", zQsystem, zmail);
+ zmail = zset;
+ zQmail = zset;
+ iclean |= FREE_MAIL;
+ }
+
+ /* The command "uucp" is handled specially. We make sure that the
+ appropriate forwarding is permitted, and we add a -u argument to
+ specify the user. */
+ if (strcmp (azQargs[0], "uucp") == 0)
+ {
+ char *zfrom, *zto;
+ boolean fmany;
+ char **azargs;
+ const char *zuser, *zsystem;
+
+ zfrom = NULL;
+ zto = NULL;
+ fmany = FALSE;
+
+ /* Skip all the options, and get the from and to specs. We
+ don't permit multiple arguments. */
+ for (i = 1; azQargs[i] != NULL; i++)
+ {
+ if (azQargs[i][0] == '-')
+ {
+ char *zopts;
+
+ for (zopts = azQargs[i] + 1; *zopts != '\0'; zopts++)
+ {
+ /* The -g, -n, and -s options take an argument. */
+ if (*zopts == 'g' || *zopts == 'n' || *zopts == 's')
+ {
+ if (zopts[1] == '\0')
+ ++i;
+ break;
+ }
+ /* The -I, -u and -x options are not permitted. */
+ if (*zopts == 'I' || *zopts == 'u' || *zopts == 'x')
+ {
+ *zopts = 'r';
+ if (zopts[1] != '\0')
+ zopts[1] = '\0';
+ else
+ {
+ ++i;
+ azQargs[i] = zbufcpy ("-r");
+ }
+ break;
+ }
+ }
+ }
+ else if (zfrom == NULL)
+ zfrom = azQargs[i];
+ else if (zto == NULL)
+ zto = azQargs[i];
+ else
+ {
+ fmany = TRUE;
+ break;
+ }
+ }
+
+ /* Add the -u argument. This is required to let uucp do the
+ correct permissions checking on the file transfer. */
+ for (i = 0; azQargs[i] != NULL; i++)
+ ;
+ azargs = (char **) xmalloc ((i + 2) * sizeof (char *));
+ azargs[0] = azQargs[0];
+ zuser = zQuser;
+ if (zuser == NULL)
+ zuser = "uucp";
+ zsystem = zQsystem;
+ if (zsystem == NULL)
+ zsystem = qsys->uuconf_zname;
+ azargs[1] = zbufalc (strlen (zsystem) + strlen (zuser)
+ + sizeof "-u!");
+ sprintf (azargs[1], "-u%s!%s", zsystem, zuser);
+ memcpy (azargs + 2, azQargs + 1, i * sizeof (char *));
+ xfree ((pointer) azQargs);
+ azQargs = azargs;
+
+ /* Find the uucp binary. */
+ zabsolute = zsysdep_find_command ("uucp", qsys->uuconf_pzcmds,
+ qsys->uuconf_pzpath, &ferr);
+ if (zabsolute == NULL && ! ferr)
+ {
+ const char *azcmds[2];
+
+ /* If "uucp" is not a permitted command, then the forwarding
+ entries must be set. */
+ if (! fqforward (zfrom, qsys->uuconf_pzforward_from, "from", zmail)
+ || ! fqforward (zto, qsys->uuconf_pzforward_to, "to", zmail))
+ {
+ uqcleanup (zfile, iclean);
+ return;
+ }
+
+ /* If "uucp" is not a permitted command, then only uucp
+ requests with a single source are permitted, since that
+ is all that will be generated by uucp or uux. */
+ if (fmany)
+ {
+ ulog (LOG_ERROR, "Bad uucp request %s", zQcmd);
+
+ if (zmail != NULL && ! fQno_ack)
+ {
+ const char *az[20];
+
+ i = 0;
+ az[i++] = "Your execution request failed because it was an";
+ az[i++] = " unsupported uucp request.\n";
+ az[i++] = "Execution requested was:\n\t";
+ az[i++] = zQcmd;
+ az[i++] = "\n";
+
+ (void) fsysdep_mail (zmail, "Execution failed", i, az);
+ }
+
+ uqcleanup (zfile, iclean);
+ return;
+ }
+
+ azcmds[0] = "uucp";
+ azcmds[1] = NULL;
+ zabsolute = zsysdep_find_command ("uucp", (char **) azcmds,
+ qsys->uuconf_pzpath, &ferr);
+ }
+ if (zabsolute == NULL)
+ {
+ if (! ferr)
+ ulog (LOG_ERROR, "Can't find uucp executable");
+
+ uqcleanup (zfile, iclean &~ (REMOVE_FILE | REMOVE_NEEDED));
+ *pfprocessed = FALSE;
+ return;
+ }
+ }
+ else
+ {
+ /* Get the pathname to execute. */
+ zabsolute = zsysdep_find_command (azQargs[0], qsys->uuconf_pzcmds,
+ qsys->uuconf_pzpath,
+ &ferr);
+ if (zabsolute == NULL)
+ {
+ if (ferr)
+ {
+ /* If we get an error, try again later. */
+ uqcleanup (zfile, iclean &~ (REMOVE_FILE | REMOVE_NEEDED));
+ *pfprocessed = FALSE;
+ return;
+ }
+
+ /* Not permitted. Send mail to requestor. */
+ ulog (LOG_ERROR, "Not permitted to execute %s",
+ azQargs[0]);
+
+ if (zmail != NULL && ! fQno_ack)
+ {
+ const char *az[20];
+
+ i = 0;
+ az[i++] = "Your execution request failed because you are not";
+ az[i++] = " permitted to execute\n\t";
+ az[i++] = azQargs[0];
+ az[i++] = "\non this system.\n";
+ az[i++] = "Execution requested was:\n\t";
+ az[i++] = zQcmd;
+ az[i++] = "\n";
+
+ (void) fsysdep_mail (zmail, "Execution failed", i, az);
+ }
+
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ }
+
+ ubuffree (azQargs[0]);
+ azQargs[0] = zabsolute;
+
+ for (i = 1; azQargs[i] != NULL; i++)
+ {
+ char *zlocal;
+
+ zlocal = zsysdep_xqt_local_file (qsys, azQargs[i]);
+ if (zlocal != NULL)
+ {
+ ubuffree (azQargs[i]);
+ azQargs[i] = zlocal;
+ }
+ }
+
+#if ! ALLOW_FILENAME_ARGUMENTS
+
+ /* Check all the arguments to make sure they don't try to specify
+ files they are not permitted to access. */
+ for (i = 1; azQargs[i] != NULL; i++)
+ {
+ if (! fsysdep_xqt_check_file (qsys, azQargs[i]))
+ {
+ if (zmail != NULL && ! fQno_ack)
+ {
+ const char *az[20];
+ const char *zfailed;
+
+ zfailed = azQargs[i];
+ i = 0;
+ az[i++] = "Your execution request failed because you are not";
+ az[i++] = " permitted to refer to file\n\t";
+ az[i++] = zfailed;
+ az[i++] = "\non this system.\n";
+ az[i++] = "Execution requested was:\n\t";
+ az[i++] = zQcmd;
+ az[i++] = "\n";
+
+ (void) fsysdep_mail (zmail, "Execution failed", i, az);
+ }
+
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ }
+
+#endif /* ! ALLOW_FILENAME_ARGUMENTS */
+
+ ulog (LOG_NORMAL, "Executing %s (%s)", zbase, zQcmd);
+
+ if (zQinput != NULL)
+ {
+ boolean fspool;
+ char *zreal;
+
+ fspool = fspool_file (zQinput);
+ if (fspool)
+ zreal = zsysdep_spool_file_name (qsys, zQinput, (pointer) NULL);
+ else
+ zreal = zsysdep_local_file (zQinput, qsys->uuconf_zpubdir);
+ if (zreal == NULL)
+ {
+ /* If we get an error, try again later. */
+ uqcleanup (zfile, iclean &~ (REMOVE_FILE | REMOVE_NEEDED));
+ *pfprocessed = FALSE;
+ return;
+ }
+
+ zQinput = zreal;
+ iclean |= FREE_QINPUT;
+
+ if (! fspool
+ && ! fin_directory_list (zQinput, qsys->uuconf_pzremote_send,
+ qsys->uuconf_zpubdir, TRUE, TRUE,
+ (const char *) NULL))
+ {
+ ulog (LOG_ERROR, "Not permitted to read %s", zQinput);
+
+ if (zmail != NULL && ! fQno_ack)
+ {
+ const char *az[20];
+
+ i = 0;
+ az[i++] = "Your execution request failed because you are";
+ az[i++] = " not permitted to read\n\t";
+ az[i++] = zQinput;
+ az[i++] = "\non this system.\n";
+ az[i++] = "Execution requested was:\n\t";
+ az[i++] = zQcmd;
+ az[i++] = "\n";
+
+ (void) fsysdep_mail (zmail, "Execution failed", i, az);
+ }
+
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ }
+
+ zoutput = NULL;
+ if (zQoutfile == NULL)
+ qoutsys = NULL;
+ else if (zQoutsys != NULL
+ && strcmp (zQoutsys, zlocalname) != 0)
+ {
+ char *zdata;
+
+ /* The output file is destined for some other system, so we must
+ use a temporary file to catch standard output. */
+ if (strcmp (zQoutsys, qsys->uuconf_zname) == 0)
+ qoutsys = qsys;
+ else
+ {
+ iuuconf = uuconf_system_info (puuconf, zQoutsys, &soutsys);
+ if (iuuconf != UUCONF_SUCCESS)
+ {
+ if (iuuconf != UUCONF_NOT_FOUND)
+ {
+ ulog_uuconf (LOG_ERROR, puuconf, iuuconf);
+ uqcleanup (zfile, iclean &~ (REMOVE_FILE | REMOVE_NEEDED));
+ *pfprocessed = FALSE;
+ return;
+ }
+
+ if (! funknown_system (puuconf, zQoutsys, &soutsys))
+ {
+ ulog (LOG_ERROR,
+ "Can't send standard output to unknown system %s",
+ zQoutsys);
+ /* We don't send mail to unknown systems, either.
+ Maybe we should. */
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ }
+
+ qoutsys = &soutsys;
+ }
+
+ zdata = zsysdep_data_file_name (qoutsys, zlocalname,
+ BDEFAULT_UUX_GRADE, FALSE, abtemp,
+ abdata, (char *) NULL);
+ if (zdata == NULL)
+ {
+ /* If we get an error, try again later. */
+ uqcleanup (zfile, iclean &~ (REMOVE_FILE | REMOVE_NEEDED));
+ *pfprocessed = FALSE;
+ return;
+ }
+ zoutput = zdata;
+ zQoutput = zoutput;
+ iclean |= FREE_OUTPUT;
+ }
+ else
+ {
+ boolean fok;
+
+ qoutsys = NULL;
+
+ /* If we permitted the standard output to be redirected into
+ the spool directory, people could set up phony commands. */
+ if (fspool_file (zQoutfile))
+ fok = FALSE;
+ else
+ {
+ zoutput = zsysdep_local_file (zQoutfile, qsys->uuconf_zpubdir);
+ if (zoutput == NULL)
+ {
+ /* If we get an error, try again later. */
+ uqcleanup (zfile, iclean &~ (REMOVE_FILE | REMOVE_NEEDED));
+ *pfprocessed = FALSE;
+ return;
+ }
+ ubuffree (zQoutfile);
+ zQoutfile = zoutput;
+
+ /* Make sure it's OK to receive this file. */
+ fok = fin_directory_list (zQoutfile,
+ qsys->uuconf_pzremote_receive,
+ qsys->uuconf_zpubdir, TRUE, FALSE,
+ (const char *) NULL);
+ }
+
+ if (! fok)
+ {
+ ulog (LOG_ERROR, "Not permitted to write to %s", zQoutfile);
+
+ if (zmail != NULL && ! fQno_ack)
+ {
+ const char *az[20];
+
+ i = 0;
+ az[i++] = "Your execution request failed because you are";
+ az[i++] = " not permitted to write to\n\t";
+ az[i++] = zQoutfile;
+ az[i++] = "\non this system.\n";
+ az[i++] = "Execution requested was:\n\t";
+ az[i++] = zQcmd;
+ az[i++] = "\n";
+
+ (void) fsysdep_mail (zmail, "Execution failed", i, az);
+ }
+
+ uqcleanup (zfile, iclean);
+ return;
+ }
+ }
+
+ /* Move the required files to the execution directory if necessary. */
+ zinput = zQinput;
+ if (! fsysdep_move_uuxqt_files (cQfiles, (const char **) azQfiles,
+ (const char **) azQfiles_to,
+ TRUE, iQlock_seq, &zinput))
+ {
+ /* If we get an error, try again later. */
+ uqcleanup (zfile, iclean &~ (REMOVE_FILE | REMOVE_NEEDED));
+ *pfprocessed = FALSE;
+ return;
+ }
+ if (zQinput != NULL && strcmp (zQinput, zinput) != 0)
+ {
+ if ((iclean & FREE_QINPUT) != 0)
+ ubuffree (zQinput);
+ zQinput = zinput;
+ iclean |= FREE_QINPUT;
+ }
+
+#if ALLOW_SH_EXECUTION
+ fshell = fQuse_sh;
+#else
+ fshell = FALSE;
+#endif
+
+ /* Get a shell command which uses the full path of the command to
+ execute. */
+ clen = 0;
+ for (i = 0; azQargs[i] != NULL; i++)
+ clen += strlen (azQargs[i]) + 1;
+ zfullcmd = zbufalc (clen);
+ strcpy (zfullcmd, azQargs[0]);
+ for (i = 1; azQargs[i] != NULL; i++)
+ {
+ strcat (zfullcmd, " ");
+ strcat (zfullcmd, azQargs[i]);
+ }
+
+ if (! fsysdep_execute (qsys,
+ zQuser == NULL ? (const char *) "uucp" : zQuser,
+ (const char **) azQargs, zfullcmd, zQinput,
+ zoutput, fshell, iQlock_seq, &zerror, &ftemp))
+ {
+ ubuffree (zfullcmd);
+
+ if (ftemp)
+ {
+ ulog (LOG_NORMAL, "Will retry later (%s)", zbase);
+ if (zoutput != NULL)
+ (void) remove (zoutput);
+ if (zerror != NULL)
+ {
+ (void) remove (zerror);
+ ubuffree (zerror);
+ }
+ (void) fsysdep_move_uuxqt_files (cQfiles, (const char **) azQfiles,
+ (const char **) azQfiles_to,
+ FALSE, iQlock_seq,
+ (char **) NULL);
+ uqcleanup (zfile, iclean &~ (REMOVE_FILE | REMOVE_NEEDED));
+ *pfprocessed = FALSE;
+ return;
+ }
+
+ ulog (LOG_NORMAL, "Execution failed (%s)", zbase);
+
+ if (zmail != NULL && ! fQno_ack)
+ {
+ const char **pz;
+ int cgot;
+ FILE *eerr;
+ int istart;
+
+ cgot = 20;
+ pz = (const char **) xmalloc (cgot * sizeof (const char *));
+ i = 0;
+ pz[i++] = "Execution request failed:\n\t";
+ pz[i++] = zQcmd;
+ pz[i++] = "\n";
+
+ if (zerror == NULL)
+ eerr = NULL;
+ else
+ eerr = fopen (zerror, "r");
+ if (eerr == NULL)
+ {
+ pz[i++] = "There was no output on standard error\n";
+ istart = i;
+ }
+ else
+ {
+ char *zline;
+ size_t cline;
+
+ pz[i++] = "Standard error output was:\n";
+ istart = i;
+
+ zline = NULL;
+ cline = 0;
+ while (getline (&zline, &cline, eerr) > 0)
+ {
+ if (i >= cgot)
+ {
+ cgot += 20;
+ pz = ((const char **)
+ xrealloc ((pointer) pz,
+ cgot * sizeof (const char *)));
+ }
+ pz[i++] = zbufcpy (zline);
+ }
+
+ (void) fclose (eerr);
+ xfree ((pointer) zline);
+ }
+
+ (void) fsysdep_mail (zmail, "Execution failed", i, pz);
+
+ for (; istart < i; istart++)
+ ubuffree ((char *) pz[istart]);
+ xfree ((pointer) pz);
+ }
+
+ if (qoutsys != NULL)
+ (void) remove (zoutput);
+ }
+ else
+ {
+ ubuffree (zfullcmd);
+
+ if (zmail != NULL && fQsuccess_ack)
+ {
+ const char *az[20];
+
+ i = 0;
+ az[i++] = "\nExecution request succeeded:\n\t";
+ az[i++] = zQcmd;
+ az[i++] = "\n";
+
+ (void) fsysdep_mail (zmail, "Execution succeded", i, az);
+ }
+
+ /* Now we may have to uucp the output to some other machine. */
+
+ if (qoutsys != NULL)
+ {
+ struct scmd s;
+
+ /* Fill in the command structure. */
+
+ s.bcmd = 'S';
+ s.pseq = NULL;
+ s.zfrom = abtemp;
+ s.zto = zQoutfile;
+ if (zQuser != NULL)
+ s.zuser = zQuser;
+ else
+ s.zuser = "uucp";
+ if (zmail != NULL && fQsuccess_ack)
+ s.zoptions = "Cn";
+ else
+ s.zoptions = "C";
+ s.ztemp = abtemp;
+ s.imode = 0666;
+ if (zmail != NULL && fQsuccess_ack)
+ s.znotify = zmail;
+ else
+ s.znotify = "";
+ s.cbytes = -1;
+ s.zcmd = NULL;
+ s.ipos = 0;
+
+ ubuffree (zsysdep_spool_commands (qoutsys, BDEFAULT_UUX_GRADE,
+ 1, &s));
+ }
+ }
+
+ if (zerror != NULL)
+ {
+ (void) remove (zerror);
+ ubuffree (zerror);
+ }
+
+ uqcleanup (zfile, iclean);
+}
+
+/* Clean up the results of uqdo_xqt_file. */
+
+static void
+uqcleanup (zfile, iflags)
+ const char *zfile;
+ int iflags;
+{
+ int i;
+
+ DEBUG_MESSAGE2 (DEBUG_SPOOLDIR,
+ "uqcleanup: %s, %d", zfile, iflags);
+
+ if (zQunlock_file != NULL)
+ {
+ (void) fsysdep_unlock_uuxqt_file (zQunlock_file);
+ zQunlock_file = NULL;
+ }
+
+ if ((iflags & REMOVE_FILE) != 0)
+ (void) remove (zfile);
+
+ if ((iflags & REMOVE_NEEDED) != 0)
+ {
+ for (i = 0; i < cQfiles; i++)
+ {
+ if (azQfiles[i] != NULL)
+ (void) remove (azQfiles[i]);
+ }
+ }
+
+ if ((iflags & FREE_QINPUT) != 0)
+ ubuffree (zQinput);
+
+ if ((iflags & FREE_OUTPUT) != 0)
+ ubuffree (zQoutput);
+ if ((iflags & FREE_MAIL) != 0)
+ ubuffree (zQmail);
+
+ if (fQunlock_directory)
+ {
+ (void) fsysdep_unlock_uuxqt_dir (iQlock_seq);
+ fQunlock_directory = FALSE;
+ }
+
+ for (i = 0; i < cQfiles; i++)
+ {
+ ubuffree (azQfiles[i]);
+ ubuffree (azQfiles_to[i]);
+ }
+
+ ubuffree (zQoutfile);
+ ubuffree (zQoutsys);
+ ubuffree (zQrequestor);
+
+ if (azQargs != NULL)
+ {
+ for (i = 0; azQargs[i] != NULL; i++)
+ ubuffree (azQargs[i]);
+ xfree ((pointer) azQargs);
+ azQargs = NULL;
+ }
+
+ xfree ((pointer) zQcmd);
+ zQcmd = NULL;
+
+ xfree ((pointer) azQfiles);
+ azQfiles = NULL;
+
+ xfree ((pointer) azQfiles_to);
+ azQfiles_to = NULL;
+}
+
+/* Check whether forwarding is permitted. */
+
+static boolean
+fqforward (zfile, pzallowed, zlog, zmail)
+ const char *zfile;
+ char **pzallowed;
+ const char *zlog;
+ const char *zmail;
+{
+ const char *zexclam;
+
+ zexclam = strchr (zfile, '!');
+ if (zexclam != NULL)
+ {
+ size_t clen;
+ char *zsys;
+ boolean fret;
+
+ clen = zexclam - zfile;
+ zsys = zbufalc (clen + 1);
+ memcpy (zsys, zfile, clen);
+ zsys[clen] = '\0';
+
+ fret = FALSE;
+ if (pzallowed != NULL)
+ {
+ char **pz;
+
+ for (pz = pzallowed; *pz != NULL; pz++)
+ {
+ if (strcmp (*pz, "ANY") == 0
+ || strcmp (*pz, zsys) == 0)
+ {
+ fret = TRUE;
+ break;
+ }
+ }
+ }
+
+ if (! fret)
+ {
+ ulog (LOG_ERROR, "Not permitted to forward %s %s (%s)",
+ zlog, zsys, zQcmd);
+
+ if (zmail != NULL && ! fQno_ack)
+ {
+ int i;
+ const char *az[20];
+
+ i = 0;
+ az[i++] = "Your execution request failed because you are";
+ az[i++] = " not permitted to forward files\n";
+ az[i++] = zlog;
+ az[i++] = " the system\n\t";
+ az[i++] = zsys;
+ az[i++] = "\n";
+ az[i++] = "Execution requested was:\n\t";
+ az[i++] = zQcmd;
+ az[i++] = "\n";
+
+ (void) fsysdep_mail (zmail, "Execution failed", i, az);
+ }
+ }
+
+ ubuffree (zsys);
+
+ return fret;
+ }
+
+ return TRUE;
+}