~ubuntu-branches/ubuntu/hardy/silo/hardy-updates

« back to all changes in this revision

Viewing changes to silo/confcheck.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-10-25 09:28:08 UTC
  • mfrom: (15.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071025092808-1yhj12t7s4zqsfu5
Tags: 1.4.13a+git20070930-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build with -fno-stack-protector.
  - Change silo.postinst to automatically update the boot block without
    invoking siloconfig and keep asking questions on upgrades.
  - Convert silo.conf to use /dev/disk/by-uuid.
  - Ubuntu maintainer foobar.
  - Fix debian/rules call to dh_installdocs.
  - Drop the requirement of gcc-4.1 and start using default gcc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* siloconfcheck - validate silo.conf syntax
 
2
 
 
3
   Copyright (C) 2000 Ben Collins <bcollins@debian.org>
 
4
 
 
5
   This program is free software; you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation; either version 2 of the License, or
 
8
   (at your option) any later version.
 
9
 
 
10
   This program is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
   GNU General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU General Public License
 
16
   along with this program; if not, write to the Free Software
 
17
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
18
   USA.  */
 
19
 
 
20
#include <stdlib.h>
 
21
#include <stdio.h>
 
22
#include <stdarg.h>
 
23
#include <string.h>
 
24
#include <setjmp.h>
 
25
#include <sys/types.h>
 
26
#include <sys/stat.h>
 
27
#include <fcntl.h>
 
28
#include <unistd.h>
 
29
#include <sys/mman.h>
 
30
#include <ctype.h>
 
31
 
 
32
/* Get decleration of enum arch */
 
33
#include <promlib.h>
 
34
/* And then make sure we get printf right */
 
35
#define prom_printf printf
 
36
 
 
37
enum arch architecture;
 
38
 
 
39
/* Tells cfg.c not to #include anything of it's own, we are in control.  */
 
40
#define SILOCONFCHECK 1
 
41
 
 
42
#include "../second/cfg.c"
 
43
 
 
44
int confcheck(char* conf) {
 
45
        struct stat st;
 
46
        int fd;
 
47
        char *buf;
 
48
 
 
49
        if (conf == NULL) return 1;
 
50
 
 
51
        if (stat(conf, &st) || ((fd = open(conf, O_RDONLY)) == -1) ||
 
52
            ((buf = (char *)mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED)) {
 
53
                perror(conf);
 
54
                return 0;
 
55
        }
 
56
 
 
57
        if (cfg_parse(conf, buf, st.st_size)) {
 
58
                fprintf(stderr, "Error parsing silo config file %s\n", conf);
 
59
                return 0;
 
60
        }
 
61
 
 
62
        munmap(buf, st.st_size);
 
63
 
 
64
        printf("%s appears to be valid\n", conf);
 
65
 
 
66
        return 1;
 
67
}