+/* $OpenLDAP$ */
/*
* Copyright (c) 1990 Regents of the University of Michigan.
* All rights reserved.
* is provided ``as is'' without express or implied warranty.
*/
+#include "portable.h"
#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <memory.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <syslog.h>
-#include <sys/param.h>
+
+#include <ac/stdlib.h>
+
+#include <ac/ctype.h>
+#include <ac/errno.h>
+#include <ac/param.h>
+#include <ac/signal.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/sysexits.h>
+#include <ac/syslog.h>
+#include <ac/time.h>
+#include <ac/unistd.h>
+#include <ac/wait.h>
+
+#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sysexits.h>
-#include <ldapconfig.h>
-#include "portable.h"
+#endif
-#include "lber.h"
-#include "ldap.h"
+#include <ldap.h>
+
+#include "fax500.h"
+#include "ldap_defaults.h"
#define USER 0
#define GROUP_ERRORS 1
char *mailfrom = NULL;
char *host = NULL;
int hostlen = 0;
-char *faxtotpc();
int identity;
#define MAIL500 1
"rfc822RequestsTo", "joinable", "cn", "member",
"facsimileTelephoneNumber", NULL };
-static do_address();
-static do_group();
-static do_group_members();
-static send_message();
-static send_errors();
-static do_noemailorfax();
-static do_ambiguous();
-static add_to();
-static isgroup();
-static add_error();
-static add_group();
-static unbind_and_exit();
-static group_loop();
-static send_group();
-static has_attributes();
-static char **get_attributes_mail_dn();
-static char *canonical();
-
-main (argc, argv)
-int argc;
-char **argv;
+
+static void do_address(char *name, char ***to, int *nto, Group **togroups, int *ngroups, Error **err, int *nerr, int type);
+static int do_group(LDAPMessage *e, char *dn, char ***to, int *nto, Group **togroups, int *ngroups, Error **err, int *nerr);
+static void do_group_members(LDAPMessage *e, char *dn, char ***to, int *nto, Group **togroups, int *ngroups, Error **err, int *nerr);
+static void send_message(char **to);
+static void send_errors(Error *err, int nerr);
+static void do_noemailorfax(FILE *fp, Error *err, int namelen, int errtype);
+static void do_ambiguous(FILE *fp, Error *err, int namelen);
+static int count_values(char **list);
+static void add_to(char ***list, int *nlist, char **new);
+static int isgroup(LDAPMessage *e);
+static void add_error(Error **err, int *nerr, int code, char *addr, LDAPMessage *msg);
+static void add_group(char *dn, Group **list, int *nlist);
+static void unbind_and_exit(int rc) LDAP_GCCATTR((noreturn));
+static int group_loop(char *dn);
+static void send_group(Group *group, int ngroup);
+static int has_attributes(LDAPMessage *e, char *attr1, char *attr2);
+static char **get_attributes_mail_dn(LDAPMessage *e, char *attr1, char *attr2);
+static char *canonical(char *s);
+static int connect_to_x500 (void);
+static void do_group_errors (LDAPMessage *e, char *dn, char ***to, int *nto, Error **err, int *nerr);
+static void do_group_request (LDAPMessage *e, char *dn, char ***to, int *nto, Error **err, int *nerr);
+static void add_member (char *gdn, char *dn, char ***to, int *nto, Group **togroups, int *ngroups, Error **err, int *nerr);
+
+
+int
+main ( int argc, char **argv )
{
char *myname;
char **tolist;
Group *togroups;
int numto, ngroups, numerr, nargs;
int i, j;
- FILE *fp;
- extern int optind, errno;
- extern char *optarg;
while ( (i = getopt( argc, argv, "f:h:m:" )) != EOF ) {
switch( i ) {
identity = MAIL500;
}
+#ifdef SIGPIPE
+ (void) SIGNAL( SIGPIPE, SIG_IGN );
+#endif
+
#ifdef LOG_MAIL
openlog( myname, OPENLOG_OPTIONS, LOG_MAIL );
-#else
+#elif LOG_DEBUG
openlog( myname, OPENLOG_OPTIONS );
#endif
*/
if ( numerr > 0 && numto > nargs || ngroups > 0 ) {
- int fd;
+ FILE *fp;
char buf[BUFSIZ];
umask( 077 );
return( EX_OK );
}
-connect_to_x500()
+static int
+connect_to_x500( void )
{
- if ( (ld = ldap_open( LDAPHOST, LDAP_PORT )) == NULL ) {
- syslog( LOG_ALERT, "ldap_open failed" );
+ int sizelimit = FAX_MAXAMBIGUOUS;
+ int deref = LDAP_DEREF_ALWAYS;
+
+ if ( (ld = ldap_init( NULL, 0 )) == NULL ) {
+ syslog( LOG_ALERT, "ldap_init failed" );
return( -1 );
}
- ld->ld_sizelimit = FAX_MAXAMBIGUOUS;
- ld->ld_deref = LDAP_DEREF_ALWAYS;
- if ( ldap_simple_bind_s( ld, FAX_BINDDN, NULL ) != LDAP_SUCCESS ) {
+ ldap_set_option(ld, LDAP_OPT_SIZELIMIT, &sizelimit);
+ ldap_set_option(ld, LDAP_OPT_DEREF, &deref);
+
+ if ( ldap_simple_bind_s( ld, NULL, NULL ) != LDAP_SUCCESS ) {
syslog( LOG_ALERT, "ldap_simple_bind_s failed" );
return( -1 );
}
}
-static
-do_address( name, to, nto, togroups, ngroups, err, nerr, type )
- char *name;
- char ***to;
- int *nto;
- Group **togroups;
- int *ngroups;
- Error **err;
- int *nerr;
- int type;
+static void
+do_address(
+ char *name,
+ char ***to,
+ int *nto,
+ Group **togroups,
+ int *ngroups,
+ Error **err,
+ int *nerr,
+ int type
+)
{
int rc, b, f, match;
LDAPMessage *e, *res;
/* no matches - bounce with user unknown */
if ( match == 0 ) {
- add_error( err, nerr, E_USERUNKNOWN, name, NULLMSG );
+ add_error( err, nerr, E_USERUNKNOWN, name, NULL );
return;
}
return;
}
-static
-do_group( e, dn, to, nto, togroups, ngroups, err, nerr )
- LDAPMessage *e;
- char *dn;
- char ***to;
- int *nto;
- Group **togroups;
- int *ngroups;
- Error **err;
- int *nerr;
+static int
+do_group(
+ LDAPMessage *e,
+ char *dn,
+ char ***to,
+ int *nto,
+ Group **togroups,
+ int *ngroups,
+ Error **err,
+ int *nerr
+)
{
/*
* If this group has an rfc822ErrorsTo attribute, we need to
}
/* ARGSUSED */
-static
-do_group_members( e, dn, to, nto, togroups, ngroups, err, nerr )
- LDAPMessage *e;
- char *dn;
- char ***to;
- int *nto;
- Group **togroups;
- int *ngroups;
- Error **err;
- int *nerr;
+static void
+do_group_members(
+ LDAPMessage *e,
+ char *dn,
+ char ***to,
+ int *nto,
+ Group **togroups,
+ int *ngroups,
+ Error **err,
+ int *nerr
+)
{
int i, rc;
char *ndn;
timeout.tv_usec = 0;
/* for each subtree to look in... */
- ld->ld_sizelimit = FAX_MAXMEMBERS;
+ {
+ int sizelimit = FAX_MAXMEMBERS;
+ ldap_set_option(ld, LDAP_OPT_SIZELIMIT, &sizelimit);
+ }
for ( i = 0; base[i].b_dn != NULL; i++ ) {
/* find entries that have joined this group... */
rc = ldap_search_st( ld, base[i].b_dn,
add_error( err, nerr,
E_JOINMEMBERNOFAXNUM, ndn,
- NULLMSG );
+ NULL );
free( ndn );
}
add_error( err, nerr,
E_JOINMEMBERNOEMAIL, ndn,
- NULLMSG );
+ NULL );
free( ndn );
}
ldap_msgfree( res );
}
- ld->ld_sizelimit = FAX_MAXAMBIGUOUS;
+ {
+ int sizelimit = FAX_MAXAMBIGUOUS;
+ ldap_set_option(ld, LDAP_OPT_SIZELIMIT, &sizelimit);
+ }
}
return;
}
-add_member( gdn, dn, to, nto, togroups, ngroups, err, nerr )
- char *gdn;
- char *dn;
- char ***to;
- int *nto;
- Group **togroups;
- int *ngroups;
- Error **err;
- int *nerr;
+static void
+add_member(
+ char *gdn,
+ char *dn,
+ char ***to,
+ int *nto,
+ Group **togroups,
+ int *ngroups,
+ Error **err,
+ int *nerr
+)
{
char *ndn;
char **mail;
timeout.tv_sec = FAX_TIMEOUT;
timeout.tv_usec = 0;
- if ( (rc = ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "(objectclass=*)",
+ if ( (rc = ldap_search_st( ld, dn, LDAP_SCOPE_BASE, NULL,
attrs, 0, &timeout, &res )) != LDAP_SUCCESS ) {
if ( rc == LDAP_NO_SUCH_OBJECT ) {
- add_error( err, nerr, E_BADMEMBER, dn, NULLMSG );
+ add_error( err, nerr, E_BADMEMBER, dn, NULL );
return;
} else {
ldap_value_free( mail );
ldap_msgfree( res );
} else {
- add_error( err, nerr, E_MEMBERNOFAXNUM, ndn, NULLMSG );
+ add_error( err, nerr, E_MEMBERNOFAXNUM, ndn, NULL );
}
break;
case MAIL500 :
/* else generate a bounce */
} else {
- add_error( err, nerr, E_MEMBERNOEMAIL, ndn, NULLMSG );
+ add_error( err, nerr, E_MEMBERNOEMAIL, ndn, NULL );
}
free( ndn );
return;
}
-do_group_request( e, dn, to, nto, err, nerr )
- LDAPMessage *e;
- char *dn;
- char ***to;
- int *nto;
- Error **err;
- int *nerr;
+static void
+do_group_request(
+ LDAPMessage *e,
+ char *dn,
+ char ***to,
+ int *nto,
+ Error **err,
+ int *nerr
+)
{
char **requeststo;
ldap_value_free( requeststo );
} else {
- add_error( err, nerr, E_NOREQUEST, dn, NULLMSG );
+ add_error( err, nerr, E_NOREQUEST, dn, NULL );
}
-
- return;
}
-do_group_errors( e, dn, to, nto, err, nerr )
- LDAPMessage *e;
- char *dn;
- char ***to;
- int *nto;
- Error **err;
- int *nerr;
+static void
+do_group_errors(
+ LDAPMessage *e,
+ char *dn,
+ char ***to,
+ int *nto,
+ Error **err,
+ int *nerr
+)
{
char **errorsto;
ldap_value_free( errorsto );
} else {
- add_error( err, nerr, E_NOERRORS, dn, NULLMSG );
+ add_error( err, nerr, E_NOERRORS, dn, NULL );
}
-
- return;
}
-static
-send_message( to )
- char **to;
+static void
+send_message( char **to )
{
int pid;
-#ifndef USE_WAITPID
+#ifndef HAVE_WAITPID
WAITSTATUSTYPE status;
#endif
/* parent */
- if ( pid = fork() ) {
-#ifdef USE_WAITPID
+ if ( (pid = fork()) != 0 ) {
+#ifdef HAVE_WAITPID
waitpid( pid, (int *) NULL, 0 );
#else
wait4( pid, &status, WAIT_FLAGS, 0 );
}
}
-static
-send_group( group, ngroup )
- Group *group;
- int ngroup;
+static void
+send_group( Group *group, int ngroup )
{
int i, pid;
char **argv;
int argc;
char *iargv[7];
-#ifndef USE_WAITPID
+#ifndef HAVE_WAITPID
WAITSTATUSTYPE status;
#endif
/* parent */
- if ( pid = fork() ) {
-#ifdef USE_WAITPID
+ if ( (pid = fork()) != 0 ) {
+#ifdef HAVE_WAITPID
waitpid( pid, (int *) NULL, 0 );
#else
wait4( pid, &status, WAIT_FLAGS, 0 );
return;
}
-static
-send_errors( err, nerr )
- Error *err;
- int nerr;
+static void
+send_errors( Error *err, int nerr )
{
int i, namelen;
FILE *fp;
}
-static
-do_noemailorfax( fp, err, namelen, errtype )
- FILE *fp;
- Error *err;
- int namelen;
- int errtype;
+static void
+do_noemailorfax( FILE *fp, Error *err, int namelen, int errtype )
{
int i, last;
char *dn, *rdn;
!= NULL ) {
for ( i = 0; vals[i]; i++ ) {
last = strlen( vals[i] ) - 1;
- if ( isdigit( vals[i][last] ) ) {
+ if ( isdigit((unsigned char) vals[i][last]) ) {
rdn = strdup( vals[i] );
break;
}
for ( i = 0; vals[0][i] != '\0'; i++ ) {
if ( vals[0][i] == '$' ) {
fprintf( fp, "\n%*s ", namelen, " " );
- while ( isspace( vals[0][i+1] ) )
+ while ( isspace((unsigned char) vals[0][i+1]) )
i++;
} else {
fprintf( fp, "%c", vals[0][i] );
}
/* ARGSUSED */
-static
-do_ambiguous( fp, err, namelen )
- FILE *fp;
- Error *err;
- int namelen;
+static void
+do_ambiguous( FILE *fp, Error *err, int namelen )
{
int i, last;
char *dn, *rdn;
if ( (vals = ldap_get_values( ld, e, "cn" )) != NULL ) {
for ( i = 0; vals[i]; i++ ) {
last = strlen( vals[i] ) - 1;
- if ( isdigit( vals[i][last] ) ) {
+ if ( isdigit((unsigned char) vals[i][last]) ) {
rdn = strdup( vals[i] );
break;
}
}
}
-static
-count_values( list )
- char **list;
+static int
+count_values( char **list )
{
int i;
return( i );
}
-static
-add_to( list, nlist, new )
- char ***list;
- int *nlist;
- char **new;
+static void
+add_to( char ***list, int *nlist, char **new )
{
int i, nnew, oldnlist;
return;
}
-static
-isgroup( e )
- LDAPMessage *e;
+static int
+isgroup( LDAPMessage *e )
{
int i;
char **oclist;
return( 0 );
}
-static
-add_error( err, nerr, code, addr, msg )
- Error **err;
- int *nerr;
- int code;
- char *addr;
- LDAPMessage *msg;
+static void
+add_error( Error **err, int *nerr, int code, char *addr, LDAPMessage *msg )
{
if ( *nerr == 0 ) {
*err = (Error *) malloc( sizeof(Error) );
return;
}
-static
-add_group( dn, list, nlist )
- char *dn;
- Group **list;
- int *nlist;
+static void
+add_group( char *dn, Group **list, int *nlist )
{
int i, namelen;
char **ufn;
return;
}
-static
-unbind_and_exit( rc )
- int rc;
+static void
+unbind_and_exit( int rc )
{
int i;
}
static char *
-canonical( s )
- char *s;
+canonical( char *s )
{
char *saves = s;
return( saves );
}
-static
-group_loop( dn )
- char *dn;
+static int
+group_loop( char *dn )
{
int i;
static char **groups;
return( 0 );
}
-static
-has_attributes( e, attr1, attr2 )
- LDAPMessage *e;
- char *attr1;
- char *attr2;
+static int
+has_attributes( LDAPMessage *e, char *attr1, char *attr2 )
{
char **attr;
}
static char **
-get_attributes_mail_dn( e, attr1, attr2 )
- LDAPMessage *e;
- char *attr1;
- char *attr2; /* this one is dn-valued */
+get_attributes_mail_dn( LDAPMessage *e, char *attr1, char *attr2 )
{
LDAPMessage *ee, *res;
char **vals, **dnlist, **mail;
for ( i = 0; dnlist[i] != NULL; i++ ) {
if ( (rc = ldap_search_st( ld, dnlist[i],
- LDAP_SCOPE_BASE, "(objectclass=*)", attrs, 0,
+ LDAP_SCOPE_BASE, NULL, attrs, 0,
&timeout, &res )) != LDAP_SUCCESS ) {
if ( rc != LDAP_NO_SUCH_OBJECT ) {
unbind_and_exit( EX_TEMPFAIL );