From 5c226f98fd1321b53cad9f785b2cad823124b599 Mon Sep 17 00:00:00 2001 From: srittau Date: Mon, 14 Jan 2002 02:54:47 +0000 Subject: [PATCH] Back-port from HEAD: Cleanups. --- etc/afpd/uam.c | 9 ++- etc/atalkd/config.c | 124 +++++++++++++++++++++++++++------------ libatalk/util/getiface.c | 12 ++-- 3 files changed, 96 insertions(+), 49 deletions(-) diff --git a/etc/afpd/uam.c b/etc/afpd/uam.c index 6635d828..b00b83be 100644 --- a/etc/afpd/uam.c +++ b/etc/afpd/uam.c @@ -1,5 +1,5 @@ /* - * $Id: uam.c,v 1.15.2.1 2001-12-03 05:01:04 jmarcus Exp $ + * $Id: uam.c,v 1.15.2.2 2002-01-14 02:54:47 srittau Exp $ * * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -36,14 +36,14 @@ char *strchr (), *strrchr (); #include #include #include +#include #include #ifdef HAVE_DLFCN_H #include #endif /* HAVE_DLFCN_H */ -#ifdef SHADOWPW -#include -#endif /* SHADOWPW */ +#include +#include #include #include @@ -58,7 +58,6 @@ char *strchr (), *strrchr (); #ifdef TRU64 #include -#include #endif /* TRU64 */ /* --- server uam functions -- */ diff --git a/etc/atalkd/config.c b/etc/atalkd/config.c index aa706e42..265ccc1b 100644 --- a/etc/atalkd/config.c +++ b/etc/atalkd/config.c @@ -1,5 +1,5 @@ /* - * $Id: config.c,v 1.6 2001-09-06 20:00:59 rufustfirefly Exp $ + * $Id: config.c,v 1.6.2.1 2002-01-14 02:54:47 srittau Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -24,8 +24,12 @@ #include #include #include +#include #include #include +#include +#include +#include /* STDC check */ #if STDC_HEADERS @@ -42,11 +46,9 @@ char *strchr (), *strrchr (); #endif /* ! HAVE_MEMCPY */ #endif /* STDC_HEADERS */ -#include #ifdef HAVE_FCNTL_H #include #endif /* HAVE_FCNTL_H */ -#include #ifdef __svr4__ #include @@ -78,54 +80,98 @@ static struct param { { "zone", zone }, }; -static char ** -parseline( line ) - char *line; +#define ARGV_CHUNK_SIZE 128 +char **parseline(const char *line) { - char *p; - int argc = 0; - static char *argv[ 128 ]; - static char buf[ 1024 ]; + const char *p; + int argc = 0; + char *buffer, *tmpbuf; + char **argv; - if ( *line == '#' ) { - return( NULL ); + /* Ignore empty lines and lines with leading hash marks. */ + p = line; + while ( isspace( *p ) ) { + p++; + } + if ( *p == '#' || *p == '\0' ) { + return NULL; } - argc = 0; - memset(argv, 0, sizeof(argv)); - strcpy( buf, line ); - p = buf; + buffer = (char *) malloc( strlen( p ) + 1 ); + if ( !buffer ) { + /* FIXME: error handling */ + return NULL; + } + strcpy( buffer, p ); + tmpbuf = buffer; + + argv = (char **) malloc( ARGV_CHUNK_SIZE * sizeof( char * ) ); + if ( !argv ) { + /* FIXME: error handling */ + free( buffer ); + return NULL; + } /* * This parser should be made more powerful -- it should * handle various escapes, e.g. \" and \031. */ - while ( *p != '\0' ) { - while ( *p != '\0' && *p != '"' && isspace( *p )) { - p++; - } - if ( *p == '\0' ) { - argv[ argc ] = 0; - break; - } - if ( *p == '"' ) { - argv[ argc ] = ++p; - while ( *p != '\0' && *p != '"' ) { - p++; + do { + if ( *tmpbuf == '"' ) { + argv[ argc++ ] = ++tmpbuf; + while ( *tmpbuf != '\0' && *tmpbuf != '"' ) { + tmpbuf++; + } + if ( *tmpbuf == '"' ) { + /* FIXME: error handling */ } } else { - argv[ argc ] = p; - while ( *p != '\0' && !isspace( *p )) { - p++; + argv[ argc++ ] = tmpbuf; + while ( *tmpbuf != '\0' && !isspace( *tmpbuf )) { + tmpbuf++; } } - *p++ = '\0'; - argc++; - } - if ( argv[ 0 ] == '\0' || *argv[ 0 ] == '#' ) { - return( NULL ); + *tmpbuf++ = '\0'; + + /* Make room for a NULL pointer and our special pointer (s.b.) */ + if ( (argc + 1) % ARGV_CHUNK_SIZE == 0 ) { + char **tmp; + tmp = (char **) realloc( argv, argc + 1 + ARGV_CHUNK_SIZE ); + if ( !tmp ) { + /* FIXME: error handling */ + free( argv ); + free( buffer ); + return NULL; + } + argv = tmp; + } + + /* Skip white spaces. */ + while ( isspace( *tmpbuf ) ) { + tmpbuf++; + } + } while ( *tmpbuf != '\0' ); + + argv[ argc++ ] = NULL; + /* We store our buffer pointer in argv, too, so we can free it later. + * (But don't tell anyone.) + */ + argv[ argc ] = buffer; + + return argv; +} + +void freeline( char **argv ) +{ + char **tmp = argv; + + if ( argv ) { + while ( *tmp ) { + tmp++; + } + free( *++tmp ); + free( argv ); } - return( argv ); } int writeconf( cf ) @@ -181,6 +227,7 @@ int writeconf( cf ) syslog( LOG_ERR, "fputs: %m" ); return( -1 ); } + freeline( argv ); continue; } @@ -288,7 +335,8 @@ int readconf( cf ) * Check that av[ 0 ] is a valid interface. * Not possible under sysV. */ - strcpy( ifr.ifr_name, argv[ 0 ] ); + strncpy( ifr.ifr_name, argv[ 0 ], sizeof(ifr.ifr_name) ); + ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0'; /* for devices that don't support appletalk */ if ((ioctl(s, SIOCGIFADDR, &ifr) < 0) && (errno == ENODEV)) { diff --git a/libatalk/util/getiface.c b/libatalk/util/getiface.c index 867e6d62..52f2f7e9 100644 --- a/libatalk/util/getiface.c +++ b/libatalk/util/getiface.c @@ -38,7 +38,7 @@ #define IFACE_NUM 5 /* we leave all of the ioctl's to the application */ -static int addname(char **list, int *i, int *length, const char *name) +static int addname(char **list, int *i, const char *name) { /* if we've run out of room, allocate some more. just return @@ -53,7 +53,7 @@ static int addname(char **list, int *i, int *length, const char *name) } -static int getifaces(const int sockfd, char ***list, int *length) +static int getifaces(const int sockfd, char ***list) { #ifdef HAVE_IFNAMEINDEX struct if_nameindex *ifstart, *ifs; @@ -65,7 +65,7 @@ static int getifaces(const int sockfd, char ***list, int *length) new = (char **) malloc((sizeof(ifs)/sizeof(struct if_nameindex) + 1) * sizeof(char *)); while (ifs && ifs->if_name) { /* just bail if there's a problem */ - if (addname(new, &i, length, ifs->if_name) < 0) + if (addname(new, &i, ifs->if_name) < 0) break; ifs++; } @@ -104,7 +104,7 @@ static int getifaces(const int sockfd, char ***list, int *length) nextifr = (struct ifreq *)((caddr_t)ifr + ifrsize ); /* just bail if there's a problem */ - if (addname(new, &i, length, ifr->ifr_name) < 0) + if (addname(new, &i, ifr->ifr_name) < 0) break; } *list = new; @@ -120,12 +120,12 @@ static int getifaces(const int sockfd, char ***list, int *length) char **getifacelist() { char **list; - int length, i, fd; + int i, fd; if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) return NULL; - if ((i = getifaces(fd, &list, &length)) == 0) { + if ((i = getifaces(fd, &list)) == 0) { free(list); close(fd); return NULL; -- 2.39.2