Changeset 304:ad3c46016584 in freeDiameter for extensions/app_radgw/rgw_conf.y
- Timestamp:
- May 14, 2010, 5:26:53 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/app_radgw/rgw_conf.y
r258 r304 53 53 #include "rgw_conf.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */ 54 54 55 #include <sys/stat.h>56 55 #include <sys/socket.h> 57 56 #include <arpa/inet.h> … … 97 96 else 98 97 fd_log_debug("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s); 99 }100 101 /* This function checks a string value is a valid filename */102 static int is_valid_file( char * candidate )103 {104 int ret;105 struct stat buffer;106 107 ret = stat(candidate, &buffer);108 if (ret != 0) {109 fd_log_debug("Error on file '%s': %s.\n", candidate, strerror(errno));110 return 0;111 }112 113 /* Ok this candidate is valid */114 return 1;115 98 } 116 99 … … 161 144 %token <ss> IP 162 145 163 %type <string> FI LENAME146 %type <string> FINDFILEEXT 164 147 165 148 /* simple tokens */ … … 197 180 198 181 /* -------------------------------------- */ 199 FILENAME: QSTRING 200 { 201 /* Verify this is a valid file */ 202 if (!is_valid_file($1)) { 203 yyerror (&yylloc, conffile, "Error on file name, aborting..."); 204 YYERROR; 205 } 206 $$ = $1; 182 FINDFILEEXT: QSTRING 183 { 184 char * fname = $1; 185 FILE * fd; 186 187 /* First, check if the file exists */ 188 fd = fopen(fname, "r"); 189 if ((fd == NULL) && (*fname != '/')) { 190 char * bkp = fname; 191 CHECK_MALLOC_DO( fname = malloc( strlen(bkp) + strlen(DEFAULT_EXTENSIONS_PATH) + 2 ), 192 { yyerror (&yylloc, conffile, "Not enough memory"); YYERROR; } ); 193 sprintf(fname, DEFAULT_EXTENSIONS_PATH "/%s", bkp); 194 free(bkp); 195 fd = fopen(fname, "r"); 196 } 197 if (fd == NULL) { 198 int ret = errno; 199 TRACE_DEBUG(INFO, "Unable to open file %s for reading: %s\n", fname, strerror(ret)); 200 yyerror (&yylloc, conffile, "Error adding plugin"); 201 YYERROR; 202 } 203 fclose(fd); 204 205 $$ = fname; 207 206 } 208 207 ; … … 214 213 free(plgconffile); plgconffile = NULL; 215 214 } 216 PLG_PREFIX '=' FI LENAMEplg_attributes ';'215 PLG_PREFIX '=' FINDFILEEXT plg_attributes ';' 217 216 { 218 217 /* Add this extension in the list */
Note: See TracChangeset
for help on using the changeset viewer.