[Date Prev][Date Next] [Chronological] [Thread] [Top]

function 'test_filter' cant handle 'begins with' filters



Hi!
I have implemented openLdap to work with a Btrieve database. To speed up
the search functionality I interpret the filterstring (example:
"(!(uid=12345)(cn=mikael)...)"). Everything work fine except when I want
to get f.e. all entries that begin with "uid=123", i.e. I get
filterstring uid=123*.
When I use "equal to" the testfilter accepts my resulting entry but when
getting the exact same entry with filter "begins with" I get mismatch???

I am not able to test with "ends with" or "contains" filters since my
database doesnt support wildcard search in the beginning (I have to do a
linear search instead).

Is it very important in what order I place the resulting attributes?

(not that it really matters here but...) Is test_filter(...) case
sensitive?

I map my database struct information into an entry in the following
way(appologize for all this code):

bool Prec2Entry(PREC prec,PRECEXT precext,Entry& sEntry,
    char dn[],char type[])
{
 try
 {
  char name[100],email[50],pCode[20],district[15],surname[40];
  char telnumb[30];
  name[0]='\0';
  email[0]='\0';
  pCode[0]='\0';
  surname[0]='\0';
  telnumb[0]='\0';
  // sEntry is inparameter
  // first create new entry structure
  sEntry.e_dn=new char[100];
  sEntry.e_ndn=new char[100];
  // common name ---> concatenation of f_name and l_name
  if (strlen(prec.l_name)>0)
   strcpy(surname,prec.l_name);
  else
   strcpy(surname,"NOSURNAME");
  int argc=fixCNFromf_name_l_name_sign(name,prec.f_name,
        prec.l_name,precext.amv_kod);
  if (argc<1)
   strcpy(name,"NONAME");
#ifdef _GENERAL_INFO_DUMP_
  printf("prec2Entry,extracted CN:%s\n",name);
  printf("prec2Entry,argc(from fixCNFrom...):%i\n",argc);
#endif
  // email
  if (strlen(prec.info7)>2)
  {
   char cemail[50];
   strcpy(email,prec.info7);
   convertToCapitalDN(email,cemail); // convert to capital letters
   strcpy(email,cemail);     // to be able to keep dn=ndn
  }           //  thinking
  else
  {
   tlwcLog.insertMess(2,3,"client doesnt have proper
email","inserting'nomail'","Prec2Entry");
   strcpy(email,"nomail");
  }
  if (strlen(precext.amv_kod)>0)
   strcpy(pCode,precext.amv_kod);
  else
   strcpy(pCode,"NOCODEYET");
  if (strlen(prec.cg)>0)
   strcpy(district,prec.cg);
  else
   strcpy(district,"FATAL_ERROR,no cg");
  if (strlen(prec.info4)>0)
  {
   strcpy(telnumb,prec.info4);
  }
  else
   strcpy(telnumb,"NONUMBERYET");
  if (strcmp(type,"CN")==0)
  {
   strcpy(sEntry.e_dn,"CN="); //*********************************
   strcat(sEntry.e_dn,name);  // insert the proper dn for record
   strcat(sEntry.e_dn,",");  //    done
   strcat(sEntry.e_dn,dn);  //*********************************
   strcpy(sEntry.e_ndn,sEntry.e_dn); // since we assume that dn=ndn
  }
  else if (strcmp(type,"MAIL")==0)
  {
   strcpy(sEntry.e_dn,"MAIL="); //*********************************
   strcat(sEntry.e_dn,email);  // insert the proper dn for record
   strcat(sEntry.e_dn,",");  //    done
   strcat(sEntry.e_dn,dn);  //*********************************
   strcpy(sEntry.e_ndn,sEntry.e_dn); // since we assume that dn=ndn
  }
  else if (strcmp(type,"UID")==0)
  {
   strcpy(sEntry.e_dn,"UID=");
   strcat(sEntry.e_dn,pCode);
   strcat(sEntry.e_dn,",");
   strcat(sEntry.e_dn,dn);
   strcpy(sEntry.e_ndn,sEntry.e_dn);
  }
  else
  {
   tlwcLog.insertMess(2,2,
    "found an invalid/unsupported rdn type:",type,
    "Prec2Entry");
   return false;
  }
  //***************************************************
  Attribute* temp1;
  temp1=new Attribute;
  temp1->a_type=new char[15];
  strcpy(temp1->a_type,"OBJECTCLASS"); // common name type
  temp1->a_vals=new BerValue*[5];

  temp1->a_vals[0]=new BerValue;
  temp1->a_vals[0]->bv_val=new char[5];
  strcpy(temp1->a_vals[0]->bv_val,"TOP");
  temp1->a_vals[0]->bv_len=strlen("TOP");

  temp1->a_vals[1]=new BerValue;
  temp1->a_vals[1]->bv_val=new char[25];
  strcpy(temp1->a_vals[1]->bv_val,"NEWPILOTPERSON");
  temp1->a_vals[1]->bv_len=strlen("NEWPILOTPERSON");
  //temp1->a_vals[2]=NULL;

  temp1->a_vals[2]=new BerValue;
  temp1->a_vals[2]->bv_val=new char[25];
  strcpy(temp1->a_vals[2]->bv_val,"INETORGPERSON");
  temp1->a_vals[2]->bv_len=strlen("INETORGPERSON");
  //temp1->a_vals[3]=NULL;

  temp1->a_vals[3]=new BerValue;
  temp1->a_vals[3]->bv_val=new char[25];
  strcpy(temp1->a_vals[3]->bv_val,"ORGANIZATIONALPERSON");
  temp1->a_vals[3]->bv_len=strlen("ORGANIZATIONALPERSON");
  temp1->a_vals[4]=NULL;

  sEntry.e_attrs=temp1;
  // objectclass specifyer, always mail in AMV:s case
  Attribute* temp2;
  temp2=new Attribute;
  temp2->a_type=new char[15];
  strcpy(temp2->a_type,"SN");
  temp2->a_vals=new BerValue*[2];
  temp2->a_vals[0]=new BerValue;
  temp2->a_vals[0]->bv_val=new char[strlen(surname)+1];
  strcpy(temp2->a_vals[0]->bv_val,surname);
  cout<<"Inside Prec2Entry, sn="<<temp2->a_vals[0]->bv_val<<endl;
  temp2->a_vals[0]->bv_len=strlen(surname);
  temp2->a_vals[1]=NULL;
  temp1->a_next=temp2;

  // COMMON NAME ATTRIBUTE
  Attribute* temp3;
  temp3=new Attribute;
  temp3->a_type=new char[3];
  strcpy(temp3->a_type,"CN"); // common name type
  temp3->a_vals=new BerValue*[2];
  temp3->a_vals[0]=new BerValue;
  temp3->a_vals[0]->bv_val=new char[strlen(name)+1];
  strcpy(temp3->a_vals[0]->bv_val,name);
  temp3->a_vals[0]->bv_len=strlen(name);
  temp3->a_vals[1]=NULL;
#ifdef _GENERAL_INFO_DUMP_
  printf("cn attr.(in search.cpp):%s\n",temp3->a_vals[0]->bv_val);
#endif
  temp2->a_next=temp3;

  // EMAIL ATTRIBUTE INSERTION
  Attribute* temp4;
  temp4=new Attribute;
  temp4->a_type=new char[6];
  strcpy(temp4->a_type,"MAIL");
  temp4->a_vals=new BerValue*[2];
  temp4->a_vals[0]=new BerValue;
  temp4->a_vals[0]->bv_val=new char[strlen(email)+1];
  strcpy(temp4->a_vals[0]->bv_val,email);
  temp4->a_vals[0]->bv_len=strlen(email);
  temp4->a_vals[1]=NULL;
  temp3->a_next=temp4;

  // Personal code attribute
  Attribute* temp5;
  temp5=new Attribute;
  temp5->a_type=new char[5];
  strcpy(temp5->a_type,"UID");
  temp5->a_vals=new BerValue*[2];
  temp5->a_vals[0]=new BerValue;
  if (strlen(pCode)>0) // should always be greater than NULL
  {
   temp5->a_vals[0]->bv_val=new char[strlen(pCode)+1];
   strcpy(temp5->a_vals[0]->bv_val,pCode);
   temp5->a_vals[0]->bv_len=strlen(pCode);
   cout<<"Inside Prec2Entry, uid="<<temp5->a_vals[0]->bv_val<<endl;
  }
  else
  {
   temp5->a_vals[0]->bv_val=new char[strlen("NOCODEYET")+1];
   strcpy(temp5->a_vals[0]->bv_val,"NOCODEYET");
   temp5->a_vals[0]->bv_len=strlen("NOCODEYET");
  }
  temp5->a_vals[1]=NULL;
  temp4->a_next=temp5;

  // Personal code attribute
  Attribute* temp6;
  temp6=new Attribute;
  temp6->a_type=new char[21];
  strcpy(temp6->a_type,"ORGANIZATIONALSTATUS");
  temp6->a_vals=new BerValue*[2];
  temp6->a_vals[0]=new BerValue;
  if (strlen(district)>0) // should always be greater than NULL
  {
   temp6->a_vals[0]->bv_val=new char[strlen(district)+1];
   strcpy(temp6->a_vals[0]->bv_val,district);
   temp6->a_vals[0]->bv_len=strlen(district);
  }
  else
  {
   temp6->a_vals[0]->bv_val=new char[strlen("ERROR_NOT_CG")+1];
   strcpy(temp6->a_vals[0]->bv_val,"ERROR_NOT_CG");
   temp6->a_vals[0]->bv_len=strlen("ERROR_NOT_CG");
  }
  temp6->a_vals[1]=NULL;
  temp5->a_next=temp6;

  // TELEPHONE NUMBER ATTRIBUTE
  Attribute* temp7;
  temp7=new Attribute;
  temp7->a_type=new char[16];
  strcpy(temp7->a_type,"TELEPHONENUMBER");
  temp7->a_vals=new BerValue*[2];
  temp7->a_vals[0]=new BerValue;
  if (strlen(telnumb)>0) // should always be greater than NULL
  {
   temp7->a_vals[0]->bv_val=new char[strlen(telnumb)+1];
   strcpy(temp7->a_vals[0]->bv_val,telnumb);
   temp7->a_vals[0]->bv_len=strlen(telnumb);
  }
  else
  {
   temp7->a_vals[0]->bv_val=new char[strlen("ERROR_NO_TELEPHONE")+1];
   strcpy(temp7->a_vals[0]->bv_val,"ERROR_NO_TELEPHONE");
   temp7->a_vals[0]->bv_len=strlen("ERROR_NO_TELEPHONE");
  }
  temp7->a_vals[1]=NULL;
  temp6->a_next=temp7;

  // ORGANIZATIONAL UNIT ATTRIBUTE
  Attribute* temp8;
  temp8=new Attribute;
  temp8->a_type=new char[3];
  strcpy(temp8->a_type,"OU");
  temp8->a_vals=new BerValue*[2];
  temp8->a_vals[0]=new BerValue;
  if (strlen(prec.org)>0) // should always be greater than NULL
  {
   temp8->a_vals[0]->bv_val=new char[strlen(prec.org)+1];
   strcpy(temp8->a_vals[0]->bv_val,prec.org);
   temp8->a_vals[0]->bv_len=strlen(prec.org);
  }
  else
  {
   temp8->a_vals[0]->bv_val=new char[strlen("ERROR_NO_OU")+1];
   strcpy(temp8->a_vals[0]->bv_val,"ERROR_NO_OU");
   temp8->a_vals[0]->bv_len=strlen("ERROR_NO_OU");
  }
  temp8->a_vals[1]=NULL;
  temp7->a_next=temp8;

  // FAX NUMBER ATTRIBUTE
  Attribute* temp9;
  temp9=new Attribute;
  temp9->a_type=new char[26];
  strcpy(temp9->a_type,"FACSIMILETELEPHONENUMBER");
  temp9->a_vals=new BerValue*[2];
  temp9->a_vals[0]=new BerValue;
  if (strlen(prec.info6)>0) // should always be greater than NULL
  {
   temp9->a_vals[0]->bv_val=new char[strlen(prec.info6)+1];
   strcpy(temp9->a_vals[0]->bv_val,prec.info6);
   temp9->a_vals[0]->bv_len=strlen(prec.info6);
  }
  else
  {
   temp9->a_vals[0]->bv_val=new char[strlen("ERROR_NO_FAX")+1];
   strcpy(temp9->a_vals[0]->bv_val,"ERROR_NO_FAX");
   temp9->a_vals[0]->bv_len=strlen("ERROR_NO_FAX");
  }
  temp9->a_vals[1]=NULL;
  temp8->a_next=temp9;

  // ROOM NUMBER ATTRIBUTE
  Attribute* temp10;
  temp10=new Attribute;
  temp10->a_type=new char[16];
  strcpy(temp10->a_type,"ROOMNUMBER");
  temp10->a_vals=new BerValue*[2];
  temp10->a_vals[0]=new BerValue;
  if (strlen(prec.info1)>0) // should always be greater than NULL
  {
   temp10->a_vals[0]->bv_val=new char[strlen(prec.info1)+1];
   strcpy(temp10->a_vals[0]->bv_val,prec.info1);
   temp10->a_vals[0]->bv_len=strlen(prec.info1);
  }
  else
  {
   temp10->a_vals[0]->bv_val=new char[strlen("ERROR_NO_ROOMNUMBER")+1];
   strcpy(temp10->a_vals[0]->bv_val,"ERROR_NO_ROOMNUMBER");
   temp10->a_vals[0]->bv_len=strlen("ERROR_NO_ROOMNUMBER");
  }
  temp10->a_vals[1]=NULL;
  temp9->a_next=temp10;

  // NEW ATTRIBUTES LATER ON
  // FINISH LINKED LIST OF ATTRIBUTES
  temp10->a_next=NULL;
....
return true;
}

Can anyone see why this is not working when testing the resulting entry
with (f.e.)
&(uid=123*)(....all objectclass stuff....)?
--
mvh/sincerely

Mikael Grehn
M.Sc
Systems Engineer
Envilogg Datateknik AB
Tel: +46 (0)18 ? 135918
Fax: +46 (0)18 ? 125968
Email: mikael@envilogg.se