THanks Steve, this is most generous!

[EMAIL PROTECTED] wrote:
>  > You're right, this is a bug.  The FuzzyHostMatch truncates the base at 
>  > the first numerical character it finds -- the sscanf equivalent of a 
>  > greedy regex match (item.c): 
>  > 
>  >    1044 { struct Item *args;
>  >    1045  char *sp, refbase[CF_MAXVARSIZE];
>  >    1046   long cmp = -1, start = -1, end = -1;
>  >    1047 
>  >    1048 sscanf(refhost,"%[^0-9]%ld",&refbase,&cmp);
>  >    1049 
>  >    1050 Debug("Found refbase=%s,cmp=%d\n",refbase,cmp);
>  > 
>  > Results in 'Found refbase=pa,cmp=2' given 'pa2-dhcp-192-168-230-46'
>  > (which happens to be my test box's hostname at the moment).  
>  > 
>  > I can't think of a ready fix for this but my printf format-fu is not
>  > strong -- spoiled by real regex engines, I guess. Maybe we should be 
>  > scanning _backwards_ through 'refhost' looking for non-numerics?
>  > (Steve Rader are you still around? This is your code, steve... :-) )
> 
> Patch for 2.1.22 enclosed...
> 
>  strncpy(refbase,refhost,strlen(refhost));
>  sp = refbase + strlen(refbase) - 1;
>  while ( isdigit((int)*sp) ) { sp--; }
>  sp++;
>  sscanf(sp,"%ld",&cmp);
>  *sp = '\0';
> 
> ...instead.
> 
> Mark: let me know if it doesn't work for you.
> 
> steve
> - - -
> 
> 
> 
> ------------------------------------------------------------------------
> 
> --- src/item.c.orig   2006-11-16 09:36:59.999034210 -0600
> +++ src/item.c        2007-04-28 08:43:04.484690876 -0500
> @@ -1027,14 +1027,14 @@
>  
>  /*
>   * do something like...
> - *   @args = split(/,/,$s1);
>   *   if ( $refhost !~ /(\d+)$/ ) {
> - *     return 1; # failure: no num in hostname
> + *     return 1; # failure: refhost doesn't end in numeral
>   *   }
> - *   if ( $1 < $args[1] || $1 > $args[2] ) {
> - *     return 1; # failure: hostname num not in range
> + *   $hostnum = $1;
> + *   if ( $hostnum < $args[1] || $hostnum > $args[2] ) {
> + *     return 1; # failure: refhost hostnum not in range
>   *   }
> - *   $refhost =~ s/^(.*?)\d.*$/$1/;
> + *   $refhost =~ s/^(.*)\d.*$/$1/;
>   *   if ( $refhost ne $args[0] ) {
>   *     return 1; # failure: hostname doesn't match basename
>   *   }
> @@ -1042,12 +1042,16 @@
>   */
>  
>  { struct Item *args;
> - char *sp, refbase[CF_MAXVARSIZE];
> +  char *sp, refbase[CF_MAXVARSIZE];
>    long cmp = -1, start = -1, end = -1;
>  
> -sscanf(refhost,"%[^0-9]%ld",&refbase,&cmp);
> -
> -Debug("Found refbase=%s,cmp=%d\n",refbase,cmp);
> +strncpy(refbase,refhost,strlen(refhost));
> +sp = refbase + strlen(refbase) - 1;
> +while ( isdigit((int)*sp) ) { sp--; }
> +sp++;
> +sscanf(sp,"%ld",&cmp);
> +*sp = '\0';
> +Debug("SRDEBUG FuzzyHostMatch: refbase=%s,cmp=%d\n",refbase,cmp);
>  
>  if (cmp < 0)
>     {
> @@ -1063,13 +1067,13 @@
>  
>  if ( cmp < start || cmp > end )
>     {
> -   Debug("Failed on numberical range (%d < %d < %d)",end,cmp,start);
> +   Debug("SRDEBUG Failed on numberical range (%d < %d < 
> %d)\n",end,cmp,start);
>     return 1;
>     }
>  
>  if (strcmp(refbase,arg0) != 0)
>     {
> -   Debug("Failed on name %s != %s)",refbase,arg0);
> +   Debug("SRDEBUG Failed on name (%s != %s)\n",refbase,arg0);
>     return 1;
>     }
>  
> --- src/functions.c.orig      2007-01-23 09:23:06.384149105 -0600
> +++ src/functions.c   2007-04-28 08:36:40.000000000 -0500
> @@ -461,16 +461,16 @@
>  /* VDEFAULTBINSERVER.name is relative domain name */
>  /* (see nameinfo.c ~line 145)                     */
>  
> -Debug("Parsing fuzzy host succeeded\n");
> +Debug("SRDEBUG FuzzyHostParse(%s,%s) succeeded for 
> %s\n",argv[0],argv[1],VUQNAME);
>  
>  if (FuzzyHostMatch(argv[0],argv[1],VUQNAME) == 0)
>     {
> -   Debug("SRDEBUG SUCCESS!\n");
> +   Debug("SRDEBUG FuzzyHostMatch(%s,%s,%s) 
> succeeded\n",argv[0],argv[1],VUQNAME);
>     strcpy(value,CF_ANYCLASS);
>     }
>  else
>     {
> -   Debug("SRDEBUG FAILURE\n");
> +   Debug("SRDEBUG FuzzyHostMatch(%s,%s,%s) 
> failed\n",argv[0],argv[1],VUQNAME);
>     strcpy(value,CF_NOCLASS);
>     }
>   
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Bug-cfengine mailing list
> [email protected]
> https://cfengine.org/mailman/listinfo/bug-cfengine

-- 
Mark Burgess

Professor of Network and System Administration
Oslo University College

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Work: +47 22453272            Email:  [EMAIL PROTECTED]
Fax : +47 22453205            WWW  :  http://www.iu.hio.no/~mark
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
Bug-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/bug-cfengine

Reply via email to