]> git.sur5r.net Git - openldap/commitdiff
Convert back-sock to dynamic config
authorHoward Chu <hyc@openldap.org>
Mon, 24 Dec 2007 05:18:25 +0000 (05:18 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 24 Dec 2007 05:18:25 +0000 (05:18 +0000)
servers/slapd/back-sock/back-sock.h
servers/slapd/back-sock/config.c
servers/slapd/back-sock/init.c
servers/slapd/back-sock/proto-sock.h
servers/slapd/bconfig.c

index 7edfb5fbedbb145ae68778000eba32544f8dd089..e4b23047006a71101279aab8f11623ef15b92e06 100644 (file)
@@ -27,7 +27,7 @@ LDAP_BEGIN_DECL
 
 struct sockinfo {
        const char      *si_sockpath;
-       int             si_extensions;
+       slap_mask_t     si_extensions;
 };
 
 #define        SOCK_EXT_BINDDN 1
index 020c924b1ba4001cb0b641d3381295d1aeb64efa..ec998c9b0d21f5e579b905691d1c7d4e4e1ad6b1 100644 (file)
@@ -15,7 +15,7 @@
  */
 /* ACKNOWLEDGEMENTS:
  * This work was initially developed by Brian Candler for inclusion
- * in OpenLDAP Software.
+ * in OpenLDAP Software. Dynamic config support by Howard Chu.
  */
 
 #include "portable.h"
 #include <ac/socket.h>
 
 #include "slap.h"
+#include "config.h"
 #include "back-sock.h"
 
-int
-sock_back_db_config(
-    BackendDB  *be,
-    const char *fname,
-    int                lineno,
-    int                argc,
-    char       **argv
-)
-{
-       struct sockinfo *si = (struct sockinfo *) be->be_private;
+static ConfigDriver bs_cf_gen;
 
-       if ( si == NULL ) {
-               fprintf( stderr, "%s: line %d: sock backend info is null!\n",
-                   fname, lineno );
-               return( 1 );
-       }
+enum {
+       BS_EXT = 1
+};
 
-       /* socketpath */
-       if ( strcasecmp( argv[0], "socketpath" ) == 0 ) {
-               if ( argc != 2 ) {
-                       fprintf( stderr,
-       "%s: line %d: exactly one parameter needed for \"socketpath\"\n",
-                           fname, lineno );
-                       return( 1 );
-               }
-               si->si_sockpath = ch_strdup( argv[1] );
+static ConfigTable bscfg[] = {
+       { "socketpath", "pathname", 2, 2, 0, ARG_STRING|ARG_OFFSET,
+               (void *)offsetof(struct sockinfo, si_sockpath),
+               "( OLcfgDbAt:7.1 NAME 'olcDbSocketPath' "
+                       "DESC 'Pathname for Unix domain socket' "
+                       "EQUALITY caseExactMatch "
+                       "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
+       { "extensions", "ext", 2, 0, 0, ARG_MAGIC|BS_EXT,
+               bs_cf_gen, "( OLcfgDbAt:7.2 NAME 'olcDbSocketExtensions' "
+                       "DESC 'binddn, peername, or ssf' "
+                       "EQUALITY caseIgnoreMatch "
+                       "SYNTAX OMsDirectoryString )", NULL, NULL },
+       { NULL, NULL }
+};
+
+static ConfigOCs bsocs[] = {
+       { "( OLcfgDbOc:7.1 "
+               "NAME 'olcDbSocketConfig' "
+               "DESC 'Socket backend configuration' "
+               "SUP olcDatabaseConfig "
+               "MUST olcDbSocketPath "
+               "MAY olcDbSocketExtensions )",
+                       Cft_Database, bscfg },
+       { NULL, 0, NULL }
+};
+
+static slap_verbmasks bs_exts[] = {
+       { BER_BVC("binddn"), SOCK_EXT_BINDDN },
+       { BER_BVC("peername"), SOCK_EXT_PEERNAME },
+       { BER_BVC("ssf"), SOCK_EXT_SSF },
+       { BER_BVNULL, 0 }
+};
+
+static int
+bs_cf_gen( ConfigArgs *c )
+{
+       struct sockinfo *si = c->be->be_private;
+       int rc;
 
-       /* extensions */
-       } else if ( strcasecmp( argv[0], "extensions" ) == 0 ) {
-               int i;
-               for ( i=1; i<argc; i++ ) {
-                       if ( strcasecmp( argv[i], "binddn" ) == 0 )
-                               si->si_extensions |= SOCK_EXT_BINDDN;
-                       else if ( strcasecmp( argv[i], "peername" ) == 0 )
-                               si->si_extensions |= SOCK_EXT_PEERNAME;
-                       else if ( strcasecmp( argv[i], "ssf" ) == 0 )
-                               si->si_extensions |= SOCK_EXT_SSF;
-                       else {
-                               fprintf( stderr,
-       "%s: line %d: unknown extension \"%s\"\n",
-                           fname, lineno, argv[i] );
-                               return( 1 );
+       if ( c->op == SLAP_CONFIG_EMIT ) {
+               switch( c->type ) {
+               case BS_EXT:
+                       return mask_to_verbs( bs_exts, si->si_extensions, &c->rvalue_vals );
+               }
+       } else if ( c->op == LDAP_MOD_DELETE ) {
+               switch( c->type ) {
+               case BS_EXT:
+                       if ( c->valx < 0 ) {
+                               si->si_extensions = 0;
+                       } else {
                        }
+                       return mask_to_verbs( bs_exts, si->si_extensions, &c->rvalue_vals );
                }
 
-       /* anything else */
        } else {
-               return SLAP_CONF_UNKNOWN;
+               switch( c->type ) {
+               case BS_EXT:
+                       return verbs_to_mask( c->argc, c->argv, bs_exts, &si->si_extensions );
+               }
        }
+       return 1;
+}
+
+int
+sock_back_init_cf( BackendInfo *bi )
+{
+       bi->bi_cf_ocs = bsocs;
 
-       return 0;
+       return config_register_schema( bscfg, bsocs );
 }
index 73eb3c7ac682818a7e67191a857c9694754aac4e..e88ecb9ebbed0f3b22449c8e2ea674071869cfd2 100644 (file)
@@ -38,7 +38,7 @@ sock_back_initialize(
        bi->bi_destroy = 0;
 
        bi->bi_db_init = sock_back_db_init;
-       bi->bi_db_config = sock_back_db_config;
+       bi->bi_db_config = 0;
        bi->bi_db_open = 0;
        bi->bi_db_close = 0;
        bi->bi_db_destroy = sock_back_db_destroy;
@@ -60,7 +60,7 @@ sock_back_initialize(
        bi->bi_connection_init = 0;
        bi->bi_connection_destroy = 0;
 
-       return 0;
+       return sock_back_init_cf( bi );
 }
 
 int
@@ -74,6 +74,7 @@ sock_back_db_init(
        si = (struct sockinfo *) ch_calloc( 1, sizeof(struct sockinfo) );
 
        be->be_private = si;
+       be->be_cf_ocs = be->bd_info->bi_cf_ocs;
 
        return si == NULL;
 }
index 9443574d160ce6e5d879fddf4bcc8463ed53fff7..cdaeaeb2343efb0bf5065d8e7f77fa92a4f2df98 100644 (file)
@@ -30,7 +30,6 @@ extern BI_destroy     sock_back_destroy;
 
 extern BI_db_init      sock_back_db_init;
 extern BI_db_destroy   sock_back_db_destroy;
-extern BI_db_config    sock_back_db_config;
 
 extern BI_op_bind      sock_back_bind;
 extern BI_op_unbind    sock_back_unbind;
@@ -41,6 +40,8 @@ extern BI_op_modrdn   sock_back_modrdn;
 extern BI_op_add       sock_back_add;
 extern BI_op_delete    sock_back_delete;
 
+extern int sock_back_init_cf( BackendInfo *bi );
+
 LDAP_END_DECL
 
 #endif /* _PROTO_SOCK_H */
index e394c3d787d9eedafcb96f986dadd90c422c146c..1b8682fc9ff72a307da1f524bb2dec3656d9b497 100644 (file)
@@ -230,6 +230,7 @@ static OidRec OidMacros[] = {
  * OLcfg{Bk|Db}{Oc|At}:4               -> back-monitor
  * OLcfg{Bk|Db}{Oc|At}:5               -> back-relay
  * OLcfg{Bk|Db}{Oc|At}:6               -> back-sql
+ * OLcfg{Bk|Db}{Oc|At}:7               -> back-sock
  */
 
 /*