]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-sql/schema-map.c
Add a safety check to bvcasechr
[openldap] / servers / slapd / back-sql / schema-map.c
index ca76a30dbcc5c36195ec0fa01b8557daa34827d7..5f84573787ff0f4420b6bd72d88aa71eed9d7b26 100644 (file)
@@ -114,6 +114,20 @@ int backsql_load_schema_map(backsql_info *si,SQLHDBC dbh)
  int tmpslen;
 
  Debug(LDAP_DEBUG_TRACE,"==>load_schema_map()\n",0,0,0);
+
+ /* TimesTen : See if the ldap_entries.dn_ru field exists in the schema. */
+
+ rc = backsql_Prepare(dbh, &oc_sth, backsql_check_dn_ru_query, 0);
+ if (rc == SQL_SUCCESS) {
+   si->has_ldapinfo_dn_ru = 1;  /* Yes, the field exists */
+   Debug(LDAP_DEBUG_TRACE, "ldapinfo.dn_ru field exists in the schema\n", 0, 0,0);
+ }
+ else {
+   si->has_ldapinfo_dn_ru = 0;  /* No such field exists */
+ }
+
+ SQLFreeStmt(oc_sth, SQL_DROP);
+
  rc=backsql_Prepare(dbh,&oc_sth,si->oc_query,0);
  if (rc != SQL_SUCCESS)
   {
@@ -121,6 +135,8 @@ int backsql_load_schema_map(backsql_info *si,SQLHDBC dbh)
    backsql_PrintErrors(si->db_env,dbh,oc_sth,rc);
    return -1;
   }
