Back to index

courier  0.68.2
ldapaddressbook.h
Go to the documentation of this file.
00001 #ifndef       ldapaddressbook_h
00002 #define       ldapaddressbook_h
00003 
00004 
00005 #include <stdio.h>
00006 
00007 /*
00008 ** Copyright 2000-2002 Double Precision, Inc.  See COPYING for
00009 ** distribution information.
00010 */
00011 
00012 #ifdef  __cplusplus
00013 extern "C" {
00014 #endif
00015 
00016 /*
00017 ** This module implements an abstraction of an interface to an LDAP address
00018 ** book.  There's no reason to reinvent the wheel, so we simply run ldapsearch
00019 ** as a child process, and read its output.  ldapsearch is run indirectly, via
00020 ** a stub shell script that can be customized on a given system.  The template
00021 ** for the stub shell script is provided.
00022 **
00023 ** There's a small library here that can be used to maintain a configuration
00024 ** file listing available address books that can be contacted.  The format
00025 ** of each line in this library is simply:
00026 **
00027 ** name<tab>host<tab>port<tab>suffix<tab>binddn<tab>bindpw
00028 **
00029 ** Functions are provided to add and remove names from this configuration
00030 ** file easily.  The above is parsed into the following structure:
00031 */
00032 
00033 struct ldapabook {
00034        struct ldapabook *next;
00035 
00036        char   *name;
00037        char   *host;
00038        char   *port;
00039        char   *suffix;
00040        char   *binddn;
00041        char   *bindpw;
00042 
00043        struct ldapabook_opts *opts;
00044 
00045        } ;
00046 
00047 struct ldapabook_opts {
00048        struct ldapabook_opts *next;
00049        char   *options;     /* First char - name, rest - value */
00050 } ;
00051 
00052        /* Potential first chars: */
00053 
00054 #define SASL_SECURITY_PROPERTIES   'O'
00055 #define SASL_AUTHENTICATION_ID            'U'
00056 #define       SASL_AUTHENTICATION_RID            'X'  /* u:username, or dn:dn */
00057 #define       SASL_AUTHENTICATION_MECHANISM      'Y'
00058 #define SASL_STARTTLS                     'Z'
00059 
00060 /* Read a configuration file, and create a link list of ldapabook structs */
00061 
00062 struct ldapabook *ldapabook_read(const char *);         /* filename */
00063 
00064 /* Free memory allocated by ldapabook_init */
00065 
00066 void ldapabook_free(struct ldapabook *);
00067 
00068 /* Find a certain address book */
00069 
00070 const struct ldapabook *ldapabook_find(const struct ldapabook *,
00071                                    const char *);
00072 
00073 /* Add a new entry to the address book */
00074 
00075 int ldapabook_add(const char *,                  /* filename */
00076               const struct ldapabook *);  /* new entry */
00077 
00078 /* Delete an entry from the address book */
00079 
00080 int ldapabook_del(const char *,           /* filename */
00081               const char *,        /* temporary filename on same filesys */
00082               const char *);              /* name to delete */
00083 
00084 /* Run ldapsearch in the background, return a file descriptor containing
00085 ** ldapsearch's output.
00086 */
00087 
00088 int ldapabook_search(const struct ldapabook *b,  /* Search this address book */
00089                    const char *script,
00090                    const char *search,
00091                    int (*callback_func)(const char *utf8_name,
00092                                      const char *address,
00093                                      void *callback_arg),
00094                    void (*callback_err)(const char *errmsg,
00095                                      void *callback_arg),
00096                    void *callback_arg);
00097 
00098 /*
00099 ** Internal function:
00100 */
00101 
00102 void ldapabook_writerec(const struct ldapabook *, FILE *);
00103 
00104 #ifdef  __cplusplus
00105 }
00106 #endif
00107 
00108 #endif