BSD 4_4 release
[unix-history] / usr / src / usr.bin / uucp / acucntrl / acucntrl.c
index 71db3d2..deba6ba 100644 (file)
@@ -1,6 +1,45 @@
+/*-
+ * Copyright (c) 1985, 1986, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)acucntrl.c 5.7 (Berkeley) %G%";
-#endif
+static char copyright[] =
+"@(#) Copyright (c) 1985, 1986, 1993\n\
+       The Regents of the University of California.  All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)acucntrl.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
 
 /*  acucntrl - turn around tty line between dialin and dialout
  * 
 
 /*  acucntrl - turn around tty line between dialin and dialout
  * 
@@ -19,28 +58,28 @@ static char sccsid[] = "@(#)acucntrl.c      5.7 (Berkeley) %G%";
  * Operation:
  *   disable (i.e. setup for dialing out)
  *     (1) check input arguments
  * Operation:
  *   disable (i.e. setup for dialing out)
  *     (1) check input arguments
- *     (2) look in /etc/utmp to check that the line is not in use by another
+ *     (2) look in _PATH_UTMP to check that the line is not in use by another
  *     (3) disable modem control on terminal
  *     (4) check for carrier on device
  *     (5) change owner of device to real id
  *     (3) disable modem control on terminal
  *     (4) check for carrier on device
  *     (5) change owner of device to real id
- *     (6) edit /etc/ttys,  changing the first character of the appropriate
+ *     (6) edit _PATH_TTYS, changing the first character of the appropriate
  *         line to 0
  *     (7) send a hangup to process 1 to poke init to disable getty
  *         line to 0
  *     (7) send a hangup to process 1 to poke init to disable getty
- *     (8) post uid name in capitals in /etc/utmp to let world know device has
- *         been grabbed
+ *     (8) post uid name in capitals in _PATH_UTMP to let world know device
+ *         has been grabbed
  *     (9) make sure that DTR is on
  *
  *   enable (i.e.) restore for dialin
  *     (1) check input arguments
  *     (9) make sure that DTR is on
  *
  *   enable (i.e.) restore for dialin
  *     (1) check input arguments
- *     (2) look in /etc/utmp to check that the line is not in use by another
+ *     (2) look in _PATH_UTMP to check that the line is not in use by another
  *     (3) make sure modem control on terminal is disabled
  *     (4) turn off DTR to make sure line is hung up
  *     (5) condition line: clear exclusive use and set hangup on close modes
  *     (6) turn on modem control
  *     (3) make sure modem control on terminal is disabled
  *     (4) turn off DTR to make sure line is hung up
  *     (5) condition line: clear exclusive use and set hangup on close modes
  *     (6) turn on modem control
- *     (7) edit /etc/ttys,  changing the first character of the appropriate
+ *     (7) edit _PATH_TTYS, changing the first character of the appropriate
  *         line to 1
  *     (8) send a hangup to process 1 to poke init to enable getty
  *         line to 1
  *     (8) send a hangup to process 1 to poke init to enable getty
- *     (9) clear uid name for /etc/utmp
+ *     (9) clear uid name for _PATH_UTMP
  */
 
 /* #define SENSECARRIER */
  */
 
 /* #define SENSECARRIER */
@@ -50,11 +89,13 @@ static char sccsid[] = "@(#)acucntrl.c      5.7 (Berkeley) %G%";
 #include <sys/buf.h>
 #include <signal.h>
 #include <sys/conf.h>
 #include <sys/buf.h>
 #include <signal.h>
 #include <sys/conf.h>
+#ifdef vax
 #ifdef BSD4_2
 #include <vaxuba/ubavar.h>
 #else
 #include <sys/ubavar.h>
 #endif
 #ifdef BSD4_2
 #include <vaxuba/ubavar.h>
 #else
 #include <sys/ubavar.h>
 #endif
+#endif /* vax */
 #include <sys/stat.h>
 #include <nlist.h>
 #include <sgtty.h>
 #include <sys/stat.h>
 #include <nlist.h>
 #include <sgtty.h>
@@ -62,6 +103,7 @@ static char sccsid[] = "@(#)acucntrl.c       5.7 (Berkeley) %G%";
 #include <pwd.h>
 #include <stdio.h>
 #include <sys/file.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <sys/file.h>
+#include "pathnames.h"
 
 #define NDZLINE        8       /* lines/dz */
 #define NDHLINE        16      /* lines/dh */
 
 #define NDZLINE        8       /* lines/dz */
 #define NDHLINE        16      /* lines/dh */
