Mercurial > noffle
changeset 287:01755687c565 noffle
[svn] * src/configfile.c: Change snprintf() to Utl_cpyStr();
* src/configfile.c,src/fetch.c,src/fetchlist.c,src/protocol.c,
src/server.c: Replace strcpy() with Utl_cpyStr() where appropriate.
See Debian bug 168128.
* src/client.c. Replace strcpy() here too.
* src/configfile.h,src/configfile.c,docs/noffle.conf.5: Add noffle-user
and noffle-group configs.
* src/control.c,src/configfile.c,src/noffle.c: Replace [s]scanf("%s")
with [s]scanf(MAXCHAR_FMT).
author | bears |
---|---|
date | Fri, 10 Jan 2003 23:11:43 +0000 |
parents | 6443163104a8 |
children | c02c4eb95f95 |
files | src/client.c src/configfile.c src/configfile.h src/control.c src/fetchlist.c src/protocol.c |
diffstat | 6 files changed, 72 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/src/client.c Fri Jan 10 23:08:17 2003 +0000 +++ b/src/client.c Fri Jan 10 23:11:43 2003 +0000 @@ -1,7 +1,7 @@ /* client.c - $Id: client.c 412 2002-12-24 09:08:59Z bears $ + $Id: client.c 419 2003-01-10 23:11:43Z bears $ */ #if HAVE_CONFIG_H @@ -108,8 +108,8 @@ Bool err; unsigned int n; - strcpy( client.lastCmd, line ); - strcpy( client.lastStat, "[no status available]" ); + Utl_cpyStr( client.lastCmd, line ); + Utl_cpyStr( client.lastStat, "[no status available]" ); Log_dbg( LOG_DBG_PROTOCOL, "[S] %s", line ); n = fprintf( client.out, "%s\r\n", line ); err = ( n != strlen( line ) + 2 ); @@ -202,7 +202,7 @@ && ! client.auth ) { client.auth = TRUE; - strcpy( lastCmd, client.lastCmd ); + Utl_cpyStr( lastCmd, client.lastCmd ); result = performAuth(); if ( result == STAT_AUTH_ACCEPTED || result == STAT_AUTH_ACCEPTED_DEPREC ) @@ -286,13 +286,13 @@ pColon = strstr( pStart, ":" ); if ( pColon == NULL ) { - strcpy( host, pStart ); + Utl_cpyStr( host, pStart ); port = 119; } else { *pColon = '\0'; - strcpy( host, pStart ); + Utl_cpyStr( host, pStart ); if ( sscanf( pColon + 1, "%hu", &port ) != 1 ) { Log_err( "Syntax error in server name: '%s'", serv ); @@ -629,7 +629,7 @@ } if ( *noServerPattern && ! isGetGroup( name ) ) continue; - strcpy( dsc, Utl_restOfLn( line, 1 ) ); + Utl_cpyStr( dsc, Utl_restOfLn( line, 1 ) ); if ( Grp_exists( name ) ) { Log_dbg( LOG_DBG_FETCH, "Description of %s: %s", name, dsc ); @@ -1237,7 +1237,7 @@ else if ( stat != STAT_SEND_ART ) { Log_err( "Posting of %s not allowed: %s", msgId, client.lastStat ); - strcpy( errStr, client.lastStat ); + Utl_cpyStr( errStr, client.lastStat ); return stat; } putTxtBuf( artTxt ); @@ -1248,7 +1248,7 @@ else if ( stat != STAT_POST_OK ) { Log_err( "Posting of %s failed: %s", msgId, client.lastStat ); - strcpy( errStr, client.lastStat ); + Utl_cpyStr( errStr, client.lastStat ); return stat; } Log_inf( "Posted %s (Status: %s)", msgId, client.lastStat );
--- a/src/configfile.c Fri Jan 10 23:08:17 2003 +0000 +++ b/src/configfile.c Fri Jan 10 23:11:43 2003 +0000 @@ -6,7 +6,7 @@ SPOOLDIR VERSION - $Id: configfile.c 405 2002-11-10 15:06:33Z bears $ + $Id: configfile.c 419 2003-01-10 23:11:43Z bears $ */ #if HAVE_CONFIG_H @@ -79,6 +79,7 @@ Bool replaceMsgId; Str hostnameMsgId; Bool postLocal; + Bool clientAuth; Str defaultAutoSubscribeMode; Str mailTo; int defaultExpire; @@ -95,6 +96,8 @@ Str pathHeader; Str fromDomain; Str organization; + Str noffleUser; + Str noffleGroup; } config = { SPOOLDIR, /* spoolDir */ @@ -109,6 +112,7 @@ FALSE, /* replaceMsgId */ "", /* hostnameMsgId */ FALSE, /* postLocal */ + FALSE, /* clientAuth */ "over", /* defaultAutoSubscribeMode */ "", /* mailTo */ 14, /* defaultExpire */ @@ -124,7 +128,9 @@ NULL, /* autoSubscribeMode */ "", /* pathHeader */ "", /* fromDomain */ - "" /* organization */ + "", /* organization */ + "news", /* user Noffle runs as */ + "news" /* group Noffle runs as */ }; const char * Cfg_spoolDir( void ) { return config.spoolDir; } @@ -140,6 +146,7 @@ Bool Cfg_replaceMsgId( void ) { return config.replaceMsgId; } const char * Cfg_hostnameMsgId( void ) { return config.hostnameMsgId; } Bool Cfg_postLocal( void ) { return config.postLocal; } +Bool Cfg_needClientAuth( void ) { return config.clientAuth; } const char * Cfg_defaultAutoSubscribeMode( void ) { return config.defaultAutoSubscribeMode; } const char * Cfg_mailTo( void ) { return config.mailTo; } @@ -147,6 +154,8 @@ const char * Cfg_pathHeader( void ) { return config.pathHeader; } const char * Cfg_fromDomain( void ) { return config.fromDomain; } const char * Cfg_organization( void ) { return config.organization; } +const char * Cfg_noffleUser( void ) { return config.noffleUser; } +const char * Cfg_noffleGroup( void ) { return config.noffleGroup; } void Cfg_beginServEnum( void ) @@ -159,7 +168,7 @@ { if ( config.servIdx >= config.numServ ) return FALSE; - strcpy( name, config.serv[ config.servIdx ].name ); + Utl_cpyStr( name, config.serv[ config.servIdx ].name ); ++config.servIdx; return TRUE; } @@ -209,8 +218,8 @@ if ( searchServ( name, &idx ) ) { - strcpy( user, config.serv[ idx ].user ); - strcpy( pass, config.serv[ idx ].pass ); + Utl_cpyStr( user, config.serv[ idx ].user ); + Utl_cpyStr( pass, config.serv[ idx ].pass ); } else { @@ -264,10 +273,7 @@ res = (GroupEnum *) malloc( sizeof( GroupEnum ) ); if ( res == NULL ) - { - Log_err( "Malloc of GroupEnum failed." ); - exit( EXIT_FAILURE ); - } + Log_fatal( "Malloc of GroupEnum failed." ); if ( ! searchServ( name, &servIdx ) ) res->groupEntry = NULL; else @@ -284,10 +290,7 @@ res = (GroupEnum *) malloc( sizeof( GroupEnum ) ); if ( res == NULL ) - { - Log_err( "Malloc of GroupEnum failed." ); - exit( EXIT_FAILURE ); - } + Log_fatal( "Malloc of GroupEnum failed." ); if ( ! searchServ( name, &servIdx ) ) res->groupEntry = NULL; else @@ -328,9 +331,9 @@ { Str value, name, lowerLn; - strcpy( lowerLn, line ); + Utl_cpyStr( lowerLn, line ); Utl_toLower( lowerLn ); - if ( sscanf( lowerLn, "%s %s", name, value ) != 2 ) + if ( sscanf( lowerLn, MAXCHAR_FMT " " MAXCHAR_FMT, name, value ) != 2 ) { logSyntaxErr( line ); return; @@ -350,7 +353,7 @@ int value; Str name; - if ( sscanf( line, "%s %d", name, &value ) != 2 ) + if ( sscanf( line, MAXCHAR_FMT " %d", name, &value ) != 2 ) { logSyntaxErr( line ); return; @@ -368,7 +371,7 @@ { Str dummy; - if ( sscanf( line, "%s %s", dummy, variable ) != 2 ) + if ( sscanf( line, MAXCHAR_FMT " " MAXCHAR_FMT, dummy, variable ) != 2 ) { logSyntaxErr( line ); return; @@ -394,7 +397,8 @@ memset( &entry, 0, sizeof( entry ) ); user[ 0 ] = pass[ 0 ] = '\0'; - r = sscanf( line, "%s %s %s %s", + r = sscanf( line, + MAXCHAR_FMT " " MAXCHAR_FMT " " MAXCHAR_FMT " " MAXCHAR_FMT, dummy, name, user, pass ); if ( r < 2 ) { @@ -417,10 +421,7 @@ if ( ! ( config.serv = realloc( config.serv, ( config.maxServ + 5 ) * sizeof( ServEntry ) ) ) ) - { - Log_err( "Could not realloc server list" ); - exit( EXIT_FAILURE ); - } + Log_fatal( "Could not realloc server list" ); config.maxServ += 5; } config.serv[ config.numServ++ ] = entry; @@ -433,7 +434,8 @@ ExpireEntry entry; int days; - if ( sscanf( line, "%s %s %d", dummy, pattern, &days ) != 3 ) + if ( sscanf( line, MAXCHAR_FMT " " MAXCHAR_FMT " %d", + dummy, pattern, &days ) != 3 ) { logSyntaxErr( line ); return; @@ -456,10 +458,7 @@ if ( ! ( config.expire = realloc( config.expire, ( config.maxExpire + 5 ) * sizeof( ExpireEntry ) ) ) ) - { - Log_err( "Could not realloc expire list" ); - exit( EXIT_FAILURE ); - } + Log_fatal( "Could not realloc expire list" ); config.maxExpire += 5; } config.expire[ config.numExpire++ ] = entry; @@ -507,10 +506,7 @@ if ( ! ( g->groups = realloc( g->groups, ( g->maxGroup + 5 ) * sizeof( char * ) ) ) ) - { - Log_err( "Could not realloc group list" ); - exit( EXIT_FAILURE ); - } + Log_fatal( "Could not realloc group list" ); g->maxGroup += 5; } Utl_allocAndCpy( &g->groups[ g->numGroup++ ], pattern ); @@ -570,6 +566,8 @@ mask |= LOG_DBG_REQUESTS; else if ( strcmp( maskName, "server" ) == 0 ) mask |= LOG_DBG_SERVER; + else if ( strcmp( maskName, "auth" ) == 0 ) + mask |= LOG_DBG_AUTH; else logSyntaxErr( line ); } @@ -593,7 +591,8 @@ AutoSubscribeModeEntry entry; int items; - items = sscanf( line, "%s %s %s", dummy, pattern, mode ); + items = sscanf( line, MAXCHAR_FMT " " MAXCHAR_FMT " " MAXCHAR_FMT, + dummy, pattern, mode ); if ( items == 2 ) { /* Backwards compat. default-auto-subscribe-mode */ @@ -604,7 +603,7 @@ logSyntaxErr( line ); return; } - strcpy( config.defaultAutoSubscribeMode, mode ); + Utl_cpyStr( config.defaultAutoSubscribeMode, mode ); return; } else if ( items != 3 ) @@ -630,10 +629,7 @@ realloc( config.autoSubscribeMode, ( config.maxAutoSubscribeMode + 5 ) * sizeof( AutoSubscribeModeEntry ) ) ) ) - { - Log_err( "Could not realloc auto subscribe mode list" ); - exit( EXIT_FAILURE ); - } + Log_fatal( "Could not realloc auto subscribe mode list" ); config.maxAutoSubscribeMode += 5; } config.autoSubscribeMode[ config.numAutoSubscribeMode++ ] = entry; @@ -919,7 +915,7 @@ FILE *f; Str file, line, lowerLine, name, s; - snprintf( file, MAXCHAR, CONFIGFILE ); + Utl_cpyStr( file, CONFIGFILE ); if ( ! ( f = fopen( file, "r" ) ) ) { Log_err( "Cannot read %s", file ); @@ -934,7 +930,7 @@ p = lowerLine; if ( *p == '\0' ) continue; - if ( sscanf( p, "%s", name ) != 1 ) + if ( sscanf( p, MAXCHAR_FMT, name ) != 1 ) Log_err( "Syntax error in %s: %s", file, line ); else if ( strcmp( "max-fetch", name ) == 0 ) getInt( &config.maxFetch, 0, INT_MAX, p ); @@ -959,6 +955,8 @@ getStr( config.hostnameMsgId, line ); else if ( strcmp( "post-locally", name ) == 0 ) getBool( &config.postLocal, p ); + else if ( strcmp( "authenticate-client", name ) == 0 ) + getBool( &config.clientAuth, p ); else if ( strcmp( "default-auto-subscribe-mode", name ) == 0 ) { getStr( s, p ); @@ -968,7 +966,7 @@ return; } else - strcpy( config.defaultAutoSubscribeMode, s ); + Utl_cpyStr( config.defaultAutoSubscribeMode, s ); } else if ( strcmp( "mail-to", name ) == 0 ) getStr( config.mailTo, p ); @@ -989,6 +987,10 @@ /* The following need line because they may have uppercase data */ else if ( strcmp( "organization", name ) == 0 ) getText( config.organization, line ); + else if ( strcmp( "noffle-user", name ) == 0 ) + getText( config.noffleUser, line ); + else if ( strcmp( "noffle-group", name ) == 0 ) + getText( config.noffleUser, line ); else if ( strcmp( "server", name ) == 0 ) getServ( line ); else if ( strcmp( "filter", name ) == 0 ) @@ -998,8 +1000,5 @@ } fclose( f ); if ( ! config.numServ ) - { - Log_err( "Config file contains no server" ); - exit( EXIT_FAILURE ); - } + Log_fatal( "Config file contains no server" ); }
--- a/src/configfile.h Fri Jan 10 23:08:17 2003 +0000 +++ b/src/configfile.h Fri Jan 10 23:11:43 2003 +0000 @@ -3,7 +3,7 @@ Common declarations and handling of the configuration file. - $Id: configfile.h 314 2001-10-30 13:16:40Z bears $ + $Id: configfile.h 419 2003-01-10 23:11:43Z bears $ */ #ifndef CONFIGFILE_H @@ -47,6 +47,8 @@ Bool Cfg_servIsPreferential( const char *name1, const char *name2 ); void Cfg_authInfo( const char *name, Str user, Str pass ); +Bool Cfg_needClientAuth( void ); + /* Return expire period for named group. */ int Cfg_expire( const char *grp ); @@ -68,6 +70,12 @@ /* Return default Organization: contents */ const char * Cfg_organization( void ); +/* Return the user Noffle should run as */ +const char * Cfg_noffleUser( void ); + +/* Return the group Noffle should run as */ +const char * Cfg_noffleGroup( void ); + void Cfg_read( void ); /* Get a new iterator for get group patterns for the given server */
--- a/src/control.c Fri Jan 10 23:08:17 2003 +0000 +++ b/src/control.c Fri Jan 10 23:11:43 2003 +0000 @@ -1,7 +1,7 @@ /* control.c - $Id: control.c 342 2001-12-09 12:31:57Z bears $ + $Id: control.c 419 2003-01-10 23:11:43Z bears $ */ #if HAVE_CONFIG_H @@ -54,7 +54,7 @@ Str grp; int no; - if ( sscanf( ref, "%s:%d", grp, &no ) != 2 ) + if ( sscanf( ref, MAXCHAR_FMT ":%d", grp, &no ) != 2 ) break; if ( Grp_exists( grp ) )
--- a/src/fetchlist.c Fri Jan 10 23:08:17 2003 +0000 +++ b/src/fetchlist.c Fri Jan 10 23:11:43 2003 +0000 @@ -1,7 +1,7 @@ /* fetchlist.c - $Id: fetchlist.c 413 2002-12-27 21:48:25Z bears $ + $Id: fetchlist.c 419 2003-01-10 23:11:43Z bears $ */ #if HAVE_CONFIG_H @@ -71,7 +71,7 @@ Log_fatal( "Could not realloc fetchlist" ); fetchlist.max += 50; } - strcpy( elem.name, name ); + Utl_cpyStr( elem.name, name ); elem.mode = mode; fetchlist.elem[ fetchlist.size++ ] = elem; } @@ -100,7 +100,7 @@ p = Utl_stripWhiteSpace( line ); if ( *p == '#' || *p == '\0' ) continue; - ret = sscanf( p, "%s %s", grp, modeStr ); + ret = sscanf( p, MAXCHAR_FMT " " MAXCHAR_FMT, grp, modeStr ); valid = TRUE; if ( ret < 1 || ret > 2 ) valid = FALSE; @@ -229,7 +229,7 @@ appGrp( name, mode ); return TRUE; } - strcpy( elem->name, name ); + Utl_cpyStr( elem->name, name ); elem->mode = mode; return FALSE; }
--- a/src/protocol.c Fri Jan 10 23:08:17 2003 +0000 +++ b/src/protocol.c Fri Jan 10 23:11:43 2003 +0000 @@ -1,7 +1,7 @@ /* protocol.c - $Id: protocol.c 414 2003-01-06 18:16:18Z bears $ + $Id: protocol.c 419 2003-01-10 23:11:43Z bears $ */ #if HAVE_CONFIG_H @@ -112,10 +112,10 @@ if ( buf[ 1 ] == 0 ) return FALSE; else - strcpy( line, buf + 1 ); + Utl_cpyStr( line, buf + 1 ); } else - strcpy( line, buf ); + Utl_cpyStr( line, buf ); return TRUE; } @@ -204,9 +204,9 @@ if ( *p == ':' ) { ++p; - strcpy( t, line + ( p - lineLower ) ); + Utl_cpyStr( t, line + ( p - lineLower ) ); p = Utl_stripWhiteSpace( t ); - strcpy( resultValue, p ); + Utl_cpyStr( resultValue, p ); return TRUE; } else return FALSE; /* Not a header line */