BSD 4_4 release
[unix-history] / usr / src / usr.bin / uucp / acucntrl / acucntrl.c
index 0a34dd9..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.13    (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.13    (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 */
@@ -64,6 +103,7 @@ static char sccsid[] = "@(#)acucntrl.c       5.13    (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 */
@@ -112,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";
 
@@ -128,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)
@@ -142,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);
        }
@@ -167,17 +206,11 @@ 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);
 
 #ifdef vax
        /* Get nlist info */
        opnttys(device);
 
 #ifdef vax
        /* Get nlist info */
-       nlist("/vmunix", nl);
+       nlist(_PATH_UNIX, nl);
 #endif vax
 
        /* Chdir to /dev */
 #endif vax
 
        /* Chdir to /dev */
@@ -197,6 +230,9 @@ int argc; char *argv[];
                exit(1);
        }
 
                exit(1);
        }
 
+       if (strcmp(p, "uucp") == 0 && argc == 4)
+               p = argv[3];
+
        /*  to upper case */
        i = 0;
        do {
        /*  to upper case */
        i = 0;
        do {
@@ -205,9 +241,9 @@ int argc; char *argv[];
        } while (*p++ && i<NAMSIZ);
 
        /* check to see if line is being used */
        } while (*p++ && i<NAMSIZ);
 
        /* 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);
        }
 
@@ -367,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 */
@@ -401,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);
 }
 
@@ -463,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;
 {
@@ -497,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;
@@ -506,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;
@@ -585,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;
 {
@@ -660,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);
        }