]> git.sur5r.net Git - openldap/blobdiff - clients/mail500/main.c
Update copyright notices
[openldap] / clients / mail500 / main.c
index b147908db6216c922d8374d1e1039c860d6fc57f..cbe5bb80372f1ce7343e6af71f9ef0deae4b17b7 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright (c) 1990 Regents of the University of Michigan.
  * All rights reserved.
@@ -8,36 +9,37 @@
  * may not be used to endorse or promote products derived from this
  * software without specific prior written permission. This software
  * is provided ``as is'' without express or implied warranty.
+ *
+ * Copyright 1998-2000 The OpenLDAP Foundation
+ * COPYING RESTRICTIONS APPLY.  See COPYRIGHT File in top level directory
+ * of this package for details.
  */
 
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/ctype.h>
+#include <ac/param.h>
+#include <ac/signal.h>
 #include <ac/string.h>
+#include <ac/sysexits.h>
 #include <ac/syslog.h>
 #include <ac/time.h>
-#include <ac/wait.h>
 #include <ac/unistd.h>
+#include <ac/wait.h>
 
 #include <sys/stat.h>
 
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
 
-#include <sysexits.h>
-
-#include "lber.h"
-#include "ldap.h"
+#include <ldap.h>
 
-#include "ldapconfig.h"
+#include "ldap_defaults.h"
 
 #ifndef MAIL500_BOUNCEFROM
 #define MAIL500_BOUNCEFROM "<>"
