]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/iniparser/iniparser.c
Change default FinderInfo for directories to be all 0
[netatalk.git] / libatalk / iniparser / iniparser.c
index 505cf124d23ca8ad8b9bffaa50bc1915f26e965a..93e14b6b46b55b6b29bbe7802b68ca70b416e881 100644 (file)
@@ -1,4 +1,3 @@
-
 /*-------------------------------------------------------------------------*/
 /**
    @file    iniparser.c
@@ -9,6 +8,10 @@
 */
 
 /*---------------------------- Includes ------------------------------------*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #include <ctype.h>
 
 #include <atalk/iniparser.h>
@@ -35,9 +38,9 @@ typedef enum _line_status_ {
 
 /*-------------------------------------------------------------------------*/
 /**
-  @brief       Remove blanks at the beginning and the end of a string.
-  @param       s       String to parse.
-  @return      ptr to statically allocated string.
+  @brief    Remove blanks at the beginning and the end of a string.
+  @param    s   String to parse.
+  @return   ptr to statically allocated string.
 
   This function returns a pointer to a statically allocated string,
   which is identical to the input string, except that all blank
@@ -50,21 +53,21 @@ typedef enum _line_status_ {
 static char * strstrip(char * s)
 {
     static char l[ASCIILINESZ+1];
-       char * last ;
-       
+    char * last ;
+
     if (s==NULL) return NULL ;
-    
-       while (isspace((int)*s) && *s) s++;
-       memset(l, 0, ASCIILINESZ+1);
-       strcpy(l, s);
-       last = l + strlen(l);
-       while (last > l) {
-               if (!isspace((int)*(last-1)))
-                       break ;
-               last -- ;
-       }
-       *last = (char)0;
-       return (char*)l ;
+
+    while (isspace((int)*s) && *s) s++;
+    memset(l, 0, ASCIILINESZ+1);
+    strcpy(l, s);
+    last = l + strlen(l);
+    while (last > l) {
+        if (!isspace((int)*(last-1)))
+            break ;
+        last -- ;
+    }
+    *last = (char)0;
+    return (char*)l ;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -441,7 +444,7 @@ void iniparser_unset(dictionary * ini, char *section, char * key)
 
 /*-------------------------------------------------------------------------*/
 /**
-  @brief       Load a single line from an INI file
+  @brief    Load a single line from an INI file
   @param    input_line  Input line, may be concatenated multi-line input
   @param    section     Output space to store section
   @param    key         Output space to store key
@@ -454,7 +457,7 @@ static line_status iniparser_line(
     char * section,
     char * key,
     char * value)
-{   
+{
     line_status sta ;
     char        line[ASCIILINESZ+1];
     int         len ;
@@ -468,15 +471,14 @@ static line_status iniparser_line(
         sta = LINE_EMPTY ;
     } else if (line[0]=='#' || line[0]==';') {
         /* Comment line */
-        sta = LINE_COMMENT ; 
+        sta = LINE_COMMENT ;
     } else if (line[0]=='[' && line[len-1]==']') {
         /* Section name */
         sscanf(line, "[%[^]]", section);
         strcpy(section, strstrip(section));
         strcpy(section, section);
         sta = LINE_SECTION ;
-    } else if (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2
-           ||  sscanf (line, "%[^=] = '%[^\']'",   key, value) == 2
+    } else if (sscanf (line, "%[^=] = '%[^\']'",   key, value) == 2
            ||  sscanf (line, "%[^=] = %[^;#]",     key, value) == 2) {
         /* Usual key=value, with or without comments */
         strcpy(key, strstrip(key));
@@ -530,7 +532,6 @@ dictionary * iniparser_load(const char * ininame)
     char line    [ASCIILINESZ+1] ;
     char section [ASCIILINESZ+1] ;
     char key     [ASCIILINESZ+1] ;
-    char tmp     [ASCIILINESZ+1] ;
     char val     [ASCIILINESZ+1] ;
 
     int  last=0 ;
@@ -541,13 +542,13 @@ dictionary * iniparser_load(const char * ininame)
     dictionary * dict ;
 
     if ((inifile=fopen(ininame, "r"))==NULL) {
-        LOG(logtype_default, log_error, "iniparser: cannot open \"%s\"", ininame);
+        LOG(log_error, logtype_default, "iniparser: cannot open \"%s\"", ininame);
         return NULL ;
     }
 
     dict = dictionary_new(0) ;
     if (!dict) {
-        fclose(in);
+        fclose(inifile);
         return NULL ;
     }
 
@@ -572,14 +573,6 @@ dictionary * iniparser_load(const char * ininame)
         len = (int)strlen(line)-1;
         if (len==0)
             continue;
-        /* Safety check against buffer overflows */
-        if (line[len]!='\n') {
-            LOG(logtype_default, log_error, "iniparser: input line too long in \"%s\" (lineno: %d)",
-                ininame, lineno);
-            dictionary_del(dict);
-            fclose(in);
-            return NULL ;
-        }
         /* Get rid of \n and spaces at end of line */
         while ((len>=0) &&
                 ((line[len]=='\n') || (isspace(line[len])))) {
@@ -599,12 +592,14 @@ dictionary * iniparser_load(const char * ininame)
         case LINE_COMMENT:
             break ;
         case LINE_SECTION:
+            if (strchr(section, ':') != NULL)
+                LOG(log_error, logtype_default, "iniparser: syntax error \"%s\" section name must not contain \":\".", section);
             errs = dictionary_set(dict, section, NULL, NULL);
             break ;
         case LINE_VALUE:
             if (strcmp(key, "include") == 0) {
                 if ((include = fopen(val, "r")) == NULL) {
-                    LOG(logtype_default, log_error, "iniparser: cannot open \"%s\"", val);
+                    LOG(log_error, logtype_default, "iniparser: cannot open \"%s\"", val);
                     continue;
                 }
                 in = include;
@@ -613,7 +608,7 @@ dictionary * iniparser_load(const char * ininame)
             errs = dictionary_set(dict, section, key, val) ;
             break ;
         case LINE_ERROR:
-            LOG(logtype_default, log_error, "iniparser: syntax error in %s (lineno: %d): %s",
+            LOG(log_error, logtype_default, "iniparser: syntax error in %s (lineno: %d): %s",
                 ininame, lineno, line);
             errs++ ;
             break;
@@ -623,7 +618,7 @@ dictionary * iniparser_load(const char * ininame)
         memset(line, 0, ASCIILINESZ);
         last=0;
         if (errs<0) {
-            LOG(logtype_default, log_error, "iniparser: memory allocation failure");
+            LOG(log_error, logtype_default, "iniparser: memory allocation failure");
             break ;
         }
     }