Ignore:
Timestamp:
Feb 3, 2009, 8:45:50 PM (16 years ago)
Author:
katerina
Message:

Allow shell expansion for cofiguration file values (ticket #137).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_readconf.c

    r205 r211  
    135135  { NULL,                     SH_SECTION_NONE}
    136136};
     137
     138static char * sh_readconf_expand_value (const char * str)
     139{
     140  char * tmp = (char*)str;
     141  char * out;
     142
     143  while (tmp && isspace((int)*tmp)) ++tmp;
     144 
     145  if (tmp[0] == '$' && tmp[1] == '(')
     146    {
     147      size_t len = strlen(tmp);
     148      while (isspace((int) tmp[len-1])) { tmp[len-1] = '\0'; --len; }
     149      if (tmp[len-1] == ')')
     150        {
     151          tmp[len-1] = '\0';
     152          out = sh_ext_popen_str(&tmp[2]);
     153          return out;
     154        }
     155    }
     156  return sh_util_strdup(str);
     157}
    137158
    138159enum {
     
    12971318    }
    12981319
     1320  /* Expand shell expressions. This return allocated memory which we must free.
     1321   */
     1322  value = sh_readconf_expand_value(value);
     1323
     1324  if (!value || (*value) == '\0')
     1325    {
     1326      TPT(( 0, FIL__, __LINE__, _("msg=<ConfigFile: empty after shell expansion: %s>\n"),
     1327            line));
     1328      SL_RETURN(good_opt, _("sh_readconf_line"));
     1329    }
    12991330
    13001331#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
     
    13621393    }
    13631394
     1395  SH_FREE((char*)value);
     1396
    13641397  SL_RETURN(good_opt, _("sh_readconf_line"));
    13651398}
Note: See TracChangeset for help on using the changeset viewer.