Subversion Repositories SvarDOS

Rev

Rev 272 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 272 Rev 613
Line 27... Line 27...
27
static int checkfordoubledirlist(const struct customdirs *dirlist) {
27
static int checkfordoubledirlist(const struct customdirs *dirlist) {
28
  struct customdirs *curpos;
28
  struct customdirs *curpos;
29
  for (; dirlist != NULL; dirlist = dirlist->next) {
29
  for (; dirlist != NULL; dirlist = dirlist->next) {
30
    for (curpos = dirlist->next; curpos != NULL; curpos = curpos->next) {
30
    for (curpos = dirlist->next; curpos != NULL; curpos = curpos->next) {
31
      if (strcasecmp(curpos->name, dirlist->name) == 0) {
31
      if (strcasecmp(curpos->name, dirlist->name) == 0) {
32
        kitten_printf(7, 0, "ERROR: custom dir '%s' is listed twice!", curpos->name);
32
        kitten_printf(7, 0, curpos->name); /* "ERROR: custom dir '%s' is listed twice!" */
33
        puts("");
33
        puts("");
34
        return(-1);
34
        return(-1);
35
      }
35
      }
36
    }
36
    }
37
  }
37
  }
Line 42... Line 42...
42
/* validates dirlist entries: check that they are absolute paths and are not using restricted names */
42
/* validates dirlist entries: check that they are absolute paths and are not using restricted names */
43
static int validatedirlist(const struct customdirs *dirlist) {
43
static int validatedirlist(const struct customdirs *dirlist) {
44
  for (; dirlist != NULL; dirlist = dirlist->next) {
44
  for (; dirlist != NULL; dirlist = dirlist->next) {
45
    /* the location must be at least 3 characters long to be a valid absolute path (like 'c:\')*/
45
    /* the location must be at least 3 characters long to be a valid absolute path (like 'c:\')*/
46
    if (strlen(dirlist->location) < 3) {
46
    if (strlen(dirlist->location) < 3) {
47
      kitten_printf(7, 15, "ERROR: custom dir '%s' is not a valid absolute path!", dirlist->name);
47
      kitten_printf(7, 15, dirlist->name); /* "ERROR: custom dir '%s' is not a valid absolute path!" */
48
      puts("");
48
      puts("");
49
      return(-1);
49
      return(-1);
50
    }
50
    }
51
    /* is it a valid absolute path? should start with [a..Z]:\ */
51
    /* is it a valid absolute path? should start with [a..Z]:\ */
52
    if ((dirlist->location[1] != ':') ||
52
    if ((dirlist->location[1] != ':') ||
53
       ((dirlist->location[2] != '/') && (dirlist->location[2] != '\\')) ||
53
       ((dirlist->location[2] != '/') && (dirlist->location[2] != '\\')) ||
54
       (((dirlist->location[0] < 'a') || (dirlist->location[0] > 'z')) && ((dirlist->location[0] < 'A') || (dirlist->location[0] > 'Z')))) {
54
       (((dirlist->location[0] < 'a') || (dirlist->location[0] > 'z')) && ((dirlist->location[0] < 'A') || (dirlist->location[0] > 'Z')))) {
55
      kitten_printf(7, 15, "ERROR: custom dir '%s' is not a valid absolute path!", dirlist->name);
55
      kitten_printf(7, 15, dirlist->name); /* "ERROR: custom dir '%s' is not a valid absolute path!" */
56
      puts("");
56
      puts("");
57
      return(-1);
57
      return(-1);
58
    }
58
    }
59
    /* check for forbidden names */
59
    /* check for forbidden names */
60
    if ((strcasecmp(dirlist->name, "appinfo") == 0) ||
60
    if ((strcasecmp(dirlist->name, "appinfo") == 0) ||
61
        (strcasecmp(dirlist->name, "bin") == 0) ||
61
        (strcasecmp(dirlist->name, "bin") == 0) ||
62
        (strcasecmp(dirlist->name, "doc") == 0) ||
62
        (strcasecmp(dirlist->name, "doc") == 0) ||
63
        (strcasecmp(dirlist->name, "help") == 0) ||
63
        (strcasecmp(dirlist->name, "help") == 0) ||
64
        (strcasecmp(dirlist->name, "nls") == 0) ||
64
        (strcasecmp(dirlist->name, "nls") == 0) ||
65
        (strcasecmp(dirlist->name, "packages") == 0)) {
65
        (strcasecmp(dirlist->name, "packages") == 0)) {
66
      kitten_printf(7, 16, "ERROR: custom dir '%s' is a reserved name!", dirlist->name);
66
      kitten_printf(7, 16, dirlist->name); /* "ERROR: custom dir '%s' is a reserved name!" */
67
      puts("");
67
      puts("");
68
      return(-1);
68
      return(-1);
69
    }
69
    }
70
  }
70
  }
71
  return(0);
71
  return(0);
Line 94... Line 94...
94
  int nline = 0;
94
  int nline = 0;
95
 
95
 
96
  snprintf(token, sizeof(token), "%s\\cfg\\pkg.cfg", dosdir);
96
  snprintf(token, sizeof(token), "%s\\cfg\\pkg.cfg", dosdir);
97
  fd = fopen(token, "r");
97
  fd = fopen(token, "r");
98
  if (fd == NULL) {
98
  if (fd == NULL) {
99
    kitten_printf(7, 1, "ERROR: Could not open config file (%s)!", token);
99
    kitten_printf(7, 1, token); /* "ERROR: Could not open config file (%s)!" */
100
    puts("");
100
    puts("");
101
    return(-1);
101
    return(-1);
102
  }
102
  }
103
 
103
 
104
  *dirlist = NULL;
104
  *dirlist = NULL;
Line 109... Line 109...
109
 
109
 
110
    /* skip comments and empty lines */
110
    /* skip comments and empty lines */
111
    if ((token[0] == '#') || (token[0] == 0)) continue;
111
    if ((token[0] == '#') || (token[0] == 0)) continue;
112
 
112
 
113
    if ((value == NULL) || (value[0] == 0)) {
113
    if ((value == NULL) || (value[0] == 0)) {
114
      kitten_printf(7, 4, "Warning: token with empty value on line #%d", nline);
114
      kitten_printf(7, 4, nline); /* "Warning: token with empty value on line #%d" */
115
      puts("");
115
      puts("");
116
      continue;
116
      continue;
117
    }
117
    }
118
 
118
 
119
    /* printf("token='%s' ; value = '%s'\n", token, value); */
119
    /* printf("token='%s' ; value = '%s'\n", token, value); */
Line 121... Line 121...
121
      char *location = NULL;
121
      char *location = NULL;
122
      int i;
122
      int i;
123
      /* find nearer space */
123
      /* find nearer space */
124
      for (i = 0; (value[i] != ' ') && (value[i] != 0); i++);
124
      for (i = 0; (value[i] != ' ') && (value[i] != 0); i++);
125
      if (value[i] == 0) {
125
      if (value[i] == 0) {
126
        kitten_printf(7, 11, "Warning: Invalid 'DIR' directive found at line #%d", nline);
126
        kitten_printf(7, 11, nline); /* "Warning: Invalid 'DIR' directive found at line #%d" */
127
        puts("");
127
        puts("");
128
        continue;
128
        continue;
129
      }
129
      }
130
      value[i] = 0;
130
      value[i] = 0;
131
      location = value + i + 1;
131
      location = value + i + 1;
Line 133... Line 133...
133
      /* add the entry to the list */
133
      /* add the entry to the list */
134
      slash2backslash(location);
134
      slash2backslash(location);
135
      removeDoubleBackslashes(location);
135
      removeDoubleBackslashes(location);
136
      if (location[strlen(location) - 1] != '\\') strcat(location, "\\"); /* make sure to end dirs with a backslash */
136
      if (location[strlen(location) - 1] != '\\') strcat(location, "\\"); /* make sure to end dirs with a backslash */
137
      if (addnewdir(dirlist, value, location) != 0) {
137
      if (addnewdir(dirlist, value, location) != 0) {
138
        kitten_printf(2, 14, "Out of memory! (%s)", "addnewdir");
138
        kitten_printf(2, 14, "addnewdir"); /* "Out of memory! (%s)" */
139
        puts("");
139
        puts("");
140
        freeconf(dirlist);
140
        freeconf(dirlist);
141
        fclose(fd);
141
        fclose(fd);
142
        return(-1);
142
        return(-1);
143
      }
143
      }
144
    } else { /* unknown token */
144
    } else { /* unknown token */
145
      kitten_printf(7, 8, "Warning: Unknown token '%s' at line #%d", token, nline);
145
      kitten_printf(7, 8, token, nline); /* "Warning: Unknown token '%s' at line #%d" */
146
      puts("");
146
      puts("");
147
    }
147
    }
148
  }
148
  }
149
  fclose(fd);
149
  fclose(fd);
150
 
150