+  Debug(LDAP_DEBUG_TRACE, "load_schema_map(): at_query '%s'\n", si->at_query,0,0);
+
  rc=backsql_Prepare(dbh,&at_sth,si->at_query,0);
  if (rc != SQL_SUCCESS)
   {
@@ -158,8 +174,15 @@ int backsql_load_schema_map(backsql_info *si,SQLHDBC dbh)
    oc_id=oc_map->id;
    Debug(LDAP_DEBUG_TRACE,"load_schema_map(): objectclass '%s': keytbl='%s' keycol='%s' ",
           oc_map->name,oc_map->keytbl,oc_map->keycol);
-   Debug(LDAP_DEBUG_TRACE,"create_proc='%s' delete_proc='%s' expect_return=%d; attributes:\n",
-       oc_map->create_proc,oc_map->delete_proc,oc_map->expect_return);
+   if (oc_map->delete_proc) {
+     Debug(LDAP_DEBUG_TRACE,"delete_proc='%s'\n", oc_map->delete_proc, 0, 0);
+   }
+   if (oc_map->create_proc) {
+     Debug(LDAP_DEBUG_TRACE,"create_proc='%s'\n", oc_map->create_proc, 0, 0);
+   }
+   Debug(LDAP_DEBUG_TRACE,"expect_return=%d; attributes:\n",
+       oc_map->expect_return, 0, 0);
+
    Debug(LDAP_DEBUG_TRACE,"load_schema_map(): autoadding 'objectClass' and 'ref' mappings\n",0,0,0);
    backsql_add_sysmaps(oc_map);
    if ((rc=SQLExecute(at_sth)) != SQL_SUCCESS)
@@ -177,9 +200,12 @@ int backsql_load_schema_map(backsql_info *si,SQLHDBC dbh)
         Debug(LDAP_DEBUG_TRACE,"join_where='%s',add_proc='%s' ",at_row.cols[3],
              at_row.cols[4],0);
         Debug(LDAP_DEBUG_TRACE,"delete_proc='%s'\n",at_row.cols[5],0,0);
+        Debug(LDAP_DEBUG_TRACE,"sel_expr_u='%s'\n", at_row.cols[8],0,0); /* TimesTen*/
      at_map=(backsql_at_map_rec*)ch_calloc(1,sizeof(backsql_at_map_rec));
      at_map->name=ch_strdup(at_row.cols[0]);
      at_map->sel_expr=ch_strdup(at_row.cols[1]);
+        at_map->sel_expr_u = (at_row.is_null[8]<0)?NULL:ch_strdup(at_row.cols[8
+]);
         tmps=NULL;tmpslen=0;
         backsql_merge_from_clause(&tmps,&tmpslen,at_row.cols[2]);
      at_map->from_tbls=ch_strdup(tmps);
@@ -208,13 +234,14 @@ backsql_oc_map_rec* backsql_oc_with_name(backsql_info *si,char* objclass)
 {
  backsql_oc_map_rec tmp,*res;
  
-// Debug(LDAP_DEBUG_TRACE,"==>oc_with_name(): searching for objectclass with name='%s'\n",objclass,0,0);
+/* Debug(LDAP_DEBUG_TRACE,"==>oc_with_name(): searching for objectclass with name='%s'\n",objclass,0,0);*/
  tmp.name=objclass;
  res=(backsql_oc_map_rec*)avl_find(si->oc_by_name,&tmp,(AVL_CMP)backsql_cmp_oc_name);
-// if (res!=NULL)
-//  Debug(LDAP_DEBUG_TRACE,"<==oc_with_name(): found name='%s', id=%d\n",res->name,res->id,0);
-// else
-//  Debug(LDAP_DEBUG_TRACE,"<==oc_with_name(): not found\n",0,0,0);
+/* if (res!=NULL)
+  Debug(LDAP_DEBUG_TRACE,"<==oc_with_name(): found name='%s', id=%d\n",res->name,res->id,0);
+ else
+  Debug(LDAP_DEBUG_TRACE,"<==oc_with_name(): not found\n",0,0,0);
+*/
  return res;
 }
 
@@ -222,13 +249,14 @@ backsql_oc_map_rec* backsql_oc_with_id(backsql_info *si,unsigned long id)
 {
  backsql_oc_map_rec tmp,*res;
  
-// Debug(LDAP_DEBUG_TRACE,"==>oc_with_id(): searching for objectclass with id='%d'\n",id,0,0);
+/* Debug(LDAP_DEBUG_TRACE,"==>oc_with_id(): searching for objectclass with id='%d'\n",id,0,0);*/
  tmp.id=id;
  res=(backsql_oc_map_rec*)avl_find(si->oc_by_id,&tmp,(AVL_CMP)backsql_cmp_oc_id);
-// if (res!=NULL)
-//  Debug(LDAP_DEBUG_TRACE,"<==oc_with_name(): found name='%s', id=%d\n",res->name,res->id,0);
-// else
-//  Debug(LDAP_DEBUG_TRACE,"<==oc_with_name(): not found\n",0,0,0);
+/* if (res!=NULL)
+  Debug(LDAP_DEBUG_TRACE,"<==oc_with_name(): found name='%s', id=%d\n",res->name,res->id,0);
+ else
+  Debug(LDAP_DEBUG_TRACE,"<==oc_with_name(): not found\n",0,0,0);
+*/
  return res;
 }
 
@@ -236,15 +264,17 @@ backsql_at_map_rec* backsql_at_with_name(backsql_oc_map_rec* objclass,char* attr
 {
  backsql_at_map_rec tmp,*res;
  
- //Debug(LDAP_DEBUG_TRACE,"==>at_with_name(): searching for attribute with name='%s' (for objectclass '%s')\n",
- //                attr,objclass->name,0);
+ /*Debug(LDAP_DEBUG_TRACE,"==>at_with_name(): searching for attribute with name='%s' (for objectclass '%s')\n",
+                 attr,objclass->name,0);
+*/
  tmp.name=attr;
  res=(backsql_at_map_rec*)avl_find(objclass->attrs,&tmp,(AVL_CMP)backsql_cmp_attr);
- //if (res!=NULL)
-  //Debug(LDAP_DEBUG_TRACE,"<==at_with_name(): found name='%s', sel_expr='%s'\n",
-  //            res->name,res->sel_expr,0);
- //else
- // Debug(LDAP_DEBUG_TRACE,"<==at_with_name(): not found\n",0,0,0);
+ /*if (res!=NULL)
+  Debug(LDAP_DEBUG_TRACE,"<==at_with_name(): found name='%s', sel_expr='%s'\n",
+              res->name,res->sel_expr,0);
+ else
+  Debug(LDAP_DEBUG_TRACE,"<==at_with_name(): not found\n",0,0,0);
+*/
  return res;
 }
 
@@ -264,6 +294,8 @@ int backsql_free_attr(backsql_at_map_rec *at)
  if (at->query)
   ch_free(at->query);
  ch_free(at);
+ if (at->sel_expr_u)
+   ch_free(at->sel_expr_u); /* TimesTen */
  Debug(LDAP_DEBUG_TRACE,"<==free_attr()\n",0,0,0);
  return 1;
 }