@@ -110,14 +152,13 @@ struct nlist nl[] = {
 #define ENABLE 1
 #define DISABLE        0
 
 #define ENABLE 1
 #define DISABLE        0
 
-char Etcutmp[] = "/etc/utmp";
-char Etcttys[] = "/etc/ttys";
+char Etcttys[] = _PATH_TTYS;
 #ifdef BSD4_3
 FILE *ttysfile, *nttysfile;
 #ifdef BSD4_3
 FILE *ttysfile, *nttysfile;
-char NEtcttys[] = "/etc/ttys.new";
+char NEtcttys[] = _PATH_NEWTTYS;
 extern long ftell();
 #endif BSD4_3
 extern long ftell();
 #endif BSD4_3
-char Devhome[] = "/dev";
+char Devhome[] = _PATH_DEV;
 
 char usage[] = "Usage: acucntrl {dis|en}able ttydX\n";
 
 
 char usage[] = "Usage: acucntrl {dis|en}able ttydX\n";
 
@@ -126,6 +167,9 @@ char resettty, resetmodem;
 int etcutmp;
 off_t utmploc;
 off_t ttyslnbeg;
 int etcutmp;
 off_t utmploc;
 off_t ttyslnbeg;
+extern int errno;
+extern char *sys_errlist[];
+off_t lseek();
 
 #define NAMSIZ sizeof(utmp.ut_name)
 #define        LINSIZ  sizeof(utmp.ut_line)
 
 #define NAMSIZ sizeof(utmp.ut_name)
 #define        LINSIZ  sizeof(utmp.ut_line)
@@ -140,14 +184,11 @@ int argc; char *argv[];
        char *device;
        int devfile;
        int uid, gid;
        char *device;
        int devfile;
        int uid, gid;
-       off_t lseek();
        struct passwd *getpwuid();
        char *rindex();
        struct passwd *getpwuid();
        char *rindex();
-       extern int errno;
-       extern char *sys_errlist[];
 
        /* check input arguments */
 
        /* check input arguments */
-       if (argc!=3) {
+       if (argc!=3 && argc != 4) {
                fprintf(stderr, usage);
                exit(1);
        }
                fprintf(stderr, usage);
                exit(1);
        }
@@ -165,16 +206,12 @@ int argc; char *argv[];
        device = rindex(argv[2], '/');
        device = (device == NULL) ? argv[2]: device+1;
 
        device = rindex(argv[2], '/');
        device = (device == NULL) ? argv[2]: device+1;
 
-       /* only recognize devices of the form ttydX */
-       if (strncmp(device, "ttyd", 4)!=0) {
-               fprintf(stderr, "Bad Device Name %s", device);
-               exit(1);
-       }
-
        opnttys(device);
 
        opnttys(device);
 
+#ifdef vax
        /* Get nlist info */
        /* Get nlist info */
-       nlist("/vmunix", nl);
+       nlist(_PATH_UNIX, nl);
+#endif vax
 
        /* Chdir to /dev */
        if(chdir(Devhome) < 0) {
 
        /* Chdir to /dev */
        if(chdir(Devhome) < 0) {
@@ -193,19 +230,20 @@ int argc; char *argv[];
                exit(1);
        }
 
                exit(1);
        }
 
+       if (strcmp(p, "uucp") == 0 && argc == 4)
+               p = argv[3];
+
        /*  to upper case */
        i = 0;
        do {
                uname[i] = *p;
        /*  to upper case */
        i = 0;
        do {
                uname[i] = *p;
-               Uname[i] = (*p>='a' && *p<='z') ? (*p - ('a'-'A')) : *p;
-               i++; p++;
-       } while (*p && i<NAMSIZ);
-
+               Uname[i++] = (*p>='a' && *p<='z') ? (*p - ('a'-'A')) : *p;
+       } while (*p++ && i<NAMSIZ);
 
        /* check to see if line is being used */
 
        /* check to see if line is being used */
-       if( (etcutmp = open(Etcutmp, 2)) < 0) {
+       if( (etcutmp = open(_PATH_UTMP, 2)) < 0) {
                fprintf(stderr, "On open %s open: %s\n",
                fprintf(stderr, "On open %s open: %s\n",
-                       Etcutmp, sys_errlist[errno]);
+                       _PATH_UTMP, sys_errlist[errno]);
                exit(1);
        }
 
                exit(1);
        }
 
@@ -229,13 +267,23 @@ int argc; char *argv[];
                exit(2);
        }
 
                exit(2);
        }
 
+#ifndef sequent
        /* Disable modem control */
        if (setmodem(device, DISABLE) < 0) {
                fprintf(stderr, "Unable to disable modem control\n");
                exit(1);
        }
        /* Disable modem control */
        if (setmodem(device, DISABLE) < 0) {
                fprintf(stderr, "Unable to disable modem control\n");
                exit(1);
        }
