X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=clients%2Frcpt500%2Fmain.c;h=f970476a5e8012fce75bfe84b2e1eb6320bcc28d;hb=ebfe58344c63a5fd99caf37f72a6acf02e6afc0e;hp=b29920ff4003a7724d8a427d30d6e814158ef938;hpb=727f6aa131b05c94108442856f04d11ecf508d03;p=openldap diff --git a/clients/rcpt500/main.c b/clients/rcpt500/main.c index b29920ff40..f970476a5e 100644 --- a/clients/rcpt500/main.c +++ b/clients/rcpt500/main.c @@ -1,3 +1,4 @@ +/* $OpenLDAP$ */ /* * main.c: for rcpt500 (X.500 email query responder) * @@ -9,14 +10,16 @@ #include "portable.h" #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -#include "ldapconfig.h" +#include "ldap_defaults.h" #include "rcpt500.h" int dosyslog = 0; @@ -28,37 +31,32 @@ int derefaliases = 1; int sizelimit = RCPT500_SIZELIMIT; int rdncount = RCPT500_RDNCOUNT; int ldapport = 0; -char *ldaphost = LDAPHOST; -char *searchbase = RCPT500_BASE; -char *dapuser = RCPT500_BINDDN; +char *ldaphost = NULL; +char *searchbase = NULL; +char *dapuser = NULL; char *filterfile = FILTERFILE; char *templatefile = TEMPLATEFILE; -char reply[ MAXSIZE * RCPT500_LISTLIMIT ]; - +static char reply[ MAXSIZE * RCPT500_LISTLIMIT ]; /* * functions */ -int read_msg(); -char *read_hdr(); -int send_reply(); +static int read_msg(FILE *fp, struct msginfo *msgp); +static char *read_hdr(FILE *fp, int off, char *buf, int MAXSIZEe, char **ln_p); +static int send_reply(struct msginfo *msgp, char *body); +static int find_command(char *text, char **argp); /* * main is invoked by sendmail via the alias file * the entire incoming message gets piped to our standard input */ -main( argc, argv ) - int argc; - char **argv; +int +main( int argc, char **argv ) { char *prog, *usage = "%s [-l] [-U] [-h ldaphost] [-p ldapport] [-b searchbase] [-a] [-z sizelimit] [-u dapuser] [-f filterfile] [-t templatefile] [-c rdncount]\n"; struct msginfo msg; int c, errflg; - char *replytext; - - extern int optind; - extern char *optarg; *reply = '\0'; @@ -115,16 +113,20 @@ main( argc, argv ) } if ( errflg || optind < argc ) { fprintf( stderr, usage, prog ); - exit( 1 ); + exit( EXIT_FAILURE ); } +#ifdef SIGPIPE + (void) SIGNAL( SIGPIPE, SIG_IGN ); +#endif + if ( dosyslog ) { /* * if syslogging requested, initialize */ #ifdef LOG_DAEMON openlog( prog, OPENLOG_OPTIONS, LOG_DAEMON ); -#else +#elif LOG_DEBUG openlog( prog, OPENLOG_OPTIONS ); #endif } @@ -139,7 +141,7 @@ main( argc, argv ) if ( dosyslog ) { syslog( LOG_INFO, "processing command \"%s %s\" from %s", ( msg.msg_command < 0 ) ? "Unknown" : - cmds[ msg.msg_command ].cmd_text, + rcpt_cmds[ msg.msg_command ].cmd_text, ( msg.msg_arg == NULL ) ? "" : msg.msg_arg, msg.msg_replyto ); } @@ -149,10 +151,10 @@ main( argc, argv ) /* sprintf( reply, "Your request was interpreted as: %s %s\n\n", - cmds[ msg.msg_command ].cmd_text, msg.msg_arg ); + rcpt_cmds[ msg.msg_command ].cmd_text, msg.msg_arg ); */ - (*cmds[ msg.msg_command ].cmd_handler)( &msg, reply ); + (*rcpt_cmds[ msg.msg_command ].cmd_handler)( &msg, reply ); if ( send_reply( &msg, reply ) < 0 ) { if ( dosyslog ) { @@ -169,10 +171,8 @@ main( argc, argv ) } -int -read_msg( fp, msgp ) - FILE *fp; - struct msginfo *msgp; +static int +read_msg( FILE *fp, struct msginfo *msgp ) { char buf[ MAXSIZE ], *line; int command = -1; @@ -232,30 +232,25 @@ read_msg( fp, msgp ) } -char * -read_hdr( fp, offset, buf, MAXSIZEe, linep ) - FILE *fp; - int offset; - char *buf; - int MAXSIZEe; - char **linep; +static char * +read_hdr( FILE *fp, int offset, char *buf, int MAXSIZEe, char **linep ) { char *hdr; - for ( hdr = buf + offset; isspace( *hdr ); ++hdr ) { + for ( hdr = buf + offset; isspace( (unsigned char) *hdr ); ++hdr ) { ; } if (( hdr = strdup( hdr )) == NULL ) { if ( dosyslog ) { syslog( LOG_ERR, "strdup: %m" ); } - exit( 1 ); + exit( EXIT_FAILURE ); } while ( 1 ) { *linep = fgets( buf, MAXSIZE, fp ); buf[ strlen( buf ) - 1 ] = '\0'; /* remove trailing newline */ - if ( *linep == NULL || !isspace( **linep )) { + if ( *linep == NULL || !isspace( (unsigned char) **linep )) { break; } if (( hdr = realloc( hdr, strlen( hdr ) + @@ -263,7 +258,7 @@ read_hdr( fp, offset, buf, MAXSIZEe, linep ) if ( dosyslog ) { syslog( LOG_ERR, "realloc: %m" ); } - exit( 1 ); + exit( EXIT_FAILURE ); } strcat( hdr, "\n" ); strcat( hdr, *linep ); @@ -273,10 +268,8 @@ read_hdr( fp, offset, buf, MAXSIZEe, linep ) } -int -send_reply( msgp, body ) - struct msginfo *msgp; - char *body; +static int +send_reply( struct msginfo *msgp, char *body ) { char buf[ MAXSIZE ]; FILE *cmdpipe; @@ -354,10 +347,8 @@ send_reply( msgp, body ) } -int -find_command( text, argp ) - char *text; - char **argp; +static int +find_command( char *text, char **argp ) { int i; char *s, *p; @@ -365,16 +356,16 @@ find_command( text, argp ) p = text; for ( s = argbuf; *p != '\0'; ++p ) { - *s++ = tolower( *p ); + *s++ = TOLOWER( (unsigned char) *p ); } *s = '\0'; - for ( i = 0; cmds[ i ].cmd_text != NULL; ++i ) { - if (( s = strstr( argbuf, cmds[ i ].cmd_text )) != NULL - && isspace( *(s + strlen( cmds[ i ].cmd_text )))) { - strcpy( argbuf, text + (s - argbuf) + strlen( cmds[ i ].cmd_text )); + for ( i = 0; rcpt_cmds[ i ].cmd_text != NULL; ++i ) { + if (( s = strstr( argbuf, rcpt_cmds[ i ].cmd_text )) != NULL + && isspace( (unsigned char) s[ strlen( rcpt_cmds[ i ].cmd_text ) ] )) { + strcpy( argbuf, text + (s - argbuf) + strlen( rcpt_cmds[ i ].cmd_text )); *argp = argbuf; - while ( isspace( **argp )) { + while ( isspace( (unsigned char) **argp )) { ++(*argp); } return( i );