@@ -81,7 +83,7 @@ typedef struct errs {
 #define        E_NOOWNER               11
 #define E_GROUPUNKNOWN         12
        char            *e_addr;
-       union {
+       union e_union_u {
                char            *e_u_loop;
                LDAPMessage     *e_u_msg;
        } e_union;
@@ -105,20 +107,20 @@ typedef struct baseinfo {
                                /* (up to three of them) */
 } Base;
 
-Base   base[] = 
-       { "ou=People, o=University of Michigan, c=US",
+Base   base[] = {
+       {"ou=People, dc=example, dc=com",
                0, USER,
-               "uid=%s", "cn=%s", NULL,
-         "ou=System Groups, ou=Groups, o=University of Michigan, c=US",
+               {"uid=%s", "cn=%s", NULL}},
+       {"ou=System Groups, ou=Groups, dc=example, dc=com",
                1, 0xff,
-               "(&(cn=%s)(associatedDomain=%h))", NULL, NULL,
-         "ou=User Groups, ou=Groups, o=University of Michigan, c=US",
+               {"(&(cn=%s)(associatedDomain=%h))", NULL, NULL}},
+       {"ou=User Groups, ou=Groups, dc=example, dc=com",
                1, 0xff,
-               "(&(cn=%s)(associatedDomain=%h))", NULL, NULL,
-         NULL
-       };
+               {"(&(cn=%s)(associatedDomain=%h))", NULL, NULL}},
+       {NULL}
+};
 
-char   *sendmailargs[] = { MAIL500_SENDMAIL, "-oMrX.500", "-odi", "-oi", "-f", NULL, NULL };
+char   *sendmailargs[] = { MAIL500_SENDMAIL, "-oMrLDAP", "-odi", "-oi", "-f", NULL, NULL };
 
 static char    *attrs[] = { "objectClass", "title", "postaladdress",
                        "telephoneNumber", "mail", "description", "owner",
@@ -161,14 +163,18 @@ main ( int argc, char **argv )
        int             numto, ngroups, numerr, nargs;
        int             i, j;
 
-       if ( (myname = strrchr( argv[0], '/' )) == NULL )
+       if ( (myname = strrchr( argv[0], *LDAP_DIRSEP )) == NULL )
                myname = strdup( argv[0] );
        else
                myname = strdup( myname + 1 );
 
+#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
 
@@ -355,8 +361,8 @@ connect_to_x500( void )
 {
        int opt;
 
-       if ( (ld = ldap_open( ldaphost, 0 )) == NULL ) {
-               syslog( LOG_ALERT, "ldap_open failed" );
+       if ( (ld = ldap_init( ldaphost, 0 )) == NULL ) {
+               syslog( LOG_ALERT, "ldap_init failed" );
                return( -1 );
        }
 
@@ -510,9 +516,9 @@ do_address(
        /* no matches - bounce with user unknown */
        if ( match == 0 ) {
                if ( type == USER ) {
-                       add_error( err, nerr, E_USERUNKNOWN, name, NULLMSG );
+                       add_error( err, nerr, E_USERUNKNOWN, name, NULL );
                } else {
-                       add_error( err, nerr, E_GROUPUNKNOWN, name, NULLMSG );
+                       add_error( err, nerr, E_GROUPUNKNOWN, name, NULL );
                }
                return;
        }
@@ -832,7 +838,7 @@ do_group_members(
                if ( strcasecmp( joinable[0], "FALSE" ) == 0 ) {
                        if ( ! anymembers ) {
                                add_error( err, nerr, E_NOMEMBERS, dn,
-                                   NULLMSG );
+                                   NULL );
                        }
 
                        ldap_value_free( joinable );
@@ -899,7 +905,7 @@ do_group_members(
                                        ndn = ldap_get_dn( ld, ee );
 
                                        add_error( err, nerr,
-                                           E_JOINMEMBERNOEMAIL, ndn, NULLMSG );
+                                           E_JOINMEMBERNOEMAIL, ndn, NULL );
 
                                        free( ndn );
                                }
@@ -912,7 +918,7 @@ do_group_members(
        }
 
        if ( ! anymembers ) {
-               add_error( err, nerr, E_NOMEMBERS, dn, NULLMSG );
+               add_error( err, nerr, E_NOMEMBERS, dn, NULL );
        }
 }
 
@@ -931,7 +937,7 @@ add_member(
 {
        char            *ndn;
        char            **mail;
-       int             i, rc;
+       int             rc;
        LDAPMessage     *res, *e;
        struct timeval  timeout;
 
@@ -940,7 +946,7 @@ add_member(
        if ( (rc = ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "(objectclass=*)",
            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 {
@@ -979,7 +985,7 @@ add_member(
        } else {
                if ( suppress == NULL || strcasecmp( suppress[0], "FALSE" )
                    == 0 ) {
-                       add_error( err, nerr, E_MEMBERNOEMAIL, ndn, NULLMSG );
+                       add_error( err, nerr, E_MEMBERNOEMAIL, ndn, NULL );
                }
        }
 
@@ -1004,7 +1010,7 @@ do_group_request(
 
                ldap_value_free( requeststo );
        } else {
-               add_error( err, nerr, E_NOREQUEST, dn, NULLMSG );
+               add_error( err, nerr, E_NOREQUEST, dn, NULL );
        }
 }
 
@@ -1026,7 +1032,7 @@ do_group_errors(
 
                ldap_value_free( errorsto );
        } else {
-               add_error( err, nerr, E_NOERRORS, dn, NULLMSG );
+               add_error( err, nerr, E_NOERRORS, dn, NULL );
        }
 }
 
@@ -1046,7 +1052,7 @@ do_group_owner(
                add_to( to, nto, owner );
                ldap_value_free( owner );
        } else {
-               add_error( err, nerr, E_NOOWNER, dn, NULLMSG );
+               add_error( err, nerr, E_NOOWNER, dn, NULL );
        }
 }
 
@@ -1315,7 +1321,7 @@ do_noemail( FILE *fp, Error *err, int namelen )
                    != 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;
                                }
@@ -1353,7 +1359,7 @@ do_noemail( FILE *fp, Error *err, int namelen )
                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] );
@@ -1402,7 +1408,7 @@ do_ambiguous( FILE *fp, Error *err, int namelen )
                        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;
                                        }
@@ -1617,7 +1623,7 @@ get_attributes_mail_dn(
 )
 {
        LDAPMessage     *ee, *res;
-       char            **vals, **dnlist, **mail, **grname, **graddr;
+       char            **vals, **dnlist, **mail, **grname;
         char            *dn;
        int             nto = 0, i, rc;
        struct timeval  timeout;