+#endif !sequent
 
        if (enable) {
 
        if (enable) {
+#ifdef sequent
+               if (setmodem(device, ENABLE) < 0) {
+                       fprintf(stderr, "Cannot Enable modem control\n");
+                       (void)setmodem(device, i);
+                       exit(1);
+               }
+#endif sequent
+#ifndef sequent
                if((devfile = open(device, 1)) < 0) {
                        fprintf(stderr, "On open of %s: %s\n",
                                device, sys_errlist[errno]);
                if((devfile = open(device, 1)) < 0) {
                        fprintf(stderr, "On open of %s: %s\n",
                                device, sys_errlist[errno]);
@@ -257,13 +305,16 @@ int argc; char *argv[];
                            "Cannot set hangup on close on %s: %s\n",
                                device, sys_errlist[errno]);
 
                            "Cannot set hangup on close on %s: %s\n",
                                device, sys_errlist[errno]);
 
+#endif !sequent
                i = resetmodem;
 
                i = resetmodem;
 
+#ifndef sequent
                if (setmodem(device, ENABLE) < 0) {
                        fprintf(stderr, "Cannot Enable modem control\n");
                        (void)setmodem(device, i);
                        exit(1);
                }
                if (setmodem(device, ENABLE) < 0) {
                        fprintf(stderr, "Cannot Enable modem control\n");
                        (void)setmodem(device, i);
                        exit(1);
                }
+#endif sequent
                resetmodem=i;
 
                if (settys(ENABLE)) {
                resetmodem=i;
 
                if (settys(ENABLE)) {
@@ -312,6 +363,13 @@ int argc; char *argv[];
                        pokeinit(device, Uname, enable);
                }
                post(device, Uname);
                        pokeinit(device, Uname, enable);
                }
                post(device, Uname);
+#ifdef sequent
+       /* Disable modem control */
+       if (setmodem(device, DISABLE) < 0) {
+               fprintf(stderr, "Unable to disable modem control\n");
+               exit(1);
+       }
+#endif sequent
                if((devfile = open(device, O_RDWR|O_NDELAY)) < 0) {
                        fprintf(stderr, "On %s open: %s\n",
                                device, sys_errlist[errno]);
                if((devfile = open(device, O_RDWR|O_NDELAY)) < 0) {
                        fprintf(stderr, "On %s open: %s\n",
                                device, sys_errlist[errno]);
@@ -345,11 +403,11 @@ char *device, *name;
        strncpy(utmp.ut_line, device, LINSIZ);
        strncpy(utmp.ut_name, name,  NAMSIZ);
        if (lseek(etcutmp, utmploc, 0) < 0)
        strncpy(utmp.ut_line, device, LINSIZ);
        strncpy(utmp.ut_name, name,  NAMSIZ);
        if (lseek(etcutmp, utmploc, 0) < 0)
-               fprintf(stderr, "on lseek in /etc/utmp: %s",
-                       sys_errlist[errno]);
+               fprintf(stderr, "on lseek in %s: %s",
+                       _PATH_UTMP, sys_errlist[errno]);
        if (write(etcutmp, (char *)&utmp, sizeof(utmp)) < 0)
        if (write(etcutmp, (char *)&utmp, sizeof(utmp)) < 0)
-               fprintf(stderr, "on write in /etc/utmp: %s",
-                       sys_errlist[errno]);
+               fprintf(stderr, "on write in %s: %s",
+                       _PATH_UTMP, sys_errlist[errno]);
 }
        
 /* poke process 1 and wait for it to do its thing */
 }
        
 /* poke process 1 and wait for it to do its thing */
@@ -379,11 +437,11 @@ char *uname, *device; int enable;
        do {
                sleep(1);
                if (lseek(etcutmp, utmploc, 0) < 0)
        do {
                sleep(1);
                if (lseek(etcutmp, utmploc, 0) < 0)
-                       fprintf(stderr, "On lseek in /etc/utmp: %s",
-                               sys_errlist[errno]);
+                       fprintf(stderr, "On lseek in %s: %s",
+                               _PATH_UTMP, sys_errlist[errno]);
                if (read(etcutmp, (char *)&utmp, sizeof utmp) < 0)
                if (read(etcutmp, (char *)&utmp, sizeof utmp) < 0)
-                       fprintf(stderr, "On read from /etc/utmp: %s",
-                               sys_errlist[errno]);
+                       fprintf(stderr, "On read from %s: %s",
+                               _PATH_UTMP, sys_errlist[errno]);
        } while (utmp.ut_name[0] != '\0' && --i > 0);
 }
 
        } while (utmp.ut_name[0] != '\0' && --i > 0);
 }
 
@@ -441,7 +499,7 @@ char *device;
        exit(1);
 }
 
        exit(1);
 }
 
