]> git.saurik.com Git - apple/network_cmds.git/blobdiff - rtadvd.tproj/advcap.c
network_cmds-596.tar.gz
[apple/network_cmds.git] / rtadvd.tproj / advcap.c
index 2a52ff266f09987679898d2892a9fb5eb2812155..33b6fae33635350adf2e48b428bf489898440a9d 100644 (file)
@@ -1,4 +1,32 @@
-/*     $KAME: advcap.c,v 1.5 2001/02/01 09:12:08 jinmei Exp $  */
+/*
+ * Copyright (c) 2009-2011 Apple Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ *
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+
+/*     $KAME: advcap.c,v 1.11 2003/05/19 09:46:50 keiichi Exp $        */
 
 /*
  * Copyright (c) 1983 The Regents of the University of California.
@@ -31,8 +59,6 @@
  * 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.
- *
- * $FreeBSD: src/usr.sbin/rtadvd/advcap.c,v 1.1.2.2 2001/07/03 11:02:13 ume Exp $
  */
 
 /*
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <syslog.h>
 #include <errno.h>
 #include <string.h>
 #include "pathnames.h"
+#include "rtadvd_logging.h"
 
 #ifndef BUFSIZ
 #define        BUFSIZ          1024
@@ -92,15 +118,15 @@ static     char *remotefile;
 
 extern char *conffile;
 
-int tgetent __P((char *, char *));
-int getent __P((char *, char *, char *));
-int tnchktc __P((void));
-int tnamatch __P((char *));
-static char *tskip __P((char *));
-long long tgetnum __P((char *));
-int tgetflag __P((char *));
-char *tgetstr __P((char *, char **));
-static char *tdecode __P((char *, char **));
+int tgetent(char *, char *);
+int getent(char *, char *, char *);
+int tnchktc(void);
+int tnamatch(char *);
+static char *tskip(char *);
+int64_t tgetnum(char *);
+int tgetflag(char *);
+char *tgetstr(char *, char **);
+static char *tdecode(char *, char **);
 
 /*
  * Get an entry for terminal name in buffer bp,
@@ -121,8 +147,8 @@ int
 getent(bp, name, cp)
        char *bp, *name, *cp;
 {
-       register int c;
-       register int i = 0, cnt = 0;
+       int c;
+       int i = 0, cnt = 0;
        char ibuf[BUFSIZ];
        int tf;
 
@@ -139,8 +165,7 @@ getent(bp, name, cp)
                tf = open(RM = cp, O_RDONLY);
        }
        if (tf < 0) {
-               syslog(LOG_INFO,
-                      "<%s> open: %s", __FUNCTION__, strerror(errno));
+               infolog("<%s> open: %s", __func__, strerror(errno));
                return (-2);
        }
        for (;;) {
@@ -162,8 +187,9 @@ getent(bp, name, cp)
                                }
                                break;
                        }
-                       if (cp >= bp+BUFSIZ) {
-                               write(2,"Remcap entry too long\n", 23);
+                       if (cp >= bp + BUFSIZ - 1) {
+                               write(STDERR_FILENO, "Remcap entry too long\n",
+                                     22);
                                break;
                        } else
                                *cp++ = c;
@@ -190,7 +216,7 @@ getent(bp, name, cp)
 int
 tnchktc()
 {
-       register char *p, *q;
+       char *p, *q;
        char tcname[16];        /* name of similar terminal */
        char tcbuf[BUFSIZ];
        char *holdtbuf = tbuf;
@@ -198,21 +224,21 @@ tnchktc()
 
        p = tbuf + strlen(tbuf) - 2;    /* before the last colon */
        while (*--p != ':')
-               if (p<tbuf) {
-                       write(2, "Bad remcap entry\n", 18);
+               if (p < tbuf) {
+                       write(STDERR_FILENO, "Bad remcap entry\n", 18);
                        return (0);
                }
        p++;
        /* p now points to beginning of last field */
        if (p[0] != 't' || p[1] != 'c')
                return (1);
-       strcpy(tcname, p+3);
+       strlcpy(tcname, p + 3, sizeof tcname);
        q = tcname;
        while (*q && *q != ':')
                q++;
        *q = 0;
        if (++hopcount > MAXHOP) {
-               write(2, "Infinite tc= loop\n", 18);
+               write(STDERR_FILENO, "Infinite tc= loop\n", 18);
                return (0);
        }
        if (getent(tcbuf, tcname, remotefile) != 1) {
@@ -221,11 +247,13 @@ tnchktc()
        for (q = tcbuf; *q++ != ':'; )
                ;
        l = p - holdtbuf + strlen(q);
+
+       /* check length before copying string below */
        if (l > BUFSIZ) {
-               write(2, "Remcap entry too long\n", 23);
+               write(STDERR_FILENO, "Remcap entry too long\n", 23);
                q[BUFSIZ - (p-holdtbuf)] = 0;
        }
-       strcpy(p, q);
+       strlcpy(p, q, p-tbuf);
        tbuf = holdtbuf;
        return (1);
 }
@@ -240,7 +268,7 @@ int
 tnamatch(np)
        char *np;
 {
-       register char *Np, *Bp;
+       char *Np, *Bp;
 
        Bp = tbuf;
        if (*Bp == '#')
@@ -265,7 +293,7 @@ tnamatch(np)
  */
 static char *
 tskip(bp)
-       register char *bp;
+       char *bp;
 {
        int dquote;
 
@@ -308,13 +336,13 @@ breakbreak:
  * a # character.  If the option is not found we return -1.
  * Note that we handle octal numbers beginning with 0.
  */
-long long
+int64_t
 tgetnum(id)
        char *id;
 {
-       register long long i;
-       register int base;
-       register char *bp = tbuf;
+       int64_t i;
+       int base;
+       char *bp = tbuf;
 
        for (;;) {
                bp = tskip(bp);
@@ -348,7 +376,7 @@ int
 tgetflag(id)
        char *id;
 {
-       register char *bp = tbuf;
+       char *bp = tbuf;
 
        for (;;) {
                bp = tskip(bp);
@@ -376,7 +404,7 @@ char *
 tgetstr(id, area)
        char *id, **area;
 {
-       register char *bp = tbuf;
+       char *bp = tbuf;
 
        for (;;) {
                bp = tskip(bp);
@@ -400,12 +428,12 @@ tgetstr(id, area)
  */
 static char *
 tdecode(str, area)
-       register char *str;
+       char *str;
        char **area;
 {
-       register char *cp;
-       register int c;
-       register char *dp;
+       char *cp;
+       int c;
+       char *dp;
        int i;
        char term;