-/* modify appropriate line in /etc/ttys to turn on/off the device */
+/* modify appropriate line in _PATH_TTYS to turn on/off the device */
 settys(enable)
 int enable;
 {
 settys(enable)
 int enable;
 {
@@ -475,7 +533,8 @@ int enable;
                        cp++;
        }
        if (*cp == '\0') {
                        cp++;
        }
        if (*cp == '\0') {
-               fprintf(stderr,"Badly formatted line in /etc/ttys:\n%s", lbuf);
+               fprintf(stderr,"Badly formatted line in %s:\n%s",
+                   _PATH_TTYS, lbuf);
                exit(1);
        }
        c1 = *--cp;
                exit(1);
        }
        c1 = *--cp;
@@ -484,7 +543,8 @@ int enable;
        while (*cp && *cp != ' ' && *cp != '\t' && *cp != '\n')
                cp++;
        if (*cp == '\0') {
        while (*cp && *cp != ' ' && *cp != '\t' && *cp != '\n')
                cp++;
        if (*cp == '\0') {
-               fprintf(stderr,"Badly formatted line in /etc/ttys:\n%s", lbuf);
+               fprintf(stderr,"Badly formatted line in %s:\n%s",
+                   _PATH_TTYS, lbuf);
                exit(1);
        }
        c2 = *cp;
                exit(1);
        }
        c2 = *cp;
@@ -550,6 +610,10 @@ char *device;
                        *p = '\0';
                if(strncmp(device, &linebuf[2], ndevice) == 0) {
                        (void)fclose(ttysfile);
                        *p = '\0';
                if(strncmp(device, &linebuf[2], ndevice) == 0) {
                        (void)fclose(ttysfile);
+#ifdef sequent
+                       /* Why is the sequent off by one? */
+                       utmploc += sizeof(utmp);
+#endif sequent
                        return;
                }
                ttyslnbeg += lnsiz;
                        return;
                }
                ttyslnbeg += lnsiz;
@@ -559,7 +623,7 @@ char *device;
        exit(1);
 }
 
        exit(1);
 }
 
-/* modify appropriate line in /etc/ttys to turn on/off the device */
+/* modify appropriate line in _PATH_TTYS to turn on/off the device */
 settys(enable)
 int enable;
 {
 settys(enable)
 int enable;
 {
@@ -591,6 +655,17 @@ int enable;
 }
 #endif !BSD4_3
 
 }
 #endif !BSD4_3
 
+#ifdef sequent
+setmodem(ttyline, enable)
+char *ttyline; int enable;
+{
+       char *sysbuf[BUFSIZ];
+       sprintf(sysbuf,"/etc/ttyconfig /dev/%s -special %s", ttyline,
+               enable ? "-carrier" : "-nocarrier");
+       system(sysbuf);
+}
+#endif /* sequent */
+#ifdef vax
 /*
  * Excerpted from (June 8, 1983 W.Sebok)
  * > ttymodem.c - enable/disable modem control for tty lines.
 /*
  * Excerpted from (June 8, 1983 W.Sebok)
  * > ttymodem.c - enable/disable modem control for tty lines.
@@ -623,8 +698,9 @@ char *ttyline; int enable;
                return(-1);
        }
 
                return(-1);
        }
 
-       if((kmem = open("/dev/kmem", 2)) < 0) {
-               fprintf(stderr, "/dev/kmem open: %s\n", sys_errlist[errno]);
+       if((kmem = open(_PATH_KMEM, 2)) < 0) {
+               fprintf(stderr, "%s open: %s\n", _PATH_KMEM,
+                   sys_errlist[errno]);
                return(-1);
        }
 
                return(-1);
        }
 
@@ -710,7 +786,7 @@ char *ttyline; int enable;
                        }
                        cflags = flags;
                        (void)lseek(kmem, (off_t) &(((char *)addr)[unit]), 0);
                        }
                        cflags = flags;
                        (void)lseek(kmem, (off_t) &(((char *)addr)[unit]), 0);
-                       (void)write(kmem, (char *) &flags, sizeof cflags);
+                       (void)write(kmem, (char *) &cflags, sizeof cflags);
                        break;
                default:
                        fprintf(stderr, "Unknown device type\n");
                        break;
                default:
                        fprintf(stderr, "Unknown device type\n");
@@ -718,6 +794,7 @@ char *ttyline; int enable;
        }
        return(0);
 }
        }
        return(0);
 }
+#endif /* vax */
 
 prefix(s1, s2)
        register char *s1, *s2;
 
 prefix(s1, s2)
        register char *s1, *s2;
@@ -729,4 +806,9 @@ prefix(s1, s2)
                        return (1);
        return (c == '\0');
 }
                        return (1);
        return (c == '\0');
 }
-#endif DIALINOUT
+#else  /* !DIALINOUT */
+main()
+{
+       fprintf(stderr,"acucntrl is not supported on this system\n");
+}
+#endif /* !DIALINOUT */